9front - general discussion about 9front
 help / color / mirror / Atom feed
* Mothra facelift.
@ 2020-04-26 16:25 ori
  0 siblings, 0 replies; only message in thread
From: ori @ 2020-04-26 16:25 UTC (permalink / raw)
  To: 9front

Inline: /tmp/mothra.png

This change updates mothra's look, bringing it in line with the other
plan 9 programs without any odd menu separators, unnecessary faux 3d,
or similar,and deletes a bunch of code in the process.

I've done a pass, but it seems likely that I've left some dead code
in by accident.

The final appearance should be close to what I've attached, though the
gray is a little bit lighter.

diff -r 248152111380 sys/src/cmd/mothra/libpanel/button.c
--- a/sys/src/cmd/mothra/libpanel/button.c	Sun Apr 26 09:03:42 2020 -0700
+++ b/sys/src/cmd/mothra/libpanel/button.c	Sun Apr 26 09:22:02 2020 -0700
@@ -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;
 	}
diff -r 248152111380 sys/src/cmd/mothra/libpanel/draw.c
--- a/sys/src/cmd/mothra/libpanel/draw.c	Sun Apr 26 09:03:42 2020 -0700
+++ b/sys/src/cmd/mothra/libpanel/draw.c	Sun Apr 26 09:22:02 2020 -0700
@@ -6,107 +6,58 @@
 #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;
-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);
 	if(pl_white==0 || pl_light==0 || pl_black==0 || pl_dark==0) return 0;
 	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);
+		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 DOWN:
 	case DOWN1:
 	case DOWN2:
 	case DOWN3:
-		pl_relief(b, pl_black, pl_black, r, BWID);
+		if(fill) draw(b, r, pl_dark, 0, ZP);
+		else border(b, r, BWID+SPACE, pl_dark, ZP);
+		if(doborder) border(b, r, BWID, pl_black, ZP);
 		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);
-		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);
 		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);
-		r=insetrect(r, FWID);
-		pl_relief(b, pl_black, pl_white, r, FWID);
+		border(b, r, FWID, pl_black, ZP);
 		r=insetrect(r, FWID);
 		if(fill) draw(b, r, pl_light, 0, ZP);
 		else border(b, r, SPACE, pl_white, ZP);
@@ -134,7 +85,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);
 }
@@ -153,8 +104,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));
 	}
 }
 
@@ -192,15 +143,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;
 }
@@ -210,15 +155,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);
@@ -290,7 +229,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);
diff -r 248152111380 sys/src/cmd/mothra/libpanel/entry.c
--- a/sys/src/cmd/mothra/libpanel/entry.c	Sun Apr 26 09:03:42 2020 -0700
+++ b/sys/src/cmd/mothra/libpanel/entry.c	Sun Apr 26 09:22:02 2020 -0700
@@ -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;
diff -r 248152111380 sys/src/cmd/mothra/libpanel/group.c
--- a/sys/src/cmd/mothra/libpanel/group.c	Sun Apr 26 09:03:42 2020 -0700
+++ b/sys/src/cmd/mothra/libpanel/group.c	Sun Apr 26 09:22:02 2020 -0700
@@ -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;
diff -r 248152111380 sys/src/cmd/mothra/libpanel/init.c
--- a/sys/src/cmd/mothra/libpanel/init.c	Sun Apr 26 09:03:42 2020 -0700
+++ b/sys/src/cmd/mothra/libpanel/init.c	Sun Apr 26 09:22:02 2020 -0700
@@ -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;
 }
diff -r 248152111380 sys/src/cmd/mothra/libpanel/panel.h
--- a/sys/src/cmd/mothra/libpanel/panel.h	Sun Apr 26 09:03:42 2020 -0700
+++ b/sys/src/cmd/mothra/libpanel/panel.h	Sun Apr 26 09:22:02 2020 -0700
@@ -109,7 +109,7 @@
 
 Panel *plkbfocus;			/* the panel in keyboard focus */
 
-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 */
diff -r 248152111380 sys/src/cmd/mothra/libpanel/pldefs.h
--- a/sys/src/cmd/mothra/libpanel/pldefs.h	Sun Apr 26 09:03:42 2020 -0700
+++ b/sys/src/cmd/mothra/libpanel/pldefs.h	Sun Apr 26 09:22:02 2020 -0700
@@ -25,7 +25,8 @@
 	DOWN3,
 	DOWN,
 	PASSIVE,
-	FRAME
+	FRAME,
+	BORDER = 1<<8,
 };
 /*
  * Scroll flags
@@ -53,7 +54,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);
diff -r 248152111380 sys/src/cmd/mothra/mothra.c
--- a/sys/src/cmd/mothra/mothra.c	Sun Apr 26 09:03:42 2020 -0700
+++ b/sys/src/cmd/mothra/mothra.c	Sun Apr 26 09:22:02 2020 -0700
@@ -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);



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-04-26 16:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-26 16:25 Mothra facelift ori

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).