Fix T38110: GameEngine keyboard sensor ignores unicode characters

This commit is contained in:
Campbell Barton 2014-01-23 14:58:04 +11:00
parent c02c2dfdd9
commit 3b71cab420
14 changed files with 51 additions and 47 deletions

@ -151,8 +151,9 @@ static int BL_KetsjiNextFrame(KX_KetsjiEngine *ketsjiengine, bContext *C, wmWind
while (wmEvent *event= (wmEvent *)win->queue.first) { while (wmEvent *event= (wmEvent *)win->queue.first) {
short val = 0; short val = 0;
//unsigned short event = 0; //XXX extern_qread(&val); //unsigned short event = 0; //XXX extern_qread(&val);
unsigned int unicode = event->utf8_buf[0] ? BLI_str_utf8_as_unicode(event->utf8_buf) : event->ascii;
if (keyboarddevice->ConvertBlenderEvent(event->type,event->val)) if (keyboarddevice->ConvertBlenderEvent(event->type, event->val, unicode))
exitrequested = KX_EXIT_REQUEST_BLENDER_ESC; exitrequested = KX_EXIT_REQUEST_BLENDER_ESC;
/* Coordinate conversion... where /* Coordinate conversion... where
@ -161,13 +162,13 @@ static int BL_KetsjiNextFrame(KX_KetsjiEngine *ketsjiengine, bContext *C, wmWind
if (event->type == MOUSEMOVE) { if (event->type == MOUSEMOVE) {
/* Note, not nice! XXX 2.5 event hack */ /* Note, not nice! XXX 2.5 event hack */
val = event->x - ar->winrct.xmin; val = event->x - ar->winrct.xmin;
mousedevice->ConvertBlenderEvent(MOUSEX, val); mousedevice->ConvertBlenderEvent(MOUSEX, val, 0);
val = ar->winy - (event->y - ar->winrct.ymin) - 1; val = ar->winy - (event->y - ar->winrct.ymin) - 1;
mousedevice->ConvertBlenderEvent(MOUSEY, val); mousedevice->ConvertBlenderEvent(MOUSEY, val, 0);
} }
else { else {
mousedevice->ConvertBlenderEvent(event->type,event->val); mousedevice->ConvertBlenderEvent(event->type, event->val, 0);
} }
BLI_remlink(&win->queue, event); BLI_remlink(&win->queue, event);

@ -69,7 +69,7 @@ public:
virtual bool IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode)=0; virtual bool IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode)=0;
// virtual const SCA_InputEvent& GetEventValue(SCA_IInputDevice::KX_EnumInputs inputcode)=0; // virtual const SCA_InputEvent& GetEventValue(SCA_IInputDevice::KX_EnumInputs inputcode)=0;
virtual bool ConvertBlenderEvent(unsigned short incode,short val)=0; virtual bool ConvertBlenderEvent(unsigned short incode, short val, unsigned int unicode)=0;
#ifdef WITH_CXX_GUARDEDALLOC #ifdef WITH_CXX_GUARDEDALLOC

@ -91,7 +91,7 @@ void KX_BlenderKeyboardDevice::NextFrame()
* ConvertBlenderEvent translates blender keyboard events into ketsji kbd events * ConvertBlenderEvent translates blender keyboard events into ketsji kbd events
* extra event information is stored, like ramp-mode (just released/pressed) * extra event information is stored, like ramp-mode (just released/pressed)
*/ */
bool KX_BlenderKeyboardDevice::ConvertBlenderEvent(unsigned short incode, short val) bool KX_BlenderKeyboardDevice::ConvertBlenderEvent(unsigned short incode, short val, unsigned int unicode)
{ {
bool result = false; bool result = false;
@ -112,6 +112,7 @@ bool KX_BlenderKeyboardDevice::ConvertBlenderEvent(unsigned short incode, short
// todo: convert val ?? // todo: convert val ??
m_eventStatusTables[m_currentTable][kxevent].m_eventval = val ; //??? m_eventStatusTables[m_currentTable][kxevent].m_eventval = val ; //???
m_eventStatusTables[m_currentTable][kxevent].m_unicode = unicode;
switch (m_eventStatusTables[previousTable][kxevent].m_status) switch (m_eventStatusTables[previousTable][kxevent].m_status)
{ {

@ -47,7 +47,7 @@ public:
virtual bool IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode); virtual bool IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode);
// virtual const SCA_InputEvent& GetEventValue(SCA_IInputDevice::KX_EnumInputs inputcode); // virtual const SCA_InputEvent& GetEventValue(SCA_IInputDevice::KX_EnumInputs inputcode);
virtual bool ConvertBlenderEvent(unsigned short incode,short val); virtual bool ConvertBlenderEvent(unsigned short incode, short val, unsigned int unicode);
virtual void NextFrame(); virtual void NextFrame();
virtual void HookEscape(); virtual void HookEscape();
private: private:

@ -108,7 +108,7 @@ void KX_BlenderMouseDevice::NextFrame()
* ConvertBlenderEvent translates blender mouse events into ketsji kbd events * ConvertBlenderEvent translates blender mouse events into ketsji kbd events
* extra event information is stored, like ramp-mode (just released/pressed) * extra event information is stored, like ramp-mode (just released/pressed)
*/ */
bool KX_BlenderMouseDevice::ConvertBlenderEvent(unsigned short incode, short val) bool KX_BlenderMouseDevice::ConvertBlenderEvent(unsigned short incode, short val, unsigned int unicode)
{ {
bool result = false; bool result = false;

@ -46,7 +46,7 @@ public:
virtual bool IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode); virtual bool IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode);
// virtual const SCA_InputEvent& GetEventValue(SCA_IInputDevice::KX_EnumInputs inputcode); // virtual const SCA_InputEvent& GetEventValue(SCA_IInputDevice::KX_EnumInputs inputcode);
virtual bool ConvertBlenderEvent(unsigned short incode,short val); virtual bool ConvertBlenderEvent(unsigned short incode, short val, unsigned int unicode);
virtual void NextFrame(); virtual void NextFrame();

@ -51,15 +51,17 @@ public:
KX_JUSTRELEASED, KX_JUSTRELEASED,
}; };
SCA_InputEvent(SCA_EnumInputs status=KX_NO_INPUTSTATUS,int eventval=0) SCA_InputEvent(SCA_EnumInputs status=KX_NO_INPUTSTATUS,int eventval=0, int unicode=0)
: m_status(status), : m_status(status),
m_eventval(eventval) m_eventval(eventval),
m_unicode(unicode)
{ {
} }
SCA_EnumInputs m_status; SCA_EnumInputs m_status;
int m_eventval; int m_eventval;
unsigned int m_unicode;
}; };
/* Originally from wm_event_types.h, now only used by GameEngine */ /* Originally from wm_event_types.h, now only used by GameEngine */

@ -40,6 +40,7 @@
#include "SCA_IInputDevice.h" #include "SCA_IInputDevice.h"
extern "C" { extern "C" {
#include "BLI_string_utf8.h"
#include "BLI_string_cursor_utf8.h" #include "BLI_string_cursor_utf8.h"
} }
@ -331,14 +332,15 @@ bool SCA_KeyboardSensor::Evaluate()
} }
void SCA_KeyboardSensor::AddToTargetProp(int keyIndex) void SCA_KeyboardSensor::AddToTargetProp(int keyIndex, int unicode)
{ {
if (IsPrintable(keyIndex)) { if (IsPrintable(keyIndex)) {
CValue* tprop = GetParent()->GetProperty(m_targetprop); CValue* tprop = GetParent()->GetProperty(m_targetprop);
if (tprop) { if (IsDelete(keyIndex)) {
/* overwrite the old property */ /* Make a new property. Deletes can be ignored. */
if (IsDelete(keyIndex)) { if (tprop) {
/* overwrite the old property */
/* strip one char, if possible */ /* strip one char, if possible */
STR_String newprop = tprop->GetText(); STR_String newprop = tprop->GetText();
int oldlength = newprop.Length(); int oldlength = newprop.Length();
@ -352,26 +354,22 @@ void SCA_KeyboardSensor::AddToTargetProp(int keyIndex)
GetParent()->SetProperty(m_targetprop, newstringprop); GetParent()->SetProperty(m_targetprop, newstringprop);
newstringprop->Release(); newstringprop->Release();
} }
} else {
/* append */
char pchar = ToCharacter(keyIndex, IsShifted());
STR_String newprop = tprop->GetText() + pchar;
CStringValue * newstringprop = new CStringValue(newprop, m_targetprop);
GetParent()->SetProperty(m_targetprop, newstringprop);
newstringprop->Release();
}
} else {
if (!IsDelete(keyIndex)) {
/* Make a new property. Deletes can be ignored. */
char pchar = ToCharacter(keyIndex, IsShifted());
STR_String newprop = pchar;
CStringValue * newstringprop = new CStringValue(newprop, m_targetprop);
GetParent()->SetProperty(m_targetprop, newstringprop);
newstringprop->Release();
} }
} }
else {
char utf8_buf[7];
size_t utf8_len;
utf8_len = BLI_str_utf8_from_unicode(unicode, utf8_buf);
utf8_buf[utf8_len] = '\0';
STR_String newprop = tprop ? (tprop->GetText() + utf8_buf) : utf8_buf;
CStringValue * newstringprop = new CStringValue(newprop, m_targetprop);
GetParent()->SetProperty(m_targetprop, newstringprop);
newstringprop->Release();
}
} }
} }
/** /**
@ -416,7 +414,7 @@ void SCA_KeyboardSensor::LogKeystrokes(void)
{ {
if (index < num) if (index < num)
{ {
AddToTargetProp(i); AddToTargetProp(i, inevent.m_unicode);
index++; index++;
} }
} }

@ -79,7 +79,7 @@ class SCA_KeyboardSensor : public SCA_ISensor
/** /**
* Adds this key-code to the target prop. * Adds this key-code to the target prop.
*/ */
void AddToTargetProp(int keyIndex); void AddToTargetProp(int keyIndex, int unicode);
/** /**
* Tests whether shift is pressed. * Tests whether shift is pressed.

@ -64,7 +64,7 @@ void GPC_KeyboardDevice::NextFrame()
* ConvertBPEvent translates Windows keyboard events into ketsji kbd events. * ConvertBPEvent translates Windows keyboard events into ketsji kbd events.
* Extra event information is stored, like ramp-mode (just released/pressed) * Extra event information is stored, like ramp-mode (just released/pressed)
*/ */
bool GPC_KeyboardDevice::ConvertEvent(int incode, int val) bool GPC_KeyboardDevice::ConvertEvent(int incode, int val, unsigned int unicode)
{ {
bool result = false; bool result = false;
@ -83,6 +83,7 @@ bool GPC_KeyboardDevice::ConvertEvent(int incode, int val)
// todo: convert val ?? // todo: convert val ??
m_eventStatusTables[m_currentTable][kxevent].m_eventval = val ; //??? m_eventStatusTables[m_currentTable][kxevent].m_eventval = val ; //???
m_eventStatusTables[m_currentTable][kxevent].m_unicode = unicode ;
switch (m_eventStatusTables[previousTable][kxevent].m_status) switch (m_eventStatusTables[previousTable][kxevent].m_status)
{ {

@ -82,7 +82,7 @@ public:
return m_reverseKeyTranslateTable[incode]; return m_reverseKeyTranslateTable[incode];
} }
virtual bool ConvertEvent(int incode, int val); virtual bool ConvertEvent(int incode, int val, unsigned int unicode);
virtual void HookEscape(); virtual void HookEscape();
}; };

@ -97,19 +97,19 @@ bool GPC_MouseDevice::ConvertButtonEvent(TButtonId button, bool isDown)
switch (button) switch (button)
{ {
case buttonLeft: case buttonLeft:
result = ConvertEvent(KX_LEFTMOUSE, isDown); result = ConvertEvent(KX_LEFTMOUSE, isDown, 0);
break; break;
case buttonMiddle: case buttonMiddle:
result = ConvertEvent(KX_MIDDLEMOUSE, isDown); result = ConvertEvent(KX_MIDDLEMOUSE, isDown, 0);
break; break;
case buttonRight: case buttonRight:
result = ConvertEvent(KX_RIGHTMOUSE, isDown); result = ConvertEvent(KX_RIGHTMOUSE, isDown, 0);
break; break;
case buttonWheelUp: case buttonWheelUp:
result = ConvertEvent(KX_WHEELUPMOUSE, isDown); result = ConvertEvent(KX_WHEELUPMOUSE, isDown, 0);
break; break;
case buttonWheelDown: case buttonWheelDown:
result = ConvertEvent(KX_WHEELDOWNMOUSE, isDown); result = ConvertEvent(KX_WHEELDOWNMOUSE, isDown, 0);
break; break;
default: default:
// Should not happen! // Should not happen!
@ -144,16 +144,16 @@ bool GPC_MouseDevice::ConvertMoveEvent(int x, int y)
bool result; bool result;
// Convert to local coordinates? // Convert to local coordinates?
result = ConvertEvent(KX_MOUSEX, x); result = ConvertEvent(KX_MOUSEX, x, 0);
if (result) { if (result) {
result = ConvertEvent(KX_MOUSEY, y); result = ConvertEvent(KX_MOUSEY, y, 0);
} }
return result; return result;
} }
bool GPC_MouseDevice::ConvertEvent(KX_EnumInputs kxevent, int eventval) bool GPC_MouseDevice::ConvertEvent(KX_EnumInputs kxevent, int eventval, unsigned int unicode)
{ {
bool result = true; bool result = true;

@ -99,7 +99,7 @@ protected:
* \param eventval Value for this event. * \param eventval Value for this event.
* \return Indication as to whether the event was processed. * \return Indication as to whether the event was processed.
*/ */
virtual bool ConvertEvent(KX_EnumInputs kxevent, int eventval); virtual bool ConvertEvent(KX_EnumInputs kxevent, int eventval, unsigned int unicode);
}; };
#endif /* __GPC_MOUSEDEVICE_H__ */ #endif /* __GPC_MOUSEDEVICE_H__ */

@ -951,11 +951,12 @@ bool GPG_Application::handleKey(GHOST_IEvent* event, bool isDown)
{ {
GHOST_TEventDataPtr eventData = ((GHOST_IEvent*)event)->getData(); GHOST_TEventDataPtr eventData = ((GHOST_IEvent*)event)->getData();
GHOST_TEventKeyData* keyData = static_cast<GHOST_TEventKeyData*>(eventData); GHOST_TEventKeyData* keyData = static_cast<GHOST_TEventKeyData*>(eventData);
unsigned int unicode = keyData->utf8_buf[0] ? BLI_str_utf8_as_unicode(keyData->utf8_buf) : keyData->ascii;
if (m_keyboard->ToNative(keyData->key) == KX_KetsjiEngine::GetExitKey() && !m_keyboard->m_hookesc && !m_isEmbedded) { if (m_keyboard->ToNative(keyData->key) == KX_KetsjiEngine::GetExitKey() && !m_keyboard->m_hookesc && !m_isEmbedded) {
m_exitRequested = KX_EXIT_REQUEST_OUTSIDE; m_exitRequested = KX_EXIT_REQUEST_OUTSIDE;
} }
m_keyboard->ConvertEvent(keyData->key, isDown); m_keyboard->ConvertEvent(keyData->key, isDown, unicode);
handled = true; handled = true;
} }
return handled; return handled;