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