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 #ifndef MODALMENU_HEADER
21 #define MODALMENU_HEADER
23 #include "irrlichttypes_extrabloated.h"
24 #ifdef HAVE_TOUCHSCREENGUI
25 #include "touchscreengui.h"
33 // A GUIModalMenu calls these when this class is passed as a parameter
34 virtual void createdMenu(GUIModalMenu *menu) = 0;
35 virtual void deletingMenu(GUIModalMenu *menu) = 0;
39 Remember to drop() the menu after creating, so that it can
40 remove itself when it wants to.
43 class GUIModalMenu : public gui::IGUIElement
46 GUIModalMenu(gui::IGUIEnvironment* env,
47 gui::IGUIElement* parent, s32 id,
48 IMenuManager *menumgr):
49 IGUIElement(gui::EGUIET_ELEMENT, env, parent, id,
50 core::rect<s32>(0,0,100,100))
52 //m_force_regenerate_gui = false;
55 m_allow_focus_removal = false;
56 m_screensize_old = v2u32(0,0);
59 Environment->setFocus(this);
60 m_menumgr->createdMenu(this);
62 virtual ~GUIModalMenu()
64 m_menumgr->deletingMenu(this);
67 void allowFocusRemoval(bool allow)
69 m_allow_focus_removal = allow;
72 bool canTakeFocus(gui::IGUIElement *e)
74 return (e && (e == this || isMyChild(e))) || m_allow_focus_removal;
82 video::IVideoDriver* driver = Environment->getVideoDriver();
83 v2u32 screensize = driver->getScreenSize();
84 if(screensize != m_screensize_old /*|| m_force_regenerate_gui*/)
86 m_screensize_old = screensize;
87 regenerateGui(screensize);
88 //m_force_regenerate_gui = false;
95 This should be called when the menu wants to quit.
97 WARNING: THIS DEALLOCATES THE MENU FROM MEMORY. Return
98 immediately if you call this from the menu itself.
102 allowFocusRemoval(true);
103 // This removes Environment's grab on us
104 Environment->removeFocus(this);
105 m_menumgr->deletingMenu(this);
107 #ifdef HAVE_TOUCHSCREENGUI
108 if (g_touchscreengui)
109 g_touchscreengui->Show();
113 void removeChildren()
115 const core::list<gui::IGUIElement*> &children = getChildren();
116 core::list<gui::IGUIElement*> children_copy;
117 for(core::list<gui::IGUIElement*>::ConstIterator
118 i = children.begin(); i != children.end(); i++)
120 children_copy.push_back(*i);
122 for(core::list<gui::IGUIElement*>::Iterator
123 i = children_copy.begin();
124 i != children_copy.end(); i++)
130 virtual void regenerateGui(v2u32 screensize) = 0;
131 virtual void drawMenu() = 0;
132 virtual bool preprocessEvent(const SEvent& event) { return false; };
133 virtual bool OnEvent(const SEvent& event) { return false; };
134 virtual bool pausesGame(){ return false; } // Used for pause menu
137 //bool m_force_regenerate_gui;
138 v2u32 m_screensize_old;
140 IMenuManager *m_menumgr;
141 // This might be necessary to expose to the implementation if it
142 // wants to launch other menus
143 bool m_allow_focus_removal;