Advertisement
Guest User

Some FB buttons

a guest
Jan 3rd, 2013
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.86 KB | None | 0 0
  1. function RGB(r, g, b) {
  2. return (0xff000000 | (r << 16) | (g << 8) | (b));
  3. };
  4. function RGBA(r, g, b, a) {
  5. return ((a << 24) | (r << 16) | (g << 8) | (b));
  6. };
  7.  
  8. var image_path = fb.FoobarPath + "icons\\custom\\";
  9.  
  10. //1. put this in the global code section:
  11.  
  12. //=================================================// OBJECT button
  13. button = function () {
  14. this._attrb = {};
  15.  
  16. this.create = function (path_normal, path_hover, path_down) {
  17. this._attrb.normal = gdi.Image(path_normal);
  18. this._attrb.hover = gdi.Image(path_hover);
  19. this._attrb.down= gdi.Image(path_down);
  20. if (typeof this._attrb.x == "undefined") this._attrb.x= 0;
  21. if (typeof this._attrb.y == "undefined") this._attrb.y= 0;
  22. this._attrb.w = this._attrb.normal.Width;
  23. this._attrb.h= this._attrb.normal.Height;
  24. if (typeof this._attrb.state == "undefined") this._attrb.state=0;
  25. }
  26.  
  27. this.draw = function (gr, bx, by, alpha, label) {
  28. var image;
  29. this._attrb.x = bx;
  30. this._attrb.y = by;
  31. switch(this._attrb.state)
  32. {
  33. case 0:
  34. image = this._attrb.normal;
  35. break;
  36. case 1:
  37. image = this._attrb.hover;
  38. break;
  39. case 2:
  40. image = this._attrb.down;
  41. break;
  42. }
  43. gr.DrawImage(image, bx, by, this._attrb.w, this._attrb.h, 0, 0, this._attrb.w, this._attrb.h, 0, alpha);
  44. }
  45.  
  46. this.checkstate = function (action, x, y) {
  47. switch(action)
  48. {
  49. case "down":
  50. if (x>this._attrb.x && x<this._attrb.x+this._attrb.w && y>this._attrb.y && y<this._attrb.y+this._attrb.h)
  51. {
  52. this._attrb.state=2;
  53. window.Repaint();
  54. } else if (this._attrb.state==2){
  55. this._attrb.state=0;
  56. window.Repaint();
  57. }
  58. break;
  59. case "move":
  60. if (x>this._attrb.x && x<this._attrb.x+this._attrb.w && y>this._attrb.y && y<this._attrb.y+this._attrb.h)
  61. {
  62. this._attrb.state=1;
  63. window.Repaint();
  64. } else if (this._attrb.state==1){
  65. this._attrb.state=0;
  66. window.Repaint();
  67. }
  68. break;
  69. case "up":
  70. this._attrb.state=0;
  71. break;
  72. }
  73. return this._attrb.state;
  74. }
  75.  
  76. }
  77.  
  78. var ButtonStates = {normal: 0,hover: 1,down: 2};
  79.  
  80.  
  81. var ww;
  82. var wh;
  83.  
  84.  
  85. //2. always in global code section, declare a new button instance, for example : button01 :
  86. var button01 = new button;
  87. var button02 = new button;
  88. var button03 = new button;
  89. var button04 = new button;
  90.  
  91. //3. in on_paint() function, call the draw method for the button01 just created smile.gif
  92. //draw button 01 at position x,y with alpha transparency level
  93. function on_paint(gr){
  94. gr.FillSolidRect(0, 0, ww, wh, RGB(240,240,240));
  95. button01.draw(gr,0,4,255);
  96. button02.draw(gr,18,4,255);
  97. button03.draw(gr,36,4,255);
  98. button04.draw(gr,54,4,255);
  99. }
  100.  
  101. //4. in on_size() function, set the button images (for the 3 possible states : normal, down, hover)
  102. function on_size(){
  103. ww = window.Width;
  104. wh = window.Height;
  105. button01.create(image_path + "headphones.png", image_path + "headphonesHover.png", image_path + "headphonesDown.png");
  106. button02.create(image_path + "gapless.png", image_path + "gaplessHover.png", image_path + "gaplessDown.png");
  107. button03.create(image_path + "heart.png", image_path + "heartHover.png", image_path + "heartDown.png");
  108. button04.create(image_path + "clear.png", image_path + "clearHover.png", image_path + "clearDown.png");
  109. }
  110.  
  111. //5. in on_lbtn_down() function, call checkstate method for this event "down"
  112. function on_mouse_lbtn_down(x, y) {
  113. if (button01.checkstate("down",x,y)==ButtonStates.down) {
  114. // code ... actions ... here
  115. fb.RunMainMenuCommand("Playback/DSP Settings/Headphone Magic 48KHz");
  116. }
  117. if (button02.checkstate("down",x,y)==ButtonStates.down) {
  118. // code ... actions ... here
  119. fb.RunMainMenuCommand("Playback/DSP Settings/Gapless 48KHz");
  120. }
  121. if (button03.checkstate("down",x,y)==ButtonStates.down) {
  122. // code ... actions ... here
  123. fb.RunContextCommand("Last.fm/Last.fm Love '" + fb.TitleFormat("%title%").Eval() + "' By '" + fb.TitleFormat("%artist%").Eval() + "'");
  124. }
  125. if (button04.checkstate("down",x,y)==ButtonStates.down) {
  126. // code ... actions ... here
  127. fb.RunMainMenuCommand("Edit/Clear");
  128. }
  129. window.Repaint();
  130. }
  131.  
  132.  
  133. //6. in on_mouse_move() function, call checkstate method for this event "move" to display hover image
  134. function on_mouse_move(x, y) {
  135. hand = false;
  136. button01.checkstate("move",x,y);
  137. button02.checkstate("move",x,y);
  138. button03.checkstate("move",x,y);
  139. button04.checkstate("move",x,y);
  140. }
  141.  
  142.  
  143. //7. in on_mouse_lbtn_up() function, restore the normal state and so the normal button image
  144. function on_mouse_lbtn_up(x, y) {
  145. button01.checkstate("up",x,y);
  146. button02.checkstate("up",x,y);
  147. button03.checkstate("up",x,y);
  148. button04.checkstate("up",x,y);
  149. window.Repaint(); // repaint needed after the check state in this function
  150. }
  151.  
  152. //8. in on_mouse_leave() function, restore the normal state and so the normal button image
  153. function on_mouse_leave() {
  154. button01.checkstate("up",0,0);
  155. button02.checkstate("up",0,0);
  156. button03.checkstate("up",0,0);
  157. button04.checkstate("up",0,0);
  158. window.Repaint(); // repaint needed after the check state in this function
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement