Fixed up formatting, debug messages in new Windows Hotkey stuff.

develop
Clayton Hughes 2012-03-09 01:07:47 -08:00
parent 3d1ce32785
commit 47bbe1a3ff
3 changed files with 31 additions and 34 deletions

@ -882,41 +882,36 @@ bool Core::ncurses_wgetch(int in, int & out)
int Core::UnicodeAwareSym(const SDL::KeyboardEvent& ke) int Core::UnicodeAwareSym(const SDL::KeyboardEvent& ke)
{ {
con.print("Unicode came in as %d\n", ke.ksym.unicode); // Assume keyboard layouts don't change the order of numbers:
// Assume keyboard layouts don't change the order of numbers: if( '0' <= ke.ksym.sym && ke.ksym.sym <= '9') return ke.ksym.sym;
if( '0' <= ke.ksym.sym && ke.ksym.sym <= '9') return ke.ksym.sym;
int unicode = ke.ksym.unicode; int unicode = ke.ksym.unicode;
// convert Ctrl characters to their 0x40-0x5F counterparts: // convert Ctrl characters to their 0x40-0x5F counterparts:
if (unicode < ' ') if (unicode < ' ')
{ {
unicode += 'A' - 1; unicode += 'A' - 1;
con.print("Unicode is a control character. Adding 0x40: %d\n", unicode);
} }
// convert A-Z to their a-z counterparts: // convert A-Z to their a-z counterparts:
if('A' < unicode && unicode < 'Z') if('A' < unicode && unicode < 'Z')
{ {
unicode += 'a' - 'A'; unicode += 'a' - 'A';
con.print("Unicode is a upper case. Subtracting 0x20: %d\n", unicode); }
}
// convert various other punctuation marks:
// convert various other punctuation marks: if('\"' == unicode) unicode = '\'';
if('\"' == unicode) unicode = '\''; if('+' == unicode) unicode = '=';
if('+' == unicode) unicode = '='; if(':' == unicode) unicode = ';';
if(':' == unicode) unicode = ';'; if('<' == unicode) unicode = ',';
if('<' == unicode) unicode = ','; if('>' == unicode) unicode = '.';
if('>' == unicode) unicode = '.'; if('?' == unicode) unicode = '/';
if('?' == unicode) unicode = '/'; if('{' == unicode) unicode = '[';
if('{' == unicode) unicode = '['; if('|' == unicode) unicode = '\\';
if('|' == unicode) unicode = '\\'; if('}' == unicode) unicode = ']';
if('}' == unicode) unicode = ']'; if('~' == unicode) unicode = '`';
if('~' == unicode) unicode = '`';
return unicode;
con.print("Unicode punctuation filter. Now: %d\n", unicode);
return unicode;
} }
//MEMO: return false if event is consumed //MEMO: return false if event is consumed
@ -932,7 +927,7 @@ int Core::SDL_Event(SDL::Event* ev)
if(ke->state == SDL::BTN_PRESSED && !hotkey_states[ke->ksym.sym]) if(ke->state == SDL::BTN_PRESSED && !hotkey_states[ke->ksym.sym])
{ {
hotkey_states[ke->ksym.sym] = true; hotkey_states[ke->ksym.sym] = true;
int mod = 0; int mod = 0;
if (ke->ksym.mod & SDL::KMOD_SHIFT) mod |= 1; if (ke->ksym.mod & SDL::KMOD_SHIFT) mod |= 1;
@ -942,9 +937,8 @@ int Core::SDL_Event(SDL::Event* ev)
// Use unicode so Windows gives the correct value for the // Use unicode so Windows gives the correct value for the
// user's Input Language // user's Input Language
if((ke->ksym.unicode & 0xff80) == 0) if((ke->ksym.unicode & 0xff80) == 0)
{ {
int key = UnicodeAwareSym(*ke);
int key = UnicodeAwareSym(*ke);
SelectHotkey(key, mod); SelectHotkey(key, mod);
} }
else else

@ -404,6 +404,10 @@ DFhackCExport int SDL_EnableKeyRepeat(int delay, int interval)
static int (*_SDL_EnableUNICODE)(int enable) = 0; static int (*_SDL_EnableUNICODE)(int enable) = 0;
DFhackCExport int SDL_EnableUNICODE(int enable) DFhackCExport int SDL_EnableUNICODE(int enable)
{ {
if(!enable)
{
fprintf(stderr, "SDL_EnableUNICODE turned off. Keybindings may break.\n");
}
return _SDL_EnableUNICODE(enable); return _SDL_EnableUNICODE(enable);
} }
@ -800,7 +804,7 @@ bool FirstCall()
_SDL_SemWait = (int (*)(void *))GetProcAddress(realSDLlib,"SDL_SemWait"); _SDL_SemWait = (int (*)(void *))GetProcAddress(realSDLlib,"SDL_SemWait");
_SDL_ThreadID = (uint32_t (*)(void))GetProcAddress(realSDLlib,"SDL_ThreadID"); _SDL_ThreadID = (uint32_t (*)(void))GetProcAddress(realSDLlib,"SDL_ThreadID");
_SDL_EnableUNICODE(1); _SDL_EnableUNICODE(1);
fprintf(stderr,"Initized HOOKS!\n"); fprintf(stderr,"Initized HOOKS!\n");
inited = true; inited = true;

@ -178,8 +178,7 @@ namespace DFHack
tthread::mutex * HotkeyMutex; tthread::mutex * HotkeyMutex;
tthread::condition_variable * HotkeyCond; tthread::condition_variable * HotkeyCond;
int UnicodeAwareSym(const SDL::KeyboardEvent& ke); int UnicodeAwareSym(const SDL::KeyboardEvent& ke);
bool SelectHotkey(int key, int modifiers); bool SelectHotkey(int key, int modifiers);
void *last_world_data_ptr; // for state change tracking void *last_world_data_ptr; // for state change tracking