From e26dc905f828bb63755ad535e80562b75de2a336 Mon Sep 17 00:00:00 2001 From: Mikayla Date: Sun, 7 May 2023 01:27:36 +0000 Subject: [PATCH] #226 updated mouse events WIP --- coordinator/ui/components/boiler.lua | 4 +- coordinator/ui/components/imatrix.lua | 6 +-- coordinator/ui/components/processctl.lua | 6 +-- coordinator/ui/components/reactor.lua | 4 +- coordinator/ui/components/turbine.lua | 4 +- coordinator/ui/components/unit_detail.lua | 6 +-- coordinator/ui/components/unit_overview.lua | 4 +- coordinator/ui/layout/main_view.lua | 4 +- coordinator/ui/style.lua | 2 +- graphics/core.lua | 48 ++++++++++++-------- graphics/element.lua | 4 +- graphics/elements/controls/hazard_button.lua | 2 +- graphics/elements/controls/push_button.lua | 2 +- graphics/elements/indicators/coremap.lua | 2 +- graphics/elements/pipenet.lua | 4 +- graphics/elements/textbox.lua | 2 +- graphics/graphics.lua | 30 ++++++++++++ pocket/ui/components/boiler_page.lua | 4 +- pocket/ui/components/conn_waiting.lua | 4 +- pocket/ui/components/home_page.lua | 4 +- pocket/ui/components/reactor_page.lua | 4 +- pocket/ui/components/turbine_page.lua | 4 +- pocket/ui/components/unit_page.lua | 4 +- pocket/ui/main.lua | 4 +- pocket/ui/style.lua | 2 +- reactor-plc/panel/front_panel.lua | 6 +-- reactor-plc/panel/style.lua | 2 +- rtu/panel/front_panel.lua | 4 +- rtu/panel/style.lua | 2 +- 29 files changed, 109 insertions(+), 69 deletions(-) create mode 100644 graphics/graphics.lua diff --git a/coordinator/ui/components/boiler.lua b/coordinator/ui/components/boiler.lua index c4a433b..9ed497c 100644 --- a/coordinator/ui/components/boiler.lua +++ b/coordinator/ui/components/boiler.lua @@ -9,8 +9,8 @@ local DataIndicator = require("graphics.elements.indicators.data") local StateIndicator = require("graphics.elements.indicators.state") local VerticalBar = require("graphics.elements.indicators.vbar") -local cpair = core.graphics.cpair -local border = core.graphics.border +local cpair = core.cpair +local border = core.border -- new boiler view ---@param root graphics_element parent diff --git a/coordinator/ui/components/imatrix.lua b/coordinator/ui/components/imatrix.lua index 2910fbb..c94ff9f 100644 --- a/coordinator/ui/components/imatrix.lua +++ b/coordinator/ui/components/imatrix.lua @@ -13,10 +13,10 @@ local PowerIndicator = require("graphics.elements.indicators.power") local StateIndicator = require("graphics.elements.indicators.state") local VerticalBar = require("graphics.elements.indicators.vbar") -local cpair = core.graphics.cpair -local border = core.graphics.border +local cpair = core.cpair +local border = core.border -local TEXT_ALIGN = core.graphics.TEXT_ALIGN +local TEXT_ALIGN = core.TEXT_ALIGN -- new induction matrix view ---@param root graphics_element parent diff --git a/coordinator/ui/components/processctl.lua b/coordinator/ui/components/processctl.lua index 5b8d8ae..8719968 100644 --- a/coordinator/ui/components/processctl.lua +++ b/coordinator/ui/components/processctl.lua @@ -21,10 +21,10 @@ local HazardButton = require("graphics.elements.controls.hazard_button") local RadioButton = require("graphics.elements.controls.radio_button") 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 border = core.graphics.border +local cpair = core.cpair +local border = core.border local period = core.flasher.PERIOD diff --git a/coordinator/ui/components/reactor.lua b/coordinator/ui/components/reactor.lua index db75fb1..578bbba 100644 --- a/coordinator/ui/components/reactor.lua +++ b/coordinator/ui/components/reactor.lua @@ -11,8 +11,8 @@ local DataIndicator = require("graphics.elements.indicators.data") local HorizontalBar = require("graphics.elements.indicators.hbar") local StateIndicator = require("graphics.elements.indicators.state") -local cpair = core.graphics.cpair -local border = core.graphics.border +local cpair = core.cpair +local border = core.border -- create new reactor view ---@param root graphics_element parent diff --git a/coordinator/ui/components/turbine.lua b/coordinator/ui/components/turbine.lua index e4d6967..3bfd731 100644 --- a/coordinator/ui/components/turbine.lua +++ b/coordinator/ui/components/turbine.lua @@ -12,8 +12,8 @@ local PowerIndicator = require("graphics.elements.indicators.power") local StateIndicator = require("graphics.elements.indicators.state") local VerticalBar = require("graphics.elements.indicators.vbar") -local cpair = core.graphics.cpair -local border = core.graphics.border +local cpair = core.cpair +local border = core.border -- new turbine view ---@param root graphics_element parent diff --git a/coordinator/ui/components/unit_detail.lua b/coordinator/ui/components/unit_detail.lua index a29dd4b..7181430 100644 --- a/coordinator/ui/components/unit_detail.lua +++ b/coordinator/ui/components/unit_detail.lua @@ -26,10 +26,10 @@ local PushButton = require("graphics.elements.controls.push_button") local RadioButton = require("graphics.elements.controls.radio_button") 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 border = core.graphics.border +local cpair = core.cpair +local border = core.border local period = core.flasher.PERIOD diff --git a/coordinator/ui/components/unit_overview.lua b/coordinator/ui/components/unit_overview.lua index 24bc02e..bd341bf 100644 --- a/coordinator/ui/components/unit_overview.lua +++ b/coordinator/ui/components/unit_overview.lua @@ -14,9 +14,9 @@ local Div = require("graphics.elements.div") local PipeNetwork = require("graphics.elements.pipenet") 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 ---@param parent graphics_element parent diff --git a/coordinator/ui/layout/main_view.lua b/coordinator/ui/layout/main_view.lua index a7f8ae2..5510382 100644 --- a/coordinator/ui/layout/main_view.lua +++ b/coordinator/ui/layout/main_view.lua @@ -18,9 +18,9 @@ local TextBox = require("graphics.elements.textbox") 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 ---@param main graphics_element main displaybox diff --git a/coordinator/ui/style.lua b/coordinator/ui/style.lua index 74923f2..b78fc91 100644 --- a/coordinator/ui/style.lua +++ b/coordinator/ui/style.lua @@ -6,7 +6,7 @@ local core = require("graphics.core") local style = {} -local cpair = core.graphics.cpair +local cpair = core.cpair -- GLOBAL -- diff --git a/graphics/core.lua b/graphics/core.lua index d03e551..1ef315f 100644 --- a/graphics/core.lua +++ b/graphics/core.lua @@ -1,26 +1,33 @@ -- --- Graphics Core Functions and Objects +-- Graphics Core Types, Checks, and Constructors -- local core = {} -local flasher = require("graphics.flasher") - -core.flasher = flasher +-- Core Events local events = {} ----@enum click_type -events.click_type = { +---@enum click_button +events.click_button = { VIRTUAL = 0, LEFT_BUTTON = 1, RIGHT_BUTTON = 2, MID_BUTTON = 3 } +---@enum click_type +events.click_type = { + TAP = 0, + DOWN = 1, + DRAG = 2, + UP = 3 +} + ---@class mouse_interaction ---@field monitor string ----@field button integer +---@field button click_button +---@field type click_type ---@field x integer ---@field y integer @@ -33,7 +40,8 @@ events.click_type = { function events.touch(monitor, x, y) return { monitor = monitor, - button = events.click_type.LEFT_BUTTON, + button = events.click_button.LEFT_BUTTON, + type = events.click_type.TAP, x = x, y = y } @@ -41,7 +49,7 @@ end -- create a new mouse click mouse interaction event ---@nodiscard ----@param button click_type +---@param button click_button ---@param x integer ---@param y integer ---@return mouse_interaction @@ -49,6 +57,7 @@ function events.click(button, x, y) return { monitor = "terminal", button = button, + type = events.click_type.UP, x = x, y = y } @@ -64,6 +73,7 @@ function events.mouse_transposed(event, new_x, new_y) return { monitor = event.monitor, button = event.button, + type = event.type, x = new_x, y = new_y } @@ -72,14 +82,16 @@ end -- create a new generic mouse interaction event ---@nodiscard ---@param monitor string ----@param button click_type +---@param button click_button +---@param type click_type ---@param x integer ---@param y integer ---@return mouse_interaction -function events.mouse_generic(monitor, button, x, y) +function events.mouse_generic(monitor, button, type, x, y) return { monitor = monitor, button = button, + type = type, x = x, y = y } @@ -87,10 +99,10 @@ end core.events = events -local graphics = {} +-- Core Types ---@enum TEXT_ALIGN -graphics.TEXT_ALIGN = { +core.TEXT_ALIGN = { LEFT = 1, CENTER = 2, RIGHT = 3 @@ -109,7 +121,7 @@ graphics.TEXT_ALIGN = { ---@param color color border color ---@param even? boolean whether to pad width extra to account for rectangular pixels, defaults to false ---@return graphics_border -function graphics.border(width, color, even) +function core.border(width, color, even) return { width = width, color = color, @@ -130,7 +142,7 @@ end ---@param w integer ---@param h integer ---@return graphics_frame -function graphics.gframe(x, y, w, h) +function core.gframe(x, y, w, h) return { x = x, y = y, @@ -154,7 +166,7 @@ end ---@param a color ---@param b color ---@return cpair -function graphics.cpair(a, b) +function core.cpair(a, b) return { -- color pairs color_a = a, @@ -191,7 +203,7 @@ end ---@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 ---@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 { x1 = x1, y1 = y1, @@ -205,6 +217,4 @@ function graphics.pipe(x1, y1, x2, y2, color, thin, align_tr) } end -core.graphics = graphics - return core diff --git a/graphics/element.lua b/graphics/element.lua index 04d4fd2..13baec3 100644 --- a/graphics/element.lua +++ b/graphics/element.lua @@ -73,8 +73,8 @@ function element.new(args) enabled = true, value = nil, ---@type any window = nil, ---@type table - fg_bg = core.graphics.cpair(colors.white, colors.black), - frame = core.graphics.gframe(1, 1, 1, 1) + fg_bg = core.cpair(colors.white, colors.black), + frame = core.gframe(1, 1, 1, 1) } -- element as string diff --git a/graphics/elements/controls/hazard_button.lua b/graphics/elements/controls/hazard_button.lua index 2b9baa6..d8e2d6d 100644 --- a/graphics/elements/controls/hazard_button.lua +++ b/graphics/elements/controls/hazard_button.lua @@ -176,7 +176,7 @@ local function hazard_button(args) -- set the value (true simulates pressing the button) ---@param val boolean new value 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 -- show the button as disabled diff --git a/graphics/elements/controls/push_button.lua b/graphics/elements/controls/push_button.lua index 9b5f971..79cde7f 100644 --- a/graphics/elements/controls/push_button.lua +++ b/graphics/elements/controls/push_button.lua @@ -76,7 +76,7 @@ local function push_button(args) -- set the value (true simulates pressing the button) ---@param val boolean new value 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 -- show butten as enabled diff --git a/graphics/elements/indicators/coremap.lua b/graphics/elements/indicators/coremap.lua index 323e17c..05434a3 100644 --- a/graphics/elements/indicators/coremap.lua +++ b/graphics/elements/indicators/coremap.lua @@ -26,7 +26,7 @@ local function core_map(args) args.height = 18 -- 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 local e = element.new(args) diff --git a/graphics/elements/pipenet.lua b/graphics/elements/pipenet.lua index 71ee9fd..8a1d29b 100644 --- a/graphics/elements/pipenet.lua +++ b/graphics/elements/pipenet.lua @@ -37,7 +37,7 @@ local function pipenet(args) args.y = args.y or 1 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 -- create new graphics element base object @@ -55,7 +55,7 @@ local function pipenet(args) 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 -- cross width then height diff --git a/graphics/elements/textbox.lua b/graphics/elements/textbox.lua index c911677..9066deb 100644 --- a/graphics/elements/textbox.lua +++ b/graphics/elements/textbox.lua @@ -5,7 +5,7 @@ local util = require("scada-common.util") local core = require("graphics.core") local element = require("graphics.element") -local TEXT_ALIGN = core.graphics.TEXT_ALIGN +local TEXT_ALIGN = core.TEXT_ALIGN ---@class textbox_args ---@field text string text to show diff --git a/graphics/graphics.lua b/graphics/graphics.lua new file mode 100644 index 0000000..11b04ff --- /dev/null +++ b/graphics/graphics.lua @@ -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 diff --git a/pocket/ui/components/boiler_page.lua b/pocket/ui/components/boiler_page.lua index fd0eca1..ec13d59 100644 --- a/pocket/ui/components/boiler_page.lua +++ b/pocket/ui/components/boiler_page.lua @@ -5,9 +5,9 @@ local core = require("graphics.core") local Div = require("graphics.elements.div") 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 ---@param root graphics_element parent diff --git a/pocket/ui/components/conn_waiting.lua b/pocket/ui/components/conn_waiting.lua index cd08652..9bbbfc0 100644 --- a/pocket/ui/components/conn_waiting.lua +++ b/pocket/ui/components/conn_waiting.lua @@ -11,9 +11,9 @@ local TextBox = require("graphics.elements.textbox") 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 ---@param parent graphics_element parent diff --git a/pocket/ui/components/home_page.lua b/pocket/ui/components/home_page.lua index 5287cac..a31cae8 100644 --- a/pocket/ui/components/home_page.lua +++ b/pocket/ui/components/home_page.lua @@ -5,9 +5,9 @@ local core = require("graphics.core") local Div = require("graphics.elements.div") 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 ---@param root graphics_element parent diff --git a/pocket/ui/components/reactor_page.lua b/pocket/ui/components/reactor_page.lua index 50b1939..c7a2e96 100644 --- a/pocket/ui/components/reactor_page.lua +++ b/pocket/ui/components/reactor_page.lua @@ -5,9 +5,9 @@ local core = require("graphics.core") local Div = require("graphics.elements.div") 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 ---@param root graphics_element parent diff --git a/pocket/ui/components/turbine_page.lua b/pocket/ui/components/turbine_page.lua index 9fd7af5..527e419 100644 --- a/pocket/ui/components/turbine_page.lua +++ b/pocket/ui/components/turbine_page.lua @@ -5,9 +5,9 @@ local core = require("graphics.core") local Div = require("graphics.elements.div") 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 ---@param root graphics_element parent diff --git a/pocket/ui/components/unit_page.lua b/pocket/ui/components/unit_page.lua index 2e24df3..a0718e6 100644 --- a/pocket/ui/components/unit_page.lua +++ b/pocket/ui/components/unit_page.lua @@ -5,9 +5,9 @@ local core = require("graphics.core") local Div = require("graphics.elements.div") 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 ---@param root graphics_element parent diff --git a/pocket/ui/main.lua b/pocket/ui/main.lua index 5af9ce8..1b7be88 100644 --- a/pocket/ui/main.lua +++ b/pocket/ui/main.lua @@ -22,9 +22,9 @@ local TextBox = require("graphics.elements.textbox") 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 ---@param main graphics_element main displaybox diff --git a/pocket/ui/style.lua b/pocket/ui/style.lua index b9a09fc..2fb7526 100644 --- a/pocket/ui/style.lua +++ b/pocket/ui/style.lua @@ -6,7 +6,7 @@ local core = require("graphics.core") local style = {} -local cpair = core.graphics.cpair +local cpair = core.cpair -- GLOBAL -- diff --git a/reactor-plc/panel/front_panel.lua b/reactor-plc/panel/front_panel.lua index 70c80ef..c000a3d 100644 --- a/reactor-plc/panel/front_panel.lua +++ b/reactor-plc/panel/front_panel.lua @@ -22,10 +22,10 @@ local LED = require("graphics.elements.indicators.led") local LEDPair = require("graphics.elements.indicators.ledpair") 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 border = core.graphics.border +local cpair = core.cpair +local border = core.border -- create new main view ---@param panel graphics_element main displaybox diff --git a/reactor-plc/panel/style.lua b/reactor-plc/panel/style.lua index 31039d4..996453c 100644 --- a/reactor-plc/panel/style.lua +++ b/reactor-plc/panel/style.lua @@ -6,7 +6,7 @@ local core = require("graphics.core") local style = {} -local cpair = core.graphics.cpair +local cpair = core.cpair -- GLOBAL -- diff --git a/rtu/panel/front_panel.lua b/rtu/panel/front_panel.lua index f6014da..8dcaa1f 100644 --- a/rtu/panel/front_panel.lua +++ b/rtu/panel/front_panel.lua @@ -16,9 +16,9 @@ local TextBox = require("graphics.elements.textbox") local LED = require("graphics.elements.indicators.led") 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 = { "UNKNOWN", diff --git a/rtu/panel/style.lua b/rtu/panel/style.lua index 31039d4..996453c 100644 --- a/rtu/panel/style.lua +++ b/rtu/panel/style.lua @@ -6,7 +6,7 @@ local core = require("graphics.core") local style = {} -local cpair = core.graphics.cpair +local cpair = core.cpair -- GLOBAL --