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 "guiMessageMenu.h"
22 #include "serialization.h"
24 #include <IGUICheckBox.h>
25 #include <IGUIEditBox.h>
26 #include <IGUIButton.h>
27 #include <IGUIStaticText.h>
32 GUIMessageMenu::GUIMessageMenu(gui::IGUIEnvironment* env,
33 gui::IGUIElement* parent, s32 id,
34 IMenuManager *menumgr,
35 std::wstring message_text
37 GUIModalMenu(env, parent, id, menumgr),
38 m_message_text(message_text),
43 GUIMessageMenu::~GUIMessageMenu()
48 void GUIMessageMenu::removeChildren()
51 gui::IGUIElement *e = getElementFromId(256);
56 gui::IGUIElement *e = getElementFromId(257);
62 void GUIMessageMenu::regenerateGui(v2u32 screensize)
70 Calculate new sizes and positions
73 screensize.X/2 - 580/2,
74 screensize.Y/2 - 300/2,
75 screensize.X/2 + 580/2,
76 screensize.Y/2 + 300/2
80 recalculateAbsolutePosition(false);
82 v2s32 size = rect.getSize();
88 core::rect<s32> rect(0, 0, 400, 50);
89 rect = rect + v2s32(size.X/2-400/2, size.Y/2-50/2-25);
90 Environment->addStaticText(m_message_text.c_str(), rect, false,
95 core::rect<s32> rect(0, 0, 140, 30);
96 rect = rect + v2s32(size.X/2-140/2, size.Y/2-30/2+25);
98 Environment->addButton(rect, this, 257,
100 Environment->setFocus(e);
105 void GUIMessageMenu::drawMenu()
107 gui::IGUISkin* skin = Environment->getSkin();
110 video::IVideoDriver* driver = Environment->getVideoDriver();
112 video::SColor bgcolor(140,0,0,0);
113 driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
115 gui::IGUIElement::draw();
118 bool GUIMessageMenu::OnEvent(const SEvent& event)
120 if(event.EventType==EET_KEY_INPUT_EVENT)
122 if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)
128 if(event.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown)
135 if(event.EventType==EET_GUI_EVENT)
137 if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST
140 if(!canTakeFocus(event.GUIEvent.Element))
142 dstream<<"GUIMessageMenu: Not allowing focus change."
144 // Returning true disables focus change
148 if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
150 switch(event.GUIEvent.Caller->getID())
160 return Parent ? Parent->OnEvent(event) : false;