Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
43 KB
Referenced Files
None
Subscribers
None
diff --git a/util/init.cpp b/util/init.cpp
index 17533fc3..ab4e8b86 100644
--- a/util/init.cpp
+++ b/util/init.cpp
@@ -1,439 +1,438 @@
#ifdef USE_ALLEGRO
#include <allegro.h>
#ifdef ALLEGRO_WINDOWS
#include <winalleg.h>
#endif
#endif
#ifdef USE_SDL
#include <SDL.h>
#endif
#ifndef WINDOWS
#include <signal.h>
#include <string.h>
#endif
#ifdef LINUX
#include <execinfo.h>
#endif
/* don't be a boring tuna */
// #warning you are ugly
#include "globals.h"
#include "init.h"
#include "network/network.h"
#include "util/thread.h"
#include <time.h>
#include <ostream>
#include "util/dumb/include/dumb.h"
#ifdef USE_ALLEGRO
#include "util/dumb/include/aldumb.h"
#include "util/loadpng/loadpng.h"
#include "util/gif/algif.h"
#endif
#include "util/bitmap.h"
#include "util/funcs.h"
#include "util/file-system.h"
#include "util/font.h"
#include "util/sound.h"
#include "configuration.h"
#include "script/script.h"
#include "util/music.h"
#include "util/loading.h"
#ifdef WII
#include <fat.h>
#endif
using namespace std;
volatile int Global::speed_counter = 0;
/* enough seconds for 136 years */
volatile unsigned int Global::second_counter = 0;
/* the original engine was running at 90 ticks per second, but we dont
* need to render that fast, so TICS_PER_SECOND is really fps and
* LOGIC_MULTIPLIER will be used to adjust the speed counter to its
* original value.
*/
const int Global::TICS_PER_SECOND = 40;
const double Global::LOGIC_MULTIPLIER = (double) 90 / (double) Global::TICS_PER_SECOND;
#ifdef USE_ALLEGRO
const int Global::WINDOWED = GFX_AUTODETECT_WINDOWED;
const int Global::FULLSCREEN = GFX_AUTODETECT_FULLSCREEN;
#else
/* FIXME: use enums here or something */
const int Global::WINDOWED = 0;
const int Global::FULLSCREEN = 1;
#endif
/* game counter, controls FPS */
static void inc_speed_counter(){
/* probably put input polling here, InputManager::poll() */
Global::speed_counter += 1;
}
#ifdef USE_ALLEGRO
END_OF_FUNCTION( inc_speed_counter )
#endif
/* if you need to count seconds for some reason.. */
static void inc_second_counter() {
Global::second_counter += 1;
}
#ifdef USE_ALLEGRO
END_OF_FUNCTION( inc_second_counter )
#endif
#if !defined(WINDOWS) && !defined(WII) && !defined(MINPSPW) && !defined(PS3) && !defined(NDS)
#ifdef LINUX
static void print_stack_trace(){
/* use addr2line on these addresses to get a filename and line number */
void *trace[128];
int frames = backtrace(trace, 128);
printf("Stack trace\n");
for (int i = 0; i < frames; i++){
printf(" %p\n", trace[i]);
}
}
#endif
static void handleSigSegV(int i, siginfo_t * sig, void * data){
const char * message = "Bug! Caught a memory violation. Shutting down..\n";
int dont_care = write(1, message, 48);
dont_care = dont_care;
#ifdef LINUX
print_stack_trace();
#endif
// Global::shutdown_message = "Bug! Caught a memory violation. Shutting down..";
Bitmap::setGfxModeText();
#ifdef USE_ALLEGRO
allegro_exit();
#endif
#ifdef USE_SDL
SDL_Quit();
#endif
/* write to a log file or something because sigsegv shouldn't
* normally happen.
*/
exit(1);
}
#else
#endif
/* catch a socket being closed prematurely on unix */
#if !defined(WINDOWS) && !defined(WII) && !defined(MINPSPW) && !defined(PS3) && !defined(NDS)
static void handleSigPipe( int i, siginfo_t * sig, void * data ){
}
/*
static void handleSigUsr1( int i, siginfo_t * sig, void * data ){
pthread_exit( NULL );
}
*/
#endif
static void registerSignals(){
#if !defined(WINDOWS) && !defined(WII) && !defined(MINPSPW) && !defined(PS3) && !defined(NDS)
struct sigaction action;
memset( &action, 0, sizeof(struct sigaction) );
action.sa_sigaction = handleSigPipe;
sigaction( SIGPIPE, &action, NULL );
memset( &action, 0, sizeof(struct sigaction) );
action.sa_sigaction = handleSigSegV;
sigaction( SIGSEGV, &action, NULL );
/*
action.sa_sigaction = handleSigUsr1;
sigaction( SIGUSR1, &action, NULL );
*/
#endif
}
/* should probably call the janitor here or something */
static void close_paintown(){
Music::pause();
Bitmap::setGfxModeText();
#ifdef USE_ALLEGRO
allegro_exit();
#endif
exit(0);
}
namespace Global{
extern int do_shutdown;
}
static void close_window(){
/* when do_shutdown is 1 the game will attempt to throw ShutdownException
* wherever it is. If the game is stuck or the code doesn't throw
* ShutdownException then when the user tries to close the window
* twice we just forcifully shutdown.
*/
Global::do_shutdown += 1;
if (Global::do_shutdown == 2){
close_paintown();
}
}
#ifdef USE_ALLEGRO
END_OF_FUNCTION(close_window)
#endif
#ifdef USE_ALLEGRO
static void initSystem(ostream & out){
out << "Allegro version: " << ALLEGRO_VERSION_STR << endl;
out << "Allegro init: " <<allegro_init()<<endl;
out << "Install timer: " <<install_timer()<<endl;
/* png */
loadpng_init();
algif_init();
out<<"Install keyboard: "<<install_keyboard()<<endl;
/* do we need the mouse?? */
// out<<"Install mouse: "<<install_mouse()<<endl;
out<<"Install joystick: "<<install_joystick(JOY_TYPE_AUTODETECT)<<endl;
/* 16 bit color depth */
set_color_depth(16);
LOCK_VARIABLE( speed_counter );
LOCK_VARIABLE( second_counter );
LOCK_FUNCTION( (void *)inc_speed_counter );
LOCK_FUNCTION( (void *)inc_second_counter );
/* set up the timers */
out<<"Install game timer: "<< install_int_ex(inc_speed_counter, BPS_TO_TIMER(Global::TICS_PER_SECOND))<<endl;
out<<"Install second timer: "<<install_int_ex(inc_second_counter, BPS_TO_TIMER(1))<<endl;
/* keep running in the background */
set_display_switch_mode(SWITCH_BACKGROUND);
/* close window when the X is pressed */
LOCK_FUNCTION(close_window);
set_close_button_callback(close_window);
}
#endif
#ifdef USE_SDL
// static pthread_t events;
struct TimerInfo{
TimerInfo(void (*x)(), int y):
tick(x), frequency(y){}
void (*tick)();
int frequency;
};
static void * do_timer(void * arg){
TimerInfo info = *(TimerInfo *) arg;
uint32_t delay = (uint32_t)(1000.0 / (double) info.frequency);
/* assuming SDL_GetTicks() starts at 0, this should last for about 50 days
* before overflowing. overflow should work out fine. Assuming activate occurs
* when the difference between now and ticks is at least 6, the following will happen.
* ticks now now-ticks
* 4294967294 4294967294 0
* 4294967294 4294967295 1
* 4294967294 0 2
* 4294967294 1 3
* 4294967294 2 4
* 4294967294 3 5
* 4294967294 4 6
* Activate
* 3 5 2
* 3 6 3
* 3 7 4
* 3 8 5
* 3 9 6
* Activate
*
* Can 'now' ever be much larger than 'ticks' due to overflow?
* It doesn't seem like it.
*/
uint32_t ticks = SDL_GetTicks();
/* TODO: pass in some variable that tells this loop to quit */
while (true){
uint32_t now = SDL_GetTicks();
while (now - ticks >= delay){
// Global::debug(0) << "Tick!" << endl;
info.tick();
ticks += delay;
}
SDL_Delay(1);
}
delete (TimerInfo *) arg;
return NULL;
}
static Util::Thread::Id start_timer(void (*func)(), int frequency){
TimerInfo * speed = new TimerInfo(func, frequency);
/*
speed.tick = func;
speed.frequency = frequency;
*/
Util::Thread::Id thread;
Util::Thread::createThread(&thread, NULL, (Util::Thread::ThreadFunction) do_timer, (void*) speed);
return thread;
}
#if 0
static void * handleEvents(void * arg){
bool done = false;
while (!done){
SDL_Event event;
int ok = SDL_WaitEvent(&event);
if (ok){
switch (event.type){
case SDL_QUIT : {
done = true;
close_window();
break;
}
default : {
// Global::debug(0) << "Ignoring SDL event " << event.type << endl;
break;
}
}
}
}
return NULL;
}
#endif
/*
static void doSDLQuit(){
SDL_Event quit;
quit.type = SDL_QUIT;
SDL_PushEvent(&quit);
Global::debug(0) << "Waiting for SDL event handler to finish" << endl;
pthread_join(events, NULL);
SDL_Quit();
}
*/
static void initSystem(ostream & out){
out << "SDL Init: ";
int ok = SDL_Init(SDL_INIT_VIDEO |
SDL_INIT_AUDIO |
SDL_INIT_TIMER |
SDL_INIT_JOYSTICK |
SDL_INIT_NOPARACHUTE);
if (ok == 0){
out << "Ok" << endl;
} else {
out << "Failed (" << ok << ") - " << SDL_GetError() << endl;
exit(ok);
}
/* Just do SDL thread init
#ifdef MINPSPW
pthread_init();
#endif
*/
start_timer(inc_speed_counter, Global::TICS_PER_SECOND);
start_timer(inc_second_counter, 1);
try{
SDL_Surface * icon = SDL_LoadBMP(Filesystem::find(Filesystem::RelativePath("menu/icon.bmp")).path().c_str());
if (icon != NULL){
SDL_WM_SetIcon(icon, NULL);
}
} catch (const Filesystem::NotFound & failed){
Global::debug(0) << "Could not find window icon: " << failed.getTrace() << endl;
}
SDL_WM_SetCaption("Paintown", NULL);
SDL_EnableUNICODE(1);
SDL_JoystickEventState(1);
- SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
atexit(SDL_Quit);
// atexit(doSDLQuit);
}
#endif
bool Global::init(int gfx){
ostream & out = Global::debug( 0 );
out << "-- BEGIN init --" << endl;
out << "Data path is " << Util::getDataPath2().path() << endl;
out << "Paintown version " << Global::getVersionString() << endl;
out << "Build date " << __DATE__ << " " << __TIME__ << endl;
#ifdef WII
fatInitDefault();
#endif
/* do implementation specific setup */
initSystem(out);
dumb_register_stdfiles();
Sound::initialize();
Bitmap::SCALE_X = GFX_X;
Bitmap::SCALE_Y = GFX_Y;
Configuration::loadConfigurations();
const int sx = Configuration::getScreenWidth();
const int sy = Configuration::getScreenHeight();
if (gfx == -1){
gfx = Configuration::getFullscreen() ? Global::FULLSCREEN : Global::WINDOWED;
} else {
Configuration::setFullscreen(gfx == Global::FULLSCREEN);
}
/* set up the screen */
int gfxCode = Bitmap::setGraphicsMode(gfx, sx, sy);
if (gfxCode == 0){
out << "Set graphics mode: Ok" << endl;
} else {
out << "Set graphics mode: Failed! (" << gfxCode << ")" << endl;
return false;
}
/* music */
atexit(&dumb_exit);
out << "Initialize random number generator" << endl;
/* initialize random number generator */
srand(time(NULL));
registerSignals();
#ifdef HAVE_NETWORKING
out << "Initialize network" << endl;
Network::init();
atexit(Network::closeAll);
#endif
/* this mutex is used to show the loading screen while the game loads */
// Util::Thread::initializeLock(&Loader::loading_screen_mutex);
out << "-- END init --" << endl;
/*
const Font & font = Font::getDefaultFont();
// font.setSize(30, 30);
Bitmap temp(font.textLength("Loading") + 1, font.getHeight("Loading") + 1);
font.printf(0, 0, Bitmap::makeColor(255, 255, 255), temp, "Loading", 0);
temp.BlitToScreen(sx / 2, sy / 2);
*/
Bitmap white(sx, sy);
white.fill(Bitmap::makeColor(255, 255, 255));
white.BlitToScreen();
return true;
}
diff --git a/util/input/allegro/keyboard.cpp b/util/input/allegro/keyboard.cpp
index 5ac4dbe3..aa4202e2 100644
--- a/util/input/allegro/keyboard.cpp
+++ b/util/input/allegro/keyboard.cpp
@@ -1,317 +1,326 @@
#include <allegro.h>
#ifdef WINDOWS
#include <winalleg.h>
#endif
#include "../keyboard.h"
#include "util/thread.h"
#include "util/funcs.h"
#include "globals.h"
#include <iostream>
#include <vector>
#include <map>
using namespace std;
const int Keyboard::Key_A = ::KEY_A;
const int Keyboard::Key_B = ::KEY_B;
const int Keyboard::Key_C = ::KEY_C;
const int Keyboard::Key_D = ::KEY_D;
const int Keyboard::Key_E = ::KEY_E;
const int Keyboard::Key_F = ::KEY_F;
const int Keyboard::Key_G = ::KEY_G;
const int Keyboard::Key_H = ::KEY_H;
const int Keyboard::Key_I = ::KEY_I;
const int Keyboard::Key_J = ::KEY_J;
const int Keyboard::Key_K = ::KEY_K;
const int Keyboard::Key_L = ::KEY_L;
const int Keyboard::Key_M = ::KEY_M;
const int Keyboard::Key_N = ::KEY_N;
const int Keyboard::Key_O = ::KEY_O;
const int Keyboard::Key_P = ::KEY_P;
const int Keyboard::Key_Q = ::KEY_Q;
const int Keyboard::Key_R = ::KEY_R;
const int Keyboard::Key_S = ::KEY_S;
const int Keyboard::Key_T = ::KEY_T;
const int Keyboard::Key_U = ::KEY_U;
const int Keyboard::Key_V = ::KEY_V;
const int Keyboard::Key_W = ::KEY_W;
const int Keyboard::Key_X = ::KEY_X;
const int Keyboard::Key_Y = ::KEY_Y;
const int Keyboard::Key_Z = ::KEY_Z;
const int Keyboard::Key_0 = ::KEY_0;
const int Keyboard::Key_1 = ::KEY_1;
const int Keyboard::Key_2 = ::KEY_2;
const int Keyboard::Key_3 = ::KEY_3;
const int Keyboard::Key_4 = ::KEY_4;
const int Keyboard::Key_5 = ::KEY_5;
const int Keyboard::Key_6 = ::KEY_6;
const int Keyboard::Key_7 = ::KEY_7;
const int Keyboard::Key_8 = ::KEY_8;
const int Keyboard::Key_9 = ::KEY_9;
const int Keyboard::Key_0_PAD = ::KEY_0_PAD;
const int Keyboard::Key_1_PAD = ::KEY_1_PAD;
const int Keyboard::Key_2_PAD = ::KEY_2_PAD;
const int Keyboard::Key_3_PAD = ::KEY_3_PAD;
const int Keyboard::Key_4_PAD = ::KEY_4_PAD;
const int Keyboard::Key_5_PAD = ::KEY_5_PAD;
const int Keyboard::Key_6_PAD = ::KEY_6_PAD;
const int Keyboard::Key_7_PAD = ::KEY_7_PAD;
const int Keyboard::Key_8_PAD = ::KEY_8_PAD;
const int Keyboard::Key_9_PAD = ::KEY_9_PAD;
const int Keyboard::Key_F1 = ::KEY_F1;
const int Keyboard::Key_F2 = ::KEY_F2;
const int Keyboard::Key_F3 = ::KEY_F3;
const int Keyboard::Key_F4 = ::KEY_F4;
const int Keyboard::Key_F5 = ::KEY_F5;
const int Keyboard::Key_F6 = ::KEY_F6;
const int Keyboard::Key_F7 = ::KEY_F7;
const int Keyboard::Key_F8 = ::KEY_F8;
const int Keyboard::Key_F9 = ::KEY_F9;
const int Keyboard::Key_F10 = ::KEY_F10;
const int Keyboard::Key_F11 = ::KEY_F11;
const int Keyboard::Key_F12 = ::KEY_F12;
const int Keyboard::Key_ESC = ::KEY_ESC;
const int Keyboard::Key_TILDE = ::KEY_TILDE;
const int Keyboard::Key_MINUS = ::KEY_MINUS;
const int Keyboard::Key_EQUALS = ::KEY_EQUALS;
const int Keyboard::Key_BACKSPACE = ::KEY_BACKSPACE;
const int Keyboard::Key_TAB = ::KEY_TAB;
const int Keyboard::Key_OPENBRACE = ::KEY_OPENBRACE;
const int Keyboard::Key_CLOSEBRACE = ::KEY_CLOSEBRACE;
const int Keyboard::Key_ENTER = ::KEY_ENTER;
const int Keyboard::Key_COLON = ::KEY_COLON;
const int Keyboard::Key_QUOTE = ::KEY_QUOTE;
const int Keyboard::Key_BACKSLASH = ::KEY_BACKSLASH;
const int Keyboard::Key_BACKSLASH2 = ::KEY_BACKSLASH2;
const int Keyboard::Key_COMMA = ::KEY_COMMA;
const int Keyboard::Key_STOP = ::KEY_STOP;
const int Keyboard::Key_SLASH = ::KEY_SLASH;
const int Keyboard::Key_SPACE = ::KEY_SPACE;
const int Keyboard::Key_INSERT = ::KEY_INSERT;
const int Keyboard::Key_DEL = ::KEY_DEL;
const int Keyboard::Key_HOME = ::KEY_HOME;
const int Keyboard::Key_END = ::KEY_END;
const int Keyboard::Key_PGUP = ::KEY_PGUP;
const int Keyboard::Key_PGDN = ::KEY_PGDN;
const int Keyboard::Key_LEFT = ::KEY_LEFT;
const int Keyboard::Key_RIGHT = ::KEY_RIGHT;
const int Keyboard::Key_UP = ::KEY_UP;
const int Keyboard::Key_DOWN = ::KEY_DOWN;
const int Keyboard::Key_SLASH_PAD = ::KEY_SLASH_PAD;
const int Keyboard::Key_ASTERISK = ::KEY_ASTERISK;
const int Keyboard::Key_MINUS_PAD = ::KEY_MINUS_PAD;
const int Keyboard::Key_PLUS_PAD = ::KEY_PLUS_PAD;
const int Keyboard::Key_DEL_PAD = ::KEY_DEL_PAD;
const int Keyboard::Key_ENTER_PAD = ::KEY_ENTER_PAD;
const int Keyboard::Key_PRTSCR = ::KEY_PRTSCR;
const int Keyboard::Key_PAUSE = ::KEY_PAUSE;
const int Keyboard::Key_ABNT_C1 = ::KEY_ABNT_C1;
const int Keyboard::Key_YEN = ::KEY_YEN;
const int Keyboard::Key_KANA = ::KEY_KANA;
const int Keyboard::Key_CONVERT = ::KEY_CONVERT;
const int Keyboard::Key_NOCONVERT = ::KEY_NOCONVERT;
const int Keyboard::Key_AT = ::KEY_AT;
const int Keyboard::Key_CIRCUMFLEX = ::KEY_CIRCUMFLEX;
const int Keyboard::Key_COLON2 = ::KEY_COLON2;
const int Keyboard::Key_KANJI = ::KEY_KANJI;
const int Keyboard::Key_EQUALS_PAD = ::KEY_EQUALS_PAD;
const int Keyboard::Key_BACKQUOTE = ::KEY_BACKQUOTE;
const int Keyboard::Key_SEMICOLON = ::KEY_SEMICOLON;
const int Keyboard::Key_COMMAND = ::KEY_COMMAND;
/*
const int Keyboard::Key_UNKNOWN1 = ::KEY_UNKNOWN1;
const int Keyboard::Key_UNKNOWN2 = ::KEY_UNKNOWN2;
const int Keyboard::Key_UNKNOWN3 = ::KEY_UNKNOWN3;
const int Keyboard::Key_UNKNOWN4 = ::KEY_UNKNOWN4;
const int Keyboard::Key_UNKNOWN5 = ::KEY_UNKNOWN5;
const int Keyboard::Key_UNKNOWN6 = ::KEY_UNKNOWN6;
const int Keyboard::Key_UNKNOWN7 = ::KEY_UNKNOWN7;
const int Keyboard::Key_UNKNOWN8 = ::KEY_UNKNOWN8;
*/
const int Keyboard::Key_MODIFIERS = ::KEY_MODIFIERS;
const int Keyboard::Key_LSHIFT = ::KEY_LSHIFT;
const int Keyboard::Key_RSHIFT = ::KEY_RSHIFT;
const int Keyboard::Key_LCONTROL = ::KEY_LCONTROL;
const int Keyboard::Key_RCONTROL = ::KEY_RCONTROL;
const int Keyboard::Key_ALT = ::KEY_ALT;
const int Keyboard::Key_ALTGR = ::KEY_ALTGR;
const int Keyboard::Key_LWIN = ::KEY_LWIN;
const int Keyboard::Key_RWIN = ::KEY_RWIN;
const int Keyboard::Key_MENU = ::KEY_MENU;
const int Keyboard::Key_SCRLOCK = ::KEY_SCRLOCK;
const int Keyboard::Key_NUMLOCK = ::KEY_NUMLOCK;
const int Keyboard::Key_CAPSLOCK = ::KEY_CAPSLOCK;
static Util::Thread::Lock keyboardData;
static vector<Keyboard::KeyData> stolenKeys;
static int steal_keys(int unicode, int * scancode){
// Global::debug(0) << "Steal key " << unicode << " " << *scancode << endl;
Util::Thread::acquireLock(&keyboardData);
stolenKeys.push_back(Keyboard::KeyData(*scancode, unicode, true));
Util::Thread::releaseLock(&keyboardData);
return unicode;
}
static map<int, bool> stolenPresses;
static void steal_scancode(int scancode){
Util::Thread::acquireLock(&keyboardData);
if (scancode & 0x80){
stolenPresses[scancode & 0x7f] = false;
} else {
stolenPresses[scancode & 0x7f] = true;
}
Util::Thread::releaseLock(&keyboardData);
}
Keyboard::Keyboard():
enableBuffer(false){
/*
for ( int q = 0; q < KEY_MAX; q++ ){
my_keys[ q ] = 0;
}
*/
- setAllDelay( 0 );
+ setAllDelay(0);
Util::Thread::initializeLock(&keyboardData);
::keyboard_ucallback = steal_keys;
::keyboard_lowlevel_callback = steal_scancode;
}
/* KEY_MAX is defined in allegro at
* allegro/include/allegro/keyboard.h
*/
void Keyboard::poll(){
buffer.clear();
// keyState.clear();
Util::Thread::acquireLock(&keyboardData);
for (vector<KeyData>::iterator it = stolenKeys.begin(); it != stolenKeys.end(); it++){
const KeyData & data = *it;
keyState[data.key] = data;
}
stolenKeys.clear();
for (map<int, bool>::iterator it = stolenPresses.begin(); it != stolenPresses.end(); it++){
int key = it->first;
bool pressed = it->second;
keyState[key].enabled = pressed;
if (pressed){
press(key, keyState[key].unicode);
} else {
release(key);
}
}
stolenPresses.clear();
Util::Thread::releaseLock(&keyboardData);
/*
::poll_keyboard();
keyState.clear();
while (::keypressed()){
int unicode;
int key = ::ureadkey(&unicode);
keyState[key] = KeyData(key, unicode, true);
}
*/
#if 0
for ( int q = 0; q < KEY_MAX; q++ ){
// my_keys[ q ] = key[ q ];
if ( key[ q ] ){
/* my_keys[ q ] becomes negative so that the key
* can be pressed the first time without having
* to wait for a delay
*/
if ( my_keys[ q ] <= 0 ){
my_keys[ q ] -= 1;
} else {
my_keys[ q ] += 1;
}
// printf( "Key %d = %d\n", q, my_keys[ q ] );
} else {
my_keys[ q ] = 0;
}
}
#endif
}
#if 0
std::vector<Keyboard::KeyData> Keyboard::readData(){
std::vector<Keyboard::KeyData> out;
/* TODO */
return out;
}
std::vector<Keyboard::unicode_t> Keyboard::readText(){
std::vector<Keyboard::unicode_t> out;
/* TODO */
return out;
}
#endif
+void Keyboard::enableKeyRepeat(){
+ /* these numbers come from the allergo source, src/keyboard.c */
+ set_keyboard_rate(250, 33);
+}
+
+void Keyboard::disableKeyRepeat(){
+ set_keyboard_rate(0, 0);
+}
+
void Keyboard::readKeys( vector< int > & all_keys ){
for (std::map<KeyType, KeyData>::iterator it = keyState.begin(); it != keyState.end(); it++){
KeyType key = it->first;
const KeyData & data = it->second;
if (data.enabled){
all_keys.push_back(key);
}
}
/*
for ( map<int,int>::const_iterator it = my_keys.begin(); it != my_keys.end(); it++ ){
const int & key = it->first;
const int & delay = it->second;
if ( delay != 0 ){
Global::debug( 6 ) << "Key " << key << " delay " << delay << " key_delay " << key_delay[ key ] << endl;
}
if ( delay < 0 ){
all_keys.push_back( key );
my_keys[ key ] = 1;
} else if ( delay > key_delay[ key ] ){
all_keys.push_back( key );
my_keys[ key ] = 1;
}
}
*/
}
/*
int Keyboard::readKey(){
return ::readkey() >> 8;
}
*/
void Keyboard::wait(){
clear();
poll();
while ( keypressed() ){
poll();
Util::rest( 1 );
}
}
bool Keyboard::keypressed(){
return ::keypressed();
/*
for ( map<int,int>::const_iterator it = my_keys.begin(); it != my_keys.end(); it++ ){
const int & n = (*it).second;
if ( n < 0 || n > key_delay[ it->first ] ){
return true;
}
}
return false;
*/
}
void Keyboard::clear(){
::clear_keybuf();
buffer.clear();
keyState.clear();
// my_keys.clear();
}
diff --git a/util/input/keyboard.h b/util/input/keyboard.h
index a9ec1735..3fe23c41 100644
--- a/util/input/keyboard.h
+++ b/util/input/keyboard.h
@@ -1,261 +1,264 @@
#ifndef _paintown_keyboard_h
#define _paintown_keyboard_h
#include <map>
#include <vector>
#include <stdint.h>
/* handles allegro key[] array better than keypressed()
* and readkey()
*/
class Keyboard{
private:
Keyboard();
public:
friend class InputManager;
typedef const int KeyType;
typedef uint32_t unicode_t;
struct KeyData{
KeyData():
key(-1),
unicode(-1),
enabled(false){
}
KeyData(int key, unicode_t unicode, bool enabled):
key(key),
unicode(unicode),
enabled(enabled){
}
int key;
/* Converted to a unicode character in UTF-32 */
unicode_t unicode;
/* whether the key is being pressed */
bool enabled;
};
/*
typedef void (*ObserverCallback)(const KeyData & data, void * extra);
struct Observer{
Observer():
callback(NULL),
extra(NULL){
}
Observer(ObserverCallback callback, void * extra):
callback(callback),
extra(extra){
}
ObserverCallback callback;
void * extra;
};
*/
/* poll:
* Put the keys in Allegro's key[] array into our map of int -> bool
*/
void poll();
/* wait for all keys to be released */
void wait();
/* []:
* Extract a boolean value given a key number
*/
#if 0
inline bool operator[] ( const int i ){
/* if the key has been pressed for the first time return true */
if ( my_keys[ i ] < 0 ){
my_keys[ i ] = 1;
return true;
}
bool b = my_keys[ i ] > key_delay[ i ];
if ( b ){
my_keys[ i ] = 1;
}
return b;
}
#endif
/* keypressed:
* Returns true if a key is pressed
*/
bool keypressed();
/* readKeys:
* Store all pressed keys in a user supplied vector
*/
void readKeys(std::vector< int > & all_keys);
void readBufferedKeys(std::vector<int> & keys);
std::vector<KeyData> readData();
std::vector<unicode_t> readText();
// int readKey();
void clear();
+ static void disableKeyRepeat();
+ static void enableKeyRepeat();
+
void setDelay( const int key, const int delay );
void setAllDelay( const int delay );
inline const std::vector<KeyData> & getBufferedKeys() const {
return buffer;
}
static const char * keyToName( int key );
static bool isNumber( int key );
static bool isChar( int key );
static bool isAlpha( int key );
static KeyType Key_A;
static KeyType Key_B;
static KeyType Key_C;
static KeyType Key_D;
static KeyType Key_E;
static KeyType Key_F;
static KeyType Key_G;
static KeyType Key_H;
static KeyType Key_I;
static KeyType Key_J;
static KeyType Key_K;
static KeyType Key_L;
static KeyType Key_M;
static KeyType Key_N;
static KeyType Key_O;
static KeyType Key_P;
static KeyType Key_Q;
static KeyType Key_R;
static KeyType Key_S;
static KeyType Key_T;
static KeyType Key_U;
static KeyType Key_V;
static KeyType Key_W;
static KeyType Key_X;
static KeyType Key_Y;
static KeyType Key_Z;
static KeyType Key_0;
static KeyType Key_1;
static KeyType Key_2;
static KeyType Key_3;
static KeyType Key_4;
static KeyType Key_5;
static KeyType Key_6;
static KeyType Key_7;
static KeyType Key_8;
static KeyType Key_9;
static KeyType Key_0_PAD;
static KeyType Key_1_PAD;
static KeyType Key_2_PAD;
static KeyType Key_3_PAD;
static KeyType Key_4_PAD;
static KeyType Key_5_PAD;
static KeyType Key_6_PAD;
static KeyType Key_7_PAD;
static KeyType Key_8_PAD;
static KeyType Key_9_PAD;
static KeyType Key_F1;
static KeyType Key_F2;
static KeyType Key_F3;
static KeyType Key_F4;
static KeyType Key_F5;
static KeyType Key_F6;
static KeyType Key_F7;
static KeyType Key_F8;
static KeyType Key_F9;
static KeyType Key_F10;
static KeyType Key_F11;
static KeyType Key_F12;
static KeyType Key_ESC;
static KeyType Key_TILDE;
static KeyType Key_MINUS;
static KeyType Key_EQUALS;
static KeyType Key_BACKSPACE;
static KeyType Key_TAB;
static KeyType Key_OPENBRACE;
static KeyType Key_CLOSEBRACE;
static KeyType Key_ENTER;
static KeyType Key_COLON;
static KeyType Key_QUOTE;
static KeyType Key_BACKSLASH;
static KeyType Key_BACKSLASH2;
static KeyType Key_COMMA;
static KeyType Key_STOP;
static KeyType Key_SLASH;
static KeyType Key_SPACE;
static KeyType Key_INSERT;
static KeyType Key_DEL;
static KeyType Key_HOME;
static KeyType Key_END;
static KeyType Key_PGUP;
static KeyType Key_PGDN;
static KeyType Key_LEFT;
static KeyType Key_RIGHT;
static KeyType Key_UP;
static KeyType Key_DOWN;
static KeyType Key_SLASH_PAD;
static KeyType Key_ASTERISK;
static KeyType Key_MINUS_PAD;
static KeyType Key_PLUS_PAD;
static KeyType Key_DEL_PAD;
static KeyType Key_ENTER_PAD;
static KeyType Key_PRTSCR;
static KeyType Key_PAUSE;
static KeyType Key_ABNT_C1;
static KeyType Key_YEN;
static KeyType Key_KANA;
static KeyType Key_CONVERT;
static KeyType Key_NOCONVERT;
static KeyType Key_AT;
static KeyType Key_CIRCUMFLEX;
static KeyType Key_COLON2;
static KeyType Key_KANJI;
static KeyType Key_EQUALS_PAD;
static KeyType Key_BACKQUOTE;
static KeyType Key_SEMICOLON;
static KeyType Key_COMMAND;
/*
static KeyType Key_UNKNOWN1;
static KeyType Key_UNKNOWN2;
static KeyType Key_UNKNOWN3;
static KeyType Key_UNKNOWN4;
static KeyType Key_UNKNOWN5;
static KeyType Key_UNKNOWN6;
static KeyType Key_UNKNOWN7;
static KeyType Key_UNKNOWN8;
*/
static KeyType Key_MODIFIERS;
static KeyType Key_LSHIFT;
static KeyType Key_RSHIFT;
static KeyType Key_LCONTROL;
static KeyType Key_RCONTROL;
static KeyType Key_ALT;
static KeyType Key_ALTGR;
static KeyType Key_LWIN;
static KeyType Key_RWIN;
static KeyType Key_MENU;
static KeyType Key_SCRLOCK;
static KeyType Key_NUMLOCK;
static KeyType Key_CAPSLOCK;
void press(KeyType key, unicode_t unicode);
void release(KeyType key);
/*
virtual void addObserver(ObserverCallback observer, void * extra);
virtual void removeObserver(ObserverCallback observer, void * extra);
*/
protected:
// std::map<int,int> my_keys;
std::map<int,int> key_delay;
// std::vector<Observer> observers;
std::map<KeyType, KeyData> keyState;
std::vector<KeyData> buffer;
bool enableBuffer;
};
#endif
diff --git a/util/input/sdl/keyboard.cpp b/util/input/sdl/keyboard.cpp
index 0d9277fe..7ce4b7f0 100644
--- a/util/input/sdl/keyboard.cpp
+++ b/util/input/sdl/keyboard.cpp
@@ -1,206 +1,214 @@
#include <SDL.h>
#include "../keyboard.h"
#include "../input-manager.h"
#include "util/funcs.h"
#ifdef PS3
Uint8 * getKeyState(int * keys){
return SDL_GetKeyboardState(keys);
}
#else
Uint8 * getKeyState(int * keys){
return SDL_GetKeyState(keys);
}
#endif
Keyboard::Keyboard():
enableBuffer(false){
}
void Keyboard::poll(){
buffer.clear();
SDL_PumpEvents();
}
void Keyboard::wait(){
while (keypressed()){
Util::rest(1);
poll();
}
}
bool Keyboard::keypressed(){
int keys = 0;
Uint8 * state = getKeyState(&keys);
for (int i = 0; i < keys; i++){
if (i != SDLK_NUMLOCK && state[i] == 1){
return true;
}
}
return false;
}
+
+void Keyboard::disableKeyRepeat(){
+ SDL_EnableKeyRepeat(0, 0);
+}
+
+void Keyboard::enableKeyRepeat(){
+ SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
+}
#if 0
void Keyboard::readKeys( std::vector<int> & all_keys ){
int keys = 0;
Uint8 * state = getKeyState(&keys);
/* FIXME: the mapping between SDLK_* and our keyboard values are not 1-1 so
* use a function here that returns the right mapping.
*/
for (int i = 0; i < keys; i++){
if (i != SDLK_NUMLOCK && state[i] == 1){
all_keys.push_back(i);
}
}
}
#endif
void Keyboard::readKeys(std::vector<int> & all_keys){
for (std::map<KeyType, KeyData>::iterator it = keyState.begin(); it != keyState.end(); it++){
KeyType key = it->first;
const KeyData & data = it->second;
if (data.enabled){
all_keys.push_back(key);
}
}
}
/*
int Keyboard::readKey(){
std::vector<int> keys;
do{
readKeys(keys);
Util::rest(1);
InputManager::poll();
poll();
} while (keys.size() == 0);
return keys.front();
}
*/
void Keyboard::clear(){
buffer.clear();
keyState.clear();
}
Keyboard::KeyType Keyboard::Key_A = SDLK_a;
Keyboard::KeyType Keyboard::Key_B = SDLK_b;
Keyboard::KeyType Keyboard::Key_C = SDLK_c;
Keyboard::KeyType Keyboard::Key_D = SDLK_d;
Keyboard::KeyType Keyboard::Key_E = SDLK_e;
Keyboard::KeyType Keyboard::Key_F = SDLK_f;
Keyboard::KeyType Keyboard::Key_G = SDLK_g;
Keyboard::KeyType Keyboard::Key_H = SDLK_h;
Keyboard::KeyType Keyboard::Key_I = SDLK_i;
Keyboard::KeyType Keyboard::Key_J = SDLK_j;
Keyboard::KeyType Keyboard::Key_K = SDLK_k;
Keyboard::KeyType Keyboard::Key_L = SDLK_l;
Keyboard::KeyType Keyboard::Key_M = SDLK_m;
Keyboard::KeyType Keyboard::Key_N = SDLK_n;
Keyboard::KeyType Keyboard::Key_O = SDLK_o;
Keyboard::KeyType Keyboard::Key_P = SDLK_p;
Keyboard::KeyType Keyboard::Key_Q = SDLK_q;
Keyboard::KeyType Keyboard::Key_R = SDLK_r;
Keyboard::KeyType Keyboard::Key_S = SDLK_s;
Keyboard::KeyType Keyboard::Key_T = SDLK_t;
Keyboard::KeyType Keyboard::Key_U = SDLK_u;
Keyboard::KeyType Keyboard::Key_V = SDLK_v;
Keyboard::KeyType Keyboard::Key_W = SDLK_w;
Keyboard::KeyType Keyboard::Key_X = SDLK_x;
Keyboard::KeyType Keyboard::Key_Y = SDLK_y;
Keyboard::KeyType Keyboard::Key_Z = SDLK_z;
Keyboard::KeyType Keyboard::Key_0 = SDLK_0;
Keyboard::KeyType Keyboard::Key_1 = SDLK_1;
Keyboard::KeyType Keyboard::Key_2 = SDLK_2;
Keyboard::KeyType Keyboard::Key_3 = SDLK_3;
Keyboard::KeyType Keyboard::Key_4 = SDLK_4;
Keyboard::KeyType Keyboard::Key_5 = SDLK_5;
Keyboard::KeyType Keyboard::Key_6 = SDLK_6;
Keyboard::KeyType Keyboard::Key_7 = SDLK_7;
Keyboard::KeyType Keyboard::Key_8 = SDLK_8;
Keyboard::KeyType Keyboard::Key_9 = SDLK_9;
Keyboard::KeyType Keyboard::Key_0_PAD = SDLK_KP0;
Keyboard::KeyType Keyboard::Key_1_PAD = SDLK_KP1;
Keyboard::KeyType Keyboard::Key_2_PAD = SDLK_KP2;
Keyboard::KeyType Keyboard::Key_3_PAD = SDLK_KP3;
Keyboard::KeyType Keyboard::Key_4_PAD = SDLK_KP4;
Keyboard::KeyType Keyboard::Key_5_PAD = SDLK_KP5;
Keyboard::KeyType Keyboard::Key_6_PAD = SDLK_KP6;
Keyboard::KeyType Keyboard::Key_7_PAD = SDLK_KP7;
Keyboard::KeyType Keyboard::Key_8_PAD = SDLK_KP8;
Keyboard::KeyType Keyboard::Key_9_PAD = SDLK_KP9;
Keyboard::KeyType Keyboard::Key_F1 = SDLK_F1;
Keyboard::KeyType Keyboard::Key_F2 = SDLK_F2;
Keyboard::KeyType Keyboard::Key_F3 = SDLK_F3;
Keyboard::KeyType Keyboard::Key_F4 = SDLK_F4;
Keyboard::KeyType Keyboard::Key_F5 = SDLK_F5;
Keyboard::KeyType Keyboard::Key_F6 = SDLK_F6;
Keyboard::KeyType Keyboard::Key_F7 = SDLK_F7;
Keyboard::KeyType Keyboard::Key_F8 = SDLK_F8;
Keyboard::KeyType Keyboard::Key_F9 = SDLK_F9;
Keyboard::KeyType Keyboard::Key_F10 = SDLK_F10;
Keyboard::KeyType Keyboard::Key_F11 = SDLK_F11;
Keyboard::KeyType Keyboard::Key_F12 = SDLK_F12;
Keyboard::KeyType Keyboard::Key_ESC = SDLK_ESCAPE;
Keyboard::KeyType Keyboard::Key_TILDE = SDLK_BACKQUOTE;
Keyboard::KeyType Keyboard::Key_MINUS = SDLK_MINUS;
Keyboard::KeyType Keyboard::Key_EQUALS = SDLK_EQUALS;
Keyboard::KeyType Keyboard::Key_BACKSPACE = SDLK_BACKSPACE;
Keyboard::KeyType Keyboard::Key_TAB = SDLK_TAB;
Keyboard::KeyType Keyboard::Key_OPENBRACE = SDLK_LEFTBRACKET;
Keyboard::KeyType Keyboard::Key_CLOSEBRACE = SDLK_RIGHTBRACKET;
Keyboard::KeyType Keyboard::Key_ENTER = SDLK_RETURN;
Keyboard::KeyType Keyboard::Key_COLON = SDLK_COLON;
Keyboard::KeyType Keyboard::Key_QUOTE = SDLK_QUOTEDBL;
Keyboard::KeyType Keyboard::Key_BACKSLASH = SDLK_BACKSLASH;
Keyboard::KeyType Keyboard::Key_BACKSLASH2 = 999; /* FIXME */
Keyboard::KeyType Keyboard::Key_COMMA = SDLK_COMMA;
Keyboard::KeyType Keyboard::Key_STOP = SDLK_PERIOD;
Keyboard::KeyType Keyboard::Key_SLASH = SDLK_SLASH;
Keyboard::KeyType Keyboard::Key_SPACE = SDLK_SPACE;
Keyboard::KeyType Keyboard::Key_INSERT = SDLK_INSERT;
Keyboard::KeyType Keyboard::Key_DEL = SDLK_DELETE;
Keyboard::KeyType Keyboard::Key_HOME = SDLK_HOME;
Keyboard::KeyType Keyboard::Key_END = SDLK_END;
Keyboard::KeyType Keyboard::Key_PGUP = SDLK_PAGEUP;
Keyboard::KeyType Keyboard::Key_PGDN = SDLK_PAGEDOWN;
Keyboard::KeyType Keyboard::Key_LEFT = SDLK_LEFT;
Keyboard::KeyType Keyboard::Key_RIGHT = SDLK_RIGHT;
Keyboard::KeyType Keyboard::Key_UP = SDLK_UP;
Keyboard::KeyType Keyboard::Key_DOWN = SDLK_DOWN;
Keyboard::KeyType Keyboard::Key_SLASH_PAD = SDLK_KP_DIVIDE;
Keyboard::KeyType Keyboard::Key_ASTERISK = SDLK_ASTERISK;
Keyboard::KeyType Keyboard::Key_MINUS_PAD = SDLK_KP_MINUS;
Keyboard::KeyType Keyboard::Key_PLUS_PAD = SDLK_KP_PLUS;
Keyboard::KeyType Keyboard::Key_DEL_PAD = 1000; /* FIXME */
Keyboard::KeyType Keyboard::Key_ENTER_PAD = SDLK_KP_ENTER;
Keyboard::KeyType Keyboard::Key_PRTSCR = SDLK_PRINT;
Keyboard::KeyType Keyboard::Key_PAUSE = SDLK_PAUSE;
Keyboard::KeyType Keyboard::Key_ABNT_C1 = 1001; /* FIXME */
Keyboard::KeyType Keyboard::Key_YEN = 1002;
Keyboard::KeyType Keyboard::Key_KANA = 1003;
Keyboard::KeyType Keyboard::Key_CONVERT = 1004;
Keyboard::KeyType Keyboard::Key_NOCONVERT = 1005;
Keyboard::KeyType Keyboard::Key_AT = SDLK_AT;
Keyboard::KeyType Keyboard::Key_CIRCUMFLEX = SDLK_CARET;
Keyboard::KeyType Keyboard::Key_COLON2 = 1006;
Keyboard::KeyType Keyboard::Key_KANJI = 1007;
Keyboard::KeyType Keyboard::Key_EQUALS_PAD = SDLK_KP_EQUALS;
Keyboard::KeyType Keyboard::Key_BACKQUOTE = 1008;
Keyboard::KeyType Keyboard::Key_SEMICOLON = SDLK_SEMICOLON;
Keyboard::KeyType Keyboard::Key_COMMAND = 1009;
Keyboard::KeyType Keyboard::Key_MODIFIERS = 1010;
Keyboard::KeyType Keyboard::Key_LSHIFT = SDLK_LSHIFT;
Keyboard::KeyType Keyboard::Key_RSHIFT = SDLK_RSHIFT;
Keyboard::KeyType Keyboard::Key_LCONTROL = SDLK_LCTRL;
Keyboard::KeyType Keyboard::Key_RCONTROL = SDLK_RCTRL;
Keyboard::KeyType Keyboard::Key_ALT = SDLK_LALT;
Keyboard::KeyType Keyboard::Key_ALTGR = SDLK_RALT;
Keyboard::KeyType Keyboard::Key_LWIN = SDLK_LMETA;
Keyboard::KeyType Keyboard::Key_RWIN = SDLK_RMETA;
Keyboard::KeyType Keyboard::Key_MENU = SDLK_HELP;
Keyboard::KeyType Keyboard::Key_SCRLOCK = SDLK_SCROLLOCK;
Keyboard::KeyType Keyboard::Key_NUMLOCK = SDLK_NUMLOCK;
Keyboard::KeyType Keyboard::Key_CAPSLOCK = SDLK_CAPSLOCK;
diff --git a/util/input/text-input.cpp b/util/input/text-input.cpp
index 52ba653f..8a1412f6 100644
--- a/util/input/text-input.cpp
+++ b/util/input/text-input.cpp
@@ -1,207 +1,210 @@
#include "input-map.h"
#include "text-input.h"
#include "input-manager.h"
+#include "keyboard.h"
#include <string.h>
#include <sstream>
#include <string>
using namespace std;
static const int Shift = 198;
static const int Control = 199;
static const int Backspace = 200;
TextInput::TextInput(const string & start):
InputMap<unsigned char>(),
blockingKeys(false),
enabled(false),
handle(201){
const int delay = 100;
/*
set(Keyboard::Key_TILDE, delay * 2, false, Toggle);
set(Keyboard::Key_ESC, delay, false, Esc);
set(Keyboard::Key_ENTER, 0, false, Enter);
*/
// set(Keyboard::Key_LCONTROL, 0, false, Control);
set(Keyboard::Key_BACKSPACE, delay, false, Backspace);
/*
set(Keyboard::Key_LSHIFT, 0, false, Shift);
set(Keyboard::Key_RSHIFT, 0, false, Shift);
*/
text.str(start);
text.rdbuf()->pubseekoff(0, ios_base::end, ios_base::out);
text.clear();
}
int TextInput::nextHandle(){
int i = handle;
handle += 1;
return i;
}
void TextInput::addBlockingHandle(int key, callback function, void * data){
int handle = nextHandle();
set(key, 1, true, handle);
callbacks[handle] = Callback(function, data);
}
void TextInput::addHandle(int key, int delay, callback function, void * data){
int handle = nextHandle();
set(key, delay, false, handle);
callbacks[handle] = Callback(function, data);
}
bool TextInput::doInput(){
bool modified = false;
/* TODO: ensure these codes are consistent across platforms. So far
* they seem to work in windows xp and linux (ubuntu)
*/
const Keyboard::unicode_t control_u = 21;
const Keyboard::unicode_t control_w = 23;
if (enabled){
vector<InputEvent> events = InputManager::getEvents(*this);
/* the order of reading input is arbitrary right now. I'm not
* sure it matters what order things are done in, but probably
* a few corner cases exist. When they come up please document them.
*/
for (vector<InputEvent>::iterator it = events.begin(); it != events.end(); it++){
InputEvent event = *it;
if (event.enabled){
if (event.out == Backspace){
backspace();
modified = true;
}
if (callbacks.find(event.out) != callbacks.end()){
Callback & callback = callbacks[event.out];
callback.function(callback.data);
}
if (event.unicode == control_u){
clearInput();
modified = true;
}
if (event.unicode == control_w){
deleteLastWord();
modified = true;
}
/* FIXME: whats the maximum unicode value? */
if (event.unicode >= 32 && event.unicode < 0xffffff){
this->text << (unsigned char) event.unicode;
modified = true;
}
}
}
}
return modified;
}
void TextInput::enable(){
InputManager::captureInput(*this);
enabled = true;
+ Keyboard::enableKeyRepeat();
}
void TextInput::disable(){
InputManager::releaseInput(*this);
enabled = false;
+ Keyboard::disableKeyRepeat();
}
string TextInput::getText(){
return text.str();
}
/*
void TextInput::clear(){
text.str("");
text.clear();
}
*/
void TextInput::setText(const std::string & text){
this->text.str(text);
this->text.rdbuf()->pubseekoff(0, ios_base::end, ios_base::out);
this->text.clear();
}
void TextInput::clearInput(){
text.str(string());
text.rdbuf()->pubseekoff(0, ios_base::end, ios_base::out);
text.clear();
}
void TextInput::backspace(){
string now = text.str();
now = now.substr(0, now.size()-1);
text.str(now);
text.rdbuf()->pubseekoff(0, ios_base::end, ios_base::out);
text.clear();
}
void TextInput::deleteLastWord(){
string now = text.str();
// Global::debug(0) << "Delete last word '" << now << "'" << endl;
if (now.size() > 0){
if (now.at(now.size() - 1) != ' '){
int here = now.size() - 1;
while (here > 0 && now.at(here) != ' '){
here -= 1;
}
if (now.at(here) == ' '){
here += 1;
}
now.erase(here);
} else {
int here = now.size() - 1;
while (here > 0 && now.at(here) == ' '){
here -= 1;
}
if (here > 0){
while (here > 0 && now.at(here) != ' '){
here -= 1;
}
if (now.at(here) == ' '){
here += 1;
}
}
now.erase(here);
}
text.str(now);
text.rdbuf()->pubseekoff(0, ios_base::end, ios_base::out);
text.clear();
}
/*
size_t get = now.rfind(" ");
if (get != string::npos){
Global::debug(0) << "get " << get << " size " << now.size() << endl;
if (get == now.size() - 1){
get = now.find_last_not_of(' ');
get = now.rfind(' ', get);
if (get != string::npos){
get = 0;
}
now.erase(get + 1);
} else {
now = now.substr(0, get + 1);
}
text.str(now);
text.rdbuf()->pubseekoff(0, ios_base::end, ios_base::out);
text.clear();
} else {
clearInput();
}
*/
}
TextInput::~TextInput(){
disable();
}

File Metadata

Mime Type
text/x-diff
Expires
Thu, Jun 11, 11:33 AM (3 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
68789
Default Alt Text
(43 KB)

Event Timeline