GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/windowcontainer.cpp Lines: 18 34 52.9 %
Date: 2018-05-19 03:07:18 Branches: 4 20 20.0 %

Line Branch Exec Source
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
23
#include "gui/widgets/windowcontainer.h"
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
33
WindowContainer *windowContainer = nullptr;
34
35
252
WindowContainer::WindowContainer(const Widget2 *const widget) :
36
    Container(widget),
37
    mDeathList(),
38
756
    mDeathSet()
39
{
40
252
}
41
42
504
void WindowContainer::slowLogic()
43
{
44
1008
    delete_all(mDeathList);
45
1008
    mDeathList.clear();
46
1008
    mDeathSet.clear();
47
504
}
48
49
void WindowContainer::scheduleDelete(Widget *const widget)
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
{
69
    FOR_EACH (WidgetListIterator, i, mWidgets)
70
    {
71
        if (Window *const window = dynamic_cast<Window*>(*i))
72
            window->adjustPositionAfterResize(oldScreenWidth, oldScreenHeight);
73
    }
74
}
75
76
2
void WindowContainer::moveWidgetAfter(Widget *const after,
77
                                      Widget *const widget)
78
{
79
    const WidgetListIterator widgetIter = std::find(
80
6
        mWidgets.begin(), mWidgets.end(), widget);
81
82
6
    if (widgetIter != mWidgets.end())
83
    {
84
        WidgetListIterator afterIter = std::find(
85
6
            mWidgets.begin(), mWidgets.end(), after);
86
87
6
        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
6
        mLogicWidgets.begin(), mLogicWidgets.end(), widget);
97
98
6
    if (widgetIter2 != mLogicWidgets.end())
99
    {
100
        WidgetListIterator afterIter = std::find(
101
6
            mLogicWidgets.begin(), mLogicWidgets.end(), after);
102
103
6
        if (afterIter != mLogicWidgets.end())
104
        {
105
            ++ afterIter;
106
            mLogicWidgets.erase(widgetIter2);
107
            mLogicWidgets.insert(afterIter, widget);
108
        }
109
    }
110
2
}
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