diff --git a/backends/pixel/pixel.go b/backends/pixel/pixel.go index 2c8c763..661d764 100644 --- a/backends/pixel/pixel.go +++ b/backends/pixel/pixel.go @@ -20,6 +20,7 @@ type Backend struct { fontAtlas *text.Atlas textDrawer *text.Text showBounds bool + showCellBounds bool metrics struct { cellWidth int @@ -27,16 +28,24 @@ type Backend struct { padding int paddingX int paddingY int + descent int } } func (backend *Backend) Run (callback func (application *stone.Application)) { + // backend.showBounds = true + backend.showCellBounds = true + if backend.fontFace == nil { backend.fontFace = basicfont.Face7x13 } - faceMetrics := backend.fontFace.Metrics() - backend.metrics.cellHeight = faceMetrics.Height.Round() + backend.backgroundStamper = imdraw.New(nil) + backend.fontAtlas = text.NewAtlas(backend.fontFace, text.ASCII) + backend.textDrawer = text.New(pixel.V(0, 0), backend.fontAtlas) + + backend.metrics.descent = int(backend.fontAtlas.Descent()) + backend.metrics.cellHeight = int(backend.fontAtlas.LineHeight()) // FIXME?: this might not be the best way to get the cell width faceAdvance, ok := backend.fontFace.GlyphAdvance('M') if ok { @@ -56,9 +65,6 @@ func (backend *Backend) Run (callback func (application *stone.Application)) { Title: backend.application.Title(), Bounds: backend.calculateWindowSize(), }) - backend.backgroundStamper = imdraw.New(nil) - backend.fontAtlas = text.NewAtlas(backend.fontFace, text.ASCII) - backend.textDrawer = text.New(pixel.V(0, 0), backend.fontAtlas) backend.Poll() if err != nil { panic(err.Error()) } @@ -166,6 +172,17 @@ func (backend *Backend) draw () { backend.vectorAtPosition(x + 1, y + 1)) backend.backgroundStamper.Rectangle(0) // didDrawing = true + + if backend.showCellBounds { + backend.backgroundStamper.Color = + backend.config.Color(stone.ColorForeground) + backend.backgroundStamper.Push ( + backend.vectorAtPosition(x, y), + backend.vectorAtPosition(x + 1, y + 1)) + backend.backgroundStamper.Rectangle(1) + backend.backgroundStamper.Color = + backend.config.Color(stone.ColorApplication) + } } } backend.backgroundStamper.Draw(backend.window) @@ -185,7 +202,15 @@ func (backend *Backend) draw () { if content < 32 { continue } // draw cell - backend.textDrawer.Dot = backend.vectorAtPosition(x, y + 1) + backend.textDrawer.Dot = pixel.V ( + float64 ( + x * backend.metrics.cellWidth + + backend.metrics.paddingX), + backend.windowBounds.Y - float64 ( + (y + 1) * backend.metrics.cellHeight + + backend.metrics.paddingY - + backend.metrics.descent)) + backend.textDrawer.WriteRune(content) backend.textDrawer.Draw(backend.window, pixel.IM) }