diff --git a/dotscape b/dotscape index d2cbfdc..1f71638 100755 Binary files a/dotscape and b/dotscape differ diff --git a/fcore/app-with.sml b/fcore/app-with.sml index 950728f..d297c44 100644 --- a/fcore/app-with.sml +++ b/fcore/app-with.sml @@ -56,11 +56,6 @@ struct , redo } = app - val yAxis = Vector.sub (squares, newX) - val undoData = Vector.sub (yAxis, newY) - val undo = undoData :: undo - val redo = [] - val item = {r = r, g = g, b = b, a = a} val squares = updateSquares (squares, newX, newY, item) in @@ -91,6 +86,65 @@ struct } end + fun deleteSquare (app, deleteX, deleteY, arrowX, arrowY) = + let + val + { mode + , squares + , arrowX = _ + , arrowY = _ + , canvasWidth + , canvasHeight + , windowWidth + , windowHeight + , xClickPoints + , yClickPoints + + , showGraph + , mouseX + , mouseY + , openFilePath + , fileBrowser + , fileBrowserIdx + , r + , g + , b + , a + , modalNum + , undo + , redo + } = app + + val item = {r = 0, g = 0, b = 0, a = 0} + val squares = updateSquares (squares, deleteX, deleteY, item) + in + { mode = mode + , squares = squares + , arrowX = arrowX + , arrowY = arrowY + , canvasWidth = canvasWidth + , canvasHeight = canvasHeight + , windowWidth = windowWidth + , windowHeight = windowHeight + , xClickPoints = xClickPoints + , yClickPoints = yClickPoints + + , showGraph = showGraph + , mouseX = mouseX + , mouseY = mouseY + , openFilePath = openFilePath + , fileBrowser = fileBrowser + , fileBrowserIdx = fileBrowserIdx + , r = r + , g = g + , b = b + , a = a + , modalNum = modalNum + , undo = undo + , redo = redo + } + end + fun arrowX (app, arrowX) = let val diff --git a/fcore/normal-mode.sml b/fcore/normal-mode.sml index 672d87d..10b372c 100644 --- a/fcore/normal-mode.sml +++ b/fcore/normal-mode.sml @@ -180,6 +180,47 @@ struct in addCoordinates (model, arrowX, arrowY) end + fun deletePixel (model, hIdx, vIdx) = + let + val + { windowWidth + , windowHeight + , xClickPoints + , yClickPoints + , canvasWidth + , canvasHeight + , ... + } = model + + val xpos = Vector.sub (xClickPoints, hIdx) + val ypos = Vector.sub (yClickPoints, vIdx) + + val model = AppWith.deleteSquare (model, hIdx, vIdx, hIdx, vIdx) + val squares = #squares model + + val dotVec = getDotVecFromIndices (model, hIdx, vIdx) + + val maxSide = Int.max (canvasWidth, canvasHeight) + val squares = CollisionTree.toTriangles + ( windowWidth + , windowHeight + , squares + , maxSide + , canvasWidth + , canvasHeight + , xClickPoints + , yClickPoints + ) + val drawMsg = DRAW_SQUARES_AND_DOTS {squares = squares, dots = dotVec} + in + (model, [DRAW drawMsg]) + end + + fun backspace model = + let val {arrowX, arrowY, ...} = model + in deletePixel (model, arrowX, arrowY) + end + fun resizeWindow (model, width, height) = let val model = AppWith.windowResize (model, width, height) @@ -355,6 +396,7 @@ struct | ARROW_LEFT => moveArrowLeft model | ARROW_RIGHT => moveArrowRight model | ARROW_DOWN => moveArrowDown model + | KEY_BACKSPACE => backspace model | KEY_ENTER => enterOrSpaceCoordinates model | KEY_SPACE => enterOrSpaceCoordinates model | FILE_BROWSER_AND_PATH {fileBrowser, path} => diff --git a/ffi/glfw-input.c b/ffi/glfw-input.c index 8c93d06..6da5b7d 100644 --- a/ffi/glfw-input.c +++ b/ffi/glfw-input.c @@ -29,6 +29,7 @@ int KEY_UP = GLFW_KEY_UP; int KEY_LEFT = GLFW_KEY_LEFT; int KEY_RIGHT = GLFW_KEY_RIGHT; int KEY_DOWN = GLFW_KEY_DOWN; +int KEY_BACKSPACE = GLFW_KEY_BACKSPACE; int KEY_0 = GLFW_KEY_0; int KEY_1 = GLFW_KEY_1; diff --git a/ffi/glfw-input.sml b/ffi/glfw-input.sml index db5a3ab..fe604e4 100644 --- a/ffi/glfw-input.sml +++ b/ffi/glfw-input.sml @@ -74,6 +74,8 @@ struct _symbol "KEY_RIGHT" public : ( unit -> int ) * ( int -> unit ); val (KEY_DOWN, _) = _symbol "KEY_DOWN" public : ( unit -> int ) * ( int -> unit ); + val (KEY_BACKSPACE, _) = + _symbol "KEY_BACKSPACE" public : ( unit -> int ) * ( int -> unit ); val (KEY_0, _) = _symbol "KEY_0" public : ( unit -> int ) * ( int -> unit ); diff --git a/imperative-shell/input-callbacks.sml b/imperative-shell/input-callbacks.sml index 8e54d12..c28d8cf 100644 --- a/imperative-shell/input-callbacks.sml +++ b/imperative-shell/input-callbacks.sml @@ -100,6 +100,11 @@ struct andalso mods = 0x0 then Mailbox.send (mailbox, ARROW_DOWN) + else if + key = Input.KEY_BACKSPACE () andalso action = Input.PRESS () + andalso mods = 0x0 + then + Mailbox.send (mailbox, KEY_BACKSPACE) else if key = Input.KEY_ENTER () andalso action = Input.PRESS () andalso mods = 0x0 diff --git a/message-types/input-msg.sml b/message-types/input-msg.sml index b1f8033..baa282e 100644 --- a/message-types/input-msg.sml +++ b/message-types/input-msg.sml @@ -14,6 +14,7 @@ struct | KEY_A | KEY_W | KEY_H + | KEY_BACKSPACE | KEY_CTRL_S | KEY_CTRL_L | KEY_CTRL_E