mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 01:45:36 +00:00
op: remove op.Save
op.Save, op.SaveStack were compatibility stop-gaps. API change. Most op.Save/Loads can safely be removed altogether, or replaced with trans := op.Offset(f32.Pt(0, 0).Push(gtx.Ops) ... trans.Pop() cl := clip.Rect(image.Rect(-1e6, -1e6, 1e6, 1e6)).Push(gtx.Ops) ... cl.Pop() Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -67,7 +67,6 @@ package op
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"image"
|
|
||||||
"math"
|
"math"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -140,49 +139,6 @@ func Defer(o *Ops, c CallOp) {
|
|||||||
c.Add(o)
|
c.Add(o)
|
||||||
}
|
}
|
||||||
|
|
||||||
type SaveStack struct {
|
|
||||||
ops *ops.Ops
|
|
||||||
clip struct {
|
|
||||||
id ops.StackID
|
|
||||||
macroID int
|
|
||||||
}
|
|
||||||
trans TransformStack
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deprecated: use state-specific stack operations instead (TransformOp.Push
|
|
||||||
// etc.).
|
|
||||||
func Save(o *Ops) SaveStack {
|
|
||||||
st := SaveStack{
|
|
||||||
ops: &o.Internal,
|
|
||||||
trans: Offset(f32.Point{}).Push(o),
|
|
||||||
}
|
|
||||||
const inf = 1e6
|
|
||||||
bounds := image.Rectangle{Min: image.Pt(-inf, -inf), Max: image.Pt(inf, inf)}
|
|
||||||
{
|
|
||||||
st.clip.id, st.clip.macroID = ops.PushOp(&o.Internal, ops.ClipStack)
|
|
||||||
// Push clip stack with no-op (infinite) clipping rect. Copied from clip.Op.Push.
|
|
||||||
bo := binary.LittleEndian
|
|
||||||
data := ops.Write(&o.Internal, ops.TypeClipLen)
|
|
||||||
data[0] = byte(ops.TypeClip)
|
|
||||||
bo.PutUint32(data[1:], uint32(bounds.Min.X))
|
|
||||||
bo.PutUint32(data[5:], uint32(bounds.Min.Y))
|
|
||||||
bo.PutUint32(data[9:], uint32(bounds.Max.X))
|
|
||||||
bo.PutUint32(data[13:], uint32(bounds.Max.Y))
|
|
||||||
data[17] = byte(1) // Outline
|
|
||||||
data[18] = byte(1) // Push
|
|
||||||
}
|
|
||||||
return st
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s SaveStack) Load() {
|
|
||||||
// Pop clip.
|
|
||||||
ops.PopOp(s.ops, ops.ClipStack, s.clip.id, s.clip.macroID)
|
|
||||||
data := ops.Write(s.ops, ops.TypePopClipLen)
|
|
||||||
data[0] = byte(ops.TypePopClip)
|
|
||||||
|
|
||||||
s.trans.Pop()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reset the Ops, preparing it for re-use. Reset invalidates
|
// Reset the Ops, preparing it for re-use. Reset invalidates
|
||||||
// any recorded macros.
|
// any recorded macros.
|
||||||
func (o *Ops) Reset() {
|
func (o *Ops) Reset() {
|
||||||
|
|||||||
Reference in New Issue
Block a user