SDL: Move the compatibility functions into SurfaceSdlGraphicsManager
This commit is contained in:
parent
981b771e38
commit
5fd8aed047
4 changed files with 41 additions and 52 deletions
|
@ -49,6 +49,13 @@
|
|||
#include "common/text-to-speech.h"
|
||||
#endif
|
||||
|
||||
// SDL surface flags which got removed in SDL2.
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
#define SDL_SRCCOLORKEY 0
|
||||
#define SDL_SRCALPHA 0
|
||||
#define SDL_FULLSCREEN 0x40000000
|
||||
#endif
|
||||
|
||||
static const OSystem::GraphicsMode s_supportedShaders[] = {
|
||||
{"NONE", "Normal (no shader)", 0},
|
||||
{0, 0, 0}
|
||||
|
@ -2766,6 +2773,37 @@ void SurfaceSdlGraphicsManager::SDL_UpdateRects(SDL_Surface *screen, int numrect
|
|||
SDL_RenderCopy(_renderer, _screenTexture, NULL, &viewport);
|
||||
SDL_RenderPresent(_renderer);
|
||||
}
|
||||
|
||||
int SurfaceSdlGraphicsManager::SDL_SetColors(SDL_Surface *surface, SDL_Color *colors, int firstcolor, int ncolors) {
|
||||
if (surface->format->palette) {
|
||||
return !SDL_SetPaletteColors(surface->format->palette, colors, firstcolor, ncolors) ? 1 : 0;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int SurfaceSdlGraphicsManager::SDL_SetAlpha(SDL_Surface *surface, Uint32 flag, Uint8 alpha) {
|
||||
if (SDL_SetSurfaceAlphaMod(surface, alpha)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (alpha == 255 || !flag) {
|
||||
if (SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_NONE)) {
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if (SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SurfaceSdlGraphicsManager::SDL_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key) {
|
||||
return ::SDL_SetColorKey(surface, SDL_TRUE, key) ? -1 : 0;
|
||||
}
|
||||
|
||||
#endif // SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
|
||||
#endif
|
||||
|
|
|
@ -200,6 +200,9 @@ protected:
|
|||
|
||||
virtual SDL_Surface *SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags);
|
||||
virtual void SDL_UpdateRects(SDL_Surface *screen, int numrects, SDL_Rect *rects);
|
||||
int SDL_SetColors(SDL_Surface *surface, SDL_Color *colors, int firstcolor, int ncolors);
|
||||
int SDL_SetAlpha(SDL_Surface *surface, Uint32 flag, Uint8 alpha);
|
||||
int SDL_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key);
|
||||
#endif
|
||||
|
||||
/** Unseen game screen */
|
||||
|
|
|
@ -274,23 +274,4 @@
|
|||
|
||||
#endif // FORBIDDEN_SYMBOL_EXCEPTION_time_h
|
||||
|
||||
// SDL 2 has major API changes. We redefine constants which got renamed to
|
||||
// ease the transition. This is sometimes dangerous because the values changed
|
||||
// too!
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
// SDL surface flags which got removed.
|
||||
#define SDL_SRCCOLORKEY 0
|
||||
#define SDL_SRCALPHA 0
|
||||
#define SDL_FULLSCREEN 0x40000000
|
||||
|
||||
// Compatibility implementations for removed functionality.
|
||||
int SDL_SetColors(SDL_Surface *surface, SDL_Color *colors, int firstcolor, int ncolors);
|
||||
int SDL_SetAlpha(SDL_Surface *surface, Uint32 flag, Uint8 alpha);
|
||||
|
||||
#define SDL_SetColorKey SDL_SetColorKey_replacement
|
||||
int SDL_SetColorKey_replacement(SDL_Surface *surface, Uint32 flag, Uint32 key);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -750,39 +750,6 @@ void OSystem_SDL::setupGraphicsModes() {
|
|||
}
|
||||
#endif
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
int SDL_SetColors(SDL_Surface *surface, SDL_Color *colors, int firstcolor, int ncolors) {
|
||||
if (surface->format->palette) {
|
||||
return !SDL_SetPaletteColors(surface->format->palette, colors, firstcolor, ncolors) ? 1 : 0;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int SDL_SetAlpha(SDL_Surface *surface, Uint32 flag, Uint8 alpha) {
|
||||
if (SDL_SetSurfaceAlphaMod(surface, alpha)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (alpha == 255 || !flag) {
|
||||
if (SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_NONE)) {
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if (SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#undef SDL_SetColorKey
|
||||
int SDL_SetColorKey_replacement(SDL_Surface *surface, Uint32 flag, Uint32 key) {
|
||||
return SDL_SetColorKey(surface, SDL_TRUE, key) ? -1 : 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
char *OSystem_SDL::convertEncoding(const char *to, const char *from, const char *string, size_t length) {
|
||||
#if SDL_VERSION_ATLEAST(1, 2, 10)
|
||||
int zeroBytes = 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue