mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 10:25:37 +00:00
op/clip: remove Op.Add
The Add method was a compatibility stop-gap. API change. Use clip.Op.Push and Pop the return value to explicitly mark the region affected by the clip operation. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+3
-10
@@ -1710,7 +1710,6 @@ func (c *collector) addClip(state *encoderState, viewport, bounds f32.Rectangle,
|
|||||||
path: path,
|
path: path,
|
||||||
pathKey: key,
|
pathKey: key,
|
||||||
intersect: intersect,
|
intersect: intersect,
|
||||||
push: push,
|
|
||||||
clipKey: clipKey{
|
clipKey: clipKey{
|
||||||
bounds: bounds,
|
bounds: bounds,
|
||||||
relTrans: state.relTrans,
|
relTrans: state.relTrans,
|
||||||
@@ -1775,18 +1774,12 @@ func (c *collector) collect(root *op.Ops, viewport image.Point, texOps *[]textur
|
|||||||
case ops.TypeClip:
|
case ops.TypeClip:
|
||||||
var op clipOp
|
var op clipOp
|
||||||
op.decode(encOp.Data)
|
op.decode(encOp.Data)
|
||||||
c.addClip(&state, fview, op.bounds, pathData.data, pathData.key, pathData.hash, strWidth, op.push)
|
c.addClip(&state, fview, op.bounds, pathData.data, pathData.key, pathData.hash, strWidth, true)
|
||||||
pathData.data = nil
|
pathData.data = nil
|
||||||
strWidth = 0
|
strWidth = 0
|
||||||
case ops.TypePopClip:
|
case ops.TypePopClip:
|
||||||
for {
|
state.relTrans = state.clip.relTrans.Mul(state.relTrans)
|
||||||
push := state.clip.push
|
state.clip = state.clip.parent
|
||||||
state.relTrans = state.clip.relTrans.Mul(state.relTrans)
|
|
||||||
state.clip = state.clip.parent
|
|
||||||
if push {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case ops.TypeColor:
|
case ops.TypeColor:
|
||||||
state.matType = materialColor
|
state.matType = materialColor
|
||||||
state.color = decodeColorOp(encOp.Data)
|
state.color = decodeColorOp(encOp.Data)
|
||||||
|
|||||||
+2
-14
@@ -109,9 +109,6 @@ type pathOp struct {
|
|||||||
// rect tracks whether the clip stack can be represented by a
|
// rect tracks whether the clip stack can be represented by a
|
||||||
// pixel-aligned rectangle.
|
// pixel-aligned rectangle.
|
||||||
rect bool
|
rect bool
|
||||||
// push is set to true for clip operations that corresponds to
|
|
||||||
// a push operation.
|
|
||||||
push bool
|
|
||||||
// clip is the union of all
|
// clip is the union of all
|
||||||
// later clip rectangles.
|
// later clip rectangles.
|
||||||
clip image.Rectangle
|
clip image.Rectangle
|
||||||
@@ -173,7 +170,6 @@ type clipOp struct {
|
|||||||
// TODO: Use image.Rectangle?
|
// TODO: Use image.Rectangle?
|
||||||
bounds f32.Rectangle
|
bounds f32.Rectangle
|
||||||
outline bool
|
outline bool
|
||||||
push bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// imageOpData is the shadow of paint.ImageOp.
|
// imageOpData is the shadow of paint.ImageOp.
|
||||||
@@ -207,7 +203,6 @@ func (op *clipOp) decode(data []byte) {
|
|||||||
*op = clipOp{
|
*op = clipOp{
|
||||||
bounds: layout.FRect(r),
|
bounds: layout.FRect(r),
|
||||||
outline: data[17] == 1,
|
outline: data[17] == 1,
|
||||||
push: data[18] == 1,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -863,7 +858,6 @@ func (d *drawOps) addClipPath(state *drawState, aux []byte, auxKey opKey, bounds
|
|||||||
off: off,
|
off: off,
|
||||||
intersect: bounds.Add(off),
|
intersect: bounds.Add(off),
|
||||||
rect: true,
|
rect: true,
|
||||||
push: push,
|
|
||||||
}
|
}
|
||||||
if npath.parent != nil {
|
if npath.parent != nil {
|
||||||
npath.rect = npath.parent.rect
|
npath.rect = npath.parent.rect
|
||||||
@@ -971,16 +965,10 @@ loop:
|
|||||||
quads.aux, op.bounds, _ = d.boundsForTransformedRect(bounds, trans)
|
quads.aux, op.bounds, _ = d.boundsForTransformedRect(bounds, trans)
|
||||||
quads.key = opKey{Key: encOp.Key}
|
quads.key = opKey{Key: encOp.Key}
|
||||||
}
|
}
|
||||||
d.addClipPath(&state, quads.aux, quads.key, op.bounds, off, op.push)
|
d.addClipPath(&state, quads.aux, quads.key, op.bounds, off, true)
|
||||||
quads = quadsOp{}
|
quads = quadsOp{}
|
||||||
case ops.TypePopClip:
|
case ops.TypePopClip:
|
||||||
for {
|
state.cpath = state.cpath.parent
|
||||||
push := state.cpath.push
|
|
||||||
state.cpath = state.cpath.parent
|
|
||||||
if push {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
case ops.TypeColor:
|
case ops.TypeColor:
|
||||||
state.matType = materialColor
|
state.matType = materialColor
|
||||||
|
|||||||
+1
-1
@@ -118,7 +118,7 @@ const (
|
|||||||
TypeSaveLen = 1 + 4
|
TypeSaveLen = 1 + 4
|
||||||
TypeLoadLen = 1 + 4
|
TypeLoadLen = 1 + 4
|
||||||
TypeAuxLen = 1
|
TypeAuxLen = 1
|
||||||
TypeClipLen = 1 + 4*4 + 1 + 1
|
TypeClipLen = 1 + 4*4 + 1
|
||||||
TypePopClipLen = 1
|
TypePopClipLen = 1
|
||||||
TypeProfileLen = 1
|
TypeProfileLen = 1
|
||||||
TypeCursorLen = 1 + 1
|
TypeCursorLen = 1 + 1
|
||||||
|
|||||||
+2
-12
@@ -41,18 +41,11 @@ func init() {
|
|||||||
// state to the intersection of the current p.
|
// state to the intersection of the current p.
|
||||||
func (p Op) Push(o *op.Ops) Stack {
|
func (p Op) Push(o *op.Ops) Stack {
|
||||||
id, macroID := ops.PushOp(&o.Internal, ops.ClipStack)
|
id, macroID := ops.PushOp(&o.Internal, ops.ClipStack)
|
||||||
p.add(o, true)
|
p.add(o)
|
||||||
return Stack{ops: &o.Internal, id: id, macroID: macroID}
|
return Stack{ops: &o.Internal, id: id, macroID: macroID}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add is like Push except it doesn't save the current state on the stack.
|
func (p Op) add(o *op.Ops) {
|
||||||
//
|
|
||||||
// Deprecated: use Push instead.
|
|
||||||
func (p Op) Add(o *op.Ops) {
|
|
||||||
p.add(o, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p Op) add(o *op.Ops, push bool) {
|
|
||||||
path := p.path
|
path := p.path
|
||||||
outline := p.outline
|
outline := p.outline
|
||||||
|
|
||||||
@@ -87,9 +80,6 @@ func (p Op) add(o *op.Ops, push bool) {
|
|||||||
if outline {
|
if outline {
|
||||||
data[17] = byte(1)
|
data[17] = byte(1)
|
||||||
}
|
}
|
||||||
if push {
|
|
||||||
data[18] = byte(1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Stack) Pop() {
|
func (s Stack) Pop() {
|
||||||
|
|||||||
@@ -28,13 +28,6 @@ func (r Rect) Push(ops *op.Ops) Stack {
|
|||||||
return r.Op().Push(ops)
|
return r.Op().Push(ops)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the rectangle clip to the clip state.
|
|
||||||
//
|
|
||||||
// Deprecated: use Push instead.
|
|
||||||
func (r Rect) Add(ops *op.Ops) {
|
|
||||||
r.Op().Add(ops)
|
|
||||||
}
|
|
||||||
|
|
||||||
// UniformRRect returns an RRect with all corner radii set to the
|
// UniformRRect returns an RRect with all corner radii set to the
|
||||||
// provided radius.
|
// provided radius.
|
||||||
func UniformRRect(rect f32.Rectangle, radius float32) RRect {
|
func UniformRRect(rect f32.Rectangle, radius float32) RRect {
|
||||||
@@ -78,13 +71,6 @@ func (rr RRect) Push(ops *op.Ops) Stack {
|
|||||||
return rr.Op(ops).Push(ops)
|
return rr.Op(ops).Push(ops)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the rectangle clip to the clip state.
|
|
||||||
//
|
|
||||||
// Deprecated: use Push instead.
|
|
||||||
func (rr RRect) Add(ops *op.Ops) {
|
|
||||||
rr.Op(ops).Add(ops)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Path returns the PathSpec for the rounded rectangle.
|
// Path returns the PathSpec for the rounded rectangle.
|
||||||
func (rr RRect) Path(ops *op.Ops) PathSpec {
|
func (rr RRect) Path(ops *op.Ops) PathSpec {
|
||||||
var p Path
|
var p Path
|
||||||
@@ -138,13 +124,6 @@ func (c Circle) Push(ops *op.Ops) Stack {
|
|||||||
return c.Op(ops).Push(ops)
|
return c.Op(ops).Push(ops)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the circle clip to the clip state.
|
|
||||||
//
|
|
||||||
// Deprecated: use Push instead.
|
|
||||||
func (c Circle) Add(ops *op.Ops) {
|
|
||||||
c.Op(ops).Add(ops)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Path returns the PathSpec for the circle.
|
// Path returns the PathSpec for the circle.
|
||||||
func (c Circle) Path(ops *op.Ops) PathSpec {
|
func (c Circle) Path(ops *op.Ops) PathSpec {
|
||||||
var p Path
|
var p Path
|
||||||
|
|||||||
Reference in New Issue
Block a user