Working on buffer stuff...
Trying to figure out how/if it fits...
This commit is contained in:
24
buffer.go
24
buffer.go
@@ -27,7 +27,6 @@ import (
|
||||
)
|
||||
|
||||
type Buffer struct {
|
||||
// cells [][]Cell
|
||||
cells map[Coord]Cell
|
||||
maxX, maxY int
|
||||
minX, minY int
|
||||
@@ -46,6 +45,22 @@ func (b *Buffer) Draw(x, y int, screen tcell.Screen) {
|
||||
}
|
||||
}
|
||||
|
||||
// MoveTo moves the minimum x and y of the buffer to x, y
|
||||
// All cell coordinates are updated accordingly
|
||||
func (b *Buffer) MoveTo(x, y int) {
|
||||
diffX := b.minX - x
|
||||
diffY := b.minY - y
|
||||
cells := make(map[Coord]Cell)
|
||||
for k, v := range b.cells {
|
||||
cells[Coord{X: k.X - diffX, Y: k.Y - diffY}] = v
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Buffer) Clear() {
|
||||
b.cells = make(map[Coord]Cell)
|
||||
b.maxX, b.maxY, b.minX, b.minY = 0, 0, 0, 0
|
||||
}
|
||||
|
||||
func (b *Buffer) SetCell(x, y int, c Cell) {
|
||||
b.cells[Coord{X: x, Y: y}] = c
|
||||
b.maxX, b.maxY = h.Max(b.maxX, x), h.Max(b.maxY, y)
|
||||
@@ -60,6 +75,13 @@ func (b *Buffer) SetCells(x, y int, c [][]Cell) {
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Buffer) Merge(atX, atY int, b2 *Buffer) {
|
||||
b2.MoveTo(atX, atY)
|
||||
for k, v := range b2.cells {
|
||||
b.cells[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
// Buffer Helpers
|
||||
func (b *Buffer) FillText(x, y int, txt string, style tcell.Style) {
|
||||
for i := range txt {
|
||||
|
||||
Reference in New Issue
Block a user