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);

};