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
Notes: blender-bot 2023-02-14 11:22:50 +01:00
Referenced by issue #38330, Anisotropic glitch on animation
Referenced by issue #38110, Keyboard sensor ignores unicode characters
14 changed files with 51 additions and 47 deletions

View File

@ -151,8 +151,9 @@ static int BL_KetsjiNextFrame(KX_KetsjiEngine *ketsjiengine, bContext *C, wmWind
while (wmEvent *event= (wmEvent *)win->queue.first) {
short val = 0;
//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;
/* Coordinate conversion... where
@ -161,13 +162,13 @@ static int BL_KetsjiNextFrame(KX_KetsjiEngine *ketsjiengine, bContext *C, wmWind
if (event->type == MOUSEMOVE) {
/* Note, not nice! XXX 2.5 event hack */
val = event->x - ar->winrct.xmin;
mousedevice->ConvertBlenderEvent(MOUSEX, val);
mousedevice->ConvertBlenderEvent(MOUSEX, val, 0);
val = ar->winy - (event->y - ar->winrct.ymin) - 1;
mousedevice->ConvertBlenderEvent(MOUSEY, val);
mousedevice->ConvertBlenderEvent(MOUSEY, val, 0);
}
else {
mousedevice->ConvertBlenderEvent(event->type,event->val);
mousedevice->ConvertBlenderEvent(event->type, event->val, 0);
}
BLI_remlink(&win->queue, event);

View File

@ -69,7 +69,7 @@ public:
virtual bool IsPressed(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

View File

@ -91,7 +91,7 @@ void KX_BlenderKeyboardDevice::NextFrame()
* ConvertBlenderEvent translates blender keyboard events into ketsji kbd events
* 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;
@ -112,6 +112,7 @@ bool KX_BlenderKeyboardDevice::ConvertBlenderEvent(unsigned short incode, short
// todo: convert val ??
m_eventStatusTables[m_currentTable][kxevent].m_eventval = val ; //???
m_eventStatusTables[m_currentTable][kxevent].m_unicode = unicode;
switch (m_eventStatusTables[previousTable][kxevent].m_status)
{

View File

@ -47,7 +47,7 @@ public:
virtual bool IsPressed(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 HookEscape();
private:

View File

@ -108,7 +108,7 @@ void KX_BlenderMouseDevice::NextFrame()
* ConvertBlenderEvent translates blender mouse events into ketsji kbd events
* 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;

View File

@ -46,7 +46,7 @@ public:
virtual bool IsPressed(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();

View File

@ -51,15 +51,17 @@ public:
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_eventval(eventval)
m_eventval(eventval),
m_unicode(unicode)
{
}
SCA_EnumInputs m_status;
int m_eventval;
unsigned int m_unicode;
};
/* Originally from wm_event_types.h, now only used by GameEngine */

View File

@ -40,6 +40,7 @@
#include "SCA_IInputDevice.h"
extern "C" {
#include "BLI_string_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)) {
CValue* tprop = GetParent()->GetProperty(m_targetprop);
if (tprop) {
/* overwrite the old property */
if (IsDelete(keyIndex)) {
if (IsDelete(keyIndex)) {
/* Make a new property. Deletes can be ignored. */
if (tprop) {
/* overwrite the old property */
/* strip one char, if possible */
STR_String newprop = tprop->GetText();
int oldlength = newprop.Length();
@ -352,26 +354,22 @@ void SCA_KeyboardSensor::AddToTargetProp(int keyIndex)
GetParent()->SetProperty(m_targetprop, newstringprop);
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)
{
AddToTargetProp(i);
AddToTargetProp(i, inevent.m_unicode);
index++;
}
}

View File

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

View File

@ -64,7 +64,7 @@ void GPC_KeyboardDevice::NextFrame()
* ConvertBPEvent translates Windows keyboard events into ketsji kbd events.
* 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;
@ -83,6 +83,7 @@ bool GPC_KeyboardDevice::ConvertEvent(int incode, int val)
// todo: convert val ??
m_eventStatusTables[m_currentTable][kxevent].m_eventval = val ; //???
m_eventStatusTables[m_currentTable][kxevent].m_unicode = unicode ;
switch (m_eventStatusTables[previousTable][kxevent].m_status)
{

View File

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

View File

@ -97,19 +97,19 @@ bool GPC_MouseDevice::ConvertButtonEvent(TButtonId button, bool isDown)
switch (button)
{
case buttonLeft:
result = ConvertEvent(KX_LEFTMOUSE, isDown);
result = ConvertEvent(KX_LEFTMOUSE, isDown, 0);
break;
case buttonMiddle:
result = ConvertEvent(KX_MIDDLEMOUSE, isDown);
result = ConvertEvent(KX_MIDDLEMOUSE, isDown, 0);
break;
case buttonRight:
result = ConvertEvent(KX_RIGHTMOUSE, isDown);
result = ConvertEvent(KX_RIGHTMOUSE, isDown, 0);
break;
case buttonWheelUp:
result = ConvertEvent(KX_WHEELUPMOUSE, isDown);
result = ConvertEvent(KX_WHEELUPMOUSE, isDown, 0);
break;
case buttonWheelDown:
result = ConvertEvent(KX_WHEELDOWNMOUSE, isDown);
result = ConvertEvent(KX_WHEELDOWNMOUSE, isDown, 0);
break;
default:
// Should not happen!
@ -144,16 +144,16 @@ bool GPC_MouseDevice::ConvertMoveEvent(int x, int y)
bool result;
// Convert to local coordinates?
result = ConvertEvent(KX_MOUSEX, x);
result = ConvertEvent(KX_MOUSEX, x, 0);
if (result) {
result = ConvertEvent(KX_MOUSEY, y);
result = ConvertEvent(KX_MOUSEY, y, 0);
}
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;

View File

@ -99,7 +99,7 @@ protected:
* \param eventval Value for this event.
* \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__ */

View File

@ -951,11 +951,12 @@ bool GPG_Application::handleKey(GHOST_IEvent* event, bool isDown)
{
GHOST_TEventDataPtr eventData = ((GHOST_IEvent*)event)->getData();
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) {
m_exitRequested = KX_EXIT_REQUEST_OUTSIDE;
}
m_keyboard->ConvertEvent(keyData->key, isDown);
m_keyboard->ConvertEvent(keyData->key, isDown, unicode);
handled = true;
}
return handled;