Injecting absolute mouse movements
Posted: Fri Oct 08, 2004 05:46
It would be good to support injecting absolute mouse movements.
I need this because I want to use Window's mouse messages to manipulate the GUI which gives absolute positions. I have already added an injectMouseMoveAbsolute(...) method based off of injectMouseMove(...) to System so here is the code:
In CEGUISystem.h after injectMouseMove(...):
In CEGUISystem.cpp after injectMouseMove(...):
I need this because I want to use Window's mouse messages to manipulate the GUI which gives absolute positions. I have already added an injectMouseMoveAbsolute(...) method based off of injectMouseMove(...) to System so here is the code:
In CEGUISystem.h after injectMouseMove(...):
Code: Select all
/*!
\brief
Method that injects an absolute mouse movement event into the system
\param abs_x
position the mouse moved to on the x axis.
\param abs_y
position the mouse moved to on the y axis.
\return
- true if the input was processed by the gui system.
- false if the input was not processed by the gui system.
*/
bool injectMouseMoveAbsolute(float abs_x, float abs_y);
In CEGUISystem.cpp after injectMouseMove(...):
Code: Select all
/*************************************************************************
Method that injects an absolute mouse movement event into the system
*************************************************************************/
bool System::injectMouseMoveAbsolute(float abs_x, float abs_y)
{
MouseEventArgs ma(NULL);
MouseCursor& mouse = MouseCursor::getSingleton();
ma.position.d_x = abs_x * d_mouseScalingFactor;
ma.position.d_y = abs_y * d_mouseScalingFactor;
ma.wheelChange = 0;
// move the mouse cursor & update position in args.
mouse.setPosition(ma.position);
ma.position = mouse.getPosition();
Window* dest_window = getTargetWindow(ma.position);
// if there is no GUI sheet, then there is nowhere to send input
if (dest_window != NULL)
{
if (dest_window != d_wndWithMouse)
{
if (d_wndWithMouse != NULL)
{
ma.window = d_wndWithMouse;
d_wndWithMouse->onMouseLeaves(ma);
}
d_wndWithMouse = dest_window;
ma.window = dest_window;
dest_window->onMouseEnters(ma);
}
// ensure event starts as 'not handled'
ma.handled = false;
// loop backwards until event is handled or we run out of windows.
while ((!ma.handled) && (dest_window != NULL))
{
ma.window = dest_window;
dest_window->onMouseMove(ma);
dest_window = dest_window->getParent();
}
}
return ma.handled;
}