mirror of
https://github.com/pevans/erc-c.git
synced 2025-02-07 03:30:28 +00:00
Break keyboard event logic out into normal/special
This commit is contained in:
parent
fa5bfe09ae
commit
608b2259e5
@ -10,5 +10,7 @@ typedef struct {
|
||||
|
||||
extern void vm_event_keyboard(vm_event *);
|
||||
extern void vm_event_poll(vm_screen *);
|
||||
extern void vm_event_keyboard_normal(vm_event *, char);
|
||||
extern void vm_event_keyboard_special(vm_event *, char);
|
||||
|
||||
#endif
|
||||
|
@ -35,6 +35,42 @@ vm_event_keyboard(vm_event *ev)
|
||||
// ASCII in the low range.
|
||||
ch = (char)ev->event.key.keysym.sym;
|
||||
|
||||
switch (ev->event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
ev->screen->dirty = true;
|
||||
ev->screen->key_pressed = true;
|
||||
vm_event_keyboard_normal(ev, ch);
|
||||
break;
|
||||
|
||||
case SDL_KEYUP:
|
||||
// Note we do not erase the last_key value.
|
||||
ev->screen->key_pressed = false;
|
||||
vm_event_keyboard_special(ev, ch);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Handle the keyboard event for a normal (printable) character; this is
|
||||
* basically anything alphanumeric, but also includes symbols like $#?!
|
||||
* etc.
|
||||
*
|
||||
* This function only fires in the case of a KEYDOWN event.
|
||||
*/
|
||||
void
|
||||
vm_event_keyboard_normal(vm_event *ev, char ch)
|
||||
{
|
||||
// Basically, we only care about printable characters. Sorry to be
|
||||
// exclusionary to other characters! They are handled in other
|
||||
// functions.
|
||||
if (!isprint(ch)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If we had shift pressed, we need to uppercase the
|
||||
// character.
|
||||
if (ev->event.key.keysym.mod & KMOD_LSHIFT ||
|
||||
@ -43,24 +79,27 @@ vm_event_keyboard(vm_event *ev)
|
||||
ch = toupper(ch);
|
||||
}
|
||||
|
||||
switch (ev->event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
ev->screen->dirty = true;
|
||||
ev->screen->key_pressed = true;
|
||||
ev->screen->last_key = ch;
|
||||
break;
|
||||
ev->screen->last_key = ch;
|
||||
}
|
||||
|
||||
case SDL_KEYUP:
|
||||
// Note we do not erase the last_key value.
|
||||
ev->screen->key_pressed = false;
|
||||
/*
|
||||
* Handle keyboard events for "special" characters, which are
|
||||
* essentially those which are not printable. ESC, RET, TAB...you get
|
||||
* the idea.
|
||||
*
|
||||
* Unlike the normal event, this function should only fire in the case
|
||||
* of a KEYUP event.
|
||||
*/
|
||||
void
|
||||
vm_event_keyboard_special(vm_event *ev, char ch)
|
||||
{
|
||||
int mod = ev->event.key.keysym.mod;
|
||||
|
||||
if (ch == SDLK_ESCAPE) {
|
||||
if (mod & KMOD_ALT) {
|
||||
switch (ch) {
|
||||
case 'q':
|
||||
ev->screen->should_exit = true;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user