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  protected:
64  irr::gui::IGUIWindow* m_irrlicht_window;
65  irr::core::rect< irr::s32 > m_area;
66  bool m_fade_background;
67 
68  InputManager::InputDriverMode m_previous_mode;
69 
73  ModalDialog(const float percentWidth, const float percentHeight,
74  ModalDialogLocation location = MODAL_DIALOG_LOCATION_CENTER);
75 
79  void loadFromFile(const char* xmlFile);
80 
81  virtual void onEnterPressedInternal();
82  void clearWindow();
83 
87  virtual void loadedFromFile() {}
88  void doInit();
89  void setArea();
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 
120  virtual void onResize();
121 
126  virtual void beforeAddingWidgets() {}
127  virtual void load() {}
128 
130  virtual void init() {}
131 
135  virtual int getWidth() { return m_area.getWidth(); }
136 
140  virtual int getHeight() { return m_area.getHeight(); }
141 
142  bool fadeBackground() const { return m_fade_background; }
143 
144  bool isMyIrrChild(irr::gui::IGUIElement* widget) const { return m_irrlicht_window->isMyChild(widget); }
145  virtual bool enableScreenPadding() const { return false; }
146  };
147 
148 }
149 #endif
Represents a GUI widgets container.
Definition: abstract_top_level_container.hpp:43
Abstract base class representing a modal dialog.
Definition: modaldialog.hpp:56
virtual void onResize()
Override to be notified of resizes.
Definition: modaldialog.cpp:214
virtual void init()
Optional callback invoked after widgets have been add()ed.
Definition: modaldialog.hpp:130
virtual int getHeight()
Implementing callback from AbstractTopLevelContainer.
Definition: modaldialog.hpp:140
void loadFromFile(const char *xmlFile)
Load a XML file to create the dialog from.
Definition: modaldialog.cpp:67
bool isInited()
Because C++ doesn't support constructor delegation...
Definition: modaldialog.hpp:96
virtual void onUpdate(float dt)
Override to be notified of updates.
Definition: modaldialog.hpp:117
virtual void beforeAddingWidgets()
Optional callback invoked very early, before widgets have been added (contrast with init(),...
Definition: modaldialog.hpp:126
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
virtual bool onEscapePressed()
Override to change what happens on escape pressed.
Definition: modaldialog.hpp:114
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:54
virtual int getWidth()
Implementing callback from AbstractTopLevelContainer.
Definition: modaldialog.hpp:135
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:87
In order to avoid calculating render information every frame, it's stored in a SkinWidgetContainer fo...
Definition: skin.hpp:142
Contains all GUI engine related classes and functions.
Definition: abstract_state_manager.hpp:33