diff --git a/dotscape b/dotscape index 23c1f32..0b83805 100755 Binary files a/dotscape and b/dotscape differ diff --git a/fcore/app-with.sml b/fcore/app-with.sml index dafb00a..364677e 100644 --- a/fcore/app-with.sml +++ b/fcore/app-with.sml @@ -19,62 +19,6 @@ struct Vector.tabulate (maxPoints, fn _ => {r = 0, g = 0, b = 0, a = 0})) end - fun squares (app, newSquares) = - let - val - { mode - , squares - , arrowX - , arrowY - , canvasWidth - , canvasHeight - , windowWidth - , windowHeight - , xClickPoints - , yClickPoints - - , showGraph - , mouseX - , mouseY - , openFilePath - , fileBrowser - , fileBrowserIdx - , r - , g - , b - , a - , layer - , layerTree - , modalNum - } = app - in - { mode = mode - , squares = newSquares - , 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 - , layer = layer - , layerTree = layerTree - , modalNum = modalNum - } - end - fun arrowX (app, arrowX) = let val diff --git a/fcore/move-mode.sml b/fcore/move-mode.sml index ed7eae9..b7134f9 100644 --- a/fcore/move-mode.sml +++ b/fcore/move-mode.sml @@ -20,17 +20,19 @@ struct , canvasHeight , windowWidth , windowHeight - , squares + , layerTree , xClickPoints , yClickPoints , ... } = model val maxSide = Int.max (canvasWidth, canvasHeight) + val grid = LayerTree.flatten (maxSide, layerTree) + val squares = CollisionTree.toTriangles ( windowWidth , windowHeight - , squares + , grid , maxSide , canvasWidth , canvasHeight @@ -51,71 +53,61 @@ struct fun makeBlankXAxis length = Vector.tabulate (length, fn _ => makeBlankYAxis length) - fun moveImageUp (model: app_type) = + fun finishMove (model: app_type, newGrid) = let - val {squares, ...} = model - - val squares = - Vector.mapi - (fn (_, yAxis) => - Vector.mapi - (fn (yIdx, pixel) => - if yIdx = Vector.length yAxis - 1 then blankPixel - else Vector.sub (yAxis, yIdx + 1)) yAxis) squares - - val model = AppWith.squares (model, squares) + val {layer, layerTree, arrowX, arrowY, ...} = model + val layerTree = LayerTree.insert (layer, newGrid, layerTree) + val model = AppWith.layerTree (model, layerTree, arrowX, arrowY) in getDrawMsg model end - fun moveImageDown (model: app_type) = + fun moveImage (model: app_type, fMove) = let - val {squares, ...} = model - - val squares = - Vector.mapi - (fn (_, yAxis) => - Vector.mapi - (fn (yIdx, pixel) => - if yIdx = 0 then blankPixel else Vector.sub (yAxis, yIdx - 1)) - yAxis) squares - - val model = AppWith.squares (model, squares) + val {layer, layerTree, ...} = model in - getDrawMsg model + case LayerTree.get (layer, layerTree) of + SOME grid => finishMove (model, fMove grid) + | NONE => (model, []) end - fun moveImageLeft (model: app_type) = - let - val {squares, ...} = model + fun helpMoveImageUp grid = + Vector.mapi + (fn (_, yAxis) => + Vector.mapi + (fn (yIdx, pixel) => + if yIdx = Vector.length yAxis - 1 then blankPixel + else Vector.sub (yAxis, yIdx + 1)) yAxis) grid - val squares = - Vector.mapi - (fn (idx, yAxis) => - if idx + 1 = Vector.length squares then - makeBlankYAxis (Vector.length squares) - else - Vector.sub (squares, idx + 1)) squares + fun moveImageUp (model: app_type) = moveImage (model, helpMoveImageUp) - val model = AppWith.squares (model, squares) - in - getDrawMsg model - end + fun helpMoveImageDown grid = + Vector.mapi + (fn (_, yAxis) => + Vector.mapi + (fn (yIdx, pixel) => + if yIdx = 0 then blankPixel else Vector.sub (yAxis, yIdx - 1)) + yAxis) grid - fun moveImageRight (model: app_type) = - let - val {squares, ...} = model + fun moveImageDown (model: app_type) = moveImage (model, helpMoveImageDown) - val squares = - Vector.mapi - (fn (idx, yAxis) => - if idx = 0 then makeBlankYAxis (Vector.length squares) - else Vector.sub (squares, idx - 1)) squares + fun helpMoveImageLeft grid = + Vector.mapi + (fn (idx, yAxis) => + if idx + 1 = Vector.length grid then + makeBlankYAxis (Vector.length grid) + else + Vector.sub (grid, idx + 1)) grid - val model = AppWith.squares (model, squares) - in - getDrawMsg model - end + fun moveImageLeft (model: app_type) = moveImage (model, helpMoveImageLeft) + + fun helpMoveImageRight grid = + Vector.mapi + (fn (idx, yAxis) => + if idx = 0 then makeBlankYAxis (Vector.length grid) + else Vector.sub (grid, idx - 1)) grid + + fun moveImageRight (model: app_type) = moveImage (model, helpMoveImageRight) fun enterNormalMode model = let val model = AppWith.mode (model, AppType.NORMAL_MODE)