From 6e5cbd50f5d2054a3098cb9225832c8111d2aee7 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sat, 5 Nov 2022 18:56:56 -0400 Subject: [PATCH] Fixed coordinate system --- application.go | 2 ++ backends/pixel/pixel.go | 24 ++++++++++++++++++------ examples/hello/main.go | 13 +++++++++++-- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/application.go b/application.go index e368cb9..c20ccef 100644 --- a/application.go +++ b/application.go @@ -35,6 +35,8 @@ func (application *Application) Run (callback func (application *Application)) { color.RGBA { R: 0xD8, G: 0xDE, B: 0xE9, A: 0xFF }, color.RGBA { R: 0x2B, G: 0x30, B: 0x3C, A: 0xFF }, } + + application.config.padding = 4 // TODO: instead, return the error var err error diff --git a/backends/pixel/pixel.go b/backends/pixel/pixel.go index 5e7d8f0..2eb3445 100644 --- a/backends/pixel/pixel.go +++ b/backends/pixel/pixel.go @@ -12,7 +12,7 @@ import "git.tebibyte.media/sashakoshka/stone" type Backend struct { window *pixelgl.Window boundsDirty bool - previousBounds pixel.Vec + windowBounds pixel.Vec fontFace font.Face application *stone.Application config *stone.Config @@ -166,19 +166,28 @@ func (backend *Backend) draw () { if content < 32 { continue } // draw cell - backend.textDrawer.Dot = backend.vectorAtPosition(x, y) + backend.textDrawer.Dot = backend.vectorAtPosition(x, y + 1) backend.textDrawer.WriteRune(content) backend.textDrawer.Draw(backend.window, pixel.IM) } } + + backend.backgroundStamper.Clear() + backend.backgroundStamper.Color = + backend.config.Color(stone.ColorBackground) + backend.backgroundStamper.Push ( + backend.vectorAtPosition(0, 0), + backend.vectorAtPosition(width, height)) + backend.backgroundStamper.Rectangle(1) + backend.backgroundStamper.Draw(backend.window) backend.window.SwapBuffers() } func (backend *Backend) processEvents () { newBounds := backend.window.Bounds().Max - backend.boundsDirty = backend.previousBounds != newBounds - backend.previousBounds = newBounds + backend.boundsDirty = backend.windowBounds != newBounds + backend.windowBounds = newBounds if backend.boundsDirty { // TODO: set size of buffer @@ -186,9 +195,12 @@ func (backend *Backend) processEvents () { } func (backend *Backend) vectorAtPosition (x, y int) (vector pixel.Vec) { + padding := backend.config.Padding() * backend.metrics.cellWidth + vector = pixel.V ( - float64(x * backend.metrics.cellWidth), - float64(y * backend.metrics.cellHeight)) + float64 (x * backend.metrics.cellWidth + padding), + backend.windowBounds.Y - float64 ( + y * backend.metrics.cellHeight + padding)) return } diff --git a/examples/hello/main.go b/examples/hello/main.go index fd4b2d6..d0bbab2 100644 --- a/examples/hello/main.go +++ b/examples/hello/main.go @@ -20,8 +20,17 @@ func run (application *stone.Application) { application.SetRune(6, 0, 'l') application.SetRune(7, 0, 'd') application.SetRune(8, 0, '!') - application.SetRune(4, 4, ':') - application.SetRune(5, 4, '3') + application.SetRune(4, 1, ':') + application.SetRune(5, 1, '3') + application.SetRune(0, 2, 'A') + application.SetRune(1, 2, 'A') + application.SetRune(2, 2, 'A') + application.SetRune(3, 2, 'A') + application.SetRune(4, 2, 'A') + application.SetRune(5, 2, 'A') + application.SetRune(6, 2, 'A') + application.SetRune(7, 2, 'A') + application.SetRune(8, 2, 'A') } if !application.Await(0) { break }