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>
32 GUITextInputMenu::GUITextInputMenu(gui::IGUIEnvironment* env,
33 gui::IGUIElement* parent, s32 id,
34 IMenuManager *menumgr,
36 std::wstring initial_text
38 GUIModalMenu(env, parent, id, menumgr),
40 m_initial_text(initial_text)
44 GUITextInputMenu::~GUITextInputMenu()
51 void GUITextInputMenu::removeChildren()
54 gui::IGUIElement *e = getElementFromId(256);
59 gui::IGUIElement *e = getElementFromId(257);
65 void GUITextInputMenu::regenerateGui(v2u32 screensize)
70 gui::IGUIElement *e = getElementFromId(256);
77 text = m_initial_text;
88 Calculate new sizes and positions
91 screensize.X/2 - 580/2,
92 screensize.Y/2 - 300/2,
93 screensize.X/2 + 580/2,
94 screensize.Y/2 + 300/2
98 recalculateAbsolutePosition(false);
100 v2s32 size = rect.getSize();
106 core::rect<s32> rect(0, 0, 300, 30);
107 rect = rect + v2s32(size.X/2-300/2, size.Y/2-30/2-25);
108 gui::IGUIElement *e =
109 Environment->addEditBox(text.c_str(), rect, true, this, 256);
110 Environment->setFocus(e);
113 evt.EventType = EET_KEY_INPUT_EVENT;
114 evt.KeyInput.Key = KEY_END;
115 evt.KeyInput.PressedDown = true;
120 core::rect<s32> rect(0, 0, 140, 30);
121 rect = rect + v2s32(size.X/2-140/2, size.Y/2-30/2+25);
122 Environment->addButton(rect, this, 257,
123 wgettext("Proceed"));
128 void GUITextInputMenu::drawMenu()
130 gui::IGUISkin* skin = Environment->getSkin();
133 video::IVideoDriver* driver = Environment->getVideoDriver();
135 video::SColor bgcolor(140,0,0,0);
136 driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
138 gui::IGUIElement::draw();
141 void GUITextInputMenu::acceptInput()
145 gui::IGUIElement *e = getElementFromId(256);
148 m_dest->gotText(e->getText());
155 bool GUITextInputMenu::OnEvent(const SEvent& event)
157 if(event.EventType==EET_KEY_INPUT_EVENT)
159 if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)
164 if(event.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown)
171 if(event.EventType==EET_GUI_EVENT)
173 if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST
176 if(!canTakeFocus(event.GUIEvent.Element))
178 dstream<<"GUITextInputMenu: Not allowing focus change."
180 // Returning true disables focus change
184 if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
186 switch(event.GUIEvent.Caller->getID())
191 // quitMenu deallocates menu
195 if(event.GUIEvent.EventType==gui::EGET_EDITBOX_ENTER)
197 switch(event.GUIEvent.Caller->getID())
202 // quitMenu deallocates menu
208 return Parent ? Parent->OnEvent(event) : false;