How can i make a context menu with cegui ?
----------------------------------
ITS RESOLVED, THANKS FOR CE'S HELP!
make context menu with cegui[resolved]
Moderators: CEGUI MVP, CEGUI Team
-
- Not too shy to talk
- Posts: 30
- Joined: Wed Nov 01, 2006 05:59
- Contact:
make context menu with cegui[resolved]
Last edited by silenttree on Thu Nov 02, 2006 15:02, edited 2 times in total.
- CrazyEddie
- CEGUI Project Lead
- Posts: 6760
- Joined: Wed Jan 12, 2005 12:06
- Location: England
- Contact:
Ok, this is a complete example, but be aware that for real world usage, there are various things that you'd need to add to make it more robust and/or usable
Consider this initialisation code:
The handler for the mouse button is this, though would normally have some checks to make sure the window is the one with the context menu (you could set a user-string on the Window with the name of the context menu window and handle things that way).
The is the layout (context_menu.layout) - though this could easily be created in code.
HTH
CE.
Consider this initialisation code:
Code: Select all
void initialise()
{
using namespace CEGUI;
// load some of the base files.
SchemeManager::getSingleton().loadScheme("TaharezLook.scheme");
System::getSingleton().setDefaultMouseCursor("TaharezLook", "MouseArrow");
FontManager::getSingleton().createFont("Commonwealth-10.font");
WindowManager& winMgr = WindowManager::getSingleton();
// create the root window and set it as active sheet.
DefaultWindow* root = (DefaultWindow*)winMgr.createWindow("DefaultWindow", "root");
System::getSingleton().setGUISheet(root);
// create a frame window and add it to the active sheet.
FrameWindow* wnd = (FrameWindow*)winMgr.createWindow("TaharezLook/FrameWindow", "frame_window");
wnd->setPosition(UVector2(cegui_reldim(0.25f), cegui_reldim( 0.25f)));
wnd->setSize(UVector2(cegui_reldim(0.5f), cegui_reldim( 0.5f)));
root->addChildWindow(wnd);
// set a title for the window.
wnd->setText("Context Menu Example");
// load a menu via a layout and add it to the frame window.
PopupMenu* ctxMenu = (PopupMenu*)winMgr.loadWindowLayout("context_menu.layout");
wnd->addChildWindow(ctxMenu);
// attach handler to process the mouse button up events.
wnd->subscribeEvent( Window::EventMouseButtonUp, &myMouseHandler);
}
The handler for the mouse button is this, though would normally have some checks to make sure the window is the one with the context menu (you could set a user-string on the Window with the name of the context menu window and handle things that way).
Code: Select all
bool myMouseHandler(const CEGUI::EventArgs& args)
{
using namespace CEGUI;
// convert event to MouseEventArgs
const MouseEventArgs& ma =
static_cast<const MouseEventArgs&>(args);
// was it the right mouse button?
if (ma.button == RightButton)
{
UVector2 popup_pos;
// get x position of mouse as UDim absolute position within the
// window
popup_pos.d_x = cegui_absdim(
CoordConverter::screenToWindowX(*ma.window, ma.position.d_x));
// get y position of mouse as UDim absolute position within the
// window
popup_pos.d_y = cegui_absdim(
CoordConverter::screenToWindowY(*ma.window, ma.position.d_y));
// get pointer to the context menu window.
Window* ctxmenu = WindowManager::getSingleton().getWindow("ctxmenu");
// set position of menu so it's around where the mouse was clicked.
ctxmenu->setPosition( popup_pos );
// show the menu.
ctxmenu->show();
// event was handled.
return true;
}
// event was not handled.
return false;
}
The is the layout (context_menu.layout) - though this could easily be created in code.
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<GUILayout>
<Window Type="TaharezLook/PopupMenu" Name="ctxmenu">
<Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{0,128},{0,300}}" />
<Window Type="TaharezLook/MenuItem" >
<Property Name="Text" Value="Cut" />
</Window>
<Window Type="TaharezLook/MenuItem" >
<Property Name="Text" Value="Copy" />
</Window>
<Window Type="TaharezLook/MenuItem" >
<Property Name="Text" Value="Paste" />
</Window>
<Window Type="TaharezLook/MenuItem" >
<Property Name="Text" Value="Select All" />
</Window>
</Window>
</GUILayout>
HTH
CE.
-
- Not too shy to talk
- Posts: 30
- Joined: Wed Nov 01, 2006 05:59
- Contact:
-
- Not too shy to talk
- Posts: 30
- Joined: Wed Nov 01, 2006 05:59
- Contact:
Who is online
Users browsing this forum: No registered users and 33 guests