From fc307c1e71a1b5da28fbe6861dddb30fc61dc583 Mon Sep 17 00:00:00 2001 From: Chris Waldon Date: Wed, 21 Oct 2020 21:31:36 -0400 Subject: [PATCH] op/paint: add Fill helpers for painting an area with a solid color Signed-off-by: Chris Waldon --- op/paint/paint.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/op/paint/paint.go b/op/paint/paint.go index b4a9a56b..b2f05dbb 100644 --- a/op/paint/paint.go +++ b/op/paint/paint.go @@ -12,6 +12,7 @@ import ( "gioui.org/f32" "gioui.org/internal/opconst" "gioui.org/op" + "gioui.org/op/clip" ) // ImageOp sets the brush to an image. @@ -125,3 +126,27 @@ func (d PaintOp) Add(o *op.Ops) { bo.PutUint32(data[9:], math.Float32bits(d.Rect.Max.X)) bo.PutUint32(data[13:], math.Float32bits(d.Rect.Max.Y)) } + +// FillShape fills the area described by the provided clip.Op with the +// provided color. +func FillShape(ops *op.Ops, shape clip.Op, c color.RGBA) { + defer op.Push(ops).Pop() + shape.Add(ops) + Fill(ops, c) +} + +// Fill paints an infinitely large plane with the provided color. It +// is intended to be used with a clip.Op already in place to limit +// the painted area. Use FillShape unless you need to paint several +// times within the same clip.Op. +func Fill(ops *op.Ops, c color.RGBA) { + defer op.Push(ops).Pop() + ColorOp{Color: c}.Add(ops) + inf := float32(math.Inf(+1)) + PaintOp{ + Rect: f32.Rectangle{ + Min: f32.Pt(-inf, -inf), + Max: f32.Pt(+inf, +inf), + }, + }.Add(ops) +}