74 lines
1.9 KiB
Lua
74 lines
1.9 KiB
Lua
require "common.globals"
|
|
require "common.class"
|
|
|
|
local PageView = require "api.page.pageview"
|
|
|
|
---@class Screen
|
|
---@field pageview PageView
|
|
local Screen = {
|
|
__tostring = function() return "Screen" end
|
|
}
|
|
|
|
---Create a new Screen instance
|
|
---@param o? Screen
|
|
---@return Screen
|
|
function Screen.new(o)
|
|
local self = CreateInstance(Screen, o)
|
|
self.pageview = PageView.new()
|
|
return self
|
|
end
|
|
|
|
---Initialize screen, override to push new page into pageview
|
|
function Screen:init()
|
|
|
|
end
|
|
|
|
---@param button integer # options are under the `game` table prefixed with `BUTTON`
|
|
function Screen:handleButtonInput(button)
|
|
if self.pageview:get() then
|
|
self.pageview:get():handleButtonInput(button)
|
|
end
|
|
end
|
|
|
|
---@param knob integer # `0` = Left, `1` = Right
|
|
---@param delta number # in radians, `-2*pi` to `0` (turning CCW) and `0` to `2*pi` (turning CW)
|
|
function Screen:handleKnobInput(knob, delta)
|
|
if self.pageview:get() then
|
|
self.pageview:get():handleKnobInput(knob, delta)
|
|
end
|
|
end
|
|
|
|
---@param x number
|
|
---@param y number
|
|
---@param button integer # `0` = Left, `1` = Right, `2` = Middle
|
|
function Screen:handleMouseInput(x, y, button)
|
|
if self.pageview:get() then
|
|
self.pageview:get():handleMouseInput(x, y, button)
|
|
end
|
|
end
|
|
|
|
---@class ScreenCallbackObject
|
|
---@field reason string # short string representation what the cb object is about
|
|
---@field hint any # hint object to help continue code flow in parent
|
|
|
|
---Event callback when screen gets deactivated (eg.: pageview is empty)
|
|
---@param obj ScreenCallbackObject
|
|
function Screen.onDeactivation(obj)
|
|
|
|
end
|
|
|
|
function Screen:deactivate()
|
|
self.onDeactivation({reason = "deactivation"})
|
|
end
|
|
|
|
---@param deltaTime number # frametime in seconds
|
|
function Screen:render(deltaTime)
|
|
if not self.pageview:get() then
|
|
self:deactivate()
|
|
end
|
|
|
|
self.pageview:render(deltaTime)
|
|
end
|
|
|
|
return Screen
|