diff --git a/dotscape b/dotscape index 4fc28fd..86ba19b 100755 Binary files a/dotscape and b/dotscape differ diff --git a/ffi/glfw-input.c b/ffi/glfw-input.c index 5538bf6..756094c 100644 --- a/ffi/glfw-input.c +++ b/ffi/glfw-input.c @@ -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) { diff --git a/ffi/glfw-input.sml b/ffi/glfw-input.sml index f829574..ab59740 100644 --- a/ffi/glfw-input.sml +++ b/ffi/glfw-input.sml @@ -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 diff --git a/functional-core/app-init.sml b/functional-core/app-init.sml index 0bc5b17..c4d3ac2 100644 --- a/functional-core/app-init.sml +++ b/functional-core/app-init.sml @@ -23,6 +23,7 @@ struct , redo = [] , mouseX = 0.0 , mouseY = 0.0 + , showGraph = true } end diff --git a/functional-core/app-type.sml b/functional-core/app-type.sml index bda5e45..38d7045 100644 --- a/functional-core/app-type.sml +++ b/functional-core/app-type.sml @@ -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 diff --git a/functional-core/app-update.sml b/functional-core/app-update.sml index 2ac9ad4..da721df 100644 --- a/functional-core/app-update.sml +++ b/functional-core/app-update.sml @@ -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 diff --git a/functional-core/app-with.sml b/functional-core/app-with.sml index b8484a6..d784dda 100644 --- a/functional-core/app-with.sml +++ b/functional-core/app-with.sml @@ -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 diff --git a/imperative-shell/input-callbacks.sml b/imperative-shell/input-callbacks.sml index 5122021..1f7c239 100644 --- a/imperative-shell/input-callbacks.sml +++ b/imperative-shell/input-callbacks.sml @@ -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 () diff --git a/message-types/draw-msg.sml b/message-types/draw-msg.sml index 4c048c0..a2041bc 100644 --- a/message-types/draw-msg.sml +++ b/message-types/draw-msg.sml @@ -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 diff --git a/message-types/input-msg.sml b/message-types/input-msg.sml index 4f8b6f2..fde5675 100644 --- a/message-types/input-msg.sml +++ b/message-types/input-msg.sml @@ -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