diff options
author | June McEnroe <june@causal.agency> | 2019-03-28 15:26:00 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2019-03-28 15:26:00 -0400 |
commit | f24e98906404e10c19116b617ee329b89b82607f (patch) | |
tree | cd207ccd04a5d055a10ecc475bac938b359ed685 | |
parent | Fix double-click regardless of selection (diff) | |
download | wep-f24e98906404e10c19116b617ee329b89b82607f.tar.gz wep-f24e98906404e10c19116b617ee329b89b82607f.zip |
Add right click to reveal cards
This is a feature I didn't know about until reading the help.
-rw-r--r-- | freecell.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/freecell.c b/freecell.c index d50b641..233a720 100644 --- a/freecell.c +++ b/freecell.c @@ -154,6 +154,7 @@ static const struct Style FanDown = { 1, 0, 0, 0, FanDownDeltaY }; static struct SDL_Rect stackRects[StacksLen]; static struct Layout layout; +static struct List reveal; static void updateLayout(void) { layoutClear(&layout); @@ -193,6 +194,12 @@ static bool mouseButtonDown(SDL_MouseButtonEvent button) { struct SDL_Point point = { button.x, button.y }; struct Item *item = listFind(&layout.main, &point); + if (button.button == SDL_BUTTON_RIGHT) { + if (!item) return false; + listPush(&reveal, &item->rect, item->card); + return true; + } + if (button.clicks % 2 == 0) { Card card = layout.dragItem.card; if (!card) { @@ -223,6 +230,15 @@ 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_Window *window; static SDL_Renderer *render; @@ -339,6 +355,7 @@ int main(void) { renderOutlines(); renderList(textures, &layout.main); renderList(inverted, &layout.drag); + renderList(textures, &reveal); SDL_RenderPresent(render); // TODO: Add more than a frame delay between automatic moves? @@ -353,6 +370,8 @@ int main(void) { if (keyDown(event.key)) break; } else if (event.type == SDL_MOUSEBUTTONDOWN) { if (mouseButtonDown(event.button)) break; + } else if (event.type == SDL_MOUSEBUTTONUP) { + if (mouseButtonUp(event.button)) break; } } } |