diff options
Diffstat (limited to 'gui.cpp')
-rw-r--r-- | gui.cpp | 144 |
1 files changed, 144 insertions, 0 deletions
@@ -0,0 +1,144 @@ +#include "gui.h" +#include "video.h" + +#include <boost/format.hpp> + +using namespace CEGUI; + +GUI::GUI() { + OpenGLRenderer::bootstrapSystem(); + DefaultResourceProvider* rp = static_cast<DefaultResourceProvider*> + (System::getSingleton().getResourceProvider()); + + rp->setResourceGroupDirectory("schemes", "GUI/"); + rp->setResourceGroupDirectory("imagesets", "GUI/"); + rp->setResourceGroupDirectory("fonts", "fonts/"); + rp->setResourceGroupDirectory("layouts", "GUI/"); + rp->setResourceGroupDirectory("looknfeels", "GUI/"); + + Imageset::setDefaultResourceGroup("imagesets"); + Font::setDefaultResourceGroup("fonts"); + Scheme::setDefaultResourceGroup("schemes"); + WidgetLookManager::setDefaultResourceGroup("looknfeels"); + WindowManager::setDefaultResourceGroup("layouts"); + + SchemeManager::getSingleton().create( "VanillaSkin.scheme" ); + + FontManager::getSingleton().create("VeraMono.font"); + + System::getSingleton().setDefaultFont( "VeraMono" ); + System::getSingleton().setDefaultMouseCursor( "Vanilla-Images", "MouseArrow" ); + + WindowManager& wmgr(WindowManager::getSingleton()); + + root = wmgr.createWindow("DefaultWindow", "root"); + System::getSingleton().setGUISheet(root); + + wnd = static_cast<FrameWindow*>(wmgr.createWindow("Vanilla/FrameWindow", "foo")); + root->addChildWindow(wnd); + + wnd->setPosition(UVector2(UDim(.25, 0), UDim(.25, 0))); + wnd->setSize(UVector2(UDim(.5, 0), UDim(.5, 0))); + wnd->setText("foobar"); + + btn = static_cast<PushButton*>(wmgr.createWindow("Vanilla/Button", "button")); + wnd->addChildWindow(btn); + + btn->setPosition(UVector2(UDim(0, 0), UDim(.9, 0))); + btn->setSize(UVector2(UDim(.3, 0), UDim(.1, 0))); + btn->setText("buttan"); + + /* radius */ + radius_lbl = wmgr.createWindow("Vanilla/StaticText", "radius_lbl"); + wnd->addChildWindow(radius_lbl); + + radius_lbl->setPosition(UVector2(UDim(0, 0), UDim(0, 0))); + radius_lbl->setSize(UVector2(UDim(.2, 0), UDim(.1, 0))); + radius_lbl->setText("Radius"); + + radius_sb = static_cast<Scrollbar*>(wmgr.createWindow("Vanilla/HorizontalScrollbar", "radius_sb")); + wnd->addChildWindow(radius_sb); + + radius_sb->setPosition(UVector2(UDim(.2, 0), UDim(0, 0))); + radius_sb->setSize(UVector2(UDim(.65, 0), UDim(.1, 0))); + radius_sb->setDocumentSize(50.0); + + radius_sb_lbl = wmgr.createWindow("Vanilla/StaticText", "radius_sb_lbl"); + wnd->addChildWindow(radius_sb_lbl); + + radius_sb_lbl->setPosition(UVector2(UDim(.85, 0), UDim(0, 0))); + radius_sb_lbl->setSize(UVector2(UDim(.15, 0), UDim(.1, 0))); + + /* focus */ + focus_lbl = wmgr.createWindow("Vanilla/StaticText", "focus_lbl"); + wnd->addChildWindow(focus_lbl); + + focus_lbl->setPosition(UVector2(UDim(0, 0), UDim(.1, 0))); + focus_lbl->setSize(UVector2(UDim(.2, 0), UDim(.1, 0))); + focus_lbl->setText("Focus"); + + focus_sb = static_cast<Scrollbar*>(wmgr.createWindow("Vanilla/HorizontalScrollbar", "focus_sb")); + wnd->addChildWindow(focus_sb); + + focus_sb->setPosition(UVector2(UDim(.2, 0), UDim(.1, 0))); + focus_sb->setSize(UVector2(UDim(.65, 0), UDim(.1, 0))); + focus_sb->setDocumentSize(2.0); + focus_sb->setStepSize(.1); + + focus_sb_lbl = wmgr.createWindow("Vanilla/StaticText", "focus_sb_lbl"); + wnd->addChildWindow(focus_sb_lbl); + + focus_sb_lbl->setPosition(UVector2(UDim(.85, 0), UDim(.1, 0))); + focus_sb_lbl->setSize(UVector2(UDim(.15, 0), UDim(.1, 0))); + + /* strength */ + strength_lbl = wmgr.createWindow("Vanilla/StaticText", "strength_lbl"); + wnd->addChildWindow(strength_lbl); + + strength_lbl->setPosition(UVector2(UDim(0, 0), UDim(.2, 0))); + strength_lbl->setSize(UVector2(UDim(.2, 0), UDim(.1, 0))); + strength_lbl->setText("Strength"); + + strength_sb = static_cast<Scrollbar*>(wmgr.createWindow("Vanilla/HorizontalScrollbar", "strength_sb")); + wnd->addChildWindow(strength_sb); + + strength_sb->setPosition(UVector2(UDim(.2, 0), UDim(.2, 0))); + strength_sb->setSize(UVector2(UDim(.65, 0), UDim(.1, 0))); + strength_sb->setDocumentSize(1.0); + strength_sb->setStepSize(.1); + + strength_sb_lbl = wmgr.createWindow("Vanilla/StaticText", "strength_sb_lbl"); + wnd->addChildWindow(strength_sb_lbl); + + strength_sb_lbl->setPosition(UVector2(UDim(.85, 0), UDim(.2, 0))); + strength_sb_lbl->setSize(UVector2(UDim(.15, 0), UDim(.1, 0))); +} + +GUI::~GUI() { + delete root; + delete wnd; + delete btn; + + delete radius_lbl; + delete radius_sb; + delete radius_sb_lbl; + + delete focus_lbl; + delete focus_sb; + delete focus_sb_lbl; + + delete strength_lbl; + delete strength_sb; + delete strength_sb_lbl; +} + +void GUI::render() { + radius_sb_lbl->setText((boost::format("%.2f") % radius_sb->getScrollPosition()).str().c_str()); + focus_sb_lbl->setText((boost::format("%.2f") % focus_sb->getScrollPosition()).str().c_str()); + strength_sb_lbl->setText((boost::format("%.2f") % strength_sb->getScrollPosition()).str().c_str()); + + /* Disable depth testing to avoid cursor bugginess. */ + glDisable(GL_DEPTH_TEST); + System::getSingleton().renderGUI(); + glEnable(GL_DEPTH_TEST); +} |