Implemented StrokeRectangle

This commit is contained in:
Sasha Koshka 2023-01-14 13:40:05 -05:00
parent ec24eb7b4f
commit b52696025a
3 changed files with 45 additions and 1 deletions

View File

@ -3,6 +3,8 @@ package artist
import "image" import "image"
import "git.tebibyte.media/sashakoshka/tomo" import "git.tebibyte.media/sashakoshka/tomo"
// Line draws a line from one point to another with the specified weight and
// pattern.
func Line ( func Line (
destination tomo.Canvas, destination tomo.Canvas,
source Pattern, source Pattern,

View File

@ -50,3 +50,44 @@ func FillRectangle (
}} }}
return return
} }
// StrokeRectangle draws the outline of a rectangle with the specified line
// weight and pattern.
func StrokeRectangle (
destination tomo.Canvas,
source Pattern,
weight int,
bounds image.Rectangle,
) {
bounds = bounds.Canon()
insetBounds := bounds.Inset(weight)
if insetBounds.Empty() {
FillRectangle(destination, source, bounds)
return
}
// top
FillRectangle (destination, source, image.Rect (
bounds.Min.X, bounds.Min.Y,
insetBounds.Max.X, insetBounds.Min.Y))
// bottom
FillRectangle (destination, source, image.Rect (
bounds.Min.X, insetBounds.Max.Y,
insetBounds.Max.X, bounds.Max.Y))
// left
FillRectangle (destination, source, image.Rect (
bounds.Min.X, insetBounds.Min.Y,
insetBounds.Min.X, insetBounds.Max.Y))
// right
FillRectangle (destination, source, image.Rect (
insetBounds.Max.X, insetBounds.Min.Y,
bounds.Max.X, insetBounds.Max.Y))
}
// TODO: FillEllipse
// TODO: StrokeEllipse

View File

@ -107,7 +107,8 @@ func (drawer *TextDrawer) Draw (
} }
if !drawer.layoutClean { drawer.recalculate() } if !drawer.layoutClean { drawer.recalculate() }
// TODO: reimplement a version of draw mask that takes in a pattern // TODO: reimplement a version of draw mask that takes in a pattern and
// only draws to a tomo.Canvas.
for _, word := range drawer.layout { for _, word := range drawer.layout {
for _, character := range word.text { for _, character := range word.text {
destinationRectangle, destinationRectangle,