ManaPlus
graphics_drawImageRect.hpp
Go to the documentation of this file.
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 const Image *restrict const *restrict const grid = imgRect.grid;
32 const Image *restrict const topLeft = grid[0];
33 const Image *restrict const topRight = grid[2];
34 const Image *restrict const bottomLeft = grid[6];
35 const Image *restrict const bottomRight = grid[8];
36 const Image *restrict const top = grid[1];
37 const Image *restrict const right = grid[5];
38 const Image *restrict const bottom = grid[7];
39 const Image *restrict const left = grid[3];
40 const Image *restrict const center = grid[4];
41 
42 const bool drawMain = center && topLeft && topRight
43  && bottomLeft && bottomRight;
44 
45 // Draw the center area
47 {
48  const int tlw = topLeft->getWidth();
49  const int tlh = topLeft->getHeight();
50  drawPatternInline(center, tlw + x, tlh + y,
51  w - tlw - topRight->getWidth(),
52  h - tlh - bottomLeft->getHeight());
53 }
54 
55 // Draw the sides
56 if (top && left && bottom && right)
57 {
58  const int lw = left->getWidth();
59  const int rw = right->getWidth();
60  const int th = top->getHeight();
61  const int bh = bottom->getHeight();
62  drawPatternInline(top, x + lw, y, w - lw - rw, th);
63  drawPatternInline(bottom, x + lw, h - bh + y, w - lw - rw, bh);
64  drawPatternInline(left, x, y + th, lw, h - th - bh);
65  if (w > rw)
66  drawPatternInline(right, x + w - rw, th + y, rw, h - th - bh);
67 }
68 // Draw the corners
70 {
72  const int trw = topRight->getWidth();
73  if (w > trw)
74  drawImageInline(topRight, x + w - trw, y);
75  drawImageInline(bottomLeft, x, h - bottomLeft->getHeight() + y);
76  const int brw = bottomRight->getWidth();
77  if (w > brw)
78  {
80  x + w - brw,
81  y + h - bottomRight->getHeight());
82  }
83 }
84 BLOCK_END("Graphics::drawImageRect")
const Image *restrict const bottomLeft
const Image *restrict const left
BLOCK_START("Graphics::drawImageRect") const Image *restrict const *restrict const grid
const Image *restrict const bottom
const Image *restrict const center
const Image *restrict const top
const bool drawMain
const Image *restrict const topRight
const Image *restrict const bottomRight
if(center &&drawMain)
const Image *restrict const right
const Image *restrict const topLeft
void drawPatternInline(const Image *restrict const image, const int x, const int y, const int w, const int h) restrict2 A_INLINE
void void drawImageInline(const Image *restrict const image, int dstX, int dstY) restrict2 A_INLINE
#define restrict
Definition: localconsts.h:165
#define BLOCK_END(name)
Definition: perfomance.h:80