termui/canvas.go

44 lines
753 B
Go
Raw Permalink Normal View History

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