#226 updated mouse events WIP
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user