git: 9front

Download patch

ref: c1685c7be1d76f31ed1204a2447341b2517e31c2
parent: 8ab4f89068110c14870162fbb233cccb3e094e1d
author: Sigrid <ftrvxmtrx@gmail.com>
date: Sat May 23 16:41:20 EDT 2020

paint: change colors in the palette with button 3

--- a/sys/man/1/paint
+++ b/sys/man/1/paint
@@ -13,6 +13,8 @@
 down buttons 1 or 2 for foreground or background color.  The canvas
 may be moved with button 3.  Colors and brush sizes may be selected by
 clicking on the palette at the bottom of the screen with buttons 1 or 2.
+Clicking button 3 on the palette allows changing a color by entering its
+hex value.
 .PP
 If the optional
 .I file
--- a/sys/src/cmd/paint.c
+++ b/sys/src/cmd/paint.c
@@ -515,6 +515,10 @@
 int
 hitpal(Mouse m)
 {
+	int i;
+	u32int c;
+	char buf[16], *e;
+
 	if(ptinrect(m.xy, penr)){
 		if(m.buttons & 7){
 			brush = ((m.xy.x - penr.min.x) * NBRUSH) / Dx(penr);
@@ -525,7 +529,8 @@
 	if(ptinrect(m.xy, palr)){
 		Image *col;
 
-		col = pal[(m.xy.x - palr.min.x) * nelem(pal) / Dx(palr)];
+		i = (m.xy.x - palr.min.x) * nelem(pal) / Dx(palr);
+		col = pal[i];
 		switch(m.buttons & 7){
 		case 1:
 			ink = col;
@@ -535,6 +540,18 @@
 			back = col;
 			drawpal();
 			update(nil);
+			break;
+		case 4:
+			snprint(buf, sizeof(buf), "%06x", c64[i]);
+			if(eenter("Hex", buf, sizeof(buf), &m) == 6){
+				c = strtoll(buf, &e, 16);
+				if(*e == 0){
+					c64[i] = c;
+					freeimage(pal[i]);
+					pal[i] = allocimage(display, Rect(0, 0, 1, 1), RGB24, 1, c<<8|0xff);
+					drawpal();
+				}
+			}
 			break;
 		}
 		return 1;
--