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;
124 evt.KeyInput.Char = 0;
125 evt.KeyInput.Control = 0;
126 evt.KeyInput.Shift = 0;
131 core::rect<s32> rect(0, 0, 140, 30);
132 rect = rect + v2s32(size.X/2-140/2, size.Y/2-30/2+25);
133 wchar_t* text = wgettext("Proceed");
134 Environment->addButton(rect, this, 257,
141 void GUITextInputMenu::drawMenu()
143 gui::IGUISkin* skin = Environment->getSkin();
146 video::IVideoDriver* driver = Environment->getVideoDriver();
148 video::SColor bgcolor(140,0,0,0);
149 driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
151 gui::IGUIElement::draw();
154 void GUITextInputMenu::acceptInput()
158 gui::IGUIElement *e = getElementFromId(256);
161 m_dest->gotText(e->getText());
168 bool GUITextInputMenu::OnEvent(const SEvent& event)
170 if(event.EventType==EET_KEY_INPUT_EVENT)
172 if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)
177 if(event.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown)
184 if(event.EventType==EET_GUI_EVENT)
186 if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST
189 if(!canTakeFocus(event.GUIEvent.Element))
191 dstream<<"GUITextInputMenu: Not allowing focus change."
193 // Returning true disables focus change
197 if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
199 switch(event.GUIEvent.Caller->getID())
204 // quitMenu deallocates menu
208 if(event.GUIEvent.EventType==gui::EGET_EDITBOX_ENTER)
210 switch(event.GUIEvent.Caller->getID())
215 // quitMenu deallocates menu
221 return Parent ? Parent->OnEvent(event) : false;