فهرست منبع

Merge branch 'development' of https://github.com/TorqueGameEngines/Torque2D into development

Peter Robinson 4 سال پیش
والد
کامیت
f3aa2a5bdf
3فایلهای تغییر یافته به همراه53 افزوده شده و 2 حذف شده
  1. 42 1
      engine/source/gui/guiCanvas.cc
  2. 6 0
      engine/source/gui/guiCanvas.h
  3. 5 1
      toybox/AppCore/1/scripts/defaultPreferences.cs

+ 42 - 1
engine/source/gui/guiCanvas.cc

@@ -95,6 +95,10 @@ GuiCanvas::GuiCanvas()
    mDoubleClickHeight = Input::getDoubleClickHeight();
    mDoubleClickTime = Input::getDoubleClickTime();
 
+   mTouchDetectionSize = 100;
+   mPotentialTouchEvent = false;
+   mHideCursorBecauseOfTouch = false;
+
     /// Background color.
     mBackgroundColor.set( 0.0f, 0.0f, 0.0f, 0.0f );
     mUseBackgroundColor = true;
@@ -276,6 +280,32 @@ void GuiCanvas::processMouseMoveEvent(const MouseMoveEvent *event)
          mRightMouseLast = false;
       }
 
+		//should we try to detect a touch event pretending to be a mouse event?
+		if( Con::getBoolVariable( "$pref::Gui::hideCursorWhenTouchEventDetected", false ))
+		{
+			mPotentialTouchEvent = false;
+			Point2F jump = mPrevMouseMovePosition - cursorPt;
+			if ((mAbs((S32)jump.x) > mTouchDetectionSize) || (mAbs((S32)jump.y) > mTouchDetectionSize))
+			{
+				mPotentialTouchEvent = true;
+				mPotentialMouseEventCount = 0;
+			}
+			else if(mHideCursorBecauseOfTouch && !mMouseButtonDown)
+			{
+				if(mPotentialMouseEventCount > 20) 
+				{
+					//This is our 20th small movement with no click or drag so it must be a mouse!
+					mHideCursorBecauseOfTouch = false;
+					mPotentialMouseEventCount = 0;
+				}
+				else 
+				{
+					mPotentialMouseEventCount++;
+				}
+			}
+			mPrevMouseMovePosition.set(cursorPt.x, cursorPt.y);
+		}
+
         if (mMouseButtonDown)
             rootMouseDragged(mLastEvent);
         else if (mMouseRightButtonDown)
@@ -475,6 +505,15 @@ bool GuiCanvas::processInputEvent(const InputEvent *event)
                mLastMouseDownTime = curTime;
                mLastEvent.mouseClickCount = mLastMouseClickCount;
 
+			   if(mHideCursorBecauseOfTouch)
+			   {
+					mPotentialMouseEventCount = 0;
+				}
+			   if(mPotentialTouchEvent)
+			   {
+					mHideCursorBecauseOfTouch = true;
+			   }
+
                rootMouseDown(mLastEvent);
             }
             //else button was released
@@ -487,6 +526,7 @@ bool GuiCanvas::processInputEvent(const InputEvent *event)
          }
          else if(event->objInst == KEY_BUTTON1) // right button
          {
+			mHideCursorBecauseOfTouch = false;
             if(event->action == SI_MAKE)
             {
                U32 curTime = Platform::getVirtualMilliseconds();
@@ -517,6 +557,7 @@ bool GuiCanvas::processInputEvent(const InputEvent *event)
          }
          else if(event->objInst == KEY_BUTTON2) // middle button
          {
+			 mHideCursorBecauseOfTouch = false;
             if(event->action == SI_MAKE)
             {
                U32 curTime = Platform::getVirtualMilliseconds();
@@ -1317,7 +1358,7 @@ void GuiCanvas::renderFrame(bool preRenderOnly, bool bufferSwap /* = true */)
       //   helpCtrl->render(srf);
       //}
 
-      if (cursorON && mouseCursor && mShowCursor)
+      if (cursorON && mouseCursor && mShowCursor && !mHideCursorBecauseOfTouch)
       {
          Point2I pos((S32)cursorPt.x, (S32)cursorPt.y);
          Point2I spot = mouseCursor->getHotSpot();

+ 6 - 0
engine/source/gui/guiCanvas.h

@@ -136,6 +136,12 @@ protected:
    S32                        mDoubleClickHeight;
    S32                        mDoubleClickTime;
 
+   Point2F					  mPrevMouseMovePosition; ///< Holds the previous position of the mouse the last time a mouse move event was processed.
+   S32						  mTouchDetectionSize; ///< Changes in the x or y position of the mouse greater than this value will could be touch events.
+   bool						  mPotentialTouchEvent; ///< True if the mouse made a jump that looks like a touch event.
+   U8						  mPotentialMouseEventCount; ///< Counts how many small mouse movements have occured in a row that to determine if touch has been abandoned.
+   bool						  mHideCursorBecauseOfTouch; ///< Touch event has been detected. Hide the cursor.
+
    virtual void findMouseControl(const GuiEvent &event);
    virtual void refreshMouseControl();
    /// @}

+ 5 - 1
toybox/AppCore/1/scripts/defaultPreferences.cs

@@ -32,7 +32,7 @@ $pref::iOS::UseMusic            = 0;
 $pref::iOS::UseMoviePlayer      = 0;
 $pref::iOS::UseAutoRotate       = 1;
 $pref::iOS::EnableOrientationRotation = 1;
-$pref::iOS::EnableOtherOrientationRotation = 1;   
+$pref::iOS::EnableOtherOrientationRotation = 1;
 $pref::iOS::StatusBarType       = 0;
 
 /// Audio
@@ -69,3 +69,7 @@ $pref::OpenGL::gammaCorrection = 0.5;
 
 /// Fonts.
 $Gui::fontCacheDirectory = expandPath( "^AppCore/fonts" );
+
+// Gui
+$pref::Gui::noClampTorqueCursorToWindow = 1;
+$pref::Gui::hideCursorWhenTouchEventDetected = 1;