1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Refactoring towards backward compatibility (WiP)

This commit is contained in:
AlexVinS 2014-05-23 14:51:38 +04:00 committed by AlexVinS
parent 1597254399
commit 0ef16feca9
15 changed files with 136 additions and 170 deletions

View File

@ -294,12 +294,7 @@ void CResDataBar::clickRight(tribool down, bool previousState)
CResDataBar::CResDataBar(const std::string &defname, int x, int y, int offx, int offy, int resdist, int datedist)
{
bg = BitmapHandler::loadBitmap(defname);
#if 0
SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
#else
SDL_SetColorKey(bg,SDL_TRUE,SDL_MapRGB(bg->format,0,255,255));
#endif
graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
pos = genRect(bg->h, bg->w, pos.x+x, pos.y+y);
@ -318,11 +313,7 @@ CResDataBar::CResDataBar(const std::string &defname, int x, int y, int offx, int
CResDataBar::CResDataBar()
{
bg = BitmapHandler::loadBitmap(ADVOPT.resdatabarG);
#if 0
SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
#else
SDL_SetColorKey(bg,SDL_TRUE,SDL_MapRGB(bg->format,0,255,255));
#endif
graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
pos = genRect(bg->h,bg->w,ADVOPT.resdatabarX,ADVOPT.resdatabarY);
@ -930,7 +921,7 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
if(CGuiHandler::isArrowKey(SDLKey(k)))
k = CGuiHandler::arrowToNum(SDLKey(k));
#if 0
#ifdef VCMI_SDL1
k -= SDLK_KP0 + 1;
#else
k -= SDL_SCANCODE_KP_0 + 1;

View File

@ -157,11 +157,7 @@ CDefFile::CDefFile(std::string Name):
palette[i].r = data[it++];
palette[i].g = data[it++];
palette[i].b = data[it++];
#if 0
palette[i].unused = 255;
#else
palette[i].a = 255;
#endif // 0
CSDL_Ext::colorSetAlpha(palette[i],255);
}
if (type == 71 || type == 64)//Buttons/buildings don't have shadows\semi-transparency
memset(palette, 0, sizeof(SDL_Color)*2);
@ -390,11 +386,7 @@ inline void SDLImageLoader::EndLine()
SDLImageLoader::~SDLImageLoader()
{
SDL_UnlockSurface(image->surf);
#if 0
SDL_SetColorKey(image->surf, SDL_SRCCOLORKEY, 0);
#else
SDL_SetColorKey(image->surf, SDL_TRUE, 0);
#endif // 0
//TODO: RLE if compressed and bpp>1
}
@ -451,7 +443,7 @@ inline ui8 CompImageLoader::typeOf(ui8 color)
{
if (color == 0)
return 0;
#if 0
#ifdef VCMI_SDL1
if (image->palette[color].unused != 255)
return 1;
#else
@ -635,7 +627,7 @@ SDLImage::SDLImage(std::string filename, bool compressed):
{
SDL_Surface *temp = surf;
// add RLE flag
#if 0
#ifdef VCMI_SDL1
if (surf->format->palette)
{
const SDL_Color &c = temp->format->palette->colors[0];
@ -822,7 +814,7 @@ void CompImage::BlitBlock(ui8 type, ui8 size, ui8 *&data, ui8 *&dest, ui8 alpha)
for (size_t i=0; i<size; i++)
{
SDL_Color col = palette[*(data++)];
#if 0
#ifdef VCMI_SDL1
col.unused = (ui32)col.unused*alpha/255;
#else
col.a = (ui32)col.a*alpha/255;
@ -832,7 +824,7 @@ void CompImage::BlitBlock(ui8 type, ui8 size, ui8 *&data, ui8 *&dest, ui8 alpha)
return;
}
#if 0
#ifdef VCMI_SDL1
if (palette[color].unused == 255)
#else
if (palette[color].a == 255)
@ -853,7 +845,7 @@ void CompImage::BlitBlock(ui8 type, ui8 size, ui8 *&data, ui8 *&dest, ui8 alpha)
//RLE-d sequence
else
{
#if 0
#ifdef VCMI_SDL1
if (alpha != 255 && palette[type].unused !=0)//Per-surface alpha is set
{
SDL_Color col = palette[type];
@ -917,14 +909,7 @@ void CompImage::playerColored(PlayerColor player)
for(int i=0; i<32; ++i)
{
palette[224+i].r = pal[i].r;
palette[224+i].g = pal[i].g;
palette[224+i].b = pal[i].b;
#if 0
palette[224+i].unused = pal[i].unused;
#else
palette[224+i].a = pal[i].a;
#endif // 0
CSDL_Ext::colorAssign(palette[224+i],pal[i]);
}
}

View File

@ -70,11 +70,7 @@ SDL_Surface * BitmapHandler::loadH3PCX(ui8 * pcx, size_t size)
tp.r = pcx[it++];
tp.g = pcx[it++];
tp.b = pcx[it++];
#if 0
tp.unused = SDL_ALPHA_OPAQUE;
#else
tp.a = SDL_ALPHA_OPAQUE;
#endif // 0
CSDL_Ext::colorSetAlpha(tp,SDL_ALPHA_OPAQUE);
ret->format->palette->colors[i] = tp;
}
}
@ -126,11 +122,7 @@ SDL_Surface * BitmapHandler::loadBitmapFromDir(std::string path, std::string fna
if(ret->format->BytesPerPixel == 1 && setKey)
{
const SDL_Color &c = ret->format->palette->colors[0];
#if 0
SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format, c.r, c.g, c.b));
#else
SDL_SetColorKey(ret,SDL_TRUE,SDL_MapRGB(ret->format, c.r, c.g, c.b));
#endif // 0
SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format, c.r, c.g, c.b));
}
}
else
@ -150,12 +142,8 @@ SDL_Surface * BitmapHandler::loadBitmapFromDir(std::string path, std::string fna
if (ret->format->palette)
{
//set correct value for alpha\unused channel
for (int i=0; i< ret->format->palette->ncolors; i++)
#if 0
ret->format->palette->colors[i].unused = 255;
#else
ret->format->palette->colors[i].a = 255;
#endif // 0
for (int i=0; i < ret->format->palette->ncolors; i++)
CSDL_Ext::colorSetAlpha(ret->format->palette->colors[i],SDL_ALPHA_OPAQUE);
}
}
else
@ -178,19 +166,11 @@ SDL_Surface * BitmapHandler::loadBitmapFromDir(std::string path, std::string fna
// set color key only if exactly such color was found
if (color.r == 0 && color.g == 255 && color.b == 255)
#if 0
SDL_SetColorKey(ret, SDL_SRCCOLORKEY, colorID);
#else
SDL_SetColorKey(ret, SDL_TRUE, colorID);
#endif // 0
SDL_SetColorKey(ret, SDL_SRCCOLORKEY, colorID);
}
else // always set
{
#if 0
SDL_SetColorKey(ret, SDL_SRCCOLORKEY, colorID);
#else
SDL_SetColorKey(ret, SDL_TRUE, colorID);
#endif // 0
}
return ret;
}

View File

@ -5,7 +5,7 @@
#include "../lib/filesystem/Filesystem.h"
#include "../lib/VCMI_Lib.h"
#include "CBitmapHandler.h"
#include "gui/SDL_Extensions.h"
/*
* CDefHandler.cpp, part of VCMI engine
*
@ -67,11 +67,7 @@ void CDefHandler::openFromMemory(ui8 *table, const std::string & name)
palette[it].r = de.palette[it].R;
palette[it].g = de.palette[it].G;
palette[it].b = de.palette[it].B;
#if 0
palette[it].unused = 255;
#else
palette[it].a = 255;
#endif // 0
CSDL_Ext::colorSetAlpha(palette[it],SDL_ALPHA_OPAQUE);
}
// The SDefEntryBlock starts just after the SDefEntry
@ -185,7 +181,7 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, const ui8 * FDef, const SDL_Co
BaseOffset += sizeof(SSpriteDef);
int BaseOffsetor = BaseOffset;
#if 0
#ifdef VCMI_SDL1
for(int i=0; i<256; ++i)
{
SDL_Color pr;
@ -367,7 +363,7 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, const ui8 * FDef, const SDL_Co
}
SDL_Color ttcol = ret->format->palette->colors[0];
#if 0
#ifdef VCMI_SDL1
Uint32 keycol = SDL_MapRGBA(ret->format, ttcol.r, ttcol.b, ttcol.g, ttcol.unused);
SDL_SetColorKey(ret, SDL_SRCCOLORKEY, keycol);
#else

View File

@ -344,7 +344,7 @@ int main(int argc, char** argv)
if(!gNoGUI)
{
#if 0
#ifdef VCMI_SDL1
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO))
#else
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO|SDL_INIT_NOPARACHUTE))
@ -844,11 +844,20 @@ static bool recreateWindow(int w, int h, int bpp, bool fullscreen)
//logGlobal->infoStream() << "New screen flags: " << screen->flags;
SDL_FreeSurface(screen);
#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
int bmask = 0xff000000;
int gmask = 0x00ff0000;
int rmask = 0x0000ff00;
int amask = 0x000000ff;
#else
int bmask = 0x000000ff;
int gmask = 0x0000ff00;
int rmask = 0x00ff0000;
int amask = 0xFF000000;
#endif
screen = SDL_CreateRGBSurface(0,w,h,bpp,0x00FF0000,
0x0000FF00,
0x000000FF,
0xFF000000);
screen = SDL_CreateRGBSurface(0,w,h,bpp,rmask,gmask,bmask,amask);
if(nullptr == screen)
{
logGlobal->errorStream() << "Unable to create surface";
@ -898,7 +907,7 @@ static void setScreenRes(int w, int h, int bpp, bool fullscreen, bool resetVideo
return;
}
#if 0
#ifdef VCMI_SDL1
SDL_EnableUNICODE(1);
#else

View File

@ -3990,7 +3990,7 @@ void CInGameConsole::keyPressed (const SDL_KeyboardEvent & key)
}
default:
{
#if 0
#ifdef VCMI_SDL1
if(enteredText.size() > 0 && enteredText.size() < conf.go()->ac.inputLineLength)
{
if( key.keysym.unicode < 0x80 && key.keysym.unicode > 0 )

View File

@ -62,11 +62,7 @@ void Graphics::loadPaletteAndColors()
col.r = pals[startPoint++];
col.g = pals[startPoint++];
col.b = pals[startPoint++];
#if 0
col.unused = 255;
#else
col.a = 255;
#endif // 0
CSDL_Ext::colorSetAlpha(col,SDL_ALPHA_OPAQUE);
startPoint++;
playerColorPalette[i] = col;
}
@ -81,7 +77,7 @@ void Graphics::loadPaletteAndColors()
neutralColorPalette[i].r = reader.readUInt8();
neutralColorPalette[i].g = reader.readUInt8();
neutralColorPalette[i].b = reader.readUInt8();
#if 0
#ifdef VCMI_SDL1
neutralColorPalette[i].unused = reader.readUInt8();
neutralColorPalette[i].unused = !neutralColorPalette[i].unused;
#else
@ -92,25 +88,16 @@ void Graphics::loadPaletteAndColors()
//colors initialization
int3 kolory[] = {int3(0xff,0,0),int3(0x31,0x52,0xff),int3(0x9c,0x73,0x52),int3(0x42,0x94,0x29),
int3(0xff,0x84,0x0),int3(0x8c,0x29,0xa5),int3(0x09,0x9c,0xa5),int3(0xc6,0x7b,0x8c)};
#if 0
for(int i=0;i<8;i++)
{
playerColors[i].r = kolory[i].x;
playerColors[i].g = kolory[i].y;
playerColors[i].b = kolory[i].z;
playerColors[i].unused = 255;
CSDL_Ext::colorSetAlpha(playerColors[i],SDL_ALPHA_OPAQUE);
}
neutralColor->r = 0x84; neutralColor->g = 0x84; neutralColor->b = 0x84; neutralColor->unused = 255;//gray
#else
for(int i=0;i<8;i++)
{
playerColors[i].r = kolory[i].x;
playerColors[i].g = kolory[i].y;
playerColors[i].b = kolory[i].z;
playerColors[i].a = 255;
}
neutralColor->r = 0x84; neutralColor->g = 0x84; neutralColor->b = 0x84; neutralColor->a = 255;//gray
#endif // 0
neutralColor->r = 0x84; neutralColor->g = 0x84; neutralColor->b = 0x84; //gray
CSDL_Ext::colorSetAlpha(*neutralColor,SDL_ALPHA_OPAQUE);
}
void Graphics::initializeBattleGraphics()

View File

@ -2,6 +2,30 @@
#include "../Global.h"
#include <SDL_version.h>
#if (SDL_MAJOR_VERSION == 2)
#define VCMI_SDL2
#include <SDL_keycode.h>
typedef int SDLX_Coord;
typedef int SDLX_Size;
typedef SDL_Keycode SDLKey;
#define SDL_SRCCOLORKEY SDL_TRUE
#define SDL_FULLSCREEN SDL_WINDOW_FULLSCREEN
#elif (SDL_MAJOR_VERSION == 1)
#define VCMI_SDL1
//SDL 1.x
typedef Sint16 SDLX_Coord;
typedef Uint16 SDLX_Size;
#else
#error "unkown or unsupported SDL version"
#endif
// This header should be treated as a pre compiled header file(PCH) in the compiler building settings.
// Here you can add specific libraries and macros which are specific to this project.
// Here you can add specific libraries and macros which are specific to this project.

View File

@ -365,11 +365,7 @@ CBattleInterface::CBattleInterface(const CCreatureSet * army1, const CCreatureSe
idToObstacle[ID] = CDefHandler::giveDef(elem->getInfo().defName);
for(auto & _n : idToObstacle[ID]->ourImages)
{
#if 0
SDL_SetColorKey(_n.bitmap, SDL_SRCCOLORKEY, SDL_MapRGB(_n.bitmap->format,0,255,255));
#else
SDL_SetColorKey(_n.bitmap, SDL_TRUE, SDL_MapRGB(_n.bitmap->format,0,255,255));
#endif // 0
SDL_SetColorKey(_n.bitmap, SDL_SRCCOLORKEY, SDL_MapRGB(_n.bitmap->format,0,255,255));
}
}
else if(elem->obstacleType == CObstacleInstance::ABSOLUTE_OBSTACLE)

View File

@ -178,11 +178,7 @@ CCreatureAnimation::CCreatureAnimation(std::string name, TSpeedController contro
elem.r = reader.readUInt8();
elem.g = reader.readUInt8();
elem.b = reader.readUInt8();
#if 0
elem.unused = 0;
#else
elem.a = 0;
#endif
CSDL_Ext::colorSetAlpha(elem,0);
}
for (int i=0; i<totalBlocks; i++)
@ -271,7 +267,7 @@ static SDL_Color genShadow(ui8 alpha)
static SDL_Color genBorderColor(ui8 alpha, const SDL_Color & base)
{
#if 0
#ifdef VCMI_SDL1
return CSDL_Ext::makeColor(base.r, base.g, base.b, ui8(base.unused * alpha / 256));
#else
return CSDL_Ext::makeColor(base.r, base.g, base.b, ui8(base.a * alpha / 256));
@ -285,7 +281,7 @@ static ui8 mixChannels(ui8 c1, ui8 c2, ui8 a1, ui8 a2)
static SDL_Color addColors(const SDL_Color & base, const SDL_Color & over)
{
#if 0
#ifdef VCMI_SDL1
return CSDL_Ext::makeColor(
mixChannels(over.r, base.r, over.unused, base.unused),
mixChannels(over.g, base.g, over.unused, base.unused),
@ -300,7 +296,7 @@ static SDL_Color addColors(const SDL_Color & base, const SDL_Color & over)
ui8(over.a + base.a * (255 - over.a) / 256)
);
#endif // 0
#endif // VCMI_SDL1
}
std::array<SDL_Color, 8> CCreatureAnimation::genSpecialPalette()
@ -431,7 +427,7 @@ inline void CCreatureAnimation::putPixel(ui8 * dest, const SDL_Color & color, si
if (index < 8)
{
const SDL_Color & pal = special[index];
#if 0
#ifdef VCMI_SDL1
ColorPutter<bpp, 0>::PutColor(dest, pal.r, pal.g, pal.b, pal.unused);
#else
ColorPutter<bpp, 0>::PutColor(dest, pal.r, pal.g, pal.b, pal.a);

View File

@ -264,7 +264,7 @@ void CGuiHandler::handleEvent(SDL_Event *sEvent)
}
}
}
#if 0
#ifdef VCMI_SDL1
else if(sEvent->button.button == SDL_BUTTON_WHEELDOWN || sEvent->button.button == SDL_BUTTON_WHEELUP)
{
std::list<CIntObject*> hlp = wheelInterested;
@ -276,8 +276,7 @@ void CGuiHandler::handleEvent(SDL_Event *sEvent)
}
#endif
}
#if 0
#else
#ifndef VCMI_SDL1
else if ((sEvent->type == SDL_MOUSEWHEEL))
{
std::list<CIntObject*> hlp = wheelInterested;
@ -287,7 +286,7 @@ void CGuiHandler::handleEvent(SDL_Event *sEvent)
(*i)->wheelScrolled(sEvent->wheel.y < 0, isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y));
}
}
#endif // 0
#endif // VCMI_SDL1
else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_LEFT))
{
std::list<CIntObject*> hlp = lclickable;
@ -452,7 +451,7 @@ void CGuiHandler::drawFPSCounter()
SDLKey CGuiHandler::arrowToNum( SDLKey key )
{
#if 0
#ifdef VCMI_SDL1
switch(key)
{
case SDLK_DOWN:
@ -486,7 +485,7 @@ SDLKey CGuiHandler::arrowToNum( SDLKey key )
SDLKey CGuiHandler::numToDigit( SDLKey key )
{
#if 0
#ifdef VCMI_SDL1
if(key >= SDLK_KP0 && key <= SDLK_KP9)
return SDLKey(key - SDLK_KP0 + SDLK_0);
#else
@ -516,7 +515,7 @@ SDLKey CGuiHandler::numToDigit( SDLKey key )
bool CGuiHandler::isNumKey( SDLKey key, bool number )
{
#if 0
#ifdef VCMI_SDL1
if(number)
return key >= SDLK_KP0 && key <= SDLK_KP9;
else

View File

@ -134,7 +134,7 @@ void CPicture::convertToScreenBPP()
void CPicture::setAlpha(int value)
{
#if 0
#ifdef VCMI_SDL1
SDL_SetAlpha(bg, SDL_SRCALPHA, value);
#else
SDL_SetSurfaceAlphaMod(bg,value);
@ -289,11 +289,7 @@ void CButtonBase::block(bool on)
CAdventureMapButton::CAdventureMapButton ()
{
hoverable = actOnDown = borderEnabled = soundDisabled = false;
#if 0
borderColor.unused = 1; // represents a transparent color, used for HighlightableButton
#else
borderColor.a = 1; // represents a transparent color, used for HighlightableButton
#endif // 0
CSDL_Ext::colorSetAlpha(borderColor,1);// represents a transparent color, used for HighlightableButton
addUsedEvents(LCLICK | RCLICK | HOVER | KEYBOARD);
}
@ -412,11 +408,7 @@ void CAdventureMapButton::init(const CFunctionList<void()> &Callback, const std:
addUsedEvents(LCLICK | RCLICK | HOVER | KEYBOARD);
callback = Callback;
hoverable = actOnDown = borderEnabled = soundDisabled = false;
#if 0
borderColor.unused = 1; // represents a transparent color, used for HighlightableButton
#else
borderColor.a = 1; // represents a transparent color, used for HighlightableButton
#endif // 0
CSDL_Ext::colorSetAlpha(borderColor,1);// represents a transparent color, used for HighlightableButton
hoverTexts = Name;
helpBox=HelpBox;
@ -465,7 +457,7 @@ void CAdventureMapButton::showAll(SDL_Surface * to)
{
CIntObject::showAll(to);
#if 0
#ifdef VCMI_SDL1
if (borderEnabled && borderColor.unused == 0)
CSDL_Ext::drawBorder(to, pos.x-1, pos.y-1, pos.w+2, pos.h+2, int3(borderColor.r, borderColor.g, borderColor.b));
#else
@ -1621,7 +1613,7 @@ void CTextInput::keyPressed( const SDL_KeyboardEvent & key )
text.resize(text.size()-1);
break;
default:
#if 0
#ifdef VCMI_SDL1
if (key.keysym.unicode < ' ')
return;
else
@ -1629,7 +1621,7 @@ void CTextInput::keyPressed( const SDL_KeyboardEvent & key )
#endif // 0
break;
}
#if 0
#ifdef VCMI_SDL1
filters(text, oldText);
if (text != oldText)
{
@ -1653,7 +1645,7 @@ bool CTextInput::captureThisEvent(const SDL_KeyboardEvent & key)
if(key.keysym.sym == SDLK_RETURN || key.keysym.sym == SDLK_KP_ENTER)
return false;
#if 0
#ifdef VCMI_SDL1
//this should allow all non-printable keys to go through (for example arrows)
if (key.keysym.unicode < ' ')
return false;

View File

@ -445,7 +445,7 @@ int CSDL_Ext::blit8bppAlphaTo24bppT(const SDL_Surface * src, const SDL_Rect * sr
for(int x = w; x; x--)
{
const SDL_Color &tbc = colors[*color++]; //color to blit
#if 0
#ifdef VCMI_SDL1
ColorPutter<bpp, +1>::PutColorAlphaSwitch(p, tbc.r, tbc.g, tbc.b, tbc.unused);
#else
ColorPutter<bpp, +1>::PutColorAlphaSwitch(p, tbc.r, tbc.g, tbc.b, tbc.a);
@ -474,7 +474,7 @@ int CSDL_Ext::blit8bppAlphaTo24bpp(const SDL_Surface * src, const SDL_Rect * src
Uint32 CSDL_Ext::colorToUint32(const SDL_Color * color)
{
Uint32 ret = 0;
#if 0
#ifdef VCMI_SDL1
ret+=color->unused;
#else
ret+=color->a;
@ -490,7 +490,7 @@ Uint32 CSDL_Ext::colorToUint32(const SDL_Color * color)
void CSDL_Ext::update(SDL_Surface * what)
{
#if 0
#ifdef VCMI_SDL1
if(what)
SDL_UpdateRect(what, 0, 0, what->w, what->h);
#else
@ -615,7 +615,7 @@ bool CSDL_Ext::isTransparent( SDL_Surface * srf, int x, int y )
SDL_Color color;
#if 0
#ifdef VCMI_SDL1
SDL_GetRGBA(SDL_GetPixel(srf, x, y), srf->format, &color.r, &color.g, &color.b, &color.unused);
#else
SDL_GetRGBA(SDL_GetPixel(srf, x, y), srf->format, &color.r, &color.g, &color.b, &color.a);
@ -625,7 +625,7 @@ bool CSDL_Ext::isTransparent( SDL_Surface * srf, int x, int y )
// a) image has aplha: less than 50% transparency
// b) no alpha: color is cyan
if (srf->format->Amask)
#if 0
#ifdef VCMI_SDL1
return color.unused < 128; // almost transparent
#else
return color.a < 128; // almost transparent

View File

@ -1,12 +1,3 @@
#pragma once
#include <SDL_render.h>
#include <SDL_video.h>
#include <SDL_ttf.h>
#include "../../lib/int3.h"
#include "../Graphics.h"
#include "Geometries.h"
/*
* SDL_Extensions.h, part of VCMI engine
*
@ -16,6 +7,20 @@
* Full text of license available in license.txt file, in main folder
*
*/
#pragma once
#include <SDL_version.h>
#ifndef VCMI_SDL1
#include <SDL_render.h>
#endif
#include <SDL_video.h>
#include <SDL_ttf.h>
#include "../../lib/int3.h"
#include "../Graphics.h"
#include "Geometries.h"
//A macro to force inlining some of our functions. Compiler (at least MSVC) is not so smart here-> without that displaying is MUCH slower
#ifdef _MSC_VER
@ -30,28 +35,13 @@
#define SDL_GetKeyState SDL_GetKeyboardState
#endif
//compatibility stuff
#if 0
typedef Sint16 SDLX_Coord;
typedef Uint16 SDLX_Size;
#else
//SDL2 support
#if (SDL_MAJOR_VERSION == 2)
extern SDL_Window * mainWindow;
extern SDL_Renderer * mainRenderer;
extern SDL_Texture * screenTexture;
typedef int SDLX_Coord;
typedef int SDLX_Size;
typedef SDL_Keycode SDLKey;
#define SDL_SRCCOLORKEY SDL_TRUE
#define SDL_FULLSCREEN SDL_WINDOW_FULLSCREEN
inline void SDL_SetColors(SDL_Surface *surface, SDL_Color *colors, int firstcolor, int ncolors)
{
SDL_SetPaletteColors(surface->format->palette,colors,firstcolor,ncolors);
@ -73,36 +63,57 @@ inline void SDL_UpdateRect(SDL_Surface *surface, int x, int y, int w, int h)
SDL_RenderPresent(mainRenderer);
}
#endif // 0
#endif
inline bool isCtrlKeyDown()
{
#if 0
#ifdef VCMI_SDL1
return SDL_GetKeyState(nullptr)[SDLK_LCTRL] || SDL_GetKeyState(nullptr)[SDLK_RCTRL];
#else
return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LCTRL] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RCTRL];
#endif // 0
#endif
}
inline bool isAltKeyDown()
{
#if 0
#ifdef VCMI_SDL1
return SDL_GetKeyState(nullptr)[SDLK_LALT] || SDL_GetKeyState(nullptr)[SDLK_RALT];
#else
return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LALT] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RALT];
#endif // 0
#endif
}
inline bool isShiftKeyDown()
{
#if 0
#ifdef VCMI_SDL1
return SDL_GetKeyState(nullptr)[SDLK_LSHIFT] || SDL_GetKeyState(nullptr)[SDLK_RSHIFT];
#else
return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LSHIFT] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RSHIFT];
#endif // 0
#endif
}
namespace CSDL_Ext
{
STRONG_INLINE void colorSetAlpha(SDL_Color & color, Uint8 alpha)
{
#ifdef VCMI_SDL1
color.unused = alpha;
#else
color.a = alpha;
#endif
}
//todo: should this better be assignment operator?
STRONG_INLINE void colorAssign(SDL_Color & dest, const SDL_Color & source)
{
dest.r = source.r;
dest.g = source.g;
dest.b = source.b;
#ifdef VCMI_SDL1
dest.unused = source.unused;
#else
dest.a = source.a;
#endif
}
}
struct Rect;
extern SDL_Surface * screen, *screen2, *screenBuf;

View File

@ -133,7 +133,7 @@ struct ColorPutter<2, incrementPtr>
template<int bpp, int incrementPtr>
STRONG_INLINE void ColorPutter<bpp, incrementPtr>::PutColorAlpha(Uint8 *&ptr, const SDL_Color & Color)
{
#if 0
#ifdef VCMI_SDL1
PutColor(ptr, Color.r, Color.g, Color.b, Color.unused);
#else
PutColor(ptr, Color.r, Color.g, Color.b, Color.a);
@ -266,7 +266,7 @@ STRONG_INLINE void ColorPutter<2, incrementPtr>::PutColor(Uint8 *&ptr, const Uin
template <int incrementPtr>
STRONG_INLINE void ColorPutter<2, incrementPtr>::PutColorAlpha(Uint8 *&ptr, const SDL_Color & Color)
{
#if 0
#ifdef VCMI_SDL1
PutColor(ptr, Color.r, Color.g, Color.b, Color.unused);
#else
PutColor(ptr, Color.r, Color.g, Color.b, Color.a);