op/paint: remove support for PaintOp.Rect

PaintOp.Rect is the wrong abstraction; it implies a clip operation
better handled by package clip, and not all paints need it (colors).
Furthermore, it's awkward to specify a PaintOp that fills up the
current clip area, regardless of its size.

Redefine PathOp to mean "fill current clip area".

API change. Replace uses of PaintOp.Rect with a TransformOp applied
before the PaintOp.

Leave a TODO for the PathOp infinity area.

Fixes gio#167

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-11-05 16:09:55 +01:00
parent afb52194d1
commit 94d242d18c
19 changed files with 93 additions and 106 deletions
+2 -17
View File
@@ -43,12 +43,8 @@ type LinearGradientOp struct {
Color2 color.RGBA
}
// PaintOp fills an area with the current brush, respecting the
// current clip path and transformation.
// PaintOp fills fills the current clip area with the current brush.
type PaintOp struct {
// Rect is the destination area to paint. If necessary, the brush is
// scaled to cover the rectangle area.
Rect f32.Rectangle
}
// NewImageOp creates an ImageOp backed by src. See
@@ -139,11 +135,6 @@ func (c LinearGradientOp) Add(o *op.Ops) {
func (d PaintOp) Add(o *op.Ops) {
data := o.Write(opconst.TypePaintLen)
data[0] = byte(opconst.TypePaint)
bo := binary.LittleEndian
bo.PutUint32(data[1:], math.Float32bits(d.Rect.Min.X))
bo.PutUint32(data[5:], math.Float32bits(d.Rect.Min.Y))
bo.PutUint32(data[9:], math.Float32bits(d.Rect.Max.X))
bo.PutUint32(data[13:], math.Float32bits(d.Rect.Max.Y))
}
// FillShape fills the clip shape with a color.
@@ -160,11 +151,5 @@ func FillShape(ops *op.Ops, c color.RGBA, shape clip.Op) {
func Fill(ops *op.Ops, c color.RGBA) {
defer op.Push(ops).Pop()
ColorOp{Color: c}.Add(ops)
inf := float32(1e6)
PaintOp{
Rect: f32.Rectangle{
Min: f32.Pt(-inf, -inf),
Max: f32.Pt(+inf, +inf),
},
}.Add(ops)
PaintOp{}.Add(ops)
}