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 Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser 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"
24 #include <IGUICheckBox.h>
25 #include <IGUIEditBox.h>
26 #include <IGUIButton.h>
27 #include <IGUIStaticText.h>
33 #include "intlGUIEditBox.h"
36 GUITextInputMenu::GUITextInputMenu(gui::IGUIEnvironment* env,
37 gui::IGUIElement* parent, s32 id,
38 IMenuManager *menumgr,
40 std::wstring initial_text
42 GUIModalMenu(env, parent, id, menumgr),
44 m_initial_text(initial_text)
48 GUITextInputMenu::~GUITextInputMenu()
55 void GUITextInputMenu::removeChildren()
58 gui::IGUIElement *e = getElementFromId(256);
63 gui::IGUIElement *e = getElementFromId(257);
69 void GUITextInputMenu::regenerateGui(v2u32 screensize)
74 gui::IGUIElement *e = getElementFromId(256);
81 text = m_initial_text;
92 Calculate new sizes and positions
95 screensize.X/2 - 580/2,
96 screensize.Y/2 - 300/2,
97 screensize.X/2 + 580/2,
98 screensize.Y/2 + 300/2
102 recalculateAbsolutePosition(false);
104 v2s32 size = rect.getSize();
110 core::rect<s32> rect(0, 0, 300, 30);
111 rect = rect + v2s32(size.X/2-300/2, size.Y/2-30/2-25);
113 gui::IGUIElement *e = (gui::IGUIElement *) new gui::intlGUIEditBox(text.c_str(), true, Environment, this, 256, rect);
116 gui::IGUIElement *e = Environment->addEditBox(text.c_str(), rect, true, this, 256);
118 Environment->setFocus(e);
121 evt.EventType = EET_KEY_INPUT_EVENT;
122 evt.KeyInput.Key = KEY_END;
123 evt.KeyInput.PressedDown = true;
128 core::rect<s32> rect(0, 0, 140, 30);
129 rect = rect + v2s32(size.X/2-140/2, size.Y/2-30/2+25);
130 Environment->addButton(rect, this, 257,
131 wgettext("Proceed"));
136 void GUITextInputMenu::drawMenu()
138 gui::IGUISkin* skin = Environment->getSkin();
141 video::IVideoDriver* driver = Environment->getVideoDriver();
143 video::SColor bgcolor(140,0,0,0);
144 driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
146 gui::IGUIElement::draw();
149 void GUITextInputMenu::acceptInput()
153 gui::IGUIElement *e = getElementFromId(256);
156 m_dest->gotText(e->getText());
163 bool GUITextInputMenu::OnEvent(const SEvent& event)
165 if(event.EventType==EET_KEY_INPUT_EVENT)
167 if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)
172 if(event.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown)
179 if(event.EventType==EET_GUI_EVENT)
181 if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST
184 if(!canTakeFocus(event.GUIEvent.Element))
186 dstream<<"GUITextInputMenu: Not allowing focus change."
188 // Returning true disables focus change
192 if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
194 switch(event.GUIEvent.Caller->getID())
199 // quitMenu deallocates menu
203 if(event.GUIEvent.EventType==gui::EGET_EDITBOX_ENTER)
205 switch(event.GUIEvent.Caller->getID())
210 // quitMenu deallocates menu
216 return Parent ? Parent->OnEvent(event) : false;