ManaPlus
windowcontainer.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2004-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2017 The ManaPlus Developers
6  *
7  * This file is part of The ManaPlus Client.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
24 
25 #include "gui/widgets/window.h"
26 
27 #include "utils/dtor.h"
28 #include "utils/foreach.h"
29 
30 #include "debug.h"
31 
33 
35  Container(widget),
36  mDeathList()
37 {
38 }
39 
41 {
43  mDeathList.clear();
44 }
45 
47 {
48  if (widget != nullptr)
49  mDeathList.push_back(widget);
50 }
51 
52 void WindowContainer::adjustAfterResize(const int oldScreenWidth,
53  const int oldScreenHeight)
54 {
56  {
57  if (Window *const window = dynamic_cast<Window*>(*i))
58  window->adjustPositionAfterResize(oldScreenWidth, oldScreenHeight);
59  }
60 }
61 
63  Widget *const widget)
64 {
65  const WidgetListIterator widgetIter = std::find(
66  mWidgets.begin(), mWidgets.end(), widget);
67 
68  if (widgetIter != mWidgets.end())
69  {
70  WidgetListIterator afterIter = std::find(
71  mWidgets.begin(), mWidgets.end(), after);
72 
73  if (afterIter != mWidgets.end())
74  {
75  ++ afterIter;
76  mWidgets.erase(widgetIter);
77  mWidgets.insert(afterIter, widget);
78  }
79  }
80 
81  const WidgetListIterator widgetIter2 = std::find(
82  mLogicWidgets.begin(), mLogicWidgets.end(), widget);
83 
84  if (widgetIter2 != mLogicWidgets.end())
85  {
86  WidgetListIterator afterIter = std::find(
87  mLogicWidgets.begin(), mLogicWidgets.end(), after);
88 
89  if (afterIter != mLogicWidgets.end())
90  {
91  ++ afterIter;
92  mLogicWidgets.erase(widgetIter2);
93  mLogicWidgets.insert(afterIter, widget);
94  }
95  }
96 }
97 
98 #ifdef USE_PROFILER
99 void WindowContainer::draw(Graphics *const graphics)
100 {
101  BLOCK_START("WindowContainer::draw")
102  Container::draw(graphics);
103  BLOCK_END("WindowContainer::draw")
104 }
105 #endif // USE_PROFILER
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
void scheduleDelete(Widget *const widget)
void moveWidgetAfter(Widget *const before, Widget *const widget)
WindowContainer * windowContainer
WindowContainer(const Widget2 *const widget)
Definition: window.h:98
#define BLOCK_START(name)
Definition: perfomance.h:78
#define BLOCK_END(name)
Definition: perfomance.h:79
WidgetList mLogicWidgets
void draw(Graphics *const graphics)
bool find(const std::string &key)
void delete_all(Container &c)
Definition: dtor.h:55
void adjustAfterResize(const int oldScreenWidth, const int oldScreenHeight)
Definition: widget.h:97
WidgetList mWidgets
WidgetList::iterator WidgetListIterator