Browse Source

Refactoring towards backward compatibility (WiP)

AlexVinS 11 years ago
parent
commit
0ef16feca9

+ 1 - 10
client/CAdvmapInterface.cpp

@@ -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)
 CResDataBar::CResDataBar(const std::string &defname, int x, int y, int offx, int offy, int resdist, int datedist)
 {
 {
 	bg = BitmapHandler::loadBitmap(defname);
 	bg = BitmapHandler::loadBitmap(defname);
-	#if 0
 	SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
 	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);
 	graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
 	pos = genRect(bg->h, bg->w, pos.x+x, pos.y+y);
 	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()
 CResDataBar::CResDataBar()
 {
 {
 	bg = BitmapHandler::loadBitmap(ADVOPT.resdatabarG);
 	bg = BitmapHandler::loadBitmap(ADVOPT.resdatabarG);
-	#if 0
 	SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
 	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);
 	graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
 	pos = genRect(bg->h,bg->w,ADVOPT.resdatabarX,ADVOPT.resdatabarY);
 	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)))
 			if(CGuiHandler::isArrowKey(SDLKey(k)))
 				k = CGuiHandler::arrowToNum(SDLKey(k));
 				k = CGuiHandler::arrowToNum(SDLKey(k));
 			
 			
-			#if 0
+			#ifdef VCMI_SDL1
 			k -= SDLK_KP0 + 1;
 			k -= SDLK_KP0 + 1;
 			#else
 			#else
 			k -= SDL_SCANCODE_KP_0 + 1;
 			k -= SDL_SCANCODE_KP_0 + 1;

+ 7 - 22
client/CAnimation.cpp

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

+ 5 - 25
client/CBitmapHandler.cpp

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

+ 4 - 8
client/CDefHandler.cpp

@@ -5,7 +5,7 @@
 #include "../lib/filesystem/Filesystem.h"
 #include "../lib/filesystem/Filesystem.h"
 #include "../lib/VCMI_Lib.h"
 #include "../lib/VCMI_Lib.h"
 #include "CBitmapHandler.h"
 #include "CBitmapHandler.h"
-
+#include "gui/SDL_Extensions.h"
 /*
 /*
  * CDefHandler.cpp, part of VCMI engine
  * 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].r = de.palette[it].R;
 		palette[it].g = de.palette[it].G;
 		palette[it].g = de.palette[it].G;
 		palette[it].b = de.palette[it].B;
 		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
 	// 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);
 	BaseOffset += sizeof(SSpriteDef);
 	int BaseOffsetor = BaseOffset;
 	int BaseOffsetor = BaseOffset;
 
 
-	#if 0
+	#ifdef VCMI_SDL1
 	for(int i=0; i<256; ++i)
 	for(int i=0; i<256; ++i)
 	{		
 	{		
 		SDL_Color pr;
 		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];
 	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);	
 	Uint32 keycol = SDL_MapRGBA(ret->format, ttcol.r, ttcol.b, ttcol.g, ttcol.unused);	
 	SDL_SetColorKey(ret, SDL_SRCCOLORKEY, keycol);	
 	SDL_SetColorKey(ret, SDL_SRCCOLORKEY, keycol);	
 	#else
 	#else

+ 15 - 6
client/CMT.cpp

@@ -344,7 +344,7 @@ int main(int argc, char** argv)
 
 
 	if(!gNoGUI)
 	if(!gNoGUI)
 	{
 	{
-		#if 0
+		#ifdef VCMI_SDL1
 		if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO))
 		if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO))
 		#else
 		#else
 		if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO|SDL_INIT_NOPARACHUTE))
 		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;
 	//logGlobal->infoStream() << "New screen flags: " << screen->flags;
 	SDL_FreeSurface(screen);
 	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)
 	if(nullptr == screen)
 	{
 	{
 		logGlobal->errorStream() << "Unable to create surface";
 		logGlobal->errorStream() << "Unable to create surface";
@@ -898,7 +907,7 @@ static void setScreenRes(int w, int h, int bpp, bool fullscreen, bool resetVideo
 		return;
 		return;
 	}
 	}
 
 
-	#if 0
+	#ifdef VCMI_SDL1
 	SDL_EnableUNICODE(1);
 	SDL_EnableUNICODE(1);
 	#else
 	#else
 
 

+ 1 - 1
client/GUIClasses.cpp

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

+ 6 - 19
client/Graphics.cpp

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

+ 25 - 1
client/StdInc.h

@@ -2,6 +2,30 @@
 
 
 #include "../Global.h"
 #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.
 // 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.

+ 1 - 5
client/battle/CBattleInterface.cpp

@@ -365,11 +365,7 @@ CBattleInterface::CBattleInterface(const CCreatureSet * army1, const CCreatureSe
 			idToObstacle[ID] = CDefHandler::giveDef(elem->getInfo().defName);
 			idToObstacle[ID] = CDefHandler::giveDef(elem->getInfo().defName);
 			for(auto & _n : idToObstacle[ID]->ourImages)
 			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)
 		else if(elem->obstacleType == CObstacleInstance::ABSOLUTE_OBSTACLE)

+ 5 - 9
client/battle/CCreatureAnimation.cpp

@@ -178,11 +178,7 @@ CCreatureAnimation::CCreatureAnimation(std::string name, TSpeedController contro
 		elem.r = reader.readUInt8();
 		elem.r = reader.readUInt8();
 		elem.g = reader.readUInt8();
 		elem.g = reader.readUInt8();
 		elem.b = 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++)
 	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)
 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));
 	return CSDL_Ext::makeColor(base.r, base.g, base.b, ui8(base.unused * alpha / 256));
 	#else
 	#else
 	return CSDL_Ext::makeColor(base.r, base.g, base.b, ui8(base.a * alpha / 256));
 	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)
 static SDL_Color addColors(const SDL_Color & base, const SDL_Color & over)
 {
 {
-	#if 0
+	#ifdef VCMI_SDL1
 	return CSDL_Ext::makeColor(
 	return CSDL_Ext::makeColor(
 			mixChannels(over.r, base.r, over.unused, base.unused),
 			mixChannels(over.r, base.r, over.unused, base.unused),
 			mixChannels(over.g, base.g, 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)
 			ui8(over.a + base.a * (255 - over.a) / 256)
 			);
 			);
 
 
-	#endif // 0
+	#endif // VCMI_SDL1
 }
 }
 
 
 std::array<SDL_Color, 8> CCreatureAnimation::genSpecialPalette()
 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)
 	if (index < 8)
 	{
 	{
 		const SDL_Color & pal = special[index];
 		const SDL_Color & pal = special[index];
-		#if 0
+		#ifdef VCMI_SDL1
 		ColorPutter<bpp, 0>::PutColor(dest, pal.r, pal.g, pal.b, pal.unused);
 		ColorPutter<bpp, 0>::PutColor(dest, pal.r, pal.g, pal.b, pal.unused);
 		#else
 		#else
 		ColorPutter<bpp, 0>::PutColor(dest, pal.r, pal.g, pal.b, pal.a);
 		ColorPutter<bpp, 0>::PutColor(dest, pal.r, pal.g, pal.b, pal.a);

+ 6 - 7
client/gui/CGuiHandler.cpp

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

+ 7 - 15
client/gui/CIntObjectClasses.cpp

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

+ 5 - 5
client/gui/SDL_Extensions.cpp

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

+ 46 - 35
client/gui/SDL_Extensions.h

@@ -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
  * SDL_Extensions.h, part of VCMI engine
  *
  *
@@ -16,6 +7,20 @@
  * Full text of license available in license.txt file, in main folder
  * 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
 //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
 #ifdef _MSC_VER
@@ -30,28 +35,13 @@
 #define SDL_GetKeyState SDL_GetKeyboardState
 #define SDL_GetKeyState SDL_GetKeyboardState
 #endif
 #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_Window * mainWindow;
 extern SDL_Renderer * mainRenderer;
 extern SDL_Renderer * mainRenderer;
 extern SDL_Texture * screenTexture;
 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)
 inline void SDL_SetColors(SDL_Surface *surface, SDL_Color *colors, int firstcolor, int ncolors)
 {
 {
 	SDL_SetPaletteColors(surface->format->palette,colors,firstcolor,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);	
 	SDL_RenderPresent(mainRenderer);	
 	
 	
 }
 }
-#endif // 0
+#endif
 
 
 inline bool isCtrlKeyDown()
 inline bool isCtrlKeyDown()
 {
 {
-	#if 0
+	#ifdef VCMI_SDL1
 	return SDL_GetKeyState(nullptr)[SDLK_LCTRL] || SDL_GetKeyState(nullptr)[SDLK_RCTRL];
 	return SDL_GetKeyState(nullptr)[SDLK_LCTRL] || SDL_GetKeyState(nullptr)[SDLK_RCTRL];
 	#else
 	#else
 	return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LCTRL] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RCTRL];
 	return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LCTRL] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RCTRL];
-	#endif // 0	
+	#endif
 }
 }
 
 
 inline bool isAltKeyDown()
 inline bool isAltKeyDown()
 {
 {
-	#if 0
+	#ifdef VCMI_SDL1
 	return SDL_GetKeyState(nullptr)[SDLK_LALT] || SDL_GetKeyState(nullptr)[SDLK_RALT];
 	return SDL_GetKeyState(nullptr)[SDLK_LALT] || SDL_GetKeyState(nullptr)[SDLK_RALT];
 	#else
 	#else
 	return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LALT] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RALT];
 	return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LALT] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RALT];
-	#endif // 0	
+	#endif
 }
 }
 
 
 inline bool isShiftKeyDown()
 inline bool isShiftKeyDown()
 {
 {
-	#if 0
+	#ifdef VCMI_SDL1
 	return SDL_GetKeyState(nullptr)[SDLK_LSHIFT] || SDL_GetKeyState(nullptr)[SDLK_RSHIFT];
 	return SDL_GetKeyState(nullptr)[SDLK_LSHIFT] || SDL_GetKeyState(nullptr)[SDLK_RSHIFT];
 	#else
 	#else
 	return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LSHIFT] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RSHIFT];
 	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;
 struct Rect;
 
 
 extern SDL_Surface * screen, *screen2, *screenBuf;
 extern SDL_Surface * screen, *screen2, *screenBuf;

+ 2 - 2
client/gui/SDL_Pixels.h

@@ -133,7 +133,7 @@ struct ColorPutter<2, incrementPtr>
 template<int bpp, int incrementPtr>
 template<int bpp, int incrementPtr>
 STRONG_INLINE void ColorPutter<bpp, incrementPtr>::PutColorAlpha(Uint8 *&ptr, const SDL_Color & Color)
 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);
 	PutColor(ptr, Color.r, Color.g, Color.b, Color.unused);
 	#else
 	#else
 	PutColor(ptr, Color.r, Color.g, Color.b, Color.a);
 	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>
 template <int incrementPtr>
 STRONG_INLINE void ColorPutter<2, incrementPtr>::PutColorAlpha(Uint8 *&ptr, const SDL_Color & Color)
 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);
 	PutColor(ptr, Color.r, Color.g, Color.b, Color.unused);
 	#else
 	#else
 	PutColor(ptr, Color.r, Color.g, Color.b, Color.a);
 	PutColor(ptr, Color.r, Color.g, Color.b, Color.a);