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
Right click events on tree items & hiding context menues
Moderators: CEGUI MVP, CEGUI Team
- 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
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.
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.
Useful Links: Forum Guidelines | Documentation | Tutorials | HOWTO | Videos | Donate to CEGUI | CEGUI Twitter
Re: Right click events on tree items & hiding context menues
I implemented right click for tree items quite easily by just adding an event and adding a few extra lines in selection detection code.
- 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
Cool. I'm glad you found it easy - since I did not want to have to look at the tree code any more
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.
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.
Useful Links: Forum Guidelines | Documentation | Tutorials | HOWTO | Videos | Donate to CEGUI | CEGUI Twitter
Who is online
Users browsing this forum: No registered users and 16 guests