#226 updated mouse events WIP

This commit is contained in:
Mikayla
2023-05-07 01:27:36 +00:00
parent c7edd8c487
commit e26dc905f8
29 changed files with 109 additions and 69 deletions

View File

@@ -9,8 +9,8 @@ local DataIndicator = require("graphics.elements.indicators.data")
local StateIndicator = require("graphics.elements.indicators.state") local StateIndicator = require("graphics.elements.indicators.state")
local VerticalBar = require("graphics.elements.indicators.vbar") local VerticalBar = require("graphics.elements.indicators.vbar")
local cpair = core.graphics.cpair local cpair = core.cpair
local border = core.graphics.border local border = core.border
-- new boiler view -- new boiler view
---@param root graphics_element parent ---@param root graphics_element parent

View File

@@ -13,10 +13,10 @@ local PowerIndicator = require("graphics.elements.indicators.power")
local StateIndicator = require("graphics.elements.indicators.state") local StateIndicator = require("graphics.elements.indicators.state")
local VerticalBar = require("graphics.elements.indicators.vbar") local VerticalBar = require("graphics.elements.indicators.vbar")
local cpair = core.graphics.cpair local cpair = core.cpair
local border = core.graphics.border local border = core.border
local TEXT_ALIGN = core.graphics.TEXT_ALIGN local TEXT_ALIGN = core.TEXT_ALIGN
-- new induction matrix view -- new induction matrix view
---@param root graphics_element parent ---@param root graphics_element parent

View File

@@ -21,10 +21,10 @@ local HazardButton = require("graphics.elements.controls.hazard_button")
local RadioButton = require("graphics.elements.controls.radio_button") local RadioButton = require("graphics.elements.controls.radio_button")
local SpinboxNumeric = require("graphics.elements.controls.spinbox_numeric") local SpinboxNumeric = require("graphics.elements.controls.spinbox_numeric")
local TEXT_ALIGN = core.graphics.TEXT_ALIGN local TEXT_ALIGN = core.TEXT_ALIGN
local cpair = core.graphics.cpair local cpair = core.cpair
local border = core.graphics.border local border = core.border
local period = core.flasher.PERIOD local period = core.flasher.PERIOD

View File

@@ -11,8 +11,8 @@ local DataIndicator = require("graphics.elements.indicators.data")
local HorizontalBar = require("graphics.elements.indicators.hbar") local HorizontalBar = require("graphics.elements.indicators.hbar")
local StateIndicator = require("graphics.elements.indicators.state") local StateIndicator = require("graphics.elements.indicators.state")
local cpair = core.graphics.cpair local cpair = core.cpair
local border = core.graphics.border local border = core.border
-- create new reactor view -- create new reactor view
---@param root graphics_element parent ---@param root graphics_element parent

View File

@@ -12,8 +12,8 @@ local PowerIndicator = require("graphics.elements.indicators.power")
local StateIndicator = require("graphics.elements.indicators.state") local StateIndicator = require("graphics.elements.indicators.state")
local VerticalBar = require("graphics.elements.indicators.vbar") local VerticalBar = require("graphics.elements.indicators.vbar")
local cpair = core.graphics.cpair local cpair = core.cpair
local border = core.graphics.border local border = core.border
-- new turbine view -- new turbine view
---@param root graphics_element parent ---@param root graphics_element parent

View File

@@ -26,10 +26,10 @@ local PushButton = require("graphics.elements.controls.push_button")
local RadioButton = require("graphics.elements.controls.radio_button") local RadioButton = require("graphics.elements.controls.radio_button")
local SpinboxNumeric = require("graphics.elements.controls.spinbox_numeric") local SpinboxNumeric = require("graphics.elements.controls.spinbox_numeric")
local TEXT_ALIGN = core.graphics.TEXT_ALIGN local TEXT_ALIGN = core.TEXT_ALIGN
local cpair = core.graphics.cpair local cpair = core.cpair
local border = core.graphics.border local border = core.border
local period = core.flasher.PERIOD local period = core.flasher.PERIOD

View File

@@ -14,9 +14,9 @@ local Div = require("graphics.elements.div")
local PipeNetwork = require("graphics.elements.pipenet") local PipeNetwork = require("graphics.elements.pipenet")
local TextBox = require("graphics.elements.textbox") local TextBox = require("graphics.elements.textbox")
local TEXT_ALIGN = core.graphics.TEXT_ALIGN local TEXT_ALIGN = core.TEXT_ALIGN
local pipe = core.graphics.pipe local pipe = core.pipe
-- make a new unit overview window -- make a new unit overview window
---@param parent graphics_element parent ---@param parent graphics_element parent

View File

@@ -18,9 +18,9 @@ local TextBox = require("graphics.elements.textbox")
local DataIndicator = require("graphics.elements.indicators.data") local DataIndicator = require("graphics.elements.indicators.data")
local TEXT_ALIGN = core.graphics.TEXT_ALIGN local TEXT_ALIGN = core.TEXT_ALIGN
local cpair = core.graphics.cpair local cpair = core.cpair
-- create new main view -- create new main view
---@param main graphics_element main displaybox ---@param main graphics_element main displaybox

View File

@@ -6,7 +6,7 @@ local core = require("graphics.core")
local style = {} local style = {}
local cpair = core.graphics.cpair local cpair = core.cpair
-- GLOBAL -- -- GLOBAL --

View File

@@ -1,26 +1,33 @@
-- --
-- Graphics Core Functions and Objects -- Graphics Core Types, Checks, and Constructors
-- --
local core = {} local core = {}
local flasher = require("graphics.flasher") -- Core Events
core.flasher = flasher
local events = {} local events = {}
---@enum click_type ---@enum click_button
events.click_type = { events.click_button = {
VIRTUAL = 0, VIRTUAL = 0,
LEFT_BUTTON = 1, LEFT_BUTTON = 1,
RIGHT_BUTTON = 2, RIGHT_BUTTON = 2,
MID_BUTTON = 3 MID_BUTTON = 3
} }
---@enum click_type
events.click_type = {
TAP = 0,
DOWN = 1,
DRAG = 2,
UP = 3
}
---@class mouse_interaction ---@class mouse_interaction
---@field monitor string ---@field monitor string
---@field button integer ---@field button click_button
---@field type click_type
---@field x integer ---@field x integer
---@field y integer ---@field y integer
@@ -33,7 +40,8 @@ events.click_type = {
function events.touch(monitor, x, y) function events.touch(monitor, x, y)
return { return {
monitor = monitor, monitor = monitor,
button = events.click_type.LEFT_BUTTON, button = events.click_button.LEFT_BUTTON,
type = events.click_type.TAP,
x = x, x = x,
y = y y = y
} }
@@ -41,7 +49,7 @@ end
-- create a new mouse click mouse interaction event -- create a new mouse click mouse interaction event
---@nodiscard ---@nodiscard
---@param button click_type ---@param button click_button
---@param x integer ---@param x integer
---@param y integer ---@param y integer
---@return mouse_interaction ---@return mouse_interaction
@@ -49,6 +57,7 @@ function events.click(button, x, y)
return { return {
monitor = "terminal", monitor = "terminal",
button = button, button = button,
type = events.click_type.UP,
x = x, x = x,
y = y y = y
} }
@@ -64,6 +73,7 @@ function events.mouse_transposed(event, new_x, new_y)
return { return {
monitor = event.monitor, monitor = event.monitor,
button = event.button, button = event.button,
type = event.type,
x = new_x, x = new_x,
y = new_y y = new_y
} }
@@ -72,14 +82,16 @@ end
-- create a new generic mouse interaction event -- create a new generic mouse interaction event
---@nodiscard ---@nodiscard
---@param monitor string ---@param monitor string
---@param button click_type ---@param button click_button
---@param type click_type
---@param x integer ---@param x integer
---@param y integer ---@param y integer
---@return mouse_interaction ---@return mouse_interaction
function events.mouse_generic(monitor, button, x, y) function events.mouse_generic(monitor, button, type, x, y)
return { return {
monitor = monitor, monitor = monitor,
button = button, button = button,
type = type,
x = x, x = x,
y = y y = y
} }
@@ -87,10 +99,10 @@ end
core.events = events core.events = events
local graphics = {} -- Core Types
---@enum TEXT_ALIGN ---@enum TEXT_ALIGN
graphics.TEXT_ALIGN = { core.TEXT_ALIGN = {
LEFT = 1, LEFT = 1,
CENTER = 2, CENTER = 2,
RIGHT = 3 RIGHT = 3
@@ -109,7 +121,7 @@ graphics.TEXT_ALIGN = {
---@param color color border color ---@param color color border color
---@param even? boolean whether to pad width extra to account for rectangular pixels, defaults to false ---@param even? boolean whether to pad width extra to account for rectangular pixels, defaults to false
---@return graphics_border ---@return graphics_border
function graphics.border(width, color, even) function core.border(width, color, even)
return { return {
width = width, width = width,
color = color, color = color,
@@ -130,7 +142,7 @@ end
---@param w integer ---@param w integer
---@param h integer ---@param h integer
---@return graphics_frame ---@return graphics_frame
function graphics.gframe(x, y, w, h) function core.gframe(x, y, w, h)
return { return {
x = x, x = x,
y = y, y = y,
@@ -154,7 +166,7 @@ end
---@param a color ---@param a color
---@param b color ---@param b color
---@return cpair ---@return cpair
function graphics.cpair(a, b) function core.cpair(a, b)
return { return {
-- color pairs -- color pairs
color_a = a, color_a = a,
@@ -191,7 +203,7 @@ end
---@param thin? boolean true for 1 subpixel, false (default) for 2 ---@param thin? boolean true for 1 subpixel, false (default) for 2
---@param align_tr? boolean false to align bottom left (default), true to align top right ---@param align_tr? boolean false to align bottom left (default), true to align top right
---@return pipe ---@return pipe
function graphics.pipe(x1, y1, x2, y2, color, thin, align_tr) function core.pipe(x1, y1, x2, y2, color, thin, align_tr)
return { return {
x1 = x1, x1 = x1,
y1 = y1, y1 = y1,
@@ -205,6 +217,4 @@ function graphics.pipe(x1, y1, x2, y2, color, thin, align_tr)
} }
end end
core.graphics = graphics
return core return core

View File

@@ -73,8 +73,8 @@ function element.new(args)
enabled = true, enabled = true,
value = nil, ---@type any value = nil, ---@type any
window = nil, ---@type table window = nil, ---@type table
fg_bg = core.graphics.cpair(colors.white, colors.black), fg_bg = core.cpair(colors.white, colors.black),
frame = core.graphics.gframe(1, 1, 1, 1) frame = core.gframe(1, 1, 1, 1)
} }
-- element as string -- element as string

View File

@@ -176,7 +176,7 @@ local function hazard_button(args)
-- set the value (true simulates pressing the button) -- set the value (true simulates pressing the button)
---@param val boolean new value ---@param val boolean new value
function e.set_value(val) function e.set_value(val)
if val then e.handle_mouse(core.events.mouse_generic("", core.events.click_type.VIRTUAL, 1, 1)) end if val then e.handle_mouse(core.events.mouse_generic("", core.events.click_button.VIRTUAL, core.events.click_type.UP, 1, 1)) end
end end
-- show the button as disabled -- show the button as disabled

View File

@@ -76,7 +76,7 @@ local function push_button(args)
-- set the value (true simulates pressing the button) -- set the value (true simulates pressing the button)
---@param val boolean new value ---@param val boolean new value
function e.set_value(val) function e.set_value(val)
if val then e.handle_mouse(core.events.mouse_generic("", core.events.click_type.VIRTUAL, 1, 1)) end if val then e.handle_mouse(core.events.mouse_generic("", core.events.click_button.VIRTUAL, core.events.click_type.UP, 1, 1)) end
end end
-- show butten as enabled -- show butten as enabled

View File

@@ -26,7 +26,7 @@ local function core_map(args)
args.height = 18 args.height = 18
-- inherit only foreground color -- inherit only foreground color
args.fg_bg = core.graphics.cpair(args.parent.get_fg_bg().fgd, colors.gray) args.fg_bg = core.cpair(args.parent.get_fg_bg().fgd, colors.gray)
-- create new graphics element base object -- create new graphics element base object
local e = element.new(args) local e = element.new(args)

View File

@@ -37,7 +37,7 @@ local function pipenet(args)
args.y = args.y or 1 args.y = args.y or 1
if args.bg ~= nil then if args.bg ~= nil then
args.fg_bg = core.graphics.cpair(args.bg, args.bg) args.fg_bg = core.cpair(args.bg, args.bg)
end end
-- create new graphics element base object -- create new graphics element base object
@@ -55,7 +55,7 @@ local function pipenet(args)
e.window.setCursorPos(x, y) e.window.setCursorPos(x, y)
local c = core.graphics.cpair(pipe.color, e.fg_bg.bkg) local c = core.cpair(pipe.color, e.fg_bg.bkg)
if pipe.align_tr then if pipe.align_tr then
-- cross width then height -- cross width then height

View File

@@ -5,7 +5,7 @@ local util = require("scada-common.util")
local core = require("graphics.core") local core = require("graphics.core")
local element = require("graphics.element") local element = require("graphics.element")
local TEXT_ALIGN = core.graphics.TEXT_ALIGN local TEXT_ALIGN = core.TEXT_ALIGN
---@class textbox_args ---@class textbox_args
---@field text string text to show ---@field text string text to show

30
graphics/graphics.lua Normal file
View File

@@ -0,0 +1,30 @@
local flasher = require("graphics.flasher")
local core = require("graphics.core")
local graphics = {}
graphics.flasher = flasher
-- pass mouse events to graphics engine
-- supports: mouse_click, mouse_up, mouse_drag, mouse_scroll, and monitor_touch
---@param event_type os_event
function graphics.handle_mouse(event_type)
if event_type == "mouse_click" then
elseif event_type == "mouse_up" or event_type == "monitor_touch" then
elseif event_type == "mouse_drag" then
elseif event_type == "mouse_scroll" then
end
end
-- pass char, key, or key_up event to graphics engine
---@param event_type os_event
function graphics.handle_key(event_type)
if event_type == "char" then
elseif event_type == "key" then
elseif event_type == "key_up" then
end
end
return graphics

View File

@@ -5,9 +5,9 @@ local core = require("graphics.core")
local Div = require("graphics.elements.div") local Div = require("graphics.elements.div")
local TextBox = require("graphics.elements.textbox") local TextBox = require("graphics.elements.textbox")
-- local cpair = core.graphics.cpair -- local cpair = core.cpair
local TEXT_ALIGN = core.graphics.TEXT_ALIGN local TEXT_ALIGN = core.TEXT_ALIGN
-- new boiler page view -- new boiler page view
---@param root graphics_element parent ---@param root graphics_element parent

View File

@@ -11,9 +11,9 @@ local TextBox = require("graphics.elements.textbox")
local WaitingAnim = require("graphics.elements.animations.waiting") local WaitingAnim = require("graphics.elements.animations.waiting")
local TEXT_ALIGN = core.graphics.TEXT_ALIGN local TEXT_ALIGN = core.TEXT_ALIGN
local cpair = core.graphics.cpair local cpair = core.cpair
-- create a waiting view -- create a waiting view
---@param parent graphics_element parent ---@param parent graphics_element parent

View File

@@ -5,9 +5,9 @@ local core = require("graphics.core")
local Div = require("graphics.elements.div") local Div = require("graphics.elements.div")
local TextBox = require("graphics.elements.textbox") local TextBox = require("graphics.elements.textbox")
-- local cpair = core.graphics.cpair -- local cpair = core.cpair
local TEXT_ALIGN = core.graphics.TEXT_ALIGN local TEXT_ALIGN = core.TEXT_ALIGN
-- new home page view -- new home page view
---@param root graphics_element parent ---@param root graphics_element parent

View File

@@ -5,9 +5,9 @@ local core = require("graphics.core")
local Div = require("graphics.elements.div") local Div = require("graphics.elements.div")
local TextBox = require("graphics.elements.textbox") local TextBox = require("graphics.elements.textbox")
-- local cpair = core.graphics.cpair -- local cpair = core.cpair
local TEXT_ALIGN = core.graphics.TEXT_ALIGN local TEXT_ALIGN = core.TEXT_ALIGN
-- new reactor page view -- new reactor page view
---@param root graphics_element parent ---@param root graphics_element parent

View File

@@ -5,9 +5,9 @@ local core = require("graphics.core")
local Div = require("graphics.elements.div") local Div = require("graphics.elements.div")
local TextBox = require("graphics.elements.textbox") local TextBox = require("graphics.elements.textbox")
-- local cpair = core.graphics.cpair -- local cpair = core.cpair
local TEXT_ALIGN = core.graphics.TEXT_ALIGN local TEXT_ALIGN = core.TEXT_ALIGN
-- new turbine page view -- new turbine page view
---@param root graphics_element parent ---@param root graphics_element parent

View File

@@ -5,9 +5,9 @@ local core = require("graphics.core")
local Div = require("graphics.elements.div") local Div = require("graphics.elements.div")
local TextBox = require("graphics.elements.textbox") local TextBox = require("graphics.elements.textbox")
-- local cpair = core.graphics.cpair -- local cpair = core.cpair
local TEXT_ALIGN = core.graphics.TEXT_ALIGN local TEXT_ALIGN = core.TEXT_ALIGN
-- new unit page view -- new unit page view
---@param root graphics_element parent ---@param root graphics_element parent

View File

@@ -22,9 +22,9 @@ local TextBox = require("graphics.elements.textbox")
local Sidebar = require("graphics.elements.controls.sidebar") local Sidebar = require("graphics.elements.controls.sidebar")
local TEXT_ALIGN = core.graphics.TEXT_ALIGN local TEXT_ALIGN = core.TEXT_ALIGN
local cpair = core.graphics.cpair local cpair = core.cpair
-- create new main view -- create new main view
---@param main graphics_element main displaybox ---@param main graphics_element main displaybox

View File

@@ -6,7 +6,7 @@ local core = require("graphics.core")
local style = {} local style = {}
local cpair = core.graphics.cpair local cpair = core.cpair
-- GLOBAL -- -- GLOBAL --

View File

@@ -22,10 +22,10 @@ local LED = require("graphics.elements.indicators.led")
local LEDPair = require("graphics.elements.indicators.ledpair") local LEDPair = require("graphics.elements.indicators.ledpair")
local RGBLED = require("graphics.elements.indicators.ledrgb") local RGBLED = require("graphics.elements.indicators.ledrgb")
local TEXT_ALIGN = core.graphics.TEXT_ALIGN local TEXT_ALIGN = core.TEXT_ALIGN
local cpair = core.graphics.cpair local cpair = core.cpair
local border = core.graphics.border local border = core.border
-- create new main view -- create new main view
---@param panel graphics_element main displaybox ---@param panel graphics_element main displaybox

View File

@@ -6,7 +6,7 @@ local core = require("graphics.core")
local style = {} local style = {}
local cpair = core.graphics.cpair local cpair = core.cpair
-- GLOBAL -- -- GLOBAL --

View File

@@ -16,9 +16,9 @@ local TextBox = require("graphics.elements.textbox")
local LED = require("graphics.elements.indicators.led") local LED = require("graphics.elements.indicators.led")
local RGBLED = require("graphics.elements.indicators.ledrgb") local RGBLED = require("graphics.elements.indicators.ledrgb")
local TEXT_ALIGN = core.graphics.TEXT_ALIGN local TEXT_ALIGN = core.TEXT_ALIGN
local cpair = core.graphics.cpair local cpair = core.cpair
local UNIT_TYPE_LABELS = { local UNIT_TYPE_LABELS = {
"UNKNOWN", "UNKNOWN",

View File

@@ -6,7 +6,7 @@ local core = require("graphics.core")
local style = {} local style = {}
local cpair = core.graphics.cpair local cpair = core.cpair
-- GLOBAL -- -- GLOBAL --