3 Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "guiTextInputMenu.h"
22 #include "serialization.h"
27 GUITextInputMenu::GUITextInputMenu(gui::IGUIEnvironment* env,
28 gui::IGUIElement* parent, s32 id,
29 IMenuManager *menumgr,
31 std::wstring initial_text
33 GUIModalMenu(env, parent, id, menumgr),
35 m_initial_text(initial_text)
39 GUITextInputMenu::~GUITextInputMenu()
46 void GUITextInputMenu::removeChildren()
49 gui::IGUIElement *e = getElementFromId(256);
54 gui::IGUIElement *e = getElementFromId(257);
60 void GUITextInputMenu::regenerateGui(v2u32 screensize)
65 gui::IGUIElement *e = getElementFromId(256);
72 text = m_initial_text;
83 Calculate new sizes and positions
86 screensize.X/2 - 580/2,
87 screensize.Y/2 - 300/2,
88 screensize.X/2 + 580/2,
89 screensize.Y/2 + 300/2
93 recalculateAbsolutePosition(false);
95 v2s32 size = rect.getSize();
101 core::rect<s32> rect(0, 0, 300, 30);
102 rect = rect + v2s32(size.X/2-300/2, size.Y/2-30/2-25);
103 gui::IGUIElement *e =
104 Environment->addEditBox(text.c_str(), rect, true, this, 256);
105 Environment->setFocus(e);
107 setlocale(LC_CTYPE, "");
109 core::rect<s32> rect(0, 0, 140, 30);
110 rect = rect + v2s32(size.X/2-140/2, size.Y/2-30/2+25);
111 Environment->addButton(rect, this, 257,
112 chartowchar_t(gettext("Proceed")));
114 setlocale(LC_CTYPE, "en_US");
117 void GUITextInputMenu::drawMenu()
119 gui::IGUISkin* skin = Environment->getSkin();
122 video::IVideoDriver* driver = Environment->getVideoDriver();
124 video::SColor bgcolor(140,0,0,0);
125 driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
127 gui::IGUIElement::draw();
130 void GUITextInputMenu::acceptInput()
134 gui::IGUIElement *e = getElementFromId(256);
137 m_dest->gotText(e->getText());
144 bool GUITextInputMenu::OnEvent(const SEvent& event)
146 if(event.EventType==EET_KEY_INPUT_EVENT)
148 if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)
153 if(event.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown)
160 if(event.EventType==EET_GUI_EVENT)
162 if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST
165 if(!canTakeFocus(event.GUIEvent.Element))
167 dstream<<"GUITextInputMenu: Not allowing focus change."
169 // Returning true disables focus change
173 if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
175 switch(event.GUIEvent.Caller->getID())
180 // quitMenu deallocates menu
184 if(event.GUIEvent.EventType==gui::EGET_EDITBOX_ENTER)
186 switch(event.GUIEvent.Caller->getID())
191 // quitMenu deallocates menu
197 return Parent ? Parent->OnEvent(event) : false;