Advertisement
rooksword

BasicButtons

May 20th, 2024 (edited)
659
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. global.bb_hover = 0; // 0 = darken, 1 = alpha
  2. global.bb_rect_colour = c_ltgray;
  3. global.bb_rect_alpha = 1;
  4. global.bb_text_colour = c_dkgray;
  5. global.bb_outline = false;
  6. global.bb_padding = 4;
  7. global.bb_mousex = 0;
  8. global.bb_mousey = 0;
  9.  
  10. function Button(_string) constructor
  11. {
  12.     text = _string;
  13.     text_x = 0;
  14.     text_y = 0;
  15.    
  16.     x0 = -global.bb_padding;
  17.     y0 = -global.bb_padding;
  18.     x1 = global.bb_padding;
  19.     y1 = global.bb_padding;
  20.    
  21.     radius = 0;
  22.    
  23.     function Define4(_x0, _y0, _x1, _y1)
  24.     {
  25.         x0 += _x0;
  26.         y0 += _y0;
  27.         x1 += _x1;
  28.         y1 += _y1;
  29.     }
  30.    
  31.     function DefineTL(_x, _y, _w, _h)
  32.     {
  33.         x0 += _x;
  34.         y0 += _y;
  35.         x1 += _x + _w;
  36.         y1 += _y + _h;
  37.        
  38.         text_x = _x;
  39.         text_y = _y;
  40.     }
  41.    
  42.     function DefineTR(_x, _y, _w, _h)
  43.     {
  44.         x0 += _x - _w;
  45.         y0 += _y - _h;
  46.         x1 += _x;
  47.         y1 += _y;
  48.        
  49.         text_x = _x;
  50.         text_y = _y;
  51.     }
  52.    
  53.     function DefineC(_x, _y, _w, _h)
  54.     {
  55.         x0 += _x - (_w / 2);
  56.         y0 += _y - (_h / 2);
  57.         x1 += _x + (_w / 2);
  58.         y1 += _y + (_h / 2);
  59.        
  60.         text_x = _x;
  61.         text_y = _y;
  62.     }
  63.  
  64.     function Draw()
  65.     {
  66.         var _alpha = 1;
  67.        
  68.         var _rcolour = global.bb_rect_colour;
  69.         var _tcolour = global.bb_text_colour;
  70.        
  71.         if global.bb_hover == 0
  72.         {
  73.             if Hover()
  74.             {
  75.                 _rcolour = merge_colour(_rcolour, c_black, 0.5);
  76.                 _tcolour = merge_colour(_tcolour, c_black, 0.5);
  77.             }
  78.         }
  79.         else
  80.         {
  81.             if !Hover()
  82.             {
  83.                 _alpha = 0.5;
  84.             }
  85.         }
  86.        
  87.         draw_set_alpha(_alpha);
  88.        
  89.         draw_set_colour(_rcolour);
  90.         draw_set_alpha(global.bb_rect_alpha);
  91.         draw_roundrect_ext(x0, y0, x1, y1, radius, radius, global.bb_outline);
  92.        
  93.         draw_set_alpha(1);
  94.         draw_set_alpha(_alpha);
  95.        
  96.         draw_set_colour(_tcolour);
  97.         draw_text(text_x, text_y, text);
  98.        
  99.         draw_set_alpha(1);
  100.     }
  101.    
  102.     function Hover()
  103.     {
  104.         return point_in_rectangle(global.bb_mousex, global.bb_mousey, x0, y0, x1, y1); 
  105.     }
  106.    
  107.     function Pressed()
  108.     {
  109.         return Hover() and mouse_check_button_pressed(mb_left);
  110.     }
  111.    
  112.     function PressedR()
  113.     {
  114.         return Hover() and mouse_check_button_pressed(mb_right);
  115.     }
  116.    
  117.     function Down()
  118.     {
  119.         return Hover() and mouse_check_button(mb_left);
  120.     }
  121.    
  122.     function DownR()
  123.     {
  124.         return Hover() and mouse_check_button(mb_right);
  125.     }
  126.    
  127.     function Released()
  128.     {
  129.         return Hover() and mouse_check_button_released(mb_left);
  130.     }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement