2017-01-14 06:07:43 +00:00
|
|
|
// Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
|
2015-03-20 20:21:50 +00:00
|
|
|
// Use of this source code is governed by a MIT license that can
|
|
|
|
// be found in the LICENSE file.
|
|
|
|
|
2015-02-03 14:07:31 +00:00
|
|
|
package termui
|
|
|
|
|
2015-09-18 15:41:44 +00:00
|
|
|
import (
|
2015-12-06 17:51:37 +00:00
|
|
|
"image"
|
2019-03-07 10:00:36 +00:00
|
|
|
"sync"
|
2015-09-18 15:41:44 +00:00
|
|
|
|
2018-09-06 21:48:09 +00:00
|
|
|
tb "github.com/nsf/termbox-go"
|
2015-09-18 15:41:44 +00:00
|
|
|
)
|
2015-02-03 14:07:31 +00:00
|
|
|
|
2019-01-24 04:12:10 +00:00
|
|
|
type Drawable interface {
|
|
|
|
GetRect() image.Rectangle
|
|
|
|
SetRect(int, int, int, int)
|
|
|
|
Draw(*Buffer)
|
2019-03-07 10:00:36 +00:00
|
|
|
sync.Locker
|
2019-01-24 04:12:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func Render(items ...Drawable) {
|
|
|
|
for _, item := range items {
|
|
|
|
buf := NewBuffer(item.GetRect())
|
2019-03-07 10:00:36 +00:00
|
|
|
item.Lock()
|
2019-01-24 04:12:10 +00:00
|
|
|
item.Draw(buf)
|
2019-03-07 10:00:36 +00:00
|
|
|
item.Unlock()
|
2019-01-24 04:12:10 +00: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 13:56:10 +00:00
|
|
|
}
|
2015-02-04 01:56:49 +00:00
|
|
|
}
|
2015-12-06 17:51:37 +00:00
|
|
|
}
|
2018-09-06 21:48:09 +00:00
|
|
|
tb.Flush()
|
2015-02-03 14:07:31 +00:00
|
|
|
}
|