Added graphic virtual keyboard

This commit is contained in:
fabio.olimpieri 2014-01-11 06:58:34 +00:00
parent 807f70fe2e
commit 0aaba1033f
8 changed files with 187 additions and 125 deletions

View File

@ -144,11 +144,13 @@ CFLAGS := $(COMMON_FLAGS) $(INCLUDES) $(DEFINES)
#unused defines; -DCAPS (to enable ipf file) -DFDI2RAW (to enable DFI file)
# Test link flags.
LDFLAGS := $(COMMON_FLAGS) -L$(LIB_DIR) -L$(PORTLIBS)/lib -L$(DEVKITPRO)/libogc/lib -L$(DEVKITPRO)/libogc/lib/wii -lz -lSDL_ttf -lSDL -lfreetype -lfat -lwiiuse -lbte -logc -lm -lwiikeyboard -ltinysmb
LDFLAGS := $(COMMON_FLAGS) -L$(LIB_DIR) -L$(PORTLIBS)/lib -L$(DEVKITPRO)/libogc/lib -L$(DEVKITPRO)/libogc/lib/wii -lz -lSDL_ttf -lSDL -lSDL_image -lpng -ljpeg -lfreetype -lfat -lwiiuse -lbte -logc -lm -lwiikeyboard -ltinysmb
dist:uae.dol
install -d $@/apps/uae
install -d $@/apps/uae/docs
install -d $@/apps/uae/images/
install -d $@/uae
install -d $@/uae/roms
install -d $@/uae/floppies
@ -166,11 +168,12 @@ dist:uae.dol
cp icon.png $@/apps/uae/
cp FreeMono.ttf $@/apps/uae/
cp Smaller.ttf $@/apps/uae/
cp README.Cloanto-Amiga_Forever $@/apps/uae/
cp README.Cloanto-Amiga_Forever $@/apps/uae/docs/
cp images/kb_amiga.png $@/apps/uae/images/
cp uaerc.wii $@/uae/uaerc
cp uaerc.smb $@/uae/
cp docs/configuration.txt $@/apps/uae/
cp docs/Joystick_mapping.txt $@/apps/uae/
cp docs/configuration.txt $@/apps/uae/docs/
cp docs/Joystick_mapping.txt $@/apps/uae/docs/
cp src/resource/*.wav $@/uae/wave
cd $@ && tar -czf ../uae-wii-vx-bin.tar.gz *

BIN
images/kb_amiga.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

View File

@ -1,31 +1,36 @@
/*********************************************************************
*
* Copyright (C) 2009, Simon Kagstrom
* Copyright (C) 2014, Fabio Olimpieri
*
* Filename: VirtualKeyboard.c
* Author: Simon Kagstrom <simon.kagstrom@gmail.com>
* Author: Simon Kagstrom <simon.kagstrom@gmail.com>, Fabio Olimpieri
* Description: A virtual keyboard
*
* $Id$
*
********************************************************************/
#include <SDL.h>
#include <SDL_ttf.h>
#include<SDL/SDL_image.h>
#ifdef GEKKO
#include <wiiuse/wpad.h>
#endif
#include "menu.h"
#include "VirtualKeyboard.h"
#include "writelog.h"
#include "target.h"
#include "gensound.h"
static SDL_Surface *image_kbd, *tmp_surface ;
static int vkb_is_init;
//static int key_code;
static struct virtkey* get_key_internal();
static void draw();
static void select_next(int dx, int dy);
static VirtualKeyboard_struct VirtualKeyboard;
static SDL_Surface *screen;
static TTF_Font *font;
static int sel_x;
static int sel_y;
static char buf[255];
int kbd_is_active;
#define K(name, sdl_code) \
@ -39,113 +44,149 @@ static char buf[255];
#define NJ(name, joy_name) \
{ name, joy_name, 0, 0 }
#define KEY_COLS 14
#define KEY_ROWS 8
#define KEY_COLS 21
#define KEY_ROWS 7
static virtkey_t keys[KEY_COLS * KEY_ROWS] = {
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()
};
N("Esc","ESC",27), 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), KNL(),KNL(),KNL(),KNL(),KNL(),KNL(),KNL(),KNL(),KNL(),KNL(),
N("~`","BACKQUOTE",96),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("\\","KEY_BACKSLASH",92),N("BS","BACKSPACE",8),N("Del", "DELETE",127),N("Help", "HELP",277),K("LEFTPAREN",278), K("RIGHTPAREN",279),K("KP_DIVIDE",267),K("KP_MULTIPLY",268),
N("Tab", "TAB", 9), 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("Ret","RETURN",13),KNL(), K("KP7",263), K("KP8",264), K("KP9",265), K("KP_MINUS",269),KNL(),KNL(),
N("Ctrl","CTRL",306),N("Capslock","CAPSLOCK",301), 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),KNL(),N("Up","CURSOR_UP",273),KNL(),K("KP4",260), K("KP5",261), K("KP6",262),K("KP_PLUS",270),
N("Sft","SHIFT_LEFT",304),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("Sft","SHIFT_RIGHT",303), N("Lft","CURSOR_LEFT",276), N("Dwn","CURSOR_DOWN",274), N("Rgt", "CURSOR_RIGHT",275),K("KP1",257),K("KP2",258), K("KP3",259), N("Enter","KP_ENTERENTER",271),KNL(),KNL(),
N("Alt","ALT_LEFT",308), N("Amg","AMIGA_LEFT",310),N("space", "SPACE",32),N("Amg","AMIGA_RIGHT",309),N("Alt","ALT_RIGHT",307),KNL(),K("KP0",256),N(".","KP_PERIOD",266),N("Enter","KP_ENTER",271),KNL(),KNL(),KNL(),KNL(),KNL(),KNL(),KNL(),KNL(),KNL(),KNL(),KNL(),KNL(),
NJ("Fire","JOY_FIRE_BUTTON"),NJ("Joy 2nd button","JOY_2ND_BUTTON"),NJ("Joy 3rd button","JOY_3RD_BUTTON"), NJ("Joy left","JOY_LEFT"),NJ("Joy right","JOY_RIGHT"),NJ("Joy up","JOY_UP"),NJ("Joy down","JOY_DOWN"),D("None"),KNL(),KNL(),KNL(),KNL(),KNL(),KNL(),KNL(),KNL(),KNL(),KNL(),KNL(),KNL(), KNL()};
static int rows_margins[KEY_ROWS+1] = {26, 49, 74, 98, 122, 145, 172, 198};
static int buttons_margins[KEY_ROWS][KEY_COLS+1] = {
{14,44,79,110,143,175,216,257,289,321,353,386},
{14,47,73,99,125,151,177,203,229,255,281,307,333,359,385,417,462,509,541,567,593,620},
{14,62,88,114,140,166,192,218,244,270,296,322,348,374,412,515,541,567,593,620},
{14,42,67,93,119,145,171,197,223,249,275,301,327,353,412,449,476,515,541,567,593,620},
{14,80,106,132,158,184,210,236,262,288,314,340,417,449,476,515,541,567,593,620 },
{28,63,95,329,361,396,515,567,593,620},
{14,80,146,212,278,344,411,476,543}};
void draw()
void VirtualKeyboard_init(SDL_Surface *screen)
{
int screen_w = screen->w;
int screen_h = screen->h;
int key_w = 36;
int key_h = 36;
int border_x = (screen_w - (key_w * KEY_COLS)) / 2;
int border_y = (screen_h - (key_h * KEY_ROWS)) / 2;
int y;
int x;
VirtualKeyboard.screen = screen;
VirtualKeyboard.x = 3; //Where to print the keyboard
VirtualKeyboard.y = 100;
vkb_is_init = -1;
SDL_Rect bg_rect = {border_x, border_y,
key_w * KEY_COLS, key_h * KEY_ROWS};
char kbd_image[255];
SDL_FillRect(screen, &bg_rect,
SDL_MapRGB(screen->format, 0xff, 0xff, 0xff));
strcpy (kbd_image, "");
for (y = 0; y < KEY_ROWS; y++ )
{
for (x = 0; x < KEY_COLS; x++ )
{
int which = y * KEY_COLS + x;
virtkey_t key = keys[which];
int r = 64, g = 64, b = 64;
const char *what = key.name;
#ifdef OPTIONS_IN_HOME
char *home;
home = getenv ("HOME");
if (home != NULL && strlen (home) < 240)
{
strcpy (kbd_image, home);
strcat (kbd_image, "/");
}
#endif
/* Skip empty positions */
if (key.name == NULL)
continue;
strcat (kbd_image, KBDIMAGE);
tmp_surface=IMG_Load(kbd_image);
if ( key.is_done )
r = 255;
if ( (x == sel_x && y == sel_y))
g = 200;
menu_print_font(screen, r, g, b,
x * key_w + border_x, y * key_h + border_y,
what, 20);
}
}
if (tmp_surface == NULL) {write_log("Impossible to load keyboard image\n"); return;}
image_kbd=SDL_DisplayFormat(tmp_surface);
SDL_FreeSurface (tmp_surface);
memset(VirtualKeyboard.buf, 0, sizeof(VirtualKeyboard.buf));
vkb_is_init = 1;
kbd_is_active=0;
}
void select_next(int dx, int dy)
void draw_vk()
{
int next_x = (sel_x + dx) % KEY_COLS;
int next_y = (sel_y + dy) % KEY_ROWS;
virtkey_t key;
if (next_x < 0)
next_x = KEY_COLS + next_x;
if (next_y < 0)
next_y = KEY_ROWS + next_y;
sel_x = next_x;
sel_y = next_y;
key = keys[ next_y * KEY_COLS + next_x ];
/* Skip the empty spots */
if (key.name == NULL)
{
if (dy != 0) /* Look left */
select_next(-1, 0);
else
select_next(dx, dy);
}
SDL_Rect dst_rect = {VirtualKeyboard.x, VirtualKeyboard.y, 0, 0};
SDL_BlitSurface(image_kbd, NULL, VirtualKeyboard.screen, &dst_rect);
}
inline void flip_VKB()
{
SDL_Flip(VirtualKeyboard.screen);
}
int get_index(int x, int y)
{
int row, col;
row=col=0;
if ((x<0)||(x> 620)) return -1;
if ((y<0)||(y> 198)) return -1;
for (row=0; (rows_margins[row]<y)&&(row<KEY_ROWS+1); row++);
if (row==0) return -1; //not valid
if (rows_margins[row]<y) return -1; //not valid
row--;
for (col=0; (buttons_margins[row][col]<x)&&(row<KEY_COLS+1); col++);
if (col==0) return -1; //not valid
if (buttons_margins[row][col]<x) return -1; //not valid
col--;
return ((col) + (row) *KEY_COLS);
}
struct virtkey *get_key_internal()
{
while(1)
{
uint32_t k;
int x,y,xm, ym, i=0;
int border_x = VirtualKeyboard.x;
int border_y = VirtualKeyboard.y;
draw();
SDL_Flip(screen);
draw_vk();
SDL_ShowCursor(SDL_ENABLE);
flip_VKB();
k = menu_wait_key_press();
SDL_ShowCursor(SDL_DISABLE);
if (k & KEY_UP)
select_next(0, -1);
else if (k & KEY_DOWN)
select_next(0, 1);
else if (k & KEY_LEFT)
select_next(-1, 0);
else if (k & KEY_RIGHT)
select_next(1, 0);
else if (k & KEY_ESCAPE)
return NULL;
if (k & KEY_ESCAPE) return NULL;
else if (k & KEY_SELECT)
{
virtkey_t *key = &keys[ sel_y * KEY_COLS + sel_x ];
SDL_GetMouseState(&xm, &ym);
x = (xm-border_x);
y = (ym-border_y);
i = get_index(x,y);
if (i==-1) continue;
#ifdef GEKKO
WPAD_Rumble(0, 1);
SDL_Delay(90);
WPAD_Rumble(0, 0);
#endif
virtkey_t *key = &keys[i];
return key;
}
}
@ -153,25 +194,24 @@ struct virtkey *get_key_internal()
return NULL;
}
struct virtkey* virtkbd_get_key(void)
struct virtkey* virtkbd_get_key()
{
virtkey_t *key;
SDL_Rect rect = {56, 80, FULL_DISPLAY_X-104, FULL_DISPLAY_Y-176};
SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format, 0xff, 0xff, 0xff));
if (vkb_is_init != 1) return NULL;
pause_sound();
kbd_is_active=1;
key = get_key_internal();
kbd_is_active=0;
resume_sound();
return key;
}
void virtkbd_init(SDL_Surface *surf, TTF_Font *fnt)
{
sel_x = 0;
sel_y = 0;
screen = surf;
font = fnt;
memset(buf, 0, sizeof(buf));
}

View File

@ -1,9 +1,10 @@
/*********************************************************************
*
* Copyright (C) 2009, Simon Kagstrom
* Copyright (C) 2014, Fabio Olimpieri
*
* Filename: VirtualKeyboard.c
* Author: Simon Kagstrom <simon.kagstrom@gmail.com>
* Author: Simon Kagstrom <simon.kagstrom@gmail.com>, Fabio Olimpieri
* Description: A virtual keyboard
*
* $Id$
@ -20,5 +21,16 @@ typedef struct virtkey
int is_done;
} virtkey_t;
extern void virtkbd_init(SDL_Surface *surf, TTF_Font *fnt);
typedef struct Virtual_Keyboard
{
SDL_Surface *screen;
int x;
int y;
char buf[255];
} VirtualKeyboard_struct;
extern void VirtualKeyboard_init(SDL_Surface *surf);
extern struct virtkey *virtkbd_get_key(void);
extern void flip_VKB();
extern int kbd_is_active;

View File

@ -1,9 +1,9 @@
/*
* UAE - The Un*x Amiga Emulator
*
* Interface to the Tcl/Tk GUI
* WII Interface
*
* Copyright 1996 Bernd Schmidt
* Copyright 2014 Fabio Olimpieri
*/
#include <sys/types.h>
@ -864,8 +864,7 @@ msgInfo("File deleted",3000,NULL);
static int get_dfxclick(void)
{
int sounddf_on = 0;
int i;
int sounddf_on = 0;
sounddf_on = (changed_prefs.dfxclick[0]!=0)||(changed_prefs.dfxclick[1]!=0)||
(changed_prefs.dfxclick[2]!=0)||(changed_prefs.dfxclick[3]!=0);
@ -1096,7 +1095,6 @@ static void input_options(int joy)
const char *key;
int submenus[5];
int opt;
int i;
struct virtkey *virtualkey;
memset(submenus, 0, sizeof(submenus));
@ -1159,6 +1157,19 @@ static void input_options(int joy)
if (!strcmp(key,"JOY_3RD_BUTTON"))
key= joy ? "JOY1_3RD_BUTTON": "JOY2_3RD_BUTTON";
if (!strcmp(key,"JOY_LEFT"))
key= joy ? "JOY1_LEFT": "JOY2_LEFT";
if (!strcmp(key,"JOY_RIGHT"))
key= joy ? "JOY1_RIGHT": "JOY2_RIGHT";
if (!strcmp(key,"JOY_UP"))
key= joy ? "JOY1_UP": "JOY2_UP";
if (!strcmp(key,"JOY_DOWN"))
key= joy ? "JOY1_DOWN": "JOY2_DOWN";
setup_joystick(joy, key, sdl_key);

View File

@ -77,7 +77,7 @@ int fh, fw;
int msgInfo(char *text, int duration, SDL_Rect *irc)
{
int len = strlen(text);
int X, Y, wX, wY;
int X, Y;
SDL_Rect src;
SDL_Rect rc;
SDL_Rect brc;
@ -137,7 +137,7 @@ void msgKill(SDL_Rect *rc)
int msgYesNo(char *text, int default_opt, int x, int y)
{
int len = strlen(text);
int X, Y, wX, wY;
int X, Y;
SDL_Rect src;
SDL_Rect rc;
SDL_Rect brc;
@ -426,7 +426,6 @@ static void menu_draw(SDL_Surface *screen, menu_t *p_menu, int sel, int font_siz
int entries_visible = (p_menu->y2 - p_menu->y1) / line_height - 1;
int i, y;
char pTemp[256];
if ( p_menu->n_entries * line_height > p_menu->y2 )
y_start = p_menu->y1 + line_height;
@ -565,7 +564,6 @@ static int get_next_seq_y(menu_t *p_menu, int v, int dy, int cicle)
static void select_next(menu_t *p_menu, int dx, int dy, int cicle)
{
int next;
char buffer[256];
p_menu->cur_sel = get_next_seq_y(p_menu, p_menu->cur_sel, dy, cicle);
next = get_next_seq_y(p_menu, p_menu->cur_sel, dy + 1, cicle);
@ -612,7 +610,6 @@ static void menu_init_internal(menu_t *p_menu, const char *title,
int16_t x1, int16_t y1, int16_t x2, int16_t y2)
{
int submenu;
int i;
int j;
memset(p_menu, 0, sizeof(menu_t));
@ -704,7 +701,6 @@ uint32_t menu_wait_key_press(void)
hats = SDL_JoystickNumHats (joy);
for (i = 0; i < hats; i++) {
Uint8 v = SDL_JoystickGetHat (joy, i);
int x = 0, y = 0;
if (v & SDL_HAT_UP)
keys |= KEY_UP;
@ -796,7 +792,7 @@ uint32_t menu_wait_key_press(void)
if (keys != 0)
break;
SDL_Delay(100);
SDL_Delay(20);
}
return keys;
}
@ -1050,7 +1046,7 @@ void menu_init(SDL_Surface *screen)
menu_font_alt16 = read_font(FONT_ALT_PATH,16);
real_screen = screen;
virtkbd_init(screen, menu_font_alt16);
VirtualKeyboard_init(screen);
is_inited = 1;
}

View File

@ -23,6 +23,7 @@
#define SMBFILENAME "/uae/uaerc.smb"
#define USERFILENAME "/uae/uaerc.user"
#define SAVEDFILENAME "/uae/uaerc.saved"
#define KBDIMAGE "/apps/uae/images/kb_amiga.png"
#define DEFPRTNAME "lpr"
#define DEFSERNAME "/dev/ttyS1"

View File

@ -74,7 +74,6 @@ floppy3soundext=/uae/wave/
floppy_speed=100
# Sound configuration
sound_output=normal
sound_frequency=32000