Application must now manually call application.Draw in all cases
This behavior is way more consistent, and it makes the drawing code a bit simpler.
This commit is contained in:
parent
c865f7146a
commit
e4f97a918a
@ -53,6 +53,11 @@ type Backend struct {
|
||||
paddingY int
|
||||
descent int
|
||||
}
|
||||
|
||||
memory struct {
|
||||
windowWidth int
|
||||
windowHeight int
|
||||
}
|
||||
}
|
||||
|
||||
func (backend *Backend) Run (channel chan(stone.Event)) {
|
||||
@ -86,6 +91,16 @@ func (backend *Backend) Run (channel chan(stone.Event)) {
|
||||
func (backend *Backend) Draw () {
|
||||
backend.drawLock.Lock()
|
||||
defer backend.drawLock.Unlock()
|
||||
|
||||
boundsChanged :=
|
||||
backend.memory.windowWidth != backend.metrics.windowWidth ||
|
||||
backend.memory.windowHeight != backend.metrics.windowHeight
|
||||
backend.memory.windowWidth = backend.metrics.windowWidth
|
||||
backend.memory.windowHeight = backend.metrics.windowHeight
|
||||
|
||||
if boundsChanged {
|
||||
backend.reallocateCanvas()
|
||||
}
|
||||
|
||||
backend.drawCells(true)
|
||||
backend.canvas.XDraw()
|
||||
@ -152,10 +167,6 @@ func (backend *Backend) handleXEvent (event xgb.Event) {
|
||||
if sizeChanged {
|
||||
configureEvent =
|
||||
backend.compressConfigureNotify(configureEvent)
|
||||
// TODO: remove draw functions from reallocate canvas,
|
||||
// and only reallocate when drawing and the window
|
||||
// dimensions have changed
|
||||
backend.reallocateCanvas()
|
||||
backend.application.SetSize(backend.calculateBufferSize())
|
||||
backend.channel <- stone.EventResize { }
|
||||
}
|
||||
@ -214,9 +225,6 @@ func (backend *Backend) calculateBufferSize () (width, height int) {
|
||||
}
|
||||
|
||||
func (backend *Backend) reallocateCanvas () {
|
||||
backend.drawLock.Lock()
|
||||
defer backend.drawLock.Unlock()
|
||||
|
||||
if backend.canvas != nil {
|
||||
backend.canvas.Destroy()
|
||||
}
|
||||
@ -230,28 +238,7 @@ func (backend *Backend) reallocateCanvas () {
|
||||
return backend.colors[stone.ColorApplication]
|
||||
})
|
||||
|
||||
// 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.drawRune(0, 1, 'b')
|
||||
// backend.drawRune(1, 1, 'r')
|
||||
// backend.drawRune(2, 1, 'o')
|
||||
// backend.drawRune(3, 1, 'w')
|
||||
// backend.drawRune(4, 1, 'n')
|
||||
// backend.drawRune(6, 1, 'f')
|
||||
// backend.drawRune(7, 1, 'o')
|
||||
// backend.drawRune(8, 1, 'x')
|
||||
|
||||
backend.drawCells(true)
|
||||
|
||||
backend.canvas.XSurfaceSet(backend.window.Id)
|
||||
backend.canvas.XDraw()
|
||||
backend.canvas.XPaint(backend.window.Id)
|
||||
}
|
||||
|
||||
func (backend *Backend) drawCells (forceRedraw bool) (areas []image.Rectangle) {
|
||||
|
@ -33,14 +33,12 @@ func main () {
|
||||
if err != nil { panic(err) }
|
||||
|
||||
redraw()
|
||||
application.Draw()
|
||||
go tick()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <- tickPing:
|
||||
redraw()
|
||||
application.Draw()
|
||||
|
||||
case event := <- channel:
|
||||
switch event.(type) {
|
||||
@ -72,6 +70,8 @@ func redraw () {
|
||||
application.SetRune(5, 1, ':')
|
||||
application.SetRune(6, 1, rune(second / 10 + 48))
|
||||
application.SetRune(7, 1, rune(second % 10 + 48))
|
||||
|
||||
application.Draw()
|
||||
}
|
||||
|
||||
func tick () {
|
||||
|
Loading…
Reference in New Issue
Block a user