#include "gui.h" #include "video.h" #include "widgets/FormattedListboxTextItem.h" #include #include #include using namespace CEGUI; CEGUI::Window *GUI::root = NULL; void GUI::init() { OpenGLRenderer::bootstrapSystem(); DefaultResourceProvider* rp = static_cast (System::getSingleton().getResourceProvider()); rp->setResourceGroupDirectory("schemes", "GUI/"); rp->setResourceGroupDirectory("imagesets", "GUI/"); rp->setResourceGroupDirectory("fonts", "fonts/"); rp->setResourceGroupDirectory("layouts", "GUI/layouts/"); 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); } void GUI::pre_render() { MouseCursor::getSingleton().hide(); } void GUI::render() { /* Disable depth testing to avoid cursor bugginess. */ glDisable(GL_DEPTH_TEST); System::getSingleton().renderGUI(); glEnable(GL_DEPTH_TEST); } void GUI::show() { wnd->show(); _showing = true; } void GUI::hide() { wnd->hide(); _showing = false; } bool GUI::showing() { return _showing; } /* ConsoleWindow */ ConsoleWindow::ConsoleWindow(Lua *lua) { this->lua = lua; WindowManager& wmgr(WindowManager::getSingleton()); wnd = wmgr.loadWindowLayout("console.layout"); root->addChildWindow(wnd); editbox = wmgr.getWindow("console_editbox"); editbox->subscribeEvent(Editbox::EventMouseClick, Event::Subscriber(&ConsoleWindow::clicked, this)); editbox->subscribeEvent(Editbox::EventKeyDown, Event::Subscriber(&ConsoleWindow::keydown, this)); listbox = static_cast(wmgr.getWindow("console_listbox")); } ConsoleWindow::~ConsoleWindow() { WindowManager& wmgr(WindowManager::getSingleton()); wmgr.destroyWindow(wnd); wmgr.cleanDeadPool(); } bool ConsoleWindow::clicked(const EventArgs& e) { handle_input(); return true; } void ConsoleWindow::erase_editbox_text() { String s(editbox->getText()); if(s.size() == 0) return; s.erase(s.size()-1); editbox->setText(s); } bool ConsoleWindow::keydown(const EventArgs& e) { const KeyEventArgs& ke = static_cast(e); switch(ke.scancode) { // enter case 36: handle_input(); break; // backspace case 22: erase_editbox_text(); break; default: break; } return true; } void ConsoleWindow::handle_input() { std::string s = editbox->getText().c_str(); editbox->setText(""); boost::trim(s); if(!s.size()) return; add_line(s); try { lua->dostring(s); } catch(LuaError& e) { add_line(e.what()); } } void ConsoleWindow::add_line(const std::string& line) { add_line(line.c_str()); } void ConsoleWindow::add_line(const char *line) { FormattedListboxTextItem *item = new FormattedListboxTextItem(String((utf8*)line), HTF_WORDWRAP_LEFT_ALIGNED); listbox->addItem(item); listbox->ensureItemIsVisible(item); } void ConsoleWindow::update() { MouseCursor::getSingleton().show(); WindowManager::getSingleton().getWindow("console_editbox")->activate(); } /* RaiseWindow */ /* default values */ float RaiseWindow::radius = 5; float RaiseWindow::focus = .8; float RaiseWindow::strength = .3; RaiseWindow::RaiseWindow() { WindowManager& wmgr(WindowManager::getSingleton()); wnd = wmgr.loadWindowLayout("raisewnd.layout"); root->addChildWindow(wnd); radius_sb = static_cast(wmgr.getWindow("radius_sb")); radius_sb_lbl = wmgr.getWindow("radius_sb_lbl"); focus_sb = static_cast(wmgr.getWindow("focus_sb")); focus_sb_lbl = wmgr.getWindow("focus_sb_lbl"); strength_sb = static_cast(wmgr.getWindow("strength_sb")); strength_sb_lbl = wmgr.getWindow("strength_sb_lbl"); /* load default/last used values */ radius_sb->setScrollPosition(radius); focus_sb->setScrollPosition(focus); strength_sb->setScrollPosition(strength); } RaiseWindow::~RaiseWindow() { /* store current values */ radius = get_radius(); focus = get_focus(); strength = get_strength(); WindowManager& wmgr(WindowManager::getSingleton()); wmgr.destroyWindow(wnd); wmgr.cleanDeadPool(); } void RaiseWindow::update() { MouseCursor::getSingleton().show(); 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()); } float RaiseWindow::get_radius() { return radius_sb->getScrollPosition(); } float RaiseWindow::get_focus() { return focus_sb->getScrollPosition(); } float RaiseWindow::get_strength() { return strength_sb->getScrollPosition(); }