From f24e98906404e10c19116b617ee329b89b82607f Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Thu, 28 Mar 2019 15:26:00 -0400 Subject: Add right click to reveal cards This is a feature I didn't know about until reading the help. --- freecell.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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; } } } -- cgit 1.4.1