Injecting absolute mouse movements

If you found a bug in our library or on our website, please report it in this section. In this forum you can also make concrete suggestions or feature requests.

Moderators: CEGUI MVP, CEGUI Team

User avatar
ArmaDuck
Just popping in
Just popping in
Posts: 7
Joined: Wed Jan 12, 2005 12:06

Injecting absolute mouse movements

Postby ArmaDuck » 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(...):

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;
}

User avatar
gcarlton
Just can't stay away
Just can't stay away
Posts: 149
Joined: Wed Jan 12, 2005 12:06

Injecting absolute mouse movements

Postby gcarlton » Fri Oct 08, 2004 05:54

This also does the job:

Code: Select all

MouseCursor::getSingleton().setPosition(x, y);
System::getSingleton().injectMouseMove(0.0f, 0.0f);

Not quite as elegant, but it works!

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Injecting absolute mouse movements

Postby CrazyEddie » Fri Oct 08, 2004 08:35

It's a good idea, I'll put it on the list of things to add when I start adding things again :) I do think that the method would be better named "injectMousePosition" though.

The second code snippet posted by Geoff might actually be better, since it reduces code repetition.

Thanks for the suggestion,

CE.

User avatar
jwace81
Not too shy to talk
Not too shy to talk
Posts: 26
Joined: Wed Jan 12, 2005 12:06

Injecting absolute mouse movements

Postby jwace81 » Fri Oct 08, 2004 17:55

I have a similar function for the C# port as well, although currently mine looks much more like ArmaDuck's. I think that I'll change it to be more like gcarlton's solution, and I'll make sure that the name is 'InjectMousePosition' before I commit it.
I needed it for my current work on the plugin for Chronos since the input doesn't always need to be fed to CEGUI.

J.W.

User avatar
ArmaDuck
Just popping in
Just popping in
Posts: 7
Joined: Wed Jan 12, 2005 12:06

Injecting absolute mouse movements

Postby ArmaDuck » Fri Oct 08, 2004 19:27

gcarlton's solution does look a lot better! I'll switch my function and code over to your suggestions. Thanks!


Return to “Bug Reports, Suggestions, Feature Requests”

Who is online

Users browsing this forum: No registered users and 4 guests