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
+8 -23
View File
@@ -25,7 +25,6 @@ import (
gunsafe "gioui.org/internal/unsafe"
"gioui.org/layout"
"gioui.org/op"
"gioui.org/op/paint"
)
type GPU struct {
@@ -216,26 +215,6 @@ func decodeLinearGradientOp(data []byte) linearGradientOpData {
}
}
func decodePaintOp(data []byte) paint.PaintOp {
bo := binary.LittleEndian
if opconst.OpType(data[0]) != opconst.TypePaint {
panic("invalid op")
}
r := f32.Rectangle{
Min: f32.Point{
X: math.Float32frombits(bo.Uint32(data[1:])),
Y: math.Float32frombits(bo.Uint32(data[5:])),
},
Max: f32.Point{
X: math.Float32frombits(bo.Uint32(data[9:])),
Y: math.Float32frombits(bo.Uint32(data[13:])),
},
}
return paint.PaintOp{
Rect: r,
}
}
type clipType uint8
type resource interface {
@@ -854,12 +833,18 @@ loop:
state.matType = materialTexture
state.image = decodeImageOp(encOp.Data, encOp.Refs)
case opconst.TypePaint:
op := decodePaintOp(encOp.Data)
// Transform (if needed) the painting rectangle and if so generate a clip path,
// for those cases also compute a partialTrans that maps texture coordinates between
// the new bounding rectangle and the transformed original paint rectangle.
trans, off := splitTransform(state.t)
clipData, bnd, partialTrans := d.boundsForTransformedRect(op.Rect, trans)
// Fill the clip area, unless the material is a (bounded) image.
// TODO: Find a tighter bound.
inf := float32(1e6)
dst := f32.Rect(-inf, -inf, inf, inf)
if state.matType == materialTexture {
dst = layout.FRect(state.image.src.Rect)
}
clipData, bnd, partialTrans := d.boundsForTransformedRect(dst, trans)
clip := state.clip.Intersect(bnd.Add(off))
if clip.Empty() {
continue