From abad3f0ef49e3891ceef6844adeb139778de6738 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 26 Aug 2013 20:05:01 +0300 Subject: fix SDL_Rect field types in SDL2. --- src/sdl2graphics.cpp | 134 ++++++++++++++++++++++++--------------------------- 1 file changed, 64 insertions(+), 70 deletions(-) (limited to 'src') diff --git a/src/sdl2graphics.cpp b/src/sdl2graphics.cpp index e24978e37..a0ca2e04d 100644 --- a/src/sdl2graphics.cpp +++ b/src/sdl2graphics.cpp @@ -42,12 +42,6 @@ #include "debug.h" -#if SDL_BYTEORDER == SDL_LIL_ENDIAN -static unsigned int *cR = nullptr; -static unsigned int *cG = nullptr; -static unsigned int *cB = nullptr; -#endif - #ifdef DEBUG_SDL_SURFACES #define MSDL_RenderCopy(render, texture, src, dst) \ @@ -103,17 +97,17 @@ bool SDLGraphics::drawRescaledImage(const Image *const image, int srcX, int srcY const SDL_Rect &bounds = image->mBounds; const SDL_Rect srcRect { - static_cast(srcX + bounds.x), - static_cast(srcY + bounds.y), - static_cast(width), - static_cast(height) + static_cast(srcX + bounds.x), + static_cast(srcY + bounds.y), + static_cast(width), + static_cast(height) }; const SDL_Rect dstRect { - static_cast(dstX + top.xOffset), - static_cast(dstY + top.yOffset), - static_cast(desiredWidth), - static_cast(desiredHeight) + static_cast(dstX + top.xOffset), + static_cast(dstY + top.yOffset), + static_cast(desiredWidth), + static_cast(desiredHeight) }; return (MSDL_RenderCopy(mRenderer, image->mTexture, @@ -133,17 +127,17 @@ bool SDLGraphics::drawImage2(const Image *const image, int srcX, int srcY, const SDL_Rect &bounds = image->mBounds; const SDL_Rect srcRect { - static_cast(srcX + bounds.x), - static_cast(srcY + bounds.y), - static_cast(width), - static_cast(height) + static_cast(srcX + bounds.x), + static_cast(srcY + bounds.y), + static_cast(width), + static_cast(height) }; const SDL_Rect dstRect { - static_cast(dstX + top.xOffset), - static_cast(dstY + top.yOffset), - static_cast(width), - static_cast(height) + static_cast(dstX + top.xOffset), + static_cast(dstY + top.yOffset), + static_cast(width), + static_cast(height) }; return !MSDL_RenderCopy(mRenderer, image->mTexture, &srcRect, &dstRect); @@ -172,21 +166,21 @@ void SDLGraphics::drawImagePattern(const Image *const image, SDL_Rect dstRect; SDL_Rect srcRect; - srcRect.x = static_cast(bounds.x); - srcRect.y = static_cast(bounds.y); + srcRect.x = static_cast(bounds.x); + srcRect.y = static_cast(bounds.y); for (int py = 0; py < h; py += ih) { const int dh = (py + ih >= h) ? h - py : ih; - dstRect.y = static_cast(py + yOffset); - srcRect.h = static_cast(dh); - dstRect.h = static_cast(dh); + dstRect.y = static_cast(py + yOffset); + srcRect.h = static_cast(dh); + dstRect.h = static_cast(dh); for (int px = 0; px < w; px += iw) { const int dw = (px + iw >= w) ? w - px : iw; - dstRect.x = static_cast(px + xOffset); - srcRect.w = static_cast(dw); - dstRect.w = static_cast(dw); + dstRect.x = static_cast(px + xOffset); + srcRect.w = static_cast(dw); + dstRect.w = static_cast(dw); MSDL_RenderCopy(mRenderer, image->mTexture, &srcRect, &dstRect); } @@ -225,21 +219,21 @@ void SDLGraphics::drawRescaledImagePattern(const Image *const image, SDL_Rect dstRect; SDL_Rect srcRect; - srcRect.x = static_cast(bounds.x); - srcRect.y = static_cast(bounds.y); + srcRect.x = static_cast(bounds.x); + srcRect.y = static_cast(bounds.y); for (int py = 0; py < h; py += ih) { const int dh = (py + ih >= h) ? h - py : ih; - dstRect.y = static_cast(py + yOffset); - srcRect.h = static_cast(dh); - dstRect.h = static_cast(dh); + dstRect.y = static_cast(py + yOffset); + srcRect.h = static_cast(dh); + dstRect.h = static_cast(dh); for (int px = 0; px < w; px += iw) { const int dw = (px + iw >= w) ? w - px : iw; - dstRect.x = static_cast(px + xOffset); - srcRect.w = static_cast(dw); - dstRect.w = static_cast(dw); + dstRect.x = static_cast(px + xOffset); + srcRect.w = static_cast(dw); + dstRect.w = static_cast(dw); MSDL_RenderCopy(mRenderer, image->mTexture, &srcRect, &dstRect); } @@ -281,14 +275,14 @@ void SDLGraphics::calcImagePattern(ImageVertexes* const vert, DoubleRect *const r = new DoubleRect(); SDL_Rect &dstRect = r->dst; SDL_Rect &srcRect = r->src; - srcRect.x = static_cast(srcX); - srcRect.y = static_cast(srcY); - srcRect.w = static_cast(dw); - srcRect.h = static_cast(dh); - dstRect.x = static_cast(dstX); - dstRect.y = static_cast(dstY); - dstRect.w = static_cast(dw); - dstRect.h = static_cast(dh); + srcRect.x = static_cast(srcX); + srcRect.y = static_cast(srcY); + srcRect.w = static_cast(dw); + srcRect.h = static_cast(dh); + dstRect.x = static_cast(dstX); + dstRect.y = static_cast(dstY); + dstRect.w = static_cast(dw); + dstRect.h = static_cast(dh); vert->sdl.push_back(r); } @@ -342,14 +336,14 @@ void SDLGraphics::calcTileSDL(ImageVertexes *const vert, int x, int y) const SDL_Rect &dstRect = rect->dst; SDL_Rect &srcRect = rect->src; - srcRect.x = static_cast(bounds.x); - srcRect.y = static_cast(bounds.y); - srcRect.w = static_cast(bounds.w); - srcRect.h = static_cast(bounds.h); - dstRect.x = static_cast(x); - dstRect.y = static_cast(y); - dstRect.w = static_cast(bounds.w); - dstRect.h = static_cast(bounds.h); + srcRect.x = static_cast(bounds.x); + srcRect.y = static_cast(bounds.y); + srcRect.w = static_cast(bounds.w); + srcRect.h = static_cast(bounds.h); + dstRect.x = static_cast(x); + dstRect.y = static_cast(y); + dstRect.w = static_cast(bounds.w); + dstRect.h = static_cast(bounds.h); vert->sdl.push_back(rect); } @@ -483,10 +477,10 @@ void SDLGraphics::fillRectangle(const gcn::Rectangle &rectangle) const gcn::ClipRectangle &top = mClipStack.top(); const SDL_Rect rect { - static_cast(rectangle.x + top.xOffset), - static_cast(rectangle.y + top.yOffset), - static_cast(rectangle.width), - static_cast(rectangle.height) + static_cast(rectangle.x + top.xOffset), + static_cast(rectangle.y + top.yOffset), + static_cast(rectangle.width), + static_cast(rectangle.height) }; SDL_SetRenderDrawColor(mRenderer, mColor.r, mColor.g, mColor.b, mColor.a); @@ -510,10 +504,10 @@ bool SDLGraphics::pushClipArea(gcn::Rectangle area) const gcn::ClipRectangle &carea = mClipStack.top(); const SDL_Rect rect { - static_cast(carea.x), - static_cast(carea.y), - static_cast(carea.width), - static_cast(carea.height) + static_cast(carea.x), + static_cast(carea.y), + static_cast(carea.width), + static_cast(carea.height) }; SDL_RenderSetClipRect(mRenderer, &rect); return result; @@ -529,10 +523,10 @@ void SDLGraphics::popClipArea() const gcn::ClipRectangle &carea = mClipStack.top(); const SDL_Rect rect { - static_cast(carea.x), - static_cast(carea.y), - static_cast(carea.width), - static_cast(carea.height) + static_cast(carea.x), + static_cast(carea.y), + static_cast(carea.width), + static_cast(carea.height) }; SDL_RenderSetClipRect(mRenderer, &rect); @@ -561,10 +555,10 @@ void SDLGraphics::drawRectangle(const gcn::Rectangle &rectangle) const gcn::ClipRectangle &top = mClipStack.top(); const SDL_Rect rect { - static_cast(rectangle.x) + top.xOffset, - static_cast(rectangle.y) + top.yOffset, - static_cast(rectangle.width), - static_cast(rectangle.height) + static_cast(rectangle.x) + top.xOffset, + static_cast(rectangle.y) + top.yOffset, + static_cast(rectangle.width), + static_cast(rectangle.height) }; SDL_SetRenderDrawColor(mRenderer, mColor.r, mColor.g, mColor.b, mColor.a); -- cgit v1.2.3-60-g2f50