Minor drawing fixess

This commit is contained in:
Sasha Koshka 2023-09-08 16:39:58 -04:00
parent db2ed06daf
commit c91d4577e7
3 changed files with 13 additions and 4 deletions

View File

@ -97,7 +97,7 @@ func (this *pen) Path (points ...image.Point) {
if this.fill.A > 0 { if this.fill.A > 0 {
this.fillPolygon(this.fill, points...) this.fillPolygon(this.fill, points...)
} }
} else if this.closed { } else if this.closed && len(points) > 2 {
if this.stroke.A > 0 { if this.stroke.A > 0 {
this.strokePolygon(this.stroke, points...) this.strokePolygon(this.stroke, points...)
} }

View File

@ -3,6 +3,7 @@ package xcanvas
import "image" import "image"
import "github.com/jezek/xgbutil/xgraphics" import "github.com/jezek/xgbutil/xgraphics"
// TODO: clip the line to the bounds
func (this *pen) line ( func (this *pen) line (
c xgraphics.BGRA, c xgraphics.BGRA,
min image.Point, min image.Point,
@ -17,11 +18,11 @@ func (this *pen) line (
min: min, min: min,
max: max, max: max,
} }
if abs(max.Y - min.Y) < abs(max.X - min.X) { if abs(max.Y - min.Y) < abs(max.X - min.X) {
if max.X < min.X { context.swap() } if max.X < min.X { context.swap() }
context.lineLow() context.lineLow()
} else { } else {
if max.Y < min.Y { context.swap() } if max.Y < min.Y { context.swap() }
context.lineHigh() context.lineHigh()

View File

@ -5,11 +5,13 @@ import "git.tebibyte.media/tomo/tomo/canvas"
type canvasBox struct { type canvasBox struct {
*box *box
userDrawer canvas.Drawer
} }
func (backend *Backend) NewCanvasBox () tomo.CanvasBox { func (backend *Backend) NewCanvasBox () tomo.CanvasBox {
this := &canvasBox { } this := &canvasBox { }
this.box = backend.newBox(this) this.box = backend.newBox(this)
this.drawer = this
return this return this
} }
@ -18,10 +20,16 @@ func (this *canvasBox) Box () tomo.Box {
} }
func (this *canvasBox) SetDrawer (drawer canvas.Drawer) { func (this *canvasBox) SetDrawer (drawer canvas.Drawer) {
this.drawer = drawer this.userDrawer = drawer
this.invalidateDraw() this.invalidateDraw()
} }
func (this *canvasBox) Invalidate () { func (this *canvasBox) Invalidate () {
this.invalidateDraw() this.invalidateDraw()
} }
func (this *canvasBox) Draw (can canvas.Canvas) {
this.box.Draw(can)
this.userDrawer.Draw (
can.Clip(this.padding.Apply(this.innerClippingBounds)))
}