GUI fixes; Mesh loader WIP
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
--@include label.txt
|
||||
--@include radius_mixin.txt
|
||||
--@include /koptilnya/libs/utils.txt
|
||||
|
||||
require("label.txt")
|
||||
require("/koptilnya/libs/utils.txt")
|
||||
|
||||
EButton = class("EButton", ELabel)
|
||||
EButton:include(require("radius_mixin.txt"))
|
||||
@@ -28,9 +26,6 @@ function EButton:initialize()
|
||||
})
|
||||
end
|
||||
|
||||
function EButton:onClick()
|
||||
end
|
||||
|
||||
function EButton:onMousePressed(x, y, key, keyName)
|
||||
if keyName == "MOUSE1" then
|
||||
self:onClick()
|
||||
@@ -52,3 +47,8 @@ function EButton:paint(x, y, w, h)
|
||||
render.setColor(self:getColorFromScheme("text"))
|
||||
render.drawSimpleText(x + w / 2 - textW / 2, y + h / 2 - textH / 2, self:getText())
|
||||
end
|
||||
|
||||
-- STUB
|
||||
|
||||
function EButton:onClick()
|
||||
end
|
||||
@@ -1,8 +1,6 @@
|
||||
--@include element.txt
|
||||
--@include /koptilnya/libs/utils.txt
|
||||
|
||||
require("element.txt")
|
||||
require("/koptilnya/libs/utils.txt")
|
||||
|
||||
ECheckbox = class("ECheckbox", Element)
|
||||
|
||||
@@ -47,12 +45,14 @@ end
|
||||
|
||||
function ECheckbox:paint(x, y, w, h)
|
||||
render.setColor(self:isChecked() and self:getColorFromScheme("mark") or Color(0, 0, 0, 0))
|
||||
render.drawRectFast(x, y, h, h)
|
||||
render.drawRectFast(x + 4, y + 4, w - 8, h - 8)
|
||||
|
||||
render.setColor(self:getColorFromScheme("border"))
|
||||
render.drawRectOutline(x, y, h, h, 1)
|
||||
render.drawRectOutline(x + 1, y + 1, h - 2, h - 2, 1)
|
||||
render.drawRectOutline(x, y, w, h, 1)
|
||||
render.drawRectOutline(x + 1, y + 1, w - 2, h - 2, 1)
|
||||
end
|
||||
|
||||
-- STUB
|
||||
|
||||
function ECheckbox:onChange(state)
|
||||
end
|
||||
@@ -24,7 +24,7 @@ end
|
||||
function Element:setWidth(width)
|
||||
self._width = width
|
||||
|
||||
self:performLayout(self:getSize())
|
||||
self:invalidateLayout()
|
||||
end
|
||||
|
||||
function Element:getWidth()
|
||||
@@ -34,7 +34,7 @@ end
|
||||
function Element:setHeight(height)
|
||||
self._height = height
|
||||
|
||||
self:performLayout(self:getSize())
|
||||
self:invalidateLayout()
|
||||
end
|
||||
|
||||
function Element:getHeight()
|
||||
@@ -56,7 +56,7 @@ function Element:setPos(x, y)
|
||||
end
|
||||
|
||||
function Element:getPos()
|
||||
return self._x, self._y
|
||||
return self:getX(), self:getY()
|
||||
end
|
||||
|
||||
function Element:getAbsolutePos(x, y)
|
||||
@@ -182,7 +182,7 @@ function Element:cursorIntersect(x, y)
|
||||
--local self:getAbsoluteBounds()
|
||||
local aX, aY = self:getAbsolutePos()
|
||||
|
||||
if x >= aX and x <= aX + self:getWidth() and y >= aY and y <= aY + self:getHeight() then
|
||||
if x >= aX and x < aX + self:getWidth() and y >= aY and y < aY + self:getHeight() then
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -256,10 +256,8 @@ function Element:_postEventToAllReverse(eventKey, ...)
|
||||
end
|
||||
|
||||
function Element:_onThink()
|
||||
if self:isEnabled() then
|
||||
if type(self.think) == "function" then
|
||||
self:think()
|
||||
end
|
||||
if self:isEnabled() and self:isVisible() then
|
||||
self:think()
|
||||
|
||||
if self._firstChild then
|
||||
self._firstChild:_postEventToAllReverse("THINK")
|
||||
@@ -357,6 +355,13 @@ end
|
||||
function Element:performLayout()
|
||||
end
|
||||
|
||||
function Element:invalidateLayout()
|
||||
self:performLayout(self:getSize())
|
||||
end
|
||||
|
||||
function Element:think()
|
||||
end
|
||||
|
||||
function Element:paint()
|
||||
end
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ function ELabel:getFont()
|
||||
return self._font
|
||||
end
|
||||
|
||||
function ELabel:getTextSize()
|
||||
function ELabel:getTextSize()
|
||||
return self._textWidth, self._textHeight
|
||||
end
|
||||
|
||||
|
||||
@@ -40,6 +40,15 @@ function ELabeledCheckbox:isChecked()
|
||||
return self.checkbox:isChecked()
|
||||
end
|
||||
|
||||
function ELabeledCheckbox:setEnabled(state)
|
||||
self.checkbox:setEnabled(state)
|
||||
self.label:setEnabled(state)
|
||||
end
|
||||
|
||||
function ELabeledCheckbox:isEnabled()
|
||||
return self.checkbox:isEnabled() and self.label:isEnabled()
|
||||
end
|
||||
|
||||
function ELabeledCheckbox:toggle()
|
||||
self.checkbox:toggle()
|
||||
end
|
||||
@@ -55,7 +64,7 @@ function ELabeledCheckbox:setFont(font)
|
||||
end
|
||||
|
||||
function ELabeledCheckbox:sizeToContents()
|
||||
self:performLayout(self:getSize())
|
||||
self:invalidateLayout()
|
||||
self:setWidth(self.label:getX() + self.label:getWidth())
|
||||
self:setHeight(math.max(self.checkbox:getHeight(), self.label:getHeight()))
|
||||
end
|
||||
@@ -65,5 +74,7 @@ function ELabeledCheckbox:performLayout(w, h)
|
||||
self.label:setX(self.checkbox:getWidth() + self:getIndent())
|
||||
end
|
||||
|
||||
-- STUB
|
||||
|
||||
function ELabeledCheckbox:onChange(state)
|
||||
end
|
||||
@@ -16,6 +16,7 @@ function EPanel:initialize()
|
||||
Element.initialize(self)
|
||||
|
||||
self._minimized = false
|
||||
self._lastHeight = 0
|
||||
|
||||
self.title = ELabel:new()
|
||||
self.title:setPos(12, 8)
|
||||
@@ -30,17 +31,18 @@ function EPanel:initialize()
|
||||
}
|
||||
|
||||
self.minimizeButton = EButton:new()
|
||||
self.minimizeButton:setFont(GUI.fonts["icons"])
|
||||
self.minimizeButton:setText("_")
|
||||
self.minimizeButton:setSize(32, 32)
|
||||
self.minimizeButton:setRadius(0)
|
||||
self.minimizeButton:setColorScheme(colorScheme)
|
||||
self.minimizeButton:setEnabled(false)
|
||||
self.minimizeButton.onClick = function()
|
||||
self:minimizeMaximize()
|
||||
end
|
||||
self:addChild(self.minimizeButton)
|
||||
|
||||
self.closeButton = EButton:new()
|
||||
self.closeButton:setFont(GUI.fonts["icons"])
|
||||
self.closeButton:setText("X")
|
||||
self.closeButton:setText(string.utf8char(10005))
|
||||
self.closeButton:setSize(32, 32)
|
||||
self.closeButton:setRadius(0)
|
||||
self.closeButton:setColorScheme(colorScheme)
|
||||
@@ -85,8 +87,48 @@ function EPanel:close()
|
||||
end
|
||||
|
||||
function EPanel:open()
|
||||
self:setVisible(false)
|
||||
self:setEnabled(false)
|
||||
self:setVisible(true)
|
||||
self:setEnabled(true)
|
||||
end
|
||||
|
||||
function EPanel:minimize()
|
||||
self._lastHeight = self:getHeight()
|
||||
|
||||
self.minimizeButton:setText(string.utf8char(10063))
|
||||
self:setMinimized(true)
|
||||
self:setHeight(34)
|
||||
|
||||
local child = self._firstChild
|
||||
while child do
|
||||
if child ~= self.title and child ~= self.minimizeButton and child ~= self.closeButton then
|
||||
child:setVisible(false)
|
||||
end
|
||||
|
||||
child = child._nextSibling
|
||||
end
|
||||
end
|
||||
|
||||
function EPanel:maximize()
|
||||
self.minimizeButton:setText("_")
|
||||
self:setMinimized(false)
|
||||
self:setHeight(self._lastHeight)
|
||||
|
||||
local child = self._firstChild
|
||||
while child do
|
||||
if child ~= self.title and child ~= self.minimizeButton and child ~= self.closeButton then
|
||||
child:setVisible(true)
|
||||
end
|
||||
|
||||
child = child._nextSibling
|
||||
end
|
||||
end
|
||||
|
||||
function EPanel:minimizeMaximize()
|
||||
if self:isMinimized() then
|
||||
self:maximize()
|
||||
else
|
||||
self:minimize()
|
||||
end
|
||||
end
|
||||
|
||||
function EPanel:onMousePressed(x, y, key, keyName)
|
||||
@@ -125,8 +167,8 @@ function EPanel:onMouseLeave()
|
||||
end
|
||||
|
||||
function EPanel:performLayout(w, h)
|
||||
self.closeButton:setPos(w - 33, 1)
|
||||
self.minimizeButton:setPos(w - 65, 1)
|
||||
self.closeButton:setPos(w - 33, 1)
|
||||
end
|
||||
|
||||
function EPanel:paint(x, y, w, h)
|
||||
|
||||
20
koptilnya/gui/elements/radio.txt
Normal file
20
koptilnya/gui/elements/radio.txt
Normal file
@@ -0,0 +1,20 @@
|
||||
--@include checkbox.txt
|
||||
--@include /koptilnya/libs/utils.txt
|
||||
--@include /koptilnya/libs/render.txt
|
||||
|
||||
require("checkbox.txt")
|
||||
require("/koptilnya/libs/utils.txt")
|
||||
require("/koptilnya/libs/render.txt")
|
||||
|
||||
ERadio = class("ERadio", ECheckbox)
|
||||
|
||||
function ERadio:paint(x, y, w, h)
|
||||
render.setColor(self:isChecked() and self:getColorFromScheme("mark") or Color(0, 0, 0, 0))
|
||||
render.setMaterial()
|
||||
render.drawFilledCircle(x + w / 2, y + h / 2, w / 2 - 4, 6)
|
||||
|
||||
render.setColor(self:getColorFromScheme("border"))
|
||||
render.setMaterial()
|
||||
render.drawCircle(x + w / 2, y + h / 2, w / 2)
|
||||
render.drawCircle(x + w / 2, y + h / 2, w / 2 - 1)
|
||||
end
|
||||
@@ -8,7 +8,7 @@ GUI = class("GUI")
|
||||
|
||||
GUI.static.fonts = {
|
||||
main = render.createFont("Roboto", 16, 700, true),
|
||||
icons = render.createFont("Roboto Mono", 16, 700, true)
|
||||
icons = render.createFont("Roboto Mono", 24, 400, true)
|
||||
}
|
||||
|
||||
function GUI:initialize(renderDevice)
|
||||
|
||||
Reference in New Issue
Block a user