2024-07-31 10:03:30 +01:00
|
|
|
structure EventLoop =
|
|
|
|
|
struct
|
|
|
|
|
open CML
|
|
|
|
|
open InputMessage
|
|
|
|
|
|
2024-07-31 12:00:07 +01:00
|
|
|
local
|
2024-07-31 12:30:12 +01:00
|
|
|
fun loop (inputMailbox, drawMailbox, mouseX, mouseY, model) =
|
|
|
|
|
let
|
|
|
|
|
val inputMsg = Mailbox.recv inputMailbox
|
|
|
|
|
val (model, drawMsg, mouseX, mouseY) =
|
|
|
|
|
AppUpdate.update (model, mouseX, mouseY, inputMsg)
|
|
|
|
|
val _ = Mailbox.send (drawMailbox, drawMsg)
|
|
|
|
|
in
|
|
|
|
|
loop (inputMailbox, drawMailbox, mouseX, mouseY, model)
|
|
|
|
|
end
|
2024-07-31 12:00:07 +01:00
|
|
|
in
|
|
|
|
|
fun update (inputMailbox, drawMailbox) =
|
|
|
|
|
loop (inputMailbox, drawMailbox, 0, 0, AppType.initial)
|
|
|
|
|
end
|
2024-07-31 10:03:30 +01:00
|
|
|
|
2024-07-31 12:30:12 +01:00
|
|
|
fun draw
|
|
|
|
|
(drawMailbox, window, graphDrawObject, buttonDrawObject, buttonDrawLength) =
|
2024-07-31 10:03:30 +01:00
|
|
|
if not (Glfw.windowShouldClose window) then
|
|
|
|
|
let
|
|
|
|
|
val _ = Gles3.clearColor (1.0, 1.0, 1.0, 1.0)
|
|
|
|
|
val _ = Gles3.clear ()
|
|
|
|
|
|
|
|
|
|
val _ = AppDraw.drawGraphLines graphDrawObject
|
|
|
|
|
val _ = AppDraw.drawButton (buttonDrawObject, buttonDrawLength)
|
|
|
|
|
|
|
|
|
|
val _ = Glfw.pollEvents ()
|
|
|
|
|
val _ = Glfw.swapBuffers window
|
|
|
|
|
in
|
2024-07-31 12:30:12 +01:00
|
|
|
draw
|
|
|
|
|
( drawMailbox
|
|
|
|
|
, window
|
|
|
|
|
, graphDrawObject
|
|
|
|
|
, buttonDrawObject
|
|
|
|
|
, buttonDrawLength
|
|
|
|
|
)
|
2024-07-31 10:03:30 +01:00
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
Glfw.terminate ()
|
|
|
|
|
end
|