jubilant-funicular
Screen.h
1 #ifndef NTA_SCREEN_H_INCLUDED
2 #define NTA_SCREEN_H_INCLUDED
3 
4 #include "nta/Window.h"
5 #include "nta/InputManager.h"
6 
7 namespace nta {
8  class ScreenManager;
9  class ResourceManager;
10  enum class ScreenState{NONE, RUNNING, SWITCH, SWITCH_ESC, SWITCH_X};
12  class SetManagerKey {
13  friend class ScreenManager;
14  SetManagerKey() {}
16  SetManagerKey& operator=(const SetManagerKey&);
17  };
19  class SetIndicesKey {
20  friend class ScreenManager;
21  SetIndicesKey() {}
23  SetIndicesKey& operator=(const SetIndicesKey&);
24  };
26  class SetWindowKey {
27  friend class ScreenManager;
28  SetWindowKey() {}
29  SetWindowKey(const SetWindowKey&);
30  SetWindowKey& operator=(const SetWindowKey&);
31  };
34  ScreenSwitchInfo() : data(nullptr), fromIndex(-1) {
35  }
36  ScreenSwitchInfo(void* data) : data(data), fromIndex(-1) {
37  }
38  ScreenSwitchInfo(void* data, int index) : data(data), fromIndex(index) {
39  }
40 
42  void* data;
44  int fromIndex;
45  };
47  class Screen {
48  private:
50  int m_index = -1;
52  int m_escIndex = -1;
54  int m_xIndex = -1;
55  protected:
56  const InputManager& getInput() const;
57 
59  ScreenState m_state = ScreenState::NONE;
63  Window* m_window = nullptr;
65  std::string m_name;
67  int m_nextIndex = -1;
69  void* m_switchData = nullptr;
70  public:
72  Screen(crstring name = "UNAMED_SCREEN");
73  virtual ~Screen();
75  ScreenState getState() const;
77  std::string getName() const;
79  int getEscIndex() const;
80  int getXIndex() const;
81  int getNextIndex() const;
82  int getIndex() const;
84  void* getSwitchData() const;
86  void setManager(ScreenManager* manager, SetManagerKey key);
88  void setIndices(int index, int escIndex, int xIndex, SetIndicesKey key);
90  void setWindow(crstring title, SetWindowKey key);
92  virtual void render() = 0;
94  virtual void update() = 0;
96  virtual void onFocus(const ScreenSwitchInfo& info);
98  virtual void offFocus();
100  virtual void init() = 0;
101  void close() { m_state = ScreenState::SWITCH_X; }
102  void esc() { m_state = ScreenState::SWITCH_ESC; }
103  };
104 }
105 
106 #endif // NTA_SCREEN_H_INCLUDED
nta::Screen::getName
std::string getName() const
gets name of screen
Definition: Screen.cpp:19
nta::Screen::m_window
Window * m_window
the Window this Screen appears on
Definition: Screen.h:63
nta::Screen::setManager
void setManager(ScreenManager *manager, SetManagerKey key)
Sets the manager of this screen.
Definition: Screen.cpp:37
nta::Screen::setWindow
void setWindow(crstring title, SetWindowKey key)
sets the window to associate with this screen
Definition: Screen.cpp:45
nta::SetManagerKey
Key unlocking the setManager() "private" function of class Screen.
Definition: Screen.h:12
nta::Screen::render
virtual void render()=0
renders screen
nta::ScreenSwitchInfo
Info passed to Screen::onFocus.
Definition: Screen.h:33
nta::Screen::setIndices
void setIndices(int index, int escIndex, int xIndex, SetIndicesKey key)
sets various screen indices
Definition: Screen.cpp:40
nta::Screen::offFocus
virtual void offFocus()
called when the screen is no longer active
Definition: Screen.cpp:51
nta::Screen::m_state
ScreenState m_state
the state of this screen
Definition: Screen.h:59
nta::Screen::Screen
Screen(crstring name="UNAMED_SCREEN")
basic constructor and destructor
Definition: Screen.cpp:9
nta::Screen::m_name
std::string m_name
the name of the Screen
Definition: Screen.h:65
nta::Screen::m_manager
ScreenManager * m_manager
the ScreenManager that owns this screen
Definition: Screen.h:61
nta::Screen::onFocus
virtual void onFocus(const ScreenSwitchInfo &info)
called when the screen becomes active
Definition: Screen.cpp:48
nta::Screen::m_switchData
void * m_switchData
data to pass to the new screen (via onFocus) when m_state == SWITCH
Definition: Screen.h:69
nta::Screen::m_nextIndex
int m_nextIndex
the index of the screen to go to when m_state == SWITCH
Definition: Screen.h:67
nta::Screen::m_index
int m_index
the index of this screen in its container
Definition: Screen.h:50
nta::ScreenSwitchInfo::fromIndex
int fromIndex
the index of the screen switched from
Definition: Screen.h:44
nta::Screen::getState
ScreenState getState() const
returns state of screen
Definition: Screen.cpp:16
nta::Window
Represent a window.
Definition: Window.h:30
nta
Definition: Animation2D.h:6
nta::SetWindowKey
Key unlocking the setWindow() "private" function of class Screen.
Definition: Screen.h:26
nta::ScreenManager
Definition: ScreenManager.h:16
nta::Screen
Represents a game screen.
Definition: Screen.h:47
nta::Screen::m_escIndex
int m_escIndex
the index of the screen to go to when the Esc key is pressed
Definition: Screen.h:52
nta::Screen::init
virtual void init()=0
initializes the screen
nta::SetIndicesKey
Key unlocking the setIndices() "private" function of class Screen.
Definition: Screen.h:19
nta::ScreenSwitchInfo::data
void * data
arbitrary data to pass along
Definition: Screen.h:42
nta::InputManager
keeps track of all input
Definition: InputManager.h:20
nta::Screen::getSwitchData
void * getSwitchData() const
gets the switch data (shoudl this require a key?)
Definition: Screen.cpp:34
nta::Screen::update
virtual void update()=0
updates screen
nta::Screen::m_xIndex
int m_xIndex
the index of the screen to go to when the window's X button is pressed
Definition: Screen.h:54
nta::Screen::getEscIndex
int getEscIndex() const
gets various screen indices
Definition: Screen.cpp:22