GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/layoutcell.cpp Lines: 58 58 100.0 %
Date: 2017-11-29 Branches: 22 30 73.3 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2007-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/layoutcell.h"
24
25
#include "gui/widgets/layoutarray.h"
26
#include "gui/widgets/widget.h"
27
28
#include "utils/delete2.h"
29
30
#include "debug.h"
31
32
2
static LayoutArray tempArray;
33
2
LayoutCell LayoutCell::emptyCell;
34
35
4182
LayoutCell::~LayoutCell()
36
{
37
1452
    if (mType == ARRAY)
38
308
        delete2(mArray)
39
2730
}
40
41
1528
LayoutArray &LayoutCell::getArray()
42
{
43
1528
    if (mType == WIDGET)
44
        return tempArray;
45
1528
    if (mType == ARRAY)
46
    {
47
1220
        if (mArray == nullptr)
48
            return tempArray;
49
1220
        return *mArray;
50
    }
51
52
308
    mArray = new LayoutArray;
53
308
    mType = ARRAY;
54
308
    mExtent[0] = 1;
55
308
    mExtent[1] = 1;
56
308
    mHPadding = 0;
57
308
    mVPadding = 0;
58
308
    mAlign[0] = FILL;
59
308
    mAlign[1] = FILL;
60
308
    return *mArray;
61
}
62
63
1912
void LayoutCell::reflow(int nx, int ny, int nw, int nh)
64
{
65
1912
    if (mType == NONE)
66
        return;
67
68
1912
    nx += mHPadding;
69
1912
    ny += mVPadding;
70
1912
    nw -= 2 * mHPadding;
71
1912
    nh -= 2 * mVPadding;
72
1912
    if (mType == ARRAY)
73
416
        mArray->reflow(nx, ny, nw, nh);
74
    else
75
2992
        mWidget->setDimension(Rect(nx, ny, nw, nh));
76
}
77
78
304
void LayoutCell::computeSizes()
79
{
80
304
    if (mType != ARRAY)
81
        return;
82
83
    STD_VECTOR <STD_VECTOR <LayoutCell *> >::const_iterator
84
912
        i = mArray->mCells.begin();
85
    const STD_VECTOR <STD_VECTOR <LayoutCell *> >::const_iterator
86
912
        i_end = mArray->mCells.end();
87
3108
    while (i != i_end)
88
    {
89
2804
        STD_VECTOR <LayoutCell *>::const_iterator j = i->begin();
90
29970
        while (j != i->end())
91
        {
92
8588
            LayoutCell *const cell = *j;
93

8588
            if ((cell != nullptr) && cell->mType == ARRAY)
94
136
                cell->computeSizes();
95
96
            ++j;
97
        }
98
1402
        ++i;
99
    }
100
101
304
    mSize[0] = mArray->getSize(0);
102
304
    mSize[1] = mArray->getSize(1);
103
}
104
105
148
LayoutCell &LayoutCell::at(const int x, const int y)
106
{
107
148
    return getArray().at(x, y);
108
}
109
110
1130
LayoutCell &LayoutCell::place(Widget *const wg,
111
                              const int x, const int y,
112
                              const int w, const int h)
113
{
114
1130
    return getArray().place(wg, x, y, w, h);
115
}
116
117
12
void LayoutCell::matchColWidth(const int n1, const int n2)
118
{
119
12
    getArray().matchColWidth(n1, n2);
120
12
}
121
122
6
void LayoutCell::setColWidth(const int n, const int w)
123
{
124
6
    getArray().setColWidth(n, w);
125
6
}
126
127
58
void LayoutCell::setRowHeight(const int n, const int h)
128
{
129
58
    getArray().setRowHeight(n, h);
130
58
}
131
132
2
void LayoutCell::extend(const int x, const int y,
133
                        const int w, const int h)
134
{
135
2
    getArray().extend(x, y, w, h);
136

8
}