progress towards toggling graph
This commit is contained in:
@@ -4,8 +4,10 @@
|
||||
int PRESS = GLFW_PRESS;
|
||||
int RELEASE = GLFW_RELEASE;
|
||||
int LEFT_MOUSE_BUTTON = GLFW_MOUSE_BUTTON_1;
|
||||
int KEY_Z = GLFW_KEY_Z;
|
||||
|
||||
int KEY_G = GLFW_KEY_G;
|
||||
int KEY_Y = GLFW_KEY_Y;
|
||||
int KEY_Z = GLFW_KEY_Z;
|
||||
|
||||
// Calls function exported from SML
|
||||
void mouseMoveCallback(GLFWwindow *window, double xpos, double ypos) {
|
||||
|
||||
@@ -31,8 +31,10 @@ struct
|
||||
_export "mltonKeyCallback" public : (int * int * int * int -> unit) -> unit;
|
||||
val setKeyCallback = _import "setKeyCallback" public reentrant : window -> unit;
|
||||
|
||||
val (KEY_Z, _) =
|
||||
_symbol "KEY_Z" public : ( unit -> int ) * ( int -> unit );
|
||||
val (KEY_G, _) =
|
||||
_symbol "KEY_G" public : ( unit -> int ) * ( int -> unit );
|
||||
val (KEY_Y, _) =
|
||||
_symbol "KEY_Y" public : ( unit -> int ) * ( int -> unit );
|
||||
val (KEY_Z, _) =
|
||||
_symbol "KEY_Z" public : ( unit -> int ) * ( int -> unit );
|
||||
end
|
||||
|
||||
@@ -23,6 +23,7 @@ struct
|
||||
, redo = []
|
||||
, mouseX = 0.0
|
||||
, mouseY = 0.0
|
||||
, showGraph = true
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ sig
|
||||
, redo: (Real32.real * Real32.real) list
|
||||
, mouseX: Real32.real
|
||||
, mouseY: Real32.real
|
||||
, showGraph: bool
|
||||
}
|
||||
end
|
||||
|
||||
@@ -65,5 +66,6 @@ struct
|
||||
, redo: (Real32.real * Real32.real) list
|
||||
, mouseX: Real32.real
|
||||
, mouseY: Real32.real
|
||||
, showGraph: bool
|
||||
}
|
||||
end
|
||||
|
||||
@@ -174,7 +174,26 @@ struct
|
||||
in
|
||||
(model, drawMsg)
|
||||
end)
|
||||
| [] => (* Nothing to redo. *) (model, NO_DRAW)
|
||||
| [] =>
|
||||
(* Nothing to redo. *)
|
||||
(model, NO_DRAW)
|
||||
|
||||
fun toggleGraph (model: app_type) =
|
||||
if #showGraph model then
|
||||
let
|
||||
val model = AppWith.graphVisibility (model, false)
|
||||
val drawMsg = DRAW_GRAPH (Vector.fromList [])
|
||||
in
|
||||
(model, drawMsg)
|
||||
end
|
||||
else
|
||||
let
|
||||
val model = AppWith.graphVisibility (model, true)
|
||||
val graphLines = GraphLines.generate model
|
||||
val drawMsg = DRAW_GRAPH graphLines
|
||||
in
|
||||
(model, drawMsg)
|
||||
end
|
||||
|
||||
fun update (model: app_type, inputMsg) =
|
||||
case inputMsg of
|
||||
@@ -187,4 +206,5 @@ struct
|
||||
| RESIZE_WINDOW {width, height} => resizeWindow (model, width, height)
|
||||
| UNDO_ACTION => undoAction model
|
||||
| REDO_ACTION => redoAction model
|
||||
| KEY_G => toggleGraph model
|
||||
end
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
signature APP_WITH =
|
||||
sig
|
||||
val graphVisibility: AppType.app_type * bool -> AppType.app_type
|
||||
|
||||
val windowResize: AppType.app_type * int * int -> AppType.app_type
|
||||
|
||||
val mousePosition: AppType.app_type * Real32.real * Real32.real
|
||||
@@ -59,6 +61,7 @@ struct
|
||||
, redo = _
|
||||
, mouseX
|
||||
, mouseY
|
||||
, showGraph
|
||||
} = app
|
||||
|
||||
val newUndo = newUndoHd :: undo
|
||||
@@ -73,6 +76,7 @@ struct
|
||||
, windowHeight = windowHeight
|
||||
, mouseX = mouseX
|
||||
, mouseY = mouseY
|
||||
, showGraph = showGraph
|
||||
}
|
||||
end
|
||||
|
||||
@@ -89,6 +93,7 @@ struct
|
||||
, redo = _
|
||||
, mouseX
|
||||
, mouseY
|
||||
, showGraph
|
||||
} = app
|
||||
|
||||
val newTriangle = {x1 = x1, y1 = y1, x2 = x2, y2 = y2, x3 = x3, y3 = y3}
|
||||
@@ -105,6 +110,7 @@ struct
|
||||
, windowHeight = windowHeight
|
||||
, mouseX = mouseX
|
||||
, mouseY = mouseY
|
||||
, showGraph = showGraph
|
||||
}
|
||||
end
|
||||
|
||||
@@ -123,6 +129,7 @@ struct
|
||||
, redo
|
||||
, mouseX
|
||||
, mouseY
|
||||
, showGraph
|
||||
} = app
|
||||
|
||||
val xClickPoints = ClickPoints.generate (wStart, wFinish)
|
||||
@@ -138,6 +145,7 @@ struct
|
||||
, redo = redo
|
||||
, mouseX = mouseX
|
||||
, mouseY = mouseY
|
||||
, showGraph = showGraph
|
||||
}
|
||||
end
|
||||
|
||||
@@ -177,6 +185,7 @@ struct
|
||||
, windowHeight
|
||||
, undo
|
||||
, redo
|
||||
, showGraph
|
||||
} = app
|
||||
in
|
||||
{ mouseX = mouseX
|
||||
@@ -189,6 +198,7 @@ struct
|
||||
, windowHeight = windowHeight
|
||||
, undo = undo
|
||||
, redo = redo
|
||||
, showGraph = showGraph
|
||||
}
|
||||
end
|
||||
|
||||
@@ -206,6 +216,7 @@ struct
|
||||
, redo
|
||||
, mouseX
|
||||
, mouseY
|
||||
, showGraph
|
||||
} = app
|
||||
|
||||
val newUndo =
|
||||
@@ -225,6 +236,7 @@ struct
|
||||
, windowHeight = windowHeight
|
||||
, mouseX = mouseX
|
||||
, mouseY = mouseY
|
||||
, showGraph = showGraph
|
||||
}
|
||||
end
|
||||
|
||||
@@ -242,6 +254,7 @@ struct
|
||||
, redo
|
||||
, mouseX
|
||||
, mouseY
|
||||
, showGraph
|
||||
} = app
|
||||
|
||||
val newUndo = newUndoHd :: undo
|
||||
@@ -260,6 +273,37 @@ struct
|
||||
, windowHeight = windowHeight
|
||||
, mouseX = mouseX
|
||||
, mouseY = mouseY
|
||||
, showGraph = showGraph
|
||||
}
|
||||
end
|
||||
|
||||
fun graphVisibility (app: app_type, shouldShowGraph) =
|
||||
let
|
||||
val
|
||||
{ triangleStage
|
||||
, triangles
|
||||
, xClickPoints
|
||||
, yClickPoints
|
||||
, windowWidth
|
||||
, windowHeight
|
||||
, undo
|
||||
, redo
|
||||
, mouseX
|
||||
, mouseY
|
||||
, showGraph = _
|
||||
} = app
|
||||
in
|
||||
{ showGraph = shouldShowGraph
|
||||
, triangleStage = triangleStage
|
||||
, triangles = triangles
|
||||
, undo = undo
|
||||
, redo = redo
|
||||
, xClickPoints = xClickPoints
|
||||
, yClickPoints = yClickPoints
|
||||
, windowWidth = windowWidth
|
||||
, windowHeight = windowHeight
|
||||
, mouseX = mouseX
|
||||
, mouseY = mouseY
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -37,6 +37,10 @@ struct
|
||||
then
|
||||
(* ctrl-y *)
|
||||
Mailbox.send (mailbox, REDO_ACTION)
|
||||
else if
|
||||
key = Input.KEY_G () andalso action <> Input.RELEASE () andalso mods = 0x0
|
||||
then
|
||||
Mailbox.send (mailbox, KEY_G)
|
||||
else
|
||||
()
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ sig
|
||||
| DRAW_TRIANGLES_AND_BUTTONS of
|
||||
{triangles: Real32.real vector, buttons: Real32.real vector}
|
||||
| DRAW_TRIANGLES_AND_RESET_BUTTONS of Real32.real vector
|
||||
| DRAW_GRAPH of Real32.real vector
|
||||
| RESIZE_TRIANGLES_BUTTONS_AND_GRAPH of
|
||||
{triangles: Real32.real vector, graphLines: Real32.real vector}
|
||||
| CLEAR_BUTTONS
|
||||
@@ -18,6 +19,7 @@ struct
|
||||
| DRAW_TRIANGLES_AND_BUTTONS of
|
||||
{triangles: Real32.real vector, buttons: Real32.real vector}
|
||||
| DRAW_TRIANGLES_AND_RESET_BUTTONS of Real32.real vector
|
||||
| DRAW_GRAPH of Real32.real vector
|
||||
| RESIZE_TRIANGLES_BUTTONS_AND_GRAPH of
|
||||
{triangles: Real32.real vector, graphLines: Real32.real vector}
|
||||
| CLEAR_BUTTONS
|
||||
|
||||
@@ -7,6 +7,7 @@ sig
|
||||
| RESIZE_WINDOW of {width: int, height: int}
|
||||
| UNDO_ACTION
|
||||
| REDO_ACTION
|
||||
| KEY_G
|
||||
end
|
||||
|
||||
structure InputMessage :> INPUT_MESSAGE =
|
||||
@@ -18,4 +19,5 @@ struct
|
||||
| RESIZE_WINDOW of {width: int, height: int}
|
||||
| UNDO_ACTION
|
||||
| REDO_ACTION
|
||||
| KEY_G
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user