keep triangle stages (clicked positions) drawn on screen, until triangle stages resets to NO_TRIANGLE
This commit is contained in:
BIN
dot-to-dot
BIN
dot-to-dot
Binary file not shown.
@@ -18,6 +18,8 @@ sig
|
|||||||
type app_type = {triangleStage: triangle_stage, triangles: triangle list}
|
type app_type = {triangleStage: triangle_stage, triangles: triangle list}
|
||||||
|
|
||||||
val initial: app_type
|
val initial: app_type
|
||||||
|
|
||||||
|
val withTriangleStage: app_type * triangle_stage -> app_type
|
||||||
end
|
end
|
||||||
|
|
||||||
structure AppType :> APP_TYPE =
|
structure AppType :> APP_TYPE =
|
||||||
@@ -48,4 +50,10 @@ struct
|
|||||||
type app_type = {triangles: triangle list, triangleStage: triangle_stage}
|
type app_type = {triangles: triangle list, triangleStage: triangle_stage}
|
||||||
|
|
||||||
val initial = {triangles = [], triangleStage = NO_TRIANGLE}
|
val initial = {triangles = [], triangleStage = NO_TRIANGLE}
|
||||||
|
|
||||||
|
fun withTriangleStage (app: app_type, newTriangleStage: triangle_stage) :
|
||||||
|
app_type =
|
||||||
|
let val {triangles, triangleStage = _} = app
|
||||||
|
in {triangles = triangles, triangleStage = newTriangleStage}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -150,6 +150,7 @@ struct
|
|||||||
MOUSE_MOVE {x = mouseX, y = mouseY} =>
|
MOUSE_MOVE {x = mouseX, y = mouseY} =>
|
||||||
let
|
let
|
||||||
val (drawVec, _, _) = getClickPos (mouseX, mouseY, 1.0, 0.0, 0.0)
|
val (drawVec, _, _) = getClickPos (mouseX, mouseY, 1.0, 0.0, 0.0)
|
||||||
|
val drawVec = getTriangleStageVector (model, drawVec)
|
||||||
val drawMsg = DRAW_BUTTON drawVec
|
val drawMsg = DRAW_BUTTON drawVec
|
||||||
in
|
in
|
||||||
(model, drawMsg, mouseX, mouseY)
|
(model, drawMsg, mouseX, mouseY)
|
||||||
@@ -157,21 +158,52 @@ struct
|
|||||||
| MOUSE_LEFT_RELEASE =>
|
| MOUSE_LEFT_RELEASE =>
|
||||||
let
|
let
|
||||||
val (drawVec, _, _) = getClickPos (mouseX, mouseY, 1.0, 0.0, 0.0)
|
val (drawVec, _, _) = getClickPos (mouseX, mouseY, 1.0, 0.0, 0.0)
|
||||||
|
val drawVec = getTriangleStageVector (model, drawVec)
|
||||||
val drawMsg = DRAW_BUTTON drawVec
|
val drawMsg = DRAW_BUTTON drawVec
|
||||||
in
|
in
|
||||||
(model, drawMsg, mouseX, mouseY)
|
(model, drawMsg, mouseX, mouseY)
|
||||||
end
|
end
|
||||||
| MUSE_LEFT_CLICK =>
|
| MUSE_LEFT_CLICK =>
|
||||||
let
|
let
|
||||||
val (buttonVec, hpos, vpos) =
|
val (buttonVec, hpos, vpos) = getClickPos
|
||||||
getClickPos (mouseX, mouseY, 0.0, 0.0, 1.0)
|
(mouseX, mouseY, 0.0, 0.0, 1.0)
|
||||||
in
|
in
|
||||||
if Vector.length buttonVec > 0 then
|
if Vector.length buttonVec > 0 then
|
||||||
let
|
(case #triangleStage model of
|
||||||
val drawMsg = DRAW_BUTTON buttonVec
|
NO_TRIANGLE =>
|
||||||
in
|
let
|
||||||
(model, drawMsg, mouseX, mouseY)
|
val drawVec = getTriangleStageVector (model, buttonVec)
|
||||||
end
|
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 = getTriangleStageVector (model, buttonVec)
|
||||||
|
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 drawVec = getTriangleStageVector (model, buttonVec)
|
||||||
|
val drawMsg = DRAW_BUTTON drawVec
|
||||||
|
|
||||||
|
val newTriangleStage = NO_TRIANGLE
|
||||||
|
val model =
|
||||||
|
AppType.withTriangleStage (model, newTriangleStage)
|
||||||
|
in
|
||||||
|
(model, drawMsg, mouseX, mouseY)
|
||||||
|
end)
|
||||||
else
|
else
|
||||||
(model, NO_DRAW, mouseX, mouseY)
|
(model, NO_DRAW, mouseX, mouseY)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user