Implemented some shape drawing functions to debug character positioning

This commit is contained in:
Sasha Koshka 2022-11-11 15:20:52 -05:00
parent cc498fa89c
commit 8ef81ecc7f

View File

@ -222,6 +222,12 @@ func (backend *Backend) drawRune (x, y int, character rune) {
_, mask, maskPoint, _, _ := backend.font.face.Glyph (
fixed.Point26_6 { },
character)
strokeRectangle (
&image.Uniform {
C: backend.config.Color(stone.ColorForeground),
},
backend.canvas,
backend.boundsOfCell(x, y))
draw.DrawMask (
backend.canvas,
backend.boundsOfCell(x, y),
@ -352,6 +358,44 @@ func findAndLoadFont (name string, size float64) (face font.Face) {
return
}
func fillRectangle (
source image.Image,
destination draw.Image,
bounds image.Rectangle,
) {
for y := bounds.Min.Y; y < bounds.Max.Y; y ++ {
for x := bounds.Min.X; x < bounds.Max.X; x ++ {
destination.Set(x, y, source.At(x, y))
}}
}
func strokeRectangle (
source image.Image,
destination draw.Image,
bounds image.Rectangle,
) {
x := 0
y := bounds.Min.Y
for x = bounds.Min.X; x < bounds.Max.X; x ++ {
destination.Set(x, y, source.At(x, y))
}
y = bounds.Max.Y - 1
for x = bounds.Min.X; x < bounds.Max.X; x ++ {
destination.Set(x, y, source.At(x, y))
}
x = bounds.Min.X
for y = bounds.Min.Y; y < bounds.Max.Y; y ++ {
destination.Set(x, y, source.At(x, y))
}
x = bounds.Max.X - 1
for y = bounds.Min.Y; y < bounds.Max.Y; y ++ {
destination.Set(x, y, source.At(x, y))
}
}
// init registers this backend when the program starts.
func init () {
stone.RegisterBackend(factory)