Advertisement
Mouamle

Render Thingy

Apr 27th, 2016
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.72 KB | None | 0 0
  1.  
  2. function createButton( x, y, w, h, text, Color, textColor )
  3.     xOfset = 0;
  4.     yOfset = 0;
  5.     isVisableX = true;
  6.     local MButton = {
  7.         x = 0, y = 0,
  8.         w = 80, h = 20,
  9.         text = "Button",
  10.         isVisable = isVisableX,
  11.         textColor = tocolor( 236, 240, 241, 255 ),
  12.         Color = tocolor( 231, 76, 60, 150 ),
  13.  
  14.  
  15.         render = function ()
  16.             if ( isVisableX == true ) then
  17.                 dxDrawRectangle( x + xOfset, y + yOfset, w, h, Color )
  18.                 dxDrawText( text, ( (x + xOfset) + (w/2) ) - (string.len(text)*3), ((y + yOfset) - 7) + (h/2)  )
  19.             end
  20.         end,
  21.  
  22.         isMouseInside = function ()
  23.             mouseX, mouseY = getCursorPosition();
  24.             if ( not isCursorShowing ( ) ) then
  25.                 return false
  26.             end
  27.             local Sx, Sy = guiGetScreenSize( )
  28.             if ( mouseX * Sx >= x + xOfset and mouseX * Sx <= w + xOfset + 10 and mouseY * Sy >= y + yOfset and mouseY * Sy <= h + yOfset + 20) then
  29.                 return true;
  30.             end
  31.  
  32.             return false;
  33.         end,
  34.  
  35.         setVisable = function ( visable )
  36.             isVisableX = visable;
  37.         end,
  38.  
  39.         setTextColor = function ( color )
  40.             textColor = color;
  41.         end,
  42.  
  43.         setTextColorRGBA = function ( r, g, b, a )
  44.             textColor = tocolor( r, g, b, a )
  45.         end,
  46.  
  47.         getText = function ( )
  48.             return text;
  49.         end,
  50.  
  51.         setText = function ( text2 )
  52.             text = text2;
  53.         end,
  54.  
  55.         setColor = function ( Color2 )
  56.             Color = Color2;
  57.         end,
  58.  
  59.         setColorRGBA = function ( r, g, b, a )
  60.             Color = tocolor( r, g, b, a )
  61.         end,
  62.  
  63.         getColorRGBA = function (  )
  64.            
  65.         end,
  66.  
  67.         setOfset = function ( ofx, ofy )
  68.             xOfset = ofx;
  69.             yOfset = ofy;
  70.         end,
  71.  
  72.         setX = function (x2) x = x2 end,
  73.         getX = function () return x; end,
  74.  
  75.         setY = function (y2) y = y2 end,
  76.         getY = function () return y; end,
  77.  
  78.         setW = function (w2) w = w2 end,
  79.         getW = function () return w; end,
  80.  
  81.         setH = function (h2) h = h2 end,
  82.         getH = function () return h; end
  83.     }
  84.     local create = function ()
  85.         MButton.x = x; MButton.y = y;
  86.         MButton.w = w; MButton.h = h;
  87.         MButton.text = text; MButton.Color = Color;
  88.         MButton.textColor = textColor;
  89.         return MButton;
  90.     end
  91.  
  92.     return create()
  93. end
  94.  
  95. function createFrame( x, y, w, h, Title, Color, TitleBarColor )
  96.     MFrame = {
  97.         x = 0, y = 0,
  98.         w = 400, h = 250,
  99.         Title = "Frame",
  100.         Color = tocolor( 120, 120, 120, 150 ),
  101.         Color = tocolor( 120, 120, 120, 255 ),
  102.  
  103.         components = {
  104.  
  105.         },
  106.  
  107.         render = function ()
  108.             dxDrawRectangle( x, y, w, h, Color, false)
  109.             dxDrawRectangle( x, y, w, 15, TitleBarColor, false)
  110.             dxDrawText( Title, x + 5, y )
  111.             for k,v in pairs(MFrame.components) do
  112.                 v.render();
  113.             end
  114.         end,
  115.  
  116.         add = function ( comp )
  117.             comp.setOfset(x, y)
  118.             table.insert(MFrame.components, comp);
  119.         end
  120.  
  121.     }
  122.  
  123.     function create()
  124.         MFrame.x = x; MFrame.y = y;
  125.         MFrame.w = w; MFrame.h = h;
  126.         MFrame.Title = Title;
  127.         MFrame.Color = Color; MFrame.TitleBarColor = TitleBarColor;
  128.         return MFrame;
  129.     end
  130.  
  131.     return create();
  132. end
  133.  
  134.  
  135. local Frame;
  136. local b1;
  137.  
  138. function renderer ( )
  139.     Frame.render();
  140.     local screenx, screeny, worldx, worldy, worldz = getCursorPosition()
  141.     local x, y = guiGetScreenSize( )
  142.     x2 = screenx * x;
  143.     y2 = screeny * y;
  144.     if ( b1.isMouseInside() ) then
  145.         ButtonColor = tocolor( 200, 76, 60, 200 )
  146.         b1.setColor(ButtonColor)
  147.     else
  148.         ButtonColor = tocolor( 231, 76, 60, 255 )
  149.         b1.setColor(ButtonColor)
  150.     end
  151. end
  152. function init()
  153.     showCursor(true)
  154.     ButtonColor = tocolor( 231, 76, 60, 255 )
  155.     textColor = tocolor( 236, 240, 241, 255 )
  156.     b1 = createButton( 10, 20, 80, 40, "Test Test", ButtonColor, textColor )
  157.  
  158.     FrameColor = tocolor( 231, 76, 60, 120 )
  159.     Frame = createFrame( 400, 400, 450, 250, "Frame", FrameColor, FrameColor );
  160.  
  161.     Frame.add(b1)
  162.     addEventHandler ( "onClientRender", root, renderer )
  163. end
  164.  
  165. addEventHandler ( "onClientResourceStart", resourceRoot, init )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement