add functionality to delete pixel
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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} =>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -14,6 +14,7 @@ struct
|
||||
| KEY_A
|
||||
| KEY_W
|
||||
| KEY_H
|
||||
| KEY_BACKSPACE
|
||||
| KEY_CTRL_S
|
||||
| KEY_CTRL_L
|
||||
| KEY_CTRL_E
|
||||
|
||||
Reference in New Issue
Block a user