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

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

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