forked from Barnold1953/GraphicsTutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScreenList.cpp
More file actions
56 lines (45 loc) · 1.55 KB
/
ScreenList.cpp
File metadata and controls
56 lines (45 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "ScreenList.h"
#include "IGameScreen.h"
namespace Bengine {
ScreenList::ScreenList(IMainGame* game) :
m_game(game) {
// Empty
}
ScreenList::~ScreenList() {
destroy();
}
IGameScreen* Bengine::ScreenList::moveNext() {
IGameScreen* currentScreen = getCurrent();
if (currentScreen->getNextScreenIndex() != SCREEN_INDEX_NO_SCREEN) {
m_currentScreenIndex = currentScreen->getNextScreenIndex();
}
return getCurrent();
}
IGameScreen* Bengine::ScreenList::movePrevious() {
IGameScreen* currentScreen = getCurrent();
if (currentScreen->getPreviousScreenIndex() != SCREEN_INDEX_NO_SCREEN) {
m_currentScreenIndex = currentScreen->getPreviousScreenIndex();
}
return getCurrent();
}
void Bengine::ScreenList::setScreen(int nextScreen) {
m_currentScreenIndex = nextScreen;
}
void Bengine::ScreenList::addScreen(IGameScreen* newScreen) {
newScreen->m_screenIndex = m_screens.size();
m_screens.push_back(newScreen);
newScreen->build();
newScreen->setParentGame(m_game);
}
void Bengine::ScreenList::destroy() {
for (size_t i = 0; i < m_screens.size(); i++) {
m_screens[i]->destroy();
}
m_screens.resize(0);
m_currentScreenIndex = SCREEN_INDEX_NO_SCREEN;
}
IGameScreen* ScreenList::getCurrent() {
if (m_currentScreenIndex == SCREEN_INDEX_NO_SCREEN) return nullptr;
return m_screens[m_currentScreenIndex];
}
}