SHARE
TWEET

Button.lua

a guest Dec 15th, 2017 9 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. require"ui/ui_base"
  2.  
  3. local Button = UIClass("Button",UI.Base)
  4. UI.Button = Button
  5.  
  6. local bg_col, hov_col, t_col, t_hov_col =
  7. Color(220,220,220,170), Color(170,220,255,220), Color(0,0,0), Color(50,50,50)
  8.  
  9. local d_col, a_col = Color(165,205,230,220), Color(255,255,255,90)
  10.  
  11. VarFunc(Button,"Text","Button")
  12. VarFunc(Button,"Font",GAME.Fonts["vollkornsc-regular_18"])
  13. VarFunc(Button,"TextColor",t_col)
  14. VarFunc(Button,"HTextColor",t_hov_col)
  15. VarFunc(Button,"Color",bg_col)
  16. VarFunc(Button,"HColor",hov_col)
  17. VarFunc(Button,"DColor",d_col)
  18.  
  19. function Button:init()
  20.    
  21. end
  22.  
  23. function Button:SetFont(str)
  24.     self.Font = GAME.Fonts[str] or GAME.Fonts["vollkornsc-regular_18"]
  25. end
  26.  
  27. local rect = love.graphics.rectangle
  28. local drawtext = love.graphics.print
  29. local setfont = love.graphics.setFont
  30. local setcolor,getcolor = love.graphics.setColor, love.graphics.getColor
  31. local align = "center"
  32. function Button:Draw(x,y,w,h)
  33.     if self.Font ~= "" then setfont(self.Font) end
  34.    
  35.     local tw,th = self.Font:getWidth(self.Text), self.Font:getHeight(self.Text)
  36.    
  37.     if self.press then
  38.         setcolor(self.DColor)
  39.         rect("fill",x,y,w,h)
  40.         setcolor(a_col)
  41.         rect("line",x,y,w,h)
  42.        
  43.         setcolor(self.HTextColor)
  44.     elseif self.hover then
  45.         setcolor(self.HColor)
  46.         rect("fill",x,y,w,h)
  47.         setcolor(a_col)
  48.         rect("line",x,y,w,h)
  49.        
  50.         setcolor(self.HTextColor)
  51.     else
  52.         setcolor(self.Color)
  53.         rect("fill",x,y,w,h)
  54.         setcolor(a_col)
  55.         rect("line",x,y,w,h)
  56.        
  57.         setcolor(self.TextColor)
  58.     end
  59.  
  60.     drawtext(self.Text,x+(w-tw)/2,y+(h-th)/2)
  61.  
  62. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top