[Bf-blender-cvs] [3b71cab] master: Fix T38110: GameEngine keyboard sensor ignores unicode characters
Campbell Barton
noreply at git.blender.org
Thu Jan 23 04:59:45 CET 2014
Commit: 3b71cab420c642df30d9f9addee166444ce5b85b
Author: Campbell Barton
Date: Thu Jan 23 14:58:04 2014 +1100
https://developer.blender.org/rB3b71cab420c642df30d9f9addee166444ce5b85b
Fix T38110: GameEngine keyboard sensor ignores unicode characters
===================================================================
M source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
M source/gameengine/BlenderRoutines/KX_BlenderInputDevice.h
M source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.cpp
M source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.h
M source/gameengine/BlenderRoutines/KX_BlenderMouseDevice.cpp
M source/gameengine/BlenderRoutines/KX_BlenderMouseDevice.h
M source/gameengine/GameLogic/SCA_IInputDevice.h
M source/gameengine/GameLogic/SCA_KeyboardSensor.cpp
M source/gameengine/GameLogic/SCA_KeyboardSensor.h
M source/gameengine/GamePlayer/common/GPC_KeyboardDevice.cpp
M source/gameengine/GamePlayer/common/GPC_KeyboardDevice.h
M source/gameengine/GamePlayer/common/GPC_MouseDevice.cpp
M source/gameengine/GamePlayer/common/GPC_MouseDevice.h
M source/gameengine/GamePlayer/ghost/GPG_Application.cpp
===================================================================
diff --git a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
index 2b1c8a1..d136131 100644
--- a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
+++ b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
@@ -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);
diff --git a/source/gameengine/BlenderRoutines/KX_BlenderInputDevice.h b/source/gameengine/BlenderRoutines/KX_BlenderInputDevice.h
index 0ce479c..a936f32 100644
--- a/source/gameengine/BlenderRoutines/KX_BlenderInputDevice.h
+++ b/source/gameengine/BlenderRoutines/KX_BlenderInputDevice.h
@@ -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
diff --git a/source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.cpp b/source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.cpp
index 5917ce4..ea78d2d 100644
--- a/source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.cpp
+++ b/source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.cpp
@@ -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)
{
diff --git a/source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.h b/source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.h
index dec7020..10a5b00 100644
--- a/source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.h
+++ b/source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.h
@@ -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:
diff --git a/source/gameengine/BlenderRoutines/KX_BlenderMouseDevice.cpp b/source/gameengine/BlenderRoutines/KX_BlenderMouseDevice.cpp
index 0cdc102..9df06e8 100644
--- a/source/gameengine/BlenderRoutines/KX_BlenderMouseDevice.cpp
+++ b/source/gameengine/BlenderRoutines/KX_BlenderMouseDevice.cpp
@@ -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;
diff --git a/source/gameengine/BlenderRoutines/KX_BlenderMouseDevice.h b/source/gameengine/BlenderRoutines/KX_BlenderMouseDevice.h
index 8746da8..04b78af 100644
--- a/source/gameengine/BlenderRoutines/KX_BlenderMouseDevice.h
+++ b/source/gameengine/BlenderRoutines/KX_BlenderMouseDevice.h
@@ -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();
diff --git a/source/gameengine/GameLogic/SCA_IInputDevice.h b/source/gameengine/GameLogic/SCA_IInputDevice.h
index ce7c865..23346c2 100644
--- a/source/gameengine/GameLogic/SCA_IInputDevice.h
+++ b/source/gameengine/GameLogic/SCA_IInputDevice.h
@@ -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 */
diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp
index 7005ea1..cc20388 100644
--- a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp
+++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp
@@ -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++;
}
}
diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.h b/source/gameengine/GameLogic/SCA_KeyboardSensor.h
index c6610d0..c9d5528 100644
--- a/source/gameengine/GameLogic/SCA_KeyboardSensor.h
+++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.h
@@ -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.
diff --git a/source/gameengine/GamePlayer/common/GPC_KeyboardDevice.cpp b/source/gameengine/GamePlayer/common/GPC_KeyboardDevice.cpp
index ecb58ed..0821d1d 100644
--- a/source/gameengine/GamePlayer/common/GPC_KeyboardDevice.cpp
+++ b/source/gameengine/GamePlayer/common/GPC_KeyboardDevice.cpp
@@ -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)
{
diff --git a/source/gameengine/GamePlayer/common/GPC_KeyboardDevice.
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list