From e37a6a4f8d9b204c5d2eca0d04f387ec9661fffc Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Thu, 28 Mar 2019 15:45:36 -0400 Subject: Add keys to reveal ranks This isn't a feature in the original but I want it. --- freecell.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/freecell.c b/freecell.c index 233a720..f7a19cb 100644 --- a/freecell.c +++ b/freecell.c @@ -183,11 +183,44 @@ static void updateLayout(void) { } } +static void revealRank(Card rank) { + for (uint i = 0; i < layout.main.len; ++i) { + struct Item item = layout.main.items[i]; + if (cardRank(item.card) != rank) continue; + listPush(&reveal, &item.rect, item.card); + } +} + static bool keyDown(SDL_KeyboardEvent key) { switch (key.keysym.sym) { case SDLK_F2: gameDeal(); return true; - default: return false; } + if (key.repeat) return false; + switch (key.keysym.sym) { + break; case SDLK_a: revealRank(Cards_A); + break; case SDLK_2: revealRank(Cards_2); + break; case SDLK_3: revealRank(Cards_3); + break; case SDLK_4: revealRank(Cards_4); + break; case SDLK_5: revealRank(Cards_5); + break; case SDLK_6: revealRank(Cards_6); + break; case SDLK_7: revealRank(Cards_7); + break; case SDLK_8: revealRank(Cards_8); + break; case SDLK_9: revealRank(Cards_9); + break; case SDLK_1: revealRank(Cards_10); + break; case SDLK_0: revealRank(Cards_10); + break; case SDLK_j: revealRank(Cards_J); + break; case SDLK_q: revealRank(Cards_Q); + break; case SDLK_k: revealRank(Cards_K); + break; default: return false; + } + return true; +} + +static bool keyUp(SDL_KeyboardEvent key) { + (void)key; + if (!reveal.len) return false; + reveal.len = 0; + return true; } static bool mouseButtonDown(SDL_MouseButtonEvent button) { @@ -223,7 +256,6 @@ static bool mouseButtonDown(SDL_MouseButtonEvent button) { return true; } - // TODO: Right click to reveal? if (!item) return false; if (!gameAvail(item->card)) return false; layout.dragItem = *item; @@ -368,6 +400,8 @@ int main(void) { goto quit; } else if (event.type == SDL_KEYDOWN) { if (keyDown(event.key)) break; + } else if (event.type == SDL_KEYUP) { + if (keyUp(event.key)) break; } else if (event.type == SDL_MOUSEBUTTONDOWN) { if (mouseButtonDown(event.button)) break; } else if (event.type == SDL_MOUSEBUTTONUP) { -- cgit 1.4.1 90c2e164e7fc8c98a709ccf31&showmsg=1'>unfollow)
Commit message (Collapse)Author
2019-02-18Don't match nested parentheses in Tag for CJune McEnroe
Fixes mistaken highlight of: pngWrite(file, (uint8_t []) { 0, 0, 0 }, 3);
2019-02-18Match whitespace between * [] {}June McEnroe
2019-02-18Fix function-like #define regexJune McEnroe
A define like #define FOO (1) is not function-like.
2019-02-18Match Tag in RustJune McEnroe
2019-02-18Match sh functions as TagJune McEnroe
2019-02-18Match Sh and Ss as Tag in mdocJune McEnroe
2019-02-18Match statics and typedefs as TagJune McEnroe
2019-02-18Clean up htmlHeaderJune McEnroe
2019-02-18Remove hi line numberingJune McEnroe
Tags are much better for referring to specific parts of a file and line numbering is better done by a post-processing tool such as cat -n or producing a two-column HTML <table>.
2019-02-18Add Tag class to hiJune McEnroe
2019-02-17Generate HTML with hi -n -f html -o anchorJune McEnroe
Running hi twice to insert stuff between the head and the content is a bit of a hack but oh well.
2019-02-17Add hi -f html -o anchor for line number linksJune McEnroe
2019-02-17Simplify temp trap in upJune McEnroe
2019-02-17Add line numbers to hiJune McEnroe
Renames previous -n option to -m to stay consistent with cat -n. Prefixing lines with line numbers affects where the first tab indent ends up relative to the text above it. Not sure if it's worth fixing somehow.
2019-02-17Always split spans after newlinesJune McEnroe
Simplifies ANSI and IRC output code, and prepares for line numbered output.
2019-02-15Color format specifiers light cyan in vimJune McEnroe
2019-02-15Highlight Interp as yellowJune McEnroe
2019-02-15Highlight strings in sh command substitutionsJune McEnroe
2019-02-15Add nmap gpJune McEnroe
2019-02-14Avoid newline when copying URL to pasteboardJune McEnroe
2019-02-13Add forgotten "sixth" book of H2G2June McEnroe