shithub: riscv

Download patch

ref: 9b8af272991e25aed9be9b1349b6677359739e94
parent: dcf96a006d0d29db2ae1d5f73d8faf14be8ac380
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Apr 28 16:50:10 EDT 2020

facelift for mothra: flat ui is in.

Remove false 3d, add borders for visual separation between
content area and navigation area.

--- a/sys/src/cmd/mothra/libpanel/button.c
+++ b/sys/src/cmd/mothra/libpanel/button.c
@@ -21,16 +21,24 @@
 #define	BUTTON	1
 #define	CHECK	2
 #define	RADIO	3
+#define MENU	4
 void pl_drawbutton(Panel *p){
 	Rectangle r;
 	Button *bp;
 	bp=p->data;
-	r=pl_box(p->b, p->r, p->state);
 	switch(bp->btype){
+	case MENU:
+		r=pl_box(p->b, p->r, p->state);
+		break;
+	case BUTTON:
+		r=pl_box(p->b, p->r, p->state|BORDER);
+		break;
 	case CHECK:
+		r=pl_box(p->b, p->r, p->state|BORDER);
 		r=pl_check(p->b, r, bp->check);
 		break;
 	case RADIO:
+		r=pl_box(p->b, p->r, p->state|BORDER);
 		r=pl_radio(p->b, r, bp->check);
 		break;
 	}
@@ -93,7 +101,7 @@
 	USED(children);		/* shouldn't have any children */
 	bp=p->data;
 	s=pl_iconsize(p->flags, bp->icon);
-	if(bp->btype!=BUTTON){
+	if(bp->btype!=BUTTON && bp->btype!=MENU){
 		ckw=pl_ckwid();
 		if(s.y<ckw){
 			s.x+=ckw;
@@ -121,6 +129,7 @@
 	bp->hit=hit;
 	bp->icon=icon;
 	switch(btype){
+	case MENU:   v->kind="button"; break;
 	case BUTTON: v->kind="button"; break;
 	case CHECK:  v->kind="checkbutton"; break;
 	case RADIO:  v->kind="radiobutton"; break;
@@ -140,6 +149,13 @@
 void plinitradiobutton(Panel *p, int flags, Icon *icon, void (*hit)(Panel *, int, int)){
 	pl_initbtype(p, flags, icon, hit, RADIO);
 }
+Panel *pl_menubutton(Panel *parent, int flags, Icon *icon, void (*hit)(Panel *, int)){
+	Panel *p;
+	p=pl_newpanel(parent, sizeof(Button));
+	((Button *)p->data)->pl_buttonhit=hit;
+	pl_initbtype(p, flags, icon, pl_buttonhit, MENU);
+	return p;
+}
 Panel *plbutton(Panel *parent, int flags, Icon *icon, void (*hit)(Panel *, int)){
 	Panel *p;
 	p=pl_newpanel(parent, sizeof(Button));
@@ -173,7 +189,7 @@
 		v->child=0;
 	}
 	for(i=0;item[i];i++){
-		b=plbutton(v, cflags, item[i], pl_hitmenu);
+		b=pl_menubutton(v, cflags, item[i], pl_hitmenu);
 		((Button *)b->data)->menuhit=hit;
 		((Button *)b->data)->index=i;
 	}
--- a/sys/src/cmd/mothra/libpanel/draw.c
+++ b/sys/src/cmd/mothra/libpanel/draw.c
@@ -6,22 +6,19 @@
 #include "pldefs.h"
 #define	PWID	1	/* width of label border */
 #define	BWID	1	/* width of button relief */
-#define	FWID	2	/* width of frame relief */
-#define	SPACE	1	/* space inside relief of button or frame */
+#define	FWID	1	/* width of frame relief */
+#define	SPACE	2	/* space inside relief of button or frame */
 #define	CKSIZE	3	/* size of check mark */
 #define	CKSPACE	2	/* space around check mark */
 #define	CKWID	1	/* width of frame around check mark */
 #define	CKINSET	1	/* space around check mark frame */
 #define	CKBORDER 2	/* space around X inside frame */
-static int plldepth;
 static Image *pl_white, *pl_light, *pl_dark, *pl_black, *pl_hilit;
 Image *pl_blue;
-int pl_drawinit(int ldepth){
-	plldepth=ldepth;
-	/* mono */
+int pl_drawinit(void){
 	pl_white=allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0xFFFFFFFF);
 	pl_light=allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0xFFFFFFFF);
-	pl_dark=allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x555555FF);
+	pl_dark=allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x777777FF);
 	pl_black=allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x000000FF);
 	pl_hilit=allocimage(display, Rect(0,0,1,1), CHAN1(CAlpha,8), 1, 0x80);
 	pl_blue=allocimage(display, Rect(0,0,1,1), RGB24, 1, 0x0000FFFF);
@@ -28,88 +25,42 @@
 	if(pl_white==0 || pl_light==0 || pl_black==0 || pl_dark==0 || pl_blue==0) sysfatal("allocimage: %r");
 	return 1;
 }
-void pl_relief(Image *b, Image *ul, Image *lr, Rectangle r, int wid){
-	int x, y;
-	draw(b, Rect(r.min.x, r.max.y-wid, r.max.x, r.max.y), lr, 0, ZP); /* bottom */
-	draw(b, Rect(r.max.x-wid, r.min.y, r.max.x, r.max.y), lr, 0, ZP); /* right */
-	draw(b, Rect(r.min.x, r.min.y, r.min.x+wid, r.max.y), ul, 0, ZP); /* left */
-	draw(b, Rect(r.min.x, r.min.y, r.max.x, r.min.y+wid), ul, 0, ZP); /* top */
-	for(x=0;x!=wid;x++) for(y=wid-1-x;y!=wid;y++){
-		draw(b, rectaddpt(Rect(0,0,1,1), Pt(x+r.max.x-wid, y+r.min.y)), lr, 0, ZP);
-		draw(b, rectaddpt(Rect(0,0,1,1), Pt(x+r.min.x, y+r.max.y-wid)), lr, 0, ZP);
-	}
-}
 Rectangle pl_boxoutline(Image *b, Rectangle r, int style, int fill){
-	if(plldepth==0) switch(style){
+	int doborder;
+	
+	doborder = (style & BORDER) != 0;
+	switch(style & ~BORDER){
 	case SUP:
 	case TUP:
-		pl_relief(b, pl_white, pl_white, r, BWID);
+		if(fill) draw(b, r, pl_light, 0, ZP);
+		else border(b, r, BWID+SPACE, pl_white, ZP);
+		if(doborder) border(b, r, BWID, pl_black, ZP);
 		r=insetrect(r, BWID);
-		if(fill) draw(b, r, pl_white, 0, ZP);
-		else border(b, r, SPACE, pl_white, ZP);
 		break;
 	case UP:
-		pl_relief(b, pl_black, pl_black, r, BWID);
-		r=insetrect(r, BWID);
-		if(fill) draw(b, r, pl_white, 0, ZP);
-		else border(b, r, SPACE, pl_white, ZP);
-		break;
-	case DOWN:
-	case DOWN1:
-	case DOWN2:
-	case DOWN3:
-		pl_relief(b, pl_black, pl_black, r, BWID);
-		r=insetrect(r, BWID);
-		if(fill) draw(b, r, pl_black, 0, ZP);
-		border(b, r, SPACE, pl_black, ZP);
-		break;
-	case PASSIVE:
-		if(fill) draw(b, r, pl_white, 0, ZP);
-		r=insetrect(r, PWID);
-		if(!fill) border(b, r, SPACE, pl_white, ZP);
-		break;
-	case FRAME:
-		pl_relief(b, pl_white, pl_black, r, FWID);
-		r=insetrect(r, FWID);
-		pl_relief(b, pl_black, pl_white, r, FWID);
-		r=insetrect(r, FWID);
-		if(fill) draw(b, r, pl_white, 0, ZP);
-		else border(b, r, SPACE, pl_white, ZP);
-		break;
-	}
-	else switch(style){
-	case SUP:
-	case TUP:
-		pl_relief(b, pl_white, pl_white, r, BWID);
-		r=insetrect(r, BWID);
 		if(fill) draw(b, r, pl_light, 0, ZP);
-		else border(b, r, SPACE, pl_white, ZP);
-		break;
-	case UP:
-		pl_relief(b, pl_white, pl_black, r, BWID);
+		else border(b, r, BWID+SPACE, pl_white, ZP);
+		if(doborder) border(b, r, BWID, pl_black, ZP);
 		r=insetrect(r, BWID);
-		if(fill) draw(b, r, pl_light, 0, ZP);
-		else border(b, r, SPACE, pl_white, ZP);
 		break;
 	case DOWN:
 	case DOWN1:
 	case DOWN2:
 	case DOWN3:
-		pl_relief(b, pl_black, pl_white, r, BWID);
-		r=insetrect(r, BWID);
 		if(fill) draw(b, r, pl_dark, 0, ZP);
-		else border(b, r, SPACE, pl_black, ZP);
+		else border(b, r, BWID+SPACE, pl_dark, ZP);
+		if(doborder) border(b, r, BWID, pl_black, ZP);
+		r=insetrect(r, BWID);
 		break;
 	case PASSIVE:
 		if(fill) draw(b, r, pl_light, 0, ZP);
+		else border(b, r, PWID+SPACE, pl_white, ZP);
+		if(doborder) border(b, r, BWID, pl_black, ZP);
 		r=insetrect(r, PWID);
-		if(!fill) border(b, r, SPACE, pl_white, ZP);
 		break;
 	case FRAME:
-		pl_relief(b, pl_white, pl_black, r, FWID);
+		border(b, r, FWID, pl_black, ZP);
 		r=insetrect(r, FWID);
-		pl_relief(b, pl_black, pl_white, r, FWID);
-		r=insetrect(r, FWID);
 		if(fill) draw(b, r, pl_light, 0, ZP);
 		else border(b, r, SPACE, pl_white, ZP);
 		break;
@@ -136,7 +87,7 @@
 	case PASSIVE:
 		return addpt(interior, Pt(2*(PWID+SPACE), 2*(PWID+SPACE)));
 	case FRAME:
-		return addpt(interior, Pt(4*FWID+2*SPACE, 4*FWID+2*SPACE));
+		return addpt(interior, Pt(2*FWID+2*SPACE, 2*FWID+2*SPACE));
 	}
 	return Pt(0, 0);
 }
@@ -155,8 +106,8 @@
 		*size=subpt(*size, Pt(2*(PWID+SPACE), 2*(PWID+SPACE)));
 		break;
 	case FRAME:
-		*ul=addpt(*ul, Pt(2*FWID+SPACE, 2*FWID+SPACE));
-		*size=subpt(*size, Pt(4*FWID+2*SPACE, 4*FWID+2*SPACE));
+		*ul=addpt(*ul, Pt(FWID+SPACE, FWID+SPACE));
+		*size=subpt(*size, Pt(2*FWID+2*SPACE, 2*FWID+2*SPACE));
 	}
 }
 
@@ -194,15 +145,9 @@
 	r.max.x=r.min.x+r.max.y-r.min.y;
 	remainder.min.x=r.max.x;
 	r=insetrect(r, CKINSET);
-	if(plldepth==0)
-		pl_relief(b, pl_black, pl_black, r, CKWID);
-	else
-		pl_relief(b, pl_black, pl_white, r, CKWID);
+	border(b, r, CKWID, pl_white, ZP);
 	r=insetrect(r, CKWID);
-	if(plldepth==0)
-		draw(b, r, pl_white, 0, ZP);
-	else
-		draw(b, r, pl_light, 0, ZP);
+	draw(b, r, pl_light, 0, ZP);
 	if(val) draw(b, insetrect(r, CKSPACE), pl_black, 0, ZP);
 	return remainder;
 }
@@ -212,15 +157,9 @@
 	r.max.x=r.min.x+r.max.y-r.min.y;
 	remainder.min.x=r.max.x;
 	r=insetrect(r, CKINSET);
-	if(plldepth==0)
-		pl_relief(b, pl_black, pl_black, r, CKWID);
-	else
-		pl_relief(b, pl_black, pl_white, r, CKWID);
+	border(b, r, CKWID, pl_white, ZP);
 	r=insetrect(r, CKWID);
-	if(plldepth==0)
-		draw(b, r, pl_white, 0, ZP);
-	else
-		draw(b, r, pl_light, 0, ZP);
+	draw(b, r, pl_light, 0, ZP);
 	r=insetrect(r, CKBORDER);
 	if(val){
 		line(b, Pt(r.min.x,   r.min.y+1), Pt(r.max.x-1, r.max.y  ), Endsquare, Endsquare, 0, pl_black, ZP);
@@ -292,7 +231,7 @@
 	draw(b, r, display->white, 0, ZP);
 }
 void pl_fill(Image *b, Rectangle r){
-	draw(b, r, plldepth==0? pl_white : pl_light, 0, ZP);
+	draw(b, r, pl_light, 0, ZP);
 }
 void pl_cpy(Image *b, Point dst, Rectangle src){
 	draw(b, Rpt(dst, addpt(dst, subpt(src.max, src.min))), b, 0, src.min);
--- a/sys/src/cmd/mothra/libpanel/entry.c
+++ b/sys/src/cmd/mothra/libpanel/entry.c
@@ -49,7 +49,7 @@
 	char *s;
 
 	ep=p->data;
-	r=pl_box(p->b, p->r, p->state);
+	r=pl_box(p->b, p->r, p->state|BORDER);
 	s=ep->entry;
 	if(p->flags & USERFL){
 		char *p;
--- a/sys/src/cmd/mothra/libpanel/group.c
+++ b/sys/src/cmd/mothra/libpanel/group.c
@@ -5,7 +5,7 @@
 #include <panel.h>
 #include "pldefs.h"
 void pl_drawgroup(Panel *p){
-	USED(p);
+	pl_outline(p->b, p->r, FRAME);
 }
 int pl_hitgroup(Panel *p, Mouse *m){
 	USED(p, m);
@@ -14,12 +14,11 @@
 void pl_typegroup(Panel *p, Rune c){
 	USED(p, c);
 }
-Point pl_getsizegroup(Panel *p, Point children){
-	USED(p);
-	return children;
+Point pl_getsizegroup(Panel *, Point children){
+	return pl_boxsize(children, FRAME);
 }
-void pl_childspacegroup(Panel *p, Point *ul, Point *size){
-	USED(p, ul, size);
+void pl_childspacegroup(Panel *, Point *ul, Point *size){
+	pl_interior(FRAME, ul, size);
 }
 void plinitgroup(Panel *v, int flags){
 	v->flags=flags;
--- a/sys/src/cmd/mothra/libpanel/init.c
+++ b/sys/src/cmd/mothra/libpanel/init.c
@@ -7,7 +7,7 @@
 /*
  * Just a wrapper for all the initialization routines
  */
-int plinit(int ldepth){
-	if(!pl_drawinit(ldepth)) return 0;
+int plinit(void){
+	if(!pl_drawinit()) return 0;
 	return 1;
 }
--- a/sys/src/cmd/mothra/libpanel/panel.h
+++ b/sys/src/cmd/mothra/libpanel/panel.h
@@ -109,9 +109,7 @@
 
 Panel *plkbfocus;			/* the panel in keyboard focus */
 
-extern Image *pl_blue;
-
-int plinit(int);			/* initialization */
+int plinit(void);			/* initialization */
 void plpack(Panel *, Rectangle);	/* figure out where to put the Panel & children */
 void plmove(Panel *, Point);		/* move an already-packed panel to a new location */
 void pldraw(Panel *, Image *);		/* display the panel on the bitmap */
--- a/sys/src/cmd/mothra/libpanel/pldefs.h
+++ b/sys/src/cmd/mothra/libpanel/pldefs.h
@@ -25,7 +25,8 @@
 	DOWN3,
 	DOWN,
 	PASSIVE,
-	FRAME
+	FRAME,
+	BORDER = 1<<8,
 };
 /*
  * Scroll flags
@@ -38,6 +39,9 @@
 	SCROLLRIGHT,
 	SCROLLABSX,
 };
+
+extern Image *pl_blue;
+
 /*
  * Scrollbar, slider orientations
  */
@@ -53,7 +57,7 @@
 /*
  * Drawing primitives
  */
-int pl_drawinit(int);
+int pl_drawinit(void);
 Rectangle pl_box(Image *, Rectangle, int);
 Rectangle pl_outline(Image *, Rectangle, int);
 Point pl_boxsize(Point, int);
--- a/sys/src/cmd/mothra/libpanel/rtext.c
+++ b/sys/src/cmd/mothra/libpanel/rtext.c
@@ -216,7 +216,7 @@
 				if(t->flags&PL_HOT)
 					string(b, dr.min, pl_blue, ZP, t->font, t->text);
 				else
-					string(b, dr.min,display->black, ZP, t->font, t->text);
+					string(b, dr.min, display->black, ZP, t->font, t->text);
 				if(t->flags&PL_SEL)
 					pl_highlight(b, dr);
 				if(t->flags&PL_STR){
--- a/sys/src/cmd/mothra/mothra.c
+++ b/sys/src/cmd/mothra/mothra.c
@@ -349,7 +349,7 @@
 	if(pipe(kickpipe) < 0)
 		sysfatal("pipe: %r");
 	estart(Ekick, kickpipe[0], 256);
-	plinit(screen->depth);
+	plinit();
 	if(debug) notify(dienow);
 	getfonts();
 	hrule=allocimage(display, Rect(0, 0, 1, 5), screen->chan, 1, DWhite);