From 38f7185be2ace3c8a04e20a1dff320ae233a28d9 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Fri, 11 Nov 2022 18:14:43 -0500 Subject: [PATCH] Draw the actual buffer text on screen --- backends/x/x.go | 57 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/backends/x/x.go b/backends/x/x.go index 1a1037e..fc5be02 100644 --- a/backends/x/x.go +++ b/backends/x/x.go @@ -142,6 +142,9 @@ func (backend *Backend) handleXEvent (event xgb.Event) { // resize and rebind canvas backend.reallocateCanvas() + + // notify application of resize + backend.channel <- stone.EventResize { } } } } @@ -201,28 +204,50 @@ func (backend *Backend) reallocateCanvas () { return backend.colors[stone.ColorApplication] }) - backend.drawRune(0, 0, 'T') - backend.drawRune(1, 0, 'h') - backend.drawRune(2, 0, 'e') - backend.drawRune(4, 0, 'q') - backend.drawRune(5, 0, 'u') - backend.drawRune(6, 0, 'i') - backend.drawRune(7, 0, 'c') - backend.drawRune(8, 0, 'k') - backend.drawRune(0, 1, 'b') - backend.drawRune(1, 1, 'r') - backend.drawRune(2, 1, 'o') - backend.drawRune(3, 1, 'w') - backend.drawRune(4, 1, 'n') - backend.drawRune(6, 1, 'f') - backend.drawRune(7, 1, 'o') - backend.drawRune(8, 1, 'x') + // backend.drawRune(0, 0, 'T') + // backend.drawRune(1, 0, 'h') + // backend.drawRune(2, 0, 'e') + // backend.drawRune(4, 0, 'q') + // backend.drawRune(5, 0, 'u') + // backend.drawRune(6, 0, 'i') + // backend.drawRune(7, 0, 'c') + // backend.drawRune(8, 0, 'k') + // backend.drawRune(0, 1, 'b') + // backend.drawRune(1, 1, 'r') + // backend.drawRune(2, 1, 'o') + // backend.drawRune(3, 1, 'w') + // backend.drawRune(4, 1, 'n') + // backend.drawRune(6, 1, 'f') + // backend.drawRune(7, 1, 'o') + // backend.drawRune(8, 1, 'x') + + backend.drawCells(true) backend.canvas.XSurfaceSet(backend.window.Id) backend.canvas.XDraw() backend.canvas.XPaint(backend.window.Id) } +func (backend *Backend) drawCells (forceRedraw bool) (areas []image.Rectangle) { + width, height := backend.application.Size() + for y := 0; y < height; y ++ { + for x := 0; x < width; x ++ { + if !forceRedraw && backend.application.Clean(x, y) { continue } + backend.application.MarkClean(x, y) + + cell := backend.application.Cell(x, y) + content := cell.Rune() + if content < 32 { continue } + + backend.drawRune(x, y, content) + }} + return +} + +func (backend *Backend) updateWindowAreas (areas ...image.Rectangle) { + backend.canvas.XPaintRects(backend.window.Id, areas...) +} + func (backend *Backend) drawRune (x, y int, character rune) { // TODO: cache these draws as non-transparent buffers with the // application background color as the background. that way, we won't