Buffer, DamageBuffer, and Application are io.Writers
This commit is contained in:
parent
18ea5681de
commit
4b129a8391
@ -19,6 +19,7 @@ type Backend struct {
|
|||||||
backgroundStamper *imdraw.IMDraw
|
backgroundStamper *imdraw.IMDraw
|
||||||
fontAtlas *text.Atlas
|
fontAtlas *text.Atlas
|
||||||
textDrawer *text.Text
|
textDrawer *text.Text
|
||||||
|
showBounds bool
|
||||||
|
|
||||||
metrics struct {
|
metrics struct {
|
||||||
cellWidth int
|
cellWidth int
|
||||||
@ -176,15 +177,18 @@ func (backend *Backend) draw () {
|
|||||||
backend.textDrawer.Draw(backend.window, pixel.IM)
|
backend.textDrawer.Draw(backend.window, pixel.IM)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
backend.backgroundStamper.Clear()
|
// draw a rectangle around the buffer if we are showing bounds
|
||||||
backend.backgroundStamper.Color =
|
if backend.showBounds {
|
||||||
backend.config.Color(stone.ColorBackground)
|
backend.backgroundStamper.Clear()
|
||||||
backend.backgroundStamper.Push (
|
backend.backgroundStamper.Color =
|
||||||
backend.vectorAtPosition(0, 0),
|
backend.config.Color(stone.ColorBackground)
|
||||||
backend.vectorAtPosition(width, height))
|
backend.backgroundStamper.Push (
|
||||||
backend.backgroundStamper.Rectangle(1)
|
backend.vectorAtPosition(0, 0),
|
||||||
backend.backgroundStamper.Draw(backend.window)
|
backend.vectorAtPosition(width, height))
|
||||||
|
backend.backgroundStamper.Rectangle(1)
|
||||||
|
backend.backgroundStamper.Draw(backend.window)
|
||||||
|
}
|
||||||
|
|
||||||
backend.window.SwapBuffers()
|
backend.window.SwapBuffers()
|
||||||
}
|
}
|
||||||
|
|||||||
41
buffer.go
41
buffer.go
@ -43,6 +43,10 @@ type Buffer struct {
|
|||||||
content []Cell
|
content []Cell
|
||||||
width int
|
width int
|
||||||
height int
|
height int
|
||||||
|
Dot struct {
|
||||||
|
X int
|
||||||
|
Y int
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (buffer *Buffer) Size () (width, height int) {
|
func (buffer *Buffer) Size () (width, height int) {
|
||||||
@ -74,6 +78,27 @@ func (buffer *Buffer) SetRune (x, y int, content rune) {
|
|||||||
buffer.content[x + y * buffer.width].content = content
|
buffer.content[x + y * buffer.width].content = content
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (buffer *Buffer) Write (bytes []byte) (bytesWritten int, err error) {
|
||||||
|
text := string(bytes)
|
||||||
|
bytesWritten = len(bytes)
|
||||||
|
|
||||||
|
for _, character := range text {
|
||||||
|
buffer.SetRune(buffer.Dot.X, buffer.Dot.Y, character)
|
||||||
|
buffer.Dot.X ++
|
||||||
|
if buffer.Dot.X > buffer.width {
|
||||||
|
buffer.Dot.X = 0
|
||||||
|
buffer.Dot.Y --
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (buffer *Buffer) ResetDot () {
|
||||||
|
buffer.Dot.X = 0
|
||||||
|
buffer.Dot.Y = 0
|
||||||
|
}
|
||||||
|
|
||||||
type DamageBuffer struct {
|
type DamageBuffer struct {
|
||||||
Buffer
|
Buffer
|
||||||
clean []bool
|
clean []bool
|
||||||