diff --git a/backends/x/x.go b/backends/x/x.go index ec588e3..df34e69 100644 --- a/backends/x/x.go +++ b/backends/x/x.go @@ -32,6 +32,8 @@ type Backend struct { font struct { face font.Face } + + colors [4]xgraphics.BGRA metrics struct { windowWidth int @@ -134,20 +136,7 @@ func (backend *Backend) handleXEvent (event xgb.Event) { backend.compressConfigureNotify(configureEvent) // resize and rebind canvas - backend.canvas.Destroy() - 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() + backend.reallocateCanvas() } } } @@ -193,14 +182,32 @@ func (backend *Backend) calculateWindowSize () (x, y int) { 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.XDraw() backend.canvas.XPaint(backend.window.Id) } func (backend *Backend) drawRune (x, y int, character rune) { - + // bounds, image, point, _, _ := } // 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 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 metrics := backend.font.face.Metrics() glyphAdvance, _ := backend.font.face.GlyphAdvance('M') @@ -246,13 +269,7 @@ func factory (application *stone.Application) (output stone.Backend, err error) backend.SetIcon(application.Icon()) // create a canvas - backend.canvas = xgraphics.New ( - backend.connection, - image.Rect ( - 0, 0, - backend.metrics.windowWidth, - backend.metrics.windowHeight)) - backend.bindCanvas() + backend.reallocateCanvas() // attatch graceful close handler backend.window.WMGracefulClose (func (window *xwindow.Window) {