Right click events on tree items & hiding context menues

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

Sairon
Not too shy to talk
Not too shy to talk
Posts: 22
Joined: Sun Dec 07, 2008 01:11

Right click events on tree items & hiding context menues

Postby Sairon » Wed Sep 16, 2009 13:35

Hi,

I use the seemingly loated tree widget hehe. Anyway, I have a need to recieve right click events on TreeItems in order to display a context menu, but I can't seem to find any convinient way to implement this functionality neither on the Tree level nor the TreeItem level.

I use right click context menues in some areas and are having problems hiding them when the user clicks outside the context menu. I've tried to use EventDeactivated but it doesn't seem to be sent. Is there perhaps anything I'm missing or is this the correct route but a problem somewhere at my end?

Thanks in advance :)

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

Re: Right click events on tree items & hiding context menues

Postby CrazyEddie » Wed Sep 16, 2009 18:51

Hehe :)

For the right-click, there's no event notifications for tree items so I think you will have to subscribe to Window::EventMouseClick on the tree control itself and then try and determine the item that was clicked. That involves getting the item render area, the scroll bar position, and then working your way through the content to establish what was under the mouse button. You might refer to the tree code in order to see how to do this, especially the getItemAtPoint and getItemFromListAtPoint functions (these are unfortunately have protected access, so you can't just call them).

For the menu, the issue will likely be that the menu itself was not the front-most 'active' window (one of the attached items would have been) and it's that window that receives the deactivation event rather than the containing menu window. I'm not sure of the cleanest way to deal with this at the moment, I'll have a think about it and perhaps post a possible solution tomorrow :)

CE.

Sairon
Not too shy to talk
Not too shy to talk
Posts: 22
Joined: Sun Dec 07, 2008 01:11

Re: Right click events on tree items & hiding context menues

Postby Sairon » Thu Sep 17, 2009 16:33

I implemented right click for tree items quite easily by just adding an event and adding a few extra lines in selection detection code.

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

Re: Right click events on tree items & hiding context menues

Postby CrazyEddie » Thu Sep 17, 2009 19:05

Cool. I'm glad you found it easy - since I did not want to have to look at the tree code any more :lol:

For the context menu issue, first I'll point you to this Wiki page: http://www.cegui.org.uk/wiki/index.php/MenuAndPopup IIRC(!) it shows a menu set up and context menu - so you might find that useful. If that's no good, another thing you can try is to manually capture input to the context menu (and enable captured input distribution), this way your menu will hear about all clicks - even those outside of it's window. What you then do is check any clicks to see if they're within the window area - if not, you close/hide the menu (and release input capture, don't forget to do that!). I've not actually tried this, so you may have issues - let us know if you do, as there's probably a way to fix it :)

CE.


Return to “Help”

Who is online

Users browsing this forum: No registered users and 16 guests