2024-07-30 17:10:48 +01:00
|
|
|
structure InputCallbacks =
|
|
|
|
|
struct
|
|
|
|
|
open CML
|
2024-07-30 19:04:36 +01:00
|
|
|
open InputMessage
|
2024-07-30 17:10:48 +01:00
|
|
|
|
|
|
|
|
fun mouseMoveCallback mailbox (x, y) =
|
|
|
|
|
Mailbox.send (mailbox, (MOUSE_MOVE {x = x, y = y}))
|
|
|
|
|
|
|
|
|
|
fun mouseClickCallback mailbox (button, action) =
|
|
|
|
|
if button = Input.LEFT_MOUSE_BUTTON () then
|
2024-08-08 06:34:40 +01:00
|
|
|
if action = Input.PRESS () then Mailbox.send (mailbox, MOUSE_LEFT_CLICK)
|
|
|
|
|
else Mailbox.send (mailbox, MOUSE_LEFT_RELEASE)
|
2024-07-30 17:10:48 +01:00
|
|
|
else
|
|
|
|
|
()
|
2024-07-31 12:00:07 +01:00
|
|
|
|
2024-08-01 23:33:54 +01:00
|
|
|
fun framebufferSizeCallback mailbox (width, height) =
|
|
|
|
|
let val _ = Gles3.viewport (width, height)
|
|
|
|
|
in Mailbox.send (mailbox, RESIZE_WINDOW {width = width, height = height})
|
|
|
|
|
end
|
|
|
|
|
|
2024-08-08 06:34:40 +01:00
|
|
|
fun keyActionCallback mailbox (key, scancode, action, mods) =
|
|
|
|
|
if
|
|
|
|
|
key = Input.KEY_Z () andalso action <> Input.RELEASE ()
|
2024-08-08 23:52:49 +01:00
|
|
|
then
|
|
|
|
|
if mods = 0x0002 then
|
|
|
|
|
(* ctrl-z *)
|
|
|
|
|
Mailbox.send (mailbox, UNDO_ACTION)
|
|
|
|
|
else if mods = 0x0003 then
|
|
|
|
|
(* ctrl-shift-z *)
|
|
|
|
|
Mailbox.send (mailbox, REDO_ACTION)
|
|
|
|
|
else
|
|
|
|
|
(* no action recognised *)
|
|
|
|
|
()
|
|
|
|
|
else if
|
2024-08-29 00:05:30 +01:00
|
|
|
(* ctrl-y *)
|
2024-08-08 23:52:49 +01:00
|
|
|
key = Input.KEY_Y () andalso action <> Input.RELEASE ()
|
2024-08-08 06:34:40 +01:00
|
|
|
andalso mods = 0x0002
|
2024-08-08 23:52:49 +01:00
|
|
|
then
|
|
|
|
|
Mailbox.send (mailbox, REDO_ACTION)
|
2024-12-30 03:41:11 +00:00
|
|
|
else if
|
|
|
|
|
key = Input.KEY_R () andalso action <> Input.RELEASE () andalso mods = 0x0
|
|
|
|
|
then
|
|
|
|
|
Mailbox.send (mailbox, KEY_R)
|
2024-08-14 02:31:28 +01:00
|
|
|
else if
|
|
|
|
|
key = Input.KEY_G () andalso action <> Input.RELEASE () andalso mods = 0x0
|
|
|
|
|
then
|
|
|
|
|
Mailbox.send (mailbox, KEY_G)
|
2024-12-30 03:41:11 +00:00
|
|
|
else if
|
|
|
|
|
key = Input.KEY_B () andalso action <> Input.RELEASE () andalso mods = 0x0
|
|
|
|
|
then
|
|
|
|
|
Mailbox.send (mailbox, KEY_B)
|
|
|
|
|
else if
|
|
|
|
|
key = Input.KEY_T () andalso action <> Input.RELEASE () andalso mods = 0x0
|
|
|
|
|
then
|
|
|
|
|
Mailbox.send (mailbox, KEY_T)
|
2024-08-29 00:05:30 +01:00
|
|
|
else if
|
|
|
|
|
(* ctrl-s *)
|
|
|
|
|
key = Input.KEY_S () andalso action = Input.PRESS () andalso mods = 0x002
|
|
|
|
|
then
|
|
|
|
|
Mailbox.send (mailbox, KEY_CTRL_S)
|
2024-08-29 05:21:04 +01:00
|
|
|
else if
|
|
|
|
|
(* ctrl-l *)
|
|
|
|
|
key = Input.KEY_L () andalso action = Input.PRESS () andalso mods = 0x002
|
|
|
|
|
then
|
|
|
|
|
Mailbox.send (mailbox, KEY_CTRL_L)
|
2024-08-30 02:34:24 +01:00
|
|
|
else if
|
|
|
|
|
(* ctrl-l *)
|
|
|
|
|
key = Input.KEY_E () andalso action = Input.PRESS () andalso mods = 0x002
|
|
|
|
|
then
|
|
|
|
|
Mailbox.send (mailbox, KEY_CTRL_E)
|
2025-07-11 15:34:29 +01:00
|
|
|
else if
|
|
|
|
|
key = Input.KEY_A () andalso action = Input.PRESS () andalso mods = 0
|
|
|
|
|
then
|
|
|
|
|
Mailbox.send (mailbox, KEY_A)
|
2024-09-20 14:38:04 +01:00
|
|
|
else if
|
|
|
|
|
key = Input.KEY_UP () andalso action <> Input.RELEASE ()
|
|
|
|
|
andalso mods = 0x0
|
|
|
|
|
then
|
|
|
|
|
Mailbox.send (mailbox, ARROW_UP)
|
|
|
|
|
else if
|
|
|
|
|
key = Input.KEY_LEFT () andalso action <> Input.RELEASE ()
|
|
|
|
|
andalso mods = 0x0
|
|
|
|
|
then
|
|
|
|
|
Mailbox.send (mailbox, ARROW_LEFT)
|
|
|
|
|
else if
|
|
|
|
|
key = Input.KEY_RIGHT () andalso action <> Input.RELEASE ()
|
|
|
|
|
andalso mods = 0x0
|
|
|
|
|
then
|
|
|
|
|
Mailbox.send (mailbox, ARROW_RIGHT)
|
|
|
|
|
else if
|
|
|
|
|
key = Input.KEY_DOWN () andalso action <> Input.RELEASE ()
|
|
|
|
|
andalso mods = 0x0
|
|
|
|
|
then
|
|
|
|
|
Mailbox.send (mailbox, ARROW_DOWN)
|
|
|
|
|
else if
|
|
|
|
|
key = Input.KEY_ENTER () andalso action = Input.PRESS ()
|
|
|
|
|
andalso mods = 0x0
|
|
|
|
|
then
|
|
|
|
|
Mailbox.send (mailbox, KEY_ENTER)
|
|
|
|
|
else if
|
|
|
|
|
key = Input.KEY_SPACE () andalso action = Input.PRESS ()
|
|
|
|
|
andalso mods = 0x0
|
|
|
|
|
then
|
|
|
|
|
Mailbox.send (mailbox, KEY_SPACE)
|
2024-09-25 10:17:57 +01:00
|
|
|
else if
|
|
|
|
|
key = Input.KEY_O () andalso action = Input.PRESS () andalso mods = 0x02
|
|
|
|
|
then
|
|
|
|
|
Mailbox.send (mailbox, KEY_CTRL_O)
|
2024-12-30 04:32:15 +00:00
|
|
|
else if
|
|
|
|
|
key = Input.KEY_0 () andalso action = Input.PRESS () andalso mods = 0
|
|
|
|
|
then
|
|
|
|
|
Mailbox.send (mailbox, NUM 0)
|
|
|
|
|
else if
|
|
|
|
|
key = Input.KEY_1 () andalso action = Input.PRESS () andalso mods = 0
|
|
|
|
|
then
|
|
|
|
|
Mailbox.send (mailbox, NUM 1)
|
|
|
|
|
else if
|
|
|
|
|
key = Input.KEY_2 () andalso action = Input.PRESS () andalso mods = 0
|
|
|
|
|
then
|
|
|
|
|
Mailbox.send (mailbox, NUM 2)
|
|
|
|
|
else if
|
|
|
|
|
key = Input.KEY_3 () andalso action = Input.PRESS () andalso mods = 0
|
|
|
|
|
then
|
|
|
|
|
Mailbox.send (mailbox, NUM 3)
|
|
|
|
|
else if
|
|
|
|
|
key = Input.KEY_4 () andalso action = Input.PRESS () andalso mods = 0
|
|
|
|
|
then
|
|
|
|
|
Mailbox.send (mailbox, NUM 4)
|
|
|
|
|
else if
|
|
|
|
|
key = Input.KEY_5 () andalso action = Input.PRESS () andalso mods = 0
|
|
|
|
|
then
|
|
|
|
|
Mailbox.send (mailbox, NUM 5)
|
|
|
|
|
else if
|
|
|
|
|
key = Input.KEY_6 () andalso action = Input.PRESS () andalso mods = 0
|
|
|
|
|
then
|
|
|
|
|
Mailbox.send (mailbox, NUM 6)
|
|
|
|
|
else if
|
|
|
|
|
key = Input.KEY_7 () andalso action = Input.PRESS () andalso mods = 0
|
|
|
|
|
then
|
|
|
|
|
Mailbox.send (mailbox, NUM 7)
|
|
|
|
|
else if
|
|
|
|
|
key = Input.KEY_8 () andalso action = Input.PRESS () andalso mods = 0
|
|
|
|
|
then
|
|
|
|
|
Mailbox.send (mailbox, NUM 8)
|
|
|
|
|
else if
|
|
|
|
|
key = Input.KEY_9 () andalso action = Input.PRESS () andalso mods = 0
|
|
|
|
|
then
|
|
|
|
|
Mailbox.send (mailbox, NUM 9)
|
2024-08-08 23:52:49 +01:00
|
|
|
else
|
|
|
|
|
()
|
2024-08-08 06:34:40 +01:00
|
|
|
|
2024-07-31 12:00:07 +01:00
|
|
|
fun registerCallbacks (window, inputMailbox) =
|
2024-07-31 12:30:12 +01:00
|
|
|
let
|
|
|
|
|
val mouseMoveCallback = mouseMoveCallback inputMailbox
|
|
|
|
|
val _ = Input.exportMouseMoveCallback mouseMoveCallback
|
|
|
|
|
val _ = Input.setMouseMoveCallback window
|
2024-07-31 12:00:07 +01:00
|
|
|
|
2024-07-31 12:30:12 +01:00
|
|
|
val mouseClickCallback = mouseClickCallback inputMailbox
|
|
|
|
|
val _ = Input.exportMouseClickCallback mouseClickCallback
|
|
|
|
|
val _ = Input.setMouseClickCallback window
|
2024-08-01 23:33:54 +01:00
|
|
|
|
|
|
|
|
val resizeCallback = framebufferSizeCallback inputMailbox
|
|
|
|
|
val _ = Input.exportFramebufferSizeCallback resizeCallback
|
|
|
|
|
val _ = Input.setFramebufferSizeCallback window
|
2024-08-08 06:34:40 +01:00
|
|
|
|
|
|
|
|
val keyCallback = keyActionCallback inputMailbox
|
|
|
|
|
val _ = Input.exportKeyCallback keyCallback
|
|
|
|
|
val _ = Input.setKeyCallback window
|
2024-07-31 12:30:12 +01:00
|
|
|
in
|
|
|
|
|
()
|
|
|
|
|
end
|
2024-07-30 17:10:48 +01:00
|
|
|
end
|