Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function createButton( x, y, w, h, text, Color, textColor )
- local xOfset = 0;
- local yOfset = 0;
- local isVisableX = true;
- local mouseInside = false;
- local swap = Color;
- local swapCheck = 0;
- local test = 0;
- local MButton = {
- x = 0, y = 0,
- w = 80, h = 20,
- text = "Button",
- isVisable = isVisableX,
- textColor = tocolor( 236, 240, 241, 255 ),
- Color = tocolor( 231, 76, 60, 150 ),
- type = "Button",
- render = function ()
- if ( isVisableX == true ) then
- dxDrawRectangle( x + xOfset, y + yOfset, w, h, Color )
- dxDrawText( text, ( (x + xOfset) + (w/2) ) - (string.len(text)*3), ((y + yOfset) - 7) + (h/2) )
- end
- end,
- isMouseInside = function ()
- mouseX, mouseY = getCursorPosition();
- if ( not isCursorShowing ( ) ) then
- return false
- end
- local Sx, Sy = guiGetScreenSize( )
- x2 = Sx * mouseX;
- y2 = Sy * mouseY;
- --outputChatBox(y + yOfset .. " : " .. h + yOfset + 40 .. ", " .. math.floor(y2))
- --outputChatBox(x + xOfset .. " : " .. w + xOfset + x .. ", " .. math.floor(x2))
- if ( x2 >= x + xOfset and x2 <= w + xOfset + x and y2 >= y + yOfset and y2 <= h + yOfset + y) then
- return true;
- end
- return false;
- end,
- highlight = function ( value )
- if ( swapCheck == 0 ) then
- swap = Color;
- swapCheck = 1;
- Color = Color + value
- end
- end,
- dehighlight = function ()
- Color = swap;
- swapCheck = 0;
- end,
- setVisable = function ( visable )
- isVisableX = visable;
- end,
- getVisable = function ( )
- return isVisableX;
- end,
- setTextColor = function ( color )
- textColor = color;
- end,
- setTextColorRGBA = function ( r, g, b, a )
- textColor = tocolor( r, g, b, a )
- end,
- getText = function ( )
- return text;
- end,
- setText = function ( text2 )
- text = text2;
- end,
- setColor = function ( Color2 )
- Color = Color2;
- end,
- setColorRGBA = function ( r, g, b, a )
- Color = tocolor( r, g, b, a )
- end,
- getColorRGBA = function ( )
- end,
- setOfset = function ( ofx, ofy )
- xOfset = ofx;
- yOfset = ofy;
- end,
- setX = function (x2) x = x2 end,
- getX = function () return x; end,
- setY = function (y2) y = y2 end,
- getY = function () return y; end,
- setW = function (w2) w = w2 end,
- getW = function () return w; end,
- setH = function (h2) h = h2 end,
- getH = function () return h; end,
- Click = function ( button, state )
- if ( not mouseInside ) then
- return;
- end
- if ( test == 0 ) then
- triggerEvent( "onMButtonClicked", getRootElement(), button, state, text, x, y, w, h )
- test = 1;
- Color = Color + 30;
- setTimer( function ()
- test = 0;
- Color = Color - 30;
- end, 150, 1 )
- end
- end,
- }
- local update = function ()
- mouseInside = MButton.isMouseInside();
- end
- local create = function ()
- MButton.x = x; MButton.y = y;
- MButton.w = w; MButton.h = h;
- MButton.text = text; MButton.Color = Color;
- MButton.textColor = textColor;
- addEventHandler( "onClientClick", getRootElement(), MButton.Click )
- addEventHandler( "onClientRender", getRootElement(), update )
- return MButton;
- end
- return create()
- end
Add Comment
Please, Sign In to add comment