From 8bdca84c56902502e4120cda296232a198f89252 Mon Sep 17 00:00:00 2001 From: Chris Waldon Date: Wed, 21 Oct 2020 21:29:37 -0400 Subject: [PATCH] op/clip: export Op method of clip shapes This allows passing the resulting clip.Op types into functions that draw shapes. Signed-off-by: Chris Waldon --- op/clip/clip.go | 7 ++++++- op/clip/shapes.go | 11 ++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/op/clip/clip.go b/op/clip/clip.go index 955a6e0f..d85ea630 100644 --- a/op/clip/clip.go +++ b/op/clip/clip.go @@ -324,7 +324,12 @@ func (p *Path) End() Op { // Rect represents the clip area of a pixel-aligned rectangle. type Rect image.Rectangle +// Op returns the op for the rectangle. +func (r Rect) Op(ops *op.Ops) Op { + return Op{bounds: image.Rectangle(r)} +} + // Add the clip operation. func (r Rect) Add(ops *op.Ops) { - Op{bounds: image.Rectangle(r)}.Add(ops) + r.Op(ops).Add(ops) } diff --git a/op/clip/shapes.go b/op/clip/shapes.go index 3c16ec3c..52091290 100644 --- a/op/clip/shapes.go +++ b/op/clip/shapes.go @@ -18,8 +18,8 @@ type RRect struct { SE, SW, NW, NE float32 } -// op returns the op for the rectangle. -func (rr RRect) op(ops *op.Ops) Op { +// Op returns the op for the rounded rectangle. +func (rr RRect) Op(ops *op.Ops) Op { var p Path p.Begin(ops) p.Move(rr.Rect.Min) @@ -29,7 +29,7 @@ func (rr RRect) op(ops *op.Ops) Op { // Add the rectangle clip. func (rr RRect) Add(ops *op.Ops) { - rr.op(ops).Add(ops) + rr.Op(ops).Add(ops) } // Border represents the clip area of a rectangular border. @@ -41,7 +41,8 @@ type Border struct { SE, SW, NW, NE float32 } -func (b Border) op(ops *op.Ops) Op { +// Op returns the Op for the border. +func (b Border) Op(ops *op.Ops) Op { var p Path p.Begin(ops) w := b.Width @@ -65,7 +66,7 @@ func (b Border) op(ops *op.Ops) Op { // Add the border clip. func (rr Border) Add(ops *op.Ops) { - rr.op(ops).Add(ops) + rr.Op(ops).Add(ops) } // roundRect adds the outline of a rectangle with rounded corners to a