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 |
|
|
|
24 |
|
|
#include "gui/widgets/windowcontainer.h" |
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 |
|
|
|
34 |
|
|
WindowContainer *windowContainer = nullptr; |
35 |
|
|
|
36 |
|
127 |
WindowContainer::WindowContainer(const Widget2 *const widget) : |
37 |
|
|
Container(widget), |
38 |
|
|
mDeathList(), |
39 |
|
381 |
mDeathSet() |
40 |
|
|
{ |
41 |
|
127 |
} |
42 |
|
|
|
43 |
|
254 |
void WindowContainer::slowLogic() |
44 |
|
|
{ |
45 |
|
508 |
delete_all(mDeathList); |
46 |
|
508 |
mDeathList.clear(); |
47 |
|
508 |
mDeathSet.clear(); |
48 |
|
254 |
} |
49 |
|
|
|
50 |
|
|
void WindowContainer::scheduleDelete(Widget *const widget) |
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 |
|
|
{ |
70 |
|
|
FOR_EACH (WidgetListIterator, i, mWidgets) |
71 |
|
|
{ |
72 |
|
|
if (Window *const window = dynamic_cast<Window*>(*i)) |
73 |
|
|
window->adjustPositionAfterResize(oldScreenWidth, oldScreenHeight); |
74 |
|
|
} |
75 |
|
|
} |
76 |
|
|
|
77 |
|
1 |
void WindowContainer::moveWidgetAfter(Widget *const after, |
78 |
|
|
Widget *const widget) |
79 |
|
|
{ |
80 |
|
|
const WidgetListIterator widgetIter = std::find( |
81 |
|
3 |
mWidgets.begin(), mWidgets.end(), widget); |
82 |
|
|
|
83 |
✓✗ |
3 |
if (widgetIter != mWidgets.end()) |
84 |
|
|
{ |
85 |
|
|
WidgetListIterator afterIter = std::find( |
86 |
|
3 |
mWidgets.begin(), mWidgets.end(), after); |
87 |
|
|
|
88 |
✗✓ |
3 |
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 |
|
3 |
mLogicWidgets.begin(), mLogicWidgets.end(), widget); |
98 |
|
|
|
99 |
✓✗ |
3 |
if (widgetIter2 != mLogicWidgets.end()) |
100 |
|
|
{ |
101 |
|
|
WidgetListIterator afterIter = std::find( |
102 |
|
3 |
mLogicWidgets.begin(), mLogicWidgets.end(), after); |
103 |
|
|
|
104 |
✗✓ |
3 |
if (afterIter != mLogicWidgets.end()) |
105 |
|
|
{ |
106 |
|
|
++ afterIter; |
107 |
|
|
mLogicWidgets.erase(widgetIter2); |
108 |
|
|
mLogicWidgets.insert(afterIter, widget); |
109 |
|
|
} |
110 |
|
|
} |
111 |
|
1 |
} |
112 |
|
|
|
113 |
|
|
#ifdef USE_PROFILER |
114 |
|
|
void WindowContainer::draw(Graphics *const graphics) |
115 |
|
|
{ |
116 |
|
|
BLOCK_START("WindowContainer::draw") |
117 |
|
|
Container::draw(graphics); |
118 |
|
|
BLOCK_END("WindowContainer::draw") |
119 |
|
|
} |
120 |
|
|
#endif // USE_PROFILER |