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 General Public License as published by
7 the Free Software Foundation; either version 2 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 General Public License for more details.
15 You should have received a copy of the GNU 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"
25 GUITextInputMenu::GUITextInputMenu(gui::IGUIEnvironment* env,
26 gui::IGUIElement* parent, s32 id,
27 int *active_menu_count,
29 std::wstring initial_text
31 GUIModalMenu(env, parent, id, active_menu_count),
33 m_initial_text(initial_text)
37 GUITextInputMenu::~GUITextInputMenu()
44 void GUITextInputMenu::removeChildren()
47 gui::IGUIElement *e = getElementFromId(256);
52 gui::IGUIElement *e = getElementFromId(257);
58 void GUITextInputMenu::regenerateGui(v2u32 screensize)
63 gui::IGUIElement *e = getElementFromId(256);
70 text = m_initial_text;
81 Calculate new sizes and positions
84 screensize.X/2 - 580/2,
85 screensize.Y/2 - 300/2,
86 screensize.X/2 + 580/2,
87 screensize.Y/2 + 300/2
91 recalculateAbsolutePosition(false);
93 v2s32 size = rect.getSize();
99 core::rect<s32> rect(0, 0, 300, 30);
100 rect = rect + v2s32(size.X/2-300/2, size.Y/2-30/2-25);
101 gui::IGUIElement *e =
102 Environment->addEditBox(text.c_str(), rect, true, this, 256);
103 Environment->setFocus(e);
106 core::rect<s32> rect(0, 0, 140, 30);
107 rect = rect + v2s32(size.X/2-140/2, size.Y/2-30/2+25);
108 Environment->addButton(rect, this, 257, L"Proceed");
112 void GUITextInputMenu::drawMenu()
114 gui::IGUISkin* skin = Environment->getSkin();
117 video::IVideoDriver* driver = Environment->getVideoDriver();
119 video::SColor bgcolor(140,0,0,0);
120 driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
122 gui::IGUIElement::draw();
125 void GUITextInputMenu::acceptInput()
129 gui::IGUIElement *e = getElementFromId(256);
132 m_dest->gotText(e->getText());
139 bool GUITextInputMenu::OnEvent(const SEvent& event)
141 if(event.EventType==EET_KEY_INPUT_EVENT)
143 if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)
148 if(event.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown)
155 if(event.EventType==EET_GUI_EVENT)
157 if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST
160 if(!canTakeFocus(event.GUIEvent.Element))
162 dstream<<"GUITextInputMenu: Not allowing focus change."
164 // Returning true disables focus change
168 if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
170 switch(event.GUIEvent.Caller->getID())
178 if(event.GUIEvent.EventType==gui::EGET_EDITBOX_ENTER)
180 switch(event.GUIEvent.Caller->getID())
190 return Parent ? Parent->OnEvent(event) : false;