summaryrefslogtreecommitdiff
path: root/src/render/sdl2softwaregraphics.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-01-04 21:57:32 +0300
committerAndrei Karas <akaras@inbox.ru>2014-01-04 21:57:32 +0300
commit8a5603e487f682f5f67bc2cedae81249aa138f5b (patch)
tree697535ca4d8e50ee6da8cf364cad814fa5f7603a /src/render/sdl2softwaregraphics.cpp
parent80f7177ea4ce0185e1ef3355e91dcf14617d0f09 (diff)
parentf2d1d2b43a0ebdb625aea94cb4b8ff7fce6bf8f4 (diff)
downloadplus-8a5603e487f682f5f67bc2cedae81249aa138f5b.tar.gz
plus-8a5603e487f682f5f67bc2cedae81249aa138f5b.tar.bz2
plus-8a5603e487f682f5f67bc2cedae81249aa138f5b.tar.xz
plus-8a5603e487f682f5f67bc2cedae81249aa138f5b.zip
Merge branch 'master' into stable
Diffstat (limited to 'src/render/sdl2softwaregraphics.cpp')
-rw-r--r--src/render/sdl2softwaregraphics.cpp319
1 files changed, 276 insertions, 43 deletions
diff --git a/src/render/sdl2softwaregraphics.cpp b/src/render/sdl2softwaregraphics.cpp
index 7556bc5ac..95c8f08b1 100644
--- a/src/render/sdl2softwaregraphics.cpp
+++ b/src/render/sdl2softwaregraphics.cpp
@@ -2,7 +2,7 @@
* The ManaPlus Client
* Copyright (C) 2004-2009 The Mana World Development Team
* Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2013 The ManaPlus Developers
+ * Copyright (C) 2011-2014 The ManaPlus Developers
*
* This file is part of The ManaPlus Client.
*
@@ -62,12 +62,9 @@ SDL2SoftwareGraphics::~SDL2SoftwareGraphics()
}
bool SDL2SoftwareGraphics::drawRescaledImage(const Image *const image,
- int srcX, int srcY,
int dstX, int dstY,
- const int width, const int height,
const int desiredWidth,
- const int desiredHeight,
- const bool useColor A_UNUSED)
+ const int desiredHeight)
{
FUNC_BLOCK("Graphics::drawRescaledImage", 1)
// Check that preconditions for blitting are met.
@@ -89,10 +86,10 @@ bool SDL2SoftwareGraphics::drawRescaledImage(const Image *const image,
SDL_Rect srcRect =
{
- static_cast<int16_t>(srcX + bounds.x),
- static_cast<int16_t>(srcY + bounds.y),
- static_cast<uint16_t>(width),
- static_cast<uint16_t>(height)
+ static_cast<int16_t>(bounds.x),
+ static_cast<int16_t>(bounds.y),
+ static_cast<uint16_t>(bounds.w),
+ static_cast<uint16_t>(bounds.h)
};
SDL_Rect dstRect =
@@ -112,10 +109,13 @@ bool SDL2SoftwareGraphics::drawRescaledImage(const Image *const image,
}
bool SDL2SoftwareGraphics::drawImage2(const Image *const image,
- int srcX, int srcY,
- int dstX, int dstY, const int width,
- const int height,
- const bool useColor A_UNUSED)
+ int dstX, int dstY)
+{
+ return drawImageInline(image, dstX, dstY);
+}
+
+bool SDL2SoftwareGraphics::drawImageInline(const Image *const image,
+ int dstX, int dstY)
{
FUNC_BLOCK("Graphics::drawImage2", 1)
// Check that preconditions for blitting are met.
@@ -125,16 +125,15 @@ bool SDL2SoftwareGraphics::drawImage2(const Image *const image,
const gcn::ClipRectangle &top = mClipStack.top();
const SDL_Rect &bounds = image->mBounds;
-
SDL_Surface *const src = image->mSDLSurface;
- srcX += bounds.x;
- srcY += bounds.y;
+ int srcX = bounds.x;
+ int srcY = bounds.y;
dstX += top.xOffset;
dstY += top.yOffset;
- int w = width;
- int h = height;
+ int w = bounds.w;
+ int h = bounds.h;
if (srcX < 0)
{
w += srcX;
@@ -203,11 +202,219 @@ bool SDL2SoftwareGraphics::drawImage2(const Image *const image,
return 0;
}
-void SDL2SoftwareGraphics::drawImagePattern(const Image *const image,
- const int x, const int y,
- const int w, const int h)
+void SDL2SoftwareGraphics::drawImageCached(const Image *const image,
+ int x, int y)
+{
+ FUNC_BLOCK("Graphics::drawImageCached", 1)
+ // Check that preconditions for blitting are met.
+ if (!mSurface || !image || !image->mSDLSurface)
+ return;
+
+ const gcn::ClipRectangle &top = mClipStack.top();
+ const SDL_Rect &bounds = image->mBounds;
+
+ SDL_Surface *const src = image->mSDLSurface;
+
+ int srcX = bounds.x;
+ int srcY = bounds.y;
+ x += top.xOffset;
+ y += top.yOffset;
+
+ int w = bounds.w;
+ int h = bounds.h;
+ if (srcX < 0)
+ {
+ w += srcX;
+ x -= static_cast<int16_t>(srcX);
+ srcX = 0;
+ }
+ const int maxw = src->w - srcX;
+ if (maxw < w)
+ w = maxw;
+
+ if (srcY < 0)
+ {
+ h += srcY;
+ y -= static_cast<int16_t>(srcY);
+ srcY = 0;
+ }
+ const int maxh = src->h - srcY;
+ if (maxh < h)
+ h = maxh;
+
+ const SDL_Rect *const clip = &mSurface->clip_rect;
+ const int clipX = clip->x;
+ const int clipY = clip->y;
+ int dx = clipX - x;
+ if (dx > 0)
+ {
+ w -= dx;
+ x += static_cast<int16_t>(dx);
+ srcX += dx;
+ }
+ dx = x + w - clipX - clip->w;
+ if (dx > 0)
+ w -= dx;
+
+ int dy = clipY - y;
+ if (dy > 0)
+ {
+ h -= dy;
+ y += static_cast<int16_t>(dy);
+ srcY += dy;
+ }
+ dy = y + h - clipY - clip->h;
+ if (dy > 0)
+ h -= dy;
+
+ if (w > 0 && h > 0)
+ {
+ SDL_Rect srcRect =
+ {
+ static_cast<int16_t>(srcX),
+ static_cast<int16_t>(srcY),
+ static_cast<uint16_t>(w),
+ static_cast<uint16_t>(h)
+ };
+
+ SDL_Rect dstRect =
+ {
+ static_cast<int16_t>(x),
+ static_cast<int16_t>(y),
+ static_cast<uint16_t>(w),
+ static_cast<uint16_t>(h)
+ };
+
+ SDL_LowerBlit(src, &srcRect, mSurface, &dstRect);
+ }
+}
+
+void SDL2SoftwareGraphics::drawPatternCached(const Image *const image,
+ const int x, const int y,
+ const int w, const int h)
+{
+ FUNC_BLOCK("Graphics::drawPatternCached", 1)
+ // Check that preconditions for blitting are met.
+ if (!mSurface || !image)
+ return;
+ if (!image->mSDLSurface)
+ return;
+
+ const SDL_Rect &bounds = image->mBounds;
+ const int iw = bounds.w;
+ const int ih = bounds.h;
+ if (iw == 0 || ih == 0)
+ return;
+
+ const gcn::ClipRectangle &top = mClipStack.top();
+ const int xOffset = top.xOffset + x;
+ const int yOffset = top.yOffset + y;
+ const int srcX = bounds.x;
+ const int srcY = bounds.y;
+ SDL_Surface *const src = image->mSDLSurface;
+ const SDL_Rect *const clip = &mSurface->clip_rect;
+ const int clipX = clip->x;
+ const int clipY = clip->y;
+
+ for (int py = 0; py < h; py += ih)
+ {
+ const int dh = (py + ih >= h) ? h - py : ih;
+ int dstY = py + yOffset;
+ int y2 = srcY;
+ int h2 = dh;
+ if (y2 < 0)
+ {
+ h2 += y2;
+ dstY -= static_cast<int16_t>(y2);
+ y2 = 0;
+ }
+ const int maxh = src->h - y2;
+ if (maxh < h2)
+ h2 = maxh;
+
+ int dy = clipY - dstY;
+ if (dy > 0)
+ {
+ h2 -= dy;
+ dstY += static_cast<int16_t>(dy);
+ y2 += dy;
+ }
+ dy = dstY + h2 - clipY - clip->h;
+ if (dy > 0)
+ h2 -= dy;
+
+ if (h2 > 0)
+ {
+ for (int px = 0; px < w; px += iw)
+ {
+ const int dw = (px + iw >= w) ? w - px : iw;
+ int dstX = px + xOffset;
+ int x2 = srcX;
+ int w2 = dw;
+ if (x2 < 0)
+ {
+ w2 += x2;
+ dstX -= static_cast<int16_t>(x2);
+ x2 = 0;
+ }
+ const int maxw = src->w - x2;
+ if (maxw < w2)
+ w2 = maxw;
+
+ int dx = clipX - dstX;
+ if (dx > 0)
+ {
+ w2 -= dx;
+ dstX += static_cast<int16_t>(dx);
+ x2 += dx;
+ }
+ dx = dstX + w2 - clipX - clip->w;
+ if (dx > 0)
+ w2 -= dx;
+
+ if (w2 > 0)
+ {
+ SDL_Rect srcRect =
+ {
+ static_cast<int16_t>(x2),
+ static_cast<int16_t>(y2),
+ static_cast<uint16_t>(w2),
+ static_cast<uint16_t>(h2)
+ };
+
+ SDL_Rect dstRect =
+ {
+ static_cast<int16_t>(dstX),
+ static_cast<int16_t>(dstY),
+ static_cast<uint16_t>(w2),
+ static_cast<uint16_t>(h2)
+ };
+
+ SDL_LowerBlit(src, &srcRect, mSurface, &dstRect);
+ }
+
+// SDL_BlitSurface(image->mSDLSurface, &srcRect, mWindow, &dstRect);
+ }
+ }
+ }
+}
+
+void SDL2SoftwareGraphics::completeCache()
{
- FUNC_BLOCK("Graphics::drawImagePattern", 1)
+}
+
+void SDL2SoftwareGraphics::drawPattern(const Image *const image,
+ const int x, const int y,
+ const int w, const int h)
+{
+ drawPatternInline(image, x, y, w, h);
+}
+
+void SDL2SoftwareGraphics::drawPatternInline(const Image *const image,
+ const int x, const int y,
+ const int w, const int h)
+{
+ FUNC_BLOCK("Graphics::drawPattern", 1)
// Check that preconditions for blitting are met.
if (!mSurface || !image)
return;
@@ -313,11 +520,11 @@ void SDL2SoftwareGraphics::drawImagePattern(const Image *const image,
}
}
-void SDL2SoftwareGraphics::drawRescaledImagePattern(const Image *const image,
- const int x, const int y,
- const int w, const int h,
- const int scaledWidth,
- const int scaledHeight)
+void SDL2SoftwareGraphics::drawRescaledPattern(const Image *const image,
+ const int x, const int y,
+ const int w, const int h,
+ const int scaledWidth,
+ const int scaledHeight)
{
// Check that preconditions for blitting are met.
if (!mSurface || !image)
@@ -379,10 +586,18 @@ void SDL2SoftwareGraphics::drawRescaledImagePattern(const Image *const image,
delete tmpImage;
}
-void SDL2SoftwareGraphics::calcImagePattern(ImageVertexes* const vert,
- const Image *const image,
- const int x, const int y,
- const int w, const int h) const
+void SDL2SoftwareGraphics::calcPattern(ImageVertexes* const vert,
+ const Image *const image,
+ const int x, const int y,
+ const int w, const int h) const
+{
+ calcPatternInline(vert, image, x, y, w, h);
+}
+
+void SDL2SoftwareGraphics::calcPatternInline(ImageVertexes* const vert,
+ const Image *const image,
+ const int x, const int y,
+ const int w, const int h) const
{
// Check that preconditions for blitting are met.
if (!vert || !mSurface || !image || !image->mSDLSurface)
@@ -433,10 +648,10 @@ void SDL2SoftwareGraphics::calcImagePattern(ImageVertexes* const vert,
}
}
-void SDL2SoftwareGraphics::calcImagePattern(ImageCollection* const vertCol,
- const Image *const image,
- const int x, const int y,
- const int w, const int h) const
+void SDL2SoftwareGraphics::calcPattern(ImageCollection* const vertCol,
+ const Image *const image,
+ const int x, const int y,
+ const int w, const int h) const
{
ImageVertexes *vert = nullptr;
if (vertCol->currentImage != image)
@@ -452,7 +667,7 @@ void SDL2SoftwareGraphics::calcImagePattern(ImageCollection* const vertCol,
vert = vertCol->currentVert;
}
- calcImagePattern(vert, image, x, y, w, h);
+ calcPatternInline(vert, image, x, y, w, h);
}
void SDL2SoftwareGraphics::calcTileVertexes(ImageVertexes *const vert,
@@ -463,6 +678,14 @@ void SDL2SoftwareGraphics::calcTileVertexes(ImageVertexes *const vert,
calcTileSDL(vert, x, y);
}
+void SDL2SoftwareGraphics::calcTileVertexesInline(ImageVertexes *const vert,
+ const Image *const image,
+ int x, int y) const
+{
+ vert->image = image;
+ calcTileSDL(vert, x, y);
+}
+
void SDL2SoftwareGraphics::calcTileSDL(ImageVertexes *const vert,
int x, int y) const
{
@@ -589,7 +812,7 @@ bool SDL2SoftwareGraphics::drawNet(const int x1, const int y1,
return true;
}
-bool SDL2SoftwareGraphics::calcWindow(ImageCollection *const vertCol,
+void SDL2SoftwareGraphics::calcWindow(ImageCollection *const vertCol,
const int x, const int y,
const int w, const int h,
const ImageRect &imgRect)
@@ -608,12 +831,7 @@ bool SDL2SoftwareGraphics::calcWindow(ImageCollection *const vertCol,
{
vert = vertCol->currentVert;
}
-
- const Image *const *const grid = &imgRect.grid[0];
- return calcImageRect(vert, x, y, w, h,
- grid[0], grid[2], grid[6], grid[8],
- grid[1], grid[5], grid[7], grid[3],
- grid[4]);
+ calcImageRect(vert, x, y, w, h, imgRect);
}
int SDL2SoftwareGraphics::SDL_FakeUpperBlit(const SDL_Surface *const src,
@@ -1288,4 +1506,19 @@ bool SDL2SoftwareGraphics::resizeScreen(const int width, const int height)
return ret;
}
+void SDL2SoftwareGraphics::drawImageRect(const int x, const int y,
+ const int w, const int h,
+ const ImageRect &imgRect)
+{
+ #include "render/graphics_drawImageRect.hpp"
+}
+
+void SDL2SoftwareGraphics::calcImageRect(ImageVertexes *const vert,
+ const int x, const int y,
+ const int w, const int h,
+ const ImageRect &imgRect)
+{
+ #include "render/graphics_calcImageRect.hpp"
+}
+
#endif // USE_SDL2