add functionality to flip drawing horizontally

This commit is contained in:
2025-08-12 22:25:16 +01:00
parent 55fe9b7605
commit 4a9b5947e7
9 changed files with 32 additions and 2 deletions

View File

@@ -32,4 +32,14 @@ struct
fun makeEmpty maxSide =
Vector.tabulate (maxSide, fn _ =>
Vector.tabulate (maxSide, fn _ => emptyPixel))
fun flipHorizontally (xAxis: t) =
Vector.mapi
(fn (xIdx, yAxis) =>
let
val flippedXIdx = Vector.length xAxis - 1 - xIdx
val flippedYAxis = Vector.sub (xAxis, flippedXIdx)
in
Vector.mapi (fn (yIdx, _) => Vector.sub (flippedYAxis, yIdx)) yAxis
end) xAxis
end

View File

@@ -107,4 +107,6 @@ struct
in
insert (key, grid, tree)
end
fun flipHorizontally tree = map (Grid.flipHorizontally, tree)
end

View File

@@ -369,6 +369,15 @@ struct
in (model, [])
end
fun flipHorizontally (model: app_type) =
let
val {layerTree, arrowX, arrowY, ...} = model
val layerTree = LayerTree.flipHorizontally layerTree
val model = AppWith.layerTree (model, layerTree, arrowX, arrowY)
in
getDrawMessage (model, [])
end
fun update (model: app_type, inputMsg) =
case inputMsg of
MOUSE_MOVE {x = mouseX, y = mouseY} =>
@@ -388,6 +397,7 @@ struct
| KEY_W => updateCanvasWidth model
| KEY_H => updateCanvasHeight model
| KEY_M => enterMoveMode model
| KEY_F => flipHorizontally model
| RESIZE_WINDOW {width, height} => resizeWindow (model, width, height)
| UNDO_ACTION => undoAction model
| REDO_ACTION => redoAction model