mirror of
https://github.com/Oibaf66/frodo-wii.git
synced 2024-11-22 19:39:24 +01:00
97 lines
1.7 KiB
C++
97 lines
1.7 KiB
C++
/*********************************************************************
|
|
*
|
|
* 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"
|
|
#include "gui_view.hh"
|
|
#include "font.hh"
|
|
|
|
struct virtkey;
|
|
|
|
class KeyListener
|
|
{
|
|
public:
|
|
/* Each key is a string */
|
|
virtual void keyCallback(bool shift, const char *str) = 0;
|
|
};
|
|
|
|
class StringListener
|
|
{
|
|
public:
|
|
virtual void stringCallback(const char *str) = 0;
|
|
};
|
|
|
|
class VirtualKeyboard : public GuiView
|
|
{
|
|
public:
|
|
VirtualKeyboard(Font *font);
|
|
|
|
void registerListener(KeyListener *kl);
|
|
void registerListener(StringListener *sl);
|
|
void unregisterListener(KeyListener *kl);
|
|
void unregisterListener(StringListener *sl);
|
|
|
|
/* Conversions */
|
|
const char *keycodeToString(int kc);
|
|
const char keycodeToChar(int kc);
|
|
int charToKeycode(char c);
|
|
int stringToKeycode(const char *str);
|
|
|
|
void activate();
|
|
|
|
void setFont(Font *font)
|
|
{
|
|
this->font = font;
|
|
}
|
|
|
|
void deactivate()
|
|
{
|
|
this->is_active = false;
|
|
}
|
|
|
|
bool isActive()
|
|
{
|
|
return this->is_active;
|
|
}
|
|
|
|
virtual void updateTheme();
|
|
|
|
void draw(SDL_Surface *where);
|
|
|
|
void runLogic();
|
|
|
|
void draw(SDL_Surface *where, int x, int y, int w, int h);
|
|
|
|
/* Singleton object */
|
|
static VirtualKeyboard *kbd;
|
|
private:
|
|
KeyListener *keyListeners[8];
|
|
StringListener *stringListeners[8];
|
|
|
|
void selectNext(int dx, int dy);
|
|
void toggleShift();
|
|
|
|
Font *font;
|
|
int sel_x;
|
|
int sel_y;
|
|
bool shift_on;
|
|
|
|
bool is_active;
|
|
char buf[255];
|
|
unsigned buf_head;
|
|
};
|
|
|
|
#endif /* __VIRTUAL_KEYBORD_HH__ */
|