Adds logic so the canvas keeps track of the last input device

This commit is contained in:
Areloch 2023-02-09 18:54:36 -06:00
parent 3d8220c413
commit 5599721a1e
2 changed files with 30 additions and 0 deletions

View file

@ -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();
}

View file

@ -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);