mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-02 16:06:19 +00:00
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:
+8
-23
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user