summary refs log tree commit diff homepage
diff options
context:
space:
mode:
-rw-r--r--freecell.c35
1 files changed, 32 insertions, 3 deletions
diff --git a/freecell.c b/freecell.c
index 872009a..9185870 100644
--- a/freecell.c
+++ b/freecell.c
@@ -216,7 +216,8 @@ static void curse(void) {
 	initscr();
 	cbreak();
 	noecho();
-	keypad(stdscr, false);
+	keypad(stdscr, true);
+	mousemask(BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED, NULL);
 	struct termios term;
 	tcgetattr(STDOUT_FILENO, &term);
 	term.c_iflag &= ~IXON;
@@ -266,10 +267,13 @@ enum {
 	CardHeight = 1,
 	CellX = Padding,
 	CellY = 2*CardHeight,
-	FoundationX = CellX + 4*(CardWidth+Padding),
+	CellWidth = 4*(CardWidth+Padding),
+	FoundationX = CellX + CellWidth,
 	FoundationY = CellY,
+	FoundationWidth = 4*(CardWidth+Padding),
 	TableauX = CellX,
 	TableauY = CellY + 2*CardHeight,
+	TableauWidth = 8*(CardWidth+Padding),
 };
 
 static uint game;
@@ -319,8 +323,32 @@ static void draw(void) {
 
 static bool quit;
 static void input(void) {
-	char ch = getch();
+	MEVENT m;
+	int ch = getch();
 	uint stack = Stacks;
+
+	if (ch == KEY_MOUSE && getmouse(&m) == OK) {
+		if (m.y == CellY && m.x >= CellX && m.x < CellX+CellWidth) {
+			stack = Cell + (m.x-CellX) / (CardWidth+Padding);
+		} else if (
+			m.y == FoundationY &&
+			m.x >= FoundationX && m.x < FoundationX+FoundationWidth
+		) {
+			stack = Foundation+3 - (m.x-FoundationX) / (CardWidth+Padding);
+		} else if (
+			m.y >= TableauY && m.x >= TableauX && m.x < TableauX+TableauWidth
+		) {
+			stack = Tableau + (m.x-TableauX) / (CardWidth+Padding);
+		} else {
+			srcStack = Stacks;
+		}
+		if (m.bstate == BUTTON1_DOUBLE_CLICKED) {
+			srcStack = stack;
+		} else if (stack == srcStack) {
+			srcStack = stack = Stacks;
+		}
+	}
+
 	switch (tolower(ch)) {
 		break; case 'Q'^'@': quit = true;
 		break; case '\33': srcStack = Stacks;
@@ -384,5 +412,6 @@ uint playFreeCell(void) {
 		draw();
 		input();
 	}
+	mousemask(0, NULL);
 	return win();
 }
Enroe If background-color is only set on body then overscroll in Safari reveals white. 2019-07-12Make author consistent and update URLsJune McEnroe 2019-07-12Move to www/text.causal.agencyJune McEnroe 2019-07-12Add new causal.agency with shotty shotsJune McEnroe 2019-07-12Use -s to infer terminal sizeJune McEnroe 2019-07-12Add DCH to shottyJune McEnroe This makes htop mostly work. Scrolling region still missing. 2019-07-12Support insert mode in shottyJune McEnroe This is how curses puts characters into the bottom-right cell of the terminal. 2019-07-11Don't do carriage return on line feedJune McEnroe 2019-07-11Interpret 256color-style SGRsJune McEnroe 2019-07-11Use inline style rather than <b>, <i>, <u>June McEnroe 2019-07-11Factor out clearJune McEnroe 2019-07-11Add bright option to shottyJune McEnroe 2019-07-11Output <b>, <i>, <u> in shottyJune McEnroe 2019-07-10Ignore SM and RMJune McEnroe 2019-07-09Add shotty man page and build itJune McEnroe 2019-07-09Add up -cJune McEnroe 2019-07-09Add options for default colors to shottyJune McEnroe 2019-07-08Use char literals consistentlyJune McEnroe