x-backend #2
@ -33,6 +33,8 @@ type Backend struct {
|
|||||||
face font.Face
|
face font.Face
|
||||||
}
|
}
|
||||||
|
|
||||||
|
colors [4]xgraphics.BGRA
|
||||||
|
|
||||||
metrics struct {
|
metrics struct {
|
||||||
windowWidth int
|
windowWidth int
|
||||||
windowHeight int
|
windowHeight int
|
||||||
@ -134,20 +136,7 @@ func (backend *Backend) handleXEvent (event xgb.Event) {
|
|||||||
backend.compressConfigureNotify(configureEvent)
|
backend.compressConfigureNotify(configureEvent)
|
||||||
|
|
||||||
// resize and rebind canvas
|
// resize and rebind canvas
|
||||||
backend.canvas.Destroy()
|
backend.reallocateCanvas()
|
||||||
backend.canvas = xgraphics.New (
|
|
||||||
backend.connection,
|
|
||||||
image.Rect (
|
|
||||||
0, 0,
|
|
||||||
backend.metrics.windowWidth,
|
|
||||||
backend.metrics.windowHeight))
|
|
||||||
// FIXME (?): this doesn't work. if it were to work, it
|
|
||||||
// would possibly be a cleaner way to resize the canvas.
|
|
||||||
// backend.canvas.Scale (
|
|
||||||
// backend.metrics.windowWidth,
|
|
||||||
// backend.metrics.windowHeight)
|
|
||||||
backend.drawRune(8, 16, 'X')
|
|
||||||
backend.bindCanvas()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -193,14 +182,32 @@ func (backend *Backend) calculateWindowSize () (x, y int) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (backend *Backend) bindCanvas () {
|
func (backend *Backend) reallocateCanvas () {
|
||||||
|
if backend.canvas != nil {
|
||||||
|
backend.canvas.Destroy()
|
||||||
|
}
|
||||||
|
backend.canvas = xgraphics.New (
|
||||||
|
backend.connection,
|
||||||
|
image.Rect (
|
||||||
|
0, 0,
|
||||||
|
backend.metrics.windowWidth,
|
||||||
|
backend.metrics.windowHeight))
|
||||||
|
backend.canvas.For (func (x, y int) xgraphics.BGRA {
|
||||||
|
return backend.colors[stone.ColorApplication]
|
||||||
|
})
|
||||||
|
// FIXME (?): this doesn't work. if it were to work, it
|
||||||
|
// would possibly be a cleaner way to resize the canvas.
|
||||||
|
// backend.canvas.Scale (
|
||||||
|
// backend.metrics.windowWidth,
|
||||||
|
// backend.metrics.windowHeight)
|
||||||
|
backend.drawRune(8, 16, 'X')
|
||||||
backend.canvas.XSurfaceSet(backend.window.Id)
|
backend.canvas.XSurfaceSet(backend.window.Id)
|
||||||
backend.canvas.XDraw()
|
backend.canvas.XDraw()
|
||||||
backend.canvas.XPaint(backend.window.Id)
|
backend.canvas.XPaint(backend.window.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (backend *Backend) drawRune (x, y int, character rune) {
|
func (backend *Backend) drawRune (x, y int, character rune) {
|
||||||
|
// bounds, image, point, _, _ :=
|
||||||
}
|
}
|
||||||
|
|
||||||
// factory instantiates an X backend.
|
// factory instantiates an X backend.
|
||||||
@ -214,6 +221,22 @@ func factory (application *stone.Application) (output stone.Backend, err error)
|
|||||||
// TODO: load this from a file
|
// TODO: load this from a file
|
||||||
backend.font.face = basicfont.Face7x13
|
backend.font.face = basicfont.Face7x13
|
||||||
|
|
||||||
|
// pre-calculate colors
|
||||||
|
for index := 0; index < len(backend.colors); index ++ {
|
||||||
|
color := backend.config.Color(stone.Color(index))
|
||||||
|
r, g, b, a := color.RGBA()
|
||||||
|
r >>= 8
|
||||||
|
g >>= 8
|
||||||
|
b >>= 8
|
||||||
|
a >>= 8
|
||||||
|
backend.colors[index] = xgraphics.BGRA {
|
||||||
|
R: uint8(r),
|
||||||
|
G: uint8(g),
|
||||||
|
B: uint8(b),
|
||||||
|
A: uint8(a),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// calculate metrics
|
// calculate metrics
|
||||||
metrics := backend.font.face.Metrics()
|
metrics := backend.font.face.Metrics()
|
||||||
glyphAdvance, _ := backend.font.face.GlyphAdvance('M')
|
glyphAdvance, _ := backend.font.face.GlyphAdvance('M')
|
||||||
@ -246,13 +269,7 @@ func factory (application *stone.Application) (output stone.Backend, err error)
|
|||||||
backend.SetIcon(application.Icon())
|
backend.SetIcon(application.Icon())
|
||||||
|
|
||||||
// create a canvas
|
// create a canvas
|
||||||
backend.canvas = xgraphics.New (
|
backend.reallocateCanvas()
|
||||||
backend.connection,
|
|
||||||
image.Rect (
|
|
||||||
0, 0,
|
|
||||||
backend.metrics.windowWidth,
|
|
||||||
backend.metrics.windowHeight))
|
|
||||||
backend.bindCanvas()
|
|
||||||
|
|
||||||
// attatch graceful close handler
|
// attatch graceful close handler
|
||||||
backend.window.WMGracefulClose (func (window *xwindow.Window) {
|
backend.window.WMGracefulClose (func (window *xwindow.Window) {
|
||||||
|
Loading…
Reference in New Issue
Block a user