2024-08-08 00:50:36 +01:00
|
|
|
signature APP_UPDATE =
|
|
|
|
|
sig
|
|
|
|
|
val update: AppType.app_type * int * int * InputMessage.t
|
|
|
|
|
-> AppType.app_type * int * int * DrawMessage.t
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
structure AppUpdate :> APP_UPDATE =
|
2024-07-30 19:04:36 +01:00
|
|
|
struct
|
2024-07-31 12:00:07 +01:00
|
|
|
open AppType
|
2024-08-08 00:50:36 +01:00
|
|
|
open DrawMessage
|
|
|
|
|
open InputMessage
|
2024-07-30 19:04:36 +01:00
|
|
|
|
2024-08-08 00:50:36 +01:00
|
|
|
fun mouseMoveOrRelease (model: app_type, mouseX, mouseY) =
|
2024-07-31 21:21:45 +01:00
|
|
|
let
|
2024-08-08 00:50:36 +01:00
|
|
|
val {xClickPoints, yClickPoints, ...} = model
|
|
|
|
|
val (drawVec, _, _) = ClickPoints.getClickPosition
|
|
|
|
|
(mouseX, mouseY, 1.0, 0.0, 0.0, model)
|
|
|
|
|
val drawVec = TriangleStage.toVector (model, drawVec)
|
|
|
|
|
val drawMsg = DRAW_BUTTON drawVec
|
2024-07-31 21:21:45 +01:00
|
|
|
in
|
2024-08-08 00:50:36 +01:00
|
|
|
(model, drawMsg, mouseX, mouseY)
|
2024-07-31 21:21:45 +01:00
|
|
|
end
|
|
|
|
|
|
2024-08-08 00:50:36 +01:00
|
|
|
fun mouseLeftClick (model: app_type, mouseX, mouseY) =
|
2024-07-31 21:21:45 +01:00
|
|
|
let
|
2024-08-08 00:50:36 +01:00
|
|
|
val {xClickPoints, yClickPoints, ...} = model
|
|
|
|
|
val (buttonVec, hpos, vpos) = ClickPoints.getClickPosition
|
|
|
|
|
(mouseX, mouseY, 0.0, 0.0, 1.0, model)
|
2024-07-31 21:21:45 +01:00
|
|
|
in
|
2024-08-08 00:50:36 +01:00
|
|
|
if Vector.length buttonVec > 0 then
|
|
|
|
|
case #triangleStage model of
|
|
|
|
|
NO_TRIANGLE =>
|
|
|
|
|
let
|
|
|
|
|
val drawVec = TriangleStage.toVector (model, buttonVec)
|
|
|
|
|
val drawMsg = DRAW_BUTTON drawVec
|
|
|
|
|
|
|
|
|
|
val newTriangleStage = FIRST {x1 = hpos, y1 = vpos}
|
|
|
|
|
val model = AppType.withTriangleStage (model, newTriangleStage)
|
|
|
|
|
in
|
|
|
|
|
(model, drawMsg, mouseX, mouseY)
|
|
|
|
|
end
|
|
|
|
|
| FIRST {x1, y1} =>
|
|
|
|
|
let
|
|
|
|
|
val drawVec =
|
|
|
|
|
TriangleStage.firstToVector (x1, y1, buttonVec, model)
|
|
|
|
|
val drawMsg = DRAW_BUTTON drawVec
|
|
|
|
|
|
|
|
|
|
val newTriangleStage = SECOND
|
|
|
|
|
{x1 = x1, y1 = y1, x2 = hpos, y2 = vpos}
|
|
|
|
|
val model = AppType.withTriangleStage (model, newTriangleStage)
|
|
|
|
|
in
|
|
|
|
|
(model, drawMsg, mouseX, mouseY)
|
|
|
|
|
end
|
|
|
|
|
| SECOND {x1, y1, x2, y2} =>
|
|
|
|
|
let
|
|
|
|
|
val model = AppType.addTriangleAndResetStage
|
|
|
|
|
(model, x1, y1, x2, y2, hpos, vpos)
|
|
|
|
|
|
|
|
|
|
val drawVec = getTrianglesVector model
|
|
|
|
|
val drawMsg = DRAW_TRIANGLES_AND_RESET_BUTTONS drawVec
|
|
|
|
|
in
|
|
|
|
|
(model, drawMsg, mouseX, mouseY)
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
(model, NO_DRAW, mouseX, mouseY)
|
2024-07-31 21:21:45 +01:00
|
|
|
end
|
|
|
|
|
|
2024-08-08 00:50:36 +01:00
|
|
|
fun resizeWindow (model, mouseX, mouseY, width, height) =
|
|
|
|
|
let
|
|
|
|
|
val model = AppType.withWindowResize (model, width, height)
|
|
|
|
|
val triangles = getTrianglesVector model
|
|
|
|
|
val graphLines = #graphLines model
|
|
|
|
|
val drawMsg =
|
|
|
|
|
RESIZE_TRIANGLES_BUTTONS_AND_GRAPH
|
|
|
|
|
{triangles = triangles, graphLines = graphLines}
|
|
|
|
|
in
|
|
|
|
|
(model, drawMsg, mouseX, mouseY)
|
|
|
|
|
end
|
2024-08-02 13:35:48 +01:00
|
|
|
|
2024-08-08 00:50:36 +01:00
|
|
|
fun update (model: app_type, mouseX, mouseY, inputMsg) =
|
|
|
|
|
case inputMsg of
|
|
|
|
|
MOUSE_MOVE {x = mouseX, y = mouseY} =>
|
|
|
|
|
mouseMoveOrRelease (model, mouseX, mouseY)
|
|
|
|
|
| MOUSE_LEFT_RELEASE => mouseMoveOrRelease (model, mouseX, mouseY)
|
|
|
|
|
| MOUSE_LEFT_CLICK => mouseLeftClick (model, mouseX, mouseY)
|
|
|
|
|
| RESIZE_WINDOW {width, height} =>
|
|
|
|
|
resizeWindow (model, mouseX, mouseY, width, height)
|
2024-07-30 19:04:36 +01:00
|
|
|
end
|