Page 1 of 1

[SOLVED] Pass KeyEventArgs with MouseEventArgs

Posted: Tue Nov 03, 2009 07:03
by Van
CEGUI 0.7.1 SVN Branch

This doesn't seem to be present or we haven't figured out how to do it. We want to be able to scan for a pressed key (like shift) when the user is scrolling the mouse wheel. So far, it doesn't seem to work. We use OIS and we are receiving the SHIFT key modifier and injecting it into the CEGUI system.

Code: Select all

bool clsGUIInvList::event_SpinnerUnits_MouseWheel(const CEGUI::EventArgs& e)
{
   const CEGUI::KeyEventArgs& mKEA = static_cast<const CEGUI::KeyEventArgs&>( e );
   const CEGUI::MouseEventArgs& mMEA = static_cast<const CEGUI::MouseEventArgs&>( e );
   
   // If the user is also pressing the SHIFT key then change the spinner multiplier.
   float mMultiplier = 1.0f, mNewUnits = 0.0f;
   if ( mKEA.sysKeys == CEGUI::SystemKey::Shift ) mMultiplier = 10.0f;
   
   // Only process mouse wheel changes
   if ( mMEA.wheelChange != 0.0f )
   {
      if ( mMEA.wheelChange > 0.0f )
         mNewUnits = mSpinnerUnits->getCurrentValue() + ( mSpinnerUnits->getStepSize() * mMultiplier );
      else
         mNewUnits = mSpinnerUnits->getCurrentValue() - ( mSpinnerUnits->getStepSize() * mMultiplier );

      mSpinnerUnits->setCurrentValue( mNewUnits );
   } // wheelChange?

   return true;
} // event_SpinnerUnits_MouseWheel

Re: [SUG] Pass KeyEventArgs with MouseEventArgs

Posted: Tue Nov 03, 2009 19:19
by Jamarr
The EventArgs object passed to the function does not use multiple inheritance - in other words you cannot just typecast it from one type of EventArgs to another.

Also, CEGUI does not have any support for managing the keyboard and/or mouse state. In otherwords, when you inject input that single event is fired and then forgotten about. Based on this, assuming you want to handle this through CEGUI, you would have to subscribe to EventKeyDown/EventKeyUp and check for Shift and then set your own flag appropriately. Then when EventMouseWheel is fired you'd check said flag.

To address this I suppose CEGUI could store a keyboard state map (up/down state) and make it accessible through CEGUI::System...but then you could just as easily implement the same thing yourself, setting those states at the point you inject them into CEGUI and then checking your own keyboard state map whenever you need to.

Re: [SOLVED] Pass KeyEventArgs with MouseEventArgs

Posted: Wed Nov 04, 2009 21:42
by Van
SOLVED - Implementation already exists in a different form. Great Job CE!

Actually, studying the CEGUI::MouseEventArgs class, there is already a parameter CEGUI::MouseEventArgs::sysKeys holding the current state of CEGUI::SystemKey.
Also may want to note this function: CEGUI::System::getSystemKeys()

Re: [SOLVED] Pass KeyEventArgs with MouseEventArgs

Posted: Thu Nov 05, 2009 17:36
by Jamarr
Nice. Well now I hate you for not looking at MouseEventArgs or the System object before posting; then again, I should have looked at them myself before replying ;)