From 72a967ff3a452565ad2f15a944803e4b65f7bbd0 Mon Sep 17 00:00:00 2001 From: Jarod42 Date: Sat, 18 Nov 2023 10:59:20 +0100 Subject: [PATCH] Revert parameter of `gcn::SDLGraphics::setTarget` to `SDL_Surface*`. --- src/guichan/include/guichan/sdl/sdlgraphics.h | 13 +++-- src/guichan/sdl/sdlgraphics.cpp | 53 ++++++++++--------- src/ui/widgets.cpp | 2 +- src/video/video.cpp | 14 ++++- 4 files changed, 52 insertions(+), 30 deletions(-) diff --git a/src/guichan/include/guichan/sdl/sdlgraphics.h b/src/guichan/include/guichan/sdl/sdlgraphics.h index 2620509073..42d32139f9 100644 --- a/src/guichan/include/guichan/sdl/sdlgraphics.h +++ b/src/guichan/include/guichan/sdl/sdlgraphics.h @@ -83,13 +83,20 @@ namespace gcn SDLGraphics(); /** - * Pointer to the target surface to render into. The target can be any + * Sets the target SDL_Surface to draw to. The target can be any * SDL_Surface. This funtion also pushes a clip areas corresponding to * the dimension of the target. * * @param target the target to draw to. */ - virtual void setTarget(SDL_Surface** surface); + virtual void setTarget(SDL_Surface* surface); + + /** + * Gets the target SDL_Surface. + * + * @return the target SDL_Surface. + */ + virtual SDL_Surface* getTarget() const; /** * Draws an SDL_Surface on the target surface. Normaly you'll @@ -147,7 +154,7 @@ namespace gcn */ virtual void drawVLine(int x, int y1, int y2); - SDL_Surface** mTarget; + SDL_Surface* mTarget; Color mColor; bool mAlpha; }; diff --git a/src/guichan/sdl/sdlgraphics.cpp b/src/guichan/sdl/sdlgraphics.cpp index 087e0587ec..b136971c98 100644 --- a/src/guichan/sdl/sdlgraphics.cpp +++ b/src/guichan/sdl/sdlgraphics.cpp @@ -84,8 +84,8 @@ namespace gcn Rectangle area; area.x = 0; area.y = 0; - area.width = (*mTarget)->w; - area.height = (*mTarget)->h; + area.width = mTarget->w; + area.height = mTarget->h; pushClipArea(area); } @@ -94,11 +94,11 @@ namespace gcn popClipArea(); } - void SDLGraphics::setTarget(SDL_Surface** targetPtr) + void SDLGraphics::setTarget(SDL_Surface* target) { - mTarget = targetPtr; - Assert(SDL_MUSTLOCK(*mTarget) == 0); + mTarget = target; } + bool SDLGraphics::pushClipArea(Rectangle area) { SDL_Rect rect; @@ -110,7 +110,7 @@ namespace gcn rect.w = carea.width; rect.h = carea.height; - SDL_SetClipRect(*mTarget, &rect); + SDL_SetClipRect(mTarget, &rect); return result; } @@ -131,7 +131,12 @@ namespace gcn rect.w = carea.width; rect.h = carea.height; - SDL_SetClipRect(*mTarget, &rect); + SDL_SetClipRect(mTarget, &rect); + } + + SDL_Surface* SDLGraphics::getTarget() const + { + return mTarget; } void SDLGraphics::drawImage(const Image* image, int srcX, @@ -157,7 +162,7 @@ namespace gcn if (!SDL_SetSurfaceAlphaMod(srcImage, c.a)) { SDL_SetSurfaceAlphaMod(srcImage, 255); } - SDL_BlitSurface(srcImage, &src, *mTarget, &dst); + SDL_BlitSurface(srcImage, &src, mTarget, &dst); } void SDLGraphics::fillRectangle(const Rectangle& rectangle) @@ -184,7 +189,7 @@ namespace gcn { for (x = x1; x < x2; x++) { - SDLputPixelAlpha(*mTarget, x, y, mColor); + SDLputPixelAlpha(mTarget, x, y, mColor); } } } @@ -196,8 +201,8 @@ namespace gcn rect.w = area.width; rect.h = area.height; - Uint32 color = SDL_MapRGBA((*mTarget)->format, mColor.r, mColor.g, mColor.b, mColor.a); - SDL_FillRect(*mTarget, &rect, color); + Uint32 color = SDL_MapRGBA(mTarget->format, mColor.r, mColor.g, mColor.b, mColor.a); + SDL_FillRect(mTarget, &rect, color); } } @@ -212,11 +217,11 @@ namespace gcn if (mAlpha) { - SDLputPixelAlpha(*mTarget, x, y, mColor); + SDLputPixelAlpha(mTarget, x, y, mColor); } else { - SDLputPixel(*mTarget, x, y, mColor); + SDLputPixel(mTarget, x, y, mColor); } } @@ -255,7 +260,7 @@ namespace gcn x2 = top.x + top.width -1; } Uint32 color = - SDL_MapRGB((*mTarget)->format, mColor.r, mColor.g, mColor.b); + SDL_MapRGB(mTarget->format, mColor.r, mColor.g, mColor.b); if (mAlpha) { Video.DrawTransHLine(color, x1, y, x2 - x1, mColor.a); } else { @@ -298,7 +303,7 @@ namespace gcn y2 = top.y + top.height - 1; } Uint32 color = - SDL_MapRGB((*mTarget)->format, mColor.r, mColor.g, mColor.b); + SDL_MapRGB(mTarget->format, mColor.r, mColor.g, mColor.b); if (mAlpha) { Video.DrawTransVLine(color, x, y1,y2 - y1, mColor.a); } else { @@ -370,11 +375,11 @@ namespace gcn { if (mAlpha) { - SDLputPixelAlpha(*mTarget, x, y, mColor); + SDLputPixelAlpha(mTarget, x, y, mColor); } else { - SDLputPixel(*mTarget, x, y, mColor); + SDLputPixel(mTarget, x, y, mColor); } } @@ -398,11 +403,11 @@ namespace gcn { if (mAlpha) { - SDLputPixelAlpha(*mTarget, x, y, mColor); + SDLputPixelAlpha(mTarget, x, y, mColor); } else { - SDLputPixel(*mTarget, x, y, mColor); + SDLputPixel(mTarget, x, y, mColor); } } @@ -442,11 +447,11 @@ namespace gcn { if (mAlpha) { - SDLputPixelAlpha(*mTarget, x, y, mColor); + SDLputPixelAlpha(mTarget, x, y, mColor); } else { - SDLputPixel(*mTarget, x, y, mColor); + SDLputPixel(mTarget, x, y, mColor); } } @@ -470,11 +475,11 @@ namespace gcn { if (mAlpha) { - SDLputPixelAlpha(*mTarget, x, y, mColor); + SDLputPixelAlpha(mTarget, x, y, mColor); } else { - SDLputPixel(*mTarget, x, y, mColor); + SDLputPixel(mTarget, x, y, mColor); } } @@ -509,6 +514,6 @@ namespace gcn destination.x += top.xOffset; destination.y += top.yOffset; - SDL_BlitSurface(surface, &source, *mTarget, &destination); + SDL_BlitSurface(surface, &source, mTarget, &destination); } } diff --git a/src/ui/widgets.cpp b/src/ui/widgets.cpp index 0f81fa4318..ea0ccf39a0 100644 --- a/src/ui/widgets.cpp +++ b/src/ui/widgets.cpp @@ -91,7 +91,7 @@ void initGuichan() // Set the target for the graphics object to be the screen. // In other words, we will draw to the screen. // Note, any surface will do, it doesn't have to be the screen. - graphics->setTarget(&TheScreen); + graphics->setTarget(TheScreen); Input = std::make_unique(); diff --git a/src/video/video.cpp b/src/video/video.cpp index aad584271c..99c1818913 100644 --- a/src/video/video.cpp +++ b/src/video/video.cpp @@ -82,8 +82,6 @@ #include "stratagus.h" -#include - #include "video.h" #include "intern_video.h" @@ -92,9 +90,15 @@ #include "iolib.h" #include "map.h" #include "ui.h" +#include "widgets.h" #include #include +#include +#include + +extern std::unique_ptr Gui; + /*---------------------------------------------------------------------------- -- Declarations @@ -294,6 +298,12 @@ bool CVideo::ResizeScreen(int w, int h) 0); // AMASK); Assert(SDL_MUSTLOCK(TheScreen) == 0); + if (Gui) { + if (auto graphics = dynamic_cast(Gui->getGraphics())) { + graphics->setTarget(TheScreen); + } + } + // new texture if (TheTexture) { SDL_DestroyTexture(TheTexture);