diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-03-24 19:20:49 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-03-26 07:30:39 +0000 |
commit | 4091bd9568e5aff4a1f24416d26da567a2c076ad (patch) | |
tree | 32285c49c19821d5d287fab29cf264a647735ded /src/sdlgraphics.cpp | |
parent | 4604ee1caf00fe1a8c095119c1046e7f625e1f0b (diff) | |
download | mana-4091bd9568e5aff4a1f24416d26da567a2c076ad.tar.gz mana-4091bd9568e5aff4a1f24416d26da567a2c076ad.tar.bz2 mana-4091bd9568e5aff4a1f24416d26da567a2c076ad.tar.xz mana-4091bd9568e5aff4a1f24416d26da567a2c076ad.zip |
Added functions to draw images at sub-pixel positions
This can be used for smoother mouse cursor movement when rendering our
own mouse cursor (already changed in this commit) and is also necessary
for implementing support for HiDPI font rendering.
Also dropped some almost duplicated OpenGL code.
Diffstat (limited to 'src/sdlgraphics.cpp')
-rw-r--r-- | src/sdlgraphics.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/sdlgraphics.cpp b/src/sdlgraphics.cpp index 8e77a64f..dc56496e 100644 --- a/src/sdlgraphics.cpp +++ b/src/sdlgraphics.cpp @@ -134,6 +134,37 @@ bool SDLGraphics::drawRescaledImage(Image *image, return !(SDL_RenderCopy(mRenderer, image->mTexture, &srcRect, &dstRect) < 0); } +#if SDL_VERSION_ATLEAST(2, 0, 10) +bool SDLGraphics::drawRescaledImageF(Image *image, + int srcX, int srcY, + float dstX, float dstY, + int width, int height, + float desiredWidth, float desiredHeight, + bool useColor) +{ + // Check that preconditions for blitting are met. + if (!image || !image->mTexture) + return false; + + dstX += mClipStack.top().xOffset; + dstY += mClipStack.top().yOffset; + + srcX += image->mBounds.x; + srcY += image->mBounds.y; + + SDL_FRect dstRect; + SDL_Rect srcRect; + dstRect.x = dstX; dstRect.y = dstY; + srcRect.x = srcX; srcRect.y = srcY; + srcRect.w = width; + srcRect.h = height; + dstRect.w = desiredWidth; + dstRect.h = desiredHeight; + + return !(SDL_RenderCopyF(mRenderer, image->mTexture, &srcRect, &dstRect) < 0); +} +#endif + void SDLGraphics::drawRescaledImagePattern(Image *image, int x, int y, int w, int h, |