Game Development Community

dev|Pro Game Development Curriculum

Fix Strange position on window focus

by Brandon Maness · 05/08/2005 (3:29 pm) · 3 comments

We only needed to skip the first render frame when the app gains focus again, so I just used an additional variable to keep track of that first frame.

Go to your .\engine\platformWin32\winWindow.cc file and make these changes:

At the start of winWindow.cc add this variable.

static BYTE keyboardState[256];
static bool mouseButtonState[3];
static bool capsLockDown = false;
static S32 modifierKeys = 0;
static bool windowActive = true;

//----Addition here
static bool windowNotActive = false;
//----

static Point2I lastCursorPos(0,0);
static Point2I windowSize;
static HANDLE gMutexHandle = NULL;


Now go to the setMouseClipping code block around line 150 and make these changes:

S32 centerX = (r.right + r.left) >> 1;
         S32 centerY = (r.bottom + r.top) >> 1;
         //<---- Add the IF switch to the SetCursorPos routine
         if(!windowNotActive) SetCursorPos(centerX, centerY);
         //<----
      }
      else
         //<---- Add the IF switch to the SetCursorPos Here also!
         if(!windowNotActive) SetCursorPos(lastCursorPos.x + r.left, lastCursorPos.y + r.top);
         //<----
   }

Then go to the windowProc code block around line 500 and make these changes to the WM_ACTIVATE code block:

case WM_ACTIVATE:
         windowActive = LOWORD(wParam) != WA_INACTIVE;
         if ( windowActive )
         {
                        //---- ADD THIS HERE!
			 setMouseClipping();
			 windowNotActive = false;
			 //---- END CHANGE

            Game->refreshWindow();
            Input::activate();
         }
         else
         {
                         //---- CHANGES HERE
			 setMouseClipping();
			 windowNotActive = true;
			 //----END CHANGES

            DInputManager* mgr = dynamic_cast<DInputManager*>( Input::getManager() );
            if ( !mgr || !mgr->isMouseActive() )
            {             
               // Deactivate all the mouse triggers:
               for ( U32 i = 0; i < 3; i++ )
               {
                  if ( mouseButtonState[i] )
                     mouseButtonEvent( SI_BREAK, KEY_BUTTON0 + i );
               }
            }
            Input::deactivate();
         }

         //---- COMMENT THIS LINE OUT
         //setMouseClipping();
         //----

         break;

Ok, so with this fix we don

#1
05/09/2005 (12:43 am)
Cool, I'll check it out. This is one of those little things that keep annoying me.

Nick
#2
08/01/2005 (2:27 pm)
nice one :)
#3
06/11/2006 (11:20 pm)
I just did this on TGE 1.3, and I found that it did not work properly until I commented out the line
SetCursorPos(lastCursorPos.x + r.left, lastCursorPos.y + r.top);

from the setMouseClipping() function. Adding the if statement solved the problem for quick clicking, but not clicking and dragging.