diff --git a/dotscape b/dotscape index 1ce6a99..496043d 100755 Binary files a/dotscape and b/dotscape differ diff --git a/fcore/app-with.sml b/fcore/app-with.sml index 78c88d0..a1cade8 100644 --- a/fcore/app-with.sml +++ b/fcore/app-with.sml @@ -999,4 +999,62 @@ struct , modalNum = 0 } end + + fun useLayerTree (app: app_type, layerTree, canvasWidth, canvasHeight) : + app_type = + let + val + { mode + , mouseX + , mouseY + , xClickPoints + , yClickPoints + , windowWidth + , windowHeight + , arrowX = _ + , arrowY = _ + , canvasWidth = _ + , canvasHeight = _ + + , showGraph + , openFilePath + , fileBrowser + , fileBrowserIdx + , r + , g + , b + , a + , layer + , layerTree = _ + , modalNum + } = app + + val arrowX = 0 + val arrowY = 0 + in + { mode = mode + , mouseX = mouseX + , mouseY = mouseY + , arrowX = arrowX + , arrowY = arrowY + , canvasWidth = canvasWidth + , canvasHeight = canvasHeight + , windowWidth = windowWidth + , windowHeight = windowHeight + , xClickPoints = xClickPoints + , yClickPoints = yClickPoints + + , showGraph = showGraph + , openFilePath = openFilePath + , fileBrowser = fileBrowser + , fileBrowserIdx = fileBrowserIdx + , r = r + , g = g + , b = b + , a = a + , layer = layer + , layerTree = layerTree + , modalNum = modalNum + } + end end diff --git a/fcore/browse-mode.sml b/fcore/browse-mode.sml index 60470f3..27ae264 100644 --- a/fcore/browse-mode.sml +++ b/fcore/browse-mode.sml @@ -161,7 +161,5 @@ struct | FILE_BROWSER_AND_PATH {fileBrowser, path} => handleFileBrowserAndPathInBrowseMode (model, fileBrowser, path) | SQUARES_LOAD_ERROR => CommonUpdate.squaresLoadError model - | USE_SQUARES squares => - CommonUpdate.useSquaresInNormalMode (model, squares) | _ => (model, []) end diff --git a/fcore/normal-mode.sml b/fcore/normal-mode.sml index 6e451d3..a8f88bf 100644 --- a/fcore/normal-mode.sml +++ b/fcore/normal-mode.sml @@ -134,36 +134,25 @@ struct fun realToInt x = Real32.toInt IEEEReal.TO_NEAREST x - fun changePixel (model: app_type, hIdx, vIdx, pixel) = + fun getDrawMessage (model: app_type) = let val - { windowWidth + { canvasWidth + , canvasHeight + , layerTree + , windowWidth , windowHeight , xClickPoints , yClickPoints - , canvasWidth - , canvasHeight - , layer - , layerTree - , r - , g - , b - , a + , arrowX + , arrowY , ... } = model val maxSide = Int.max (canvasWidth, canvasHeight) - - val xpos = Vector.sub (xClickPoints, hIdx) - val ypos = Vector.sub (yClickPoints, vIdx) - - val layerTree = LayerTree.addPixel - (layer, hIdx, vIdx, maxSide, pixel, layerTree) - val model = AppWith.layerTree (model, layerTree, hIdx, vIdx) - val squares = LayerTree.flatten (maxSide, layerTree) - val dotVec = getDotVecFromIndices (model, hIdx, vIdx) + val dotVec = getDotVecFromIndices (model, arrowX, arrowY) val squares = CollisionTree.toTriangles ( windowWidth @@ -180,6 +169,19 @@ struct (model, [DRAW drawMsg]) end + fun changePixel (model: app_type, hIdx, vIdx, pixel) = + let + val {canvasWidth, canvasHeight, layer, layerTree, ...} = model + + val maxSide = Int.max (canvasWidth, canvasHeight) + + val layerTree = LayerTree.addPixel + (layer, hIdx, vIdx, maxSide, pixel, layerTree) + val model = AppWith.layerTree (model, layerTree, hIdx, vIdx) + in + getDrawMessage model + end + fun addPixel (model: app_type, hIdx, vIdx) = let val {r, g, b, a, ...} = model @@ -332,8 +334,13 @@ struct updateCanvas (model, canvasWidth, canvasHeight) end - fun useSquares (model, squares, canvasWidth, canvasHeight) = - raise Fail "todo: reimplement" + fun useLayers (model, layerTree, canvasWidth, canvasHeight) = + let + val model = + AppWith.layerTree (model, layerTree, canvasWidth, canvasHeight) + in + getDrawMessage model + end fun enterBrowseMode model = let @@ -382,8 +389,8 @@ struct | KEY_CTRL_L => CommonUpdate.getLoadSquaresMsg model | KEY_CTRL_E => CommonUpdate.getExportSquaresMsg model | KEY_CTRL_C => CommonUpdate.getCollisionMsg model - | USE_SQUARES {squares, canvasWidth, canvasHeight} => - useSquares (model, squares, canvasWidth, canvasHeight) + | USE_LAYERS {tree, canvasWidth, canvasHeight} => + useLayers (model, tree, canvasWidth, canvasHeight) | SQUARES_LOAD_ERROR => CommonUpdate.squaresLoadError model | KEY_CTRL_O => enterBrowseMode model | ARROW_UP => moveArrowUp model diff --git a/fcore/parser/parser.sml b/fcore/parser/parser.sml index abc7d16..7c5707c 100644 --- a/fcore/parser/parser.sml +++ b/fcore/parser/parser.sml @@ -42,7 +42,7 @@ struct (tl, canvasWidth, canvasHeight, tree, 1) in case tokens of - [T.R_BRACE] => SOME tree + [T.R_BRACE] => SOME (canvasWidth, canvasHeight, tree) | _ => NONE end | _ => NONE) diff --git a/imperative-shell/file-thread.sml b/imperative-shell/file-thread.sml index a0a97b3..fb0ef7c 100644 --- a/imperative-shell/file-thread.sml +++ b/imperative-shell/file-thread.sml @@ -25,12 +25,15 @@ struct val () = TextIO.closeIn io in case Parser.parse str of - SOME (canvasWidth, canvasHeight, grid) => - Mailbox.send (inputMailbox, USE_SQUARES - { squares = grid - , canvasWidth = canvasWidth - , canvasHeight = canvasHeight - }) + SOME (canvasWidth, canvasHeight, tree) => + Mailbox.send + ( inputMailbox + , USE_LAYERS + { tree = tree + , canvasWidth = canvasWidth + , canvasHeight = canvasHeight + } + ) | NONE => () end diff --git a/message-types/input-msg.sml b/message-types/input-msg.sml index e8929a1..dc71809 100644 --- a/message-types/input-msg.sml +++ b/message-types/input-msg.sml @@ -31,11 +31,7 @@ struct | ARROW_DOWN | KEY_ENTER | KEY_SPACE - | USE_SQUARES of - { squares: {r: int, g: int, b: int, a: int} vector vector - , canvasWidth: int - , canvasHeight: int - } + | USE_LAYERS of {tree: LayerTree.t, canvasWidth: int, canvasHeight: int} | SQUARES_LOAD_ERROR | FILE_BROWSER_AND_PATH of {fileBrowser: AppType.file_browser_item vector, path: string}