diff --git a/Engine/source/gui/core/guiCanvas.cpp b/Engine/source/gui/core/guiCanvas.cpp index 19342b24d..de57ce280 100644 --- a/Engine/source/gui/core/guiCanvas.cpp +++ b/Engine/source/gui/core/guiCanvas.cpp @@ -180,6 +180,7 @@ GuiCanvas::GuiCanvas(): GuiControl(), mNumFences = 0; #endif mConsumeLastInputEvent = false; + mLastInputDeviceType = -1; } GuiCanvas::~GuiCanvas() @@ -686,6 +687,8 @@ bool GuiCanvas::tabPrev(void) bool GuiCanvas::processInputEvent(InputEventInfo &inputEvent) { mConsumeLastInputEvent = true; + mLastInputDeviceType = inputEvent.deviceType; + // First call the general input handler (on the extremely off-chance that it will be handled): if (mFirstResponder && mFirstResponder->onInputEvent(inputEvent)) { @@ -2138,6 +2141,26 @@ void GuiCanvas::setFirstResponder( GuiControl* newResponder ) newResponder->onGainFirstResponder(); } +StringTableEntry GuiCanvas::getLastInputDeviceType() +{ + switch (mLastInputDeviceType) + { + case KeyboardDeviceType: + return StringTable->insert("Keyboard"); + break; + + case GamepadDeviceType: + return StringTable->insert("Gamepad"); + break; + + case MouseDeviceType: + return StringTable->insert("Mouse"); + break; + } + + return StringTable->EmptyString(); +} + DefineEngineMethod( GuiCanvas, getContent, S32, (),, "@brief Get the GuiControl which is being used as the content.\n\n" @@ -2954,3 +2977,7 @@ DefineEngineMethod(GuiCanvas, resetVideoMode, void, (), , "") } } +DefineEngineMethod(GuiCanvas, getLastInputDevice, const char*, (), , "Returns the name of the last input device that the GuiCanvas consumed.") +{ + return object->getLastInputDeviceType(); +} diff --git a/Engine/source/gui/core/guiCanvas.h b/Engine/source/gui/core/guiCanvas.h index 4a43fb7a0..e9ef1b728 100644 --- a/Engine/source/gui/core/guiCanvas.h +++ b/Engine/source/gui/core/guiCanvas.h @@ -475,11 +475,14 @@ private: static const U32 MAX_GAMEPADS = 4; ///< The maximum number of supported gamepads protected: bool mConsumeLastInputEvent; + S32 mLastInputDeviceType; public: void clearMouseRightButtonDown(void) { mMouseRightButtonDown = false; } void clearMouseButtonDown(void) { mMouseButtonDown = false; } void setConsumeLastInputEvent(bool flag) { mConsumeLastInputEvent = flag; } bool getLastCursorPoint(Point2I& pt) const { pt = mLastCursorPt; return mLastCursorEnabled; } + + StringTableEntry getLastInputDeviceType(); }; typedef GuiCanvas::KeyTranslationMode KeyboardTranslationMode; DefineEnumType(KeyboardTranslationMode);