63 lines
2.2 KiB
Lua
63 lines
2.2 KiB
Lua
local Rect = require "lib.simple_ui.rect"
|
||
|
||
--- @class UIElement
|
||
--- @field bounds Rect Прямоугольник, в границах которого размещается элемент. Размеры и положение в *локальных* координатах
|
||
--- @field transform love.Transform Преобразование из локальных координат элемента (bounds) в экранные координаты
|
||
local uiElement = {}
|
||
uiElement.__index = uiElement
|
||
|
||
function uiElement:update(dt) end
|
||
|
||
function uiElement:draw() end
|
||
|
||
function uiElement:hitTest(screenX, screenY)
|
||
return self.bounds:hasPoint(screenX, screenY)
|
||
end
|
||
|
||
--- @generic T : UIElement
|
||
--- @param values table
|
||
--- @param self T
|
||
--- @return T
|
||
function uiElement.new(self, values)
|
||
values.bounds = values.bounds or Rect {}
|
||
return setmetatable(values, self)
|
||
end
|
||
|
||
--- Рисует границу вокруг элемента (с псевдо-затенением)
|
||
--- @param type "outer" | "inner"
|
||
function uiElement:drawBorder(type)
|
||
if type == "inner" then
|
||
love.graphics.setColor(0.2, 0.2, 0.2)
|
||
love.graphics.line({
|
||
self.bounds.x, self.bounds.y + self.bounds.height,
|
||
self.bounds.x, self.bounds.y,
|
||
self.bounds.x + self.bounds.width, self.bounds.y,
|
||
})
|
||
|
||
love.graphics.setColor(0.3, 0.3, 0.3)
|
||
love.graphics.line({
|
||
self.bounds.x + self.bounds.width, self.bounds.y,
|
||
self.bounds.x + self.bounds.width, self.bounds.y + self.bounds.height,
|
||
self.bounds.x, self.bounds.y + self.bounds.height,
|
||
})
|
||
else
|
||
love.graphics.setColor(0.2, 0.2, 0.2)
|
||
love.graphics.line({
|
||
self.bounds.x + self.bounds.width, self.bounds.y,
|
||
self.bounds.x + self.bounds.width, self.bounds.y + self.bounds.height,
|
||
self.bounds.x, self.bounds.y + self.bounds.height,
|
||
})
|
||
|
||
love.graphics.setColor(0.3, 0.3, 0.3)
|
||
love.graphics.line({
|
||
self.bounds.x, self.bounds.y + self.bounds.height,
|
||
self.bounds.x, self.bounds.y,
|
||
self.bounds.x + self.bounds.width, self.bounds.y,
|
||
})
|
||
end
|
||
|
||
love.graphics.setColor(1, 1, 1)
|
||
end
|
||
|
||
return uiElement
|