31 lines
715 B
Go
31 lines
715 B
Go
|
package bloob
|
||
|
|
||
|
func (image *Image) DrawRect(rect Recti, color Color) {
|
||
|
start, end, _ := CropToArea(image.Size, rect, Vec2i{})
|
||
|
for y := start.Y; y < end.Y; y += 1 {
|
||
|
for x := start.X; x < end.X; x += 1 {
|
||
|
image.Data[x+y*image.Size.X] = color
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (image *Image) DrawRectRounded(rect Recti, color Color, round int) {
|
||
|
round = min(max(rect.Size.X, rect.Size.Y)/2-1, round)
|
||
|
|
||
|
start, end, _ := CropToArea(image.Size, rect, Vec2i{})
|
||
|
for y := start.Y; y < end.Y; y += 1 {
|
||
|
ri := 0
|
||
|
yt := y - start.Y
|
||
|
yp := -(y - end.Y + 1)
|
||
|
if yt < round {
|
||
|
ri = round - yt
|
||
|
}
|
||
|
if yp < round {
|
||
|
ri = round - yp
|
||
|
}
|
||
|
for x := start.X + ri; x < end.X-ri; x += 1 {
|
||
|
image.Data[x+y*image.Size.X] = color
|
||
|
}
|
||
|
}
|
||
|
}
|