From 3cb0ac64fcaf8757f9ca521028936b0ad172b2ff Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Thu, 17 Nov 2022 21:19:23 -0500 Subject: [PATCH] I made my own draw method with blackjack and hookers --- backends/x/draw.go | 49 ++++++++++++++++++++++++++----------------- backends/x/factory.go | 2 +- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/backends/x/draw.go b/backends/x/draw.go index 5523463..782a60f 100644 --- a/backends/x/draw.go +++ b/backends/x/draw.go @@ -90,17 +90,13 @@ func (backend *Backend) drawRune ( } if character < 32 { return } - + origin := backend.originOfCell(x, y + 1) - destinationRectangle, mask, maskPoint, _, ok := backend.font.face.Glyph ( - fixed.Point26_6 { - X: fixed.I(origin.X), - Y: fixed.I(origin.Y - backend.metrics.descent), - }, + destinationRectangle, mask, _, _, ok := backend.font.face.Glyph ( + fixed.Point26_6 { }, character) if !ok { - println("warning") strokeRectangle ( &image.Uniform { C: backend.config.Color(stone.ColorForeground), @@ -110,7 +106,7 @@ func (backend *Backend) drawRune ( return } - if backend.drawCellBounds { + if backend.drawCellBounds { strokeRectangle ( &image.Uniform { C: backend.config.Color(stone.ColorForeground), @@ -118,17 +114,32 @@ func (backend *Backend) drawRune ( backend.canvas, backend.boundsOfCell(x, y)) } - - draw.DrawMask ( - backend.canvas, - destinationRectangle, - &image.Uniform { - C: backend.config.Color(runeColor), - }, - image.Point { }, - mask, - maskPoint, - draw.Over) + + origin.Y += destinationRectangle.Min.Y - backend.metrics.descent + backend.sprayRuneMask(mask, origin, backend.colors[runeColor]) +} + +func (backend *Backend) sprayRuneMask ( + mask image.Image, + at image.Point, + fill xgraphics.BGRA, +) { + bounds := mask.Bounds().Max + for y := 0; y < bounds.Y; y ++ { + for x := 0; x < bounds.X; x ++ { + _, _, _, alpha := mask.At(x, y).RGBA() + backend.canvas.SetBGRA ( + x + at.X, + y + at.Y, + xgraphics.BlendBGRA ( + backend.colors[stone.ColorBackground], + xgraphics.BGRA { + R: fill.R, + G: fill.G, + B: fill.B, + A: uint8(alpha >> 8), + })) + }} } func fillRectangle ( diff --git a/backends/x/factory.go b/backends/x/factory.go index bf0728b..8a4a942 100644 --- a/backends/x/factory.go +++ b/backends/x/factory.go @@ -133,7 +133,7 @@ func factory ( Connect(backend.connection, backend.window.Id) // uncomment these to draw debug bounds - // backend.drawCellBounds = true + // backend.drawCellBounds = true // backend.drawBufferBounds = true output = backend