Browse Source

Introduce SDL::CreateRGBSurfaceWithFormat

pull/2638/head
Vladimir Olteanu 5 years ago committed by Anders Jenbo
parent
commit
2d4a205fef
  1. 3
      Source/DiabloUI/art.cpp
  2. 3
      Source/DiabloUI/credits.cpp
  3. 10
      Source/DiabloUI/diabloui.cpp
  4. 4
      Source/hwcursor.cpp
  5. 9
      Source/utils/sdl_wrap.h

3
Source/DiabloUI/art.cpp

@ -8,6 +8,7 @@
#include "utils/display.h"
#include "utils/log.hpp"
#include "utils/sdl_compat.h"
#include "utils/sdl_wrap.h"
namespace devilution {
namespace {
@ -121,7 +122,7 @@ void LoadArt(const char *pszFile, Art *art, int frames, SDL_Color *pPalette)
return;
}
SDLSurfaceUniquePtr artSurface { SDL_CreateRGBSurfaceWithFormat(SDL_SWSURFACE, width, height, bpp, GetPcxSdlPixelFormat(bpp)) };
SDLSurfaceUniquePtr artSurface = SDLWrap::CreateRGBSurfaceWithFormat(SDL_SWSURFACE, width, height, bpp, GetPcxSdlPixelFormat(bpp));
if (!LoadPcxPixelsAndPalette(handle, width, height, bpp, static_cast<BYTE *>(artSurface->pixels),
artSurface->pitch, pPalette)) {
Log("LoadArt(\"{}\"): LoadPcxPixelsAndPalette failed with code {}", pszFile, SErrGetLastError());

3
Source/DiabloUI/credits.cpp

@ -16,6 +16,7 @@
#include "utils/log.hpp"
#include "utils/sdl_compat.h"
#include "utils/sdl_ptrs.h"
#include "utils/sdl_wrap.h"
namespace devilution {
@ -77,7 +78,7 @@ CachedLine PrepareLine(std::size_t index)
SDLSurfaceUniquePtr surface;
if (text != nullptr) {
// Set up the target surface to have 3 colors: mask, text, and shadow.
surface = SDLSurfaceUniquePtr { SDL_CreateRGBSurfaceWithFormat(0, text->w + ShadowOffsetX, text->h + ShadowOffsetY, 8, SDL_PIXELFORMAT_INDEX8) };
surface = SDLWrap::CreateRGBSurfaceWithFormat(0, text->w + ShadowOffsetX, text->h + ShadowOffsetY, 8, SDL_PIXELFORMAT_INDEX8);
const SDL_Color maskColor = { 0, 255, 0, 0 }; // Any color different from both shadow and text
const SDL_Color &textColor = Palette->colors[224];
SDL_Color colors[3] = { maskColor, textColor, shadowColor };

10
Source/DiabloUI/diabloui.cpp

@ -18,7 +18,7 @@
#include "utils/display.h"
#include "utils/log.hpp"
#include "utils/sdl_compat.h"
#include "utils/sdl_ptrs.h"
#include "utils/sdl_wrap.h"
#include "utils/stubs.h"
#include "utils/utf8.h"
@ -484,7 +484,7 @@ void LoadHeros()
portraitOrder[static_cast<std::size_t>(HeroClass::Barbarian)] = 6;
}
SDL_Surface *heros = SDL_CreateRGBSurfaceWithFormat(0, ArtHero.w(), portraitHeight * (static_cast<int>(enum_size<HeroClass>::value) + 1), 8, SDL_PIXELFORMAT_INDEX8);
SDLSurfaceUniquePtr heros = SDLWrap::CreateRGBSurfaceWithFormat(0, ArtHero.w(), portraitHeight * (static_cast<int>(enum_size<HeroClass>::value) + 1), 8, SDL_PIXELFORMAT_INDEX8);
for (int i = 0; i <= static_cast<int>(enum_size<HeroClass>::value); i++) {
int offset = portraitOrder[i] * portraitHeight;
@ -493,7 +493,7 @@ void LoadHeros()
}
SDL_Rect srcRect = MakeRect(0, offset, ArtHero.w(), portraitHeight);
SDL_Rect dstRect = MakeRect(0, i * portraitHeight, ArtHero.w(), portraitHeight);
SDL_BlitSurface(ArtHero.surface.get(), &srcRect, heros, &dstRect);
SDL_BlitSurface(ArtHero.surface.get(), &srcRect, heros.get(), &dstRect);
}
for (int i = 0; i <= static_cast<int>(enum_size<HeroClass>::value); i++) {
@ -505,10 +505,10 @@ void LoadHeros()
continue;
SDL_Rect dstRect = MakeRect(0, i * portraitHeight, portrait.w(), portraitHeight);
SDL_BlitSurface(portrait.surface.get(), nullptr, heros, &dstRect);
SDL_BlitSurface(portrait.surface.get(), nullptr, heros.get(), &dstRect);
}
ArtHero.surface = SDLSurfaceUniquePtr { heros };
ArtHero.surface = std::move(heros);
ArtHero.frame_height = portraitHeight;
ArtHero.frames = static_cast<int>(enum_size<HeroClass>::value);
}

4
Source/hwcursor.cpp

@ -15,7 +15,7 @@
#include "cursor.h"
#include "engine.h"
#include "utils/display.h"
#include "utils/sdl_ptrs.h"
#include "utils/sdl_wrap.h"
namespace devilution {
namespace {
@ -74,7 +74,7 @@ bool SetHardwareCursor(SDL_Surface *surface, HotpointPosition hotpointPosition)
// SDL does not support BlitScaled from 8-bit to RGBA.
SDLSurfaceUniquePtr converted { SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_ARGB8888, 0) };
SDLSurfaceUniquePtr scaledSurface { SDL_CreateRGBSurfaceWithFormat(0, scaledSize.width, scaledSize.height, 32, SDL_PIXELFORMAT_ARGB8888) };
SDLSurfaceUniquePtr scaledSurface = SDLWrap::CreateRGBSurfaceWithFormat(0, scaledSize.width, scaledSize.height, 32, SDL_PIXELFORMAT_ARGB8888);
SDL_BlitScaled(converted.get(), nullptr, scaledSurface.get(), nullptr);
const Point hotpoint = GetHotpointPosition(*scaledSurface, hotpointPosition);
newCursor = SDLCursorUniquePtr { SDL_CreateColorCursor(scaledSurface.get(), hotpoint.x, hotpoint.y) };

9
Source/utils/sdl_wrap.h

@ -23,6 +23,15 @@ inline SDLSurfaceUniquePtr CreateRGBSurface(Uint32 flags, int width, int height,
return ret;
}
inline SDLSurfaceUniquePtr CreateRGBSurfaceWithFormat(Uint32 flags, int width, int height, int depth, Uint32 format)
{
SDLSurfaceUniquePtr ret { SDL_CreateRGBSurfaceWithFormat(flags, width, height, depth, format) };
if (ret == nullptr)
ErrSdl();
return ret;
}
} //namespace SDLWrap
} //namespace devilution

Loading…
Cancel
Save