GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/render/graphics_drawImageRect.hpp Lines: 39 39 100.0 %
Date: 2017-11-29 Branches: 10 20 50.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
24
// void GraphicsX::drawImageRect(const int x, const int y,
25
//                               const int w, const int h,
26
//                               const ImageRect &imgRect)
27
28
BLOCK_START("Graphics::drawImageRect")
29
30
90
const Image *restrict const *restrict const grid = imgRect.grid;
31
90
const Image *restrict const topLeft = grid[0];
32
90
const Image *restrict const topRight = grid[2];
33
90
const Image *restrict const bottomLeft = grid[6];
34
90
const Image *restrict const bottomRight = grid[8];
35
90
const Image *restrict const top = grid[1];
36
90
const Image *restrict const right = grid[5];
37
90
const Image *restrict const bottom = grid[7];
38
90
const Image *restrict const left = grid[3];
39
90
const Image *restrict const center = grid[4];
40
41
270
const bool drawMain = center && topLeft && topRight
42

180
    && bottomLeft && bottomRight;
43
44
// Draw the center area
45
90
if (center && drawMain)
46
{
47
90
    const int tlw = topLeft->getWidth();
48
90
    const int tlh = topLeft->getHeight();
49
180
    drawPatternInline(center, tlw + x, tlh + y,
50
180
        w - tlw - topRight->getWidth(),
51
180
        h - tlh - bottomLeft->getHeight());
52
}
53
54
// Draw the sides
55

90
if (top && left && bottom && right)
56
{
57
90
    const int lw = left->getWidth();
58
90
    const int rw = right->getWidth();
59
90
    const int th = top->getHeight();
60
90
    const int bh = bottom->getHeight();
61
180
    drawPatternInline(top, x + lw, y, w - lw - rw, th);
62
180
    drawPatternInline(bottom, x + lw, h - bh + y, w - lw - rw, bh);
63
180
    drawPatternInline(left, x, y + th, lw, h - th - bh);
64
90
    if (w > rw)
65
90
        drawPatternInline(right, x + w - rw, th + y, rw, h - th - bh);
66
}
67
// Draw the corners
68
90
if (drawMain)
69
{
70
90
    drawImageInline(topLeft, x, y);
71
90
    const int trw = topRight->getWidth();
72
90
    if (w > trw)
73
90
        drawImageInline(topRight, x + w - trw, y);
74
180
    drawImageInline(bottomLeft, x, h - bottomLeft->getHeight() + y);
75
90
    const int brw = bottomRight->getWidth();
76
90
    if (w > brw)
77
    {
78
180
        drawImageInline(bottomRight,
79
90
            x + w - brw,
80
180
            y + h - bottomRight->getHeight());
81
    }
82
}
83
BLOCK_END("Graphics::drawImageRect")