From c91d4577e7126d18246b2cb963b317589eccf76b Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Fri, 8 Sep 2023 16:39:58 -0400 Subject: [PATCH] Minor drawing fixess --- canvas/canvas.go | 2 +- canvas/line.go | 5 +++-- canvasbox.go | 10 +++++++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/canvas/canvas.go b/canvas/canvas.go index 9ab229c..838eade 100644 --- a/canvas/canvas.go +++ b/canvas/canvas.go @@ -97,7 +97,7 @@ func (this *pen) Path (points ...image.Point) { if this.fill.A > 0 { this.fillPolygon(this.fill, points...) } - } else if this.closed { + } else if this.closed && len(points) > 2 { if this.stroke.A > 0 { this.strokePolygon(this.stroke, points...) } diff --git a/canvas/line.go b/canvas/line.go index 7f507cc..e7dec33 100644 --- a/canvas/line.go +++ b/canvas/line.go @@ -3,6 +3,7 @@ package xcanvas import "image" import "github.com/jezek/xgbutil/xgraphics" +// TODO: clip the line to the bounds func (this *pen) line ( c xgraphics.BGRA, min image.Point, @@ -17,11 +18,11 @@ func (this *pen) line ( min: min, max: max, } - + if abs(max.Y - min.Y) < abs(max.X - min.X) { if max.X < min.X { context.swap() } context.lineLow() - + } else { if max.Y < min.Y { context.swap() } context.lineHigh() diff --git a/canvasbox.go b/canvasbox.go index 384fab4..13fd62a 100644 --- a/canvasbox.go +++ b/canvasbox.go @@ -5,11 +5,13 @@ import "git.tebibyte.media/tomo/tomo/canvas" type canvasBox struct { *box + userDrawer canvas.Drawer } func (backend *Backend) NewCanvasBox () tomo.CanvasBox { this := &canvasBox { } this.box = backend.newBox(this) + this.drawer = this return this } @@ -18,10 +20,16 @@ func (this *canvasBox) Box () tomo.Box { } func (this *canvasBox) SetDrawer (drawer canvas.Drawer) { - this.drawer = drawer + this.userDrawer = drawer this.invalidateDraw() } func (this *canvasBox) Invalidate () { this.invalidateDraw() } + +func (this *canvasBox) Draw (can canvas.Canvas) { + this.box.Draw(can) + this.userDrawer.Draw ( + can.Clip(this.padding.Apply(this.innerClippingBounds))) +}