BARE2D
ScreenList.cpp
Go to the documentation of this file.
1 #include "ScreenList.hpp"
2 
3 #include "Screen.hpp"
4 
5 namespace BARE2D {
6 
8  {
9  }
10 
12  {
13  for(unsigned int i = 0; i < m_screens.size(); i++) {
14  m_screens[i]->destroyScreen();
15  delete m_screens[i];
16  }
17  m_currentScreen = nullptr;
18  m_previousScreen = nullptr;
19  }
20 
22  {
23  screen->initScreen();
24  m_screens.push_back(screen);
25  }
26 
28  {
29  m_currentScreen = screen;
30  addScreen(screen);
31  }
32 
34  {
35  // Make sure we don't do something dumb.
36  if(m_currentScreen) {
37  if((long unsigned int)m_currentScreen->getNextScreenIndex() < m_screens.size()) {
38  // Exit the current screen
40 
41  // Move to the next
43 
44  // Enter the next
46  }
47  }
48  }
49 
51  {
52  // Make sure we don't do dumb stuff
53  if(m_previousScreen) {
54  // Take a temporary variable to swap this and the previous screen.
55  Screen* prev = m_currentScreen;
56 
57  // Exit this one
59 
60  // Move to previous, set the new previous
62  m_previousScreen = prev;
63 
64  // Enter previous
66  }
67  }
68 
70  return m_currentScreen;
71  }
72 
73 }
BARE2D::Screen
This is meant to be a parent for other, app-specific, screen classes, which is essentially where all ...
Definition: Screen.hpp:16
BARE2D::ScreenList::~ScreenList
~ScreenList()
Destroys the screen list, "taking care" of the screen pointers it owns.
Definition: ScreenList.cpp:11
BARE2D
Definition: App.cpp:13
Screen.hpp
BARE2D::ScreenList::moveToPreviousScreen
void moveToPreviousScreen()
Moves to the previous screen. Similar to moveToNextScreen, in that it makes sure everything's good!
Definition: ScreenList.cpp:50
BARE2D::Screen::onEntry
virtual void onEntry()=0
This is pretty close to the init function. It is called every time the screen is entered.
ScreenList.hpp
BARE2D::ScreenList::m_screens
std::vector< Screen * > m_screens
Definition: ScreenList.hpp:52
BARE2D::Screen::initScreen
virtual void initScreen()=0
This is called once, at the start of the program, when the screen is added to the screen list.
BARE2D::ScreenList::m_currentScreen
Screen * m_currentScreen
Definition: ScreenList.hpp:54
BARE2D::ScreenList::addScreen
void addScreen(Screen *screen)
Adds a screen to the list of screens, AKA the screen list. Requires non-nullptr. Also,...
Definition: ScreenList.cpp:21
BARE2D::ScreenList::m_previousScreen
Screen * m_previousScreen
Definition: ScreenList.hpp:53
BARE2D::ScreenList::addEntryScreen
void addEntryScreen(Screen *screen)
Adds a screen, and sets the current screen to this one.
Definition: ScreenList.cpp:27
BARE2D::ScreenList::ScreenList
ScreenList()
Definition: ScreenList.cpp:7
BARE2D::ScreenList::moveToNextScreen
void moveToNextScreen()
Moves to the next screen, updates needed variables. Also, exits old screen and enters new one.
Definition: ScreenList.cpp:33
BARE2D::Screen::onExit
virtual void onExit()=0
This is close to the destroy function, but is only called when the screen is exited,...
BARE2D::ScreenList::getCurrentScreen
Screen * getCurrentScreen()
Definition: ScreenList.cpp:69
BARE2D::Screen::getNextScreenIndex
virtual int getNextScreenIndex() const =0
Returns the index of the next screen. It is recommended to keep a file, say, ScreenIndices....