2017-01-14 14:07:43 +08:00
|
|
|
// Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
|
2015-03-21 04:21:50 +08:00
|
|
|
// Use of this source code is governed by a MIT license that can
|
|
|
|
// be found in the LICENSE file.
|
|
|
|
|
2015-02-03 22:07:31 +08:00
|
|
|
package termui
|
|
|
|
|
2015-09-18 23:41:44 +08:00
|
|
|
import (
|
2015-12-07 01:51:37 +08:00
|
|
|
"image"
|
2019-03-07 18:00:36 +08:00
|
|
|
"sync"
|
2015-09-18 23:41:44 +08:00
|
|
|
|
2018-09-07 05:48:09 +08:00
|
|
|
tb "github.com/nsf/termbox-go"
|
2015-09-18 23:41:44 +08:00
|
|
|
)
|
2015-02-03 22:07:31 +08:00
|
|
|
|
2019-01-24 12:12:10 +08:00
|
|
|
type Drawable interface {
|
|
|
|
GetRect() image.Rectangle
|
|
|
|
SetRect(int, int, int, int)
|
|
|
|
Draw(*Buffer)
|
2019-03-07 18:00:36 +08:00
|
|
|
sync.Locker
|
2019-01-24 12:12:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func Render(items ...Drawable) {
|
|
|
|
for _, item := range items {
|
|
|
|
buf := NewBuffer(item.GetRect())
|
2019-03-07 18:00:36 +08:00
|
|
|
item.Lock()
|
2019-01-24 12:12:10 +08:00
|
|
|
item.Draw(buf)
|
2019-03-07 18:00:36 +08:00
|
|
|
item.Unlock()
|
2019-01-24 12:12:10 +08:00
|
|
|
for point, cell := range buf.CellMap {
|
|
|
|
if point.In(buf.Rectangle) {
|
|
|
|
tb.SetCell(
|
|
|
|
point.X, point.Y,
|
|
|
|
cell.Rune,
|
|
|
|
tb.Attribute(cell.Style.Fg+1)|tb.Attribute(cell.Style.Modifier), tb.Attribute(cell.Style.Bg+1),
|
|
|
|
)
|
2015-04-21 21:56:10 +08:00
|
|
|
}
|
2015-02-04 09:56:49 +08:00
|
|
|
}
|
2015-12-07 01:51:37 +08:00
|
|
|
}
|
2018-09-07 05:48:09 +08:00
|
|
|
tb.Flush()
|
2015-02-03 22:07:31 +08:00
|
|
|
}
|