ExperimentalGear/scripts/components/pager/field.lua

109 lines
2.5 KiB
Lua

require("common.class")
---@class Field
---@field parent Page|ContainerField
---@field posX number
---@field posY number
---@field offX number
---@field offY number
---@field aabbW number
---@field aabbH number
local Field = {
__tostring = function() return "Field" end,
---@type nil|fun(button: integer): boolean
---returns true if further button input processing should be stopped, otherwise false
handleButtonInput = nil,
---@type nil|fun(knob: integer, delta: number): boolean
---returns true if further button input processing should be stopped, otherwise false
handleKnobInput = nil,
}
---Create a new Field instance
---@param o table
---@return Field
function Field:new(o)
o = o or {}
--set instance members
o.parent = o.parent or nil
o.posX = o.posX or 0
o.posY = o.posY or 0
o.offX = o.offX or 0
o.offY = o.offY or 0
o.aabbW = o.aabbW or 0
o.aabbH = o.aabbH or 0
return Base(self, o)
end
---Initialize members that need further actions after construction
---@return Field
function Field:init()
return self
end
---Get the containing top-level parent page
---@return ContainerField|Page
function Field:getParentPage()
if self.parent and self.parent.getParentPage then
return self.parent:getParentPage()
else
return self.parent
end
end
function Field:activate() end
function Field:focus() end
function Field:deactivate() end
function Field:drawContent(deltaTime)
gfx.ResetScissor()
local offX = -50
local offY = -50
local aabbW = 100
local aabbH = 100
gfx.BeginPath()
gfx.FillColor(255, 0, 128, 192)
gfx.StrokeColor(0, 0, 0)
gfx.StrokeWidth(2)
gfx.Rect(offX, offY, aabbW, aabbH)
gfx.Fill()
gfx.Stroke()
gfx.BeginPath()
gfx.MoveTo(offX, 0)
gfx.LineTo(offX + aabbW, 0)
gfx.MoveTo(0, offY)
gfx.LineTo(0, offY + aabbH)
gfx.StrokeColor(0, 0, 0, 64)
gfx.StrokeWidth(2)
gfx.Stroke()
local fontSize = 18
local fontMargin = 4
gfx.BeginPath()
gfx.FontSize(fontSize)
gfx.LoadSkinFont("dfmarugoth.ttf")
gfx.FillColor(0, 0, 0)
gfx.TextAlign(gfx.TEXT_ALIGN_CENTER | gfx.TEXT_ALIGN_MIDDLE)
gfx.Text("TEXTURE", 0, -fontSize / 2 - fontMargin)
gfx.Text("MISSING", 0, fontSize / 2 + fontMargin)
end
function Field:render(deltaTime)
gfx.Save()
gfx.Translate(self.posX, self.posY)
gfx.Scissor(self.offX, self.offY, self.aabbW, self.aabbH)
self:drawContent(deltaTime)
gfx.Restore()
end
return Field