Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function RGB(r, g, b) {
- return (0xff000000 | (r << 16) | (g << 8) | (b));
- };
- function RGBA(r, g, b, a) {
- return ((a << 24) | (r << 16) | (g << 8) | (b));
- };
- var image_path = fb.FoobarPath + "icons\\custom\\";
- //1. put this in the global code section:
- //=================================================// OBJECT button
- button = function () {
- this._attrb = {};
- this.create = function (path_normal, path_hover, path_down) {
- this._attrb.normal = gdi.Image(path_normal);
- this._attrb.hover = gdi.Image(path_hover);
- this._attrb.down= gdi.Image(path_down);
- if (typeof this._attrb.x == "undefined") this._attrb.x= 0;
- if (typeof this._attrb.y == "undefined") this._attrb.y= 0;
- this._attrb.w = this._attrb.normal.Width;
- this._attrb.h= this._attrb.normal.Height;
- if (typeof this._attrb.state == "undefined") this._attrb.state=0;
- }
- this.draw = function (gr, bx, by, alpha, label) {
- var image;
- this._attrb.x = bx;
- this._attrb.y = by;
- switch(this._attrb.state)
- {
- case 0:
- image = this._attrb.normal;
- break;
- case 1:
- image = this._attrb.hover;
- break;
- case 2:
- image = this._attrb.down;
- break;
- }
- gr.DrawImage(image, bx, by, this._attrb.w, this._attrb.h, 0, 0, this._attrb.w, this._attrb.h, 0, alpha);
- }
- this.checkstate = function (action, x, y) {
- switch(action)
- {
- case "down":
- if (x>this._attrb.x && x<this._attrb.x+this._attrb.w && y>this._attrb.y && y<this._attrb.y+this._attrb.h)
- {
- this._attrb.state=2;
- window.Repaint();
- } else if (this._attrb.state==2){
- this._attrb.state=0;
- window.Repaint();
- }
- break;
- case "move":
- if (x>this._attrb.x && x<this._attrb.x+this._attrb.w && y>this._attrb.y && y<this._attrb.y+this._attrb.h)
- {
- this._attrb.state=1;
- window.Repaint();
- } else if (this._attrb.state==1){
- this._attrb.state=0;
- window.Repaint();
- }
- break;
- case "up":
- this._attrb.state=0;
- break;
- }
- return this._attrb.state;
- }
- }
- var ButtonStates = {normal: 0,hover: 1,down: 2};
- var ww;
- var wh;
- //2. always in global code section, declare a new button instance, for example : button01 :
- var button01 = new button;
- var button02 = new button;
- var button03 = new button;
- var button04 = new button;
- //3. in on_paint() function, call the draw method for the button01 just created smile.gif
- //draw button 01 at position x,y with alpha transparency level
- function on_paint(gr){
- gr.FillSolidRect(0, 0, ww, wh, RGB(240,240,240));
- button01.draw(gr,0,4,255);
- button02.draw(gr,18,4,255);
- button03.draw(gr,36,4,255);
- button04.draw(gr,54,4,255);
- }
- //4. in on_size() function, set the button images (for the 3 possible states : normal, down, hover)
- function on_size(){
- ww = window.Width;
- wh = window.Height;
- button01.create(image_path + "headphones.png", image_path + "headphonesHover.png", image_path + "headphonesDown.png");
- button02.create(image_path + "gapless.png", image_path + "gaplessHover.png", image_path + "gaplessDown.png");
- button03.create(image_path + "heart.png", image_path + "heartHover.png", image_path + "heartDown.png");
- button04.create(image_path + "clear.png", image_path + "clearHover.png", image_path + "clearDown.png");
- }
- //5. in on_lbtn_down() function, call checkstate method for this event "down"
- function on_mouse_lbtn_down(x, y) {
- if (button01.checkstate("down",x,y)==ButtonStates.down) {
- // code ... actions ... here
- fb.RunMainMenuCommand("Playback/DSP Settings/Headphone Magic 48KHz");
- }
- if (button02.checkstate("down",x,y)==ButtonStates.down) {
- // code ... actions ... here
- fb.RunMainMenuCommand("Playback/DSP Settings/Gapless 48KHz");
- }
- if (button03.checkstate("down",x,y)==ButtonStates.down) {
- // code ... actions ... here
- fb.RunContextCommand("Last.fm/Last.fm Love '" + fb.TitleFormat("%title%").Eval() + "' By '" + fb.TitleFormat("%artist%").Eval() + "'");
- }
- if (button04.checkstate("down",x,y)==ButtonStates.down) {
- // code ... actions ... here
- fb.RunMainMenuCommand("Edit/Clear");
- }
- window.Repaint();
- }
- //6. in on_mouse_move() function, call checkstate method for this event "move" to display hover image
- function on_mouse_move(x, y) {
- hand = false;
- button01.checkstate("move",x,y);
- button02.checkstate("move",x,y);
- button03.checkstate("move",x,y);
- button04.checkstate("move",x,y);
- }
- //7. in on_mouse_lbtn_up() function, restore the normal state and so the normal button image
- function on_mouse_lbtn_up(x, y) {
- button01.checkstate("up",x,y);
- button02.checkstate("up",x,y);
- button03.checkstate("up",x,y);
- button04.checkstate("up",x,y);
- window.Repaint(); // repaint needed after the check state in this function
- }
- //8. in on_mouse_leave() function, restore the normal state and so the normal button image
- function on_mouse_leave() {
- button01.checkstate("up",0,0);
- button02.checkstate("up",0,0);
- button03.checkstate("up",0,0);
- button04.checkstate("up",0,0);
- window.Repaint(); // repaint needed after the check state in this function
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement