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-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
25 
26 #include "gui/widgets/window.h"
27 
28 #include "utils/checkutils.h"
29 #include "utils/dtor.h"
30 #include "utils/foreach.h"
31 
32 #include "debug.h"
33 
35 
37  Container(widget),
38  mDeathList(),
39  mDeathSet()
40 {
41 }
42 
44 {
46  mDeathList.clear();
47  mDeathSet.clear();
48 }
49 
51 {
52  if (widget == nullptr)
53  return;
54 
55  if (mDeathSet.find(widget) == mDeathSet.end())
56  {
57  mDeathList.push_back(widget);
58  mDeathSet.insert(widget);
59  }
60  else
61  {
62  reportAlways("double adding pointer %p for deletion in scheduleDelete",
63  static_cast<void*>(widget))
64  }
65 }
66 
67 void WindowContainer::adjustAfterResize(const int oldScreenWidth,
68  const int oldScreenHeight)
69 {
71  {
72  if (Window *const window = dynamic_cast<Window*>(*i))
73  window->adjustPositionAfterResize(oldScreenWidth, oldScreenHeight);
74  }
75 }
76 
78  Widget *const widget)
79 {
80  const WidgetListIterator widgetIter = std::find(
81  mWidgets.begin(), mWidgets.end(), widget);
82 
83  if (widgetIter != mWidgets.end())
84  {
85  WidgetListIterator afterIter = std::find(
86  mWidgets.begin(), mWidgets.end(), after);
87 
88  if (afterIter != mWidgets.end())
89  {
90  ++ afterIter;
91  mWidgets.erase(widgetIter);
92  mWidgets.insert(afterIter, widget);
93  }
94  }
95 
96  const WidgetListIterator widgetIter2 = std::find(
97  mLogicWidgets.begin(), mLogicWidgets.end(), widget);
98 
99  if (widgetIter2 != mLogicWidgets.end())
100  {
101  WidgetListIterator afterIter = std::find(
102  mLogicWidgets.begin(), mLogicWidgets.end(), after);
103 
104  if (afterIter != mLogicWidgets.end())
105  {
106  ++ afterIter;
107  mLogicWidgets.erase(widgetIter2);
108  mLogicWidgets.insert(afterIter, widget);
109  }
110  }
111 }
112 
113 #ifdef USE_PROFILER
114 void WindowContainer::draw(Graphics *const graphics)
115 {
116  BLOCK_START("WindowContainer::draw")
117  Container::draw(graphics);
119 }
120 #endif // USE_PROFILER
#define reportAlways(...)
Definition: checkutils.h:253
void draw(Graphics *const graphics)
WidgetList::iterator WidgetListIterator
WidgetList mWidgets
WidgetList mLogicWidgets
Definition: widget.h:99
void adjustAfterResize(const int oldScreenWidth, const int oldScreenHeight)
std::set< Widget * > mDeathSet
WindowContainer(const Widget2 *const widget)
void scheduleDelete(Widget *const widget)
void moveWidgetAfter(Widget *const before, Widget *const widget)
Definition: window.h:102
void delete_all(Container &c)
Definition: dtor.h:56
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25
bool find(const std::string &key)
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79
WindowContainer * windowContainer