From 7e490e72139fbfe12535c71b27228dd82ef0250b Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Thu, 23 Dec 2010 17:09:49 +0200 Subject: work-in-progress gui system updating + some settings system updating --- src/guiTextInputMenu.cpp | 168 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 src/guiTextInputMenu.cpp (limited to 'src/guiTextInputMenu.cpp') diff --git a/src/guiTextInputMenu.cpp b/src/guiTextInputMenu.cpp new file mode 100644 index 000000000..8a9da3489 --- /dev/null +++ b/src/guiTextInputMenu.cpp @@ -0,0 +1,168 @@ +/* +Minetest-c55 +Copyright (C) 2010 celeron55, Perttu Ahola + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include "guiTextInputMenu.h" +#include "debug.h" +#include "serialization.h" +#include + +GUITextInputMenu::GUITextInputMenu(gui::IGUIEnvironment* env, + gui::IGUIElement* parent, s32 id, + int *active_menu_count, + TextDest *dest, + std::wstring initial_text +): + GUIModalMenu(env, parent, id, active_menu_count), + m_dest(dest), + m_initial_text(initial_text) +{ +} + +GUITextInputMenu::~GUITextInputMenu() +{ + removeChildren(); +} + +void GUITextInputMenu::removeChildren() +{ + { + gui::IGUIElement *e = getElementFromId(256); + if(e != NULL) + e->remove(); + } + { + gui::IGUIElement *e = getElementFromId(257); + if(e != NULL) + e->remove(); + } +} + +void GUITextInputMenu::regenerateGui(v2u32 screensize) +{ + std::wstring text; + + { + gui::IGUIElement *e = getElementFromId(256); + if(e != NULL) + { + text = e->getText(); + } + else + { + text = m_initial_text; + m_initial_text = L""; + } + } + + /* + Remove stuff + */ + removeChildren(); + + /* + Calculate new sizes and positions + */ + core::rect rect( + screensize.X/2 - 580/2, + screensize.Y/2 - 300/2, + screensize.X/2 + 580/2, + screensize.Y/2 + 300/2 + ); + + DesiredRect = rect; + recalculateAbsolutePosition(false); + + v2s32 size = rect.getSize(); + + /* + Add stuff + */ + { + core::rect rect(0, 0, 300, 30); + rect = rect + v2s32(size.X/2-300/2, size.Y/2-30/2-25); + gui::IGUIElement *e = + Environment->addEditBox(text.c_str(), rect, true, this, 256); + Environment->setFocus(e); + } + { + core::rect rect(0, 0, 140, 30); + rect = rect + v2s32(size.X/2-140/2, size.Y/2-30/2+25); + Environment->addButton(rect, this, 257, L"Proceed"); + } +} + +void GUITextInputMenu::drawMenu() +{ + gui::IGUISkin* skin = Environment->getSkin(); + if (!skin) + return; + video::IVideoDriver* driver = Environment->getVideoDriver(); + + video::SColor bgcolor(140,0,0,0); + driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect); + + gui::IGUIElement::draw(); +} + +bool GUITextInputMenu::OnEvent(const SEvent& event) +{ + if(event.EventType==EET_KEY_INPUT_EVENT) + { + if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown) + { + quitMenu(); + return true; + } + } + if(event.EventType==EET_GUI_EVENT) + { + if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST + && isVisible()) + { + if(!canTakeFocus(event.GUIEvent.Element)) + { + dstream<<"GUITextInputMenu: Not allowing focus change." + <getID()) + { + case 257: + if(m_dest) + { + gui::IGUIElement *e = getElementFromId(256); + if(e != NULL) + { + m_dest->gotText(e->getText()); + } + delete m_dest; + } + quitMenu(); + break; + } + } + } + + return Parent ? Parent->OnEvent(event) : false; +} + -- cgit v1.2.3