Using CEGUI in SFML is easy, you just use CEGUI::OpenGLRenderer.
Here's a screenshot:
http://i107.photobucket.com/albums/m300/silentdae/sfmlCEGUI.jpgThe tutorials on the CEGUI website apply to SFML as well.
http://www.cegui.org.uk/wiki/index.php/TutorialsHere's a quick introduction though:
This part isn't SFML specific.
If you haven't already, download the SDK.
You may need to copy CEGUI-SDK\RendererModules\OpenGLGUIRenderer\*.h to CEGUI-SDK\include.
If you're not linking to the static CEGUI libs, you'll want to copy some DLLs to your app folder:
CEGUIBase.dll
CEGUIDevILImageCodec.dll
CEGUIExpatParser.dll
CEGUIFalagardWRBase.dll
CEGUISILLYImageCodec.dll
OpenGLGUIRenderer.dll
SILLY.dll
Plus the debug (CEGUIBase_d.dll, etc) versions as well.
The code from the screenshot was:
CEGUI::OpenGLRenderer* CEGUIRenderer = new OpenGLRenderer(0);
CEGUI::System* CEGUISystem = new System(CEGUIRenderer);
CEGUI::Window* RootWindow;
SchemeManager::getSingleton().loadScheme("WindowsLook.scheme");
FontManager::getSingleton().createFont("DejaVuSans-10.font");
CEGUISystem->setDefaultMouseCursor("WindowsLook", "MouseArrow");
CEGUISystem->setDefaultTooltip("WindowsLook/Tooltip");
CEGUI::WindowManager& WindowMgr = WindowManager::getSingleton();
RootWindow = WindowMgr.createWindow("WindowsLook/Static");
RootWindow->setProperty("FrameEnabled", "false");
CEGUISystem->setGUISheet(RootWindow);
CEGUI::Window* Dialog = WindowMgr.createWindow("WindowsLook/FrameWindow");
Dialog->setMinSize(UVector2(UDim(0, 400),UDim(0, 300)));
Dialog->setText("Window");
RootWindow->addChildWindow(Dialog);
That's all before your render loop.
Then, in your render loop add:
CEGUI::System::getSingleton().renderGUI();
Before your call to SFML's Window::Display().
To run that, you'll also need to have these files (from CEGUI-SDK/Samples/datafiles) in your app folder:
WindowsLook.scheme
WindowsLookWidgets.scheme
WindowsLook.tga
WindowsLook.imageset
DejaVuSans-10.font
DejaVuSans.ttf
WindowsLook.looknfeel
You'll also want to inject inputs into CEGUI.
Here's some code for that:
while (Window.GetEvent(Event))
{
switch (Event.Type)
{
case sf::Event::KeyPressed:
CEGUI::System::getSingleton().injectKeyDown(Event.Key.Code);
CEGUI::System::getSingleton().injectChar(Event.Text.Unicode);
break;
case sf::Event::KeyReleased:
CEGUI::System::getSingleton().injectKeyUp(Event.Key.Code);
break;
case sf::Event::MouseMoved:
CEGUI::System::getSingleton().injectMousePosition(Window.GetInput().GetMouseX(), Window.GetInput().GetMouseY());
break;
case sf::Event::MouseButtonPressed:
switch (Event.MouseButton.Button)
{
case sf::Mouse::Left:
CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::LeftButton);
break;
case sf::Mouse::Middle:
CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::MiddleButton);
break;
case sf::Mouse::Right:
CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::RightButton);
break;
}
break;
case sf::Event::MouseButtonReleased:
switch (Event.MouseButton.Button)
{
case sf::Mouse::Left:
CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::LeftButton);
break;
case sf::Mouse::Middle:
CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::MiddleButton);
break;
case sf::Mouse::Right:
CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::RightButton);
break;
}
break;
case sf::Event::MouseWheelMoved:
CEGUI::System::getSingleton().injectMouseWheelChange(Event.MouseWheel.Delta);
break;
}
}
Finally, I think that's all.
It takes a bit to get it all set up but it's worth it.
Sure beats writing your own GUI.