#226 graphics core changes for mouse events

This commit is contained in:
Mikayla Fischler
2023-05-09 20:29:07 -04:00
parent e26dc905f8
commit b8a8da1ac4
5 changed files with 188 additions and 139 deletions

View File

@@ -2,101 +2,12 @@
-- Graphics Core Types, Checks, and Constructors
--
local events = require("graphics.events")
local flasher = require("graphics.flasher")
local core = {}
-- Core Events
local events = {}
---@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 click_button
---@field type click_type
---@field x integer
---@field y integer
-- create a new monitor touch mouse interaction event
---@nodiscard
---@param monitor string
---@param x integer
---@param y integer
---@return mouse_interaction
function events.touch(monitor, x, y)
return {
monitor = monitor,
button = events.click_button.LEFT_BUTTON,
type = events.click_type.TAP,
x = x,
y = y
}
end
-- create a new mouse click mouse interaction event
---@nodiscard
---@param button click_button
---@param x integer
---@param y integer
---@return mouse_interaction
function events.click(button, x, y)
return {
monitor = "terminal",
button = button,
type = events.click_type.UP,
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,
type = event.type,
x = new_x,
y = new_y
}
end
-- create a new generic mouse interaction event
---@nodiscard
---@param monitor string
---@param button click_button
---@param type click_type
---@param x integer
---@param y integer
---@return mouse_interaction
function events.mouse_generic(monitor, button, type, x, y)
return {
monitor = monitor,
button = button,
type = type,
x = x,
y = y
}
end
core.flasher = flasher
core.events = events
-- Core Types