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