Browse Source

Cursor Fix

-Fix: Cursor fix was simpler than thought before :+1:
marauder2k7 5 years ago
parent
commit
8191e1c327

BIN
engine/compilers/VisualStudio 2017/.vs/Torque 2D/v15/Browse.VC.db


+ 10 - 7
engine/source/2d/sceneobject/Path.cc

@@ -11,13 +11,15 @@ PathObject::PathObject():
 {
    mCurrNode = 0;
    mPrevNode = 0;
-   mLoop = true;
+
+   mMaxSpeed = 1.0f;
+   mMaxForce = 3.0f;
    mOrient = false;
+   mAngOff = 0.0f;
    mSnapToNode = false;
-   mLoopCount = 0;
+   mLoop = true;
    mMaxLoop = -1;
-   mMaxSpeed = 1.0f;
-   mAngOff = 0.0f;
+   mLoopCount = 0;
 }
 
 void PathObject::setCurrNode(S32 node)
@@ -141,7 +143,7 @@ S32 Path::addNode(Vector2 pos, F32 distance, F32 weight)
    return nodeCount;
 }
 
-void Path::attachObject(SceneObject * object, F32 speed, bool orientToPath, F32 angleOff, bool snapToNode, S32 startNode, bool loop, S32 maxLoop)
+void Path::attachObject(SceneObject * object, F32 speed, F32 force, bool orientToPath, F32 angleOff, bool snapToNode, S32 startNode, bool loop, S32 maxLoop)
 {
    if (snapToNode)
    {
@@ -156,6 +158,7 @@ void Path::attachObject(SceneObject * object, F32 speed, bool orientToPath, F32
    PathObject *pObj  = new PathObject();
    pObj->mPath       = this;
    pObj->mObj        = object;
+   pObj->mMaxForce   = force;
    pObj->mObjId      = object->getId();
    pObj->mOrient     = orientToPath;
    pObj->mAngOff     = angleOff;
@@ -206,11 +209,11 @@ void Path::moveObject(PathObject& obj)
    dir.Normalize();
 
    F32 maxSpeed = obj.mMaxSpeed;
-   F32 maxForce = 1.2f;
+   F32 maxForce = obj.mMaxForce;
 
    Vector2 steer = seek(cDest, oPos, maxSpeed, currVel, slowRad);
    steer = truncate(steer, maxForce);
-   steer = steer.scale(0.5);
+   steer = steer.scale(0.5f);
    currVel = currVel.add(steer);
    currVel = truncate(currVel.add(steer), maxSpeed);
    Vector2 pos = oPos.add(currVel);

+ 5 - 2
engine/source/2d/sceneobject/Path.h

@@ -17,12 +17,15 @@ private:
    SimObjectPtr<SceneObject> mObj;
    SimObjectId mObjId;
    F32 mMaxSpeed;
+   bool mOrient;
+   F32 mMaxForce;
    F32 mAngOff;
+   
    S32 mCurrNode;
    S32 mPrevNode;
    S32 mNextNode;
    bool mLoop; 
-   bool mOrient;
+   
    bool mSnapToNode;
    S32 mLoopCount;
    S32 mMaxLoop;
@@ -76,7 +79,7 @@ public:
       if((index >= 0) && (index < mNodes.size())) return true;
    }
 
-   void attachObject(SceneObject* object, F32 speed, bool orientToPath, F32 angleOff, bool snapToNode, S32 startNode, bool loop, S32 maxLoop);
+   void attachObject(SceneObject* object, F32 speed, F32 force, bool orientToPath, F32 angleOff, bool snapToNode, S32 startNode, bool loop, S32 maxLoop);
 
    void detachObject(SceneObject* object);
 

+ 21 - 14
engine/source/2d/sceneobject/Path_ScriptBinding.h

@@ -19,7 +19,7 @@
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 // IN THE SOFTWARE.
 //-----------------------------------------------------------------------------
-ConsoleMethodWithDocs(Path, attachObject, ConsoleVoid, 4, 10, (sceneObject, float speed, [bool orient], [float angOff], [bool snapToNode],[integer startNode],[bool loop],[integer maxLoop]))
+ConsoleMethodWithDocs(Path, attachObject, ConsoleVoid, 4, 11, (sceneObject, float speed,[float force], [bool orient], [float angOff], [bool snapToNode],[integer startNode],[bool loop],[integer maxLoop]))
 {
    // Set Group.
    SceneObject* pSceneObject = dynamic_cast<SceneObject*>(Sim::findObject(argv[2]));
@@ -33,43 +33,50 @@ ConsoleMethodWithDocs(Path, attachObject, ConsoleVoid, 4, 10, (sceneObject, floa
 
    F32 speed = dAtof(argv[3]);
 
-   bool orient = false;
+   F32 force = 3.0f;
+
    if (argc > 4)
    {
-      orient = dAtob(argv[4]);
+      force = dAtof(argv[4]);
    }
 
-   F32 angleOff = 0.0f;
+   bool orient = false;
    if (argc > 5)
    {
-      angleOff = dAtof(argv[5]);
+      orient = dAtob(argv[5]);
    }
 
-   bool snapToNode = false;
+   F32 angleOff = 0.0f;
    if (argc > 6)
    {
-      snapToNode = dAtob(argv[6]);
+      angleOff = dAtof(argv[6]);
    }
 
-   S32 startNode = 0;
+   bool snapToNode = false;
    if (argc > 7)
    {
-      startNode = dAtoi(argv[7]);
+      snapToNode = dAtob(argv[7]);
    }
 
-   bool loop = true;
+   S32 startNode = 0;
    if (argc > 8)
    {
-      loop = dAtob(argv[8]);
+      startNode = dAtoi(argv[8]);
    }
 
-   S32 maxLoop = 0;
+   bool loop = true;
    if (argc > 9)
    {
-      maxLoop = dAtoi(argv[9]);
+      loop = dAtob(argv[9]);
+   }
+
+   S32 maxLoop = 0;
+   if (argc > 10)
+   {
+      maxLoop = dAtoi(argv[10]);
    }
 
-   object->attachObject(pSceneObject, speed, orient, angleOff, snapToNode, startNode, loop, maxLoop);
+   object->attachObject(pSceneObject, speed, force, orient, angleOff, snapToNode, startNode, loop, maxLoop);
 
 }
 

+ 4 - 4
engine/source/gui/guiCanvas.cc

@@ -58,7 +58,7 @@ GuiCanvas::GuiCanvas()
 
    cursorON    = true;
    mShowCursor = false;
-   //mUseNativeCursor = true;
+   mUseNativeCursor = true;
 
    lastCursorON = false;
    rLastFrameTime = 0.0f;
@@ -137,7 +137,7 @@ void GuiCanvas::setCursorON(bool onOff)
       mMouseControl = NULL;
 }
 
-/*bool GuiCanvas::getUseNativeCursor(void)
+bool GuiCanvas::getUseNativeCursor(void)
 {
    return mUseNativeCursor;
 }
@@ -145,7 +145,7 @@ void GuiCanvas::setCursorON(bool onOff)
 void GuiCanvas::useNativeCursor(bool useNative)
 {
    mUseNativeCursor = useNative;
-}*/
+}
 
 void GuiCanvas::setCursorPos(const Point2I &pt)   
 { 
@@ -1310,7 +1310,7 @@ void GuiCanvas::renderFrame(bool preRenderOnly, bool bufferSwap /* = true */)
       dglSetClipRect(updateUnion);
 
       //temp draw the mouse
-      if (cursorON && mShowCursor && !mouseCursor /*&& Canvas->getUseNativeCursor()*/)
+      if (cursorON && mShowCursor && !mouseCursor && Canvas->getUseNativeCursor())
       {
 #if defined(TORQUE_OS_IOS) || defined(TORQUE_OS_ANDROID) || defined(TORQUE_OS_EMSCRIPTEN)
          glColor4ub(255, 0, 0, 255);

+ 3 - 3
engine/source/gui/guiCanvas.h

@@ -109,7 +109,7 @@ protected:
    GuiCursor   *defaultCursor;
    GuiCursor   *lastCursor;
    bool        lastCursorON;
-   //bool        mUseNativeCursor;
+   bool        mUseNativeCursor;
    /// @}
 
    /// @name Mouse Input
@@ -253,8 +253,8 @@ public:
    /// @param   cursor   New cursor to use.
    virtual void setCursor(GuiCursor *cursor);
 
-   //virtual bool getUseNativeCursor(void);
-   //virtual void useNativeCursor(bool useNative);
+   virtual bool getUseNativeCursor(void);
+   virtual void useNativeCursor(bool useNative);
 
    /// Returns true if the cursor is on.
    virtual bool isCursorON() {return cursorON; }

+ 2 - 2
engine/source/gui/guiCanvas_ScriptBinding.h

@@ -147,9 +147,9 @@ ConsoleMethodWithDocs( GuiCanvas, setCursor, ConsoleVoid, 3, 3, ( cursorHandle )
          return;
       }
    }
-   //Canvas->useNativeCursor(false);
+   Canvas->useNativeCursor(false);
    Canvas->setCursor(curs);
-   //Canvas->showCursor(true);
+   Canvas->showCursor(true);
 }
 
 /*! Returns the cursor to the system default.

+ 4 - 0
engine/source/platformWin32/winWindow.cc

@@ -976,6 +976,10 @@ case WM_MOUSEMOVE:
       Game->postEvent(event);
    }
    break;
+case WM_SETCURSOR:
+   if ((LOWORD(lParam) == HTCLIENT) && !(Canvas->getUseNativeCursor()))
+      SetCursor(NULL);
+   break;
 case WM_LBUTTONDOWN:
    mouseButtonEvent(SI_MAKE, KEY_BUTTON0);
    break;

+ 0 - 2
modules/AppCore/1/main.cs

@@ -38,8 +38,6 @@ function AppCore::create( %this )
     
     // Initialize audio
     initializeOpenAL();
-    Canvas.setCursor(DefaultCursor);
-	Canvas.showCursor();
     ModuleDatabase.loadGroup("gameBase");
 }
 

+ 1 - 1
modules/PathToy/1/main.cs

@@ -66,5 +66,5 @@ function PathToy::createTarget(%this)
     %object.setBodyType( dynamic );
     SandboxScene.add( %object );
 	
-	SquarePath.attachObject(%object, 15.5, true, 90.0);
+	SquarePath.attachObject(%object, 22.5, 3.0, true, 90.0);
 }

+ 0 - 2
modules/Sandbox/1/main.cs

@@ -38,8 +38,6 @@ function Sandbox::create( %this )
 
     // Create the sandbox window.
     CreateSandboxWindow();
-	
-	Canvas.setCursor(DefaultCursor);
     
     // Load and configure the console.
     Sandbox.add( TamlRead("./gui/ConsoleDialog.gui.taml") );