3 Copyright (C) 2013 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 "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();
96 gui::IGUISkin *skin = Environment->getSkin();
97 gui::IGUIFont *font = skin->getFont();
98 s32 msg_h = font->getDimension(m_message_text.c_str()).Height;
99 s32 msg_w = font->getDimension(m_message_text.c_str()).Width;
109 core::rect<s32> rect(0, 0, msg_w, msg_h);
110 rect += v2s32(size.X/2-msg_w/2, size.Y/2-30/2 - msg_h/2);
111 Environment->addStaticText(m_message_text.c_str(),
112 rect, false, true, this, -1);
117 core::rect<s32> rect(0, 0, bw, 30);
118 rect = rect + v2s32(size.X/2-bw/2-(bw/2+5), size.Y/2-30/2+5 + msg_h/2);
119 wchar_t* text = wgettext("Yes");
120 Environment->addButton(rect, this, GUI_ID_YES,
125 core::rect<s32> rect(0, 0, bw, 30);
126 rect = rect + v2s32(size.X/2-bw/2+(bw/2+5), size.Y/2-30/2+5 + msg_h/2);
127 wchar_t* text = wgettext("No");
128 Environment->addButton(rect, this, GUI_ID_NO,
135 void GUIConfirmMenu::drawMenu()
137 gui::IGUISkin* skin = Environment->getSkin();
140 video::IVideoDriver* driver = Environment->getVideoDriver();
142 video::SColor bgcolor(140,0,0,0);
143 driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
145 gui::IGUIElement::draw();
148 void GUIConfirmMenu::acceptInput(bool answer)
151 m_dest->answer(answer);
154 bool GUIConfirmMenu::OnEvent(const SEvent& event)
156 if(event.EventType==EET_KEY_INPUT_EVENT)
158 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<<"GUIConfirmMenu: 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
196 // quitMenu deallocates menu
202 return Parent ? Parent->OnEvent(event) : false;