GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/layoutcell.cpp Lines: 58 58 100.0 %
Date: 2018-09-09 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-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/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
1
static LayoutArray tempArray;
33
1
LayoutCell LayoutCell::emptyCell;
34
35
2280
LayoutCell::~LayoutCell()
36
{
37
790
    if (mType == ARRAY)
38
160
        delete2(mArray)
39
1490
}
40
41
829
LayoutArray &LayoutCell::getArray()
42
{
43
829
    if (mType == WIDGET)
44
        return tempArray;
45
829
    if (mType == ARRAY)
46
    {
47
669
        if (mArray == nullptr)
48
            return tempArray;
49
669
        return *mArray;
50
    }
51
52
160
    mArray = new LayoutArray;
53
160
    mType = ARRAY;
54
160
    mExtent[0] = 1;
55
160
    mExtent[1] = 1;
56
160
    mHPadding = 0;
57
160
    mVPadding = 0;
58
160
    mAlign[0] = FILL;
59
160
    mAlign[1] = FILL;
60
160
    return *mArray;
61
}
62
63
1020
void LayoutCell::reflow(int nx, int ny, int nw, int nh)
64
{
65
1020
    if (mType == NONE)
66
        return;
67
68
1020
    nx += mHPadding;
69
1020
    ny += mVPadding;
70
1020
    nw -= 2 * mHPadding;
71
1020
    nh -= 2 * mVPadding;
72
1020
    if (mType == ARRAY)
73
214
        mArray->reflow(nx, ny, nw, nh);
74
    else
75
806
        mWidget->setDimension(Rect(nx, ny, nw, nh));
76
}
77
78
158
void LayoutCell::computeSizes()
79
{
80
158
    if (mType != ARRAY)
81
        return;
82
83
    STD_VECTOR <STD_VECTOR <LayoutCell *> >::const_iterator
84
474
        i = mArray->mCells.begin();
85
    const STD_VECTOR <STD_VECTOR <LayoutCell *> >::const_iterator
86
474
        i_end = mArray->mCells.end();
87
1628
    while (i != i_end)
88
    {
89
1470
        STD_VECTOR <LayoutCell *>::const_iterator j = i->begin();
90
15450
        while (j != i->end())
91
        {
92
4415
            LayoutCell *const cell = *j;
93

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

4
}