x-backend #2
@ -1,7 +1,10 @@
|
||||
package x
|
||||
|
||||
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/basicfont"
|
||||
|
||||
import "github.com/jezek/xgb"
|
||||
@ -12,7 +15,6 @@ 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 {
|
||||
@ -47,6 +49,28 @@ 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
|
||||
|
||||
@ -195,19 +219,56 @@ func (backend *Backend) reallocateCanvas () {
|
||||
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.drawRune(0, 0, 'T')
|
||||
backend.drawRune(1, 0, 'h')
|
||||
backend.drawRune(2, 0, 'e')
|
||||
backend.drawRune(4, 0, 'q')
|
||||
backend.drawRune(5, 0, 'u')
|
||||
backend.drawRune(6, 0, 'i')
|
||||
backend.drawRune(7, 0, 'c')
|
||||
backend.drawRune(8, 0, 'k')
|
||||
|
||||
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, _, _ :=
|
||||
_, 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.Point { },
|
||||
mask,
|
||||
maskPoint,
|
||||
draw.Over)
|
||||
}
|
||||
|
||||
func (backend *Backend) cellSubImage (x, y int) (cell *xgraphics.Image) {
|
||||
cell = backend.canvas.SubImage(backend.boundsOfCell(x, y)).(*xgraphics.Image)
|
||||
return
|
||||
}
|
||||
|
||||
func (backend *Backend) originOfCell (x, y int) (origin image.Point) {
|
||||
origin = image.Point {
|
||||
X: x * backend.metrics.cellWidth + backend.metrics.paddingX,
|
||||
Y: y * backend.metrics.cellHeight + backend.metrics.paddingY,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (backend *Backend) boundsOfCell (x, y int) (bounds image.Rectangle) {
|
||||
bounds = image.Rectangle {
|
||||
Min: backend.originOfCell(x, y),
|
||||
Max: backend.originOfCell(x + 1, y + 1),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// factory instantiates an X backend.
|
||||
|
Loading…
Reference in New Issue
Block a user