ManaPlus
graphics_calcImageRect.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 // bool GraphicsX::calcImageRect(ImageVertexes *const vert,
26 // const int x, const int y,
27 // const int w, const int h,
28 // const ImageRect &imgRect)
29 
30 if (!vert)
31  return;
32 
33 BLOCK_START("Graphics::calcImageRect")
34 
35 const Image *restrict const *restrict const grid = imgRect.grid;
36 const Image *restrict const topLeft = grid[0];
37 const Image *restrict const topRight = grid[2];
38 const Image *restrict const bottomLeft = grid[6];
39 const Image *restrict const bottomRight = grid[8];
40 const Image *restrict const top = grid[1];
41 const Image *restrict const right = grid[5];
42 const Image *restrict const bottom = grid[7];
43 const Image *restrict const left = grid[3];
44 const Image *restrict const center = grid[4];
45 
46 const bool drawMain = center && topLeft && topRight
47  && bottomLeft && bottomRight;
48 
49 // Draw the center area
51 {
52  const int tlw = topLeft->getWidth();
53  const int tlh = topLeft->getHeight();
54  calcPatternInline(vert, center, tlw + x, tlh + y,
55  w - tlw - topRight->getWidth(),
56  h - tlh - bottomLeft->getHeight());
57 }
58 // Draw the sides
59 if (top && left && bottom && right)
60 {
61  const int lw = left->getWidth();
62  const int rw = right->getWidth();
63  const int th = top->getHeight();
64  const int bh = bottom->getHeight();
65  calcPatternInline(vert, top, x + lw, y, w - lw - rw, th);
66  calcPatternInline(vert, bottom, x + lw, y + h - bh, w - lw - rw, bh);
67  calcPatternInline(vert, left, x, y + th, lw, h - th - bh);
68  if (w > rw)
69  calcPatternInline(vert, right, x + w - rw, y + th, rw, h - th - bh);
70 }
71 
72 if (topLeft)
75 {
76  const int trw = topRight->getWidth();
77  if (w > trw)
78  calcTileVertexesInline(vert, topRight, x + w - trw, y);
79 }
81 {
83  x, y + h - bottomLeft->getHeight());
84 }
86 {
87  const int brw = bottomRight->getWidth();
88  if (w > brw)
89  {
90  calcTileVertexesInline(vert, bottomRight, x + w - brw,
91  y + h - bottomRight->getHeight());
92  }
93 }
94 
95 BLOCK_END("Graphics::calcImageRect")
const Image *restrict const bottomLeft
BLOCK_START("Graphics::calcImageRect") const Image *restrict const *restrict const grid
const Image *restrict const left
if(!vert) return
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
const Image *restrict const topLeft
const Image *restrict const right
void calcPatternInline(ImageVertexes *restrict const vert, const Image *restrict const image, const int x, const int y, const int w, const int h) const restrict2 A_INLINE
void calcTileVertexesInline(ImageVertexes *restrict const vert, const Image *restrict const image, int x, int y) const restrict2 A_INLINE A_NONNULL(2
#define restrict
Definition: localconsts.h:165
#define BLOCK_END(name)
Definition: perfomance.h:80