mirror of
https://github.com/Oibaf66/uae-wii.git
synced 2024-11-22 10:39:19 +01:00
Added virtual keyboard
This commit is contained in:
parent
84ec8dd8c6
commit
63a899dbdc
@ -16,13 +16,11 @@
|
||||
#include "VirtualKeyboard.h"
|
||||
|
||||
|
||||
struct virtkey;
|
||||
|
||||
class VirtualKeyboard
|
||||
{
|
||||
public:
|
||||
VirtualKeyboard(SDL_Surface *screen, TTF_Font *font);
|
||||
const char* get_key();
|
||||
struct virtkey* get_key();
|
||||
|
||||
private:
|
||||
struct virtkey* get_key_internal();
|
||||
@ -38,35 +36,30 @@ private:
|
||||
char buf[255];
|
||||
};
|
||||
|
||||
typedef struct virtkey
|
||||
{
|
||||
const char *name;
|
||||
const char *ev_name;
|
||||
bool is_done;
|
||||
} virtkey_t;
|
||||
|
||||
#define K(name) \
|
||||
{ name, "KEY_"name, false }
|
||||
#define N(name, key_name) \
|
||||
{ name, "KEY_"key_name, false }
|
||||
|
||||
#define K(name, sdl_code) \
|
||||
{ name, "KEY_"name, sdl_code, false }
|
||||
#define N(name, key_name, sdl_code) \
|
||||
{ name, "KEY_"key_name, sdl_code, false }
|
||||
#define D(name) \
|
||||
{ name, "None", true }
|
||||
{ name, "None", 0, true }
|
||||
#define KNL() \
|
||||
{ NULL, NULL, false }
|
||||
{ NULL, NULL, 0, false }
|
||||
#define NJ(name, joy_name) \
|
||||
{ name, joy_name, false }
|
||||
{ name, joy_name, 0, false }
|
||||
|
||||
#define KEY_COLS 14
|
||||
#define KEY_ROWS 8
|
||||
|
||||
static virtkey_t keys[KEY_COLS * KEY_ROWS] = {
|
||||
N("Esc", "ESC"), KNL(), K("F1"),K("F2"),K("F3"),K("F4"),K("F5"),K("F6"),K("F7"),K("F8"),K("F9"),K("F10"), N("Del","DEL"),N("Help", "HELP"),
|
||||
N("~`","BACKQUOTE"),KNL(),K("1"), K("2"), K("3"), K("4"), K("5"), K("6"), K("7"), K("8"), K("9"), K("0"), N("-", "SUB"),N("+", "PLUS"),
|
||||
N("Tab", "TAB"), KNL(), K("Q"), K("W"), K("E"), K("R"), K("T"), K("Y"), K("U"), K("I"), K("O"), K("P"),N("[", "LEFTBRACKET"),N("]","RIGHTBRACKET"),
|
||||
N("Sft","SHIFT_LEFT"),KNL(), K("A"), K("S"), K("D"), K("F"), K("G"), K("H"), K("J"), K("K"), K("L"), N(":;", "SEMICOLON"), N("@#", "??"), N("Sft", "SHIFT_RIGHT"),
|
||||
N("Ctrl","CTRL"),KNL(),K("Z"),K("X"), K("C"), K("V"), K("B"), K("N"), K("M"),N("<,", "COMMA"),N(">.", "PERIOD"), N("\\","KEY_BACKSLASH"), N("/", "SLASH"),N("Ret", "RETURN"),
|
||||
N("Alt","ALT_LEFT"),KNL(), N("Amg","AMIGA_LEFT"),KNL(),N("space", "SPACE"),KNL(),KNL(),KNL(), N("Up", "CURSOR_UP"),KNL(),KNL(),N("Amg","AMIGA_RIGHT"),KNL(),N("Alt","ALT_RIGHT"),
|
||||
D("None"), KNL(), KNL(), KNL(), KNL(), KNL(), N("Lft", "CURSOR_LEFT"),KNL(), N("Dwn", "CURSOR_DOWN"), KNL(), N("Rgt", "CURSOR_RIGHT"),KNL(), N("Enter", "ENTER"),KNL(),
|
||||
N("Esc","ESC",27), KNL(), K("F1",282),K("F2",283),K("F3",284),K("F4",285),K("F5",286),K("F6",287),K("F7",288),K("F8",289),K("F9",290),K("F10",291), N("BS","BACKSPACE",8),N("Help", "HELP",277),
|
||||
N("~`","BACKQUOTE",96),KNL(),K("1",49),K("2",50), K("3",51), K("4",52), K("5",53), K("6",54), K("7",55), K("8",56), K("9",57), K("0",48), N("-","SUB",45),N("=","EQUALS",61),
|
||||
N("Tab", "TAB", 9), KNL(), K("Q",113), K("W",119), K("E",101), K("R",114), K("T",116), K("Y",121), K("U",117), K("I",105), K("O",111), K("P",112),N("[","LEFTBRACKET",91),N("]","RIGHTBRACKET",93),
|
||||
N("Ctrl","CTRL",306),KNL(), K("A",97), K("S",115), K("D",100), K("F",102), K("G",103), K("H",104), K("J",106), K("K",107), K("L",108),N(":;","SEMICOLON",59),N("'","SINGLEQUOTE",96),N("Ret","RETURN",13),
|
||||
N("Sft","SHIFT_LEFT",304),KNL(),K("Z",122),K("X",120),K("C",99), K("V",118), K("B",98), K("N",110), K("M",109),N("<,","COMMA",44),N(">.","PERIOD",46), N("/","SLASH",47),N("\\","KEY_BACKSLASH",92), N("Sft","SHIFT_RIGHT",303),
|
||||
N("Alt","ALT_LEFT",308),KNL(), N("Amg","AMIGA_LEFT",310),KNL(),N("space", "SPACE",32),KNL(),KNL(),KNL(),N("Up","CURSOR_UP",273),KNL(),KNL(),N("Amg","AMIGA_RIGHT",309),KNL(),N("Alt","ALT_RIGHT",307),
|
||||
D("None"), KNL(), KNL(), KNL(), KNL(), KNL(), N("Lft","CURSOR_LEFT",276),KNL(), N("Dwn","CURSOR_DOWN",274), KNL(), N("Rgt", "CURSOR_RIGHT",275),KNL(), N("Enter","ENTER",271),KNL(),
|
||||
NJ("Fire","JOY_FIRE_BUTTON"),KNL(),KNL(),NJ("Joy 2nd button","JOY_2ND_BUTTON"),KNL(),KNL(),KNL(),KNL(),KNL(),NJ("Joy 3rd button","JOY_3RD_BUTTON"),KNL(),KNL(),KNL(),KNL()
|
||||
};
|
||||
|
||||
@ -176,7 +169,7 @@ struct virtkey *VirtualKeyboard::get_key_internal()
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* VirtualKeyboard::get_key()
|
||||
struct virtkey* VirtualKeyboard::get_key()
|
||||
{
|
||||
virtkey_t *key;
|
||||
SDL_Rect rect = {32, 32, FULL_DISPLAY_X-64, FULL_DISPLAY_Y-96};
|
||||
@ -184,10 +177,8 @@ const char* VirtualKeyboard::get_key()
|
||||
SDL_FillRect(this->screen, &rect, SDL_MapRGB(screen->format, 0xff, 0xff, 0xff));
|
||||
|
||||
key = this->get_key_internal();
|
||||
if (key == NULL)
|
||||
return NULL;
|
||||
|
||||
return key->ev_name;
|
||||
return key;
|
||||
}
|
||||
|
||||
/* C interface */
|
||||
@ -197,7 +188,7 @@ void virtkbd_init(SDL_Surface *surf, TTF_Font *fnt)
|
||||
virtual_keyboard = new VirtualKeyboard(surf, fnt);
|
||||
}
|
||||
|
||||
const char *virtkbd_get_key(void)
|
||||
struct virtkey *virtkbd_get_key(void)
|
||||
{
|
||||
return virtual_keyboard->get_key();
|
||||
}
|
||||
|
@ -12,12 +12,20 @@
|
||||
#include <SDL.h>
|
||||
#include <SDL_ttf.h>
|
||||
|
||||
typedef struct virtkey
|
||||
{
|
||||
const char *name;
|
||||
const char *ev_name;
|
||||
int sdl_code;
|
||||
int is_done;
|
||||
} virtkey_t;
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern void virtkbd_init(SDL_Surface *surf, TTF_Font *fnt);
|
||||
extern const char *virtkbd_get_key(void);
|
||||
extern struct virtkey *virtkbd_get_key(void);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
};
|
||||
|
@ -24,6 +24,14 @@
|
||||
#define ID_BUTTON_OFFSET 0
|
||||
#define ID_AXIS_OFFSET 32
|
||||
|
||||
/* Uncomment for debugging output */
|
||||
//#define DEBUG
|
||||
#ifdef DEBUG
|
||||
#define DEBUG_LOG write_log
|
||||
#else
|
||||
#define DEBUG_LOG(...) do ; while(0)
|
||||
#endif
|
||||
|
||||
extern int usbismount, smbismount;
|
||||
|
||||
extern const char *strdup_path_expand (const char *src);
|
||||
@ -38,13 +46,14 @@ static const char *main_menu_messages[] = {
|
||||
/*04*/ "#1-------------------------------------",
|
||||
/*05*/ "Wiimote configuration",
|
||||
/*06*/ "^|Wiimote1|Wiimote2",
|
||||
/*07*/ "Hardware options",
|
||||
/*08*/ "Emulation options",
|
||||
/*09*/ "Other options",
|
||||
/*10*/ "Save confs",
|
||||
/*11*/ "Reset UAE",
|
||||
/*12*/ "Help",
|
||||
/*13*/ "Quit",
|
||||
/*07*/ "Virtual keyboard",
|
||||
/*08*/ "Hardware options",
|
||||
/*09*/ "Emulation options",
|
||||
/*10*/ "Other options",
|
||||
/*11*/ "Save confs",
|
||||
/*12*/ "Reset UAE",
|
||||
/*13*/ "Help",
|
||||
/*14*/ "Quit",
|
||||
NULL
|
||||
};
|
||||
|
||||
@ -579,7 +588,8 @@ static void insert_keyboard_map(const char *key, const char *fmt, ...)
|
||||
|
||||
//printf("Mibb: %s:%s\n", buf, key);
|
||||
read_inputdevice_config (&changed_prefs, buf, key);
|
||||
read_inputdevice_config (&currprefs, buf, key);
|
||||
|
||||
inputdevice_config_change();
|
||||
}
|
||||
|
||||
|
||||
@ -587,8 +597,8 @@ static void setup_joystick(int joy, const char *key, int sdl_key)
|
||||
{
|
||||
if (!strcmp(key, "None"))
|
||||
{
|
||||
currprefs.joystick_settings[1][joy].eventid[ID_BUTTON_OFFSET + sdl_key][0] = 0;
|
||||
changed_prefs.joystick_settings[1][joy].eventid[ID_BUTTON_OFFSET + sdl_key][0] = 0;
|
||||
inputdevice_config_change();
|
||||
}
|
||||
else
|
||||
insert_keyboard_map(key, "input.1.joystick.%d.button.%d", joy, sdl_key);
|
||||
@ -621,8 +631,8 @@ static void input_options(int joy)
|
||||
if (!joy) insert_keyboard_map("JOY2_HORIZ","input.1.joystick.%d.axis.6", 0);
|
||||
else insert_keyboard_map("JOY1_HORIZ" ,"input.1.joystick.%d.axis.6", 1);}
|
||||
else{
|
||||
currprefs.joystick_settings[1][joy].eventid[ID_AXIS_OFFSET + 6][0] = 0;
|
||||
changed_prefs.joystick_settings[1][joy].eventid[ID_AXIS_OFFSET + 6][0] = 0;
|
||||
inputdevice_config_change();
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -632,17 +642,16 @@ static void input_options(int joy)
|
||||
if (submenus[4])
|
||||
{
|
||||
changed_prefs.mouse_settings[1][joy].enabled = 0;
|
||||
currprefs.mouse_settings[1][joy].enabled = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
changed_prefs.mouse_settings[1][joy].enabled = 1;
|
||||
currprefs.mouse_settings[1][joy].enabled = 1;
|
||||
}
|
||||
inputdevice_config_change();
|
||||
return;
|
||||
}
|
||||
|
||||
key = virtkbd_get_key();
|
||||
key = virtkbd_get_key()->ev_name;
|
||||
if (key == NULL)
|
||||
return;
|
||||
switch(opt)
|
||||
@ -669,6 +678,25 @@ static void input_options(int joy)
|
||||
|
||||
}
|
||||
|
||||
static void virtual_keyboard(void)
|
||||
{
|
||||
int key_code;
|
||||
|
||||
virtkey_t *key =virtkbd_get_key();
|
||||
if (key) {key_code = key->sdl_code;} else return;
|
||||
|
||||
SDL_Event event_key;
|
||||
|
||||
event_key.type=SDL_KEYDOWN;
|
||||
event_key.key.keysym.sym=key_code;
|
||||
SDL_PushEvent(&event_key);
|
||||
DEBUG_LOG ("Push Event: keycode %d %s\n", key_code, "SDL_KEYDOWN");
|
||||
|
||||
event_key.type=SDL_KEYUP;
|
||||
SDL_PushEvent(&event_key);
|
||||
DEBUG_LOG ("Push Event: keycode %d %s\n", key_code, "SDL_KEYUP");
|
||||
|
||||
}
|
||||
|
||||
|
||||
static void hardware_options(void)
|
||||
@ -883,30 +911,33 @@ void gui_display(int shortcut)
|
||||
input_options(submenus[2]);
|
||||
break;
|
||||
case 7:
|
||||
hardware_options();
|
||||
virtual_keyboard();
|
||||
break;
|
||||
case 8:
|
||||
emulation_options();
|
||||
hardware_options();
|
||||
break;
|
||||
case 9:
|
||||
graphic_options();
|
||||
emulation_options();
|
||||
break;
|
||||
case 10:
|
||||
save_configurations();
|
||||
graphic_options();
|
||||
break;
|
||||
case 11:
|
||||
uae_reset(1);
|
||||
save_configurations();
|
||||
break;
|
||||
case 12:
|
||||
help();
|
||||
uae_reset(1);
|
||||
break;
|
||||
case 13:
|
||||
help();
|
||||
break;
|
||||
case 14:
|
||||
if (msgYesNo("Are you sure to quit?", 0, FULL_DISPLAY_X /2-138, FULL_DISPLAY_Y /2-48)) uae_quit();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} while (opt == 0 || opt == 5 || opt == 7 || opt == 8 || opt == 9 || opt == 12);
|
||||
} while (opt == 0 || opt == 5 || opt == 8 || opt == 9 || opt == 10 || opt == 13);
|
||||
|
||||
resume_sound();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user