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"
27 GUIMessageMenu::GUIMessageMenu(gui::IGUIEnvironment* env,
28 gui::IGUIElement* parent, s32 id,
29 IMenuManager *menumgr,
30 std::wstring message_text
32 GUIModalMenu(env, parent, id, menumgr),
33 m_message_text(message_text),
38 GUIMessageMenu::~GUIMessageMenu()
43 void GUIMessageMenu::removeChildren()
46 gui::IGUIElement *e = getElementFromId(256);
51 gui::IGUIElement *e = getElementFromId(257);
57 void GUIMessageMenu::regenerateGui(v2u32 screensize)
65 Calculate new sizes and positions
68 screensize.X/2 - 580/2,
69 screensize.Y/2 - 300/2,
70 screensize.X/2 + 580/2,
71 screensize.Y/2 + 300/2
75 recalculateAbsolutePosition(false);
77 v2s32 size = rect.getSize();
83 core::rect<s32> rect(0, 0, 400, 50);
84 rect = rect + v2s32(size.X/2-400/2, size.Y/2-50/2-25);
85 Environment->addStaticText(m_message_text.c_str(), rect, false,
90 core::rect<s32> rect(0, 0, 140, 30);
91 rect = rect + v2s32(size.X/2-140/2, size.Y/2-30/2+25);
93 Environment->addButton(rect, this, 257,
95 Environment->setFocus(e);
100 void GUIMessageMenu::drawMenu()
102 gui::IGUISkin* skin = Environment->getSkin();
105 video::IVideoDriver* driver = Environment->getVideoDriver();
107 video::SColor bgcolor(140,0,0,0);
108 driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
110 gui::IGUIElement::draw();
113 bool GUIMessageMenu::OnEvent(const SEvent& event)
115 if(event.EventType==EET_KEY_INPUT_EVENT)
117 if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)
123 if(event.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown)
130 if(event.EventType==EET_GUI_EVENT)
132 if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST
135 if(!canTakeFocus(event.GUIEvent.Element))
137 dstream<<"GUIMessageMenu: Not allowing focus change."
139 // Returning true disables focus change
143 if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
145 switch(event.GUIEvent.Caller->getID())
155 return Parent ? Parent->OnEvent(event) : false;