parent
8440be2ab1
commit
e47799650a
@ -0,0 +1,43 @@ |
||||
GUI = Object:extend() |
||||
|
||||
function GUI:new() end |
||||
|
||||
function GUI:newButton(x, y, w, h, text, selected) |
||||
love.graphics.setColor(255, 255, 255) -- reset colours |
||||
|
||||
--x,y is the top left corner of the button |
||||
local rounding = 30 -- used for rounding the buttons |
||||
local xoff = x + 10 |
||||
local yoff = y - 10 |
||||
local textX, textY = 0, 0 |
||||
-- Get width and height of text |
||||
local tw = MenuFont:getWidth(text) |
||||
local th = MenuFont:getHeight(text) |
||||
love.graphics.setFont(MenuFont) |
||||
|
||||
if not selected then |
||||
love.graphics.setColor(love.math.colorFromBytes(41, 134, 204)) |
||||
love.graphics.rectangle("fill", x, y, w, h, rounding, rounding) |
||||
|
||||
-- Calculate position to center the text |
||||
textX = x + (w - tw) / 2 |
||||
textY = y + (h - th) / 2 |
||||
-- Place text inside the rectangle |
||||
love.graphics.setColor(0, 0, 0) |
||||
love.graphics.print(text, textX, textY) |
||||
elseif selected then |
||||
-- If selected, raise the button and draw a shadow |
||||
love.graphics.setColor(love.math.colorFromBytes(0, 0, 0)) |
||||
love.graphics.rectangle("fill", x, y, w, h, rounding, rounding) -- shadow |
||||
|
||||
love.graphics.setColor(love.math.colorFromBytes(244, 67, 54)) |
||||
love.graphics.rectangle("fill", xoff, yoff, w, h, rounding, rounding) -- button offset |
||||
|
||||
-- Calculate position to center the text |
||||
textX = xoff + (w - tw) / 2 |
||||
textY = yoff + (h - th) / 2 |
||||
-- Place text inside the rectangle |
||||
love.graphics.setColor(1, 1, 1) |
||||
love.graphics.print(text, textX, textY) |
||||
end |
||||
end |
Loading…
Reference in new issue