Debian Codegraph @

engine/core/gui/hybrid/hybridguimanager.cpp

raw
1 /***************************************************************************
2 * Copyright (C) 2005-2019 by the FIFE team *
3 * http://www.fifengine.net *
4 * This file is part of FIFE. *
5 * *
6 * FIFE is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Lesser General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2.1 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * Lesser General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with this library; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
21
22 // Standard C++ library includes
23
24 // 3rd party library includes
25
26 // FIFE includes
27 // These includes are split up in two parts, separated by one empty line
28 // First block: files included from the FIFE root src directory
29 // Second block: files included from the same folder
30 #include "util/log/logger.h"
31
32 #include "hybridguimanager.h"
33
34 namespace FIFE {
35
36 static Logger _log(LM_GUI);
37
38 HybridGuiManager::HybridGuiManager() {
39 }
40
41 HybridGuiManager::~HybridGuiManager() {
42 std::vector<IGUIManager*>::iterator currManager(m_guiManagers.begin());
43 std::vector<IGUIManager*>::iterator endManager(m_guiManagers.end());
44
45 for(; currManager != endManager; ++currManager) {
46 delete (*currManager);
47 }
48
49 m_guiManagers.clear();
50 }
51
52 void HybridGuiManager::addGuiManager(IGUIManager* guiManager) {
53 m_guiManagers.push_back(guiManager);
54 }
55
56 void HybridGuiManager::removeGuiManager(IGUIManager* guiManager) {
57 std::vector<IGUIManager*>::iterator currManager(m_guiManagers.begin());
58 std::vector<IGUIManager*>::iterator endManager(m_guiManagers.end());
59
60 for(; currManager != endManager;) {
61 if((*currManager) == guiManager) {
62 m_guiManagers.erase(currManager);
63 return;
64 }
65
66 ++currManager;
67 }
68
69 FL_WARN(_log, LMsg() << "Tyring to remove a non-existing gui manager from a hybrid gui manager.");
70 }
71
72 void HybridGuiManager::turn() {
73 //call turn in reverse order because we want prior gui managers to draw on top
74 //of latter ones.
75 std::vector<IGUIManager*>::reverse_iterator currManager(m_guiManagers.rbegin());
76 std::vector<IGUIManager*>::reverse_iterator endManager(m_guiManagers.rend());
77
78 for(; currManager != endManager; ++currManager) {
79 (*currManager)->turn();
80 }
81 }
82
83 bool HybridGuiManager::onSdlEvent(SDL_Event& event) {
84
85 bool consumed = false;
86
87 std::vector<IGUIManager*>::iterator currManager(m_guiManagers.begin());
88 std::vector<IGUIManager*>::iterator endManager(m_guiManagers.end());
89
90 for(; currManager != endManager; ++currManager) {
91 consumed = (*currManager)->onSdlEvent(event);
92
93 if (consumed) {
94 return true;
95 }
96 }
97
98 return false;
99 }
100
101 void HybridGuiManager::resizeTopContainer(uint32_t x, uint32_t y, uint32_t width, uint32_t height) {
102 std::vector<IGUIManager*>::iterator currManager(m_guiManagers.begin());
103 std::vector<IGUIManager*>::iterator endManager(m_guiManagers.end());
104
105 for(; currManager != endManager; ++currManager) {
106 (*currManager)->resizeTopContainer(x, y, width, height);
107 }
108 }
109 }