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"
23 #include "main.h" // for g_settings
26 #include <IGUICheckBox.h>
27 #include <IGUIEditBox.h>
28 #include <IGUIButton.h>
29 #include <IGUIStaticText.h>
35 #include "intlGUIEditBox.h"
38 GUITextInputMenu::GUITextInputMenu(gui::IGUIEnvironment* env,
39 gui::IGUIElement* parent, s32 id,
40 IMenuManager *menumgr,
42 std::wstring initial_text
44 GUIModalMenu(env, parent, id, menumgr),
46 m_initial_text(initial_text)
50 GUITextInputMenu::~GUITextInputMenu()
57 void GUITextInputMenu::removeChildren()
60 gui::IGUIElement *e = getElementFromId(256);
65 gui::IGUIElement *e = getElementFromId(257);
71 void GUITextInputMenu::regenerateGui(v2u32 screensize)
76 gui::IGUIElement *e = getElementFromId(256);
83 text = m_initial_text;
94 Calculate new sizes and positions
97 screensize.X/2 - 580/2,
98 screensize.Y/2 - 300/2,
99 screensize.X/2 + 580/2,
100 screensize.Y/2 + 300/2
104 recalculateAbsolutePosition(false);
106 v2s32 size = rect.getSize();
112 core::rect<s32> rect(0, 0, 300, 30);
113 rect = rect + v2s32(size.X/2-300/2, size.Y/2-30/2-25);
116 if (g_settings->getBool("freetype")) {
117 e = (gui::IGUIElement *) new gui::intlGUIEditBox(text.c_str(), true, Environment, this, 256, rect);
120 e = Environment->addEditBox(text.c_str(), rect, true, this, 256);
123 e = Environment->addEditBox(text.c_str(), rect, true, this, 256);
125 Environment->setFocus(e);
128 evt.EventType = EET_KEY_INPUT_EVENT;
129 evt.KeyInput.Key = KEY_END;
130 evt.KeyInput.PressedDown = true;
131 evt.KeyInput.Char = 0;
132 evt.KeyInput.Control = 0;
133 evt.KeyInput.Shift = 0;
137 core::rect<s32> rect(0, 0, 140, 30);
138 rect = rect + v2s32(size.X/2-140/2, size.Y/2-30/2+25);
139 wchar_t* text = wgettext("Proceed");
140 Environment->addButton(rect, this, 257,
146 void GUITextInputMenu::drawMenu()
148 gui::IGUISkin* skin = Environment->getSkin();
151 video::IVideoDriver* driver = Environment->getVideoDriver();
153 video::SColor bgcolor(140,0,0,0);
154 driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
156 gui::IGUIElement::draw();
159 void GUITextInputMenu::acceptInput()
163 gui::IGUIElement *e = getElementFromId(256);
166 m_dest->gotText(e->getText());
173 bool GUITextInputMenu::OnEvent(const SEvent& event)
175 if(event.EventType==EET_KEY_INPUT_EVENT)
177 if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)
182 if(event.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown)
189 if(event.EventType==EET_GUI_EVENT)
191 if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST
194 if(!canTakeFocus(event.GUIEvent.Element))
196 dstream<<"GUITextInputMenu: Not allowing focus change."
198 // Returning true disables focus change
202 if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
204 switch(event.GUIEvent.Caller->getID())
209 // quitMenu deallocates menu
213 if(event.GUIEvent.EventType==gui::EGET_EDITBOX_ENTER)
215 switch(event.GUIEvent.Caller->getID())
220 // quitMenu deallocates menu
226 return Parent ? Parent->OnEvent(event) : false;