diff options
| author | Franklin Wei <me@fwei.tk> | 2018-04-17 16:18:16 -0400 |
|---|---|---|
| committer | Simon Tatham <anakin@pobox.com> | 2018-04-22 17:04:50 +0100 |
| commit | 60a929a250cf4f7f87ac082e5705f9a838a7f8c8 (patch) | |
| tree | 33a8a715f6320d2a2d58532b04e33ef111f31507 /misc.c | |
| parent | 3d04dd3335a2c4c6007ff4e2a58a2855c7a9c52a (diff) | |
| download | puzzles-60a929a250cf4f7f87ac082e5705f9a838a7f8c8.zip puzzles-60a929a250cf4f7f87ac082e5705f9a838a7f8c8.tar.gz puzzles-60a929a250cf4f7f87ac082e5705f9a838a7f8c8.tar.bz2 puzzles-60a929a250cf4f7f87ac082e5705f9a838a7f8c8.tar.xz | |
Add a request_keys() function with a midend wrapper.
This function gives the front end a way to find out what keys the back
end requires; and as such it is mostly useful for ports without a
keyboard. It is based on changes originally found in Chris Boyle's
Android port, though some modifications were needed to make it more
flexible.
Diffstat (limited to 'misc.c')
| -rw-r--r-- | misc.c | 45 |
1 files changed, 45 insertions, 0 deletions
@@ -21,6 +21,15 @@ void free_cfg(config_item *cfg) sfree(cfg); } +void free_keys(key_label *keys, int nkeys) +{ + int i; + + for(i = 0; i < nkeys; i++) + sfree(keys->label); + sfree(keys); +} + /* * The Mines (among others) game descriptions contain the location of every * mine, and can therefore be used to cheat. @@ -393,4 +402,40 @@ void copy_left_justified(char *buf, size_t sz, const char *str) buf[sz - 1] = 0; } +/* Returns a dynamically allocated label for a generic button. + * Game-specific buttons should go into the `label' field of key_label + * instead. */ +char *button2label(int button) +{ + /* check if it's a keyboard button */ + if(('A' <= button && button <= 'Z') || + ('a' <= button && button <= 'z') || + ('0' <= button && button <= '9') ) + { + char str[2] = { button, '\0' }; + return dupstr(str); + } + + switch(button) + { + case CURSOR_UP: + return dupstr("Up"); + case CURSOR_DOWN: + return dupstr("Down"); + case CURSOR_LEFT: + return dupstr("Left"); + case CURSOR_RIGHT: + return dupstr("Right"); + case CURSOR_SELECT: + return dupstr("Select"); + case '\b': + return dupstr("Clear"); + default: + fatal("unknown generic key"); + } + + /* should never get here */ + return NULL; +} + /* vim: set shiftwidth=4 tabstop=8: */ |