mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-04 00:45:35 +00:00
op/clip: split Rect into pixel-aligned Rect and rounded RRect
The pixel-aligned Rect is more efficient and easier to use in the common case of layout clipping. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -158,7 +158,7 @@ func draw1000Circles(gtx layout.Context) {
|
||||
for y := 0; y < 10; y++ {
|
||||
pi := op.Push(ops)
|
||||
paint.ColorOp{Color: color.RGBA{R: 100 + uint8(x), G: 100 + uint8(y), B: 100, A: 120}}.Add(ops)
|
||||
clip.Rect{Rect: f32.Rect(0, 0, 10, 10), NE: 5, SE: 5, SW: 5, NW: 5}.Add(ops)
|
||||
clip.RRect{Rect: f32.Rect(0, 0, 10, 10), NE: 5, SE: 5, SW: 5, NW: 5}.Add(ops)
|
||||
paint.PaintOp{Rect: f32.Rect(0, 0, 10, 10)}.Add(ops)
|
||||
pi.Pop()
|
||||
op.Offset(f32.Pt(0, float32(100))).Add(ops)
|
||||
@@ -171,7 +171,7 @@ func draw1000CirclesInstanced(gtx layout.Context) {
|
||||
ops := gtx.Ops
|
||||
|
||||
r := op.Record(ops)
|
||||
clip.Rect{Rect: f32.Rect(0, 0, 10, 10), NE: 5, SE: 5, SW: 5, NW: 5}.Add(ops)
|
||||
clip.RRect{Rect: f32.Rect(0, 0, 10, 10), NE: 5, SE: 5, SW: 5, NW: 5}.Add(ops)
|
||||
paint.PaintOp{Rect: f32.Rect(0, 0, 10, 10)}.Add(ops)
|
||||
c := r.Stop()
|
||||
|
||||
@@ -210,7 +210,7 @@ func drawIndividualShapes(gtx layout.Context, th *material.Theme) chan op.CallOp
|
||||
for y := 0; y < 9; y++ {
|
||||
pi := op.Push(ops)
|
||||
paint.ColorOp{Color: color.RGBA{R: 100 + uint8(x), G: 100 + uint8(y), B: 100, A: 120}}.Add(ops)
|
||||
clip.Rect{Rect: f32.Rect(0, 0, 25, 25), NE: 10, SE: 10, SW: 10, NW: 10}.Add(ops)
|
||||
clip.RRect{Rect: f32.Rect(0, 0, 25, 25), NE: 10, SE: 10, SW: 10, NW: 10}.Add(ops)
|
||||
paint.PaintOp{Rect: f32.Rect(0, 0, 25, 25)}.Add(ops)
|
||||
pi.Pop()
|
||||
op.Offset(f32.Pt(0, float32(50))).Add(ops)
|
||||
@@ -229,7 +229,7 @@ func drawShapeInstances(gtx layout.Context, th *material.Theme) chan op.CallOp {
|
||||
co := op.Record(ops)
|
||||
|
||||
r := op.Record(ops)
|
||||
clip.Rect{Rect: f32.Rect(0, 0, 25, 25), NE: 10, SE: 10, SW: 10, NW: 10}.Add(ops)
|
||||
clip.RRect{Rect: f32.Rect(0, 0, 25, 25), NE: 10, SE: 10, SW: 10, NW: 10}.Add(ops)
|
||||
paint.PaintOp{Rect: f32.Rect(0, 0, 25, 25)}.Add(ops)
|
||||
c := r.Stop()
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ func TestPaintRect(t *testing.T) {
|
||||
func TestPaintClippedRect(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
paint.ColorOp{Color: colornames.Red}.Add(o)
|
||||
clip.Rect{Rect: f32.Rect(25, 25, 60, 60)}.Add(o)
|
||||
clip.RRect{Rect: f32.Rect(25, 25, 60, 60)}.Add(o)
|
||||
paint.PaintOp{Rect: f32.Rect(0, 0, 50, 50)}.Add(o)
|
||||
}, func(r result) {
|
||||
r.expect(0, 0, colornames.White)
|
||||
@@ -40,7 +40,7 @@ func TestPaintClippedCirle(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
paint.ColorOp{Color: colornames.Red}.Add(o)
|
||||
r := float32(10)
|
||||
clip.Rect{Rect: f32.Rect(20, 20, 40, 40), SE: r, SW: r, NW: r, NE: r}.Add(o)
|
||||
clip.RRect{Rect: f32.Rect(20, 20, 40, 40), SE: r, SW: r, NW: r, NE: r}.Add(o)
|
||||
paint.PaintOp{Rect: f32.Rect(0, 0, 30, 50)}.Add(o)
|
||||
}, func(r result) {
|
||||
r.expect(21, 21, colornames.White)
|
||||
@@ -64,7 +64,7 @@ func TestPaintTexture(t *testing.T) {
|
||||
func TestPaintClippedTexture(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
squares.Add(o)
|
||||
clip.Rect{Rect: f32.Rect(0, 0, 40, 40)}.Add(o)
|
||||
clip.RRect{Rect: f32.Rect(0, 0, 40, 40)}.Add(o)
|
||||
paint.PaintOp{Rect: f32.Rect(0, 0, 80, 80)}.Add(o)
|
||||
}, func(r result) {
|
||||
r.expect(40, 40, colornames.White)
|
||||
|
||||
@@ -118,7 +118,7 @@ func constSqPath() op.CallOp {
|
||||
func constSqCirc() op.CallOp {
|
||||
innerOps := new(op.Ops)
|
||||
m := op.Record(innerOps)
|
||||
clip.Rect{Rect: f32.Rect(0, 0, 40, 40),
|
||||
clip.RRect{Rect: f32.Rect(0, 0, 40, 40),
|
||||
NW: 20, NE: 20, SW: 20, SE: 20}.Add(innerOps)
|
||||
return m.Stop()
|
||||
}
|
||||
@@ -185,7 +185,7 @@ func TestBuildOffscreen(t *testing.T) {
|
||||
|
||||
func TestNegativeOverlaps(t *testing.T) {
|
||||
run(t, func(ops *op.Ops) {
|
||||
clip.Rect{Rect: f32.Rect(50, 50, 100, 100)}.Add(ops)
|
||||
clip.RRect{Rect: f32.Rect(50, 50, 100, 100)}.Add(ops)
|
||||
paint.PaintOp{Rect: f32.Rect(0, 120, 100, 122)}.Add(ops)
|
||||
}, func(r result) {
|
||||
r.expect(60, 60, colornames.White)
|
||||
|
||||
@@ -52,7 +52,7 @@ func TestPaintShear(t *testing.T) {
|
||||
func TestClipPaintOffset(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
paint.ColorOp{Color: colornames.Red}.Add(o)
|
||||
clip.Rect{Rect: f32.Rect(10, 10, 30, 30)}.Add(o)
|
||||
clip.RRect{Rect: f32.Rect(10, 10, 30, 30)}.Add(o)
|
||||
op.Offset(f32.Pt(20, 20)).Add(o)
|
||||
paint.PaintOp{Rect: f32.Rect(0, 0, 100, 100)}.Add(o)
|
||||
}, func(r result) {
|
||||
@@ -67,7 +67,7 @@ func TestClipOffset(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
paint.ColorOp{Color: colornames.Red}.Add(o)
|
||||
op.Offset(f32.Pt(20, 20)).Add(o)
|
||||
clip.Rect{Rect: f32.Rect(10, 10, 30, 30)}.Add(o)
|
||||
clip.RRect{Rect: f32.Rect(10, 10, 30, 30)}.Add(o)
|
||||
paint.PaintOp{Rect: f32.Rect(0, 0, 100, 100)}.Add(o)
|
||||
}, func(r result) {
|
||||
r.expect(0, 0, colornames.White)
|
||||
@@ -83,7 +83,7 @@ func TestClipScale(t *testing.T) {
|
||||
paint.ColorOp{Color: colornames.Red}.Add(o)
|
||||
a := f32.Affine2D{}.Scale(f32.Point{}, f32.Pt(2, 2)).Offset(f32.Pt(10, 10))
|
||||
op.Affine(a).Add(o)
|
||||
clip.Rect{Rect: f32.Rect(10, 10, 20, 20)}.Add(o)
|
||||
clip.RRect{Rect: f32.Rect(10, 10, 20, 20)}.Add(o)
|
||||
paint.PaintOp{Rect: f32.Rect(0, 0, 1000, 1000)}.Add(o)
|
||||
}, func(r result) {
|
||||
r.expect(19+10, 19+10, colornames.White)
|
||||
@@ -97,7 +97,7 @@ func TestClipRotate(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
paint.ColorOp{Color: colornames.Red}.Add(o)
|
||||
op.Affine(f32.Affine2D{}.Rotate(f32.Pt(40, 40), -math.Pi/4)).Add(o)
|
||||
clip.Rect{Rect: f32.Rect(30, 30, 50, 50)}.Add(o)
|
||||
clip.RRect{Rect: f32.Rect(30, 30, 50, 50)}.Add(o)
|
||||
paint.PaintOp{Rect: f32.Rect(0, 40, 100, 100)}.Add(o)
|
||||
}, func(r result) {
|
||||
r.expect(39, 39, colornames.White)
|
||||
@@ -148,7 +148,7 @@ func TestRotateClipTexture(t *testing.T) {
|
||||
squares.Add(o)
|
||||
a := f32.Affine2D{}.Rotate(f32.Pt(40, 40), math.Pi/8)
|
||||
op.Affine(a).Add(o)
|
||||
clip.Rect{Rect: f32.Rect(30, 30, 50, 50)}.Add(o)
|
||||
clip.RRect{Rect: f32.Rect(30, 30, 50, 50)}.Add(o)
|
||||
paint.PaintOp{Rect: f32.Rect(10, 10, 70, 70)}.Add(o)
|
||||
}, func(r result) {
|
||||
r.expect(0, 0, colornames.White)
|
||||
@@ -164,11 +164,11 @@ func TestComplicatedTransform(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
squares.Add(o)
|
||||
|
||||
clip.Rect{Rect: f32.Rect(0, 0, 100, 100), SE: 50, SW: 50, NW: 50, NE: 50}.Add(o)
|
||||
clip.RRect{Rect: f32.Rect(0, 0, 100, 100), SE: 50, SW: 50, NW: 50, NE: 50}.Add(o)
|
||||
|
||||
a := f32.Affine2D{}.Shear(f32.Point{}, math.Pi/4, 0)
|
||||
op.Affine(a).Add(o)
|
||||
clip.Rect{Rect: f32.Rect(0, 0, 50, 40)}.Add(o)
|
||||
clip.RRect{Rect: f32.Rect(0, 0, 50, 40)}.Add(o)
|
||||
|
||||
op.Offset(f32.Pt(-100, -100)).Add(o)
|
||||
paint.PaintOp{Rect: f32.Rect(100, 100, 150, 150)}.Add(o)
|
||||
|
||||
Reference in New Issue
Block a user