shithub: pain

Download patch

ref: fe07e6a3a0099fdd447919004e6b65912de30bd8
parent: 1c2839d17d4dbe1e5aabd448aa565353ba8cd4af
author: jmq <jmq@jmq.sh>
date: Sat Aug 23 16:05:30 EDT 2025

pill: fixed whell overflow

--- a/pill/pill.c
+++ b/pill/pill.c
@@ -3,9 +3,8 @@
 #include <draw.h>
 #include <event.h>
 
-#define INTERNAL_HEIGHT 640
-#define INTERNAL_WIDTH 640
-#define STEPS 3600
+#define INTERNAL_HEIGHT 480
+#define INTERNAL_WIDTH 480
 #define RADIUS .60
 #define MAXSATURATION 1.0
 #define MIN(a, b) ((a) < (b) ? (a) : (b))
@@ -21,7 +20,8 @@
 #define INNERBORDERRADIUS	(COLORPICKERPADDING + COLORPICKERRADIUS)
 #define RECTANGLE(w, h) ((Rectangle){(Point){(0),(0)}, (Point){(w),(h)}})
 #define COLORINDICATORSIZE 0.15
-#define VALUEINCREASE 0.01
+#define VALUEINCREASE 0.05
+#define UPDATEDELAY 100
 
 Image * VirtualWindow = nil;
 Image * HuePicker = nil;
@@ -37,13 +37,12 @@
 u32int * RawCircle = nil;
 uint RawCircleSize = 0;
 Image * Background = nil;
-float SaturationStart = .50;
+float SaturationStart = .0;
 float HueStart = PI*.35;
 float Value = 1.0;
 float Hue = 0.f;
 float Saturation = 1.0;
 int RunApp = 1;
-int UpdateCanvas = 1;
 Point MouseGlobalPosition;
 Point MouseRelativePosition;
 double MouseAngle;
@@ -52,11 +51,19 @@
 double MouseHueRadiusEnd;
 int MouseInHue;
 int MouseInGradient;
-u32int Color;
+u32int Color = DNofill;
 u32int ColorUnderMouse;
+int UpdateCanvas = 1;
 int ShouldDraw = 1;
 int UpdateGradient = 1;
+ulong DrawAt = 0;
 
+ulong
+msec(void)
+{
+	return (ulong)(nsec()/1000000);
+}
+
 int resizeimage(Image * d, Image * s)
 {
 	int i;
@@ -221,7 +228,7 @@
 static void
 setgradienthue(void)
 {
-	float t, i, l, s, u, ct, st;
+	float t, i, l, s, u, ct, st, h;
 	Point c, e;
 	int rc, dx, dy;
 
@@ -245,27 +252,22 @@
 		for (s = 0; s < l; s += 0.1) {
 			e.x = c.x + s * ct;
 			e.y = c.y + s * st;
+			h = HueStart + u;
+			if (h > 2*PI) {
+				h = h - 2*PI;
+			}
 			RawGradient[dx * e.y + e.x] = hsv2rgb(
-				HueStart + u, 
+				h, 
 				(SaturationStart)+(s/l)*(MAXSATURATION - SaturationStart),
 				Value);
 		}
 	}
-	for (t = PI-CIRCLESHIFT; t < (PI - CIRCLESHIFT + CIRCLESLICE); t += i) {
-		ct = cos(t);
-		st = sin(t);
-		for (s = 0; s < l; s += 0.1) {
-			e.x = c.x + s * ct;
-			e.y = c.y + s * st;
-			RawGradient[dx * e.y + e.x] = DWhite;
-		}
-	}
 
 	rc = loadimage(Gradient, Gradient->r, (uchar *)RawGradient, RawGradientSize);
 	if (rc < 0) {
 		sysfatal("loadimage: %r");
 	}
-
+	
 	UpdateGradient = 0;
 }
 
@@ -426,7 +428,6 @@
 initcanvas(void)
 {
 	setbackground(BACKGROUNDCOLOR);
-	ShouldDraw = 1;
 }
 
 void
@@ -457,8 +458,15 @@
 	
 	ColorUnderMouse = pickcolor();
 	if (MouseInGradient && mouse.buttons & 0x01) {
-		Color = ColorUnderMouse;
-		print("%08x\n", Color);
+		if (-MouseAngle < CIRCLESHIFT && 
+			-MouseAngle >= (CIRCLESHIFT - CIRCLESLICE)) {
+			Color = DNofill;
+		} else { 
+			Color = ColorUnderMouse;
+		}
+		print("%08ux\n", Color);
+		ShouldDraw = 1;
+		DrawAt = msec();
 	}
 
 	if (MouseInHue && mouse.buttons & 0x01) {
@@ -466,6 +474,7 @@
 		UpdateGradient = 1;
 		UpdateCanvas = 1;
 		ShouldDraw = 1;
+		DrawAt = msec() + UPDATEDELAY;
 	}
 	
 	v = Value;
@@ -484,11 +493,10 @@
 		}
 		Value = v;
 		UpdateGradient = 1;
-		UpdateCanvas = 1;
 		ShouldDraw = 1;
+		UpdateCanvas = 1;
+		DrawAt = msec() + UPDATEDELAY;
 	}
-
-	updatecolorindicator();
 }
 
 void
@@ -497,6 +505,8 @@
 	if(getwindow(display, Refnone) < 0)
 		sysfatal("getwindow: %r");
 	initcanvas();
+	ShouldDraw = 1;
+	DrawAt = msec();
 }
 
 void
@@ -515,10 +525,15 @@
 
 	einit(Emouse | Ekeyboard);
 	initcanvas();
+	etimer(0, UPDATEDELAY);
+	DrawAt = msec();
 	for (;RunApp;) {
-		setgradienthue();
-		updatecanvas();
-		drawcanvas();
+		if (DrawAt > 0 && DrawAt <= msec() ) {
+			setgradienthue();
+			updatecanvas();
+			drawcanvas();
+			DrawAt = 0;
+		}
 		switch(event(&e)) {
 		case Ekeyboard:
 			if (e.kbdc == 'q') {
@@ -527,6 +542,8 @@
 			break;
 		case Emouse:
 			handlemouse(e.mouse);
+			break;
+		case 0:
 			break;
 		}
 	}
--