mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Merge branch 'SDL1Wipe' into develop
This commit is contained in:
		| @@ -29,29 +29,6 @@ | ||||
| 					<Add option="-s" /> | ||||
| 				</Linker> | ||||
| 			</Target> | ||||
| 			<Target title="Debug-win32-SDL1"> | ||||
| 				<Option platforms="Windows;" /> | ||||
| 				<Option output="../BattleAI" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="1" extension_auto="1" /> | ||||
| 				<Option object_output="obj/Debug/" /> | ||||
| 				<Option type="3" /> | ||||
| 				<Option compiler="gcc" /> | ||||
| 				<Compiler> | ||||
| 					<Add option="-g" /> | ||||
| 				</Compiler> | ||||
| 			</Target> | ||||
| 			<Target title="Release-win32-SDL1"> | ||||
| 				<Option platforms="Windows;" /> | ||||
| 				<Option output="../BattleAI" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="1" extension_auto="1" /> | ||||
| 				<Option object_output="obj/Release/" /> | ||||
| 				<Option type="3" /> | ||||
| 				<Option compiler="gcc" /> | ||||
| 				<Compiler> | ||||
| 					<Add option="-O2" /> | ||||
| 				</Compiler> | ||||
| 				<Linker> | ||||
| 					<Add option="-s" /> | ||||
| 				</Linker> | ||||
| 			</Target> | ||||
| 		</Build> | ||||
| 		<Compiler> | ||||
| 			<Add option="-pedantic" /> | ||||
|   | ||||
| @@ -23,36 +23,8 @@ | ||||
| 				<Option type="3" /> | ||||
| 				<Option compiler="gcc" /> | ||||
| 				<Compiler> | ||||
| 					<Add option="-fomit-frame-pointer" /> | ||||
| 					<Add option="-O3" /> | ||||
| 					<Add option="-O2" /> | ||||
| 				</Compiler> | ||||
| 				<Linker> | ||||
| 					<Add option="-s" /> | ||||
| 				</Linker> | ||||
| 			</Target> | ||||
| 			<Target title="Debug-win32-SDL1"> | ||||
| 				<Option platforms="Windows;" /> | ||||
| 				<Option output="../EmptyAI" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="1" extension_auto="1" /> | ||||
| 				<Option object_output="obj/Debug/" /> | ||||
| 				<Option type="3" /> | ||||
| 				<Option compiler="gcc" /> | ||||
| 				<Compiler> | ||||
| 					<Add option="-ggdb" /> | ||||
| 				</Compiler> | ||||
| 			</Target> | ||||
| 			<Target title="Release-win32-SDL1"> | ||||
| 				<Option platforms="Windows;" /> | ||||
| 				<Option output="../EmptyAI" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="1" extension_auto="1" /> | ||||
| 				<Option object_output="obj/Release/" /> | ||||
| 				<Option type="3" /> | ||||
| 				<Option compiler="gcc" /> | ||||
| 				<Compiler> | ||||
| 					<Add option="-fomit-frame-pointer" /> | ||||
| 					<Add option="-O3" /> | ||||
| 				</Compiler> | ||||
| 				<Linker> | ||||
| 					<Add option="-s" /> | ||||
| 				</Linker> | ||||
| 			</Target> | ||||
| 		</Build> | ||||
| 		<Compiler> | ||||
|   | ||||
| @@ -34,34 +34,6 @@ | ||||
| 					<Add option="-s" /> | ||||
| 				</Linker> | ||||
| 			</Target> | ||||
| 			<Target title="Debug-win32-SDL1"> | ||||
| 				<Option platforms="Windows;" /> | ||||
| 				<Option output="bin/Debug/FuzzyLite" prefix_auto="1" extension_auto="1" /> | ||||
| 				<Option working_dir="" /> | ||||
| 				<Option object_output="obj/Debug/" /> | ||||
| 				<Option type="2" /> | ||||
| 				<Option compiler="gcc" /> | ||||
| 				<Option createDefFile="1" /> | ||||
| 				<Compiler> | ||||
| 					<Add option="-g" /> | ||||
| 				</Compiler> | ||||
| 			</Target> | ||||
| 			<Target title="Release-win32-SDL1"> | ||||
| 				<Option platforms="Windows;" /> | ||||
| 				<Option output="bin/Release/FuzzyLite" prefix_auto="1" extension_auto="1" /> | ||||
| 				<Option working_dir="" /> | ||||
| 				<Option object_output="obj/Release/" /> | ||||
| 				<Option type="2" /> | ||||
| 				<Option compiler="gcc" /> | ||||
| 				<Option createDefFile="1" /> | ||||
| 				<Compiler> | ||||
| 					<Add option="-fomit-frame-pointer" /> | ||||
| 					<Add option="-O2" /> | ||||
| 				</Compiler> | ||||
| 				<Linker> | ||||
| 					<Add option="-s" /> | ||||
| 				</Linker> | ||||
| 			</Target> | ||||
| 		</Build> | ||||
| 		<Compiler> | ||||
| 			<Add option="-Wextra" /> | ||||
|   | ||||
| @@ -30,30 +30,6 @@ | ||||
| 					<Add option="-s" /> | ||||
| 				</Linker> | ||||
| 			</Target> | ||||
| 			<Target title="Debug-win32-SDL1"> | ||||
| 				<Option platforms="Windows;" /> | ||||
| 				<Option output="../StupidAI" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="1" extension_auto="1" /> | ||||
| 				<Option object_output="obj/Debug/" /> | ||||
| 				<Option type="3" /> | ||||
| 				<Option compiler="gcc" /> | ||||
| 				<Compiler> | ||||
| 					<Add option="-ggdb" /> | ||||
| 				</Compiler> | ||||
| 			</Target> | ||||
| 			<Target title="Release-win32-SDL1"> | ||||
| 				<Option platforms="Windows;" /> | ||||
| 				<Option output="../StupidAI" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="1" extension_auto="1" /> | ||||
| 				<Option object_output="obj/Release/" /> | ||||
| 				<Option type="3" /> | ||||
| 				<Option compiler="gcc" /> | ||||
| 				<Compiler> | ||||
| 					<Add option="-fomit-frame-pointer" /> | ||||
| 					<Add option="-O3" /> | ||||
| 				</Compiler> | ||||
| 				<Linker> | ||||
| 					<Add option="-s" /> | ||||
| 				</Linker> | ||||
| 			</Target> | ||||
| 		</Build> | ||||
| 		<Compiler> | ||||
| 			<Add option="-pedantic" /> | ||||
|   | ||||
| @@ -34,34 +34,6 @@ | ||||
| 					<Add directory="../FuzzyLite/bin/Release" /> | ||||
| 				</Linker> | ||||
| 			</Target> | ||||
| 			<Target title="Debug-win32-SDL1"> | ||||
| 				<Option platforms="Windows;" /> | ||||
| 				<Option output="../VCAI" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="1" extension_auto="1" /> | ||||
| 				<Option object_output="obj/Debug/" /> | ||||
| 				<Option type="3" /> | ||||
| 				<Option compiler="gcc" /> | ||||
| 				<Compiler> | ||||
| 					<Add option="-g" /> | ||||
| 				</Compiler> | ||||
| 				<Linker> | ||||
| 					<Add directory="../FuzzyLite/bin/Debug" /> | ||||
| 				</Linker> | ||||
| 			</Target> | ||||
| 			<Target title="Release-win32-SDL1"> | ||||
| 				<Option platforms="Windows;" /> | ||||
| 				<Option output="../VCAI" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="1" extension_auto="1" /> | ||||
| 				<Option object_output="obj/Release/" /> | ||||
| 				<Option type="3" /> | ||||
| 				<Option compiler="gcc" /> | ||||
| 				<Compiler> | ||||
| 					<Add option="-fomit-frame-pointer" /> | ||||
| 					<Add option="-O3" /> | ||||
| 				</Compiler> | ||||
| 				<Linker> | ||||
| 					<Add option="-s" /> | ||||
| 					<Add directory="../FuzzyLite/bin/Release" /> | ||||
| 				</Linker> | ||||
| 			</Target> | ||||
| 		</Build> | ||||
| 		<Compiler> | ||||
| 			<Add option="-pedantic" /> | ||||
|   | ||||
| @@ -21,7 +21,6 @@ option(ENABLE_EDITOR "Enable compilation of map editor" OFF) | ||||
| option(ENABLE_LAUNCHER "Enable compilation of launcher" ON) | ||||
| option(ENABLE_TEST "Enable compilation of unit tests" OFF) | ||||
| option(ENABLE_PCH "Enable compilation using precompiled headers" ON) | ||||
| option(ENABLE_SDL2 "Use SDL2 for compilation instead of SDL 1.2" ON) | ||||
|  | ||||
| ############################################ | ||||
| #        Building section                  # | ||||
| @@ -118,26 +117,20 @@ if (MINIZIP_FOUND) | ||||
|     add_definitions(-DUSE_SYSTEM_MINIZIP) | ||||
| endif() | ||||
|  | ||||
| if (ENABLE_SDL2) | ||||
| 	find_package(SDL2 REQUIRED) | ||||
| 	find_package(SDL2_image REQUIRED) | ||||
| 	find_package(SDL2_mixer REQUIRED) | ||||
| 	find_package(SDL2_ttf REQUIRED) | ||||
| find_package(SDL2 REQUIRED) | ||||
| find_package(SDL2_image REQUIRED) | ||||
| find_package(SDL2_mixer REQUIRED) | ||||
| find_package(SDL2_ttf REQUIRED) | ||||
|  | ||||
| set(SDL_INCLUDE_DIR "${SDL2_INCLUDE_DIR}") | ||||
| set(SDLTTF_INCLUDE_DIR "${SDL2_TTF_INCLUDE_DIR}") | ||||
| set(SDLIMAGE_INCLUDE_DIR "${SDL2_IMAGE_INCLUDE_DIR}") | ||||
| set(SDLMIXER_INCLUDE_DIR "${SDL2_MIXER_INCLUDE_DIR}") | ||||
| set(SDL_LIBRARY "${SDL2_LIBRARY}") | ||||
| set(SDLTTF_LIBRARY "${SDL2_TTF_LIBRARY}") | ||||
| set(SDLIMAGE_LIBRARY "${SDL2_IMAGE_LIBRARY}") | ||||
| set(SDLMIXER_LIBRARY "${SDL2_MIXER_LIBRARY}") | ||||
|  | ||||
| 	set(SDL_INCLUDE_DIR "${SDL2_INCLUDE_DIR}") | ||||
| 	set(SDLTTF_INCLUDE_DIR "${SDL2_TTF_INCLUDE_DIR}") | ||||
| 	set(SDLIMAGE_INCLUDE_DIR "${SDL2_IMAGE_INCLUDE_DIR}") | ||||
| 	set(SDLMIXER_INCLUDE_DIR "${SDL2_MIXER_INCLUDE_DIR}") | ||||
| 	set(SDL_LIBRARY "${SDL2_LIBRARY}") | ||||
| 	set(SDLTTF_LIBRARY "${SDL2_TTF_LIBRARY}") | ||||
| 	set(SDLIMAGE_LIBRARY "${SDL2_IMAGE_LIBRARY}") | ||||
| 	set(SDLMIXER_LIBRARY "${SDL2_MIXER_LIBRARY}") | ||||
| else() | ||||
| 	find_package(SDL REQUIRED) | ||||
| 	find_package(SDL_image REQUIRED) | ||||
| 	find_package(SDL_mixer REQUIRED) | ||||
| 	find_package(SDL_ttf REQUIRED) | ||||
| endif() | ||||
| include(cotire) | ||||
|  | ||||
| if (ENABLE_EDITOR OR ENABLE_LAUNCHER) | ||||
|   | ||||
| @@ -181,24 +181,11 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, const ui8 * FDef, const SDL_Co | ||||
| 	BaseOffset += sizeof(SSpriteDef); | ||||
| 	int BaseOffsetor = BaseOffset; | ||||
|  | ||||
| 	#ifdef VCMI_SDL1 | ||||
| 	for(int i=0; i<256; ++i) | ||||
| 	{		 | ||||
| 		SDL_Color pr; | ||||
| 		pr.r = palette[i].r; | ||||
| 		pr.g = palette[i].g; | ||||
| 		pr.b = palette[i].b; | ||||
| 		pr.unused = palette[i].unused; | ||||
| 		(*(ret->format->palette->colors+i))=pr;		 | ||||
| 	} | ||||
| 	#else | ||||
| 	if(SDL_SetPaletteColors(ret->format->palette,palette,0,256) != 0) | ||||
| 	{ | ||||
| 		throw std::runtime_error("Unable to set palette");	 | ||||
| 	} | ||||
| 	 | ||||
| 	#endif | ||||
|  | ||||
| 	int ftcp=0; | ||||
|  | ||||
| 	// If there's a margin anywhere, just blank out the whole surface. | ||||
| @@ -363,13 +350,8 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, const ui8 * FDef, const SDL_Co | ||||
| 	} | ||||
|  | ||||
| 	SDL_Color ttcol = ret->format->palette->colors[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 | ||||
| 	Uint32 keycol = SDL_MapRGBA(ret->format, ttcol.r, ttcol.b, ttcol.g, ttcol.a);	 | ||||
| 	SDL_SetColorKey(ret, SDL_TRUE, keycol);	 | ||||
| 	#endif // 0 | ||||
|  | ||||
| 	return ret; | ||||
| } | ||||
|   | ||||
							
								
								
									
										116
									
								
								client/CMT.cpp
									
									
									
									
									
								
							
							
						
						
									
										116
									
								
								client/CMT.cpp
									
									
									
									
									
								
							| @@ -69,12 +69,10 @@ std::string NAME = GameConstants::VCMI_VERSION + std::string(" (") + NAME_AFFIX | ||||
| CGuiHandler GH; | ||||
| static CClient *client=nullptr; | ||||
|  | ||||
| #ifndef VCMI_SDL1 | ||||
| int preferredDriverIndex = -1; | ||||
| SDL_Window * mainWindow = nullptr; | ||||
| SDL_Renderer * mainRenderer = nullptr; | ||||
| SDL_Texture * screenTexture = nullptr; | ||||
| #endif // VCMI_SDL1 | ||||
|  | ||||
| extern boost::thread_specific_ptr<bool> inGuiThread; | ||||
|  | ||||
| @@ -264,11 +262,6 @@ int main(int argc, char** argv) | ||||
| 		gNoGUI = true; | ||||
| 		vm.insert(std::pair<std::string, po::variable_value>("onlyAI", po::variable_value())); | ||||
| 	} | ||||
| #ifdef VCMI_SDL1 | ||||
| 	//Set environment vars to make window centered. Sometimes work, sometimes not. :/ | ||||
| 	putenv((char*)"SDL_VIDEO_WINDOW_POS"); | ||||
| 	putenv((char*)"SDL_VIDEO_CENTERED=1"); | ||||
| #endif | ||||
|  | ||||
| 	// Have effect on X11 system only (Linux). | ||||
| 	// For whatever reason in fullscreen mode SDL takes "raw" mouse input from DGA X11 extension | ||||
| @@ -338,11 +331,7 @@ int main(int argc, char** argv) | ||||
|  | ||||
| 	if(!gNoGUI) | ||||
| 	{ | ||||
| 		#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)) | ||||
| 		#endif | ||||
| 		{ | ||||
| 			logGlobal->errorStream()<<"Something was wrong: "<< SDL_GetError(); | ||||
| 			exit(-1); | ||||
| @@ -350,7 +339,6 @@ int main(int argc, char** argv) | ||||
| 		GH.mainFPSmng->init(); //(!)init here AFTER SDL_Init() while using SDL for FPS management | ||||
| 		atexit(SDL_Quit); | ||||
| 		 | ||||
| 		#ifndef VCMI_SDL1 | ||||
| 		int driversCount = SDL_GetNumRenderDrivers(); | ||||
| 		std::string preferredDriverName = video["driver"].String(); | ||||
| 		 | ||||
| @@ -371,7 +359,6 @@ int main(int argc, char** argv) | ||||
| 			else | ||||
| 				logGlobal->infoStream() << "\t" << driverName; | ||||
| 		}			 | ||||
| 		#endif // VCMI_SDL1	 | ||||
| 		 | ||||
| 		config::CConfigHandler::GuiOptionsMap::key_type resPair(res["width"].Float(), res["height"].Float()); | ||||
| 		if (conf.guiOptions.count(resPair) == 0) | ||||
| @@ -823,7 +810,6 @@ void dispose() | ||||
|  | ||||
| static bool checkVideoMode(int monitorIndex, int w, int h, int& bpp, bool fullscreen) | ||||
| { | ||||
| 	#ifndef VCMI_SDL1 | ||||
| 	SDL_DisplayMode mode; | ||||
| 	const int modeCount = SDL_GetNumDisplayModes(monitorIndex); | ||||
| 	for (int i = 0; i < modeCount; i++) { | ||||
| @@ -833,13 +819,8 @@ static bool checkVideoMode(int monitorIndex, int w, int h, int& bpp, bool fullsc | ||||
| 		} | ||||
| 	} | ||||
| 	return false;	 | ||||
| 	#else | ||||
| 	bpp = SDL_VideoModeOK(w, h, bpp, SDL_SWSURFACE|(fullscreen?SDL_FULLSCREEN:0)); | ||||
| 	return !(bpp==0); | ||||
| 	#endif // VCMI_SDL1 | ||||
| } | ||||
|  | ||||
| #ifndef VCMI_SDL1 | ||||
| static bool recreateWindow(int w, int h, int bpp, bool fullscreen) | ||||
| { | ||||
| 	// VCMI will only work with 2 or 4 bytes per pixel	 | ||||
| @@ -982,91 +963,14 @@ static bool recreateWindow(int w, int h, int bpp, bool fullscreen) | ||||
| 		 | ||||
| 	return true;	 | ||||
| } | ||||
| #endif | ||||
|  | ||||
|  | ||||
|  | ||||
| //used only once during initialization | ||||
| static void setScreenRes(int w, int h, int bpp, bool fullscreen, bool resetVideo) | ||||
| { | ||||
| #ifdef VCMI_SDL1 | ||||
| 	 | ||||
| 	// VCMI will only work with 2, 3 or 4 bytes per pixel | ||||
| 	vstd::amax(bpp, 16); | ||||
| 	vstd::amin(bpp, 32); | ||||
|  | ||||
| 	// Try to use the best screen depth for the display | ||||
| 	int suggestedBpp = SDL_VideoModeOK(w, h, bpp, SDL_SWSURFACE|(fullscreen?SDL_FULLSCREEN:0)); | ||||
| 	if(suggestedBpp == 0) | ||||
| 	{ | ||||
| 		logGlobal->errorStream() << "Error: SDL says that " << w << "x" << h << " resolution is not available!"; | ||||
| 		return; | ||||
| 	} | ||||
|  | ||||
| 	bool bufOnScreen = (screenBuf == screen); | ||||
|  | ||||
| 	if(suggestedBpp != bpp) | ||||
| 	{ | ||||
| 		logGlobal->infoStream() << boost::format("Using %s bpp (bits per pixel) for the video mode. Default or overridden setting was %s bpp.") % suggestedBpp % bpp; | ||||
| 	} | ||||
|  | ||||
| 	//For some reason changing fullscreen via config window checkbox result in SDL_Quit event | ||||
| 	if (resetVideo) | ||||
| 	{ | ||||
| 		if(screen) //screen has been already initialized | ||||
| 			SDL_QuitSubSystem(SDL_INIT_VIDEO); | ||||
| 		SDL_InitSubSystem(SDL_INIT_VIDEO); | ||||
| 	} | ||||
|  | ||||
| 	if((screen = SDL_SetVideoMode(w, h, suggestedBpp, SDL_SWSURFACE|(fullscreen?SDL_FULLSCREEN:0))) == nullptr) | ||||
| 	{ | ||||
| 		logGlobal->errorStream() << "Requested screen resolution is not available (" << w << "x" << h << "x" << suggestedBpp << "bpp)"; | ||||
| 		throw std::runtime_error("Requested screen resolution is not available\n"); | ||||
| 	} | ||||
|  | ||||
| 	logGlobal->infoStream() << "New screen flags: " << screen->flags; | ||||
|  | ||||
| 	if(screen2) | ||||
| 		SDL_FreeSurface(screen2); | ||||
| 	screen2 = CSDL_Ext::copySurface(screen); | ||||
| 	SDL_EnableUNICODE(1); | ||||
| 	SDL_WM_SetCaption(NAME.c_str(),""); //set window title | ||||
| 	SDL_ShowCursor(SDL_DISABLE); | ||||
| 	SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); | ||||
|  | ||||
| #ifdef VCMI_WINDOWS | ||||
| 	SDL_SysWMinfo wm; | ||||
| 	SDL_VERSION(&wm.version); | ||||
| 	int getwm = SDL_GetWMInfo(&wm); | ||||
| 	if(getwm == 1) | ||||
| 	{ | ||||
| 		int sw = GetSystemMetrics(SM_CXSCREEN), | ||||
| 			sh = GetSystemMetrics(SM_CYSCREEN); | ||||
| 		RECT curpos; | ||||
| 		GetWindowRect(wm.window,&curpos); | ||||
| 		int ourw = curpos.right - curpos.left, | ||||
| 			ourh = curpos.bottom - curpos.top; | ||||
| 		SetWindowPos(wm.window, 0, (sw - ourw)/2, (sh - ourh)/2, 0, 0, SWP_NOZORDER|SWP_NOSIZE); | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
|         logGlobal->warnStream() << "Something went wrong, getwm=" << getwm; | ||||
|         logGlobal->warnStream() << "SDL says: " << SDL_GetError(); | ||||
|         logGlobal->warnStream() << "Window won't be centered."; | ||||
| 	} | ||||
| #endif | ||||
| 	//TODO: centering game window on other platforms (or does the environment do their job correctly there?) | ||||
|  | ||||
| 	screenBuf = bufOnScreen ? screen : screen2; | ||||
| 	//setResolution = true;	 | ||||
| 	 | ||||
| #else | ||||
| 	 | ||||
| 	if(!recreateWindow(w,h,bpp,fullscreen)) | ||||
| 	{ | ||||
| 		throw std::runtime_error("Requested screen resolution is not available\n"); | ||||
| 	}	 | ||||
| #endif // VCMI_SDL1 | ||||
| } | ||||
|  | ||||
| static void fullScreenChanged() | ||||
| @@ -1078,19 +982,6 @@ static void fullScreenChanged() | ||||
|  | ||||
| 	auto bitsPerPixel = screen->format->BitsPerPixel; | ||||
| 	 | ||||
| 	#ifdef VCMI_SDL1 | ||||
| 	bitsPerPixel = SDL_VideoModeOK(screen->w, screen->h, bitsPerPixel, SDL_SWSURFACE|(toFullscreen?SDL_FULLSCREEN:0)); | ||||
| 	if(bitsPerPixel == 0) | ||||
| 	{ | ||||
|         logGlobal->errorStream() << "Error: SDL says that " << screen->w << "x" << screen->h << " resolution is not available!"; | ||||
| 		return; | ||||
| 	} | ||||
|  | ||||
| 	bool bufOnScreen = (screenBuf == screen); | ||||
| 	screen = SDL_SetVideoMode(screen->w, screen->h, bitsPerPixel, SDL_SWSURFACE|(toFullscreen?SDL_FULLSCREEN:0)); | ||||
| 	screenBuf = bufOnScreen ? screen : screen2; | ||||
| 	 | ||||
| 	#else | ||||
| 	auto w = screen->w; | ||||
| 	auto h = screen->h; | ||||
| 	 | ||||
| @@ -1099,7 +990,6 @@ static void fullScreenChanged() | ||||
| 		//will return false and report error if video mode is not supported | ||||
| 		return;	 | ||||
| 	}	 | ||||
| 	#endif | ||||
| 	 | ||||
| 	GH.totalRedraw(); | ||||
| } | ||||
| @@ -1111,13 +1001,7 @@ static void handleEvent(SDL_Event & ev) | ||||
| 		handleQuit();	 | ||||
| 		return; | ||||
| 	} | ||||
|  | ||||
| 	#ifdef VCMI_SDL1 | ||||
| 	//FIXME: this should work even in pregame | ||||
| 	else if(LOCPLINT && ev.type == SDL_KEYDOWN && ev.key.keysym.sym==SDLK_F4) | ||||
| 	#else | ||||
| 	else if(ev.type == SDL_KEYDOWN && ev.key.keysym.sym==SDLK_F4) | ||||
| 	#endif // VCMI_SDL1		 | ||||
| 	{ | ||||
| 		Settings full = settings.write["video"]["fullscreen"]; | ||||
| 		full->Bool() = !full->Bool(); | ||||
|   | ||||
| @@ -1,6 +1,5 @@ | ||||
| #pragma once | ||||
|  | ||||
| #ifndef VCMI_SDL1 | ||||
| #include <SDL_render.h> | ||||
|  | ||||
| extern SDL_Texture * screenTexture; | ||||
| @@ -8,8 +7,6 @@ extern SDL_Texture * screenTexture; | ||||
| extern SDL_Window * mainWindow; | ||||
| extern SDL_Renderer * mainRenderer; | ||||
|  | ||||
| #endif // VCMI_SDL2 | ||||
|  | ||||
| extern SDL_Surface *screen;      // main screen surface | ||||
| extern SDL_Surface *screen2;     // and hlp surface (used to store not-active interfaces layer) | ||||
| extern SDL_Surface *screenBuf; // points to screen (if only advmapint is present) or screen2 (else) - should be used when updating controls which are not regularly redrawed | ||||
|   | ||||
| @@ -451,18 +451,6 @@ void MusicEntry::load(std::string musicURI) | ||||
| 	data = CResourceHandler::get()->load(ResourceID(musicURI, EResType::MUSIC))->readAll(); | ||||
| 	musicFile = SDL_RWFromConstMem(data.first.get(), data.second); | ||||
| 	 | ||||
| 	#ifdef VCMI_SDL1 | ||||
| 	music = Mix_LoadMUS_RW(musicFile); | ||||
|  | ||||
| 	if(!music) | ||||
| 	{ | ||||
| 		SDL_FreeRW(musicFile); | ||||
| 		musicFile = nullptr; | ||||
| 		logGlobal->warnStream() << "Warning: Cannot open " << currentName << ": " << Mix_GetError(); | ||||
| 		return; | ||||
| 	} | ||||
|  | ||||
| 	#else | ||||
| 	music = Mix_LoadMUS_RW(musicFile, SDL_FALSE); | ||||
|  | ||||
| 	if(!music) | ||||
| @@ -472,9 +460,6 @@ void MusicEntry::load(std::string musicURI) | ||||
| 		logGlobal->warnStream() << "Warning: Cannot open " << currentName << ": " << Mix_GetError(); | ||||
| 		return; | ||||
| 	} | ||||
|  | ||||
| 	#endif // 0 | ||||
|  | ||||
| } | ||||
|  | ||||
| bool MusicEntry::play() | ||||
|   | ||||
| @@ -1545,16 +1545,11 @@ void CPlayerInterface::centerView (int3 pos, int focusTime) | ||||
| 	if(focusTime) | ||||
| 	{ | ||||
| 		GH.totalRedraw(); | ||||
| 		#ifdef VCMI_SDL1 | ||||
| 		CSDL_Ext::update(screen); | ||||
| 		SDL_Delay(focusTime); | ||||
| 		#else | ||||
| 		{ | ||||
| 			auto unlockPim = vstd::makeUnlockGuard(*pim); | ||||
| 			IgnoreEvents ignore(*this); | ||||
| 			SDL_Delay(focusTime); | ||||
| 		} | ||||
| 		#endif | ||||
| 	} | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -53,11 +53,7 @@ CVideoPlayer::CVideoPlayer() | ||||
| 	frame = nullptr; | ||||
| 	codec = nullptr; | ||||
| 	sws = nullptr; | ||||
| #ifdef VCMI_SDL1 | ||||
| 	overlay = nullptr; | ||||
| #else | ||||
| 	texture = nullptr; | ||||
| #endif | ||||
| 	dest = nullptr; | ||||
| 	context = nullptr; | ||||
|  | ||||
| @@ -173,13 +169,7 @@ bool CVideoPlayer::open(std::string fname, bool loop, bool useOverlay, bool scal | ||||
| 	// Allocate a place to put our YUV image on that screen | ||||
| 	if (useOverlay) | ||||
| 	{ | ||||
| #ifdef VCMI_SDL1 | ||||
| 		overlay = SDL_CreateYUVOverlay(pos.w, pos.h, | ||||
| 									   SDL_YV12_OVERLAY, screen); | ||||
| #else | ||||
| 		texture = SDL_CreateTexture( mainRenderer, SDL_PIXELFORMAT_IYUV, SDL_TEXTUREACCESS_STATIC, pos.w, pos.h); | ||||
| #endif | ||||
|  | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| @@ -188,17 +178,11 @@ bool CVideoPlayer::open(std::string fname, bool loop, bool useOverlay, bool scal | ||||
| 		destRect.w = pos.w; | ||||
| 		destRect.h = pos.h; | ||||
| 	} | ||||
| #ifdef VCMI_SDL1 | ||||
| 	if (overlay == nullptr && dest == nullptr) | ||||
| 		return false; | ||||
|  | ||||
| 	if (overlay) | ||||
| #else | ||||
| 	if (texture == nullptr && dest == nullptr) | ||||
| 		return false; | ||||
|  | ||||
| 	if (texture) | ||||
| #endif | ||||
| 	{ // Convert the image into YUV format that SDL uses | ||||
| 		sws = sws_getContext(codecContext->width, codecContext->height, codecContext->pix_fmt,  | ||||
| 							 pos.w, pos.h, PIX_FMT_YUV420P,  | ||||
| @@ -284,23 +268,6 @@ bool CVideoPlayer::nextFrame() | ||||
| 				{ | ||||
| 					AVPicture pict; | ||||
|  | ||||
| #ifdef VCMI_SDL1 | ||||
| 					if (overlay) { | ||||
| 						SDL_LockYUVOverlay(overlay); | ||||
|  | ||||
| 						pict.data[0] = overlay->pixels[0]; | ||||
| 						pict.data[1] = overlay->pixels[2]; | ||||
| 						pict.data[2] = overlay->pixels[1]; | ||||
|  | ||||
| 						pict.linesize[0] = overlay->pitches[0]; | ||||
| 						pict.linesize[1] = overlay->pitches[2]; | ||||
| 						pict.linesize[2] = overlay->pitches[1]; | ||||
|  | ||||
| 						sws_scale(sws, frame->data, frame->linesize, | ||||
| 								  0, codecContext->height, pict.data, pict.linesize); | ||||
|  | ||||
| 						SDL_UnlockYUVOverlay(overlay); | ||||
| #else | ||||
| 					if (texture) { | ||||
| 						avpicture_alloc(&pict, AV_PIX_FMT_YUV420P, pos.w, pos.h); | ||||
|  | ||||
| @@ -311,7 +278,6 @@ bool CVideoPlayer::nextFrame() | ||||
| 								pict.data[1], pict.linesize[1], | ||||
| 								pict.data[2], pict.linesize[2]); | ||||
| 						avpicture_free(&pict); | ||||
| #endif | ||||
| 					} | ||||
| 					else | ||||
| 					{ | ||||
| @@ -387,22 +353,12 @@ void CVideoPlayer::close() | ||||
| 		sws = nullptr; | ||||
| 	} | ||||
|  | ||||
| #ifdef VCMI_SDL1 | ||||
| 	if (overlay) | ||||
| 	{ | ||||
| 		SDL_FreeYUVOverlay(overlay); | ||||
| 		overlay = nullptr; | ||||
| 	} | ||||
| #else | ||||
| 	if (texture) | ||||
| 	{ | ||||
| 		SDL_DestroyTexture(texture); | ||||
| 		texture = nullptr; | ||||
| 	} | ||||
|  | ||||
| #endif | ||||
|  | ||||
|  | ||||
| 	if (dest) | ||||
| 	{ | ||||
| 		SDL_FreeSurface(dest); | ||||
| @@ -455,13 +411,8 @@ bool CVideoPlayer::playVideo(int x, int y, SDL_Surface *dst, bool stopOnKey) | ||||
| 		if(stopOnKey && keyDown()) | ||||
| 			return false; | ||||
|  | ||||
| #ifdef VCMI_SDL1 | ||||
| 		SDL_DisplayYUVOverlay(overlay, &pos); | ||||
| #else | ||||
| 		SDL_RenderCopy(mainRenderer, texture, NULL, &pos); | ||||
| 		SDL_RenderPresent(mainRenderer); | ||||
| #endif | ||||
|  | ||||
|  | ||||
| 		// Wait 3 frames | ||||
| 		GH.mainFPSmng->framerateDelay(); | ||||
|   | ||||
| @@ -47,9 +47,6 @@ public: | ||||
|  | ||||
| #include <SDL.h> | ||||
| #include <SDL_video.h> | ||||
| #if SDL_VERSION_ATLEAST(1,3,0) && !SDL_VERSION_ATLEAST(2,0,0) | ||||
| #include <SDL_compat.h> | ||||
| #endif | ||||
|  | ||||
| extern "C" { | ||||
| #include <libavformat/avformat.h> | ||||
| @@ -80,12 +77,8 @@ class CVideoPlayer : public IMainVideoPlayer | ||||
| 	AVIOContext * context; | ||||
|  | ||||
| 	// Destination. Either overlay or dest. | ||||
| #ifdef VCMI_SDL1 | ||||
| 	SDL_Overlay * overlay; | ||||
| #else | ||||
| 	SDL_Texture *texture; | ||||
| #endif | ||||
|  | ||||
| 	SDL_Texture *texture; | ||||
| 	SDL_Surface *dest; | ||||
| 	SDL_Rect destRect;			// valid when dest is used | ||||
| 	SDL_Rect pos;				// destination on screen | ||||
|   | ||||
| @@ -266,9 +266,7 @@ void Graphics::loadHeroFlagsDetail(std::pair<std::vector<CDefEssential *> Graphi | ||||
| 		for(auto & curImg : curImgs) | ||||
| 		{ | ||||
| 			CSDL_Ext::setDefaultColorKey(curImg.bitmap); | ||||
| 			#ifndef VCMI_SDL1 | ||||
| 			SDL_SetSurfaceBlendMode(curImg.bitmap,SDL_BLENDMODE_NONE); | ||||
| 			#endif | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -47,47 +47,6 @@ | ||||
| 					<Add directory="$(#sdl2.lib)" /> | ||||
| 				</Linker> | ||||
| 			</Target> | ||||
| 			<Target title="Debug-win32-SDL1"> | ||||
| 				<Option platforms="Windows;" /> | ||||
| 				<Option output="../VCMI_client" prefix_auto="1" extension_auto="1" /> | ||||
| 				<Option working_dir="../" /> | ||||
| 				<Option object_output="../obj/Debug/" /> | ||||
| 				<Option type="1" /> | ||||
| 				<Option compiler="gcc" /> | ||||
| 				<Compiler> | ||||
| 					<Add option="-Og" /> | ||||
| 					<Add option="-g" /> | ||||
| 					<Add directory="$(#sdl.include)" /> | ||||
| 				</Compiler> | ||||
| 				<Linker> | ||||
| 					<Add option="-lSDL" /> | ||||
| 					<Add option="-lSDL_image" /> | ||||
| 					<Add option="-lSDL_mixer" /> | ||||
| 					<Add option="-lSDL_ttf" /> | ||||
| 					<Add directory="$(#sdl.lib)" /> | ||||
| 				</Linker> | ||||
| 			</Target> | ||||
| 			<Target title="Release-win32-SDL1"> | ||||
| 				<Option platforms="Windows;" /> | ||||
| 				<Option output="../VCMI_client" prefix_auto="1" extension_auto="1" /> | ||||
| 				<Option working_dir="../" /> | ||||
| 				<Option object_output="../obj/Release/" /> | ||||
| 				<Option type="1" /> | ||||
| 				<Option compiler="gcc" /> | ||||
| 				<Compiler> | ||||
| 					<Add option="-fomit-frame-pointer" /> | ||||
| 					<Add option="-O2" /> | ||||
| 					<Add directory="$(#sdl.include)" /> | ||||
| 				</Compiler> | ||||
| 				<Linker> | ||||
| 					<Add option="-s" /> | ||||
| 					<Add option="-lSDL" /> | ||||
| 					<Add option="-lSDL_image" /> | ||||
| 					<Add option="-lSDL_mixer" /> | ||||
| 					<Add option="-lSDL_ttf" /> | ||||
| 					<Add directory="$(#sdl.lib)" /> | ||||
| 				</Linker> | ||||
| 			</Target> | ||||
| 		</Build> | ||||
| 		<Compiler> | ||||
| 			<Add option="-Wextra" /> | ||||
|   | ||||
| @@ -267,11 +267,7 @@ static SDL_Color genShadow(ui8 alpha) | ||||
|  | ||||
| static SDL_Color genBorderColor(ui8 alpha, const SDL_Color & base) | ||||
| { | ||||
| 	#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)); | ||||
| 	#endif | ||||
| } | ||||
|  | ||||
| static ui8 mixChannels(ui8 c1, ui8 c2, ui8 a1, ui8 a2) | ||||
| @@ -281,22 +277,12 @@ static ui8 mixChannels(ui8 c1, ui8 c2, ui8 a1, ui8 a2) | ||||
|  | ||||
| static SDL_Color addColors(const SDL_Color & base, const SDL_Color & over) | ||||
| { | ||||
| 	#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), | ||||
| 			mixChannels(over.b, base.b, over.unused, base.unused), | ||||
| 			ui8(over.unused + base.unused * (255 - over.unused) / 256) | ||||
| 			); | ||||
| 	#else | ||||
| 	return CSDL_Ext::makeColor( | ||||
| 			mixChannels(over.r, base.r, over.a, base.a), | ||||
| 			mixChannels(over.g, base.g, over.a, base.a), | ||||
| 			mixChannels(over.b, base.b, over.a, base.a), | ||||
| 			ui8(over.a + base.a * (255 - over.a) / 256) | ||||
| 			); | ||||
|  | ||||
| 	#endif // VCMI_SDL1 | ||||
| } | ||||
|  | ||||
| std::array<SDL_Color, 8> CCreatureAnimation::genSpecialPalette() | ||||
| @@ -427,11 +413,7 @@ inline void CCreatureAnimation::putPixel(ui8 * dest, const SDL_Color & color, si | ||||
| 	if (index < 8) | ||||
| 	{ | ||||
| 		const SDL_Color & pal = special[index]; | ||||
| 		#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); | ||||
| 		#endif // 0		 | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
|   | ||||
| @@ -387,7 +387,7 @@ inline void SDLImageLoader::EndLine() | ||||
| SDLImageLoader::~SDLImageLoader() | ||||
| { | ||||
| 	SDL_UnlockSurface(image->surf); | ||||
| 	SDL_SetColorKey(image->surf, SDL_SRCCOLORKEY, 0); | ||||
| 	SDL_SetColorKey(image->surf, SDL_TRUE, 0); | ||||
| 	//TODO: RLE if compressed and bpp>1 | ||||
| } | ||||
|  | ||||
| @@ -444,13 +444,9 @@ inline ui8 CompImageLoader::typeOf(ui8 color) | ||||
| { | ||||
| 	if (color == 0) | ||||
| 		return 0; | ||||
| 	#ifdef VCMI_SDL1 | ||||
| 	if (image->palette[color].unused != 255) | ||||
| 		return 1; | ||||
| 	#else | ||||
|  | ||||
| 	if (image->palette[color].a != 255) | ||||
| 		return 1; | ||||
| 	#endif // 0 | ||||
| 		 | ||||
| 	return 2; | ||||
| } | ||||
| @@ -628,22 +624,11 @@ SDLImage::SDLImage(std::string filename, bool compressed): | ||||
| 	{ | ||||
| 		SDL_Surface *temp = surf; | ||||
| 		// add RLE flag | ||||
| 		#ifdef VCMI_SDL1 | ||||
| 		if (surf->format->palette) | ||||
| 		{ | ||||
| 			const SDL_Color &c = temp->format->palette->colors[0]; | ||||
| 			SDL_SetColorKey(temp, (SDL_SRCCOLORKEY | SDL_RLEACCEL), | ||||
| 				SDL_MapRGB(temp -> format, c.r, c.g, c.b)); | ||||
| 		} | ||||
| 		else | ||||
| 			SDL_SetColorKey(temp, SDL_RLEACCEL, 0); | ||||
| 		#else | ||||
| 		if (surf->format->palette) | ||||
| 		{ | ||||
| 			CSDL_Ext::setColorKey(temp,temp->format->palette->colors[0]); | ||||
| 		} | ||||
| 		SDL_SetSurfaceRLE(temp, SDL_RLEACCEL);		 | ||||
| 		#endif		 | ||||
|  | ||||
| 		// convert surface to enable RLE | ||||
| 		surf = SDL_ConvertSurface(temp, temp->format, temp->flags); | ||||
| @@ -811,21 +796,13 @@ 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++)]; | ||||
| 				#ifdef VCMI_SDL1 | ||||
| 				col.unused = (ui32)col.unused*alpha/255; | ||||
| 				#else | ||||
| 				col.a = (ui32)col.a*alpha/255; | ||||
| 				#endif // 0				 | ||||
| 				ColorPutter<bpp, 1>::PutColorAlpha(dest, col); | ||||
| 			} | ||||
| 			return; | ||||
| 		} | ||||
| 		 | ||||
| 		#ifdef VCMI_SDL1 | ||||
| 		if (palette[color].unused == 255) | ||||
| 		#else | ||||
|  | ||||
| 		if (palette[color].a == 255) | ||||
| 		#endif // 0		 | ||||
| 		{ | ||||
| 			//Put row of RGB data | ||||
| 			for (size_t i=0; i<size; i++) | ||||
| @@ -842,19 +819,6 @@ void CompImage::BlitBlock(ui8 type, ui8 size, ui8 *&data, ui8 *&dest, ui8 alpha) | ||||
| 	//RLE-d sequence | ||||
| 	else | ||||
| 	{ | ||||
| 		#ifdef VCMI_SDL1 | ||||
| 		if (alpha != 255 && palette[type].unused !=0)//Per-surface alpha is set | ||||
| 		{ | ||||
| 			SDL_Color col = palette[type]; | ||||
| 			col.unused = (int)col.unused*(255-alpha)/255; | ||||
| 			for (size_t i=0; i<size; i++) | ||||
| 				ColorPutter<bpp, 1>::PutColorAlpha(dest, col); | ||||
| 			return; | ||||
| 		}	 | ||||
|  | ||||
| 		switch (palette[type].unused) | ||||
| 				 | ||||
| 		#else | ||||
| 		if (alpha != 255 && palette[type].a !=0)//Per-surface alpha is set | ||||
| 		{ | ||||
| 			SDL_Color col = palette[type]; | ||||
| @@ -865,7 +829,6 @@ void CompImage::BlitBlock(ui8 type, ui8 size, ui8 *&data, ui8 *&dest, ui8 alpha) | ||||
| 		} | ||||
| 		 | ||||
| 		switch (palette[type].a) | ||||
| 		#endif // 0 | ||||
| 		{ | ||||
| 			case 0: | ||||
| 			{ | ||||
|   | ||||
| @@ -27,10 +27,8 @@ void CCursorHandler::initCursor() | ||||
| 	currentCursor = nullptr; | ||||
|  | ||||
| 	help = CSDL_Ext::newSurface(40,40); | ||||
| 	#ifndef VCMI_SDL1 | ||||
| 	//No blending. Ensure, that we are copying pixels during "screen restore draw" | ||||
| 	SDL_SetSurfaceBlendMode(help,SDL_BLENDMODE_NONE);	 | ||||
| 	#endif // VCMI_SDL1 | ||||
| 	SDL_ShowCursor(SDL_DISABLE); | ||||
|  | ||||
| 	changeGraphic(ECursor::ADVENTURE, 0); | ||||
|   | ||||
| @@ -63,10 +63,7 @@ void CGuiHandler::processLists(const ui16 activityFlag, std::function<void (std: | ||||
| 	processList(CIntObject::TIME,activityFlag,&timeinterested,cb); | ||||
| 	processList(CIntObject::WHEEL,activityFlag,&wheelInterested,cb); | ||||
| 	processList(CIntObject::DOUBLECLICK,activityFlag,&doubleClickInterested,cb); | ||||
| 	 | ||||
| 	#ifndef VCMI_SDL1 | ||||
| 	processList(CIntObject::TEXTINPUT,activityFlag,&textInterested,cb); | ||||
| 	#endif // VCMI_SDL1 | ||||
| } | ||||
|  | ||||
| void CGuiHandler::handleElementActivate(CIntObject * elem, ui16 activityFlag) | ||||
| @@ -196,10 +193,8 @@ void CGuiHandler::handleEvent(SDL_Event *sEvent) | ||||
| 		//translate numpad keys | ||||
| 		if(key.keysym.sym == SDLK_KP_ENTER) | ||||
| 		{ | ||||
| 			key.keysym.sym = (SDLKey)SDLK_RETURN; | ||||
| 			#ifndef VCMI_SDL1 | ||||
| 			key.keysym.sym = SDLK_RETURN; | ||||
| 			key.keysym.scancode = SDL_SCANCODE_RETURN; | ||||
| 			#endif // VCMI_SDL1 | ||||
| 		} | ||||
|  | ||||
| 		bool keysCaptured = false; | ||||
| @@ -270,19 +265,7 @@ void CGuiHandler::handleEvent(SDL_Event *sEvent) | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 		#ifdef VCMI_SDL1 //SDL1x only events | ||||
| 		else if(sEvent->button.button == SDL_BUTTON_WHEELDOWN || sEvent->button.button == SDL_BUTTON_WHEELUP) | ||||
| 		{ | ||||
| 			std::list<CIntObject*> hlp = wheelInterested; | ||||
| 			for(auto i=hlp.begin(); i != hlp.end() && current; i++) | ||||
| 			{ | ||||
| 				if(!vstd::contains(wheelInterested,*i)) continue; | ||||
| 				(*i)->wheelScrolled(sEvent->button.button == SDL_BUTTON_WHEELDOWN, isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y)); | ||||
| 			} | ||||
| 		} | ||||
| 		#endif | ||||
| 	} | ||||
| 	#ifndef VCMI_SDL1 //SDL2x only events	 | ||||
| 	else if (sEvent->type == SDL_MOUSEWHEEL) | ||||
| 	{ | ||||
| 		std::list<CIntObject*> hlp = wheelInterested; | ||||
| @@ -307,7 +290,6 @@ void CGuiHandler::handleEvent(SDL_Event *sEvent) | ||||
| 		} | ||||
| 	}	 | ||||
| 	//todo: muiltitouch | ||||
| 	#endif // VCMI_SDL1 | ||||
| 	else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_LEFT)) | ||||
| 	{ | ||||
| 		std::list<CIntObject*> hlp = lclickable; | ||||
| @@ -341,7 +323,6 @@ void CGuiHandler::handleEvent(SDL_Event *sEvent) | ||||
| 		} | ||||
| 	} | ||||
| 	current = nullptr; | ||||
|  | ||||
| } //event end | ||||
|  | ||||
| void CGuiHandler::handleMouseMotion(SDL_Event *sEvent) | ||||
| @@ -394,12 +375,9 @@ void CGuiHandler::handleMoveInterested( const SDL_MouseMotionEvent & motion ) | ||||
| void CGuiHandler::fakeMouseMove() | ||||
| { | ||||
| 	SDL_Event evnt; | ||||
| #ifdef VCMI_SDL1 | ||||
| 	SDL_MouseMotionEvent sme = {SDL_MOUSEMOTION, 0, 0, 0, 0, 0, 0}; | ||||
| #else | ||||
| 	SDL_MouseMotionEvent sme = {SDL_MOUSEMOTION, 0, 0, 0, 0, 0, 0, 0, 0}; | ||||
| #endif	 | ||||
| 	int x, y; | ||||
|  | ||||
| 	sme.state = SDL_GetMouseState(&x, &y); | ||||
| 	sme.x = x; | ||||
| 	sme.y = y; | ||||
| @@ -420,13 +398,10 @@ void CGuiHandler::renderFrame() | ||||
| 		// draw the mouse cursor and update the screen | ||||
| 		CCS->curh->render(); | ||||
|  | ||||
| 		#ifndef	VCMI_SDL1 | ||||
| 		if(0 != SDL_RenderCopy(mainRenderer, screenTexture, nullptr, nullptr)) | ||||
| 			logGlobal->errorStream() << __FUNCTION__ << " SDL_RenderCopy " << SDL_GetError(); | ||||
|  | ||||
| 		SDL_RenderPresent(mainRenderer);				 | ||||
| 		#endif		 | ||||
| 		 | ||||
| 	}; | ||||
| 	 | ||||
| 	if(curInt) | ||||
| @@ -470,23 +445,8 @@ void CGuiHandler::drawFPSCounter() | ||||
| 	graphics->fonts[FONT_BIG]->renderTextLeft(screen, fps, yellow, Point(10, 10)); | ||||
| } | ||||
|  | ||||
| SDLKey CGuiHandler::arrowToNum( SDLKey key ) | ||||
| SDL_Keycode CGuiHandler::arrowToNum(SDL_Keycode key ) | ||||
| { | ||||
| 	#ifdef VCMI_SDL1 | ||||
| 	switch(key) | ||||
| 	{ | ||||
| 	case SDLK_DOWN: | ||||
| 		return SDLK_KP2; | ||||
| 	case SDLK_UP: | ||||
| 		return SDLK_KP8; | ||||
| 	case SDLK_LEFT: | ||||
| 		return SDLK_KP4; | ||||
| 	case SDLK_RIGHT: | ||||
| 		return SDLK_KP6; | ||||
| 	default: | ||||
| 		throw std::runtime_error("Wrong key!");assert(0); | ||||
| 	}	 | ||||
| 	#else | ||||
| 	switch(key) | ||||
| 	{ | ||||
| 	case SDLK_DOWN: | ||||
| @@ -500,20 +460,14 @@ SDLKey CGuiHandler::arrowToNum( SDLKey key ) | ||||
| 	default: | ||||
| 		throw std::runtime_error("Wrong key!"); | ||||
| 	}	 | ||||
| 	#endif // 0 | ||||
| } | ||||
|  | ||||
| SDLKey CGuiHandler::numToDigit( SDLKey key ) | ||||
| SDL_Keycode CGuiHandler::numToDigit(SDL_Keycode key) | ||||
| { | ||||
| #ifdef VCMI_SDL1 | ||||
| 	if(key >= SDLK_KP0 && key <= SDLK_KP9) | ||||
| 		return SDLKey(key - SDLK_KP0 + SDLK_0); | ||||
| #endif // 0 | ||||
|  | ||||
| #define REMOVE_KP(keyName) case SDLK_KP_ ## keyName : return SDLK_ ## keyName; | ||||
| 	switch(key) | ||||
| 	{ | ||||
| #ifndef VCMI_SDL1 | ||||
| 		REMOVE_KP(0) | ||||
| 		REMOVE_KP(1) | ||||
| 		REMOVE_KP(2) | ||||
| @@ -524,7 +478,6 @@ SDLKey CGuiHandler::numToDigit( SDLKey key ) | ||||
| 		REMOVE_KP(7) | ||||
| 		REMOVE_KP(8) | ||||
| 		REMOVE_KP(9)		 | ||||
| #endif // VCMI_SDL1		 | ||||
| 		REMOVE_KP(PERIOD) | ||||
| 		REMOVE_KP(MINUS) | ||||
| 		REMOVE_KP(PLUS) | ||||
| @@ -542,22 +495,15 @@ SDLKey CGuiHandler::numToDigit( SDLKey key ) | ||||
| #undef REMOVE_KP | ||||
| } | ||||
|  | ||||
| bool CGuiHandler::isNumKey( SDLKey key, bool number ) | ||||
| bool CGuiHandler::isNumKey(SDL_Keycode key, bool number) | ||||
| { | ||||
| 	#ifdef VCMI_SDL1 | ||||
| 	if(number) | ||||
| 		return key >= SDLK_KP0 && key <= SDLK_KP9; | ||||
| 	else | ||||
| 		return key >= SDLK_KP0 && key <= SDLK_KP_EQUALS; | ||||
| 	#else | ||||
| 	if(number) | ||||
| 		return key >= SDLK_KP_1 && key <= SDLK_KP_0; | ||||
| 	else | ||||
| 		return (key >= SDLK_KP_1 && key <= SDLK_KP_0) || key == SDLK_KP_MINUS || key == SDLK_KP_PLUS || key == SDLK_KP_EQUALS; | ||||
| 	#endif // 0 | ||||
| } | ||||
|  | ||||
| bool CGuiHandler::isArrowKey( SDLKey key ) | ||||
| bool CGuiHandler::isArrowKey(SDL_Keycode key) | ||||
| { | ||||
| 	return key == SDLK_UP || key == SDLK_DOWN || key == SDLK_LEFT || key == SDLK_RIGHT; | ||||
| } | ||||
|   | ||||
| @@ -58,10 +58,9 @@ private: | ||||
| 				   motioninterested, | ||||
| 	               timeinterested, | ||||
| 	               wheelInterested, | ||||
| 	               doubleClickInterested; | ||||
| 	#ifndef VCMI_SDL1 | ||||
| 	CIntObjectList textInterested; | ||||
| 	#endif // VCMI_SDL1 | ||||
| 	               doubleClickInterested, | ||||
| 	               textInterested; | ||||
|  | ||||
| 	                | ||||
| 	void processLists(const ui16 activityFlag, std::function<void (std::list<CIntObject*> *)> cb);                | ||||
| public: | ||||
| @@ -104,10 +103,10 @@ public: | ||||
| 	ui8 captureChildren; //all newly created objects will get their parents from stack and will be added to parents children list | ||||
| 	std::list<CIntObject *> createdObj; //stack of objs being created | ||||
|  | ||||
| 	static SDLKey arrowToNum(SDLKey key); //converts arrow key to according numpad key | ||||
| 	static SDLKey numToDigit(SDLKey key);//converts numpad digit key to normal digit key | ||||
| 	static bool isNumKey(SDLKey key, bool number = true); //checks if key is on numpad (numbers - check only for numpad digits) | ||||
| 	static bool isArrowKey(SDLKey key); | ||||
| 	static SDL_Keycode arrowToNum(SDL_Keycode key); //converts arrow key to according numpad key | ||||
| 	static SDL_Keycode numToDigit(SDL_Keycode key);//converts numpad digit key to normal digit key | ||||
| 	static bool isNumKey(SDL_Keycode key, bool number = true); //checks if key is on numpad (numbers - check only for numpad digits) | ||||
| 	static bool isArrowKey(SDL_Keycode key); | ||||
| 	static bool amIGuiThread(); | ||||
| 	static void pushSDLEvent(int type, int usercode = 0); | ||||
| }; | ||||
|   | ||||
| @@ -133,10 +133,8 @@ public: | ||||
| 	virtual void keyPressed(const SDL_KeyboardEvent & key){} | ||||
| 	virtual bool captureThisEvent(const SDL_KeyboardEvent & key); //allows refining captureAllKeys against specific events (eg. don't capture ENTER) | ||||
|  | ||||
| #ifndef VCMI_SDL1 | ||||
| 	virtual void textInputed(const SDL_TextInputEvent & event){}; | ||||
| 	virtual void textEdited(const SDL_TextEditingEvent & event){}; | ||||
| #endif // VCMI_SDL1 | ||||
|  | ||||
| 	//mouse movement handling | ||||
| 	bool strongInterest; //if true - report all mouse movements, if not - only when hovered | ||||
|   | ||||
| @@ -13,23 +13,12 @@ | ||||
| #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 "unknown or unsupported SDL version" | ||||
| #endif | ||||
|   | ||||
| @@ -14,7 +14,6 @@ const SDL_Color Colors::METALLIC_GOLD = { 173, 142, 66, 0 }; | ||||
| const SDL_Color Colors::GREEN = { 0, 255, 0, 0 }; | ||||
| const SDL_Color Colors::DEFAULT_KEY_COLOR = {0, 255, 255, 0}; | ||||
|  | ||||
| #if (SDL_MAJOR_VERSION == 2) | ||||
| void SDL_UpdateRect(SDL_Surface *surface, int x, int y, int w, int h) | ||||
| { | ||||
| 	Rect rect(x,y,w,h); | ||||
| @@ -27,7 +26,6 @@ void SDL_UpdateRect(SDL_Surface *surface, int x, int y, int w, int h) | ||||
| 	SDL_RenderPresent(mainRenderer);	 | ||||
| 	 | ||||
| } | ||||
| #endif // VCMI_SDL1 | ||||
|  | ||||
| SDL_Surface * CSDL_Ext::newSurface(int w, int h, SDL_Surface * mod) //creates new surface, with flags/format same as in surface given | ||||
| { | ||||
| @@ -171,7 +169,7 @@ void CSDL_Ext::alphaTransform(SDL_Surface *src) | ||||
| 		SDL_Color & palColor = src->format->palette->colors[i]; | ||||
| 		palColor = colors[i]; | ||||
| 	} | ||||
| 	SDL_SetColorKey(src, SDL_SRCCOLORKEY, 0); | ||||
| 	SDL_SetColorKey(src, SDL_TRUE, 0); | ||||
| } | ||||
|  | ||||
| static void prepareOutRect(SDL_Rect *src, SDL_Rect *dst, const SDL_Rect & clip_rect) | ||||
| @@ -460,11 +458,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 | ||||
| 					#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); | ||||
| 					#endif // 0					 | ||||
| 				} | ||||
| 			} | ||||
| 			SDL_UnlockSurface(dst); | ||||
| @@ -489,11 +483,7 @@ int CSDL_Ext::blit8bppAlphaTo24bpp(const SDL_Surface * src, const SDL_Rect * src | ||||
| Uint32 CSDL_Ext::colorToUint32(const SDL_Color * color) | ||||
| { | ||||
| 	Uint32 ret = 0; | ||||
| 	#ifdef VCMI_SDL1 | ||||
| 	ret+=color->unused; | ||||
| 	#else | ||||
| 	ret+=color->a; | ||||
| 	#endif // 0	 | ||||
| 	ret<<=8; //*=256 | ||||
| 	ret+=color->b; | ||||
| 	ret<<=8; //*=256 | ||||
| @@ -505,15 +495,10 @@ Uint32 CSDL_Ext::colorToUint32(const SDL_Color * color) | ||||
|  | ||||
| void CSDL_Ext::update(SDL_Surface * what) | ||||
| { | ||||
| 	#ifdef VCMI_SDL1 | ||||
| 	if(what) | ||||
| 		SDL_UpdateRect(what, 0, 0, what->w, what->h);	 | ||||
| 	#else | ||||
| 	if(!what) | ||||
| 		return; | ||||
| 	if(0 !=SDL_UpdateTexture(screenTexture, nullptr, what->pixels, what->pitch)) | ||||
| 		logGlobal->errorStream() << __FUNCTION__ << "SDL_UpdateTexture " << SDL_GetError();		 | ||||
| 	#endif // VCMI_SDL1 | ||||
| } | ||||
| void CSDL_Ext::drawBorder(SDL_Surface * sur, int x, int y, int w, int h, const int3 &color) | ||||
| { | ||||
| @@ -633,21 +618,13 @@ bool CSDL_Ext::isTransparent( SDL_Surface * srf, int x, int y ) | ||||
|  | ||||
| 	SDL_Color color; | ||||
| 	 | ||||
| 	#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); | ||||
| 	#endif // 0	 | ||||
|  | ||||
| 	// color is considered transparent here if | ||||
| 	// a) image has aplha: less than 50% transparency | ||||
| 	// b) no alpha: color is cyan | ||||
| 	if (srf->format->Amask) | ||||
| 	#ifdef VCMI_SDL1 | ||||
| 		return color.unused < 128; // almost transparent | ||||
| 	#else | ||||
| 		return color.a < 128; // almost transparent | ||||
| 	#endif // 0				 | ||||
| 	else | ||||
| 		return (color.r == 0 && color.g == 255 && color.b == 255); | ||||
| } | ||||
| @@ -988,38 +965,30 @@ SDL_Color CSDL_Ext::makeColor(ui8 r, ui8 g, ui8 b, ui8 a) | ||||
|  | ||||
| void CSDL_Ext::startTextInput(SDL_Rect * where) | ||||
| { | ||||
| 	#ifndef VCMI_SDL1 | ||||
| 	if (SDL_IsTextInputActive() == SDL_FALSE)		 | ||||
| 	{		 | ||||
| 		SDL_StartTextInput();		 | ||||
| 	}		 | ||||
| 	SDL_SetTextInputRect(where); | ||||
| 	#endif | ||||
| } | ||||
|  | ||||
| void CSDL_Ext::stopTextInput() | ||||
| { | ||||
| 	#ifndef VCMI_SDL1 | ||||
| 	if (SDL_IsTextInputActive() == SDL_TRUE) | ||||
| 	{		 | ||||
| 		SDL_StopTextInput();			 | ||||
| 	}		 | ||||
| 	#endif	 | ||||
| } | ||||
|  | ||||
| STRONG_INLINE static uint32_t mapColor(SDL_Surface * surface, SDL_Color color) | ||||
| { | ||||
| 	#ifdef VCMI_SDL1 | ||||
| 	return SDL_MapRGB(surface->format, color.r, color.g, color.b);  | ||||
| 	#else | ||||
| 	return SDL_MapRGBA(surface->format, color.r, color.g, color.b, color.a);  | ||||
| 	#endif		 | ||||
| } | ||||
|  | ||||
| void CSDL_Ext::setColorKey(SDL_Surface * surface, SDL_Color color) | ||||
| { | ||||
| 	uint32_t key = mapColor(surface,color); | ||||
| 	SDL_SetColorKey(surface, SDL_SRCCOLORKEY, key);	 | ||||
| 	SDL_SetColorKey(surface, SDL_TRUE, key);	 | ||||
| } | ||||
|  | ||||
| void CSDL_Ext::setDefaultColorKey(SDL_Surface * surface) | ||||
| @@ -1034,7 +1003,7 @@ void CSDL_Ext::setDefaultColorKeyPresize(SDL_Surface * surface) | ||||
|  | ||||
| 	// set color key only if exactly such color was found | ||||
| 	if (color.r == Colors::DEFAULT_KEY_COLOR.r && color.g == Colors::DEFAULT_KEY_COLOR.g && color.b == Colors::DEFAULT_KEY_COLOR.b) | ||||
| 		SDL_SetColorKey(surface, SDL_SRCCOLORKEY, key);	 | ||||
| 		SDL_SetColorKey(surface, SDL_TRUE, key);	 | ||||
| } | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -10,15 +10,10 @@ | ||||
|   | ||||
| #pragma once | ||||
| #include <SDL_version.h> | ||||
|  | ||||
| #ifndef VCMI_SDL1 | ||||
| #include <SDL_render.h> | ||||
| #endif | ||||
|  | ||||
| #include <SDL_video.h> | ||||
| #include <SDL_events.h> | ||||
| #include "../../lib/int3.h" | ||||
| //#include "../Graphics.h" | ||||
| #include "Geometries.h" | ||||
| #include "../../lib/GameConstants.h" | ||||
|  | ||||
| @@ -32,13 +27,6 @@ | ||||
| 	#define STRONG_INLINE inline | ||||
| #endif | ||||
|  | ||||
| #if SDL_VERSION_ATLEAST(1,3,0) | ||||
| #define SDL_GetKeyState SDL_GetKeyboardState | ||||
| #endif | ||||
|  | ||||
| //SDL2 support | ||||
| #if (SDL_MAJOR_VERSION == 2) | ||||
|  | ||||
| extern SDL_Window * mainWindow; | ||||
| extern SDL_Renderer * mainRenderer; | ||||
| extern SDL_Texture * screenTexture; | ||||
| @@ -54,43 +42,27 @@ inline void SDL_WarpMouse(int x, int y) | ||||
| } | ||||
|  | ||||
| void SDL_UpdateRect(SDL_Surface *surface, int x, int y, int w, int h); | ||||
| #endif | ||||
|  | ||||
| inline bool isCtrlKeyDown() | ||||
| { | ||||
| 	#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 | ||||
| } | ||||
|  | ||||
| inline bool isAltKeyDown() | ||||
| { | ||||
| 	#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 | ||||
| } | ||||
|  | ||||
| inline bool isShiftKeyDown() | ||||
| { | ||||
| 	#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 | ||||
| } | ||||
| namespace CSDL_Ext | ||||
| { | ||||
| 	//todo: remove | ||||
| 	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) | ||||
| @@ -98,20 +70,12 @@ namespace CSDL_Ext | ||||
| 		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			 | ||||
| 	} | ||||
|  | ||||
| 	inline void setAlpha(SDL_Surface * bg, int value) | ||||
| 	{ | ||||
| #ifdef VCMI_SDL1 | ||||
| 		SDL_SetAlpha(bg, SDL_SRCALPHA, value); | ||||
| #else | ||||
| 		SDL_SetSurfaceAlphaMod(bg, value); | ||||
| #endif | ||||
| 	} | ||||
| } | ||||
| struct Rect; | ||||
|   | ||||
| @@ -135,11 +135,7 @@ struct ColorPutter<2, incrementPtr> | ||||
| template<int bpp, int incrementPtr> | ||||
| STRONG_INLINE void ColorPutter<bpp, incrementPtr>::PutColorAlpha(Uint8 *&ptr, const SDL_Color & Color) | ||||
| { | ||||
| 	#ifdef VCMI_SDL1 | ||||
| 	PutColor(ptr, Color.r, Color.g, Color.b, Color.unused); | ||||
| 	#else | ||||
| 	PutColor(ptr, Color.r, Color.g, Color.b, Color.a); | ||||
| 	#endif | ||||
| } | ||||
|  | ||||
| template<int bpp, int incrementPtr> | ||||
| @@ -268,11 +264,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) | ||||
| { | ||||
| 	#ifdef VCMI_SDL1 | ||||
| 	PutColor(ptr, Color.r, Color.g, Color.b, Color.unused); | ||||
| 	#else | ||||
| 	PutColor(ptr, Color.r, Color.g, Color.b, Color.a); | ||||
| 	#endif | ||||
| } | ||||
|  | ||||
| template <int incrementPtr> | ||||
|   | ||||
| @@ -1121,24 +1121,11 @@ void CInGameConsole::keyPressed (const SDL_KeyboardEvent & key) | ||||
| 		} | ||||
| 	default: | ||||
| 		{ | ||||
| 			#ifdef VCMI_SDL1 | ||||
| 			if(enteredText.size() > 0 && enteredText.size() < conf.go()->ac.inputLineLength) | ||||
| 			{ | ||||
| 				if( key.keysym.unicode < 0x80 && key.keysym.unicode > 0 ) | ||||
| 				{ | ||||
| 					enteredText[enteredText.size()-1] = (char)key.keysym.unicode; | ||||
| 					enteredText += "_"; | ||||
| 					refreshEnteredText(); | ||||
| 				} | ||||
| 			} | ||||
| 			#endif // VCMI_SDL1 | ||||
| 			break; | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| #ifndef VCMI_SDL1 | ||||
|  | ||||
| void CInGameConsole::textInputed(const SDL_TextInputEvent & event) | ||||
| { | ||||
| 	if(!captureAllKeys || enteredText.size() == 0) | ||||
| @@ -1156,8 +1143,6 @@ void CInGameConsole::textEdited(const SDL_TextEditingEvent & event) | ||||
|  //do nothing here | ||||
| } | ||||
|  | ||||
| #endif // VCMI_SDL1 | ||||
|  | ||||
| void CInGameConsole::startEnteringText() | ||||
| { | ||||
| 	CSDL_Ext::startTextInput(&pos); | ||||
| @@ -1219,14 +1204,9 @@ void CInGameConsole::refreshEnteredText() | ||||
|  | ||||
| CInGameConsole::CInGameConsole() : prevEntDisp(-1), defaultTimeout(10000), maxDisplayedTexts(10) | ||||
| { | ||||
| 	#ifdef VCMI_SDL1 | ||||
| 	addUsedEvents(KEYBOARD); | ||||
| 	#else | ||||
| 	addUsedEvents(KEYBOARD | TEXTINPUT); | ||||
| 	#endif | ||||
| } | ||||
|  | ||||
|  | ||||
| CAdvMapPanel::CAdvMapPanel(SDL_Surface * bg, Point position) | ||||
| 	: CIntObject(), | ||||
| 	  background(bg) | ||||
|   | ||||
| @@ -369,10 +369,8 @@ public: | ||||
| 	void print(const std::string &txt); | ||||
| 	void keyPressed (const SDL_KeyboardEvent & key); //call-in | ||||
|  | ||||
| #ifndef VCMI_SDL1 | ||||
| 	void textInputed(const SDL_TextInputEvent & event) override; | ||||
| 	void textEdited(const SDL_TextEditingEvent & event) override; | ||||
| #endif // VCMI_SDL1 | ||||
|  | ||||
| 	void startEnteringText(); | ||||
| 	void endEnteringText(bool printEnteredText); | ||||
|   | ||||
| @@ -295,13 +295,8 @@ void CButton::showAll(SDL_Surface * to) | ||||
| { | ||||
| 	CIntObject::showAll(to); | ||||
| 	 | ||||
| 	#ifdef VCMI_SDL1 | ||||
| 	if (borderColor && 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 | ||||
| 	if (borderColor && borderColor->a == 0) | ||||
| 		CSDL_Ext::drawBorder(to, pos.x-1, pos.y-1, pos.w+2, pos.h+2, int3(borderColor->r, borderColor->g, borderColor->b)); | ||||
| 	#endif // 0 | ||||
| } | ||||
|  | ||||
| std::pair<std::string, std::string> CButton::tooltip() | ||||
|   | ||||
| @@ -461,9 +461,7 @@ void CTextInput::keyPressed( const SDL_KeyboardEvent & key ) | ||||
| 	} | ||||
|  | ||||
| 	bool redrawNeeded = false; | ||||
| 	#ifdef VCMI_SDL1 | ||||
| 	std::string oldText = text; | ||||
| 	#endif // 0	 | ||||
| 	 | ||||
| 	switch(key.keysym.sym) | ||||
| 	{ | ||||
| 	case SDLK_DELETE: // have index > ' ' so it won't be filtered out by default section | ||||
| @@ -481,20 +479,9 @@ void CTextInput::keyPressed( const SDL_KeyboardEvent & key ) | ||||
| 		}			 | ||||
| 		break; | ||||
| 	default: | ||||
| 		#ifdef VCMI_SDL1 | ||||
| 		if (key.keysym.unicode < ' ') | ||||
| 			return; | ||||
| 		else | ||||
| 		{ | ||||
| 			text += key.keysym.unicode; //TODO 16-/>8 | ||||
| 			redrawNeeded = true; | ||||
| 		}			 | ||||
| 		#endif // 0 | ||||
| 		break; | ||||
| 	} | ||||
| 	#ifdef VCMI_SDL1 | ||||
| 	filters(text, oldText); | ||||
| 	#endif // 0 | ||||
|  | ||||
| 	if (redrawNeeded) | ||||
| 	{ | ||||
| 		redraw(); | ||||
| @@ -514,18 +501,9 @@ bool CTextInput::captureThisEvent(const SDL_KeyboardEvent & key) | ||||
| 	if(key.keysym.sym == SDLK_RETURN || key.keysym.sym == SDLK_KP_ENTER) | ||||
| 		return false; | ||||
| 	 | ||||
| 	#ifdef VCMI_SDL1 | ||||
| 	//this should allow all non-printable keys to go through (for example arrows) | ||||
| 	if (key.keysym.unicode < ' ') | ||||
| 		return false; | ||||
|  | ||||
| 	return true; | ||||
| 	#else | ||||
| 	return false; | ||||
| 	#endif | ||||
| } | ||||
|  | ||||
| #ifndef VCMI_SDL1 | ||||
| void CTextInput::textInputed(const SDL_TextInputEvent & event) | ||||
| { | ||||
| 	if(!focus) | ||||
| @@ -553,9 +531,6 @@ void CTextInput::textEdited(const SDL_TextEditingEvent & event) | ||||
| 	cb(text+newText);	 | ||||
| } | ||||
|  | ||||
| #endif | ||||
|  | ||||
|  | ||||
| void CTextInput::filenameFilter(std::string & text, const std::string &) | ||||
| { | ||||
| 	static const std::string forbiddenChars = "<>:\"/\\|?*\r\n"; //if we are entering a filename, some special characters won't be allowed | ||||
|   | ||||
| @@ -174,12 +174,8 @@ public: | ||||
| 	void keyPressed(const SDL_KeyboardEvent & key) override; | ||||
| 	bool captureThisEvent(const SDL_KeyboardEvent & key) override; | ||||
| 	 | ||||
| #ifndef VCMI_SDL1 | ||||
| 	void textInputed(const SDL_TextInputEvent & event) override; | ||||
| 	void textEdited(const SDL_TextEditingEvent & event) override; | ||||
| 	 | ||||
| 	 | ||||
| #endif // VCMI_SDL1	 | ||||
|  | ||||
| 	//Filter that will block all characters not allowed in filenames | ||||
| 	static void filenameFilter(std::string &text, const std::string & oldText); | ||||
|   | ||||
| @@ -1029,7 +1029,7 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key) | ||||
| 		return; | ||||
|  | ||||
| 	ui8 Dir = 0; | ||||
| 	int k = key.keysym.sym; | ||||
| 	SDL_Keycode k = key.keysym.sym; | ||||
| 	const CGHeroInstance *h = curHero(); //selected hero | ||||
| 	const CGTownInstance *t = curTown(); //selected town | ||||
|  | ||||
| @@ -1156,17 +1156,14 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key) | ||||
| 												int3(-1, -1, 0), int3(0, -1, 0), int3(+1, -1, 0) }; | ||||
|  | ||||
| 			//numpad arrow | ||||
| 			if(CGuiHandler::isArrowKey(SDLKey(k))) | ||||
| 				k = CGuiHandler::arrowToNum(SDLKey(k)); | ||||
| 			if(CGuiHandler::isArrowKey(k)) | ||||
| 				k = CGuiHandler::arrowToNum(k); | ||||
|  | ||||
| 			#ifdef VCMI_SDL1 | ||||
| 			k -= SDLK_KP0 + 1; | ||||
| 			#else | ||||
| 			k -= SDLK_KP_1; | ||||
| 			#endif // VCMI_SDL1 | ||||
|  | ||||
| 			if(k < 0 || k > 8) | ||||
| 				return; | ||||
| 			 | ||||
|  | ||||
| 			if (!CGI->mh->canStartHeroMovement()) | ||||
| 				return; | ||||
|  | ||||
|   | ||||
| @@ -571,7 +571,7 @@ void CSpellWindow::keyPressed(const SDL_KeyboardEvent & key) | ||||
| 		//alt + 1234567890-= casts spell from 1 - 12 slot | ||||
| 		if(LOCPLINT->altPressed()) | ||||
| 		{ | ||||
| 			SDLKey hlpKey = key.keysym.sym; | ||||
| 			SDL_Keycode hlpKey = key.keysym.sym; | ||||
| 			if(CGuiHandler::isNumKey(hlpKey, false)) | ||||
| 			{ | ||||
| 				if(hlpKey == SDLK_KP_PLUS) | ||||
| @@ -580,7 +580,7 @@ void CSpellWindow::keyPressed(const SDL_KeyboardEvent & key) | ||||
| 					hlpKey = CGuiHandler::numToDigit(hlpKey); | ||||
| 			} | ||||
|  | ||||
| 			static const SDLKey spellSelectors[] = {SDLK_1, SDLK_2, SDLK_3, SDLK_4, SDLK_5, SDLK_6, SDLK_7, SDLK_8, SDLK_9, SDLK_0, SDLK_MINUS, SDLK_EQUALS}; | ||||
| 			static const SDL_Keycode spellSelectors[] = {SDLK_1, SDLK_2, SDLK_3, SDLK_4, SDLK_5, SDLK_6, SDLK_7, SDLK_8, SDLK_9, SDLK_0, SDLK_MINUS, SDLK_EQUALS}; | ||||
|  | ||||
| 			int index = -1; | ||||
| 			while(++index < ARRAY_COUNT(spellSelectors) && spellSelectors[index] != hlpKey); | ||||
|   | ||||
| @@ -1089,9 +1089,7 @@ CPuzzleWindow::CPuzzleWindow(const int3 &GrailPos, double discoveredRatio): | ||||
| 			piecesToRemove.push_back(piece); | ||||
| 			piece->needRefresh = true; | ||||
| 			piece->recActions = piece->recActions & ~SHOWALL; | ||||
| 			#ifndef VCMI_SDL1 | ||||
| 			SDL_SetSurfaceBlendMode(piece->bg,SDL_BLENDMODE_BLEND); | ||||
| 			#endif // VCMI_SDL1 | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -42,41 +42,6 @@ | ||||
| 					<Add directory="$(#sdl2.lib)" /> | ||||
| 				</Linker> | ||||
| 			</Target> | ||||
| 			<Target title="Debug-win32-SDL1"> | ||||
| 				<Option platforms="Windows;" /> | ||||
| 				<Option output="../VCMI_lib" prefix_auto="0" extension_auto="1" /> | ||||
| 				<Option object_output="../obj/Debug/Lib" /> | ||||
| 				<Option type="3" /> | ||||
| 				<Option compiler="gcc" /> | ||||
| 				<Option host_application="D:/projects/vcmi/engine/VCMI_client.exe" /> | ||||
| 				<Option run_host_application_in_terminal="1" /> | ||||
| 				<Option createStaticLib="1" /> | ||||
| 				<Compiler> | ||||
| 					<Add option="-Og" /> | ||||
| 					<Add option="-g" /> | ||||
| 					<Add directory="$(#sdl.include)" /> | ||||
| 				</Compiler> | ||||
| 				<Linker> | ||||
| 					<Add directory="$(#sdl.lib)" /> | ||||
| 				</Linker> | ||||
| 			</Target> | ||||
| 			<Target title="Release-win32-SDL1"> | ||||
| 				<Option platforms="Windows;" /> | ||||
| 				<Option output="../VCMI_lib" prefix_auto="0" extension_auto="1" /> | ||||
| 				<Option object_output="../obj/Release/Lib" /> | ||||
| 				<Option type="3" /> | ||||
| 				<Option compiler="gcc" /> | ||||
| 				<Option createStaticLib="1" /> | ||||
| 				<Compiler> | ||||
| 					<Add option="-fomit-frame-pointer" /> | ||||
| 					<Add option="-O2" /> | ||||
| 					<Add directory="$(#sdl.include)" /> | ||||
| 				</Compiler> | ||||
| 				<Linker> | ||||
| 					<Add option="-s" /> | ||||
| 					<Add directory="$(#sdl.lib)" /> | ||||
| 				</Linker> | ||||
| 			</Target> | ||||
| 		</Build> | ||||
| 		<Compiler> | ||||
| 			<Add option="-Wextra" /> | ||||
|   | ||||
| @@ -35,35 +35,6 @@ | ||||
| 					<Add option="-s" /> | ||||
| 				</Linker> | ||||
| 			</Target> | ||||
| 			<Target title="Debug-win32-SDL1"> | ||||
| 				<Option platforms="Windows;" /> | ||||
| 				<Option output="../../minizip" prefix_auto="1" extension_auto="1" /> | ||||
| 				<Option object_output="obj/Debug/" /> | ||||
| 				<Option type="3" /> | ||||
| 				<Option compiler="gcc" /> | ||||
| 				<Option createStaticLib="1" /> | ||||
| 				<Compiler> | ||||
| 					<Add option="-Wall" /> | ||||
| 					<Add option="-g" /> | ||||
| 					<Add option="-DBUILD_DLL" /> | ||||
| 				</Compiler> | ||||
| 			</Target> | ||||
| 			<Target title="Release-win32-SDL1"> | ||||
| 				<Option platforms="Windows;" /> | ||||
| 				<Option output="../../minizip" prefix_auto="1" extension_auto="1" /> | ||||
| 				<Option object_output="obj/Release/" /> | ||||
| 				<Option type="3" /> | ||||
| 				<Option compiler="gcc" /> | ||||
| 				<Option createStaticLib="1" /> | ||||
| 				<Compiler> | ||||
| 					<Add option="-O2" /> | ||||
| 					<Add option="-Wall" /> | ||||
| 					<Add option="-DBUILD_DLL" /> | ||||
| 				</Compiler> | ||||
| 				<Linker> | ||||
| 					<Add option="-s" /> | ||||
| 				</Linker> | ||||
| 			</Target> | ||||
| 		</Build> | ||||
| 		<Compiler> | ||||
| 			<Add directory="$(#zlib.include)" /> | ||||
|   | ||||
| @@ -35,35 +35,6 @@ | ||||
| 					<Add option="-s" /> | ||||
| 				</Linker> | ||||
| 			</Target> | ||||
| 			<Target title="Debug-win32-SDL1"> | ||||
| 				<Option platforms="Windows;" /> | ||||
| 				<Option output="../VCMI_server" prefix_auto="1" extension_auto="1" /> | ||||
| 				<Option object_output="../obj/Debug/Server" /> | ||||
| 				<Option type="1" /> | ||||
| 				<Option compiler="gcc" /> | ||||
| 				<Option use_console_runner="0" /> | ||||
| 				<Compiler> | ||||
| 					<Add option="-Og" /> | ||||
| 					<Add option="-ggdb" /> | ||||
| 					<Add directory="$(#sdl.include)" /> | ||||
| 				</Compiler> | ||||
| 			</Target> | ||||
| 			<Target title="Release-win32-SDL1"> | ||||
| 				<Option platforms="Windows;" /> | ||||
| 				<Option output="../VCMI_server" prefix_auto="1" extension_auto="1" /> | ||||
| 				<Option object_output="../obj/Release/Server" /> | ||||
| 				<Option type="1" /> | ||||
| 				<Option compiler="gcc" /> | ||||
| 				<Option use_console_runner="0" /> | ||||
| 				<Compiler> | ||||
| 					<Add option="-fomit-frame-pointer" /> | ||||
| 					<Add option="-O2" /> | ||||
| 					<Add directory="$(#sdl.include)" /> | ||||
| 				</Compiler> | ||||
| 				<Linker> | ||||
| 					<Add option="-s" /> | ||||
| 				</Linker> | ||||
| 			</Target> | ||||
| 		</Build> | ||||
| 		<Compiler> | ||||
| 			<Add option="-Wextra" /> | ||||
|   | ||||
| @@ -18,18 +18,6 @@ | ||||
| 					<Add option="-g" /> | ||||
| 				</Compiler> | ||||
| 			</Target> | ||||
| 			<Target title="Debug-win32-SDL1"> | ||||
| 				<Option platforms="Windows;" /> | ||||
| 				<Option output="../Test" prefix_auto="1" extension_auto="1" /> | ||||
| 				<Option object_output="obj/Debug/" /> | ||||
| 				<Option type="1" /> | ||||
| 				<Option compiler="gcc" /> | ||||
| 				<Compiler> | ||||
| 					<Add option="-march=athlon-xp" /> | ||||
| 					<Add option="-Wextra" /> | ||||
| 					<Add option="-g" /> | ||||
| 				</Compiler> | ||||
| 			</Target> | ||||
| 		</Build> | ||||
| 		<Compiler> | ||||
| 			<Add option="-Wall" /> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user