x-backend #2
@ -1,8 +1,8 @@
|
||||
package x
|
||||
|
||||
import "image"
|
||||
// import "golang.org/x/image/font"
|
||||
// import "golang.org/x/image/font/basicfont"
|
||||
import "golang.org/x/image/font"
|
||||
import "golang.org/x/image/font/basicfont"
|
||||
|
||||
import "github.com/jezek/xgb"
|
||||
import "github.com/jezek/xgbutil"
|
||||
@ -12,6 +12,7 @@ import "github.com/jezek/xgbutil/xevent"
|
||||
import "github.com/jezek/xgbutil/xwindow"
|
||||
import "github.com/jezek/xgbutil/xgraphics"
|
||||
|
||||
|
||||
import "git.tebibyte.media/sashakoshka/stone"
|
||||
|
||||
type Backend struct {
|
||||
@ -28,6 +29,10 @@ type Backend struct {
|
||||
quit chan(struct { })
|
||||
}
|
||||
|
||||
font struct {
|
||||
face font.Face
|
||||
}
|
||||
|
||||
metrics struct {
|
||||
windowWidth int
|
||||
windowHeight int
|
||||
@ -141,6 +146,7 @@ func (backend *Backend) handleXEvent (event xgb.Event) {
|
||||
// backend.canvas.Scale (
|
||||
// backend.metrics.windowWidth,
|
||||
// backend.metrics.windowHeight)
|
||||
backend.drawRune(8, 16, 'X')
|
||||
backend.bindCanvas()
|
||||
}
|
||||
}
|
||||
@ -193,6 +199,10 @@ func (backend *Backend) bindCanvas () {
|
||||
backend.canvas.XPaint(backend.window.Id)
|
||||
}
|
||||
|
||||
func (backend *Backend) drawRune (x, y int, character rune) {
|
||||
|
||||
}
|
||||
|
||||
// factory instantiates an X backend.
|
||||
func factory (application *stone.Application) (output stone.Backend, err error) {
|
||||
backend := &Backend {
|
||||
@ -200,10 +210,16 @@ func factory (application *stone.Application) (output stone.Backend, err error)
|
||||
config: application.Config(),
|
||||
}
|
||||
|
||||
// load font
|
||||
// TODO: load this from a file
|
||||
backend.font.face = basicfont.Face7x13
|
||||
|
||||
// calculate metrics
|
||||
// TODO: base these off of font metrics
|
||||
backend.metrics.cellWidth = 8
|
||||
backend.metrics.cellHeight = 16
|
||||
metrics := backend.font.face.Metrics()
|
||||
glyphAdvance, _ := backend.font.face.GlyphAdvance('M')
|
||||
backend.metrics.cellWidth = glyphAdvance.Round()
|
||||
backend.metrics.cellHeight = metrics.Height.Round()
|
||||
backend.metrics.descent = metrics.Descent.Round()
|
||||
backend.metrics.padding =
|
||||
backend.config.Padding() *
|
||||
backend.metrics.cellHeight
|
||||
|
Loading…
Reference in New Issue
Block a user