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

BIN
dotscape

Binary file not shown.

View File

@@ -999,4 +999,62 @@ struct
, modalNum = 0
}
end
fun useLayerTree (app: app_type, layerTree, canvasWidth, canvasHeight) :
app_type =
let
val
{ mode
, mouseX
, mouseY
, xClickPoints
, yClickPoints
, windowWidth
, windowHeight
, arrowX = _
, arrowY = _
, canvasWidth = _
, canvasHeight = _
, showGraph
, openFilePath
, fileBrowser
, fileBrowserIdx
, r
, g
, b
, a
, layer
, layerTree = _
, modalNum
} = app
val arrowX = 0
val arrowY = 0
in
{ mode = mode
, mouseX = mouseX
, mouseY = mouseY
, arrowX = arrowX
, arrowY = arrowY
, canvasWidth = canvasWidth
, canvasHeight = canvasHeight
, windowWidth = windowWidth
, windowHeight = windowHeight
, xClickPoints = xClickPoints
, yClickPoints = yClickPoints
, showGraph = showGraph
, openFilePath = openFilePath
, fileBrowser = fileBrowser
, fileBrowserIdx = fileBrowserIdx
, r = r
, g = g
, b = b
, a = a
, layer = layer
, layerTree = layerTree
, modalNum = modalNum
}
end
end

View File

@@ -161,7 +161,5 @@ struct
| FILE_BROWSER_AND_PATH {fileBrowser, path} =>
handleFileBrowserAndPathInBrowseMode (model, fileBrowser, path)
| SQUARES_LOAD_ERROR => CommonUpdate.squaresLoadError model
| USE_SQUARES squares =>
CommonUpdate.useSquaresInNormalMode (model, squares)
| _ => (model, [])
end

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

View File

@@ -42,7 +42,7 @@ struct
(tl, canvasWidth, canvasHeight, tree, 1)
in
case tokens of
[T.R_BRACE] => SOME tree
[T.R_BRACE] => SOME (canvasWidth, canvasHeight, tree)
| _ => NONE
end
| _ => NONE)

View File

@@ -25,12 +25,15 @@ struct
val () = TextIO.closeIn io
in
case Parser.parse str of
SOME (canvasWidth, canvasHeight, grid) =>
Mailbox.send (inputMailbox, USE_SQUARES
{ squares = grid
SOME (canvasWidth, canvasHeight, tree) =>
Mailbox.send
( inputMailbox
, USE_LAYERS
{ tree = tree
, canvasWidth = canvasWidth
, canvasHeight = canvasHeight
})
}
)
| NONE => ()
end

View File

@@ -31,11 +31,7 @@ struct
| ARROW_DOWN
| KEY_ENTER
| KEY_SPACE
| USE_SQUARES of
{ squares: {r: int, g: int, b: int, a: int} vector vector
, canvasWidth: int
, canvasHeight: int
}
| USE_LAYERS of {tree: LayerTree.t, canvasWidth: int, canvasHeight: int}
| SQUARES_LOAD_ERROR
| FILE_BROWSER_AND_PATH of
{fileBrowser: AppType.file_browser_item vector, path: string}