3 Copyright (C) 2012 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 "guiConfirmMenu.h"
22 #include "serialization.h"
24 #include <IGUICheckBox.h>
25 #include <IGUIEditBox.h>
26 #include <IGUIButton.h>
27 #include <IGUIStaticText.h>
38 GUIConfirmMenu::GUIConfirmMenu(gui::IGUIEnvironment* env,
39 gui::IGUIElement* parent, s32 id,
40 IMenuManager *menumgr,
42 std::wstring message_text
44 GUIModalMenu(env, parent, id, menumgr),
46 m_message_text(message_text)
50 GUIConfirmMenu::~GUIConfirmMenu()
57 void GUIConfirmMenu::removeChildren()
59 const core::list<gui::IGUIElement*> &children = getChildren();
60 core::list<gui::IGUIElement*> children_copy;
61 for(core::list<gui::IGUIElement*>::ConstIterator
62 i = children.begin(); i != children.end(); i++)
64 children_copy.push_back(*i);
66 for(core::list<gui::IGUIElement*>::Iterator
67 i = children_copy.begin();
68 i != children_copy.end(); i++)
74 void GUIConfirmMenu::regenerateGui(v2u32 screensize)
82 Calculate new sizes and positions
85 screensize.X/2 - 580/2,
86 screensize.Y/2 - 300/2,
87 screensize.X/2 + 580/2,
88 screensize.Y/2 + 300/2
92 recalculateAbsolutePosition(false);
94 v2s32 size = rect.getSize();
100 core::rect<s32> rect(0, 0, 300, 20);
101 rect += v2s32(size.X/2-300/2, size.Y/2-30/2-25);
102 Environment->addStaticText(m_message_text.c_str(),
103 rect, false, true, this, -1);
108 core::rect<s32> rect(0, 0, bw, 30);
109 rect = rect + v2s32(size.X/2-bw/2-(bw/2+5), size.Y/2-30/2+25);
110 Environment->addButton(rect, this, GUI_ID_YES,
114 core::rect<s32> rect(0, 0, bw, 30);
115 rect = rect + v2s32(size.X/2-bw/2+(bw/2+5), size.Y/2-30/2+25);
116 Environment->addButton(rect, this, GUI_ID_NO,
122 void GUIConfirmMenu::drawMenu()
124 gui::IGUISkin* skin = Environment->getSkin();
127 video::IVideoDriver* driver = Environment->getVideoDriver();
129 video::SColor bgcolor(140,0,0,0);
130 driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
132 gui::IGUIElement::draw();
135 void GUIConfirmMenu::acceptInput(bool answer)
138 m_dest->answer(answer);
141 bool GUIConfirmMenu::OnEvent(const SEvent& event)
143 if(event.EventType==EET_KEY_INPUT_EVENT)
145 if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)
151 if(event.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown)
158 if(event.EventType==EET_GUI_EVENT)
160 if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST
163 if(!canTakeFocus(event.GUIEvent.Element))
165 dstream<<"GUIConfirmMenu: Not allowing focus change."
167 // Returning true disables focus change
171 if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
173 switch(event.GUIEvent.Caller->getID())
178 // quitMenu deallocates menu
183 // quitMenu deallocates menu
189 return Parent ? Parent->OnEvent(event) : false;