shithub: orca

Download patch

ref: f124962fa0072163bfdef1149a17cad16da13506
parent: 4d42f22a75150a8a548df75bb1cdb6b2466422ff
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Mon Feb 17 10:36:01 EST 2020

plan9: add mouse region selection

--- a/plan9.c
+++ b/plan9.c
@@ -799,6 +799,16 @@
 	sel.max.y = MAX(0, MIN((int)field.height-1, sel.max.y));
 }
 
+static Point
+ptmouse(Point p)
+{
+	p = subpt(subpt(p, screen->r.min), Pt(Txtoff, Txtoff));
+	p.x /= glyphsz.x;
+	p.y /= glyphsz.y;
+
+	return ptclamp(p);
+}
+
 static void
 usage(void)
 {
@@ -816,7 +826,7 @@
 	char tmp[256];
 	int oldw, oldh, w, h, n;
 	long seed;
-	bool inverse;
+	bool inverse, mselecting;
 	int movex, movey;
 	bool shiftdown, complete, ctldown;
 	Alt a[Numchan+1] = {
@@ -927,6 +937,7 @@
 	shiftdown = false;
 	altdown = false;
 	complete = true;
+	mselecting = false;
 	movex = 1;
 	movey = 1;
 
@@ -942,7 +953,26 @@
 			goto end;
 
 		case Cmouse:
-			if (m.buttons == 4) {
+			if (m.buttons == 1) {
+				if (!mselecting) {
+					mselecting = true;
+					cur = ptmouse(m.xy);
+					sel.min = cur;
+					sel.max = cur;
+				} else {
+					sel.max = ptmouse(m.xy);
+					sel.min = sel.max;
+					if (sel.max.x < cur.x)
+						sel.max.x = cur.x;
+					else
+						sel.min.x = cur.x;
+					if (sel.max.y < cur.y)
+						sel.max.y = cur.y;
+					else
+						sel.min.y = cur.y;
+				}
+			} else if (m.buttons == 4) {
+				mselecting = false;
 				menu3i[Menu3dotstyle] = tmp;
 				menu3i[Menu3rulerstyle] = 1 + menu3i[Menu3dotstyle] + sprintf(tmp, "%s dots", style[(dotstyle+1) % Numstyles]);
 				sprintf(menu3i[Menu3rulerstyle], "%s rulers", style[(rulerstyle+1) % Numstyles]);
@@ -966,6 +996,8 @@
 					goto end;
 				}
 				complete = true;
+			} else if (mselecting) {
+				mselecting = false;
 			} else {
 				goto noredraw;
 			}