fix loading to use and return layer tree

This commit is contained in:
2025-08-09 11:42:37 +01:00
parent 940e4429a7
commit 99a47a410f
7 changed files with 99 additions and 37 deletions

View File

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