summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-04-02 23:16:17 -0400
committerJune McEnroe <june@causal.agency>2019-04-02 23:16:17 -0400
commit392dd8cc20b04f4d3aed4219120d597cec00d8fc (patch)
treedd0ff66810917f63a9eacd7e7ba71dba1dfd2a92
parentAdd idSkip (diff)
downloadwep-392dd8cc20b04f4d3aed4219120d597cec00d8fc.tar.gz
wep-392dd8cc20b04f4d3aed4219120d597cec00d8fc.zip
Select and move cards on mouse up
-rw-r--r--freecell.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/freecell.c b/freecell.c
index 2855219..bea3662 100644
--- a/freecell.c
+++ b/freecell.c
@@ -266,15 +266,24 @@ static bool keyUp(SDL_KeyboardEvent key) {
 }
 
 static bool mouseButtonDown(SDL_MouseButtonEvent button) {
+	if (button.button != SDL_BUTTON_RIGHT) return false;
 	struct SDL_Point point = { button.x, button.y };
 	struct Item *item = listFind(&layout.main, &point);
+	if (!item) return false;
+	listPush(&reveal, &item->rect, item->card);
+	return true;
+}
 
+static bool mouseButtonUp(SDL_MouseButtonEvent button) {
 	if (button.button == SDL_BUTTON_RIGHT) {
-		if (!item) return false;
-		listPush(&reveal, &item->rect, item->card);
+		if (!reveal.len) return false;
+		reveal.len = 0;
 		return true;
 	}
 
+	struct SDL_Point point = { button.x, button.y };
+	struct Item *item = listFind(&layout.main, &point);
+
 	if (button.clicks % 2 == 0) {
 		Card card = layout.dragItem.card;
 		if (!card) {
@@ -304,15 +313,6 @@ static bool mouseButtonDown(SDL_MouseButtonEvent button) {
 	return true;
 }
 
-static bool mouseButtonUp(SDL_MouseButtonEvent button) {
-	if (button.button == SDL_BUTTON_RIGHT) {
-		if (!reveal.len) return false;
-		reveal.len = 0;
-		return true;
-	}
-	return false;
-}
-
 static SDL_Renderer *render;
 
 static void renderOutline(SDL_Rect rect, bool out) {