shithub: lola

ref: c57b0fc5c3450b175f0896e0238ea3431fde6448
dir: /simple.c/

View raw version
#include "inc.h"

int bordersz = 4;
int titlesz = 17;//19;

enum {
	TITLE,
	LTITLE,
	TITLEHOLD,
	LTITLEHOLD,
	TITLETEXT,
	LTITLETEXT,
	TITLEHOLDTEXT,
	LTITLEHOLDTEXT,
	FRAME,
	LFRAME,

	NumWinColors
};

Image *wincolors[NumWinColors];
Image *icons[4];

void
btn(Image *img, Rectangle r, Image *col, Image *icon, int down)
{
	USED(down);

//	border(img, r, 1, col, ZP);
	r = centerrect(r, icon->r);
	draw(img, r, col, icon, ZP);
}

int
btnctl(Image *img, Rectangle r, Image *col, Image *icon)
{
	int over, prevover;

	prevover = 1;
	btn(img, r, col, icon, 1);
	while(mctl->buttons){
		readmouse(mctl);
		over = ptinrect(mctl->xy, r);
		if(over != prevover)
			btn(img, r, col, icon, over);
		prevover = over;
	}
	if(prevover)
		btn(img, r, col, icon, 0);
	return ptinrect(mctl->xy, r);
}


void
wdecor(Window *w)
{
	if(w->frame == nil)
		return;
	int c = w->holdmode ?
		w == focused ? TITLEHOLD : LTITLEHOLD :
		w == focused ? TITLE : LTITLE;
	int c2 = w == focused ? FRAME : LFRAME;

	Rectangle r, b1, b2, b3;

	if(!w->noborder){
		r = w->frame->r;
		border(w->frame, r, bordersz, wincolors[c], ZP);
		border(w->frame, r, 1, wincolors[c2], ZP);
		border(w->frame, insetrect(w->contrect,-1), 1, wincolors[c2], ZP);
	}

	if(!w->notitle){
		r = w->titlerect;
		r.max.y--;
		draw(w->frame, r, wincolors[c], nil, ZP);

		b1 = r;
b1.max.x -= bordersz/2;
		b1.min.x = b1.max.x - titlesz + bordersz;
		b1.max.y = b1.min.y + Dx(b1);
		b2 = rectsubpt(b1, Pt(titlesz, 0));
		b3 = rectsubpt(b2, Pt(titlesz, 0));
		btn(w->frame, b1, wincolors[c+4], icons[3], 0);
		btn(w->frame, b2, wincolors[c+4], icons[1+w->maximized], 0);
		btn(w->frame, b3, wincolors[c+4], icons[0], 0);

r.min.x += bordersz/2;
r.min.y -= 2;
		Point pt = Pt(r.min.x, r.min.y);
		string(w->frame, pt, wincolors[c+4], pt, font, w->label);
	}
}

void
wtitlectl(Window *w)
{
	if(mctl->buttons & 7){
		wraise(w);
		wfocus(w);
		if(mctl->buttons & 1) {
			int c = w->holdmode ?
				w == focused ? TITLEHOLD : LTITLEHOLD :
				w == focused ? TITLE : LTITLE;

			Rectangle r = w->titlerect;
			Rectangle br = Rect(0,0,titlesz-bordersz,titlesz-bordersz);
r.max.x -= bordersz/2;
			Rectangle br1 = rectaddpt(br, Pt(r.max.x-titlesz+bordersz, r.min.y));
			Rectangle br2 = rectsubpt(br1, Pt(titlesz, 0));
			Rectangle br3 = rectsubpt(br2, Pt(titlesz, 0));
			// hack...
			if(w->notitle)
				br1 = br2 = br3 = Rect(0,0,0,0);

			if(ptinrect(mctl->xy, br1)){
				if(btnctl(w->frame, br1, wincolors[c+4], icons[3]))
					wdelete(w);
			}else if(ptinrect(mctl->xy, br2)){
				if(btnctl(w->frame, br2, wincolors[c+4], icons[1+w->maximized])){
					if(w->maximized)
						wrestore(w);
					else
						wmaximize(w);
				}
			}else if(ptinrect(mctl->xy, br3)){
				if(btnctl(w->frame, br3, wincolors[c+4], icons[0]))
					whide(w);
			}else if(!w->maximized)
				grab(w, 1);
		}
		if(mctl->buttons & 4)
			btn3menu();
	}
}


static char minbtn[] = {
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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 0, 0,
	0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0,
	0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0,
	0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};

void
inittheme(void)
{
	freeimage(colors[HOLDTEXT]);
	freeimage(colors[PALEHOLDTEXT]);
	colors[HOLDTEXT] = getcolor("holdtext", 0x990000FF);
	colors[PALEHOLDTEXT] = getcolor("paleholdtext", 0xBB5D00FF);

//	wincolors[TITLE] = getcolor("title", 0x607DA1FF);
//	wincolors[LTITLE] = getcolor("ltitle", 0xA1A1A1FF);

//	wincolors[TITLE] = getcolor("title", 0x2F78EDFF);
//	wincolors[LTITLE] = getcolor("ltitle", 0x7C9DE3FF);

	wincolors[TITLE] = getcolor("title", 0x5297F9FF);
	wincolors[LTITLE] = getcolor("ltitle", 0x2C60B2FF);
	wincolors[TITLEHOLD] = getcolor("titlehold", 0xED2F2FFF);
	wincolors[LTITLEHOLD] = getcolor("ltitlehold", 0xE36A6AFF);

	wincolors[FRAME] = getcolor("frame", 0x000000FF);
	wincolors[LFRAME] = getcolor("lframe", 0x000000FF);

	wincolors[TITLETEXT] = getcolor("titletext", 0xFFFFFFFF);
	wincolors[LTITLETEXT] = getcolor("ltitletext", 0xFFFFFFFF);
	wincolors[TITLEHOLDTEXT] = getcolor("titleholdtext", 0xFFFFFFFF);
	wincolors[LTITLEHOLDTEXT] = getcolor("ltitleholdtext", 0xFFFFFFFF);

	icons[0] = mkicon(minbtn, 16, 13);
	icons[1] = mkicon(maxbtn, 16, 13);
	icons[2] = mkicon(rstbtn, 16, 13);
	icons[3] = mkicon(closebtn, 16, 13);
}