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

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

4
}