change 'move-mode.sml' to use layer tree everywhere instead of squares

This commit is contained in:
2025-08-09 09:57:19 +01:00
parent 6a39f43916
commit 21624aee0d
3 changed files with 45 additions and 109 deletions

View File

@@ -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)