mirror of
https://github.com/Oibaf66/uae-wii.git
synced 2024-11-22 10:39:19 +01:00
Added a virtual keyboard (not used yet)
This commit is contained in:
parent
ebf3cb8299
commit
aca554cdd8
@ -32,7 +32,7 @@ SRCS := $(filter-out src/compemu_raw_x86.c src/compemu_fpp.c src/compemu_support
|
|||||||
src/readdisk.c src/gengenblitter.c src/scsiemul.c src/tui.c src/linetoscr.c, $(SRCS))
|
src/readdisk.c src/gengenblitter.c src/scsiemul.c src/tui.c src/linetoscr.c, $(SRCS))
|
||||||
|
|
||||||
# Library object files.
|
# Library object files.
|
||||||
OBJS := $(subst $(SRC_DIR),$(OBJ_DIR),$(SRCS:.c=.o))
|
OBJS := $(subst $(SRC_DIR),$(OBJ_DIR),$(SRCS:.c=.o)) $(OBJ_DIR)/guidep/VirtualKeyboard.o
|
||||||
|
|
||||||
# Test source files.
|
# Test source files.
|
||||||
# It can be useful to switch this variable around to select individual tests which are problematic.
|
# It can be useful to switch this variable around to select individual tests which are problematic.
|
||||||
@ -125,11 +125,14 @@ uae-host.elf: $(SYMLINKS) src/target.h src/md-fpp.h src/sysconfig.h $(OBJS)
|
|||||||
@echo Linking $@
|
@echo Linking $@
|
||||||
@-mkdir -p $(dir $@)
|
@-mkdir -p $(dir $@)
|
||||||
g++ -o $@ $(OBJS) $(LDFLAGS)
|
g++ -o $@ $(OBJS) $(LDFLAGS)
|
||||||
#keep elf for debugging
|
|
||||||
#cp $@ /tmp/elf
|
|
||||||
|
|
||||||
# How to compile C file (SDL library).
|
# How to compile C file (SDL library).
|
||||||
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
|
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
|
||||||
@echo Compiling $<
|
@echo Compiling $<
|
||||||
@-mkdir -p $(dir $@)
|
@-mkdir -p $(dir $@)
|
||||||
gcc $(CFLAGS) -c $< -o $@ $(PIPE_TO_SED)
|
gcc $(CFLAGS) -c $< -o $@ $(PIPE_TO_SED)
|
||||||
|
|
||||||
|
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
|
||||||
|
@echo Compiling $<
|
||||||
|
@-mkdir -p $(dir $@)
|
||||||
|
g++ $(CFLAGS) -c $< -o $@ $(PIPE_TO_SED)
|
||||||
|
@ -37,7 +37,7 @@ SRCS := $(filter-out src/compemu_raw_x86.c src/compemu_fpp.c src/compemu_support
|
|||||||
src/readdisk.c src/gengenblitter.c src/scsiemul.c src/tui.c src/linetoscr.c, $(SRCS))
|
src/readdisk.c src/gengenblitter.c src/scsiemul.c src/tui.c src/linetoscr.c, $(SRCS))
|
||||||
|
|
||||||
# Library object files.
|
# Library object files.
|
||||||
OBJS := $(subst $(SRC_DIR),$(OBJ_DIR),$(SRCS:.c=.o))
|
OBJS := $(subst $(SRC_DIR),$(OBJ_DIR),$(SRCS:.c=.o)) $(OBJ_DIR)/guidep/VirtualKeyboard.o
|
||||||
|
|
||||||
# Test source files.
|
# Test source files.
|
||||||
# It can be useful to switch this variable around to select individual tests which are problematic.
|
# It can be useful to switch this variable around to select individual tests which are problematic.
|
||||||
@ -157,3 +157,8 @@ $(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
|
|||||||
@echo Compiling $<
|
@echo Compiling $<
|
||||||
@-mkdir -p $(dir $@)
|
@-mkdir -p $(dir $@)
|
||||||
@powerpc-gekko-gcc $(CFLAGS) -c $< -o $@ $(PIPE_TO_SED)
|
@powerpc-gekko-gcc $(CFLAGS) -c $< -o $@ $(PIPE_TO_SED)
|
||||||
|
|
||||||
|
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
|
||||||
|
@echo Compiling $<
|
||||||
|
@-mkdir -p $(dir $@)
|
||||||
|
@powerpc-gekko-g++ $(CFLAGS) -c $< -o $@ $(PIPE_TO_SED)
|
||||||
|
198
src/gui-sdl/VirtualKeyboard.cpp
Normal file
198
src/gui-sdl/VirtualKeyboard.cpp
Normal file
@ -0,0 +1,198 @@
|
|||||||
|
/*********************************************************************
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009, Simon Kagstrom
|
||||||
|
*
|
||||||
|
* Filename: VirtualKeyboard.c
|
||||||
|
* Author: Simon Kagstrom <simon.kagstrom@gmail.com>
|
||||||
|
* Description: A virtual keyboard
|
||||||
|
*
|
||||||
|
* $Id$
|
||||||
|
*
|
||||||
|
********************************************************************/
|
||||||
|
#include <SDL.h>
|
||||||
|
#include <SDL_ttf.h>
|
||||||
|
|
||||||
|
#include "menu.h"
|
||||||
|
#include "VirtualKeyboard.hh"
|
||||||
|
|
||||||
|
|
||||||
|
struct virtkey;
|
||||||
|
|
||||||
|
class VirtualKeyboard
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
VirtualKeyboard(SDL_Surface *screen, TTF_Font *font);
|
||||||
|
const char* get_key();
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct virtkey *get_key_internal();
|
||||||
|
void draw();
|
||||||
|
void select_next(int dx, int dy);
|
||||||
|
void toggle_shift();
|
||||||
|
|
||||||
|
SDL_Surface *screen;
|
||||||
|
TTF_Font *font;
|
||||||
|
int sel_x;
|
||||||
|
int sel_y;
|
||||||
|
|
||||||
|
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 D(name) \
|
||||||
|
{ name, "", true }
|
||||||
|
#define KNL() \
|
||||||
|
{ NULL, NULL, false }
|
||||||
|
|
||||||
|
#define KEY_COLS 14
|
||||||
|
#define KEY_ROWS 6
|
||||||
|
|
||||||
|
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"),KNL(), 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("R"), K("T"), K("Y"), K("U"), K("I"), K("O"), K("P"),N("[", "LEFTBRACKET"),N("]","RIGHTBRACKET"),D("Done"),
|
||||||
|
N("Sft","SHIFT_LEFT"),KNL(), K("A"), K("D"), K("F"), K("G"), K("H"), K("J"), K("K"), K("L"), N(":;", "SEMICOLON"), N("@#", "??"), N("Sft", "SHIFT_RIGHT"),K("Ret"),
|
||||||
|
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("Up", "CURSOR_UP"), N("/", "SLASH"),
|
||||||
|
N("Alt","ALT_LEFT"),KNL(), N("Amg","AMIGA_LEFT"),KNL(),N("space", "SPACE"),KNL(),KNL(),N("Amg","AMIGA_RIGHT"),KNL(),N("Alt","ALT_RIGHT"),KNL(),N("Lft", "CURSOR_LEFT"),N("Dwn", "CURSOR_DOWN"), N("Rgt", "CURSOR_RIGHT")
|
||||||
|
};
|
||||||
|
|
||||||
|
VirtualKeyboard::VirtualKeyboard(SDL_Surface *screen, TTF_Font *font)
|
||||||
|
{
|
||||||
|
this->screen = screen;
|
||||||
|
this->font = font;
|
||||||
|
this->sel_x = 0;
|
||||||
|
this->sel_y = 0;
|
||||||
|
|
||||||
|
memset(this->buf, 0, sizeof(this->buf));
|
||||||
|
}
|
||||||
|
|
||||||
|
void VirtualKeyboard::draw()
|
||||||
|
{
|
||||||
|
int screen_w = this->screen->w;
|
||||||
|
int screen_h = this->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;
|
||||||
|
SDL_Rect bg_rect = {border_x, border_y,
|
||||||
|
key_w * KEY_COLS, key_h * KEY_ROWS};
|
||||||
|
|
||||||
|
SDL_FillRect(this->screen, &bg_rect,
|
||||||
|
SDL_MapRGB(screen->format, 0x00, 0x80, 0x80));
|
||||||
|
|
||||||
|
for (int y = 0; y < KEY_ROWS; y++ )
|
||||||
|
{
|
||||||
|
for (int x = 0; x < KEY_COLS; x++ )
|
||||||
|
{
|
||||||
|
int which = y * KEY_COLS + x;
|
||||||
|
virtkey_t key = keys[which];
|
||||||
|
int r = 255, g = 255, b = 255;
|
||||||
|
const char *what = key.name;
|
||||||
|
|
||||||
|
/* Skip empty positions */
|
||||||
|
if (key.name == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if ( key.is_done )
|
||||||
|
r = 0;
|
||||||
|
if ( (x == this->sel_x && y == this->sel_y))
|
||||||
|
b = 0;
|
||||||
|
|
||||||
|
menu_print_font(this->screen, r, g, b,
|
||||||
|
x * key_w + border_x, y * key_h + border_y,
|
||||||
|
what);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VirtualKeyboard::select_next(int dx, int dy)
|
||||||
|
{
|
||||||
|
int next_x = (this->sel_x + dx) % KEY_COLS;
|
||||||
|
int next_y = (this->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;
|
||||||
|
this->sel_x = next_x;
|
||||||
|
this->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 */
|
||||||
|
this->select_next(-1, 0);
|
||||||
|
else
|
||||||
|
this->select_next(dx, dy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct virtkey *VirtualKeyboard::get_key_internal()
|
||||||
|
{
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
uint32_t k;
|
||||||
|
|
||||||
|
this->draw();
|
||||||
|
SDL_Flip(this->screen);
|
||||||
|
|
||||||
|
k = menu_wait_key_press();
|
||||||
|
|
||||||
|
if (k & KEY_UP)
|
||||||
|
this->select_next(0, -1);
|
||||||
|
else if (k & KEY_DOWN)
|
||||||
|
this->select_next(0, 1);
|
||||||
|
else if (k & KEY_LEFT)
|
||||||
|
this->select_next(-1, 0);
|
||||||
|
else if (k & KEY_RIGHT)
|
||||||
|
this->select_next(1, 0);
|
||||||
|
else if (k & KEY_ESCAPE)
|
||||||
|
return NULL;
|
||||||
|
else if (k & KEY_SELECT)
|
||||||
|
{
|
||||||
|
virtkey_t *key = &keys[ this->sel_y * KEY_COLS + this->sel_x ];
|
||||||
|
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* VirtualKeyboard::get_key()
|
||||||
|
{
|
||||||
|
virtkey_t *key;
|
||||||
|
|
||||||
|
SDL_FillRect(this->screen, 0, SDL_MapRGB(screen->format, 0x00, 0x80, 0x80));
|
||||||
|
|
||||||
|
key = this->get_key_internal();
|
||||||
|
if (key == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return key->ev_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* C interface */
|
||||||
|
static VirtualKeyboard *virtual_keyboard;
|
||||||
|
void virtkbd_init(SDL_Surface *surf, TTF_Font *fnt)
|
||||||
|
{
|
||||||
|
virtual_keyboard = new VirtualKeyboard(surf, fnt);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *virtkbd_get_key(void)
|
||||||
|
{
|
||||||
|
return virtual_keyboard->get_key();
|
||||||
|
}
|
24
src/gui-sdl/VirtualKeyboard.hh
Normal file
24
src/gui-sdl/VirtualKeyboard.hh
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/*********************************************************************
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009, Simon Kagstrom
|
||||||
|
*
|
||||||
|
* Filename: VirtualKeyboard.c
|
||||||
|
* Author: Simon Kagstrom <simon.kagstrom@gmail.com>
|
||||||
|
* Description: A virtual keyboard
|
||||||
|
*
|
||||||
|
* $Id$
|
||||||
|
*
|
||||||
|
********************************************************************/
|
||||||
|
#include <SDL.h>
|
||||||
|
#include <SDL_ttf.h>
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern void virtkbd_init(SDL_Surface *surf, TTF_Font *fnt);
|
||||||
|
extern const char *virtkbd_get_key(void);
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
};
|
||||||
|
#endif
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include "sysconfig.h"
|
#include "sysconfig.h"
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
|
#include "VirtualKeyboard.hh"
|
||||||
|
|
||||||
#define FULL_DISPLAY_X 640
|
#define FULL_DISPLAY_X 640
|
||||||
#define FULL_DISPLAY_Y 480
|
#define FULL_DISPLAY_Y 480
|
||||||
@ -992,6 +993,7 @@ void menu_init(SDL_Surface *screen)
|
|||||||
menu_font64 = read_font(FONT_ALT_PATH);
|
menu_font64 = read_font(FONT_ALT_PATH);
|
||||||
|
|
||||||
real_screen = screen;
|
real_screen = screen;
|
||||||
|
virtkbd_init(screen, menu_font64);
|
||||||
is_inited = 1;
|
is_inited = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,10 @@
|
|||||||
#include <SDL_ttf.h>
|
#include <SDL_ttf.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#define KEY_UP 1
|
#define KEY_UP 1
|
||||||
#define KEY_DOWN 2
|
#define KEY_DOWN 2
|
||||||
#define KEY_LEFT 4
|
#define KEY_LEFT 4
|
||||||
@ -46,4 +50,9 @@ void menu_init(SDL_Surface *screen);
|
|||||||
|
|
||||||
int menu_is_inited(void);
|
int menu_is_inited(void);
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* !__MENU_H__ */
|
#endif /* !__MENU_H__ */
|
||||||
|
Loading…
Reference in New Issue
Block a user