From b0455c752402a1e7d404a91609c3e5aa541fbb54 Mon Sep 17 00:00:00 2001 From: OTHGMars Date: Wed, 18 Jul 2018 20:35:59 -0400 Subject: [PATCH 1/2] =?UTF-8?q?Adds=20features=20to=20GuiInputCtrl=20This?= =?UTF-8?q?=20commit=20adds=20three=20new=20features=20to=20the=20GuiInput?= =?UTF-8?q?Ctrl.=20All=20three=20default=20to=20off,=20so=20it=20is=20full?= =?UTF-8?q?y=20backward=20compatible=20with=20existing=20scripts.=20The=20?= =?UTF-8?q?new=20options=20are:=20sendAxisEvents=20=E2=80=93=20If=20true,?= =?UTF-8?q?=20the=20control=20will=20generate=20onAxisEvent()=20callbacks?= =?UTF-8?q?=20for=20all=20axis=20events.=20This=20is=20useful=20for=20bind?= =?UTF-8?q?ing=20joystick/controller=20axes=20to=20game=20actions.=20sendB?= =?UTF-8?q?reakEvents=20=E2=80=93=20If=20true,=20the=20control=20will=20ge?= =?UTF-8?q?nerate=20onInputEvent()=20callbacks=20for=20SI=5FBREAK=20events?= =?UTF-8?q?=20for=20all=20keys=20and=20buttons.=20By=20default=20the=20cal?= =?UTF-8?q?lback=20is=20only=20triggered=20for=20break=20events=20on=20mod?= =?UTF-8?q?ifier=20keys.=20SendModifierEvents=20=E2=80=93=20If=20true=20SI?= =?UTF-8?q?=5FMAKE=20events=20for=20modifier=20keys=20will=20generate=20ca?= =?UTF-8?q?llbacks.=20By=20default,=20only=20the=20break=20events=20are=20?= =?UTF-8?q?sent=20for=20modifier=20keys.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Engine/source/gui/utility/guiInputCtrl.cpp | 95 +++++++++++++++++----- Engine/source/gui/utility/guiInputCtrl.h | 34 +++++--- 2 files changed, 95 insertions(+), 34 deletions(-) diff --git a/Engine/source/gui/utility/guiInputCtrl.cpp b/Engine/source/gui/utility/guiInputCtrl.cpp index c1799b43f..ba4eec0aa 100644 --- a/Engine/source/gui/utility/guiInputCtrl.cpp +++ b/Engine/source/gui/utility/guiInputCtrl.cpp @@ -58,9 +58,25 @@ ConsoleDocClass( GuiInputCtrl, //------------------------------------------------------------------------------ +GuiInputCtrl::GuiInputCtrl() + : mSendAxisEvents(false), + mSendBreakEvents(false), + mSendModifierEvents(false) +{ +} + +//------------------------------------------------------------------------------ + void GuiInputCtrl::initPersistFields() { - + addGroup("GuiInputCtrl"); + addField("sendAxisEvents", TypeBool, Offset(mSendAxisEvents, GuiInputCtrl), + "If true, onAxisEvent callbacks will be sent for SI_AXIS Move events (Default false)."); + addField("sendBreakEvents", TypeBool, Offset(mSendBreakEvents, GuiInputCtrl), + "If true, break events for all devices will generate callbacks (Default false)."); + addField("sendModifierEvents", TypeBool, Offset(mSendModifierEvents, GuiInputCtrl), + "If true, Make events will be sent for modifier keys (Default false)."); + endGroup("GuiInputCtrl"); Parent::initPersistFields(); } @@ -110,6 +126,8 @@ static bool isModifierKey( U16 keyCode ) case KEY_RALT: case KEY_LSHIFT: case KEY_RSHIFT: + case KEY_MAC_LOPT: + case KEY_MAC_ROPT: return( true ); } @@ -117,33 +135,46 @@ static bool isModifierKey( U16 keyCode ) } IMPLEMENT_CALLBACK( GuiInputCtrl, onInputEvent, void, (const char* device, const char* action, bool state ), - ( device, action, state), - "@brief Callback that occurs when an input is triggered on this control\n\n" - "@param device The device type triggering the input, such as keyboard, mouse, etc\n" - "@param action The actual event occuring, such as a key or button\n" - "@param state True if the action is being pressed, false if it is being release\n\n" -); + ( device, action, state), + "@brief Callback that occurs when an input is triggered on this control\n\n" + "@param device The device type triggering the input, such as keyboard, mouse, etc\n" + "@param action The actual event occuring, such as a key or button\n" + "@param state True if the action is being pressed, false if it is being release\n\n"); + +IMPLEMENT_CALLBACK(GuiInputCtrl, onAxisEvent, void, (const char* device, const char* action, F32 axisValue), + (device, action, axisValue), + "@brief Callback that occurs when an axis event is triggered on this control\n\n" + "@param device The device type triggering the input, such as mouse, joystick, gamepad, etc\n" + "@param action The ActionMap code for the axis\n" + "@param axisValue The current value of the axis\n\n"); //------------------------------------------------------------------------------ bool GuiInputCtrl::onInputEvent( const InputEventInfo &event ) { - // TODO - add POV support... + char deviceString[32]; if ( event.action == SI_MAKE ) { if ( event.objType == SI_BUTTON || event.objType == SI_POV - || ( ( event.objType == SI_KEY ) && !isModifierKey( event.objInst ) ) ) + || event.objType == SI_KEY ) { - char deviceString[32]; if ( !ActionMap::getDeviceName( event.deviceType, event.deviceInst, deviceString ) ) - return( false ); + return false; - const char* actionString = ActionMap::buildActionString( &event ); + if ((event.objType == SI_KEY) && isModifierKey(event.objInst)) + { + if (!mSendModifierEvents) + return false; - //Con::executef( this, "onInputEvent", deviceString, actionString, "1" ); - onInputEvent_callback(deviceString, actionString, 1); - - return( true ); + const char* actionString = INPUTMGR->findKeyboardMapDescFromCode(event.objInst); + onInputEvent_callback(deviceString, actionString, 1); + } + else + { + const char* actionString = ActionMap::buildActionString(&event); + onInputEvent_callback(deviceString, actionString, 1); + } + return true; } } else if ( event.action == SI_BREAK ) @@ -152,14 +183,36 @@ bool GuiInputCtrl::onInputEvent( const InputEventInfo &event ) { char keyString[32]; if ( !ActionMap::getKeyString( event.objInst, keyString ) ) - return( false ); + return false; - //Con::executef( this, "onInputEvent", "keyboard", keyString, "0" ); - onInputEvent_callback("keyboard", keyString, 0); + onInputEvent_callback("keyboard", keyString, 0); + return true; + } + else if (mSendBreakEvents) + { + if (!ActionMap::getDeviceName(event.deviceType, event.deviceInst, deviceString)) + return false; - return( true ); + const char* actionString = ActionMap::buildActionString(&event); + + onInputEvent_callback(deviceString, actionString, 0); + return true; } } + else if (mSendAxisEvents && ((event.objType == SI_AXIS) || (event.objType == SI_INT) || (event.objType == SI_FLOAT))) + { + F32 fValue = event.fValue; + if (event.objType == SI_INT) + fValue = (F32)event.iValue; - return( false ); + if (!ActionMap::getDeviceName(event.deviceType, event.deviceInst, deviceString)) + return false; + + const char* actionString = ActionMap::buildActionString(&event); + + onAxisEvent_callback(deviceString, actionString, fValue); + return (event.deviceType != MouseDeviceType); // Don't consume mouse move events + } + + return false; } diff --git a/Engine/source/gui/utility/guiInputCtrl.h b/Engine/source/gui/utility/guiInputCtrl.h index e5769740c..be60371f3 100644 --- a/Engine/source/gui/utility/guiInputCtrl.h +++ b/Engine/source/gui/utility/guiInputCtrl.h @@ -32,23 +32,31 @@ /// to script. This is useful for implementing custom keyboard handling code. class GuiInputCtrl : public GuiMouseEventCtrl { - public: +protected: + bool mSendAxisEvents; + bool mSendBreakEvents; + bool mSendModifierEvents; - typedef GuiMouseEventCtrl Parent; - - // GuiControl. - virtual bool onWake(); - virtual void onSleep(); +public: - virtual bool onInputEvent( const InputEventInfo &event ); - - static void initPersistFields(); + typedef GuiMouseEventCtrl Parent; - DECLARE_CONOBJECT(GuiInputCtrl); - DECLARE_CATEGORY( "Gui Other Script" ); - DECLARE_DESCRIPTION( "A control that locks the mouse and reports all keyboard input events to script." ); + GuiInputCtrl(); - DECLARE_CALLBACK( void, onInputEvent, ( const char* device, const char* action, bool state )); + // GuiControl. + virtual bool onWake(); + virtual void onSleep(); + + virtual bool onInputEvent( const InputEventInfo &event ); + + static void initPersistFields(); + + DECLARE_CONOBJECT(GuiInputCtrl); + DECLARE_CATEGORY( "Gui Other Script" ); + DECLARE_DESCRIPTION( "A control that locks the mouse and reports all input events to script." ); + + DECLARE_CALLBACK( void, onInputEvent, ( const char* device, const char* action, bool state )); + DECLARE_CALLBACK(void, onAxisEvent, (const char* device, const char* action, F32 axisValue)); }; #endif // _GUI_INPUTCTRL_H From 2add57079d9026977c3ffc7fa70ecb6aafcde529 Mon Sep 17 00:00:00 2001 From: OTHGMars Date: Thu, 10 Jan 2019 17:44:30 -0500 Subject: [PATCH 2/2] Updated to work without keyboard event refactor. --- Engine/source/gui/utility/guiInputCtrl.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Engine/source/gui/utility/guiInputCtrl.cpp b/Engine/source/gui/utility/guiInputCtrl.cpp index ba4eec0aa..907d861a9 100644 --- a/Engine/source/gui/utility/guiInputCtrl.cpp +++ b/Engine/source/gui/utility/guiInputCtrl.cpp @@ -166,8 +166,11 @@ bool GuiInputCtrl::onInputEvent( const InputEventInfo &event ) if (!mSendModifierEvents) return false; - const char* actionString = INPUTMGR->findKeyboardMapDescFromCode(event.objInst); - onInputEvent_callback(deviceString, actionString, 1); + char keyString[32]; + if (!ActionMap::getKeyString(event.objInst, keyString)) + return false; + + onInputEvent_callback(deviceString, keyString, 1); } else {