GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/windowcontainer.cpp Lines: 7 29 24.1 %
Date: 2017-11-29 Branches: 0 16 0.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-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
23
#include "gui/widgets/windowcontainer.h"
24
25
#include "gui/widgets/window.h"
26
27
#include "utils/dtor.h"
28
#include "utils/foreach.h"
29
30
#include "debug.h"
31
32
WindowContainer *windowContainer = nullptr;
33
34
248
WindowContainer::WindowContainer(const Widget2 *const widget) :
35
    Container(widget),
36
496
    mDeathList()
37
{
38
248
}
39
40
496
void WindowContainer::slowLogic()
41
{
42
992
    delete_all(mDeathList);
43
992
    mDeathList.clear();
44
496
}
45
46
void WindowContainer::scheduleDelete(Widget *const widget)
47
{
48
    if (widget != nullptr)
49
        mDeathList.push_back(widget);
50
}
51
52
void WindowContainer::adjustAfterResize(const int oldScreenWidth,
53
                                        const int oldScreenHeight)
54
{
55
    FOR_EACH (WidgetListIterator, i, mWidgets)
56
    {
57
        if (Window *const window = dynamic_cast<Window*>(*i))
58
            window->adjustPositionAfterResize(oldScreenWidth, oldScreenHeight);
59
    }
60
}
61
62
void WindowContainer::moveWidgetAfter(Widget *const after,
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