SuperTuxKart
modaldialog.hpp
1 // SuperTuxKart - a fun racing game with go-kart
2 // Copyright (C) 2009-2015 Marianne Gagnon
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 3
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 
18 #ifndef HEADER_MODAL_DIALOG_HPP
19 #define HEADER_MODAL_DIALOG_HPP
20 
21 #include <IGUIWindow.h>
22 
23 #include "utils/ptr_vector.hpp"
24 #include "guiengine/abstract_top_level_container.hpp"
25 //#include "guiengine/event_handler.hpp"
26 //#include "guiengine/layout_manager.hpp"
27 #include "guiengine/skin.hpp"
28 #include "input/input_manager.hpp"
29 #include "utils/leak_check.hpp"
30 
31 //class PlayerProfile;
32 
36 namespace GUIEngine
37 {
38  class Widget;
39  class TextBoxWidget;
40  class ButtonWidget;
41 
42  enum ModalDialogLocation
43  {
44  MODAL_DIALOG_LOCATION_CENTER = 0,
45  MODAL_DIALOG_LOCATION_BOTTOM = 1
46  };
47 
56  {
57  private:
58 
59  ModalDialogLocation m_dialog_location;
60 
61  float m_percent_width, m_percent_height;
62  bool m_init;
63 
64  protected:
65  irr::gui::IGUIWindow* m_irrlicht_window;
66  irr::core::rect< irr::s32 > m_area;
67  bool m_fade_background;
68 
69  InputManager::InputDriverMode m_previous_mode;
70 
74  ModalDialog(const float percentWidth, const float percentHeight,
75  ModalDialogLocation location = MODAL_DIALOG_LOCATION_CENTER);
76 
80  void loadFromFile(const char* xmlFile);
81 
82  virtual void onEnterPressedInternal();
83  void clearWindow();
84 
88  virtual void loadedFromFile() {}
89  void doInit();
90 
91  public:
92  LEAK_CHECK()
93 
94 
96  bool isInited() {return m_init;}
97 
98  virtual ~ModalDialog();
99 
101  virtual EventPropagation processEvent(const std::string& eventSource){ return EVENT_LET; }
102 
103  irr::gui::IGUIWindow* getIrrlichtElement()
104  {
105  return m_irrlicht_window;
106  }
107 
108  static void dismiss();
109  static void onEnterPressed();
110  static ModalDialog* getCurrent();
111  static bool isADialogActive();
112 
114  virtual bool onEscapePressed() { return true; }
115 
117  virtual void onUpdate(float dt) { }
118 
123  virtual void beforeAddingWidgets() {}
124  virtual void load() {}
125 
127  virtual void init() {}
128 
132  virtual int getWidth() { return m_area.getWidth(); }
133 
137  virtual int getHeight() { return m_area.getHeight(); }
138 
139  bool fadeBackground() const { return m_fade_background; }
140 
141  bool isMyIrrChild(irr::gui::IGUIElement* widget) const { return m_irrlicht_window->isMyChild(widget); }
142  };
143 
144 }
145 #endif
Contains all GUI engine related classes and functions.
Definition: abstract_state_manager.hpp:31
ModalDialog(const float percentWidth, const float percentHeight, ModalDialogLocation location=MODAL_DIALOG_LOCATION_CENTER)
Creates a modal dialog with given percentage of screen width and height.
Definition: modaldialog.cpp:52
virtual void onUpdate(float dt)
Override to be notified of updates.
Definition: modaldialog.hpp:117
void loadFromFile(const char *xmlFile)
Load a XML file to create the dialog from.
Definition: modaldialog.cpp:65
bool isInited()
Because C++ doesn't support constructor delegation...
Definition: modaldialog.hpp:96
Represents a GUI widgets container.
Definition: abstract_top_level_container.hpp:42
virtual int getWidth()
Implementing callback from AbstractTopLevelContainer.
Definition: modaldialog.hpp:132
virtual bool onEscapePressed()
Override to change what happens on escape pressed.
Definition: modaldialog.hpp:114
virtual void beforeAddingWidgets()
Optional callback invoked very early, before widgets have been added (contrast with init(),...
Definition: modaldialog.hpp:123
In order to avoid calculating render information every frame, it's stored in a SkinWidgetContainer fo...
Definition: skin.hpp:141
Abstract base class representing a modal dialog.
Definition: modaldialog.hpp:55
virtual void init()
Optional callback invoked after widgets have been add()ed.
Definition: modaldialog.hpp:127
virtual int getHeight()
Implementing callback from AbstractTopLevelContainer.
Definition: modaldialog.hpp:137
virtual void loadedFromFile()
Callback invoked when the dialog was loaded from the XML file (if the constructor that takes a XML fi...
Definition: modaldialog.hpp:88
virtual EventPropagation processEvent(const std::string &eventSource)
Returns whether to block event propagation (usually, you will want to block events you processed)
Definition: modaldialog.hpp:101