Advertisement
Guest User

marc2003

a guest
Jan 15th, 2010
4,135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var Buttons;
  2.  
  3. var g_tooltip = window.CreateTooltip();
  4. var g_down = false;
  5.  
  6. var btn_down = null;
  7. var cur_btn = null;
  8.  
  9. ButtonStates = {
  10.     normal: 0,
  11.     hover: 1,
  12.     down: 2
  13. }
  14.  
  15. function Button(x, y, w, h, img_src, func, tiptext)  {
  16.     this.left = x;
  17.     this.top = y;
  18.     this.w = w;
  19.     this.h = h;
  20.     this.right = x + w;
  21.     this.bottom = y + h;
  22.     this.func = func;
  23.     this.tiptext = tiptext;
  24.     this.state = ButtonStates.normal;
  25.     this.img_normal = img_src && img_src.normal ? gdi.Image(img_src.normal) : null;
  26.     this.img_hover = img_src && img_src.hover ? gdi.Image(img_src.hover) : this.img_normal;
  27.     this.img_down = img_src && img_src.down ? gdi.Image(img_src.down) : this.img_hover;
  28.     this.img = this.img_normal;
  29.    
  30.     this.alterImage = function(img_src) {
  31.         this.img_normal = img_src && img_src.normal ? gdi.Image(img_src.normal) : null;
  32.         this.img_hover = img_src && img_src.hover ? gdi.Image(img_src.hover) : this.img_normal;
  33.         this.img_down = img_src && img_src.down ? gdi.Image(img_src.down) : this.img_hover;
  34.        
  35.         this.changeState(this.state);
  36.     }
  37.    
  38.     this.traceMouse = function (x, y) {
  39.         var b = (this.left < x) && (x < this.right) && (this.top < y) && (y < this.bottom);
  40.         if (b)
  41.             g_down ? this.changeState(ButtonStates.down) : this.changeState(ButtonStates.hover);
  42.         else
  43.             this.changeState(ButtonStates.normal);
  44.         return b;
  45.     }
  46.    
  47.    
  48.     this.changeState = function (newstate) {
  49.         if (newstate != this.state)
  50.             window.RepaintRect(this.left, this.top, this.w, this.h);
  51.         this.state = newstate;
  52.         switch (this.state)
  53.         {
  54.         case ButtonStates.normal:
  55.             this.img = this.img_normal;
  56.             break;
  57.            
  58.         case ButtonStates.hover:
  59.             this.img = this.img_hover;
  60.             break;
  61.            
  62.         case ButtonStates.down:
  63.             this.img = this.img_down;
  64.             break;
  65.            
  66.         default:
  67.             this.img = null;
  68.         }
  69.     }
  70.    
  71.     this.draw = function (gr) {
  72.         this.img && gr.DrawImage(this.img, this.left, this.top, this.w, this.h, 0, 0, this.w, this.h);
  73.     }
  74.    
  75.     this.onClick = function () {
  76.         this.func && this.func(x,y);
  77.     }
  78.    
  79.     this.onMouseIn = function() {
  80.         g_tooltip.Text = this.tiptext;
  81.         g_tooltip.Activate();
  82.     }
  83.    
  84.     this.onMouseOut = function() {
  85.         g_tooltip.Deactivate();
  86.     }
  87. }
  88.  
  89. function buttonsDraw(gr) {
  90.     for (i in Buttons) {
  91.         Buttons[i].draw(gr);
  92.     }
  93. }
  94.  
  95. function buttonsTraceMouse(x, y) {
  96.     var btn = null;
  97.     for (i in Buttons) {
  98.         if (Buttons[i].traceMouse(x, y) && !btn)
  99.             btn = Buttons[i];
  100.     }
  101.  
  102.     return btn;
  103. }
  104.  
  105. function on_mouse_move(x, y) {
  106.     var btn = buttonsTraceMouse(x, y);
  107.    
  108.     if (btn != cur_btn) {
  109.         cur_btn && cur_btn.onMouseOut();
  110.         btn && btn.onMouseIn();
  111.     }
  112.    
  113.     cur_btn = btn;
  114. }
  115.  
  116. function on_mouse_lbtn_down(x, y) {
  117.     g_down = true;
  118.     btn_down = cur_btn;
  119.  
  120.     if (cur_btn) {
  121.         cur_btn.changeState(ButtonStates.down);
  122.     }
  123. }
  124.  
  125. function on_mouse_lbtn_up(x, y) {
  126.     if (cur_btn) {
  127.         cur_btn.changeState(ButtonStates.hover);
  128.         if( btn_down == cur_btn )
  129.             cur_btn.onClick(x, y);
  130.     }
  131.     g_down = false;
  132. }
  133.  
  134. function on_mouse_leave() {
  135.     if (cur_btn) {
  136.         cur_btn.changeState(ButtonStates.normal);
  137.     }
  138. }
  139.  
  140. function on_size() {
  141.     ww = window.Width;
  142.     wh = window.Height;
  143. }
  144.  
  145. function on_paint(gr) {
  146.     switch(window.GetProperty("mode", 1)) {
  147.         case 1:
  148.             col = window.GetColorDUI(1);
  149.             break;
  150.         case 2:
  151.             col = utils.GetSysColor(4);
  152.             break;
  153.         case 3:
  154.             col = custom;
  155.             break;
  156.     }
  157.     gr.FillSolidRect(0, 0, ww, wh, col);
  158.     buttonsDraw(gr);
  159.     gr.DrawRect(0,0, ww, wh, 1.0, -6250336);
  160. }
  161.  
  162. function RGB(r,g,b) {
  163.     return (0xff000000|(r<<16)|(g<<8)|(b));
  164. }
  165.  
  166. function on_colors_changed() {
  167.     window.Repaint();
  168. }
  169.  
  170. function on_mouse_rbtn_up(x, y) {
  171.     var MF_SEPARATOR = 0x00000800;
  172.     var MF_STRING = 0x00000000;
  173.     var _menu = window.CreatePopupMenu();
  174.     var idx;
  175.     _menu.AppendMenuItem(MF_STRING, 1, "Default");
  176.     _menu.AppendMenuItem(MF_STRING, 2, "Splitter");
  177.     _menu.AppendMenuItem(MF_STRING, 3, "Custom ");
  178.     _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
  179.     //_menu.AppendMenuItem(MF_STRING, 9, "Properties");
  180.     _menu.AppendMenuItem(MF_STRING, 10, "Configure...");
  181.     _menu.CheckMenuRadioItem(1, 3, window.GetProperty("mode", 1));
  182.     idx = _menu.TrackPopupMenu(x, y);
  183.     switch(idx) {
  184.         case 1:
  185.         case 2:
  186.         case 3:
  187.             window.SetProperty("mode", idx);
  188.             window.Repaint();
  189.             break;
  190.         case 9:
  191.             window.ShowProperties();
  192.             break;
  193.         case 10:
  194.             window.ShowConfigure();
  195.             break;
  196.     }
  197.     _menu.Dispose();
  198.     return true;
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement