diff options
-rw-r--r-- | freecell.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/freecell.c b/freecell.c index 487ef79..d50b641 100644 --- a/freecell.c +++ b/freecell.c @@ -191,16 +191,22 @@ static bool keyDown(SDL_KeyboardEvent key) { static bool mouseButtonDown(SDL_MouseButtonEvent button) { struct SDL_Point point = { button.x, button.y }; + struct Item *item = listFind(&layout.main, &point); - if (layout.dragItem.card) { - if (button.clicks % 2 == 0) { - for (uint dest = Cell1; dest <= Cell4; ++dest) { - if (gameMove(dest, layout.dragItem.card)) { - layout.dragItem.card = 0; - return true; - } - } + if (button.clicks % 2 == 0) { + Card card = layout.dragItem.card; + if (!card) { + if (!item) return false; + card = item->card; } + for (uint dest = Cell1; dest <= Cell4; ++dest) { + if (gameMove(dest, card)) break; + } + layout.dragItem.card = 0; + return true; + } + + if (layout.dragItem.card) { for (uint dest = 0; dest < StacksLen; ++dest) { if (SDL_PointInRect(&point, &stackRects[dest])) { if (gameMove(dest, layout.dragItem.card)) break; @@ -211,7 +217,6 @@ static bool mouseButtonDown(SDL_MouseButtonEvent button) { } // TODO: Right click to reveal? - struct Item *item = listFind(&layout.main, &point); if (!item) return false; if (!gameAvail(item->card)) return false; layout.dragItem = *item; |