GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/render/graphics_calcImageRect.hpp Lines: 42 42 100.0 %
Date: 2017-11-29 Branches: 20 28 71.4 %

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
24
// bool GraphicsX::calcImageRect(ImageVertexes *const vert,
25
//                               const int x, const int y,
26
//                               const int w, const int h,
27
//                               const ImageRect &imgRect)
28
29
332
if (!vert)
30
    return;
31
32
BLOCK_START("Graphics::calcImageRect")
33
34
332
const Image *restrict const *restrict const grid = imgRect.grid;
35
332
const Image *restrict const topLeft = grid[0];
36
332
const Image *restrict const topRight = grid[2];
37
332
const Image *restrict const bottomLeft = grid[6];
38
332
const Image *restrict const bottomRight = grid[8];
39
332
const Image *restrict const top = grid[1];
40
332
const Image *restrict const right = grid[5];
41
332
const Image *restrict const bottom = grid[7];
42
332
const Image *restrict const left = grid[3];
43
332
const Image *restrict const center = grid[4];
44
45
996
const bool drawMain = center && topLeft && topRight
46

664
    && bottomLeft && bottomRight;
47
48
// Draw the center area
49
332
if (center && drawMain)
50
{
51
310
    const int tlw = topLeft->getWidth();
52
310
    const int tlh = topLeft->getHeight();
53
620
    calcPatternInline(vert, center, tlw + x, tlh + y,
54
620
        w - tlw - topRight->getWidth(),
55
620
        h - tlh - bottomLeft->getHeight());
56
}
57
// Draw the sides
58

332
if (top && left && bottom && right)
59
{
60
310
    const int lw = left->getWidth();
61
310
    const int rw = right->getWidth();
62
310
    const int th = top->getHeight();
63
310
    const int bh = bottom->getHeight();
64
620
    calcPatternInline(vert, top, x + lw, y, w - lw - rw, th);
65
620
    calcPatternInline(vert, bottom, x + lw, y + h - bh, w - lw - rw, bh);
66
620
    calcPatternInline(vert, left, x, y + th, lw, h - th - bh);
67
310
    if (w > rw)
68
310
        calcPatternInline(vert, right, x + w - rw, y + th, rw, h - th - bh);
69
}
70
71
332
if (topLeft)
72
    calcTileVertexesInline(vert, topLeft, x, y);
73
332
if (topRight)
74
{
75
310
    const int trw = topRight->getWidth();
76
310
    if (w > trw)
77
310
        calcTileVertexesInline(vert, topRight, x + w - trw, y);
78
}
79
332
if (bottomLeft)
80
{
81
310
    calcTileVertexesInline(vert, bottomLeft,
82
620
        x, y + h - bottomLeft->getHeight());
83
}
84
332
if (bottomRight)
85
{
86
310
    const int brw = bottomRight->getWidth();
87
310
    if (w > brw)
88
    {
89
310
        calcTileVertexesInline(vert, bottomRight, x + w - brw,
90
620
            y + h - bottomRight->getHeight());
91
    }
92
}
93
94
BLOCK_END("Graphics::calcImageRect")