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

View File

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