mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 01:15:35 +00:00
op/paint: return ClipOp from Path.End
Instead of adding an implicit ClipOp, return a ClipOp ready to use, freeing the caller from recording a macro. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -210,17 +210,22 @@ func (o *Ops) Write(op []byte, refs ...interface{}) {
|
||||
}
|
||||
o.auxLen += len(op)
|
||||
default:
|
||||
if o.inAux {
|
||||
o.inAux = false
|
||||
bo := binary.LittleEndian
|
||||
bo.PutUint32(o.data[o.auxOff+1:], uint32(o.auxLen))
|
||||
}
|
||||
o.endAux()
|
||||
}
|
||||
o.write(op, refs...)
|
||||
}
|
||||
|
||||
func (d *Ops) pc() pc {
|
||||
return pc{data: len(d.data), refs: len(d.refs)}
|
||||
func (o *Ops) endAux() {
|
||||
if !o.inAux {
|
||||
return
|
||||
}
|
||||
o.inAux = false
|
||||
bo := binary.LittleEndian
|
||||
bo.PutUint32(o.data[o.auxOff+1:], uint32(o.auxLen))
|
||||
}
|
||||
|
||||
func (o *Ops) pc() pc {
|
||||
return pc{data: len(o.data), refs: len(o.refs)}
|
||||
}
|
||||
|
||||
// Record a macro of operations.
|
||||
@@ -242,6 +247,7 @@ func (m *MacroOp) Stop() {
|
||||
if !m.recording {
|
||||
panic("not recording")
|
||||
}
|
||||
m.ops.endAux()
|
||||
m.ops.macroDepth--
|
||||
m.recording = false
|
||||
m.fill()
|
||||
|
||||
+10
-5
@@ -25,14 +25,17 @@ type Path struct {
|
||||
pen f32.Point
|
||||
bounds f32.Rectangle
|
||||
hasBounds bool
|
||||
macro op.MacroOp
|
||||
}
|
||||
|
||||
// ClipOp sets the current clip path.
|
||||
type ClipOp struct {
|
||||
macro op.MacroOp
|
||||
bounds f32.Rectangle
|
||||
}
|
||||
|
||||
func (p ClipOp) Add(o *op.Ops) {
|
||||
p.macro.Add(o)
|
||||
data := make([]byte, opconst.TypeClipLen)
|
||||
data[0] = byte(opconst.TypeClip)
|
||||
bo := binary.LittleEndian
|
||||
@@ -46,6 +49,7 @@ func (p ClipOp) Add(o *op.Ops) {
|
||||
// Begin the path, storing the path data and final ClipOp into ops.
|
||||
func (p *Path) Begin(ops *op.Ops) {
|
||||
p.ops = ops
|
||||
p.macro.Record(ops)
|
||||
}
|
||||
|
||||
// MoveTo moves the pen to the given position.
|
||||
@@ -280,11 +284,12 @@ func (p *Path) simpleQuadTo(ctrl, to f32.Point) {
|
||||
p.pen = to
|
||||
}
|
||||
|
||||
// End the path and add the resulting ClipOp to
|
||||
// the operation list passed to Init.
|
||||
func (p *Path) End() {
|
||||
// End the path and return the resulting ClipOp.
|
||||
func (p *Path) End() ClipOp {
|
||||
p.end()
|
||||
ClipOp{
|
||||
p.macro.Stop()
|
||||
return ClipOp{
|
||||
macro: p.macro,
|
||||
bounds: p.bounds,
|
||||
}.Add(p.ops)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user