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