Moved key-to-string to virtualkeyboard

This commit is contained in:
simon.kagstrom 2009-01-22 21:05:04 +00:00
parent 7f262477fa
commit 1e3e2778ab
4 changed files with 32 additions and 50 deletions

View File

@ -255,43 +255,6 @@ void C64::select_disc(Prefs *np)
free(file_list); free(file_list);
} }
/*
C64 keyboard matrix:
Bit 7 6 5 4 3 2 1 0
0 CUD F5 F3 F1 F7 CLR RET DEL
1 SHL E S Z 4 A W 3
2 X T F C 6 D R 5
3 V U H B 8 G Y 7
4 N O K M 0 J I 9
5 , @ : . - L P +
6 / ^ = SHR HOM ; * <EFBFBD>
7 R/S Q C= SPC 2 CTL <- 1
*/
#define MATRIX(a,b) (((a) << 3) | (b))
static const char *key_names[] = { "None", "space", "Run/Stop", "return",
"F1", "F3", "F5", "F7",
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A",
"B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
"ctrl", "del", "home", "shl", "shr", "clr", "C=", "left arrow",
"arrow up", "key down", "key up", "key left", "key right",
NULL };
static int key_keycodes[] = { 0, MATRIX(7, 4), MATRIX(7, 7), MATRIX(0, 1), /* space, R/S, return */
MATRIX(0, 4), MATRIX(0, 5), MATRIX(0, 6), MATRIX(0, 3), /* F1-F7 */
MATRIX(4, 3), MATRIX(7, 0), MATRIX(7, 3), MATRIX(1, 0), MATRIX(1, 3), /* 0.. */
MATRIX(2, 0), MATRIX(2, 3), MATRIX(3, 0), MATRIX(3, 3), MATRIX(4, 0), /* ..9 */
MATRIX(1, 2), MATRIX(3, 4), MATRIX(2, 4), MATRIX(2, 2),
MATRIX(1, 6), MATRIX(2, 5), MATRIX(3, 2), MATRIX(3, 5), MATRIX(4, 1), MATRIX(4, 2),
MATRIX(4, 5), MATRIX(5, 2), MATRIX(4, 4), MATRIX(4, 7), MATRIX(4, 6), MATRIX(5, 1),
MATRIX(7, 6), MATRIX(2, 1), MATRIX(1, 5), MATRIX(2, 6), MATRIX(3, 6), MATRIX(3, 7),
MATRIX(1, 1), MATRIX(2, 7), MATRIX(3, 1), MATRIX(1, 4), /* ... Z */
MATRIX(7, 3), MATRIX(0, 0), MATRIX(6, 4), MATRIX(1, 7), MATRIX(6, 4),
MATRIX(0, 2), MATRIX(7, 5), MATRIX(7, 1), MATRIX(6, 6),
MATRIX(0, 7), MATRIX(0, 7) | 0x80, MATRIX(0, 2) | 0x80, MATRIX(0, 2),/* Direction keys */
};
char *C64::bind_one_key(Prefs *np, int which) char *C64::bind_one_key(Prefs *np, int which)
{ {
@ -300,19 +263,10 @@ char *C64::bind_one_key(Prefs *np, int which)
"classic R", "classic ZR", "classic ZL" }; "classic R", "classic ZR", "classic ZL" };
static char strs[N_WIIMOTE_BINDINGS][255]; static char strs[N_WIIMOTE_BINDINGS][255];
char *out = strs[which]; char *out = strs[which];
const char *cur_binding = "None";
int cur = np->JoystickKeyBinding[which]; int cur = np->JoystickKeyBinding[which];
for (unsigned int i = 1; i < sizeof(key_keycodes) / sizeof(key_keycodes[0]); i++ )
{
if (key_keycodes[i] == cur)
{
cur_binding = key_names[i];
break;
}
}
snprintf(out, 255, "Bind to %s (now %s)", which_to_button_name[which], snprintf(out, 255, "Bind to %s (now %s)", which_to_button_name[which],
cur_binding); this->virtual_keyboard->keycode_to_string(cur));
return out; return out;
} }

View File

@ -146,7 +146,7 @@ SAM.o: VIC.h SID.h
CmdPipe.o: CmdPipe.h CmdPipe.o: CmdPipe.h
C64.o: sysdeps.h sysconfig.h C64.h CPUC64.h CPU1541.h CIA.h Prefs.h VIC.h C64_SDL.h C64.o: sysdeps.h sysconfig.h C64.h CPUC64.h CPU1541.h CIA.h Prefs.h VIC.h C64_SDL.h
C64.o: SID.h REU.h IEC.h 1541job.h Display.h C64.o: SID.h REU.h IEC.h 1541job.h Display.h
C64_SC.o: C64.cpp sysdeps.h sysconfig.h C64.h CPUC64.h CPU1541.h CIA.h C64_SC.o: C64.cpp sysdeps.h sysconfig.h C64.h CPUC64.h CPU1541.h CIA.h C64_SDL.h
C64_SC.o: Prefs.h VIC.h SID.h REU.h IEC.h 1541job.h Display.h C64_SC.o: Prefs.h VIC.h SID.h REU.h IEC.h 1541job.h Display.h
CPUC64.o: sysdeps.h sysconfig.h CPUC64.h C64.h VIC.h SID.h CIA.h Prefs.h CPUC64.o: sysdeps.h sysconfig.h CPUC64.h C64.h VIC.h SID.h CIA.h Prefs.h
CPUC64.o: REU.h IEC.h Display.h Version.h CPU_emulline.h CPUC64.o: REU.h IEC.h Display.h Version.h CPU_emulline.h

View File

@ -48,8 +48,8 @@ typedef struct
#define KEY_ROWS 5 #define KEY_ROWS 5
static virtkey_t keys[KEY_COLS * KEY_ROWS] = { static virtkey_t keys[KEY_COLS * KEY_ROWS] = {
K("<-",7,1), K("1", 7,0), K("2", 7,3), K("3", 1,0), K("4", 1,3), K("5", 2,0), K("6", 2,3), K("7", 3,0), K("8", 3,3), K("9", 4,0), K("0", 4,3), K("+", 5,0), K("-", 5,3), K("£", 0,0), K("Hom", 6,3), K("<-",7,1), K("1", 7,0), K("2", 7,3), K("3", 1,0), K("4", 1,3), K("5", 2,0), K("6", 2,3), K("7", 3,0), K("8", 3,3), K("9", 4,0), K("0", 4,3), K("+", 5,0), K("-", 5,3), K("£", 6,0), K("Hom", 6,3),
K("Cr", 7,2), K("q", 7,6), K("w", 1,1), K("e", 1,6), K("r", 2,2), K("t", 2,6), K("y", 3,1), K("u", 3,6), K("i", 4,1), K("o", 6,6), K("p", 5,1), K("@", 5,6), K("*", 6,1), K("Au", 6,0),K("Rstr", 4,0), K("Cr", 7,2), K("q", 7,6), K("w", 1,1), K("e", 1,6), K("r", 2,2), K("t", 2,6), K("y", 3,1), K("u", 3,6), K("i", 4,1), K("o", 6,6), K("p", 5,1), K("@", 5,6), K("*", 6,1), K("Au", 6,6),K("Rstr", 4,0),
K("R/Stp", 7,7), K(0, 0,0), K("a", 1,2), K("s", 1,5), K("d", 2,2), K("f", 2,5), K("g", 3,2), K("h", 3,5), K("j", 4,2), K("k", 4,5), K("l", 5,2), K(":", 5,5), K(";", 6,2), K("=", 6,5), K("Ret", 0,1), K("R/Stp", 7,7), K(0, 0,0), K("a", 1,2), K("s", 1,5), K("d", 2,2), K("f", 2,5), K("g", 3,2), K("h", 3,5), K("j", 4,2), K("k", 4,5), K("l", 5,2), K(":", 5,5), K(";", 6,2), K("=", 6,5), K("Ret", 0,1),
K("C=", 7,5), S("Sh",1,7), K("z", 1,4), K("x", 2,7), K("c", 2,4), K("v", 3,7), K("b", 3,4), K("n", 4,7), K("m", 4,4), K(",", 5,7), K(".", 5,4), K("/", 6,7), K(NULL,0,0), K("Dwn", 0,7),K("Rgt", 0,2), K("C=", 7,5), S("Sh",1,7), K("z", 1,4), K("x", 2,7), K("c", 2,4), K("v", 3,7), K("b", 3,4), K("n", 4,7), K("m", 4,4), K(",", 5,7), K(".", 5,4), K("/", 6,7), K(NULL,0,0), K("Dwn", 0,7),K("Rgt", 0,2),
N("None"), K(0, 0,0), K(0, 0,0), K("space", 7,4),K(0, 0,0),K(0, 0,0), K("f1", 0,4),K("f3", 0,5),K("f5", 0,6),K("f7", 0,3),K(0, 0,0), K(0, 0,0), K(0, 0,0), K(0, 0,0), K("Del", 0,0), N("None"), K(0, 0,0), K(0, 0,0), K("space", 7,4),K(0, 0,0),K(0, 0,0), K("f1", 0,4),K("f3", 0,5),K("f5", 0,6),K("f7", 0,3),K(0, 0,0), K(0, 0,0), K(0, 0,0), K(0, 0,0), K("Del", 0,0),
@ -132,6 +132,33 @@ void VirtualKeyboard::toggle_shift()
this->shift_on = !this->shift_on; this->shift_on = !this->shift_on;
} }
const char *VirtualKeyboard::keycode_to_string(int kc)
{
bool shifted = kc & 0x80;
int kc_raw = kc & ~0x80;
const char *out = "Unknown";
if (kc < 0)
return "None";
/* Just loop through all of them */
for (int i = 0; i < KEY_COLS * KEY_ROWS; i++)
{
virtkey_t key = keys[i];
if (key.kc == kc_raw && key.name != NULL)
{
out = key.name;
if (shifted && shifted_names[i])
out = shifted_names[i];
break;
}
}
return out;
}
bool VirtualKeyboard::get_key(int *kc, bool *shifted) bool VirtualKeyboard::get_key(int *kc, bool *shifted)
{ {
bool out = false; bool out = false;

View File

@ -17,6 +17,7 @@ class VirtualKeyboard
public: public:
VirtualKeyboard(SDL_Surface *screen, TTF_Font *font); VirtualKeyboard(SDL_Surface *screen, TTF_Font *font);
bool get_key(int *kc, bool *shifted); bool get_key(int *kc, bool *shifted);
const char *keycode_to_string(int kc);
private: private:
void draw(); void draw();