3 Copyright (C) 2013 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 wchar_t* text = wgettext("Proceed");
131 Environment->addButton(rect, this, 257,
138 void GUITextInputMenu::drawMenu()
140 gui::IGUISkin* skin = Environment->getSkin();
143 video::IVideoDriver* driver = Environment->getVideoDriver();
145 video::SColor bgcolor(140,0,0,0);
146 driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
148 gui::IGUIElement::draw();
151 void GUITextInputMenu::acceptInput()
155 gui::IGUIElement *e = getElementFromId(256);
158 m_dest->gotText(e->getText());
165 bool GUITextInputMenu::OnEvent(const SEvent& event)
167 if(event.EventType==EET_KEY_INPUT_EVENT)
169 if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)
174 if(event.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown)
181 if(event.EventType==EET_GUI_EVENT)
183 if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST
186 if(!canTakeFocus(event.GUIEvent.Element))
188 dstream<<"GUITextInputMenu: Not allowing focus change."
190 // Returning true disables focus change
194 if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
196 switch(event.GUIEvent.Caller->getID())
201 // quitMenu deallocates menu
205 if(event.GUIEvent.EventType==gui::EGET_EDITBOX_ENTER)
207 switch(event.GUIEvent.Caller->getID())
212 // quitMenu deallocates menu
218 return Parent ? Parent->OnEvent(event) : false;