ManaPlus
surfacegraphics.cpp
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-2018 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 #include "render/surfacegraphics.h"
24 
25 #ifndef USE_SDL2
27 #endif // USE_SDL2
28 
29 #include "resources/image/image.h"
30 
31 #include "debug.h"
32 
34  Graphics(),
35  mBlitMode(BlitMode::BLIT_NORMAL),
36  mTarget(nullptr)
37 {
39  mName = "Surface";
40 }
41 
43 {
44 }
45 
46 void SurfaceGraphics::drawImage(const Image *restrict const image,
47  int dstX, int dstY) restrict2
48 {
49  FUNC_BLOCK("Graphics::drawImage", 1)
50  // Check that preconditions for blitting are met.
51  if (mTarget == nullptr ||
52  image == nullptr ||
53  image->mSDLSurface == nullptr)
54  {
55  return;
56  }
57 
58  const SDL_Rect &imageRect = image->mBounds;
59  SDL_Rect dstRect;
60  SDL_Rect srcRect;
61  dstRect.x = CAST_S16(dstX);
62  dstRect.y = CAST_S16(dstY);
63  srcRect.x = CAST_S16(imageRect.x);
64  srcRect.y = CAST_S16(imageRect.y);
65  srcRect.w = CAST_U16(imageRect.w);
66  srcRect.h = CAST_U16(imageRect.h);
67 
68 #ifdef USE_SDL2
69  SDL_BlitSurface(image->mSDLSurface, &srcRect, mTarget, &dstRect);
70 #else // USE_SDL2
71 
73  {
74  SDL_BlitSurface(image->mSDLSurface, &srcRect, mTarget, &dstRect);
75  }
76  else
77  {
78  SurfaceImageHelper::combineSurface(image->mSDLSurface,
79  &srcRect, mTarget, &dstRect);
80  }
81 #endif // USE_SDL2
82 }
83 
84 void SurfaceGraphics::copyImage(const Image *restrict const image,
85  int dstX, int dstY) restrict2
86 {
87  FUNC_BLOCK("Graphics::drawImage", 1)
88  // Check that preconditions for blitting are met.
89  if (mTarget == nullptr ||
90  image == nullptr ||
91  image->mSDLSurface == nullptr)
92  {
93  return;
94  }
95 
96  const SDL_Rect &imageRect = image->mBounds;
97  SDL_Rect dstRect;
98  SDL_Rect srcRect;
99  dstRect.x = CAST_S16(dstX);
100  dstRect.y = CAST_S16(dstY);
101  srcRect.x = CAST_S16(imageRect.x);
102  srcRect.y = CAST_S16(imageRect.y);
103  srcRect.w = CAST_U16(imageRect.w);
104  srcRect.h = CAST_U16(imageRect.h);
105 
106 #ifdef USE_SDL2
107  // probably need change some flags
108  SDL_BlitSurface(image->mSDLSurface, &srcRect, mTarget, &dstRect);
109 #else // USE_SDL2
110 
111  SDL_BlitSurface(image->mSDLSurface, &srcRect, mTarget, &dstRect);
112 #endif // USE_SDL2
113 }
114 
116  int x, int y) restrict2
117 {
118  FUNC_BLOCK("Graphics::drawImageCached", 1)
119  // Check that preconditions for blitting are met.
120  if (mTarget == nullptr ||
121  image == nullptr ||
122  image->mSDLSurface == nullptr)
123  {
124  return;
125  }
126 
127  const SDL_Rect &rect = image->mBounds;
128 
129  SDL_Rect dstRect;
130  SDL_Rect srcRect;
131  dstRect.x = CAST_S16(x);
132  dstRect.y = CAST_S16(y);
133  srcRect.x = CAST_S16(rect.x);
134  srcRect.y = CAST_S16(rect.y);
135  srcRect.w = CAST_U16(rect.w);
136  srcRect.h = CAST_U16(rect.h);
137 
138 #ifdef USE_SDL2
139  SDL_BlitSurface(image->mSDLSurface, &srcRect, mTarget, &dstRect);
140 #else // USE_SDL2
141 
143  {
144  SDL_BlitSurface(image->mSDLSurface, &srcRect, mTarget, &dstRect);
145  }
146  else
147  {
148  SurfaceImageHelper::combineSurface(image->mSDLSurface, &srcRect,
149  mTarget, &dstRect);
150  }
151 #endif // USE_SDL2
152 }
153 
155 {
156 }
std::string mName
Definition: graphics.h:548
RenderType mOpenGL
Definition: graphics.h:544
void drawImageCached(const Image *const image, int x, int y)
#define CAST_U16
Definition: cast.h:28
SDL_Surface * mTarget
#define nullptr
Definition: localconsts.h:44
void drawImage(const Image *const image, int dstX, int dstY)
#define FUNC_BLOCK(name, id)
Definition: perfomance.h:80
Definition: image.h:61
#define restrict
Definition: localconsts.h:156
#define CAST_S16
Definition: cast.h:27
void copyImage(const Image *const image, int dstX, int dstY)
#define restrict2
Definition: localconsts.h:157