From b0455c752402a1e7d404a91609c3e5aa541fbb54 Mon Sep 17 00:00:00 2001 From: OTHGMars Date: Wed, 18 Jul 2018 20:35:59 -0400 Subject: [PATCH] =?UTF-8?q?Adds=20features=20to=20GuiInputCtrl=20This=20co?= =?UTF-8?q?mmit=20adds=20three=20new=20features=20to=20the=20GuiInputCtrl.?= =?UTF-8?q?=20All=20three=20default=20to=20off,=20so=20it=20is=20fully=20b?= =?UTF-8?q?ackward=20compatible=20with=20existing=20scripts.=20The=20new?= =?UTF-8?q?=20options=20are:=20sendAxisEvents=20=E2=80=93=20If=20true,=20t?= =?UTF-8?q?he=20control=20will=20generate=20onAxisEvent()=20callbacks=20fo?= =?UTF-8?q?r=20all=20axis=20events.=20This=20is=20useful=20for=20binding?= =?UTF-8?q?=20joystick/controller=20axes=20to=20game=20actions.=20sendBrea?= =?UTF-8?q?kEvents=20=E2=80=93=20If=20true,=20the=20control=20will=20gener?= =?UTF-8?q?ate=20onInputEvent()=20callbacks=20for=20SI=5FBREAK=20events=20?= =?UTF-8?q?for=20all=20keys=20and=20buttons.=20By=20default=20the=20callba?= =?UTF-8?q?ck=20is=20only=20triggered=20for=20break=20events=20on=20modifi?= =?UTF-8?q?er=20keys.=20SendModifierEvents=20=E2=80=93=20If=20true=20SI=5F?= =?UTF-8?q?MAKE=20events=20for=20modifier=20keys=20will=20generate=20callb?= =?UTF-8?q?acks.=20By=20default,=20only=20the=20break=20events=20are=20sen?= =?UTF-8?q?t=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