From f45826db85a9848ccfb10c0f495f1469229ae4af Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 26 Oct 2023 20:36:15 +0100 Subject: [PATCH] Basic content, not quite right. --- .../src/main/scala/roguepaint/PaintScene.scala | 14 ++++++++++---- .../scala/roguepaint/components/Window.scala | 18 ++++++++++++++---- .../roguepaint/components/WindowManager.scala | 6 +++--- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/paint/src/main/scala/roguepaint/PaintScene.scala b/paint/src/main/scala/roguepaint/PaintScene.scala index 07e4336a..1cb280ed 100644 --- a/paint/src/main/scala/roguepaint/PaintScene.scala +++ b/paint/src/main/scala/roguepaint/PaintScene.scala @@ -66,11 +66,9 @@ object PaintScene extends Scene[Size, Model, ViewModel]: Outcome( SceneUpdateFragment( Layer( - Batch(viewModel.bg) ++ - tiles.clones + Batch(viewModel.bg) ) - ) - .addCloneBlanks(tiles.blanks) + ) |+| tiles ) final case class PaintModel(windowManager: WindowManagerModel) @@ -110,6 +108,14 @@ object PaintModel: .isCloseable .isDraggable .focus + .withContents { bounds => + SceneUpdateFragment( + Shape.Circle( + Circle(bounds.center, Math.min(bounds.size.width, bounds.size.height) / 2), + Fill.Color(RGBA.Blue) + ) + ) + } ) ) diff --git a/paint/src/main/scala/roguepaint/components/Window.scala b/paint/src/main/scala/roguepaint/components/Window.scala index fe5113de..0b97b67f 100644 --- a/paint/src/main/scala/roguepaint/components/Window.scala +++ b/paint/src/main/scala/roguepaint/components/Window.scala @@ -91,8 +91,10 @@ object Window: Batch(WindowManagerEvent.Close(model.id)) else Batch.empty val focus = - if actionsAllowed && !model.static && model.bounds.resize(model.bounds.size - 1).contains(gridPos) then - Batch(WindowManagerEvent.GiveFocusAt(gridPos)) + if actionsAllowed && !model.static && model.bounds + .resize(model.bounds.size - 1) + .contains(gridPos) + then Batch(WindowManagerEvent.GiveFocusAt(gridPos)) else Batch.empty Outcome(viewModel) @@ -156,8 +158,11 @@ object Window: case _ => Outcome(viewModel) - def present(viewModel: WindowViewModel): TerminalClones = - viewModel.terminalClones + def present(model: WindowModel, viewModel: WindowViewModel): SceneUpdateFragment = + SceneUpdateFragment( + viewModel.terminalClones.clones + ).addCloneBlanks(viewModel.terminalClones.blanks) |+| + model.contents(model.bounds.resize(model.bounds.size * charSize).moveTo(model.bounds.position * charSize)) opaque type WindowId = String object WindowId: @@ -168,6 +173,7 @@ final case class WindowModel( id: WindowId, bounds: Rectangle, title: Option[String], + contents: Rectangle => SceneUpdateFragment, draggable: Boolean, resizable: Boolean, closeable: Boolean, @@ -206,6 +212,9 @@ final case class WindowModel( def withTitle(value: String): WindowModel = this.copy(title = Option(value)) + def withContents(f: Rectangle => SceneUpdateFragment): WindowModel = + this.copy(contents = f) + def withDraggable(value: Boolean): WindowModel = this.copy(draggable = value) def isDraggable: WindowModel = @@ -251,6 +260,7 @@ object WindowModel: id, Rectangle(Point.zero, Size.zero), None, + (r: Rectangle) => SceneUpdateFragment.empty, false, false, false, diff --git a/paint/src/main/scala/roguepaint/components/WindowManager.scala b/paint/src/main/scala/roguepaint/components/WindowManager.scala index a83c2dc6..da6dd4d1 100644 --- a/paint/src/main/scala/roguepaint/components/WindowManager.scala +++ b/paint/src/main/scala/roguepaint/components/WindowManager.scala @@ -42,7 +42,7 @@ object WindowManager: frameContext: FrameContext[Size], model: WindowManagerModel, viewModel: WindowManagerViewModel - ): TerminalClones = + ): SceneUpdateFragment = model.windows .flatMap { m => viewModel.windows.find(_.id == m.id) match @@ -51,9 +51,9 @@ object WindowManager: Batch.empty case Some(vm) => - Batch(Window.present(vm)) + Batch(Window.present(m, vm)) } - .foldLeft(TerminalClones.empty)(_ |+| _) + .foldLeft(SceneUpdateFragment.empty)(_ |+| _) extension (tc: TerminalClones) def |+|(other: TerminalClones): TerminalClones =