2
0
Эх сурвалжийг харах

Merge pull request #955 from Areloch/canvasLastInputDeviceTracking

Adds logic so the canvas keeps track of the last input device
Brian Roberts 2 жил өмнө
parent
commit
7fa2e72d5f

+ 27 - 0
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();
+}

+ 3 - 0
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);