frodo-wii/virtual_keyboard.hh

104 lines
1.8 KiB
C++
Raw Normal View History

/*********************************************************************
*
* Copyright (C) 2009, Simon Kagstrom
*
* Filename: VirtualKeyboard.c
* Author: Simon Kagstrom <simon.kagstrom@gmail.com>
* Description: A virtual keyboard
*
* $Id$
*
********************************************************************/
#ifndef __VIRTUAL_KEYBORD_HH__
#define __VIRTUAL_KEYBORD_HH__
#include <SDL.h>
#include "widget.hh"
2009-12-20 10:31:46 +01:00
#include "gui_view.hh"
#include "font.hh"
struct virtkey;
class KeyboardListener
{
public:
~KeyboardListener();
/* Each key is a string */
virtual void keyCallback(bool shift, const char *str)
{
}
virtual void stringCallback(const char *str)
{
}
};
2009-12-20 10:31:46 +01:00
class VirtualKeyboard : public GuiView
{
public:
VirtualKeyboard(Font *font);
void registerListener(KeyboardListener *kl);
void unregisterListener(KeyboardListener *kl);
/* Conversions */
const char *keycodeToString(int kc);
const char keycodeToChar(int kc);
int charToKeycode(char c);
int stringToKeycode(const char *str);
struct virtkey eventToVirtkey(event_t ev);
void activate();
void setFont(Font *font)
{
this->font = font;
}
2009-12-26 10:07:18 +01:00
void deactivate();
2009-12-19 20:17:25 +01:00
bool isActive()
{
return this->is_active;
}
2009-12-20 10:31:46 +01:00
virtual void updateTheme();
void draw(SDL_Surface *where);
void runLogic();
void draw(SDL_Surface *where, int x, int y, int w, int h);
void pushEvent(SDL_Event *ev);
/* Singleton object */
static VirtualKeyboard *kbd;
private:
KeyboardListener *listeners[8];
void selectNext(int dx, int dy);
void toggleShift();
void pushKey(struct virtkey *vk);
void done();
void flushListeners();
Font *font;
int sel_x;
int sel_y;
bool shift_on;
bool is_active;
struct virtkey *buf;
unsigned buf_head;
size_t buf_len;
};
#endif /* __VIRTUAL_KEYBORD_HH__ */