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 #ifndef MODALMENU_HEADER
21 #define MODALMENU_HEADER
23 #include "common_irrlicht.h"
26 Remember to drop() the menu after creating, so that it can
27 remove itself when it wants to.
30 class GUIModalMenu : public gui::IGUIElement
33 GUIModalMenu(gui::IGUIEnvironment* env,
34 gui::IGUIElement* parent, s32 id,
35 int *active_menu_count):
36 IGUIElement(gui::EGUIET_ELEMENT, env, parent, id,
37 core::rect<s32>(0,0,100,100))
39 m_active_menu_count = active_menu_count;
40 m_allow_focus_removal = false;
41 m_screensize_old = v2u32(0,0);
44 Environment->setFocus(this);
45 (*m_active_menu_count)++;
47 virtual ~GUIModalMenu()
49 (*m_active_menu_count)--;
52 bool canTakeFocus(gui::IGUIElement *e)
54 return (e && (e == this || isMyChild(e))) || m_allow_focus_removal;
62 video::IVideoDriver* driver = Environment->getVideoDriver();
63 v2u32 screensize = driver->getScreenSize();
64 if(screensize != m_screensize_old)
66 m_screensize_old = screensize;
67 regenerateGui(screensize);
74 This should be called when the menu wants to quit
78 m_allow_focus_removal = true;
79 // This removes Environment's grab on us
80 Environment->removeFocus(this);
84 virtual void regenerateGui(v2u32 screensize) = 0;
85 virtual void drawMenu() = 0;
86 virtual bool OnEvent(const SEvent& event) { return false; };
89 int *m_active_menu_count;
90 // This might be necessary to expose to the implementation if it
91 // wants to launch other menus
92 bool m_allow_focus_removal;
93 v2u32 m_screensize_old;