change 'move-mode.sml' to use layer tree everywhere instead of squares
This commit is contained in:
@@ -19,62 +19,6 @@ struct
|
|||||||
Vector.tabulate (maxPoints, fn _ => {r = 0, g = 0, b = 0, a = 0}))
|
Vector.tabulate (maxPoints, fn _ => {r = 0, g = 0, b = 0, a = 0}))
|
||||||
end
|
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) =
|
fun arrowX (app, arrowX) =
|
||||||
let
|
let
|
||||||
val
|
val
|
||||||
|
|||||||
@@ -20,17 +20,19 @@ struct
|
|||||||
, canvasHeight
|
, canvasHeight
|
||||||
, windowWidth
|
, windowWidth
|
||||||
, windowHeight
|
, windowHeight
|
||||||
, squares
|
, layerTree
|
||||||
, xClickPoints
|
, xClickPoints
|
||||||
, yClickPoints
|
, yClickPoints
|
||||||
, ...
|
, ...
|
||||||
} = model
|
} = model
|
||||||
|
|
||||||
val maxSide = Int.max (canvasWidth, canvasHeight)
|
val maxSide = Int.max (canvasWidth, canvasHeight)
|
||||||
|
val grid = LayerTree.flatten (maxSide, layerTree)
|
||||||
|
|
||||||
val squares = CollisionTree.toTriangles
|
val squares = CollisionTree.toTriangles
|
||||||
( windowWidth
|
( windowWidth
|
||||||
, windowHeight
|
, windowHeight
|
||||||
, squares
|
, grid
|
||||||
, maxSide
|
, maxSide
|
||||||
, canvasWidth
|
, canvasWidth
|
||||||
, canvasHeight
|
, canvasHeight
|
||||||
@@ -51,71 +53,61 @@ struct
|
|||||||
fun makeBlankXAxis length =
|
fun makeBlankXAxis length =
|
||||||
Vector.tabulate (length, fn _ => makeBlankYAxis length)
|
Vector.tabulate (length, fn _ => makeBlankYAxis length)
|
||||||
|
|
||||||
fun moveImageUp (model: app_type) =
|
fun finishMove (model: app_type, newGrid) =
|
||||||
let
|
let
|
||||||
val {squares, ...} = model
|
val {layer, layerTree, arrowX, arrowY, ...} = model
|
||||||
|
val layerTree = LayerTree.insert (layer, newGrid, layerTree)
|
||||||
val squares =
|
val model = AppWith.layerTree (model, layerTree, arrowX, arrowY)
|
||||||
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)
|
|
||||||
in
|
in
|
||||||
getDrawMsg model
|
getDrawMsg model
|
||||||
end
|
end
|
||||||
|
|
||||||
fun moveImageDown (model: app_type) =
|
fun moveImage (model: app_type, fMove) =
|
||||||
let
|
let
|
||||||
val {squares, ...} = model
|
val {layer, layerTree, ...} = 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)
|
|
||||||
in
|
in
|
||||||
getDrawMsg model
|
case LayerTree.get (layer, layerTree) of
|
||||||
|
SOME grid => finishMove (model, fMove grid)
|
||||||
|
| NONE => (model, [])
|
||||||
end
|
end
|
||||||
|
|
||||||
fun moveImageLeft (model: app_type) =
|
fun helpMoveImageUp grid =
|
||||||
let
|
Vector.mapi
|
||||||
val {squares, ...} = model
|
(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 =
|
fun moveImageUp (model: app_type) = moveImage (model, helpMoveImageUp)
|
||||||
Vector.mapi
|
|
||||||
(fn (idx, yAxis) =>
|
|
||||||
if idx + 1 = Vector.length squares then
|
|
||||||
makeBlankYAxis (Vector.length squares)
|
|
||||||
else
|
|
||||||
Vector.sub (squares, idx + 1)) squares
|
|
||||||
|
|
||||||
val model = AppWith.squares (model, squares)
|
fun helpMoveImageDown grid =
|
||||||
in
|
Vector.mapi
|
||||||
getDrawMsg model
|
(fn (_, yAxis) =>
|
||||||
end
|
Vector.mapi
|
||||||
|
(fn (yIdx, pixel) =>
|
||||||
|
if yIdx = 0 then blankPixel else Vector.sub (yAxis, yIdx - 1))
|
||||||
|
yAxis) grid
|
||||||
|
|
||||||
fun moveImageRight (model: app_type) =
|
fun moveImageDown (model: app_type) = moveImage (model, helpMoveImageDown)
|
||||||
let
|
|
||||||
val {squares, ...} = model
|
|
||||||
|
|
||||||
val squares =
|
fun helpMoveImageLeft grid =
|
||||||
Vector.mapi
|
Vector.mapi
|
||||||
(fn (idx, yAxis) =>
|
(fn (idx, yAxis) =>
|
||||||
if idx = 0 then makeBlankYAxis (Vector.length squares)
|
if idx + 1 = Vector.length grid then
|
||||||
else Vector.sub (squares, idx - 1)) squares
|
makeBlankYAxis (Vector.length grid)
|
||||||
|
else
|
||||||
|
Vector.sub (grid, idx + 1)) grid
|
||||||
|
|
||||||
val model = AppWith.squares (model, squares)
|
fun moveImageLeft (model: app_type) = moveImage (model, helpMoveImageLeft)
|
||||||
in
|
|
||||||
getDrawMsg model
|
fun helpMoveImageRight grid =
|
||||||
end
|
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 =
|
fun enterNormalMode model =
|
||||||
let val model = AppWith.mode (model, AppType.NORMAL_MODE)
|
let val model = AppWith.mode (model, AppType.NORMAL_MODE)
|
||||||
|
|||||||
Reference in New Issue
Block a user