forked from gizak/termui
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathcanvas.go
More file actions
48 lines (42 loc) · 1013 Bytes
/
canvas.go
File metadata and controls
48 lines (42 loc) · 1013 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package gotui
import (
"image"
"github.com/metaspartan/gotui/v5/drawille"
)
// NewCanvas returns a new Canvas.
func NewCanvas() *Canvas {
return &Canvas{
Block: *NewBlock(),
Canvas: *drawille.NewCanvas(),
}
}
// SetPoint sets the color of the point at the given coordinates.
func (c *Canvas) SetPoint(p image.Point, color Color) {
c.Canvas.SetPoint(p, drawille.Color(color))
}
// SetLine draws a line from p0 to p1 with the given color.
func (c *Canvas) SetLine(p0, p1 image.Point, color Color) {
c.Canvas.SetLine(p0, p1, drawille.Color(color))
}
// Draw draws the canvas to the buffer.
func (c *Canvas) Draw(buf *Buffer) {
c.Block.Draw(buf)
for point, cell := range c.Canvas.GetCells() {
dest := point.Add(c.Inner.Min)
if dest.In(c.Inner) {
col := Color(cell.Color)
if col == 0 || col == ColorClear {
col = ColorWhite
}
convertedCell := Cell{
cell.Rune,
Style{
col,
ColorClear,
ModifierClear,
},
}
buf.SetCell(convertedCell, dest)
}
}
}