diff options
Diffstat (limited to 'gui.cpp')
-rw-r--r-- | gui.cpp | 101 |
1 files changed, 97 insertions, 4 deletions
@@ -1,7 +1,10 @@ #include "gui.h" #include "video.h" +#include "widgets/FormattedListboxTextItem.h" + #include <boost/format.hpp> +#include <boost/algorithm/string/trim.hpp> #include <RendererModules/OpenGL/CEGUIOpenGLRenderer.h> using namespace CEGUI; @@ -38,6 +41,10 @@ void GUI::init() { 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); @@ -45,6 +52,92 @@ void GUI::render() { 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() { + 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<Listbox*>(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<const KeyEventArgs&>(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; + + FormattedListboxTextItem *item = new FormattedListboxTextItem(s, 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 */ @@ -55,7 +148,7 @@ float RaiseWindow::strength = .3; RaiseWindow::RaiseWindow() { WindowManager& wmgr(WindowManager::getSingleton()); - wnd = static_cast<FrameWindow*>(wmgr.loadWindowLayout("raisewnd.layout")); + wnd = wmgr.loadWindowLayout("raisewnd.layout"); root->addChildWindow(wnd); radius_sb = static_cast<Scrollbar*>(wmgr.getWindow("radius_sb")); @@ -82,12 +175,12 @@ RaiseWindow::~RaiseWindow() { wmgr.cleanDeadPool(); } -void RaiseWindow::render() { +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()); - - GUI::render(); } float RaiseWindow::get_radius() { |