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-2018 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/checkutils.h"
28 #include "utils/dtor.h"
29 #include "utils/foreach.h"
30 
31 #include "debug.h"
32 
34 
36  Container(widget),
37  mDeathList(),
38  mDeathSet()
39 {
40 }
41 
43 {
45  mDeathList.clear();
46  mDeathSet.clear();
47 }
48 
50 {
51  if (widget == nullptr)
52  return;
53 
54  if (mDeathSet.find(widget) == mDeathSet.end())
55  {
56  mDeathList.push_back(widget);
57  mDeathSet.insert(widget);
58  }
59  else
60  {
61  reportAlways("double adding pointer %p for deletion in scheduleDelete",
62  static_cast<void*>(widget));
63  }
64 }
65 
66 void WindowContainer::adjustAfterResize(const int oldScreenWidth,
67  const int oldScreenHeight)
68 {
70  {
71  if (Window *const window = dynamic_cast<Window*>(*i))
72  window->adjustPositionAfterResize(oldScreenWidth, oldScreenHeight);
73  }
74 }
75 
77  Widget *const widget)
78 {
79  const WidgetListIterator widgetIter = std::find(
80  mWidgets.begin(), mWidgets.end(), widget);
81 
82  if (widgetIter != mWidgets.end())
83  {
84  WidgetListIterator afterIter = std::find(
85  mWidgets.begin(), mWidgets.end(), after);
86 
87  if (afterIter != mWidgets.end())
88  {
89  ++ afterIter;
90  mWidgets.erase(widgetIter);
91  mWidgets.insert(afterIter, widget);
92  }
93  }
94 
95  const WidgetListIterator widgetIter2 = std::find(
96  mLogicWidgets.begin(), mLogicWidgets.end(), widget);
97 
98  if (widgetIter2 != mLogicWidgets.end())
99  {
100  WidgetListIterator afterIter = std::find(
101  mLogicWidgets.begin(), mLogicWidgets.end(), after);
102 
103  if (afterIter != mLogicWidgets.end())
104  {
105  ++ afterIter;
106  mLogicWidgets.erase(widgetIter2);
107  mLogicWidgets.insert(afterIter, widget);
108  }
109  }
110 }
111 
112 #ifdef USE_PROFILER
113 void WindowContainer::draw(Graphics *const graphics)
114 {
115  BLOCK_START("WindowContainer::draw")
116  Container::draw(graphics);
117  BLOCK_END("WindowContainer::draw")
118 }
119 #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)
std::set< Widget * > mDeathSet
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
#define reportAlways(...)
Definition: checkutils.h:252
WidgetList::iterator WidgetListIterator