update 'changeCanvasWidth/Height' functions to use layer tree

This commit is contained in:
2025-08-09 10:11:37 +01:00
parent 21624aee0d
commit ab888f8410
3 changed files with 34 additions and 19 deletions

BIN
dotscape

Binary file not shown.

View File

@@ -875,7 +875,7 @@ struct
}
end
fun canvasWidth (app: app_type, newCanvasWidth) =
fun canvasWidth (app: app_type, newCanvasWidth, newLayerTree) =
let
val
{ mode
@@ -900,11 +900,10 @@ struct
, b
, a
, layer
, layerTree
, layerTree = _
, modalNum
} = app
val squares = changeSquaresSize (squares, newCanvasWidth, canvasHeight)
val arrowX = Int.min (arrowX, newCanvasWidth)
val (xClickPoints, yClickPoints) =
ClickPoints.generate
@@ -932,12 +931,12 @@ struct
, b = b
, a = a
, layer = layer
, layerTree = layerTree
, layerTree = newLayerTree
, modalNum = 0
}
end
fun canvasHeight (app: app_type, newCanvasHeight) =
fun canvasHeight (app: app_type, newCanvasHeight, newLayerTree) =
let
val
{ mode
@@ -962,11 +961,10 @@ struct
, b
, a
, layer
, layerTree
, layerTree = _
, modalNum
} = app
val squares = changeSquaresSize (squares, canvasWidth, newCanvasHeight)
val arrowY = Int.min (arrowY, newCanvasHeight)
val (xClickPoints, yClickPoints) =
ClickPoints.generate
@@ -994,7 +992,7 @@ struct
, b = b
, a = a
, layer = layer
, layerTree = layerTree
, layerTree = newLayerTree
, modalNum = 0
}
end

View File

@@ -251,12 +251,18 @@ struct
fun selectCursorColour (model: app_type) =
let
val {squares, arrowX, arrowY, ...} = model
val yAxis = Vector.sub (squares, arrowX)
val {r, g, b, a} = Vector.sub (yAxis, arrowY)
val model = AppWith.cursorColour (model, r, g, b, a)
val {layer, layerTree, arrowX, arrowY, ...} = model
in
(model, [])
case LayerTree.get (layer, layerTree) of
SOME grid =>
let
val yAxis = Vector.sub (grid, arrowX)
val {r, g, b, a} = Vector.sub (yAxis, arrowY)
val model = AppWith.cursorColour (model, r, g, b, a)
in
(model, [])
end
| NONE => (model, [])
end
fun updateCanvas (model, canvasWidth, canvasHeight) =
@@ -266,10 +272,10 @@ struct
, arrowY
, windowWidth
, windowHeight
, squares
, xClickPoints
, yClickPoints
, showGraph
, layerTree
, ...
} = model
@@ -278,6 +284,8 @@ struct
if showGraph then GraphLines.generate model else Vector.fromList []
val maxSide = Int.max (canvasWidth, canvasHeight)
val squares = LayerTree.flatten (maxSide, layerTree)
val squares = CollisionTree.toTriangles
( windowWidth
, windowHeight
@@ -298,9 +306,13 @@ struct
fun updateCanvasWidth model =
let
val newCanvasWidth = #modalNum model
val (model as {canvasWidth, canvasHeight, ...}) =
AppWith.canvasWidth (model, newCanvasWidth)
val {modalNum, layerTree, canvasHeight, ...} = model
val newCanvasWidth = modalNum
val maxSide = Int.max (newCanvasWidth, canvasHeight)
val layerTree = LayerTree.changeGridSize (maxSide, layerTree)
val model = AppWith.canvasWidth (model, newCanvasWidth, layerTree)
val {canvasWidth, canvasHeight, ...} = model
in
updateCanvas (model, canvasWidth, canvasHeight)
@@ -308,8 +320,13 @@ struct
fun updateCanvasHeight model =
let
val newCanvasHeight = #modalNum model
val model = AppWith.canvasHeight (model, newCanvasHeight)
val {modalNum, layerTree, canvasWidth, ...} = model
val newCanvasHeight = modalNum
val maxSide = Int.max (newCanvasHeight, canvasWidth)
val layerTree = LayerTree.changeGridSize (maxSide, layerTree)
val model = AppWith.canvasHeight (model, newCanvasHeight, layerTree)
val {canvasWidth, canvasHeight, ...} = model
in
updateCanvas (model, canvasWidth, canvasHeight)