From 79d8891c5bc862a4ef490ab9ffaf8d91bd33fddb Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Mon, 14 Nov 2022 23:32:05 -0500 Subject: [PATCH] Added some stuff to draw debug bounding boxes --- backends/x/draw.go | 28 +++++++++++++++++++++------- backends/x/factory.go | 4 ++++ backends/x/x.go | 3 +++ 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/backends/x/draw.go b/backends/x/draw.go index 82ff82b..0a94d08 100644 --- a/backends/x/draw.go +++ b/backends/x/draw.go @@ -51,13 +51,15 @@ func (backend *Backend) drawRune (x, y int, character rune) { Y: fixed.I(origin.Y - backend.metrics.descent), }, character) - - // strokeRectangle ( - // &image.Uniform { - // C: backend.config.Color(stone.ColorForeground), - // }, - // backend.canvas, - // backend.boundsOfCell(x, y)) + + if backend.drawCellBounds { + strokeRectangle ( + &image.Uniform { + C: backend.config.Color(stone.ColorForeground), + }, + backend.canvas, + backend.boundsOfCell(x, y)) + } draw.DrawMask ( backend.canvas, @@ -86,6 +88,18 @@ func (backend *Backend) drawCells (forceRedraw bool) (areas []image.Rectangle) { areas = append(areas, backend.boundsOfCell(x, y)) backend.drawRune(x, y, content) }} + + if backend.drawBufferBounds && forceRedraw { + strokeRectangle ( + &image.Uniform { + C: backend.config.Color(stone.ColorForeground), + }, + backend.canvas, + image.Rectangle { + Min: backend.originOfCell(0, 0), + Max: backend.originOfCell(width, height), + }) + } return } diff --git a/backends/x/factory.go b/backends/x/factory.go index 1885496..c19fd51 100644 --- a/backends/x/factory.go +++ b/backends/x/factory.go @@ -126,6 +126,10 @@ func factory (application *stone.Application) (output stone.Backend, err error) Connect(backend.connection, backend.window.Id) xevent.KeyReleaseFun(backend.handleKeyRelease). Connect(backend.connection, backend.window.Id) + + // uncomment these to draw debug bounds + // backend.drawCellBounds = true + // backend.drawBufferBounds = true output = backend return diff --git a/backends/x/x.go b/backends/x/x.go index b7c7cf2..c930c84 100644 --- a/backends/x/x.go +++ b/backends/x/x.go @@ -21,6 +21,9 @@ type Backend struct { canvas *xgraphics.Image channel chan(stone.Event) + drawCellBounds bool + drawBufferBounds bool + drawLock sync.Mutex font struct {