diverge
This commit is contained in:
12
ui/mainwindow/console.go
Normal file
12
ui/mainwindow/console.go
Normal file
@ -0,0 +1,12 @@
|
||||
package mainwindow
|
||||
|
||||
//Console is a pair of layers (BG and FG) used to render something
|
||||
// All because of lack of background colors in libbearterminal
|
||||
|
||||
type Console struct {
|
||||
x,y,w,h int
|
||||
FgLayer *Layer
|
||||
BgLayer *Layer
|
||||
}
|
||||
|
||||
func NewConsole
|
@ -2,160 +2,64 @@ 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 {
|
||||
type Layer struct {
|
||||
idx int
|
||||
defaultColor uint32
|
||||
}
|
||||
|
||||
func AddLayer(idx int, colorName string) LayerInterfaceImpl {
|
||||
func AddLayer(idx int, colorName string) Layer {
|
||||
c := blt.ColorFromName(colorName)
|
||||
return LayerInterfaceImpl{idx: idx, defaultColor: c}
|
||||
return Layer{idx: idx, defaultColor: c}
|
||||
}
|
||||
|
||||
func (lii *LayerInterfaceImpl) before() *LayerInterfaceImpl {
|
||||
blt.Layer(lii.idx)
|
||||
return lii
|
||||
func (layer *Layer) before() *Layer {
|
||||
blt.Layer(layer.idx)
|
||||
return layer
|
||||
}
|
||||
|
||||
func (lii *LayerInterfaceImpl) WithColor(colorName string) *LayerInterfaceImpl {
|
||||
lii.before()
|
||||
func (layer *Layer) WithColor(colorName string) *Layer {
|
||||
layer.before()
|
||||
c := blt.ColorFromName(colorName)
|
||||
blt.Color(c)
|
||||
return lii
|
||||
return layer
|
||||
}
|
||||
|
||||
func (lii *LayerInterfaceImpl) after() *LayerInterfaceImpl {
|
||||
blt.Color(lii.defaultColor)
|
||||
func (layer *Layer) after() *Layer {
|
||||
blt.Color(layer.defaultColor)
|
||||
blt.Layer(0)
|
||||
return lii
|
||||
return layer
|
||||
}
|
||||
|
||||
func (lii LayerInterfaceImpl) Put(x,y int, symbol string) {
|
||||
func (layer Layer) 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) {
|
||||
func (layer Layer) 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) {
|
||||
func (layer Layer) DrawWindow (title string, x, y, w, h int) {
|
||||
if len(title) > (w -2) {
|
||||
title = title[:(w-2)]
|
||||
}
|
||||
lii.NewRect(x,y,w,h).DrawBorder()
|
||||
layer.NewRect(x,y,w,h).DrawBorder()
|
||||
centerX := x + (w / 2)
|
||||
lii.Print(centerX - (len(title) / 2) - 1, y, "╡" + title + "╞")
|
||||
layer.Print(centerX - (len(title) / 2) - 1, y, "╡" + title + "╞")
|
||||
};
|
||||
|
||||
func (lii *LayerInterfaceImpl) Decorate (f func (args ...interface{})) func (args ...interface{}) {
|
||||
func (layer *Layer) Decorate (f func (args ...interface{})) func (args ...interface{}) {
|
||||
return func (args ...interface{}) {
|
||||
lii.before()
|
||||
layer.before()
|
||||
f(args)
|
||||
lii.after()
|
||||
layer.after()
|
||||
}
|
||||
}
|
97
ui/mainwindow/primitives.go
Normal file
97
ui/mainwindow/primitives.go
Normal file
@ -0,0 +1,97 @@
|
||||
package mainwindow
|
||||
|
||||
type Rect struct {
|
||||
x,y,w,h int
|
||||
layer *Layer
|
||||
}
|
||||
|
||||
type rectFill struct {
|
||||
top, bottom, left, right, topLeft, topRight, bottomLeft, bottomRight, body string
|
||||
}
|
||||
|
||||
func (layer *Layer) NewRect(x,y,w,h int) *Rect {
|
||||
return &Rect{x,y,w,h, layer}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
};
|
||||
|
Reference in New Issue
Block a user