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 , modalNum = 0
} }
end 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 end

View File

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

View File

@@ -134,36 +134,25 @@ struct
fun realToInt x = Real32.toInt IEEEReal.TO_NEAREST x fun realToInt x = Real32.toInt IEEEReal.TO_NEAREST x
fun changePixel (model: app_type, hIdx, vIdx, pixel) = fun getDrawMessage (model: app_type) =
let let
val val
{ windowWidth { canvasWidth
, canvasHeight
, layerTree
, windowWidth
, windowHeight , windowHeight
, xClickPoints , xClickPoints
, yClickPoints , yClickPoints
, canvasWidth , arrowX
, canvasHeight , arrowY
, layer
, layerTree
, r
, g
, b
, a
, ... , ...
} = model } = model
val maxSide = Int.max (canvasWidth, canvasHeight) 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 squares = LayerTree.flatten (maxSide, layerTree)
val dotVec = getDotVecFromIndices (model, hIdx, vIdx) val dotVec = getDotVecFromIndices (model, arrowX, arrowY)
val squares = CollisionTree.toTriangles val squares = CollisionTree.toTriangles
( windowWidth ( windowWidth
@@ -180,6 +169,19 @@ struct
(model, [DRAW drawMsg]) (model, [DRAW drawMsg])
end 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) = fun addPixel (model: app_type, hIdx, vIdx) =
let let
val {r, g, b, a, ...} = model val {r, g, b, a, ...} = model
@@ -332,8 +334,13 @@ struct
updateCanvas (model, canvasWidth, canvasHeight) updateCanvas (model, canvasWidth, canvasHeight)
end end
fun useSquares (model, squares, canvasWidth, canvasHeight) = fun useLayers (model, layerTree, canvasWidth, canvasHeight) =
raise Fail "todo: reimplement" let
val model =
AppWith.layerTree (model, layerTree, canvasWidth, canvasHeight)
in
getDrawMessage model
end
fun enterBrowseMode model = fun enterBrowseMode model =
let let
@@ -382,8 +389,8 @@ struct
| KEY_CTRL_L => CommonUpdate.getLoadSquaresMsg model | KEY_CTRL_L => CommonUpdate.getLoadSquaresMsg model
| KEY_CTRL_E => CommonUpdate.getExportSquaresMsg model | KEY_CTRL_E => CommonUpdate.getExportSquaresMsg model
| KEY_CTRL_C => CommonUpdate.getCollisionMsg model | KEY_CTRL_C => CommonUpdate.getCollisionMsg model
| USE_SQUARES {squares, canvasWidth, canvasHeight} => | USE_LAYERS {tree, canvasWidth, canvasHeight} =>
useSquares (model, squares, canvasWidth, canvasHeight) useLayers (model, tree, canvasWidth, canvasHeight)
| SQUARES_LOAD_ERROR => CommonUpdate.squaresLoadError model | SQUARES_LOAD_ERROR => CommonUpdate.squaresLoadError model
| KEY_CTRL_O => enterBrowseMode model | KEY_CTRL_O => enterBrowseMode model
| ARROW_UP => moveArrowUp model | ARROW_UP => moveArrowUp model

View File

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

View File

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

View File

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