From 3b1e0eaa21c19ff97a69f76a8ce0b21f4d7b6e83 Mon Sep 17 00:00:00 2001 From: faiface Date: Wed, 3 May 2017 21:48:05 +0200 Subject: [PATCH] add Text.SetMatrix and Text.SetColorMask --- text/text.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/text/text.go b/text/text.go index 9cd32b0..402c7cd 100644 --- a/text/text.go +++ b/text/text.go @@ -50,6 +50,7 @@ type Text struct { glyph pixel.TrianglesData tris pixel.TrianglesData d pixel.Drawer + trans *pixel.Batch } func New(face font.Face, runeSets ...[]rune) *Text { @@ -69,12 +70,21 @@ func New(face font.Face, runeSets ...[]rune) *Text { txt.glyph.SetLen(6) txt.d.Picture = txt.atlas.pic txt.d.Triangles = &txt.tris + txt.trans = pixel.NewBatch(&pixel.TrianglesData{}, atlas.pic) txt.Clear() return txt } +func (txt *Text) SetMatrix(m pixel.Matrix) { + txt.trans.SetMatrix(m) +} + +func (txt *Text) SetColorMask(c color.Color) { + txt.trans.SetColorMask(c) +} + func (txt *Text) Color(c color.Color) { txt.color = pixel.ToRGBA(c) } @@ -118,6 +128,7 @@ func (txt *Text) Write(p []byte) (n int, err error) { txt.Dot = txt.Dot.WithX(txt.Orig.X()) continue case '\t': + //TODO: properly align tab txt.Dot += pixel.X(txt.tabWidth) continue } @@ -153,7 +164,9 @@ func (txt *Text) Write(p []byte) (n int, err error) { } func (txt *Text) Draw(t pixel.Target) { - txt.d.Draw(t) + txt.trans.Clear() + txt.d.Draw(txt.trans) + txt.trans.Draw(t) } type atlas struct {