ref: a0d12784bd6493e9e05c98a66d65837de82f8bda
parent: bf2a6f786502026ce4229bc84a6a22e5e55a7c13
author: cinap_lenrek <[email protected]>
date: Sun Dec 6 09:50:50 EST 2020
rio: give visual clue during sweep and bandsizing when window is too small We color the window border with a dark red in case the window is too small.
--- a/sys/src/cmd/rio/dat.h
+++ b/sys/src/cmd/rio/dat.h
@@ -325,6 +325,7 @@
Image *paleholdcol;
Image *paletextcol;
Image *sizecol;
+Image *badsizecol;
int reverse; /* there are no pastel paints in the dungeons and dragons world -- rob pike */
Window **window;
--- a/sys/src/cmd/rio/data.c
+++ b/sys/src/cmd/rio/data.c
@@ -196,6 +196,7 @@
paleholdcol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DPalegreyblue);
paletextcol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x666666FF^reverse);
sizecol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DRed);
+ badsizecol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x880000FF);
if(reverse == 0)
holdcol = dholdcol;
--- a/sys/src/cmd/rio/rio.c
+++ b/sys/src/cmd/rio/rio.c
@@ -826,7 +826,7 @@
if(i == nil)
goto Rescue;
oi = i;
- border(i, r, Selborder, sizecol, ZP);
+ border(i, r, Selborder, goodrect(r)?sizecol:badsizecol, ZP);
draw(i, insetrect(r, Selborder), cols[BACK], nil, ZP);
}
}
@@ -858,7 +858,7 @@
}
void
-drawedge(Image **bp, Rectangle r)
+drawedge(Image **bp, Image *col, Rectangle r)
{
Image *b = *bp;
if(b != nil && Dx(b->r) == Dx(r) && Dy(b->r) == Dy(r))
@@ -866,28 +866,30 @@
else{
freeimage(b);
b = allocwindow(wscreen, r, Refbackup, DNofill);
- if(b != nil) draw(b, r, sizecol, nil, ZP);
+ if(b != nil) draw(b, r, col, nil, ZP);
*bp = b;
}
}
void
-drawborder(Rectangle r, int show)
+drawborder(Rectangle r, Image *col)
{
- static Image *b[4];
- int i;
- if(show == 0){
- for(i = 0; i < 4; i++){
- freeimage(b[i]);
- b[i] = nil;
- }
- }else{
+ static Image *b[4], *lastcol;
+
+ if(col != lastcol){
+ freeimage(b[0]), b[0] = nil;
+ freeimage(b[1]), b[1] = nil;
+ freeimage(b[2]), b[2] = nil;
+ freeimage(b[3]), b[3] = nil;
+ }
+ if(col != nil){
r = canonrect(r);
- drawedge(&b[0], Rect(r.min.x, r.min.y, r.min.x+Borderwidth, r.max.y));
- drawedge(&b[1], Rect(r.min.x+Borderwidth, r.min.y, r.max.x-Borderwidth, r.min.y+Borderwidth));
- drawedge(&b[2], Rect(r.max.x-Borderwidth, r.min.y, r.max.x, r.max.y));
- drawedge(&b[3], Rect(r.min.x+Borderwidth, r.max.y-Borderwidth, r.max.x-Borderwidth, r.max.y));
+ drawedge(&b[0], col, Rect(r.min.x, r.min.y, r.min.x+Borderwidth, r.max.y));
+ drawedge(&b[1], col, Rect(r.min.x+Borderwidth, r.min.y, r.max.x-Borderwidth, r.min.y+Borderwidth));
+ drawedge(&b[2], col, Rect(r.max.x-Borderwidth, r.min.y, r.max.x, r.max.y));
+ drawedge(&b[3], col, Rect(r.min.x+Borderwidth, r.max.y-Borderwidth, r.max.x-Borderwidth, r.max.y));
}
+ lastcol = col;
}
Image*
@@ -902,17 +904,17 @@
dm = subpt(om, w->screenr.min);
d = subpt(w->screenr.max, w->screenr.min);
op = subpt(om, dm);
- drawborder(Rect(op.x, op.y, op.x+d.x, op.y+d.y), 1);
+ drawborder(Rect(op.x, op.y, op.x+d.x, op.y+d.y), sizecol);
while(mouse->buttons==4){
p = subpt(mouse->xy, dm);
if(!eqpt(p, op)){
- drawborder(Rect(p.x, p.y, p.x+d.x, p.y+d.y), 1);
+ drawborder(Rect(p.x, p.y, p.x+d.x, p.y+d.y), sizecol);
op = p;
}
readmouse(mousectl);
}
r = Rect(op.x, op.y, op.x+d.x, op.y+d.y);
- drawborder(r, 0);
+ drawborder(r, nil);
p = mouse->xy;
riosetcursor(inborder(r, p) ? corners[whichcorner(r, p)] : nil);
menuing = FALSE;
@@ -936,7 +938,7 @@
or = w->screenr;
but = mouse->buttons;
startp = onscreen(mouse->xy);
- drawborder(or, 1);
+ drawborder(or, sizecol);
while(mouse->buttons == but) {
p = onscreen(mouse->xy);
which = whichcorner(or, p);
@@ -945,13 +947,15 @@
riosetcursor(corners[which]);
}
r = whichrect(or, p, owhich);
- if(!eqrect(r, or) && goodrect(r)){
+ if(!eqrect(r, or)){
+ drawborder(r, goodrect(r)?sizecol:badsizecol);
or = r;
- drawborder(r, 1);
}
readmouse(mousectl);
}
- drawborder(or, 0);
+ drawborder(or, nil);
+ if(!goodrect(or))
+ riosetcursor(nil);
if(mouse->buttons!=0 || !goodrect(or) || eqrect(or, w->screenr)
|| abs(p.x-startp.x)+abs(p.y-startp.y) <= 1){
flushimage(display, 1);