]> git.lizzy.rs Git - minetest.git/blob - src/modalMenu.h
redoing gui stuff
[minetest.git] / src / modalMenu.h
1 /*
2 Minetest-c55
3 Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
4
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.
9
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.
14
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.
18 */
19
20 #ifndef MODALMENU_HEADER
21 #define MODALMENU_HEADER
22
23 #include "common_irrlicht.h"
24
25 //TODO: Change GUIElement private
26 class GUIModalMenu : public gui::IGUIElement
27 {
28 public:
29         GUIModalMenu(gui::IGUIEnvironment* env,
30                         gui::IGUIElement* parent, s32 id,
31                         int *active_menu_count):
32                 IGUIElement(gui::EGUIET_ELEMENT, env, parent, id,
33                                 core::rect<s32>(0,0,100,100))
34         {
35                 m_active_menu_count = active_menu_count;
36                 m_allow_focus_removal = false;
37                 m_screensize_old = v2u32(0,0);
38
39                 setVisible(true);
40                 Environment->setFocus(this);
41                 (*m_active_menu_count)++;
42         }
43         virtual ~GUIModalMenu()
44         {
45                 (*m_active_menu_count)--;
46         }
47
48         bool canTakeFocus(gui::IGUIElement *e)
49         {
50                 return (e && (e == this || isMyChild(e))) || m_allow_focus_removal;
51         }
52
53         void quitMenu()
54         {
55                 m_allow_focus_removal = true;
56                 // This removes Environment's grab on us
57                 Environment->removeFocus(this);
58                 this->remove();
59         }
60
61         virtual void regenerateGui(v2u32 screensize) = 0;
62
63         virtual void drawMenu() = 0;
64
65         void draw()
66         {
67                 if(!IsVisible)
68                         return;
69                         
70                 video::IVideoDriver* driver = Environment->getVideoDriver();
71                 v2u32 screensize = driver->getScreenSize();
72                 if(screensize != m_screensize_old)
73                 {
74                         m_screensize_old = screensize;
75                         regenerateGui(screensize);
76                 }
77
78                 drawMenu();
79         }
80         
81         virtual bool OnEvent(const SEvent& event) { return false; };
82         
83 private:
84         int *m_active_menu_count;
85         bool m_allow_focus_removal;
86         v2u32 m_screensize_old;
87 };
88
89
90 #endif
91