51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package ggfx
|
|
|
|
import "image"
|
|
|
|
func (this Image[T]) FillRectangle (fill []T, rectangle image.Rectangle) {
|
|
this.assertWidth(fill)
|
|
rectangle = this.Rect.Intersect(rectangle.Canon())
|
|
if rectangle.Empty () { return }
|
|
|
|
var pos image.Point
|
|
for pos.Y = rectangle.Min.Y; pos.Y < rectangle.Max.Y; pos.Y ++ {
|
|
for offset, part := range fill {
|
|
for pos.X = rectangle.Min.X; pos.X < rectangle.Max.X; pos.X ++ {
|
|
index := this.PixOffset(pos.X, pos.Y) + offset
|
|
this.Pix[index] = part
|
|
}}}
|
|
}
|
|
|
|
func (this Image[T]) StrokeRectangle (stroke []T, weight int, rectangle image.Rectangle) {
|
|
if weight > rectangle.Dx() / 2 || weight > rectangle.Dy() / 2 {
|
|
this.FillRectangle(stroke, rectangle)
|
|
return
|
|
}
|
|
|
|
top := image.Rect (
|
|
rectangle.Min.X,
|
|
rectangle.Min.Y,
|
|
rectangle.Max.X,
|
|
rectangle.Min.Y + weight)
|
|
bottom := image.Rect (
|
|
rectangle.Min.X,
|
|
rectangle.Max.Y - weight,
|
|
rectangle.Max.X,
|
|
rectangle.Max.Y)
|
|
left := image.Rect (
|
|
rectangle.Min.X,
|
|
rectangle.Min.Y + weight,
|
|
rectangle.Min.X + weight,
|
|
rectangle.Max.Y - weight)
|
|
right := image.Rect (
|
|
rectangle.Max.X - weight,
|
|
rectangle.Min.Y + weight,
|
|
rectangle.Max.X,
|
|
rectangle.Max.Y - weight)
|
|
|
|
this.FillRectangle(stroke, top)
|
|
this.FillRectangle(stroke, bottom)
|
|
this.FillRectangle(stroke, left)
|
|
this.FillRectangle(stroke, right)
|
|
}
|