2024-08-08 00:50:36 +01:00
|
|
|
signature APP_UPDATE =
|
|
|
|
|
sig
|
2024-08-08 23:10:38 +01:00
|
|
|
val update: AppType.app_type * InputMessage.t
|
2024-09-27 08:27:53 +01:00
|
|
|
-> AppType.app_type * UpdateMessage.t list
|
2024-08-08 00:50:36 +01:00
|
|
|
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-28 20:11:00 +01:00
|
|
|
|
2024-08-08 00:50:36 +01:00
|
|
|
open DrawMessage
|
2024-08-29 00:05:30 +01:00
|
|
|
open FileMessage
|
2024-08-08 00:50:36 +01:00
|
|
|
open InputMessage
|
2024-08-28 20:11:00 +01:00
|
|
|
open UpdateMessage
|
2024-07-30 19:04:36 +01:00
|
|
|
|
2024-09-20 12:33:31 +01:00
|
|
|
fun getDotVecFromIndices (model, hIdx, vIdx) =
|
|
|
|
|
let
|
2024-09-21 13:23:25 +01:00
|
|
|
val {windowWidth, windowHeight, ...} = model
|
2024-09-20 12:33:31 +01:00
|
|
|
val xpos = Vector.sub (#xClickPoints model, hIdx)
|
|
|
|
|
val ypos = Vector.sub (#yClickPoints model, vIdx)
|
|
|
|
|
in
|
2024-09-21 13:23:25 +01:00
|
|
|
ClickPoints.getDrawDotRgb
|
|
|
|
|
(xpos, ypos, 1.0, 0.0, 0.0, windowWidth, windowHeight)
|
2024-09-20 12:33:31 +01:00
|
|
|
end
|
|
|
|
|
|
2024-08-08 21:58:50 +01:00
|
|
|
fun mouseMoveOrRelease (model: app_type) =
|
2024-07-31 21:21:45 +01:00
|
|
|
let
|
2024-09-16 21:49:05 +01:00
|
|
|
val drawVec =
|
|
|
|
|
case ClickPoints.getClickPositionFromMouse model of
|
2024-09-20 12:33:31 +01:00
|
|
|
SOME (hIdx, vIdx) => getDotVecFromIndices (model, hIdx, vIdx)
|
2024-09-16 21:49:05 +01:00
|
|
|
| NONE => Vector.fromList []
|
2024-09-19 18:54:32 +01:00
|
|
|
val drawVec = TriangleStage.toVector (model, drawVec)
|
2024-09-20 09:07:54 +01:00
|
|
|
|
2024-08-14 21:24:46 +01:00
|
|
|
val drawMsg = DRAW_DOT drawVec
|
2024-09-27 08:27:53 +01:00
|
|
|
val drawMsg = [DRAW drawMsg]
|
2024-07-31 21:21:45 +01:00
|
|
|
in
|
2024-09-27 08:27:53 +01:00
|
|
|
(model, drawMsg)
|
2024-07-31 21:21:45 +01:00
|
|
|
end
|
|
|
|
|
|
2024-09-20 12:33:31 +01:00
|
|
|
fun getDrawDotMsgWhenArrowIsAtBoundary model =
|
|
|
|
|
let
|
|
|
|
|
val {arrowX, arrowY, ...} = model
|
|
|
|
|
val dotVec = getDotVecFromIndices (model, arrowX, arrowY)
|
|
|
|
|
val dotVec = TriangleStage.toVector (model, dotVec)
|
|
|
|
|
val drawMsg = DRAW_DOT dotVec
|
2024-09-27 08:27:53 +01:00
|
|
|
val drawMsg = [DRAW drawMsg]
|
2024-09-20 12:33:31 +01:00
|
|
|
in
|
2024-09-27 08:27:53 +01:00
|
|
|
(model, drawMsg)
|
2024-09-20 12:33:31 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
fun moveArrowUp (model: app_type) =
|
|
|
|
|
let
|
|
|
|
|
val {arrowX, arrowY, ...} = model
|
|
|
|
|
in
|
|
|
|
|
if arrowY > 0 then
|
|
|
|
|
let
|
|
|
|
|
val newArrowY = arrowY - 1
|
|
|
|
|
val model = AppWith.arrowY (model, newArrowY)
|
|
|
|
|
|
|
|
|
|
val dotVec = getDotVecFromIndices (model, arrowX, newArrowY)
|
|
|
|
|
val dotVec = TriangleStage.toVector (model, dotVec)
|
|
|
|
|
val drawMsg = DRAW_DOT dotVec
|
2024-09-27 08:27:53 +01:00
|
|
|
val drawMsg = [DRAW drawMsg]
|
2024-09-20 12:33:31 +01:00
|
|
|
in
|
2024-09-27 08:27:53 +01:00
|
|
|
(model, drawMsg)
|
2024-09-20 12:33:31 +01:00
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
getDrawDotMsgWhenArrowIsAtBoundary model
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
fun moveArrowLeft (model: app_type) =
|
|
|
|
|
let
|
|
|
|
|
val {arrowX, arrowY, ...} = model
|
|
|
|
|
in
|
|
|
|
|
if arrowX > 0 then
|
|
|
|
|
let
|
|
|
|
|
val newArrowX = arrowX - 1
|
|
|
|
|
val model = AppWith.arrowX (model, newArrowX)
|
|
|
|
|
|
|
|
|
|
val dotVec = getDotVecFromIndices (model, newArrowX, arrowY)
|
|
|
|
|
val dotVec = TriangleStage.toVector (model, dotVec)
|
|
|
|
|
val drawMsg = DRAW_DOT dotVec
|
2024-09-27 08:27:53 +01:00
|
|
|
val drawMsg = [DRAW drawMsg]
|
2024-09-20 12:33:31 +01:00
|
|
|
in
|
2024-09-27 08:27:53 +01:00
|
|
|
(model, drawMsg)
|
2024-09-20 12:33:31 +01:00
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
getDrawDotMsgWhenArrowIsAtBoundary model
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
fun moveArrowRight (model: app_type) =
|
|
|
|
|
let
|
|
|
|
|
val {arrowX, arrowY, xClickPoints, ...} = model
|
|
|
|
|
in
|
|
|
|
|
if arrowX < Vector.length xClickPoints - 1 then
|
2024-09-16 21:49:05 +01:00
|
|
|
let
|
2024-09-20 12:33:31 +01:00
|
|
|
val newArrowX = arrowX + 1
|
|
|
|
|
val model = AppWith.arrowX (model, newArrowX)
|
2024-09-20 09:07:54 +01:00
|
|
|
|
2024-09-20 12:33:31 +01:00
|
|
|
val dotVec = getDotVecFromIndices (model, newArrowX, arrowY)
|
|
|
|
|
val dotVec = TriangleStage.toVector (model, dotVec)
|
|
|
|
|
val drawMsg = DRAW_DOT dotVec
|
2024-09-27 08:27:53 +01:00
|
|
|
val drawMsg = [DRAW drawMsg]
|
2024-09-20 12:33:31 +01:00
|
|
|
in
|
2024-09-27 08:27:53 +01:00
|
|
|
(model, drawMsg)
|
2024-09-20 12:33:31 +01:00
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
getDrawDotMsgWhenArrowIsAtBoundary model
|
|
|
|
|
end
|
2024-09-20 09:07:54 +01:00
|
|
|
|
2024-09-20 12:33:31 +01:00
|
|
|
fun moveArrowDown (model: app_type) =
|
|
|
|
|
let
|
|
|
|
|
val {arrowX, arrowY, yClickPoints, ...} = model
|
|
|
|
|
in
|
|
|
|
|
if arrowY < Vector.length yClickPoints - 1 then
|
|
|
|
|
let
|
|
|
|
|
val newArrowY = arrowY + 1
|
|
|
|
|
val model = AppWith.arrowY (model, newArrowY)
|
2024-09-19 17:46:40 +01:00
|
|
|
|
2024-09-20 12:33:31 +01:00
|
|
|
val dotVec = getDotVecFromIndices (model, arrowX, newArrowY)
|
|
|
|
|
val dotVec = TriangleStage.toVector (model, dotVec)
|
|
|
|
|
val drawMsg = DRAW_DOT dotVec
|
2024-09-27 08:27:53 +01:00
|
|
|
val drawMsg = [DRAW drawMsg]
|
2024-09-16 21:49:05 +01:00
|
|
|
in
|
2024-09-27 08:27:53 +01:00
|
|
|
(model, drawMsg)
|
2024-09-16 21:49:05 +01:00
|
|
|
end
|
2024-09-20 12:33:31 +01:00
|
|
|
else
|
|
|
|
|
getDrawDotMsgWhenArrowIsAtBoundary model
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
fun addCoordinates (model: app_type, hIdx, vIdx) =
|
|
|
|
|
let
|
|
|
|
|
val
|
|
|
|
|
{ windowWidth
|
|
|
|
|
, windowHeight
|
|
|
|
|
, xClickPoints
|
|
|
|
|
, yClickPoints
|
|
|
|
|
, triangleStage
|
|
|
|
|
, ...
|
|
|
|
|
} = model
|
|
|
|
|
|
|
|
|
|
val xpos = Vector.sub (xClickPoints, hIdx)
|
|
|
|
|
val ypos = Vector.sub (yClickPoints, vIdx)
|
2024-09-21 13:23:25 +01:00
|
|
|
val dotVec = ClickPoints.getDrawDotRgb
|
|
|
|
|
(xpos, ypos, 0.0, 0.0, 1.0, windowWidth, windowHeight)
|
2024-09-20 12:33:31 +01:00
|
|
|
|
|
|
|
|
val halfWidth = Real32.fromInt (windowWidth div 2)
|
|
|
|
|
val halfHeight = Real32.fromInt (windowHeight div 2)
|
|
|
|
|
val hpos =
|
|
|
|
|
ClickPoints.xposToNdc (xpos, windowWidth, windowHeight, halfWidth)
|
|
|
|
|
val vpos =
|
|
|
|
|
ClickPoints.yposToNdc (ypos, windowWidth, windowHeight, halfHeight)
|
|
|
|
|
|
|
|
|
|
val newUndoTuple = (hpos, vpos)
|
|
|
|
|
in
|
|
|
|
|
case triangleStage of
|
|
|
|
|
NO_TRIANGLE =>
|
|
|
|
|
let
|
|
|
|
|
val drawVec = TriangleStage.toVector (model, dotVec)
|
|
|
|
|
val drawMsg = DRAW_DOT drawVec
|
2024-09-27 08:27:53 +01:00
|
|
|
val drawMsg = [DRAW drawMsg]
|
2024-09-20 12:33:31 +01:00
|
|
|
|
|
|
|
|
val newTriangleStage = FIRST {x1 = hpos, y1 = vpos}
|
|
|
|
|
val model = AppWith.addTriangleStage
|
|
|
|
|
(model, newTriangleStage, newUndoTuple, hIdx, vIdx)
|
|
|
|
|
in
|
2024-09-27 08:27:53 +01:00
|
|
|
(model, drawMsg)
|
2024-09-20 12:33:31 +01:00
|
|
|
end
|
|
|
|
|
| FIRST {x1, y1} =>
|
|
|
|
|
let
|
|
|
|
|
val drawVec = TriangleStage.firstToVector (x1, y1, dotVec, model)
|
|
|
|
|
val drawMsg = DRAW_DOT drawVec
|
2024-09-27 08:27:53 +01:00
|
|
|
val drawMsg = [DRAW drawMsg]
|
2024-09-20 12:33:31 +01:00
|
|
|
|
|
|
|
|
val newTriangleStage = SECOND
|
|
|
|
|
{x1 = x1, y1 = y1, x2 = hpos, y2 = vpos}
|
|
|
|
|
val model = AppWith.addTriangleStage
|
|
|
|
|
(model, newTriangleStage, newUndoTuple, hIdx, vIdx)
|
|
|
|
|
in
|
2024-09-27 08:27:53 +01:00
|
|
|
(model, drawMsg)
|
2024-09-20 12:33:31 +01:00
|
|
|
end
|
|
|
|
|
| SECOND {x1, y1, x2, y2} =>
|
|
|
|
|
let
|
|
|
|
|
val model = AppWith.addTriangle
|
|
|
|
|
(model, x1, y1, x2, y2, hpos, vpos, newUndoTuple, hIdx, vIdx)
|
|
|
|
|
val drawVec = Triangles.toVector model
|
|
|
|
|
val drawMsg = DRAW_TRIANGLES_AND_RESET_DOTS drawVec
|
2024-09-27 08:27:53 +01:00
|
|
|
val drawMsg = [DRAW drawMsg]
|
2024-09-20 12:33:31 +01:00
|
|
|
in
|
2024-09-27 08:27:53 +01:00
|
|
|
(model, drawMsg)
|
2024-09-20 12:33:31 +01:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
fun mouseLeftClick model =
|
|
|
|
|
case ClickPoints.getClickPositionFromMouse model of
|
|
|
|
|
SOME (hIdx, vIdx) => addCoordinates (model, hIdx, vIdx)
|
2024-09-27 08:27:53 +01:00
|
|
|
| NONE => (model, [])
|
2024-07-31 21:21:45 +01:00
|
|
|
|
2024-09-20 14:14:07 +01:00
|
|
|
fun enterOrSpaceCoordinates model =
|
|
|
|
|
let val {arrowX, arrowY, ...} = model
|
|
|
|
|
in addCoordinates (model, arrowX, arrowY)
|
|
|
|
|
end
|
|
|
|
|
|
2024-08-08 21:58:50 +01:00
|
|
|
fun resizeWindow (model, width, height) =
|
2024-08-08 00:50:36 +01:00
|
|
|
let
|
2024-08-08 00:58:59 +01:00
|
|
|
val model = AppWith.windowResize (model, width, height)
|
|
|
|
|
val triangles = Triangles.toVector model
|
2024-08-14 03:54:52 +01:00
|
|
|
|
|
|
|
|
val graphLines =
|
|
|
|
|
if #showGraph model then GraphLines.generate model
|
|
|
|
|
else Vector.fromList []
|
|
|
|
|
|
2024-08-14 21:35:01 +01:00
|
|
|
val dots = TriangleStage.toVector (model, Vector.fromList [])
|
|
|
|
|
|
2024-08-08 00:50:36 +01:00
|
|
|
val drawMsg =
|
2024-08-14 21:24:46 +01:00
|
|
|
RESIZE_TRIANGLES_DOTS_AND_GRAPH
|
2024-08-14 21:35:01 +01:00
|
|
|
{triangles = triangles, graphLines = graphLines, dots = dots}
|
2024-09-27 08:27:53 +01:00
|
|
|
val drawMsg = [DRAW drawMsg]
|
2024-08-08 00:50:36 +01:00
|
|
|
in
|
2024-09-27 08:27:53 +01:00
|
|
|
(model, drawMsg)
|
2024-08-08 00:50:36 +01:00
|
|
|
end
|
2024-08-02 13:35:48 +01:00
|
|
|
|
2024-08-08 21:58:50 +01:00
|
|
|
fun undoAction model =
|
2024-08-08 21:35:48 +01:00
|
|
|
case #triangleStage model of
|
|
|
|
|
FIRST {x1, y1} =>
|
2024-08-14 21:24:46 +01:00
|
|
|
(* Change FIRST to NO_TRIANGLE and clear dots. *)
|
2024-08-08 23:43:38 +01:00
|
|
|
let
|
|
|
|
|
val model =
|
|
|
|
|
AppWith.undo (model, NO_TRIANGLE, #triangles model, (x1, y1))
|
|
|
|
|
in
|
2024-09-27 08:27:53 +01:00
|
|
|
(model, [DRAW CLEAR_DOTS])
|
2024-08-08 21:35:48 +01:00
|
|
|
end
|
|
|
|
|
| SECOND {x1, y1, x2, y2} =>
|
2024-08-14 21:24:46 +01:00
|
|
|
(* Change FIRST to SECOND and redraw dots. *)
|
2024-08-08 21:35:48 +01:00
|
|
|
let
|
|
|
|
|
val newTriangleStage = FIRST {x1 = x1, y1 = y1}
|
2024-08-08 23:10:38 +01:00
|
|
|
val model =
|
2024-08-08 23:43:38 +01:00
|
|
|
AppWith.undo (model, newTriangleStage, #triangles model, (x2, y2))
|
2024-08-08 21:35:48 +01:00
|
|
|
|
2024-08-08 23:10:38 +01:00
|
|
|
val emptyVec: Real32.real vector = Vector.fromList []
|
|
|
|
|
val drawVec = TriangleStage.firstToVector (x1, y1, emptyVec, model)
|
2024-08-14 21:24:46 +01:00
|
|
|
val drawMsg = DRAW_DOT drawVec
|
2024-09-27 08:27:53 +01:00
|
|
|
val drawMsg = [DRAW drawMsg]
|
2024-08-08 21:35:48 +01:00
|
|
|
in
|
2024-09-27 08:27:53 +01:00
|
|
|
(model, drawMsg)
|
2024-08-08 21:35:48 +01:00
|
|
|
end
|
|
|
|
|
| NO_TRIANGLE =>
|
|
|
|
|
(case #triangles model of
|
2024-08-08 23:10:38 +01:00
|
|
|
{x1, y1, x2, y2, x3, y3} :: trianglesTl =>
|
2024-08-08 21:35:48 +01:00
|
|
|
(* Have to slice off (x3, y3) from triangle head,
|
|
|
|
|
* turn (x1, y1, x2, y2) into a triangleStage,
|
|
|
|
|
* and redraw both triangle and triangleStage. *)
|
|
|
|
|
let
|
|
|
|
|
val triangleStage = SECOND {x1 = x1, y1 = y1, x2 = x2, y2 = y2}
|
|
|
|
|
val model =
|
2024-08-08 23:43:38 +01:00
|
|
|
AppWith.undo (model, triangleStage, trianglesTl, (x3, y3))
|
2024-08-08 21:35:48 +01:00
|
|
|
|
|
|
|
|
val newTriangleVec = Triangles.toVector model
|
2024-08-13 23:38:04 +01:00
|
|
|
val emptyVec: Real32.real vector = Vector.fromList []
|
2024-08-08 21:35:48 +01:00
|
|
|
val drawVec = TriangleStage.secondToVector
|
2024-08-11 15:02:04 +01:00
|
|
|
(x1, y1, x2, y2, emptyVec, model)
|
2024-08-08 21:35:48 +01:00
|
|
|
val drawMsg =
|
2024-08-14 21:24:46 +01:00
|
|
|
DRAW_TRIANGLES_AND_DOTS
|
|
|
|
|
{triangles = newTriangleVec, dots = drawVec}
|
2024-09-27 08:27:53 +01:00
|
|
|
val drawMsg = [DRAW drawMsg]
|
2024-08-08 21:35:48 +01:00
|
|
|
in
|
2024-09-27 08:27:53 +01:00
|
|
|
(model, drawMsg)
|
2024-08-08 21:35:48 +01:00
|
|
|
end
|
|
|
|
|
| [] =>
|
|
|
|
|
(* Can't undo, because there are no actions to undo. *)
|
2024-09-27 08:27:53 +01:00
|
|
|
(model, []))
|
2024-08-08 21:35:48 +01:00
|
|
|
|
2024-08-08 23:43:38 +01:00
|
|
|
fun redoAction model =
|
|
|
|
|
case #redo model of
|
|
|
|
|
(redoHd as (x, y)) :: tl =>
|
|
|
|
|
(* There is a click point to redo. *)
|
|
|
|
|
(case #triangleStage model of
|
|
|
|
|
NO_TRIANGLE =>
|
2024-08-14 21:24:46 +01:00
|
|
|
(* add to triangle stage, and redraw dots *)
|
2024-08-08 23:43:38 +01:00
|
|
|
let
|
|
|
|
|
val newTriangleStage = FIRST {x1 = x, y1 = y}
|
|
|
|
|
val model =
|
|
|
|
|
AppWith.redo
|
|
|
|
|
(model, newTriangleStage, #triangles model, redoHd)
|
|
|
|
|
|
|
|
|
|
val emptyVec: Real32.real vector = Vector.fromList []
|
2024-08-13 23:38:04 +01:00
|
|
|
val drawVec = TriangleStage.firstToVector (x, y, emptyVec, model)
|
2024-08-14 21:24:46 +01:00
|
|
|
val drawMsg = DRAW_DOT drawVec
|
2024-09-27 08:27:53 +01:00
|
|
|
val drawMsg = [DRAW drawMsg]
|
2024-08-08 23:43:38 +01:00
|
|
|
in
|
2024-09-27 08:27:53 +01:00
|
|
|
(model, drawMsg)
|
2024-08-08 23:43:38 +01:00
|
|
|
end
|
|
|
|
|
| FIRST {x1, y1} =>
|
2024-08-14 21:24:46 +01:00
|
|
|
(* add to triangle stage, redraw dots *)
|
2024-08-08 23:43:38 +01:00
|
|
|
let
|
|
|
|
|
val newTriangleStage = SECOND {x1 = x1, y1 = y1, x2 = x, y2 = y}
|
|
|
|
|
val model =
|
|
|
|
|
AppWith.redo
|
|
|
|
|
(model, newTriangleStage, #triangles model, redoHd)
|
|
|
|
|
|
|
|
|
|
val emptyVec: Real32.real vector = Vector.fromList []
|
|
|
|
|
val drawVec = TriangleStage.secondToVector
|
|
|
|
|
(x1, y1, x, y, emptyVec, model)
|
2024-08-14 21:24:46 +01:00
|
|
|
val drawMsg = DRAW_DOT drawVec
|
2024-09-27 08:27:53 +01:00
|
|
|
val drawMsg = [DRAW drawMsg]
|
2024-08-08 23:43:38 +01:00
|
|
|
in
|
2024-09-27 08:27:53 +01:00
|
|
|
(model, drawMsg)
|
2024-08-08 23:43:38 +01:00
|
|
|
end
|
|
|
|
|
| SECOND {x1, y1, x2, y2} =>
|
|
|
|
|
(* clear triangle stage, add to trinagle list and redraw triangles *)
|
|
|
|
|
let
|
|
|
|
|
val newTriangleStage = NO_TRIANGLE
|
|
|
|
|
val newTriangle =
|
|
|
|
|
{x1 = x1, y1 = y1, x2 = x2, y2 = y2, x3 = x, y3 = y}
|
2024-08-08 23:45:24 +01:00
|
|
|
val newTriangles = newTriangle :: (#triangles model)
|
2024-08-08 23:43:38 +01:00
|
|
|
val model =
|
|
|
|
|
AppWith.redo (model, newTriangleStage, newTriangles, redoHd)
|
|
|
|
|
|
|
|
|
|
val drawVec = Triangles.toVector model
|
2024-08-14 21:24:46 +01:00
|
|
|
val drawMsg = DRAW_TRIANGLES_AND_RESET_DOTS drawVec
|
2024-09-27 08:27:53 +01:00
|
|
|
val drawMsg = [DRAW drawMsg]
|
2024-08-08 23:43:38 +01:00
|
|
|
in
|
2024-09-27 08:27:53 +01:00
|
|
|
(model, drawMsg)
|
2024-08-08 23:43:38 +01:00
|
|
|
end)
|
2024-09-27 08:27:53 +01:00
|
|
|
| [] => (* Nothing to redo. *) (model, [])
|
2024-08-14 02:31:28 +01:00
|
|
|
|
|
|
|
|
fun toggleGraph (model: app_type) =
|
|
|
|
|
if #showGraph model then
|
|
|
|
|
let
|
|
|
|
|
val model = AppWith.graphVisibility (model, false)
|
|
|
|
|
val drawMsg = DRAW_GRAPH (Vector.fromList [])
|
2024-09-27 08:27:53 +01:00
|
|
|
val drawMsg = [DRAW drawMsg]
|
2024-08-14 02:31:28 +01:00
|
|
|
in
|
2024-09-27 08:27:53 +01:00
|
|
|
(model, drawMsg)
|
2024-08-14 02:31:28 +01:00
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
let
|
|
|
|
|
val model = AppWith.graphVisibility (model, true)
|
|
|
|
|
val graphLines = GraphLines.generate model
|
|
|
|
|
val drawMsg = DRAW_GRAPH graphLines
|
2024-09-27 08:27:53 +01:00
|
|
|
val drawMsg = [DRAW drawMsg]
|
2024-08-14 02:31:28 +01:00
|
|
|
in
|
2024-09-27 08:27:53 +01:00
|
|
|
(model, drawMsg)
|
2024-08-14 02:31:28 +01:00
|
|
|
end
|
2024-08-08 23:43:38 +01:00
|
|
|
|
2024-08-29 00:05:30 +01:00
|
|
|
fun getSaveTrianglesMsg model =
|
|
|
|
|
let
|
|
|
|
|
val {triangles, ...} = model
|
|
|
|
|
val fileMsg = SAVE_TRIANGLES triangles
|
2024-09-27 08:27:53 +01:00
|
|
|
val fileMsg = [FILE fileMsg]
|
2024-08-29 00:05:30 +01:00
|
|
|
in
|
2024-09-27 08:27:53 +01:00
|
|
|
(model, fileMsg)
|
2024-08-29 00:05:30 +01:00
|
|
|
end
|
|
|
|
|
|
2024-09-27 08:27:53 +01:00
|
|
|
fun getLoadTrianglesMsg model =
|
|
|
|
|
(model, [FILE LOAD_TRIANGLES])
|
2024-08-30 02:34:24 +01:00
|
|
|
|
|
|
|
|
fun getExportTrianglesMsg model =
|
|
|
|
|
let
|
|
|
|
|
val {triangles, ...} = model
|
|
|
|
|
val fileMsg = EXPORT_TRIANGLES (#triangles model)
|
2024-09-27 08:27:53 +01:00
|
|
|
val fileMsg = [FILE fileMsg]
|
2024-08-30 02:34:24 +01:00
|
|
|
in
|
2024-09-27 08:27:53 +01:00
|
|
|
(model, fileMsg)
|
2024-08-30 02:34:24 +01:00
|
|
|
end
|
2024-08-29 05:21:04 +01:00
|
|
|
|
2024-08-29 05:38:58 +01:00
|
|
|
fun useTriangles (model, triangles) =
|
|
|
|
|
let
|
|
|
|
|
val model = AppWith.useTriangles (model, triangles)
|
|
|
|
|
val drawVec = Triangles.toVector model
|
|
|
|
|
val drawMsg = DRAW_TRIANGLES_AND_RESET_DOTS drawVec
|
2024-09-27 08:27:53 +01:00
|
|
|
val drawMsg = [DRAW drawMsg]
|
2024-08-29 05:38:58 +01:00
|
|
|
in
|
2024-09-27 08:27:53 +01:00
|
|
|
(model, drawMsg)
|
2024-08-29 05:38:58 +01:00
|
|
|
end
|
|
|
|
|
|
2024-09-27 08:27:53 +01:00
|
|
|
fun trianglesLoadError model = (model, [])
|
2024-08-29 05:38:58 +01:00
|
|
|
|
2024-09-25 10:17:57 +01:00
|
|
|
fun enterBrowseMode model =
|
|
|
|
|
let
|
|
|
|
|
val model = AppWith.mode (model, AppType.BROWSE_MODE)
|
2024-09-25 20:34:59 +01:00
|
|
|
(* todo: should draw modal window as well *)
|
2024-09-25 10:17:57 +01:00
|
|
|
val fileMsg = LOAD_FILES (#openFilePath model)
|
2024-09-27 08:27:53 +01:00
|
|
|
val fileMsg = [FILE fileMsg]
|
2024-09-25 10:17:57 +01:00
|
|
|
in
|
2024-09-27 08:27:53 +01:00
|
|
|
(model, fileMsg)
|
2024-09-25 10:17:57 +01:00
|
|
|
end
|
|
|
|
|
|
2024-09-27 10:06:21 +01:00
|
|
|
fun handleFileBrowserAndPathInNormalMode (model, fileBrowser, path) =
|
2024-09-27 08:27:53 +01:00
|
|
|
let val model = AppWith.fileBrowserAndPath (model, fileBrowser, path)
|
|
|
|
|
in (model, [])
|
2024-09-25 20:34:59 +01:00
|
|
|
end
|
|
|
|
|
|
2024-09-29 16:08:04 +01:00
|
|
|
fun updateNormalMode (model: app_type, inputMsg) =
|
|
|
|
|
case inputMsg of
|
|
|
|
|
MOUSE_MOVE {x = mouseX, y = mouseY} =>
|
|
|
|
|
let val model = AppWith.mousePosition (model, mouseX, mouseY)
|
|
|
|
|
in mouseMoveOrRelease model
|
|
|
|
|
end
|
|
|
|
|
| MOUSE_LEFT_RELEASE => mouseMoveOrRelease model
|
|
|
|
|
| MOUSE_LEFT_CLICK => mouseLeftClick model
|
|
|
|
|
| RESIZE_WINDOW {width, height} => resizeWindow (model, width, height)
|
|
|
|
|
| UNDO_ACTION => undoAction model
|
|
|
|
|
| REDO_ACTION => redoAction model
|
|
|
|
|
| KEY_G => toggleGraph model
|
|
|
|
|
| KEY_CTRL_S => getSaveTrianglesMsg model
|
|
|
|
|
| KEY_CTRL_L => getLoadTrianglesMsg model
|
|
|
|
|
| KEY_CTRL_E => getExportTrianglesMsg model
|
|
|
|
|
| KEY_CTRL_O => enterBrowseMode model
|
|
|
|
|
| ARROW_UP => moveArrowUp model
|
|
|
|
|
| ARROW_LEFT => moveArrowLeft model
|
|
|
|
|
| ARROW_RIGHT => moveArrowRight model
|
|
|
|
|
| ARROW_DOWN => moveArrowDown model
|
|
|
|
|
| KEY_ENTER => enterOrSpaceCoordinates model
|
|
|
|
|
| KEY_SPACE => enterOrSpaceCoordinates model
|
|
|
|
|
| USE_TRIANGLES triangles => useTriangles (model, triangles)
|
|
|
|
|
| TRIANGLES_LOAD_ERROR => trianglesLoadError model
|
|
|
|
|
| FILE_BROWSER_AND_PATH {fileBrowser, path} =>
|
|
|
|
|
handleFileBrowserAndPathInNormalMode (model, fileBrowser, path)
|
|
|
|
|
|
2024-09-29 12:45:13 +01:00
|
|
|
fun stringToVec
|
|
|
|
|
(pos, str, acc, startX, startY, windowWidth, windowHeight, r, g, b) =
|
2024-09-27 10:06:21 +01:00
|
|
|
if pos = String.size str then
|
|
|
|
|
acc
|
|
|
|
|
else
|
|
|
|
|
let
|
|
|
|
|
val chr = String.sub (str, pos)
|
|
|
|
|
val chrFun = Vector.sub (CozetteAscii.asciiTable, Char.ord chr)
|
|
|
|
|
val chrVec = chrFun
|
2024-09-29 12:45:13 +01:00
|
|
|
(startX, startY, 25.0, 25.0, windowWidth, windowHeight, r, g, b)
|
2024-09-27 10:06:21 +01:00
|
|
|
val acc = chrVec :: acc
|
|
|
|
|
in
|
|
|
|
|
stringToVec
|
2024-09-29 12:45:13 +01:00
|
|
|
( pos + 1
|
|
|
|
|
, str
|
|
|
|
|
, acc
|
|
|
|
|
, startX + 12
|
|
|
|
|
, startY
|
|
|
|
|
, windowWidth
|
|
|
|
|
, windowHeight
|
|
|
|
|
, r
|
|
|
|
|
, g
|
|
|
|
|
, b
|
|
|
|
|
)
|
2024-09-27 10:06:21 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
fun buildFileBrowserText
|
2024-09-29 12:45:13 +01:00
|
|
|
(pos, fileBrowser, acc, startY, windowWidth, windowHeight, selectedIdx) =
|
2024-09-27 10:06:21 +01:00
|
|
|
if pos = Vector.length fileBrowser then
|
|
|
|
|
Vector.concat acc
|
|
|
|
|
else
|
|
|
|
|
let
|
|
|
|
|
val item = Vector.sub (fileBrowser, pos)
|
|
|
|
|
val itemText =
|
|
|
|
|
case item of
|
|
|
|
|
IS_FILE str => str
|
|
|
|
|
| IS_FOLDER str => str
|
2024-09-29 12:45:13 +01:00
|
|
|
val acc =
|
|
|
|
|
if pos <> selectedIdx then
|
|
|
|
|
stringToVec
|
|
|
|
|
( 0
|
|
|
|
|
, itemText
|
|
|
|
|
, acc
|
|
|
|
|
, 10
|
|
|
|
|
, startY
|
|
|
|
|
, windowWidth
|
|
|
|
|
, windowHeight
|
|
|
|
|
, 0.0
|
|
|
|
|
, 0.0
|
|
|
|
|
, 0.0
|
|
|
|
|
)
|
|
|
|
|
else
|
|
|
|
|
stringToVec
|
|
|
|
|
( 0
|
|
|
|
|
, itemText
|
|
|
|
|
, acc
|
|
|
|
|
, 10
|
|
|
|
|
, startY
|
|
|
|
|
, windowWidth
|
|
|
|
|
, windowHeight
|
|
|
|
|
, 0.35
|
|
|
|
|
, 0.35
|
|
|
|
|
, 0.75
|
|
|
|
|
)
|
2024-09-27 10:06:21 +01:00
|
|
|
in
|
|
|
|
|
buildFileBrowserText
|
2024-09-29 12:45:13 +01:00
|
|
|
( pos + 1
|
|
|
|
|
, fileBrowser
|
|
|
|
|
, acc
|
|
|
|
|
, startY + 23
|
|
|
|
|
, windowWidth
|
|
|
|
|
, windowHeight
|
|
|
|
|
, selectedIdx
|
|
|
|
|
)
|
2024-09-27 10:06:21 +01:00
|
|
|
end
|
|
|
|
|
|
2024-09-29 16:08:04 +01:00
|
|
|
fun redrawFileBrowser (model: app_type) =
|
2024-09-27 10:06:21 +01:00
|
|
|
let
|
2024-09-29 16:08:04 +01:00
|
|
|
val {windowWidth, windowHeight, fileBrowser, fileBrowserIdx, ...} = model
|
2024-09-27 10:06:21 +01:00
|
|
|
val ww = Real32.fromInt windowWidth
|
|
|
|
|
val wh = Real32.fromInt windowHeight
|
2024-09-29 12:45:13 +01:00
|
|
|
val textVec = buildFileBrowserText
|
|
|
|
|
(0, fileBrowser, [], 10, ww, wh, fileBrowserIdx)
|
2024-09-27 10:06:21 +01:00
|
|
|
|
|
|
|
|
val drawMsg = DRAW_MODAL_TEXT textVec
|
|
|
|
|
in
|
|
|
|
|
(model, [DRAW drawMsg])
|
|
|
|
|
end
|
|
|
|
|
|
2024-09-29 16:08:04 +01:00
|
|
|
fun handleFileBrowserAndPathInBrowseMode (model, fileBrowser, path) =
|
|
|
|
|
let val model = AppWith.fileBrowserAndPath (model, fileBrowser, path)
|
|
|
|
|
in redrawFileBrowser model
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
fun browseModeArrowUp (model: app_type) =
|
|
|
|
|
let
|
|
|
|
|
val {fileBrowser, fileBrowserIdx, ...} = model
|
|
|
|
|
|
|
|
|
|
val fileBrowserIdx =
|
|
|
|
|
if fileBrowserIdx > 0 then fileBrowserIdx - 1
|
|
|
|
|
else Int.max (0, Vector.length fileBrowser - 1)
|
|
|
|
|
|
|
|
|
|
val model = AppWith.fileBrowserIdx (model, fileBrowserIdx)
|
|
|
|
|
in
|
|
|
|
|
redrawFileBrowser model
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
fun browseModeArrowDown (model: app_type) =
|
|
|
|
|
let
|
|
|
|
|
val {fileBrowser, fileBrowserIdx, ...} = model
|
|
|
|
|
|
|
|
|
|
val fileBrowserIdx =
|
|
|
|
|
if fileBrowserIdx = Vector.length fileBrowser - 1 then 0
|
|
|
|
|
else fileBrowserIdx + 1
|
|
|
|
|
|
|
|
|
|
val model = AppWith.fileBrowserIdx (model, fileBrowserIdx)
|
|
|
|
|
in
|
|
|
|
|
redrawFileBrowser model
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
fun updateBrowseMode (model: app_type, inputMsg) =
|
2024-08-08 00:50:36 +01:00
|
|
|
case inputMsg of
|
2024-09-29 16:08:04 +01:00
|
|
|
ARROW_UP => browseModeArrowUp model
|
|
|
|
|
| ARROW_DOWN => browseModeArrowDown model
|
2024-08-29 05:38:58 +01:00
|
|
|
| TRIANGLES_LOAD_ERROR => trianglesLoadError model
|
2024-09-29 16:08:04 +01:00
|
|
|
(* todo:
|
|
|
|
|
| ARROW_LEFT =>
|
|
|
|
|
| ARROW_RIGHT =>
|
|
|
|
|
| KEY_ENTER =>
|
|
|
|
|
| KEY_SPACE =>
|
|
|
|
|
*)
|
2024-09-25 20:34:59 +01:00
|
|
|
| FILE_BROWSER_AND_PATH {fileBrowser, path} =>
|
2024-09-29 16:08:04 +01:00
|
|
|
handleFileBrowserAndPathInBrowseMode (model, fileBrowser, path)
|
|
|
|
|
| _ => (model, [])
|
2024-09-25 08:08:15 +01:00
|
|
|
|
|
|
|
|
fun update (model: app_type, inputMsg) =
|
2024-09-25 10:17:57 +01:00
|
|
|
case #mode model of
|
|
|
|
|
NORMAL_MODE => updateNormalMode (model, inputMsg)
|
2024-09-29 16:08:04 +01:00
|
|
|
| BROWSE_MODE => updateBrowseMode (model, inputMsg)
|
2024-07-30 19:04:36 +01:00
|
|
|
end
|