(Solved) Mouse moving/clicking when over CEGUI window

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

mboeni
Not too shy to talk
Not too shy to talk
Posts: 38
Joined: Wed Sep 08, 2010 16:02

(Solved) Mouse moving/clicking when over CEGUI window

Postby mboeni » Thu Sep 16, 2010 11:46

I have started a discussion on how to check whether the mouse is over an UI element in the Ogre forums but i think, a cegui pro can shed more light on this :)

Please check out the thread:
http://www.ogre3d.org/forums/viewtopic.php?f=2&t=60341

How is this properly done? I need to be able to differentiate between UI click/drags (e.g. dragging a window around) and manipulating the Ogre scene.

Cheers,
Michael
Last edited by mboeni on Thu Sep 23, 2010 10:38, edited 1 time in total.

ianstangoe
Quite a regular
Quite a regular
Posts: 79
Joined: Wed Jan 09, 2008 11:06

Re: Mouse moving/clicking when over CEGUI window

Postby ianstangoe » Thu Sep 16, 2010 12:34

I think setting setMousePassThroughEnabled(true) on all parent windows should eliminate the 'always over a gui element' situation. Set this on all 'Root' windows and mouse events should be ignored except for widgets contained within those parent windows, buttons, images etc..

IR3uL
Not too shy to talk
Not too shy to talk
Posts: 45
Joined: Wed Aug 25, 2010 00:32
Location: Buenos Aires - Argentina

Re: Mouse moving/clicking when over CEGUI window

Postby IR3uL » Thu Sep 16, 2010 14:19


mboeni
Not too shy to talk
Not too shy to talk
Posts: 38
Joined: Wed Sep 08, 2010 16:02

Re: Mouse moving/clicking when over CEGUI window

Postby mboeni » Mon Sep 20, 2010 19:31

No, I have not tried that yet - but will do so this evening - thanks for the tip :)

mboeni
Not too shy to talk
Not too shy to talk
Posts: 38
Joined: Wed Sep 08, 2010 16:02

Re: Mouse moving/clicking when over CEGUI window

Postby mboeni » Mon Sep 20, 2010 21:06

Okay, it seems that the problem is that my 'generat0r_MainMenu' DefaultGUISheet covers a large portion of the screen:

Code: Select all

<?xml version="1.0" ?>
<GUILayout>
<Window Type="DefaultGUISheet" Name="generat0r_MainMenu">
        <Property Name="UnifiedSize" Value="{{1,0},{1,0}}" />
        <Property Name="UnifiedPosition" Value="{{0,0},{0,0}}" />
        <Window Type="Vanilla/Menubar" Name="generat0r/Menubar">
            <Property Name="UnifiedSize" Value="{{1,0},{0.025,0}}" />
            <Property Name="UnifiedPosition" Value="{{0,0},{0,0}}" />

        <Window Type="Vanilla/MenuItem" Name="generat0r/Menubar/MenuItem1">
            <Property Name="UnifiedSize" Value="{{1,0},{0.025,0}}" />
                    <Property Name="UnifiedPosition" Value="{{0,0},{0,0}}" />
            <Property Name="Text" Value="File" />
         
         <Window Type="Vanilla/PopupMenu" Name="generat0r/Menubar/MenuItem1/PopupMenu1">
                <Property Name="UnifiedSize" Value="{{1,0},{0.1,0}}" />
                <Property Name="UnifiedPosition" Value="{{0,0},{0,0}}" />

            <Window Type="Vanilla/MenuItem" Name="generat0r/Menubar/MenuItem1/PopupMenu1/MenuItem1">
                    <Property Name="UnifiedSize" Value="{{1,0},{0.025,0}}" />
                           <Property Name="UnifiedPosition" Value="{{0,0},{0,0}}" />
                    <Property Name="Text" Value="Exit" />
                </Window>
            </Window>
         
        </Window>

        <Window Type="Vanilla/MenuItem" Name="generat0r/Menubar/MenuItem2">
            <Property Name="UnifiedSize" Value="{{1,0},{0.1,0}}" />
                    <Property Name="UnifiedPosition" Value="{{0,0},{0,0}}" />
            <Property Name="Text" Value="Help" />

            <Window Type="Vanilla/PopupMenu" Name="generat0r/Menubar/MenuItem2/PopupMenu1">
                <Property Name="UnifiedSize" Value="{{1,0},{0.1,0}}" />
                        <Property Name="UnifiedPosition" Value="{{0,0},{0,0}}" />

                <Window Type="Vanilla/MenuItem" Name="generat0r/Menubar/MenuItem2/PopupMenu1/MenuItem1">
                    <Property Name="UnifiedSize" Value="{{1,0},{0.025,0}}" />
                            <Property Name="UnifiedPosition" Value="{{0,0},{0,0}}" />
                    <Property Name="Text" Value="About generat0r" />
                </Window>
            </Window>
        </Window>


        </Window>
</Window>
</GUILayout>


Especially the following lines suggest that it covers the full screen:

Code: Select all

        <Property Name="UnifiedSize" Value="{{1,0},{1,0}}" />
        <Property Name="UnifiedPosition" Value="{{0,0},{0,0}}" />

When I set the Y scaling to something less than 1, say 0.5, the menu gets cut half and the element covers 50% of the screen. When I set it to exactly 1, all of the screen is covered by this UI element.

Additional observation: When I click on an MenuItem, then, from that time on, the MenuItem 'covers' all of the screen. Very strange.

Perhaps im testig this wrong. I am doing this for testing:

Code: Select all

   CEGUI::WindowManager& wmgr = CEGUI::WindowManager::getSingleton();
   CEGUI::System &sys = CEGUI::System::getSingleton();
   CEGUI::Window* guiW = wmgr.getWindow("uiRoot");

   std::string s1 = "UI Element under mouse: " ;
   CEGUI::Window* mWin = sys.getWindowContainingMouse();
   std::string s2 = mWin->getName().c_str();
    std::string s3 = s1 + s2;

   mTrayMgr->showOkDialog("UI Element Message", s3);



Does anyone have an idea whats wrong?

Thanks & cheers,
Michael

mboeni
Not too shy to talk
Not too shy to talk
Posts: 38
Joined: Wed Sep 08, 2010 16:02

Re: Mouse moving/clicking when over CEGUI window

Postby mboeni » Mon Sep 20, 2010 22:11

I have also tried ianstangoe's suggestion:

Code: Select all

   CEGUI::Window *mainMenu = wmgr.loadWindowLayout("g0_mainmenu.layout");
   mainMenu->setMousePassThroughEnabled(true);
   uiRoot->addChildWindow(mainMenu);


This DOES help, but for the mainmenu only. It does not help with the "MenuItem" phenomenon described above.

I dont assume that i have to activate this on each element so I must be doing something in the layouts fundamentally wrong...

Anyone?

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

Re: Mouse moving/clicking when over CEGUI window

Postby CrazyEddie » Tue Sep 21, 2010 09:46

Ok. If I understand the issue correctly, it is the classic case that you need to differentiate between when a mouse event occurred over some GUI element and when it occurs over the play field?

In this case, the correct way to deal with the situation is as follows:

1) Your root window(s) need to have the MousePassThroughEnabled property set to "True" (this also holds for other transparent 'DefaultWindow' instances you may be using for grouping or what have you)
2) You need to check the returned bool from the CEGUI::System::inject* calls. If these return true, it means CEGUI handled the input so you should do no further processing for that input event (unless you want something odd / unusual). If the inject function returns false, it means that CEGUI did not handle the input and you should proceed to do whatever processing you want as required by the rest of your app.

HTH

CE.

mboeni
Not too shy to talk
Not too shy to talk
Posts: 38
Joined: Wed Sep 08, 2010 16:02

Re: Mouse moving/clicking when over CEGUI window

Postby mboeni » Wed Sep 22, 2010 16:27

I set the uiRoot to passthrough and added the following to my mouse handling:

Code: Select all

bool BaseApplication::mouseMoved( const OIS::MouseEvent &arg )
{

   CEGUI::System &sys = CEGUI::System::getSingleton();

   if(sys.injectMousePosition(arg.state.X.abs, arg.state.Y.abs)) //If true the CEGUI needs to handle it !
   {
      // Scroll wheel.
      if (arg.state.Z.rel)
         sys.injectMouseWheelChange(arg.state.Z.rel / 120.0f);

   }
   else
   {
      if (mTrayMgr->injectMouseMove(arg)) return true;
      mCameraMan->injectMouseMove(arg);
   }

   return true;
}

bool BaseApplication::mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id )
{


   if( ! CEGUI::System::getSingleton().injectMouseButtonDown(convertButton(id))) // if this is true, CEGUI handled the mouse so ogre does not need to!
   {
      if (mTrayMgr->injectMouseDown(arg, id)) return true;
      mCameraMan->injectMouseDown(arg, id);
   }
   return true;
}

bool BaseApplication::mouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id )
{
   if( ! CEGUI::System::getSingleton().injectMouseButtonDown(convertButton(id))) // if this is true, CEGUI handled the mouse so ogre does not need to!
   {
      if (mTrayMgr->injectMouseUp(arg, id)) return true;
      mCameraMan->injectMouseUp(arg, id);
   }
   return true;
}


and this is how i create the elements:

Code: Select all

   CEGUI::WindowManager& wmgr = CEGUI::WindowManager::getSingleton();
   uiRoot = wmgr.createWindow( "DefaultWindow", "uiRoot" );
   uiRoot->setMousePassThroughEnabled(true);
   CEGUI::System::getSingleton().setGUISheet(uiRoot);
   
   CEGUI::Window *mainMenu = wmgr.loadWindowLayout("g0_mainmenu.layout");
   
   uiRoot->addChildWindow(mainMenu);


Now, every click i do anywhere triggers the 'help-about' menuitem (which is the last window in my mainmenu layout).

Just to make sure it's not the layouts:
Mainmenu layout:

Code: Select all

<?xml version="1.0" ?>
<GUILayout>

    <Window Type="Vanilla/Menubar" Name="generat0r/Menubar">
            <Property Name="UnifiedSize" Value="{{1,0},{0.025,0}}" />
            <Property Name="UnifiedPosition" Value="{{0,0},{0,0}}" />

         <Window Type="Vanilla/MenuItem" Name="generat0r/Menubar/MenuItem1">
            <Property Name="UnifiedSize" Value="{{1,0},{0.025,0}}" />
                    <Property Name="UnifiedPosition" Value="{{0,0},{0,0}}" />
            <Property Name="Text" Value="File" />
         
         <Window Type="Vanilla/PopupMenu" Name="generat0r/Menubar/MenuItem1/PopupMenu1">
                <Property Name="UnifiedSize" Value="{{1,0},{0.1,0}}" />
                <Property Name="UnifiedPosition" Value="{{0,0},{0,0}}" />

            <Window Type="Vanilla/MenuItem" Name="generat0r/Menubar/MenuItem1/PopupMenu1/MenuItem1">
                    <Property Name="UnifiedSize" Value="{{1,0},{0.025,0}}" />
                           <Property Name="UnifiedPosition" Value="{{0,0},{0,0}}" />
                    <Property Name="Text" Value="Exit" />
                </Window>
            </Window>
         
         </Window>

        <Window Type="Vanilla/MenuItem" Name="generat0r/Menubar/MenuItem2">
            <Property Name="UnifiedSize" Value="{{1,0},{0.1,0}}" />
                    <Property Name="UnifiedPosition" Value="{{0,0},{0,0}}" />
            <Property Name="Text" Value="Help" />

            <Window Type="Vanilla/PopupMenu" Name="generat0r/Menubar/MenuItem2/PopupMenu1">
                <Property Name="UnifiedSize" Value="{{1,0},{0.1,0}}" />
                        <Property Name="UnifiedPosition" Value="{{0,0},{0,0}}" />

                <Window Type="Vanilla/MenuItem" Name="generat0r/Menubar/MenuItem2/PopupMenu1/MenuItem1">
                    <Property Name="UnifiedSize" Value="{{1,0},{0.025,0}}" />
                            <Property Name="UnifiedPosition" Value="{{0,0},{0,0}}" />
                    <Property Name="Text" Value="About generat0r" />
                </Window>
            </Window>
        </Window>



    </Window>
</GUILayout>


and the aboutDialog

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<GUILayout >
        <Window Type="Vanilla/FrameWindow" Name="generat0r/AboutDialog" >
            <Property Name="Text" Value="About generat0r" />
            <Property Name="TitlebarFont" Value="Arial-14" />
            <Property Name="TitlebarEnabled" Value="True" />
            <Property Name="CloseButtonEnabled" Value="False" />
            <Property Name="SizingEnabled" Value="False" />         
            <Property Name="UnifiedAreaRect" Value="{{0.015,0},{0.015,0},{0.45,0},{0.40,0}}" />
            <Property Name="UnifiedPosition" Value="{ {0.25, 0}, {0.25, 0} }" />
            <Window Type="Vanilla/StaticText" Name="generat0r/AboutDialog/StaticText" >
                <Property Name="Text" Value="Demonstrates static (non editable) text. Use the controls on your right for formatting options." />
                <Property Name="HorzExtent" Value="361" />
                <Property Name="VertExtent" Value="59.5854" />
                <Property Name="HorzFormatting" Value="WordWrapLeftAligned" />
                <Property Name="VertFormatting" Value="TopAligned" />
                <Property Name="UnifiedAreaRect" Value="{{0.03,0},{0.03,0},{0.97,0},{0.85,0}}" />
            </Window>
            <Window Type="Vanilla/Button" Name="generat0r/AboutDialog/CloseButton" >
                <Property Name="Text" Value="Close" />
                <Property Name="UnifiedAreaRect" Value="{{0.42,0},{0.88,0},{0.60,0},{0.955,0}}" />
            </Window>

        </Window>
</GUILayout>


Anyone?

Cheers,
Michael

IR3uL
Not too shy to talk
Not too shy to talk
Posts: 45
Joined: Wed Aug 25, 2010 00:32
Location: Buenos Aires - Argentina

Re: Mouse moving/clicking when over CEGUI window

Postby IR3uL » Wed Sep 22, 2010 17:42

mboeni wrote:

Code: Select all

bool BaseApplication::mouseMoved( const OIS::MouseEvent &arg )
{

   CEGUI::System &sys = CEGUI::System::getSingleton();

   if(sys.injectMousePosition(arg.state.X.abs, arg.state.Y.abs)) //If true the CEGUI needs to handle it !
   {
      // Scroll wheel.
      if (arg.state.Z.rel)
         sys.injectMouseWheelChange(arg.state.Z.rel / 120.0f);

   }
   else
   {
      if (mTrayMgr->injectMouseMove(arg)) return true;
      mCameraMan->injectMouseMove(arg);
   }

   return true;
}



All the code looks ok to me, the only "weird" thing i notice is in this snippet. I don't know what kind of application are you working on, but for my experience an FPS is not the same as an RTS game.

In an RTS one would normally use a cursor all the time, so you can click in the level ground, and also interact with the gui stuff around, but in an FPS this behavior is not needed/wanted, and the usual approach is to take deltas from the center of the screen, and restore the cursor position there once you are done with them (This is not always the case but i think it is the most used method).

So, in the first case (RTS-like), you should inject the position always, but in the other (FPS-like) you don't need it, and you can make a test like if(hascursor) move_gui_cursor(); else move_camera();

Maybe a use case can give me some light =).

Btw, why are you using 2 gui systems? Isn't SdkTrays designed to create simple GUIs for samples?

mboeni
Not too shy to talk
Not too shy to talk
Posts: 38
Joined: Wed Sep 08, 2010 16:02

Re: Mouse moving/clicking when over CEGUI window

Postby mboeni » Wed Sep 22, 2010 17:55

Its not a game at all ;) generat0r is a VJing system used in clubs, company presentations, video shows, etc. It can react to music, take midi input and such. Having this in 3D space allows for a great deal of neat effects that i can use along with simple generative art, videos and such (compositing of 3d objects, particle systems, etc)

SDKTrays is just used for some debugging as it is very fast/convenient for that, it will not make it into the release version.

Clearer now? :)

Cheerio,
Michael

IR3uL
Not too shy to talk
Not too shy to talk
Posts: 45
Joined: Wed Aug 25, 2010 00:32
Location: Buenos Aires - Argentina

Re: Mouse moving/clicking when over CEGUI window

Postby IR3uL » Wed Sep 22, 2010 18:05

Not really, for what i know so far you can enter different rooms to change a song and fade between them according to the distance (FPS-like), or maybe drag over the 3d scene to make some scratching (RPG-like) =D

btw, sounds like a cool app.

mboeni
Not too shy to talk
Not too shy to talk
Posts: 38
Joined: Wed Sep 08, 2010 16:02

Re: Mouse moving/clicking when over CEGUI window

Postby mboeni » Wed Sep 22, 2010 18:20

Think of it more like an editor in 3d space with gui elements in it (i call this the construct). This is where the VJ sets up his/her scene, adds effects and such. The output (withouth the grid / UI elements, etc) is shown in another viewport (usually another monitor, beamer, etc).

So what i want is this: When the mouse is over an Ui element, the CEGUI should handle the mouse and not ogre. When the mouse is over the scene, i want ogre to get the mouse stuff.

Just imagine an 'about' dialog which I click/drag at its title and move it around. Currently, this also moves (rotates) the scene behind the about dialog - I dont want that. I just want the dialog to move (i.e. inject the mouse dragging only to CEGUI and not ogre) :)

Yes, i'ts really cool to work on it, but tons of challenges to solve ;)

IR3uL
Not too shy to talk
Not too shy to talk
Posts: 45
Joined: Wed Aug 25, 2010 00:32
Location: Buenos Aires - Argentina

Re: Mouse moving/clicking when over CEGUI window

Postby IR3uL » Wed Sep 22, 2010 18:37

I'll make a few tests and come back to you (tomorrow morning if time is by my side today =/).

Edit:
Hi Michael, i had time today and i was able to make those tests, but i'm not able to reproduce the behavior of your application. If you've followed all the recommendations given in this post you should be able to get the app work as expected (as i did), so, take a closer look at your code (a debugger might help :rofl: ) because the problem seems to be somewhere else (or i'm blind hehe). If you can't find the problem PM me and i'll give you my email so you can send me your code (or upload it somewhere and give me the link). Sry i can't do much more.

Cya =D

mboeni
Not too shy to talk
Not too shy to talk
Posts: 38
Joined: Wed Sep 08, 2010 16:02

Re: Mouse moving/clicking when over CEGUI window

Postby mboeni » Thu Sep 23, 2010 10:35

Hiho

Actually i wrote my own debugging code for this issue. That helped a bit, but did not lead to the solution (try and error did ;) )

I have achieved success, though, last night (hooray!). The actual solution was to get the 'mix' of the posted ideas just right (like in a puzzle). None of the concepts worked as such but the right mix did ;)

Here's a summary of what I did (feel free to post/PM me for details):
1. Remove the 'defaultWindows' in MainMenu and Aboutdialog
2. Set the uiRoot to passthrough (uiRoot->setMousePassThroughEnabled(true);)
3. Write a function that checks whether the mouse is over an UI element:

Code: Select all

bool Utility::isMouseOverUI()
{
    bool condition = false;
   CEGUI::WindowManager& wmgr = CEGUI::WindowManager::getSingleton();
   CEGUI::System &sys = CEGUI::System::getSingleton();
   CEGUI::Window* guiW = wmgr.getWindow("uiRoot");

   if(sys.getWindowContainingMouse()!=guiW) //this means the mouse is over any UI element 
      condition = true;
   return condition;
}


4. Add this check to 'mousePressed' like so:

Code: Select all

bool BaseApplication::mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id )
{
   if(Utility::isMouseOverUI()) 
   {
     CEGUI::System::getSingleton().injectMouseButtonDown(convertButton(id));
   }
   else
   {
     if (mTrayMgr->injectMouseDown(arg, id)) return true;
     mCameraMan->injectMouseDown(arg, id);
   }
   return true;
}


mouse released:

Code: Select all

if (mTrayMgr->injectMouseUp(arg, id)) return true;
mCameraMan->injectMouseUp(arg, id);
CEGUI::System::getSingleton().injectMouseButtonUp(convertButton(id));
return true;


mouse moved:

Code: Select all

   if (mTrayMgr->injectMouseMove(arg)) return true;
   mCameraMan->injectMouseMove(arg);
   CEGUI::System &sys = CEGUI::System::getSingleton();
   sys.injectMousePosition(arg.state.X.abs, arg.state.Y.abs);
   // Scroll wheel.
   if (arg.state.Z.rel)
   sys.injectMouseWheelChange(arg.state.Z.rel / 120.0f);
   return true;


This works as expected (for now ;) )

Cheerio,
michael

IR3uL
Not too shy to talk
Not too shy to talk
Posts: 45
Joined: Wed Aug 25, 2010 00:32
Location: Buenos Aires - Argentina

Re: (Solved) Mouse moving/clicking when over CEGUI window

Postby IR3uL » Thu Sep 23, 2010 15:46

I'm glad you fixed it =D


Return to “Help”

Who is online

Users browsing this forum: No registered users and 29 guests