Initial commit
This commit is contained in:
51
koptilnya/gui/elements/button.txt
Normal file
51
koptilnya/gui/elements/button.txt
Normal file
@@ -0,0 +1,51 @@
|
||||
--@include label.txt
|
||||
--@include radius_mixin.txt
|
||||
--@include ../utils.txt
|
||||
|
||||
require("label.txt")
|
||||
require("../utils.txt")
|
||||
|
||||
EButton = class("EButton", ELabel)
|
||||
EButton:include(require("radius_mixin.txt"))
|
||||
|
||||
accessorFunc(EButton, "_textColor", "TextColor", Color(230, 230, 230))
|
||||
accessorFunc(EButton, "_hoveredColor", "HoveredColor", Color(66, 66, 66))
|
||||
accessorFunc(EButton, "_hoveredTextColor", "HoveredTextColor", Color(230, 230, 230))
|
||||
accessorFunc(EButton, "_disabledColor", "DisabledColor", Color(32, 32, 32))
|
||||
accessorFunc(EButton, "_disabledTextColor", "DisabledTextColor", Color(80, 80, 80))
|
||||
|
||||
function EButton:initialize()
|
||||
ELabel.initialize(self)
|
||||
|
||||
self:setText("Button")
|
||||
self:setColor(Color(46, 46, 46))
|
||||
self:setSize(100, 32)
|
||||
self:setRoundedCorners(true)
|
||||
self:setRadius(5)
|
||||
end
|
||||
|
||||
function EButton:paint()
|
||||
local x, y = self:getAbsolutePos()
|
||||
local w, h = self:getSize()
|
||||
local textW, textH = self:getTextSize()
|
||||
local rTL, rTR, rBR, rBL = self:getRoundedCorners()
|
||||
local bgColor, textColor
|
||||
if self:isEnabled() then
|
||||
bgColor = self:isHovered() and self:getHoveredColor() or self:getColor()
|
||||
textColor = self:isHovered() and self:getHoveredTextColor() or self:getTextColor()
|
||||
else
|
||||
bgColor = self:getDisabledColor()
|
||||
textColor = self:getDisabledTextColor()
|
||||
end
|
||||
|
||||
render.setColor(bgColor)
|
||||
if self:getRadius() > 0 and (rTL or rTR or rBR or rBL) then
|
||||
render.drawRoundedBoxEx(self:getRadius(), x, y, w, h, rTL, rTR, rBL, rBR)
|
||||
else
|
||||
render.drawRectFast(x, y, w, h)
|
||||
end
|
||||
|
||||
render.setFont(self:getFont())
|
||||
render.setColor(textColor)
|
||||
render.drawSimpleText(x + w / 2 - textW / 2, y + h / 2 - textH / 2, self:getText())
|
||||
end
|
||||
Reference in New Issue
Block a user