Mouamle

Mta dxButton

Apr 28th, 2016
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.22 KB | None | 0 0
  1.  
  2. function createButton( x, y, w, h, text, Color, textColor )
  3.     local xOfset = 0;
  4.     local yOfset = 0;
  5.     local isVisableX = true;
  6.  
  7.     local mouseInside = false;
  8.  
  9.     local swap = Color;
  10.     local swapCheck = 0;
  11.  
  12.     local test = 0;
  13.  
  14.  
  15.     local MButton = {
  16.         x = 0, y = 0,
  17.         w = 80, h = 20,
  18.         text = "Button",
  19.         isVisable = isVisableX,
  20.         textColor = tocolor( 236, 240, 241, 255 ),
  21.         Color = tocolor( 231, 76, 60, 150 ),
  22.         type = "Button",
  23.  
  24.  
  25.         render = function ()
  26.             if ( isVisableX == true ) then
  27.                 dxDrawRectangle( x + xOfset, y + yOfset, w, h, Color )
  28.                 dxDrawText( text, ( (x + xOfset) + (w/2) ) - (string.len(text)*3), ((y + yOfset) - 7) + (h/2)  )
  29.             end
  30.         end,
  31.  
  32.         isMouseInside = function ()
  33.             mouseX, mouseY = getCursorPosition();
  34.             if ( not isCursorShowing ( ) ) then
  35.                 return false
  36.             end
  37.             local Sx, Sy = guiGetScreenSize( )
  38.             x2 = Sx * mouseX;
  39.             y2 = Sy * mouseY;
  40.             --outputChatBox(y + yOfset .. " : " .. h + yOfset + 40 .. ", " .. math.floor(y2))
  41.             --outputChatBox(x + xOfset .. " : " .. w + xOfset + x  .. ", " .. math.floor(x2))
  42.             if ( x2 >= x + xOfset and x2 <= w + xOfset + x and y2 >= y + yOfset and y2 <= h + yOfset + y) then
  43.                 return true;
  44.             end
  45.  
  46.             return false;
  47.         end,
  48.  
  49.  
  50.  
  51.         highlight = function ( value )
  52.             if ( swapCheck == 0 ) then
  53.                 swap = Color;
  54.                 swapCheck = 1;
  55.                 Color = Color + value
  56.             end
  57.         end,
  58.  
  59.         dehighlight = function ()
  60.             Color = swap;
  61.             swapCheck = 0;
  62.         end,
  63.  
  64.         setVisable = function ( visable )
  65.             isVisableX = visable;
  66.         end,
  67.  
  68.         getVisable = function ( )
  69.             return isVisableX;
  70.         end,
  71.  
  72.         setTextColor = function ( color )
  73.             textColor = color;
  74.         end,
  75.  
  76.         setTextColorRGBA = function ( r, g, b, a )
  77.             textColor = tocolor( r, g, b, a )
  78.         end,
  79.  
  80.         getText = function ( )
  81.             return text;
  82.         end,
  83.  
  84.         setText = function ( text2 )
  85.             text = text2;
  86.         end,
  87.  
  88.         setColor = function ( Color2 )
  89.             Color = Color2;
  90.         end,
  91.  
  92.         setColorRGBA = function ( r, g, b, a )
  93.             Color = tocolor( r, g, b, a )
  94.         end,
  95.  
  96.         getColorRGBA = function (  )
  97.            
  98.         end,
  99.  
  100.         setOfset = function ( ofx, ofy )
  101.             xOfset = ofx;
  102.             yOfset = ofy;
  103.         end,
  104.  
  105.         setX = function (x2) x = x2 end,
  106.         getX = function () return x; end,
  107.  
  108.         setY = function (y2) y = y2 end,
  109.         getY = function () return y; end,
  110.  
  111.         setW = function (w2) w = w2 end,
  112.         getW = function () return w; end,
  113.  
  114.         setH = function (h2) h = h2 end,
  115.         getH = function () return h; end,
  116.  
  117.  
  118.         Click = function ( button, state )
  119.             if ( not mouseInside  ) then
  120.                 return;
  121.             end
  122.             if ( test == 0 ) then
  123.                 triggerEvent( "onMButtonClicked", getRootElement(), button, state, text, x, y, w, h )
  124.                 test = 1;
  125.                 Color = Color + 30;
  126.                 setTimer( function ()
  127.                     test = 0;
  128.                     Color = Color - 30;
  129.                 end, 150, 1 )
  130.             end
  131.         end,
  132.  
  133.     }
  134.  
  135.  
  136.     local update = function ()
  137.         mouseInside = MButton.isMouseInside();
  138.     end
  139.  
  140.  
  141.     local create = function ()
  142.         MButton.x = x; MButton.y = y;
  143.         MButton.w = w; MButton.h = h;
  144.         MButton.text = text; MButton.Color = Color;
  145.         MButton.textColor = textColor;
  146.         addEventHandler( "onClientClick", getRootElement(), MButton.Click )
  147.         addEventHandler( "onClientRender", getRootElement(), update )
  148.         return MButton;
  149.     end
  150.  
  151.     return create()
  152. end
Add Comment
Please, Sign In to add comment