shithub: picker

Download patch

ref: f213193d7f4df8554d455dc6d9c38dba0352b099
parent: 2a853dc838b882d3eb0dc3f5bcb7cfad32baf416
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Sat Mar 14 18:08:13 EDT 2020

background for transparency

--- a/picker.c
+++ b/picker.c
@@ -7,8 +7,8 @@
 #include <keyboard.h>
 #include "hsluv.h"
 
-#define MAX(a,b) ((a)>(b)?(a):(b))
-#define MIN(a,b) ((a)<(b)?(a):(b))
+#define MAX(a,b) ((a)>=(b)?(a):(b))
+#define MIN(a,b) ((a)<=(b)?(a):(b))
 #define D2C(x) (int)MAX(0, MIN(0xff, x*256.0))
 
 enum
@@ -109,6 +109,7 @@
 static int ncolors, curcolor, nchan;
 static Rectangle srects[3];
 static Mode *mode;
+static Image *bg;
 
 static Image *
 slider(int si, int w)
@@ -183,6 +184,7 @@
 	for (i = 0; i < nchan; i++) {
 		srects[i] = r;
 		im = slider(i, Dx(r));
+		draw(screen, r, bg, nil, ZP);
 		draw(screen, r, im, nil, ZP);
 		r.min.y += Sliderheight + Offset;
 		r.max.y += Sliderheight + Offset;
@@ -204,6 +206,7 @@
 		}
 
 		cr.max.x = cr.min.x + colw;
+		draw(screen, cr, bg, nil, ZP);
 		draw(screen, cr, colors[i].i, nil, ZP);
 		colors[i].r = insetrect(cr, -3);
 		if (i == curcolor)
@@ -214,6 +217,7 @@
 
 	/* current color */
 	r.max.y = screen->r.max.y - Offset;
+	draw(screen, r, bg, nil, ZP);
 	draw(screen, r, colors[curcolor].i, nil, ZP);
 
 	/* current color in hex */
@@ -234,14 +238,38 @@
 {
 	int i;
 
-	print("usage: %s [-a] [-", argv0);
+	print("usage: %s [-", argv0);
 	for (i = 0; i < nelem(modes); i++)
 		print("%c", modes[i].opt);
-	print("] rrggbbaa ...\n");
+	print("] [-a] rrggbb[aa] ...\n");
 
 	threadexitsall("usage");
 }
 
+static void
+loadbg(void)
+{
+	Rectangle r;
+	u8int *d;
+	int i, j;
+
+	r = Rect(0, 0, Sliderheight, Sliderheight);
+	d = calloc(1, Sliderheight*Sliderheight);
+	for (i = 0; i < Sliderheight/2; i++) {
+		for (j = 0; j < Sliderheight/2; j++)
+			d[j*Sliderheight+i] = 0xff;
+	}
+	for (; i < Sliderheight; i++) {
+		for (j = Sliderheight/2; j < Sliderheight; j++)
+			d[j*Sliderheight+i] = 0xff;
+	}
+	if ((bg = allocimage(display, r, GREY8, 1, DNofill)) == nil)
+		sysfatal("allocimage: %r");
+	if (loadimage(bg, r, d, Sliderheight*Sliderheight) < 0)
+		sysfatal("loadimage: %r");
+	free(d);
+}
+
 void
 threadmain(int argc, char **argv)
 {
@@ -320,6 +348,9 @@
 	a[Cresize].c = mctl->resizec;
 	display->locking = 1;
 	unlockdisplay(display);
+
+	if (nchan > 3)
+		loadbg();
 
 	redraw();