161 lines
3.2 KiB
Go
161 lines
3.2 KiB
Go
package mainwindow
|
|
|
|
import blt "lab.zaar.be/thefish/bearlibterminal"
|
|
|
|
var emptyCorners = [4]uint32{0,0,0,0}
|
|
|
|
type LayerInterface interface {
|
|
Render()
|
|
Put(x, y int, symbol rune, color string)
|
|
}
|
|
|
|
type LayerInterfaceImpl struct {
|
|
idx int
|
|
defaultColor uint32
|
|
}
|
|
|
|
func AddLayer(idx int, colorName string) LayerInterfaceImpl {
|
|
c := blt.ColorFromName(colorName)
|
|
return LayerInterfaceImpl{idx: idx, defaultColor: c}
|
|
}
|
|
|
|
func (lii *LayerInterfaceImpl) before() *LayerInterfaceImpl {
|
|
blt.Layer(lii.idx)
|
|
return lii
|
|
}
|
|
|
|
func (lii *LayerInterfaceImpl) WithColor(colorName string) *LayerInterfaceImpl {
|
|
lii.before()
|
|
c := blt.ColorFromName(colorName)
|
|
blt.Color(c)
|
|
return lii
|
|
}
|
|
|
|
func (lii *LayerInterfaceImpl) after() *LayerInterfaceImpl {
|
|
blt.Color(lii.defaultColor)
|
|
blt.Layer(0)
|
|
return lii
|
|
}
|
|
|
|
func (lii LayerInterfaceImpl) Put(x,y int, symbol string) {
|
|
rnes := []rune(symbol)
|
|
if (len(rnes)) > 0 {
|
|
blt.Put(x, y, int(rnes[0]))
|
|
}
|
|
}
|
|
|
|
func (lii LayerInterfaceImpl) Print(x,y int, txt string) (w,h int) {
|
|
return blt.Print(x,y, txt)
|
|
}
|
|
|
|
|
|
type Rect struct {
|
|
x,y,w,h int
|
|
layer *LayerInterfaceImpl
|
|
}
|
|
|
|
type rectFill struct {
|
|
top, bottom, left, right, topLeft, topRight, bottomLeft, bottomRight, body string
|
|
}
|
|
|
|
func (lii *LayerInterfaceImpl) NewRect(x,y,w,h int) *Rect {
|
|
return &Rect{x,y,w,h, lii}
|
|
}
|
|
|
|
var noborder = rectFill{
|
|
top: "▄",
|
|
bottom: "▀",
|
|
left: "▐",
|
|
right: "▌",
|
|
topLeft: "▗",
|
|
topRight: "▖",
|
|
bottomLeft: "▝",
|
|
bottomRight: "▘",
|
|
body: "█",
|
|
}
|
|
|
|
var splash = rectFill{
|
|
top: "█",
|
|
bottom: "█",
|
|
left: "█",
|
|
right: "█",
|
|
topLeft: "█",
|
|
topRight: "█",
|
|
bottomLeft: "█",
|
|
bottomRight: "█",
|
|
body: "█",
|
|
}
|
|
|
|
var doubleBorder = rectFill {
|
|
top: "═",
|
|
bottom: "═",
|
|
left: "║",
|
|
right: "║",
|
|
topLeft: "╔",
|
|
topRight: "╗",
|
|
bottomLeft: "╚",
|
|
bottomRight: "╝",
|
|
}
|
|
|
|
func (r *Rect) Fill() {
|
|
r.render(noborder)
|
|
}
|
|
|
|
func (r *Rect) Splash() {
|
|
r.render(splash)
|
|
}
|
|
|
|
func (r *Rect) DrawBorder() {
|
|
r.render(doubleBorder)
|
|
}
|
|
|
|
func (r *Rect) render (fillage rectFill) {
|
|
|
|
if fillage.body != "" {
|
|
for i := r.x + 1; i < r.x+r.w; i++ {
|
|
for j := r.y + 1; j < r.y+r.h; j++ {
|
|
r.layer.Put(i, j, fillage.body);
|
|
//lii.Put(i, j, "X");
|
|
}
|
|
}
|
|
}
|
|
|
|
for i := r.x + 1; i < r.x+r.w; i++ {
|
|
r.layer.Put(i, r.y, fillage.top);
|
|
//lii.Put(i, y-1, "Q");
|
|
r.layer.Put(i, r.y+r.h, fillage.bottom);
|
|
//lii.Put(i, y+h, "H");
|
|
}
|
|
|
|
for j := r.y + 1; j < r.y+r.h; j++ {
|
|
r.layer.Put(r.x, j, fillage.left);
|
|
//lii.Put(x-1, j, "U");
|
|
r.layer.Put(r.x+r.w, j, fillage.right);
|
|
//lii.Put(x+w, j, "M");
|
|
}
|
|
|
|
r.layer.Put(r.x, r.y, fillage.topLeft);
|
|
//lii.Put(x-1, y-1, "T");
|
|
r.layer.Put(r.x, r.y+r.h, fillage.bottomLeft);
|
|
//lii.Put(x-1, y+h, "q");
|
|
r.layer.Put(r.x+r.w, r.y, fillage.topRight);
|
|
//lii.Put(x+w, y-1, "L");
|
|
r.layer.Put(r.x+r.w, r.y+r.h, fillage.bottomRight);
|
|
};
|
|
|
|
func (lii LayerInterfaceImpl) DrawWindow (title string, x, y, w, h int) {
|
|
if len(title) > (w -2) {
|
|
title = title[:(w-2)]
|
|
}
|
|
lii.NewRect(x,y,w,h).DrawBorder()
|
|
centerX := x + (w / 2)
|
|
lii.Print(centerX - (len(title) / 2) - 1, y, "╡" + title + "╞")
|
|
};
|
|
|
|
func (lii *LayerInterfaceImpl) Decorate (f func (args ...interface{})) func (args ...interface{}) {
|
|
return func (args ...interface{}) {
|
|
lii.before()
|
|
f(args)
|
|
lii.after()
|
|
}
|
|
} |