mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
updated graphics touch events to be mouse events
This commit is contained in:
parent
4aad591d3a
commit
67872a1053
@ -171,15 +171,15 @@ end
|
||||
function renderer.ui_ready() return engine.ui_ready end
|
||||
|
||||
-- handle a touch event
|
||||
---@param event monitor_touch
|
||||
function renderer.handle_touch(event)
|
||||
---@param event mouse_interaction
|
||||
function renderer.handle_mouse(event)
|
||||
if event.monitor == engine.monitors.primary_name then
|
||||
ui.main_layout.handle_touch(event)
|
||||
ui.main_layout.handle_mouse(event)
|
||||
else
|
||||
for id, monitor in pairs(engine.monitors.unit_name_map) do
|
||||
if event.monitor == monitor then
|
||||
local layout = ui.unit_layouts[id] ---@type graphics_element
|
||||
layout.handle_touch(event)
|
||||
layout.handle_mouse(event)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -19,7 +19,7 @@ local iocontrol = require("coordinator.iocontrol")
|
||||
local renderer = require("coordinator.renderer")
|
||||
local sounder = require("coordinator.sounder")
|
||||
|
||||
local COORDINATOR_VERSION = "v0.12.3"
|
||||
local COORDINATOR_VERSION = "v0.12.4"
|
||||
|
||||
local print = util.print
|
||||
local println = util.println
|
||||
@ -354,7 +354,7 @@ local function main()
|
||||
end
|
||||
elseif event == "monitor_touch" then
|
||||
-- handle a monitor touch event
|
||||
renderer.handle_touch(core.events.touch(param1, param2, param3))
|
||||
renderer.handle_mouse(core.events.touch(param1, param2, param3))
|
||||
elseif event == "speaker_audio_empty" then
|
||||
-- handle speaker buffer emptied
|
||||
sounder.continue()
|
||||
|
@ -10,20 +10,76 @@ core.flasher = flasher
|
||||
|
||||
local events = {}
|
||||
|
||||
---@class monitor_touch
|
||||
---@enum click_type
|
||||
events.click_type = {
|
||||
VIRTUAL = 0,
|
||||
LEFT_BUTTON = 1,
|
||||
RIGHT_BUTTON = 2,
|
||||
MID_BUTTON = 3
|
||||
}
|
||||
|
||||
---@class mouse_interaction
|
||||
---@field monitor string
|
||||
---@field button integer
|
||||
---@field x integer
|
||||
---@field y integer
|
||||
|
||||
-- create a new touch event definition
|
||||
-- create a new monitor touch mouse interaction event
|
||||
---@nodiscard
|
||||
---@param monitor string
|
||||
---@param x integer
|
||||
---@param y integer
|
||||
---@return monitor_touch
|
||||
---@return mouse_interaction
|
||||
function events.touch(monitor, x, y)
|
||||
return {
|
||||
monitor = monitor,
|
||||
button = events.click_type.LEFT_BUTTON,
|
||||
x = x,
|
||||
y = y
|
||||
}
|
||||
end
|
||||
|
||||
-- create a new mouse click mouse interaction event
|
||||
---@nodiscard
|
||||
---@param button click_type
|
||||
---@param x integer
|
||||
---@param y integer
|
||||
---@return mouse_interaction
|
||||
function events.click(button, x, y)
|
||||
return {
|
||||
monitor = "terminal",
|
||||
button = button,
|
||||
x = x,
|
||||
y = y
|
||||
}
|
||||
end
|
||||
|
||||
-- create a new transposed mouse interaction event using the event's monitor/button fields
|
||||
---@nodiscard
|
||||
---@param event mouse_interaction
|
||||
---@param new_x integer
|
||||
---@param new_y integer
|
||||
---@return mouse_interaction
|
||||
function events.mouse_transposed(event, new_x, new_y)
|
||||
return {
|
||||
monitor = event.monitor,
|
||||
button = event.button,
|
||||
x = new_x,
|
||||
y = new_y
|
||||
}
|
||||
end
|
||||
|
||||
-- create a new generic mouse interaction event
|
||||
---@nodiscard
|
||||
---@param monitor string
|
||||
---@param button click_type
|
||||
---@param x integer
|
||||
---@param y integer
|
||||
---@return mouse_interaction
|
||||
function events.mouse_generic(monitor, button, x, y)
|
||||
return {
|
||||
monitor = monitor,
|
||||
button = button,
|
||||
x = x,
|
||||
y = y
|
||||
}
|
||||
|
@ -166,9 +166,9 @@ function element.new(args)
|
||||
self.bounds.y2 = self.position.y + f.h - 1
|
||||
end
|
||||
|
||||
-- handle a touch event
|
||||
---@param event table monitor_touch event
|
||||
function protected.handle_touch(event)
|
||||
-- handle a mouse event
|
||||
---@param event mouse_interaction mouse interaction event
|
||||
function protected.handle_mouse(event)
|
||||
end
|
||||
|
||||
-- handle data value changes
|
||||
@ -410,20 +410,20 @@ function element.new(args)
|
||||
|
||||
-- FUNCTION CALLBACKS --
|
||||
|
||||
-- handle a monitor touch
|
||||
---@param event monitor_touch monitor touch event
|
||||
function public.handle_touch(event)
|
||||
-- handle a monitor touch or mouse click
|
||||
---@param event mouse_interaction mouse interaction event
|
||||
function public.handle_mouse(event)
|
||||
local in_x = event.x >= self.bounds.x1 and event.x <= self.bounds.x2
|
||||
local in_y = event.y >= self.bounds.y1 and event.y <= self.bounds.y2
|
||||
|
||||
if in_x and in_y then
|
||||
local event_T = core.events.touch(event.monitor, (event.x - self.position.x) + 1, (event.y - self.position.y) + 1)
|
||||
local event_T = core.events.mouse_transposed(event, (event.x - self.position.x) + 1, (event.y - self.position.y) + 1)
|
||||
|
||||
-- handle the touch event, transformed into the window frame
|
||||
protected.handle_touch(event_T)
|
||||
protected.handle_mouse(event_T)
|
||||
|
||||
-- pass on touch event to children
|
||||
for _, val in pairs(self.children) do val.handle_touch(event_T) end
|
||||
for _, val in pairs(self.children) do val.handle_mouse(event_T) end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -140,10 +140,10 @@ local function hazard_button(args)
|
||||
end
|
||||
end
|
||||
|
||||
-- handle touch
|
||||
---@param event monitor_touch monitor touch event
|
||||
-- handle mouse interaction
|
||||
---@param event mouse_interaction mouse event
|
||||
---@diagnostic disable-next-line: unused-local
|
||||
function e.handle_touch(event)
|
||||
function e.handle_mouse(event)
|
||||
if e.enabled then
|
||||
-- change text color to indicate clicked
|
||||
e.window.setTextColor(args.accent)
|
||||
@ -178,7 +178,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_touch(core.events.touch("", 1, 1)) end
|
||||
if val then e.handle_mouse(core.events.mouse_generic("", core.events.click_type.VIRTUAL, 1, 1)) end
|
||||
end
|
||||
|
||||
-- show the button as disabled
|
||||
|
@ -92,9 +92,10 @@ local function multi_button(args)
|
||||
end
|
||||
end
|
||||
|
||||
-- handle touch
|
||||
---@param event monitor_touch monitor touch event
|
||||
function e.handle_touch(event)
|
||||
-- handle mouse interaction
|
||||
---@param event mouse_interaction mouse event
|
||||
---@diagnostic disable-next-line: unused-local
|
||||
function e.handle_mouse(event)
|
||||
-- determine what was pressed
|
||||
if e.enabled and event.y == 1 then
|
||||
for i = 1, #args.options do
|
||||
|
@ -8,7 +8,7 @@ local element = require("graphics.element")
|
||||
---@class push_button_args
|
||||
---@field text string button text
|
||||
---@field callback function function to call on touch
|
||||
---@field min_width? integer text length + 2 if omitted
|
||||
---@field min_width? integer text length if omitted
|
||||
---@field active_fg_bg? cpair foreground/background colors when pressed
|
||||
---@field dis_fg_bg? cpair foreground/background colors when disabled
|
||||
---@field parent graphics_element
|
||||
@ -47,10 +47,10 @@ local function push_button(args)
|
||||
e.window.write(args.text)
|
||||
end
|
||||
|
||||
-- handle touch
|
||||
---@param event monitor_touch monitor touch event
|
||||
-- handle mouse interaction
|
||||
---@param event mouse_interaction mouse event
|
||||
---@diagnostic disable-next-line: unused-local
|
||||
function e.handle_touch(event)
|
||||
function e.handle_mouse(event)
|
||||
if e.enabled then
|
||||
if args.active_fg_bg ~= nil then
|
||||
-- show as pressed
|
||||
@ -78,7 +78,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_touch(core.events.touch("", 1, 1)) end
|
||||
if val then e.handle_mouse(core.events.mouse_generic("", core.events.click_type.VIRTUAL, 1, 1)) end
|
||||
end
|
||||
|
||||
-- show butten as enabled
|
||||
|
@ -79,9 +79,9 @@ local function radio_button(args)
|
||||
end
|
||||
end
|
||||
|
||||
-- handle touch
|
||||
---@param event monitor_touch monitor touch event
|
||||
function e.handle_touch(event)
|
||||
-- handle mouse interaction
|
||||
---@param event mouse_interaction mouse event
|
||||
function e.handle_mouse(event)
|
||||
-- determine what was pressed
|
||||
if e.enabled then
|
||||
if args.options[event.y] ~= nil then
|
||||
|
@ -127,9 +127,9 @@ local function spinbox(args)
|
||||
-- init with the default value
|
||||
show_num()
|
||||
|
||||
-- handle touch
|
||||
---@param event monitor_touch monitor touch event
|
||||
function e.handle_touch(event)
|
||||
-- handle mouse interaction
|
||||
---@param event mouse_interaction mouse event
|
||||
function e.handle_mouse(event)
|
||||
-- only handle if on an increment or decrement arrow
|
||||
if e.enabled and event.x ~= dec_point_x then
|
||||
local idx = util.trinary(event.x > dec_point_x, event.x - 1, event.x)
|
||||
|
@ -62,10 +62,10 @@ local function switch_button(args)
|
||||
-- initial draw
|
||||
draw_state()
|
||||
|
||||
-- handle touch
|
||||
---@param event monitor_touch monitor touch event
|
||||
-- handle mouse interaction
|
||||
---@param event mouse_interaction mouse event
|
||||
---@diagnostic disable-next-line: unused-local
|
||||
function e.handle_touch(event)
|
||||
function e.handle_mouse(event)
|
||||
if e.enabled then
|
||||
-- toggle state
|
||||
e.value = not e.value
|
||||
|
@ -17,7 +17,7 @@ local plc = require("reactor-plc.plc")
|
||||
local renderer = require("reactor-plc.renderer")
|
||||
local threads = require("reactor-plc.threads")
|
||||
|
||||
local R_PLC_VERSION = "v1.1.1"
|
||||
local R_PLC_VERSION = "v1.1.2"
|
||||
|
||||
local print = util.print
|
||||
local println = util.println
|
||||
|
Loading…
Reference in New Issue
Block a user