Skip to content

Commit

Permalink
Merge pull request #575 from Wargus/gcn_graphics_settarget
Browse files Browse the repository at this point in the history
Revert parameter of `gcn::SDLGraphics::setTarget` to `SDL_Surface*`.
  • Loading branch information
Jarod42 authored Nov 18, 2023
2 parents 9e565c0 + 72a967f commit 0dfb05b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 30 deletions.
13 changes: 10 additions & 3 deletions src/guichan/include/guichan/sdl/sdlgraphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
};
Expand Down
53 changes: 29 additions & 24 deletions src/guichan/sdl/sdlgraphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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;
Expand All @@ -110,7 +110,7 @@ namespace gcn
rect.w = carea.width;
rect.h = carea.height;

SDL_SetClipRect(*mTarget, &rect);
SDL_SetClipRect(mTarget, &rect);

return result;
}
Expand All @@ -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,
Expand All @@ -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)
Expand All @@ -184,7 +189,7 @@ namespace gcn
{
for (x = x1; x < x2; x++)
{
SDLputPixelAlpha(*mTarget, x, y, mColor);
SDLputPixelAlpha(mTarget, x, y, mColor);
}
}
}
Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion src/ui/widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<gcn::SDLInput>();

Expand Down
14 changes: 12 additions & 2 deletions src/video/video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@

#include "stratagus.h"

#include <vector>

#include "video.h"
#include "intern_video.h"

Expand All @@ -92,9 +90,15 @@
#include "iolib.h"
#include "map.h"
#include "ui.h"
#include "widgets.h"

#include <SDL.h>
#include <SDL_image.h>
#include <memory>
#include <vector>

extern std::unique_ptr<gcn::Gui> Gui;


/*----------------------------------------------------------------------------
-- Declarations
Expand Down Expand Up @@ -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<gcn::SDLGraphics *>(Gui->getGraphics())) {
graphics->setTarget(TheScreen);
}
}

// new texture
if (TheTexture) {
SDL_DestroyTexture(TheTexture);
Expand Down

0 comments on commit 0dfb05b

Please sign in to comment.