Remove fakeImage struct and replace with image.Uniform

This commit is contained in:
2022-11-11 14:51:08 -05:00
parent 93b02b4628
commit ed5c6829d4
4 changed files with 40 additions and 28 deletions

View File

@@ -1,10 +1,11 @@
package x
// import "os"
import "image"
import "image/draw"
import "image/color"
import "golang.org/x/image/font"
import "golang.org/x/image/math/fixed"
// import "golang.org/x/image/font/opentype"
import "golang.org/x/image/font/basicfont"
import "github.com/jezek/xgb"
@@ -17,6 +18,8 @@ import "github.com/jezek/xgbutil/xgraphics"
import "git.tebibyte.media/sashakoshka/stone"
// import "github.com/flopp/go-findfont"
type Backend struct {
application *stone.Application
config *stone.Config
@@ -49,28 +52,6 @@ type Backend struct {
}
}
type fakeImage struct {
color color.Color
}
func (fake fakeImage) ColorModel () (model color.Model) {
model = color.RGBAModel
return
}
func (fake fakeImage) Bounds () (bounds image.Rectangle) {
bounds.Max = image.Point {
X: 1024,
Y: 1024,
}
return
}
func (fake fakeImage) At (x, y int) (pixel color.Color) {
pixel = fake.color
return
}
func (backend *Backend) Run (channel chan(stone.Event)) {
backend.channel = channel
@@ -235,14 +216,17 @@ func (backend *Backend) reallocateCanvas () {
}
func (backend *Backend) drawRune (x, y int, character rune) {
// TODO: cache these draws as non-transparent buffers with the
// application background color as the background. that way, we won't
// need to redraw the characters *or* composite them.
_, mask, maskPoint, _, _ := backend.font.face.Glyph (
fixed.Point26_6 { },
character)
draw.DrawMask (
backend.canvas,
backend.boundsOfCell(x, y),
fakeImage {
color: backend.config.Color(stone.ColorForeground),
&image.Uniform {
C: backend.config.Color(stone.ColorForeground),
},
image.Point { },
mask,
@@ -279,8 +263,12 @@ func factory (application *stone.Application) (output stone.Backend, err error)
}
// load font
// TODO: load this from a file
backend.font.face = basicfont.Face7x13
backend.font.face = findAndLoadFont (
backend.config.FontName(),
float64(backend.config.FontSize()))
if backend.font.face == nil {
backend.font.face = basicfont.Face7x13
}
// pre-calculate colors
for index := 0; index < len(backend.colors); index ++ {
@@ -347,6 +335,23 @@ func factory (application *stone.Application) (output stone.Backend, err error)
return
}
func findAndLoadFont (name string, size float64) (face font.Face) {
// fontPath, err := findfont.Find(name)
// if err != nil { return }
// fontFile, err := os.Open(fontPath)
// if err != nil { return }
// fontObject, err := opentype.ParseReaderAt(fontFile)
// if err != nil { return }
// face, err = opentype.NewFace (fontObject, &opentype.FaceOptions {
// Size: size,
// DPI: 96,
// Hinting: font.HintingFull,
// })
// if err != nil { face = nil }
return
}
// init registers this backend when the program starts.
func init () {
stone.RegisterBackend(factory)