jubilant-funicular
ScreenManager.h
1 #ifndef NTA_SCREENMANAGER_H_INCLUDED
2 #define NTA_SCREENMANAGER_H_INCLUDED
3 
4 #include <vector>
5 #include <mutex>
6 
7 #include "nta/Screen.h"
8 #include "nta/FPSLimiter.h"
9 #include "nta/Window.h"
10 #include "nta/InputManager.h"
11 #include "nta/ContextData.h"
12 
13 namespace nta {
16  class ScreenManager {
17  private:
19  void update_input();
20 
21  static std::mutex m_window_creation_lock;
23  static std::mutex m_event_lock;
24 
26  std::vector<Screen*> m_screens;
36  int m_currScreen = -1;
37  public:
39  ScreenManager(crstring title, float maxFPS, int width = 640, int height = 480);
43  Screen* getCurrScreen() const;
45  const Window* getWindow() const { return m_window; }
47  const InputManager& getInput() const { return m_input; }
51  float getFPS() const;
54  bool owns_event(const SDL_Event& event) const;
56  void setResourceFolders(const utils::Path& tex_fldr,
57  const utils::Path& glsl_fldr,
58  const utils::Path& font_fldr);
60  void addScreen(Screen* newScreen, int escIndex = -1, int xIndex = -1, crstring title = "");
62  void switchScreen(int newIndex);
64  void destroy();
68  void run(void* initFocusData = nullptr);
69  };
70 }
71 
72 #endif // NTA_SCREENMANAGER_H_INCLUDED
nta::ScreenManager::run
void run(void *initFocusData=nullptr)
Definition: ScreenManager.cpp:141
nta::ScreenManager::addScreen
void addScreen(Screen *newScreen, int escIndex=-1, int xIndex=-1, crstring title="")
adds a screen and sets some of its properties
Definition: ScreenManager.cpp:42
nta::ScreenManager::m_currScreen
int m_currScreen
the index of the currently active screen
Definition: ScreenManager.h:36
nta::ScreenManager::~ScreenManager
~ScreenManager()
basic destructor
Definition: ScreenManager.cpp:25
nta::ScreenManager::setResourceFolders
void setResourceFolders(const utils::Path &tex_fldr, const utils::Path &glsl_fldr, const utils::Path &font_fldr)
Sets the location of textures, shaders, and fonts.
Definition: ScreenManager.cpp:35
nta::ScreenManager::m_event_lock
static std::mutex m_event_lock
Lock for access the event queue.
Definition: ScreenManager.h:23
nta::ScreenManager::m_limiter
FPSLimiter m_limiter
used to cap the FPS
Definition: ScreenManager.h:32
nta::ContextData
Definition: ContextData.h:17
nta::ScreenManager::getInput
const InputManager & getInput() const
returns the InputManager
Definition: ScreenManager.h:47
nta::ScreenManager::destroy
void destroy()
destroys screens
Definition: ScreenManager.cpp:178
utils::Path
A (case-sensitive) Path in a file system.
Definition: Path.h:16
nta::ScreenManager::ScreenManager
ScreenManager(crstring title, float maxFPS, int width=640, int height=480)
sets the max fps and the window to use
Definition: ScreenManager.cpp:20
nta::ScreenManager::m_screens
std::vector< Screen * > m_screens
the screens
Definition: ScreenManager.h:26
nta::Window
Represent a window.
Definition: Window.h:30
nta
Definition: Animation2D.h:6
nta::ScreenManager
Definition: ScreenManager.h:16
nta::ScreenManager::getCurrScreen
Screen * getCurrScreen() const
returns the active screen
Definition: ScreenManager.cpp:28
nta::ScreenManager::owns_event
bool owns_event(const SDL_Event &event) const
Definition: ScreenManager.cpp:79
nta::ScreenManager::update_input
void update_input()
Updates the state of m_input.
Definition: ScreenManager.cpp:87
nta::Screen
Represents a game screen.
Definition: Screen.h:47
nta::ScreenManager::m_context_data
ContextData m_context_data
GLTextures and GLSLPrograms and whatnot.
Definition: ScreenManager.h:28
nta::ScreenManager::m_window
Window * m_window
the main window used by the manager
Definition: ScreenManager.h:34
nta::ScreenManager::m_input
InputManager m_input
Keeps track of all input received in this window.
Definition: ScreenManager.h:30
nta::FPSLimiter
used to cap the fps of the program at a specific value
Definition: FPSLimiter.h:8
nta::InputManager
keeps track of all input
Definition: InputManager.h:20
nta::ScreenManager::getWindow
const Window * getWindow() const
returns the window
Definition: ScreenManager.h:45
nta::ScreenManager::switchScreen
void switchScreen(int newIndex)
switches the to a new screen
Definition: ScreenManager.cpp:56
nta::ScreenManager::getContextData
ContextData & getContextData()
returns the ContextData
Definition: ScreenManager.h:49
nta::ScreenManager::getFPS
float getFPS() const
returns the current fps
Definition: ScreenManager.cpp:32