Initial commit
This commit is contained in:
112
koptilnya/gui/elements/panel.txt
Normal file
112
koptilnya/gui/elements/panel.txt
Normal file
@@ -0,0 +1,112 @@
|
||||
--@include element.txt
|
||||
--@include label.txt
|
||||
--@include button.txt
|
||||
--@include ../utils.txt
|
||||
|
||||
require("element.txt")
|
||||
require("label.txt")
|
||||
require("button.txt")
|
||||
require("../utils.txt")
|
||||
|
||||
EPanel = class("EPanel", Element)
|
||||
|
||||
accessorFunc(EPanel, "_backgroundColor", "BackgroundColor", Color(23, 23, 23))
|
||||
accessorFunc(EPanel, "_parentLock", "ParentLock", false)
|
||||
|
||||
function EPanel:initialize()
|
||||
Element.initialize(self)
|
||||
|
||||
self._minimized = false
|
||||
|
||||
self.title = ELabel:new()
|
||||
self.title:setPos(12, 8)
|
||||
self:addChild(self.title)
|
||||
|
||||
self.minimizeButton = EButton:new()
|
||||
self.minimizeButton:setText("_")
|
||||
self.minimizeButton:setSize(32, 32)
|
||||
self.minimizeButton:setRadius(0)
|
||||
self.minimizeButton:setColor(Color(0, 0, 0))
|
||||
self.minimizeButton:setHoveredColor(Color(25, 25, 25))
|
||||
self:addChild(self.minimizeButton)
|
||||
|
||||
self.closeButton = EButton:new()
|
||||
self.closeButton:setText("X")
|
||||
self.closeButton:setSize(32, 32)
|
||||
self.closeButton:setRadius(0)
|
||||
self.closeButton:setColor(Color(0, 0, 0))
|
||||
self.closeButton:setHoveredColor(Color(25, 25, 25))
|
||||
self:addChild(self.closeButton)
|
||||
|
||||
self:setTitle("Panel")
|
||||
end
|
||||
|
||||
function EPanel:setTitle(title)
|
||||
self.title:setText(title)
|
||||
end
|
||||
|
||||
function EPanel:getTitle()
|
||||
return self.title:getText()
|
||||
end
|
||||
|
||||
function EPanel:setMinimized(state)
|
||||
self._minimized = state
|
||||
end
|
||||
|
||||
function EPanel:isMinimized()
|
||||
return self._minimized
|
||||
end
|
||||
|
||||
function EPanel:onMousePressed(x, y, key, keyName)
|
||||
if keyName == "MOUSE1" then
|
||||
local aX, aY = self:getAbsolutePos()
|
||||
|
||||
if self:isDraggable() and y < aY + 33 then
|
||||
self._dragStartPos = {x - self:getX(), y - self:getY()}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function EPanel:onMouseReleased(x, y, key, keyName)
|
||||
if keyName == "MOUSE1" then
|
||||
if self:isDraggable() then
|
||||
self._dragStartPos = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function EPanel:onMouseMoved(x, y)
|
||||
if self._dragStartPos then
|
||||
local targetX, targetY = x - self._dragStartPos[1], y - self._dragStartPos[2]
|
||||
|
||||
if self:hasParent() and self:getParentLock() then
|
||||
targetX = math.clamp(targetX, 0, 1920 - self:getWidth())
|
||||
targetY = math.clamp(targetY, 0, 1080 - self:getHeight())
|
||||
end
|
||||
|
||||
self:setPos(targetX, targetY)
|
||||
end
|
||||
end
|
||||
|
||||
function EPanel:onMouseLeave()
|
||||
self._dragStartPos = nil
|
||||
end
|
||||
|
||||
function EPanel:performLayout(w, h)
|
||||
self.closeButton:setPos(w - 33, 1)
|
||||
self.minimizeButton:setPos(w - 65, 1)
|
||||
end
|
||||
|
||||
function EPanel:paint()
|
||||
local x, y = self:getAbsolutePos()
|
||||
local w, h = self:getSize()
|
||||
|
||||
render.setColor(Color(255, 255, 255, 10))
|
||||
render.drawRectFast(x, y, w, h)
|
||||
|
||||
render.setColor(Color(0, 0, 0))
|
||||
render.drawRectFast(x + 1, y + 1, w - 2, 32)
|
||||
|
||||
render.setColor(self:getBackgroundColor())
|
||||
render.drawRectFast(x + 1, y + 33, w - 2, h - 34)
|
||||
end
|
||||
Reference in New Issue
Block a user