mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
#226 updated mouse events WIP
This commit is contained in:
parent
c7edd8c487
commit
e26dc905f8
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -6,7 +6,7 @@ local core = require("graphics.core")
|
||||
|
||||
local style = {}
|
||||
|
||||
local cpair = core.graphics.cpair
|
||||
local cpair = core.cpair
|
||||
|
||||
-- GLOBAL --
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
30
graphics/graphics.lua
Normal file
30
graphics/graphics.lua
Normal 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
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -6,7 +6,7 @@ local core = require("graphics.core")
|
||||
|
||||
local style = {}
|
||||
|
||||
local cpair = core.graphics.cpair
|
||||
local cpair = core.cpair
|
||||
|
||||
-- GLOBAL --
|
||||
|
||||
|
@ -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
|
||||
|
@ -6,7 +6,7 @@ local core = require("graphics.core")
|
||||
|
||||
local style = {}
|
||||
|
||||
local cpair = core.graphics.cpair
|
||||
local cpair = core.cpair
|
||||
|
||||
-- GLOBAL --
|
||||
|
||||
|
@ -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",
|
||||
|
@ -6,7 +6,7 @@ local core = require("graphics.core")
|
||||
|
||||
local style = {}
|
||||
|
||||
local cpair = core.graphics.cpair
|
||||
local cpair = core.cpair
|
||||
|
||||
-- GLOBAL --
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user