termui/canvas.go

44 lines
757 B
Go
Raw Normal View History

2015-03-26 16:11:41 -06:00
package termui
2019-01-23 21:12:10 -07:00
import (
"image"
2019-01-26 06:19:45 -07:00
drawille "github.com/cjbassi/drawille-go"
2019-01-23 21:12:10 -07:00
)
2015-03-26 16:11:41 -06:00
2019-01-23 21:12:10 -07:00
type Canvas struct {
Block
2019-01-26 06:19:45 -07:00
drawille.Canvas
2015-03-26 16:11:41 -06:00
}
2019-01-23 21:12:10 -07:00
func NewCanvas() *Canvas {
return &Canvas{
2019-01-26 06:19:45 -07:00
Block: *NewBlock(),
Canvas: *drawille.NewCanvas(),
2015-03-26 16:11:41 -06:00
}
}
2019-01-26 06:19:45 -07:00
func (self *Canvas) SetPoint(p image.Point, color Color) {
self.Canvas.SetPoint(p, drawille.Color(color))
2015-03-26 16:11:41 -06:00
}
2019-01-26 06:19:45 -07:00
func (self *Canvas) SetLine(p0, p1 image.Point, color Color) {
self.Canvas.SetLine(p0, p1, drawille.Color(color))
}
2019-01-23 21:12:10 -07:00
func (self *Canvas) Draw(buf *Buffer) {
2019-01-26 06:19:45 -07:00
for point, cell := range self.Canvas.GetCells() {
2019-01-23 21:12:10 -07:00
if point.In(self.Rectangle) {
2019-01-26 06:19:45 -07:00
convertedCell := Cell{
cell.Rune,
Style{
Color(cell.Color),
ColorClear,
ModifierClear,
},
}
buf.SetCell(convertedCell, point)
2019-01-23 21:12:10 -07:00
}
2015-03-26 16:11:41 -06:00
}
}