1Index: buildings.cpp
2===================================================================
3--- buildings.cpp	(revision 3442)
4+++ buildings.cpp	(working copy)
5@@ -277,7 +277,6 @@
6 //--------------------------------------------------------------------------
7 void cBuilding::draw (SDL_Rect* screenPos, cGameGUI& gameGUI)
8 {
9-	SDL_Rect dest, tmp;
10 	float factor = (float) gameGUI.getTileSize() / 64.0f;
11 	cPlayer* activePlayer = gameGUI.getClient()->getActivePlayer();
12 	// draw the damage effects
13@@ -296,7 +295,7 @@
14 		}
15 	}
16
17-	dest.x = dest.y = 0;
18+	SDL_Rect dest = {0, 0, 0, 0};
19 	bool bDraw = false;
20 	SDL_Surface* drawingSurface = gameGUI.getDCache()->getCachedImage (*this);
21 	if (drawingSurface == NULL)
22@@ -342,8 +341,8 @@
23 	// draw the effect if necessary
24 	if (data.powerOnGraphic && cSettings::getInstance().isAnimations() && (IsWorking || !data.canWork))
25 	{
26-		tmp = dest;
27-		SDL_SetAlpha (uiData->eff, SDL_SRCALPHA, EffectAlpha);
28+		SDL_Rect tmp = dest;
29+		SDL_SetSurfaceAlphaMod (uiData->eff, EffectAlpha);
30
31 		CHECK_SCALING (uiData->eff, uiData->eff_org, factor);
32 		SDL_BlitSurface (uiData->eff, NULL, buffer, &tmp);
33@@ -356,7 +355,7 @@
34
35 				if (EffectAlpha > 220)
36 				{
37-					EffectAlpha = 255;
38+					EffectAlpha = 254;
39 					EffectInc = false;
40 				}
41 			}
42@@ -376,7 +375,7 @@
43 	// draw the mark, when a build order is finished
44 	if ( ( (!BuildList.empty() && !IsWorking && BuildList[0].metall_remaining <= 0) || (data.canResearch && owner->researchFinished)) && owner == gameGUI.getClient()->getActivePlayer())
45 	{
46-		const Uint32 color = 0xFF00 - (0x1000 * (gameGUI.getAnimationSpeed() % 0x8));
47+		const Uint32 color = 0xFF00FF00 - (0x1000 * (gameGUI.getAnimationSpeed() % 0x8));
48 		const Uint16 max = data.isBig ? 2 * gameGUI.getTileSize() - 3 : gameGUI.getTileSize() - 3;
49 		SDL_Rect d = {Sint16 (dest.x + 2), Sint16 (dest.y + 2), max, max};
50
51@@ -392,7 +391,7 @@
52 	// draw a colored frame if necessary
53 	if (gameGUI.colorChecked())
54 	{
55-		const Uint32 color = *static_cast<Uint32*> (owner->getColorSurface()->pixels);
56+		const Uint32 color = 0xFF000000 | *static_cast<Uint32*> (owner->getColorSurface()->pixels);
57 		const Uint16 max = data.isBig ? 2 * gameGUI.getTileSize() - 1 : gameGUI.getTileSize() - 1;
58 		SDL_Rect d = {Sint16 (dest.x + 1), Sint16 (dest.y + 1), max, max};
59
60@@ -406,7 +405,7 @@
61 		const int len = max / 4;
62 		max -= 3;
63 		SDL_Rect d = {Sint16 (dest.x + 2), Sint16 (dest.y + 2), max, max};
64-		DrawSelectionCorner(buffer, d, len, gameGUI.getBlinkColor());
65+		DrawSelectionCorner(buffer, d, len, 0xFF000000 | gameGUI.getBlinkColor());
66 	}
67
68 	// draw health bar
69@@ -493,9 +492,9 @@
70 		CHECK_SCALING (GraphicsData.gfx_big_beton, GraphicsData.gfx_big_beton_org, zoomFactor);
71
72 		if (StartUp && cSettings::getInstance().isAlphaEffects())
73-			SDL_SetAlpha (GraphicsData.gfx_big_beton, SDL_SRCALPHA, StartUp);
74+			SDL_SetSurfaceAlphaMod (GraphicsData.gfx_big_beton, StartUp);
75 		else
76-			SDL_SetAlpha (GraphicsData.gfx_big_beton, SDL_SRCALPHA, 255);
77+			SDL_SetSurfaceAlphaMod (GraphicsData.gfx_big_beton, 254);
78
79 		SDL_BlitSurface (GraphicsData.gfx_big_beton, NULL, surface, &tmp);
80 	}
81@@ -503,12 +502,12 @@
82 	{
83 		CHECK_SCALING (UnitsData.ptr_small_beton, UnitsData.ptr_small_beton_org, zoomFactor);
84 		if (StartUp && cSettings::getInstance().isAlphaEffects())
85-			SDL_SetAlpha (UnitsData.ptr_small_beton, SDL_SRCALPHA, StartUp);
86+			SDL_SetSurfaceAlphaMod (UnitsData.ptr_small_beton, StartUp);
87 		else
88-			SDL_SetAlpha (UnitsData.ptr_small_beton, SDL_SRCALPHA, 255);
89+			SDL_SetSurfaceAlphaMod (UnitsData.ptr_small_beton, 254);
90
91 		SDL_BlitSurface (UnitsData.ptr_small_beton, NULL, surface, &tmp);
92-		SDL_SetAlpha (UnitsData.ptr_small_beton, SDL_SRCALPHA, 255);
93+		SDL_SetSurfaceAlphaMod (UnitsData.ptr_small_beton, 254);
94 	}
95 }
96
97@@ -531,7 +530,7 @@
98
99 	// blit the players color and building graphic
100 	if (data.hasPlayerColor) SDL_BlitSurface (owner->getColorSurface(), NULL, GraphicsData.gfx_tmp, NULL);
101-	else SDL_FillRect (GraphicsData.gfx_tmp, NULL, 0x00FF00FF);
102+	else SDL_FillRect (GraphicsData.gfx_tmp, NULL, 0xFFFF00FF);
103
104 	if (data.hasFrames)
105 	{
106@@ -566,7 +565,7 @@
107 	src.x = 0;
108 	src.y = 0;
109
110-	SDL_SetAlpha (GraphicsData.gfx_tmp, SDL_SRCALPHA, alpha);
111+	SDL_SetSurfaceAlphaMod (GraphicsData.gfx_tmp, alpha);
112 	SDL_BlitSurface (GraphicsData.gfx_tmp, &src, surface, &tmp);
113 }
114
115@@ -588,7 +587,6 @@
116 	{
117 		render_beton (surface, dest, zoomFactor);
118 	}
119-
120 	// draw the connector slots:
121 	if ( (this->SubBase && !StartUp) || data.isConnectorGraphic)
122 	{
123@@ -601,9 +599,9 @@
124 	{
125 		SDL_Rect tmp = dest;
126 		if (StartUp && cSettings::getInstance().isAlphaEffects())
127-			SDL_SetAlpha (uiData->shw, SDL_SRCALPHA, StartUp / 5);
128+			SDL_SetSurfaceAlphaMod (uiData->shw, StartUp / 5);
129 		else
130-			SDL_SetAlpha (uiData->shw, SDL_SRCALPHA, 50);
131+			SDL_SetSurfaceAlphaMod (uiData->shw, 50);
132
133 		CHECK_SCALING (uiData->shw, uiData->shw_org, zoomFactor);
134 		blittAlphaSurface (uiData->shw, NULL, surface, &tmp);
135@@ -616,7 +614,7 @@
136 		frameNr = (gameGUI->getAnimationSpeed() % data.hasFrames);
137 	}
138
139-	int alpha = 255;
140+	int alpha = 254;
141 	if (StartUp && cSettings::getInstance().isAlphaEffects()) alpha = StartUp;
142 	render_simple (surface, dest, zoomFactor, frameNr, alpha);
143 }
144@@ -668,7 +666,6 @@
145 	}
146 	else
147 	{
148-
149 		CHECK_NEIGHBOUR (PosX    , PosY - 1, BaseN)
150 		CHECK_NEIGHBOUR (PosX + 1, PosY - 1, BaseBN)
151 		CHECK_NEIGHBOUR (PosX + 2, PosY    , BaseE)
152@@ -690,8 +687,8 @@
153 	CHECK_SCALING (UnitsData.ptr_connector, UnitsData.ptr_connector_org, zoomFactor);
154 	CHECK_SCALING (UnitsData.ptr_connector_shw, UnitsData.ptr_connector_shw_org, zoomFactor);
155
156-	if (StartUp) SDL_SetAlpha (UnitsData.ptr_connector, SDL_SRCALPHA, StartUp);
157-	else SDL_SetAlpha (UnitsData.ptr_connector, SDL_SRCALPHA, 255);
158+	if (StartUp) SDL_SetSurfaceAlphaMod (UnitsData.ptr_connector, StartUp);
159+	else SDL_SetSurfaceAlphaMod (UnitsData.ptr_connector, 254);
160
161 	src.y = 0;
162 	src.x = 0;
163@@ -1346,6 +1343,7 @@
164 	dest.x = x;
165 	dest.y = y;
166
167+	Uint32 color = SDL_MapRGB (sf->format, 0xFC, 0, 0);
168 	for (int i = 0; i < value; i++)
169 	{
170 		if (i == orgvalue)
171@@ -1356,7 +1354,7 @@
172 			mark.y = dest.y;
173 			mark.w = 1;
174 			mark.h = src.h;
175-			SDL_FillRect (sf, &mark, 0xFC0000);
176+			SDL_FillRect (sf, &mark, color);
177 		}
178
179 		SDL_BlitSurface (GraphicsData.gfx_hud_stuff, &src, sf, &dest);
180Index: buildings.h
181===================================================================
182--- buildings.h	(revision 3442)
183+++ buildings.h	(working copy)
184@@ -220,7 +220,7 @@
185 	* draws the main image of the building onto the given surface
186 	*/
187 	void render (const cGameGUI* gameGUI, SDL_Surface* surface, const SDL_Rect& dest, float zoomFactor, bool drawShadow, bool drawConcrete);
188-	void render_simple (SDL_Surface* surface, const SDL_Rect& dest, float zoomFactor, int frameNr, int alpha = 255);
189+	void render_simple (SDL_Surface* surface, const SDL_Rect& dest, float zoomFactor, int frameNr, int alpha = 254);
190
191 	void executeUpdateBuildingCommmand (const cClient& client, bool updateAllOfSameType);
192 	void executeSelfDestroyCommand (cClient& client);
193Index: client.cpp
194===================================================================
195--- client.cpp	(revision 3442)
196+++ client.cpp	(working copy)
197@@ -2005,7 +2005,7 @@
198 #endif
199 	// reset the screen
200 	gameGUI->deselectUnit();
201-	SDL_Surface* sf = SDL_CreateRGBSurface (SDL_SRCCOLORKEY, Video.getResolutionX(), Video.getResolutionY(), 32, 0, 0, 0, 0);
202+	SDL_Surface* sf = SDL_CreateRGBSurface (0, Video.getResolutionX(), Video.getResolutionY(), 32, 0, 0, 0, 0);
203 	SDL_Rect scr = { 15, 356, 112u, 112u};
204 	SDL_BlitSurface (sf, NULL, buffer, NULL);
205 	SDL_BlitSurface (sf, &scr, buffer, &scr);
206Index: defines.h
207===================================================================
208--- defines.h	(revision 3446)
209+++ defines.h	(working copy)
210@@ -20,12 +20,12 @@
211 #define definesH
212 #include "settings.h"
213
214-#define GRID_COLOR         0x00305C04 // color of the grid
215-#define SCAN_COLOR         0x00E3E300 // color of scan circles
216-#define RANGE_GROUND_COLOR 0x00E20000 // color of range circles for ground attack
217-#define RANGE_AIR_COLOR    0x00FCA800 // color of range circles for air attack
218-#define PFEIL_COLOR        0x000000FF // color of a waypointarrow
219-#define PFEILS_COLOR       0x0000FF00 // color of a special waypointarrow
220+#define GRID_COLOR         0xFF305C04 // color of the grid
221+#define SCAN_COLOR         0xFFE3E300 // color of scan circles
222+#define RANGE_GROUND_COLOR 0xFFE20000 // color of range circles for ground attack
223+#define RANGE_AIR_COLOR    0xFFFCA800 // color of range circles for air attack
224+#define PFEIL_COLOR        0xFF0000FF // color of a waypointarrow
225+#define PFEILS_COLOR       0xFF00FF00 // color of a special waypointarrow
226 #define MOVE_SPEED 2     // speed of vehiclemovements
227 #define MSG_TICKS  30000 // number of ticks for how long a message will be displayed
228 #define LANDING_DISTANCE_WARNING   28
229@@ -33,7 +33,7 @@
230 #define MAX_PLANES_PER_FIELD 5
231
232 // minimap configuration
233-#define MINIMAP_COLOR 0x00FC0000 // color of the screen borders on the minimap
234+#define MINIMAP_COLOR 0xFFFC0000 // color of the screen borders on the minimap
235 #define MINIMAP_POS_X 15         // the position of the map on the screen
236 #define MINIMAP_POS_Y 356        // the position of the map on the screen
237 #define MINIMAP_SIZE  112        // the size of the minimap in pixels
238Index: dialog.cpp
239===================================================================
240--- dialog.cpp	(revision 3442)
241+++ dialog.cpp	(working copy)
242@@ -71,7 +71,7 @@
243 	menuItems.push_back (&noButton);
244 }
245
246-void cDialogYesNo::handleKeyInput (SDL_KeyboardEvent& key, const string& ch)
247+void cDialogYesNo::handleKeyInput (const SDL_KeyboardEvent& key)
248 {
249 	switch (key.keysym.sym)
250 	{
251@@ -106,7 +106,7 @@
252 	menuItems.push_back (&okButton);
253 }
254
255-void cDialogOK::handleKeyInput (SDL_KeyboardEvent& key, const string& ch)
256+void cDialogOK::handleKeyInput (const SDL_KeyboardEvent& key)
257 {
258 	if (key.keysym.sym == SDLK_RETURN)
259 	{
260@@ -248,7 +248,7 @@
261 	draw();
262 }
263
264-void cDialogLicence::handleKeyInput (SDL_KeyboardEvent& key, const string& ch)
265+void cDialogLicence::handleKeyInput (const SDL_KeyboardEvent& key)
266 {
267 	if (key.keysym.sym == SDLK_RETURN)
268 	{
269@@ -632,13 +632,13 @@
270 {
271 	const int UNIT_IMAGE_SIZE = 64;
272
273-	SDL_Surface* unitImage1 = SDL_CreateRGBSurface (SDL_SRCCOLORKEY, UNIT_IMAGE_SIZE, UNIT_IMAGE_SIZE, Video.getColDepth(), 0, 0, 0, 0);
274+	SDL_Surface* unitImage1 = SDL_CreateRGBSurface (0, UNIT_IMAGE_SIZE, UNIT_IMAGE_SIZE, Video.getColDepth(), 0, 0, 0, 0);
275 	SDL_FillRect (unitImage1, NULL, 0xFF00FF);
276-	SDL_SetColorKey (unitImage1, SDL_SRCCOLORKEY, 0xFF00FF);
277+	SDL_SetColorKey (unitImage1, SDL_TRUE, 0xFF00FF);
278
279-	SDL_Surface* unitImage2 = SDL_CreateRGBSurface (SDL_SRCCOLORKEY, UNIT_IMAGE_SIZE, UNIT_IMAGE_SIZE, Video.getColDepth(), 0, 0, 0, 0);
280+	SDL_Surface* unitImage2 = SDL_CreateRGBSurface (0, UNIT_IMAGE_SIZE, UNIT_IMAGE_SIZE, Video.getColDepth(), 0, 0, 0, 0);
281 	SDL_FillRect (unitImage2, NULL, 0xFF00FF);
282-	SDL_SetColorKey (unitImage2, SDL_SRCCOLORKEY, 0xFF00FF);
283+	SDL_SetColorKey (unitImage2, SDL_TRUE, 0xFF00FF);
284
285 	SDL_Rect dest = {0, 0, 0, 0};
286
287@@ -777,7 +777,7 @@
288 		// little hack: flip part of the image that represent the arrow
289 		const unsigned int w = 40;
290 		const unsigned int h = 20;
291-		SDL_Surface* arrowSurface = SDL_CreateRGBSurface (Video.getSurfaceType(), w, h, Video.getColDepth(), 0, 0, 0, 0);
292+		SDL_Surface* arrowSurface = SDL_CreateRGBSurface (0, w, h, Video.getColDepth(), 0, 0, 0, 0);
293 		const Sint16 x = arrowImage.getPosition().x - position.x; // 140
294 		const Sint16 y = arrowImage.getPosition().y - position.y; //  77
295 		SDL_Rect src = {x, y, w, h};
296@@ -791,7 +791,7 @@
297 	resBar->setCurrentValue ( (int) (223.f * (destCargo + transferValue) / maxDestCargo));
298 }
299
300-void cDialogTransfer::handleKeyInput (SDL_KeyboardEvent& key, const string& ch)
301+void cDialogTransfer::handleKeyInput (const SDL_KeyboardEvent& key)
302 {
303 	switch (key.keysym.sym)
304 	{
305@@ -994,7 +994,7 @@
306 	}
307 }
308
309-void cDialogResearch::handleKeyInput (SDL_KeyboardEvent& key, const string& ch)
310+void cDialogResearch::handleKeyInput (const SDL_KeyboardEvent& key)
311 {
312 	switch (key.keysym.sym)
313 	{
314Index: dialog.h
315===================================================================
316--- dialog.h	(revision 3442)
317+++ dialog.h	(working copy)
318@@ -32,7 +32,7 @@
319 	explicit cDialogYesNo (const std::string& text);
320
321 private:
322-	virtual void handleKeyInput (SDL_KeyboardEvent& key, const std::string& ch);
323+	virtual void handleKeyInput (const SDL_KeyboardEvent& key);
324
325 private:
326 	cMenuLabel textLabel;
327@@ -49,7 +49,7 @@
328 	explicit cDialogOK (const std::string& text);
329
330 private:
331-	virtual void handleKeyInput (SDL_KeyboardEvent& key, const std::string& ch);
332+	virtual void handleKeyInput (const SDL_KeyboardEvent& key);
333
334 private:
335 	cMenuLabel textLabel;
336@@ -80,7 +80,7 @@
337 	cDialogLicence();
338
339 private:
340-	virtual void handleKeyInput (SDL_KeyboardEvent& key, const std::string& ch);
341+	virtual void handleKeyInput (const SDL_KeyboardEvent& key);
342
343 private:
344 	static void upReleased (void* parent);
345@@ -201,7 +201,7 @@
346 	~cDialogTransfer();
347
348 private:
349-	virtual void handleKeyInput (SDL_KeyboardEvent& key, const std::string& ch);
350+	virtual void handleKeyInput (const SDL_KeyboardEvent& key);
351 	virtual void handleDestroyUnit (cUnit& destroyedUnit);
352
353 private:
354@@ -244,7 +244,7 @@
355 	explicit cDialogResearch (cClient& client_);
356
357 private:
358-	virtual void handleKeyInput (SDL_KeyboardEvent& key, const std::string& ch);
359+	virtual void handleKeyInput (const SDL_KeyboardEvent& key);
360 	virtual void handleDestroyUnit (cUnit& destroyedUnit);
361
362 private:
363Index: drawingcache.cpp
364===================================================================
365--- drawingcache.cpp	(revision 3442)
366+++ drawingcache.cpp	(working copy)
367@@ -77,10 +77,10 @@
368 		width  = 130;
369 		height = 130;
370 	}
371-	surface = SDL_CreateRGBSurface (SDL_SWSURFACE, width, height, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
372+	surface = SDL_CreateRGBSurface (0, width, height, 32,
373+									0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
374
375-	SDL_FillRect (surface, NULL, SDL_MapRGBA (surface->format, 255, 0, 255, 0));
376-	SDL_SetColorKey (surface, SDL_SRCCOLORKEY | SDL_RLEACCEL, SDL_MapRGBA (surface->format, 255, 0, 255, 0));
377+	SDL_FillRect (surface, NULL, SDL_MapRGBA (surface->format, 0, 0, 0, 0));
378 }
379
380 void sDrawingCacheEntry::init (const cGameGUI& gameGUI, const cBuilding& building)
381@@ -106,10 +106,10 @@
382 	int width  = (int) std::max (building.uiData->img_org->w * zoom, building.uiData->shw_org->w * zoom);
383 	if (building.data.hasFrames) width = (int) (building.uiData->shw_org->w * zoom);
384
385-	surface = SDL_CreateRGBSurface (SDL_SWSURFACE, width, height, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
386+	surface = SDL_CreateRGBSurface (0, width, height, 32,
387+									0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
388
389-	SDL_FillRect (surface, NULL, SDL_MapRGBA (surface->format, 255, 0, 255, 0));
390-	SDL_SetColorKey (surface, SDL_SRCCOLORKEY | SDL_RLEACCEL, SDL_MapRGBA (surface->format, 255, 0, 255, 0));
391+	SDL_FillRect (surface, NULL, SDL_MapRGBA (surface->format, 0, 0, 0, 0));
392 }
393
394 cDrawingCache::cDrawingCache()
395@@ -346,7 +346,7 @@
396 		return false;
397 	}
398
399-	if (vehicle.IsBuilding && vehicle.data.isBig && vehicle.BigBetonAlpha < 255)
400+	if (vehicle.IsBuilding && vehicle.data.isBig && vehicle.BigBetonAlpha < 254u)
401 	{
402 		notCached++;
403 		return false;
404Index: events.cpp
405===================================================================
406--- events.cpp	(revision 3442)
407+++ events.cpp	(working copy)
408@@ -60,17 +60,6 @@
409 	return screenshotfile;
410 }
411
412-static void HandleInputEvent_SDL_ACTIVEEVENT (SDL_Event& event)
413-{
414-	assert (event.type == SDL_ACTIVEEVENT);
415-#if 1
416-	// This is an workaround for a SDL bug.
417-	// See Ticket #86 on bugtracker.
418-	// will hopefully not be required anymore in SDL 1.3
419-	if (event.active.state & SDL_APPINPUTFOCUS) SDL_SetModState (KMOD_NONE);
420-#endif
421-}
422-
423 static void HandleInputEvent_KEY (cMenu& activeMenu, SDL_Event& event, cClient* client)
424 {
425 	assert (event.type == SDL_KEYDOWN || event.type == SDL_KEYUP);
426@@ -96,12 +85,14 @@
427 {
428 	switch (event.type)
429 	{
430-		case SDL_ACTIVEEVENT: HandleInputEvent_SDL_ACTIVEEVENT (event); break;
431 		case SDL_KEYDOWN:
432 		case SDL_KEYUP: HandleInputEvent_KEY (activeMenu, event, client); break;
433 		case SDL_MOUSEBUTTONDOWN:
434 		case SDL_MOUSEBUTTONUP: InputHandler->inputMouseButton (activeMenu, event.button); break;
435+		case SDL_MOUSEWHEEL: InputHandler->inputMouseButton (activeMenu, event.wheel); break;
436 		case SDL_QUIT: Quit(); break;
437+		case SDL_MOUSEMOTION: break;
438+		case SDL_WINDOWEVENT: Video.draw(); break;
439 		default: break;
440 	}
441 }
442Index: fxeffects.cpp
443===================================================================
444--- fxeffects.cpp	(revision 3442)
445+++ fxeffects.cpp	(working copy)
446@@ -293,7 +293,7 @@
447 	CHECK_SCALING (images[1], images[0], gameGUI.getZoom());
448
449 	const int alpha = (alphaEnd - alphaStart) * tick / length + alphaStart;
450-	SDL_SetAlpha (images[1], SDL_SRCALPHA, alpha);
451+	SDL_SetSurfaceAlphaMod (images[1], alpha);
452
453 	SDL_Rect dest;
454 	dest = gameGUI.calcScreenPos (posX - images[0]->w / 2, posY - images[0]->h / 2);
455@@ -338,7 +338,7 @@
456 	CHECK_SCALING (images[1], images[0], gameGUI.getZoom());
457
458 	const int alpha = (alphaEnd - alphaStart) * tick / length + alphaStart;
459-	SDL_SetAlpha (images[1], SDL_SRCALPHA, alpha);
460+	SDL_SetSurfaceAlphaMod (images[1], alpha);
461
462 	SDL_Rect src, dest;
463 	src.y = 0;
464@@ -473,6 +473,6 @@
465 	dest = gameGUI.calcScreenPos ( (int) (posX + tick * dx), (int) (posY + tick * dy));
466
467 	const int alpha = (alphaEnd - alphaStart) * tick / length + alphaStart;
468-	SDL_SetAlpha (images[1], SDL_SRCALPHA, alpha);
469+	SDL_SetSurfaceAlphaMod (images[1], alpha);
470 	SDL_BlitSurface (images[1], &src, buffer, &dest);
471 }
472Index: hud.cpp
473===================================================================
474--- hud.cpp	(revision 3442)
475+++ hud.cpp	(working copy)
476@@ -151,7 +151,7 @@
477 				string sTmpLine = " " + playerList[i]->getName() + ", nr: " + iToStr (playerList[i]->getNr()) + " << you! ";
478 				// black out background for better recognizing
479 				rBlackOut.w = font->getTextWide (sTmpLine, FONT_LATIN_SMALL_WHITE);
480-				SDL_FillRect (buffer, &rBlackOut, 0x00000000);
481+				SDL_FillRect (buffer, &rBlackOut, 0xFF000000);
482 				font->showText (rBlackOut.x, debugOff + 1, sTmpLine, FONT_LATIN_SMALL_WHITE);
483 			}
484 			else
485@@ -159,7 +159,7 @@
486 				string sTmpLine = " " + playerList[i]->getName() + ", nr: " + iToStr (playerList[i]->getNr()) + " ";
487 				// black out background for better recognizing
488 				rBlackOut.w = font->getTextWide (sTmpLine, FONT_LATIN_SMALL_WHITE);
489-				SDL_FillRect (buffer, &rBlackOut, 0x00000000);
490+				SDL_FillRect (buffer, &rBlackOut, 0xFF000000);
491 				font->showText (rBlackOut.x, debugOff + 1, sTmpLine, FONT_LATIN_SMALL_WHITE);
492 			}
493 			// use 10 for pixel high of dots instead of text high
494@@ -823,8 +823,6 @@
495
496 int cGameGUI::show (cClient* client)
497 {
498-	drawnEveryFrame = true;
499-
500 	// do startup actions
501 	openPanel();
502 	startup = true;
503@@ -838,7 +836,7 @@
504 		cEventHandling::handleInputEvents (*this, client);
505 		client->gameTimer.run (this);
506
507-		mouse->GetPos();
508+		mouse->updatePos();
509 		if (mouse->moved())
510 		{
511 			handleMouseMove();
512@@ -1021,10 +1019,10 @@
513
514 SDL_Surface* cGameGUI::generateSurface()
515 {
516-	SDL_Surface* surface = SDL_CreateRGBSurface (SDL_HWSURFACE, Video.getResolutionX(), Video.getResolutionY(), Video.getColDepth(), 0, 0, 0, 0);
517+	SDL_Surface* surface = SDL_CreateRGBSurface (0, Video.getResolutionX(), Video.getResolutionY(), Video.getColDepth(), 0, 0, 0, 0);
518
519 	SDL_FillRect (surface, NULL, 0x00FF00FF);
520-	SDL_SetColorKey (surface, SDL_SRCCOLORKEY, 0x00FF00FF);
521+	SDL_SetColorKey (surface, SDL_TRUE, 0x00FF00FF);
522
523 	const std::string gfxPath = cSettings::getInstance().getGfxPath() + PATH_DELIMITER;
524 	{
525@@ -1260,7 +1258,7 @@
526
527 SDL_Surface* cGameGUI::generateMiniMapSurface()
528 {
529-	SDL_Surface* minimapSurface = SDL_CreateRGBSurface (SDL_SWSURFACE, MINIMAP_SIZE, MINIMAP_SIZE, 32, 0, 0, 0, 0);
530+	SDL_Surface* minimapSurface = SDL_CreateRGBSurface (0, MINIMAP_SIZE, MINIMAP_SIZE, 32, 0, 0, 0, 0);
531
532 	// set zoom factor
533 	const int displayedMapWidth = (int) ( (Video.getResolutionX() - HUD_TOTAL_WIDTH) / getZoom());
534@@ -2940,7 +2938,7 @@
535 	return true;
536 }
537
538-void cGameGUI::handleKeyInput (SDL_KeyboardEvent& key, const string& ch)
539+void cGameGUI::handleKeyInput (const SDL_KeyboardEvent& key)
540 {
541 	if (key.keysym.sym == SDLK_LSHIFT || key.keysym.sym == SDLK_RSHIFT)
542 	{
543@@ -2981,7 +2979,7 @@
544 		cDialogYesNo yesNoDialog (lngPack.i18n ("Text~Comp~End_Game"));
545 		if (yesNoDialog.show (client) == 0) end = true;
546 	}
547-	else if (activeItem && !activeItem->isDisabled() && activeItem->handleKeyInput (key.keysym, ch, this))
548+	else if (activeItem && !activeItem->isDisabled() && activeItem->handleKeyInput (key.keysym, this))
549 	{}
550 	else if (key.keysym.sym == KeysList.KeyJumpToAction)
551 	{
552@@ -3970,7 +3968,7 @@
553 	const int mouseTopY = static_cast<int> (min (mouseBox.startY, mouseBox.endY) * getTileSize());
554 	const int mouseBottomX = static_cast<int> (max (mouseBox.startX, mouseBox.endX) * getTileSize());
555 	const int mouseBottomY = static_cast<int> (max (mouseBox.startY, mouseBox.endY) * getTileSize());
556-	const Uint32 color = 0x00FFFF00;
557+	const Uint32 color = 0xFFFFFF00;
558 	SDL_Rect d;
559
560 	d.x = mouseTopX - zoomOffX + HUD_LEFT_WIDTH;
561@@ -4115,7 +4113,6 @@
562 	while (top.y > -479)
563 	{
564 		Video.draw();
565-		mouse->draw (false, screen);
566 		SDL_Delay (10);
567 		top.y -= 10;
568 		bottom.y += 10;
569@@ -4134,7 +4131,6 @@
570 	while (bottom.y > Video.getResolutionY() / 2)
571 	{
572 		Video.draw();
573-		mouse->draw (false, screen);
574 		SDL_Delay (10);
575 		top.y += 10;
576 		if (top.y > (Video.getResolutionY() / 2) - 479 - 9) top.y = (Video.getResolutionY() / 2) - 479;
577@@ -4147,7 +4143,6 @@
578 		SDL_BlitSurface (GraphicsData.gfx_panel_bottom, NULL, buffer, &tmp);
579 	}
580 	Video.draw();
581-	mouse->draw (false, screen);
582 	SDL_Delay (100);
583 }
584
585@@ -5209,14 +5204,14 @@
586 	r2.w = (int) ( ( (float) (r1.w - 2) / unit.data.ammoMax) * unit.data.ammoCur);
587 	r2.h = r1.h - 2;
588
589-	SDL_FillRect (buffer, &r1, 0);
590+	SDL_FillRect (buffer, &r1, 0xFF000000);
591
592 	if (unit.data.ammoCur > unit.data.ammoMax / 2)
593-		SDL_FillRect (buffer, &r2, 0x0004AE04);
594+		SDL_FillRect (buffer, &r2, 0xFF04AE04);
595 	else if (unit.data.ammoCur > unit.data.ammoMax / 4)
596-		SDL_FillRect (buffer, &r2, 0x00DBDE00);
597+		SDL_FillRect (buffer, &r2, 0xFFDBDE00);
598 	else
599-		SDL_FillRect (buffer, &r2, 0x00E60000);
600+		SDL_FillRect (buffer, &r2, 0xFFE60000);
601 }
602
603 //------------------------------------------------------------------------------
604@@ -5245,15 +5240,15 @@
605 	r2.w = (int) ( ( (float) (r1.w - 2) / unit.data.hitpointsMax) * unit.data.hitpointsCur);
606 	r2.h = r1.h - 2;
607
608-	SDL_FillRect (buffer, &r1, 0);
609+	SDL_FillRect (buffer, &r1, 0xFF000000);
610
611 	Uint32 color;
612 	if (unit.data.hitpointsCur > unit.data.hitpointsMax / 2)
613-		color = 0x0004AE04; // green
614+		color = 0xFF04AE04; // green
615 	else if (unit.data.hitpointsCur > unit.data.hitpointsMax / 4)
616-		color = 0x00DBDE00; // orange
617+		color = 0xFFDBDE00; // orange
618 	else
619-		color = 0x00E60000; // red
620+		color = 0xFFE60000; // red
621 	SDL_FillRect (buffer, &r2, color);
622 }
623
624Index: hud.h
625===================================================================
626--- hud.h	(revision 3442)
627+++ hud.h	(working copy)
628@@ -466,7 +466,7 @@
629
630 	void updateInfoTexts();
631
632-	virtual void handleKeyInput (SDL_KeyboardEvent& key, const std::string& ch);
633+	virtual void handleKeyInput (const SDL_KeyboardEvent& key);
634
635 	const cClient* getClient() const { return client; }
636 	cClient* getClient() { return client; }
637Index: input.cpp
638===================================================================
639--- input.cpp	(revision 3450)
640+++ input.cpp	(working copy)
641@@ -35,13 +35,15 @@
642 cInput::cInput() :
643 	LastClickTicks (0)
644 {
645+#if 0 // TODO: [SDL2]: setting for repeat key ?
646 	// enables that SDL puts the unicode values to the keyevents.
647 	SDL_EnableUNICODE (1);
648 	// enables keyrepetition
649 	SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
650+#endif
651 }
652
653-void cInput::inputkey (cMenu& activeMenu, SDL_KeyboardEvent& key)
654+void cInput::inputkey (cMenu& activeMenu, const SDL_KeyboardEvent& key)
655 {
656 	// give the key to the active menu
657 	// But do not send events to a menu,
658@@ -50,7 +52,7 @@
659 	// after clicking the exit button
660 	if (!activeMenu.exiting())
661 	{
662-		activeMenu.handleKeyInput (key, getUTF16Char (key.keysym.unicode));
663+		activeMenu.handleKeyInput (key);
664 	}
665 }
666
667@@ -86,8 +88,7 @@
668 	}
669 }
670
671-
672-void cInput::inputMouseButton (cMenu& activeMenu, SDL_MouseButtonEvent& button)
673+void cInput::inputMouseButton (cMenu& activeMenu, const SDL_MouseButtonEvent& button)
674 {
675 	MouseState.x = button.x;
676 	MouseState.y = button.y;
677@@ -106,27 +107,7 @@
678 			MouseState.rightButtonReleased = false;
679 			MouseState.leftButtonReleased = false;
680 		}
681-		else if (button.button == SDL_BUTTON_WHEELUP)
682-		{
683-			MouseState.wheelUp = true;
684-			MouseState.leftButtonReleased = false;
685-			MouseState.rightButtonReleased = false;
686-		}
687-		else if (button.button == SDL_BUTTON_WHEELDOWN)
688-		{
689-			MouseState.wheelDown = true;
690-			MouseState.leftButtonReleased = false;
691-			MouseState.rightButtonReleased = false;
692-		}
693-
694-		if (IsDoubleClicked())
695-		{
696-			MouseState.isDoubleClick = true;
697-		}
698-		else
699-		{
700-			MouseState.isDoubleClick = false;
701-		}
702+		MouseState.isDoubleClick = IsDoubleClicked();
703 	}
704 	else if (button.state == SDL_RELEASED)
705 	{
706@@ -142,8 +123,6 @@
707 			MouseState.rightButtonReleased = true;
708 			MouseState.leftButtonReleased = false;
709 		}
710-		else if (button.button == SDL_BUTTON_WHEELUP) MouseState.wheelUp = false;
711-		else if (button.button == SDL_BUTTON_WHEELDOWN) MouseState.wheelDown = false;
712 	}
713
714 	// do not send events to a menu, after an event triggered the termination
715@@ -155,6 +134,24 @@
716 	}
717 }
718
719+void cInput::inputMouseButton (cMenu& activeMenu, const SDL_MouseWheelEvent& wheel)
720+{
721+	MouseState.wheelUp = false;
722+	MouseState.wheelDown = false;
723+	if (wheel.y > 0)
724+	{
725+		MouseState.wheelUp = true;
726+		MouseState.leftButtonReleased = false;
727+		MouseState.rightButtonReleased = false;
728+	}
729+	else if (wheel.y < 0)
730+	{
731+		MouseState.wheelDown = true;
732+		MouseState.leftButtonReleased = false;
733+		MouseState.rightButtonReleased = false;
734+	}
735+}
736+
737 std::string cInput::getUTF16Char (Uint16 ch)
738 {
739 	// convert from UTF-16 to UTF-8
740Index: input.h
741===================================================================
742--- input.h	(revision 3442)
743+++ input.h	(working copy)
744@@ -45,14 +45,8 @@
745 class cInput
746 {
747 private:
748+	sMouseState MouseState;
749
750-	sMouseState MouseState;
751-	/**
752-	 * Decodes the character from UTF-16 to UTF-8 and adds him to the input string.
753-	 * @author alzi alias DoctorDeath
754-	 * @param ch character which is to be added.
755-	 */
756-	std::string getUTF16Char (Uint16 ch);
757 public:
758 	cInput();
759 	/**
760@@ -60,13 +54,22 @@
761 	 * If input is active the character will be added to the inpput string,
762 	 * else the information will be given to the client to handle hotkeys.
763 	 * @author alzi alias DoctorDeath
764-	 * @param keysym SDL_keysym with pressed key information.
765+	 * @param keysym SDL_Keysym with pressed key information.
766 	 */
767-	void inputkey (cMenu& activeMenu, SDL_KeyboardEvent& key);
768+	void inputkey (cMenu& activeMenu, const SDL_KeyboardEvent& key);
769
770 	long LastClickTicks;
771-	void inputMouseButton (cMenu& avtiveMenu, SDL_MouseButtonEvent& button);
772+	void inputMouseButton (cMenu& avtiveMenu, const SDL_MouseButtonEvent& button);
773+	void inputMouseButton (cMenu& activeMenu, const SDL_MouseWheelEvent& wheel);
774 	bool IsDoubleClicked();
775+
776+public:
777+	/**
778+	 * Decodes the character from UTF-16 to UTF-8 and adds him to the input string.
779+	 * @author alzi alias DoctorDeath
780+	 * @param ch character which is to be added.
781+	 */
782+	static std::string getUTF16Char (Uint16 ch);
783 };
784
785 EX cInput* InputHandler;
786Index: keys.cpp
787===================================================================
788--- keys.cpp	(revision 3442)
789+++ keys.cpp	(working copy)
790@@ -139,6 +139,16 @@
791 	return 1;
792 }
793
794+#if 0 // TODO: [SDL2]: obsolete keys... use scancode ?
795+SDLK_KP0;SDLK_KP1;SDLK_KP2;SDLK_KP3;SDLK_KP4;
796+SDLK_KP5;SDLK_KP6;SDLK_KP7;SDLK_KP8;SDLK_KP9;
797+SDLK_NUMLOCK;SDLK_SCROLLOCK;
798+SDLK_RMETA;SDLK_LMETA;
799+SDLK_LSUPER;SDLK_RSUPER;
800+SDLK_COMPOSE;SDLK_PRINT;SDLK_BREAK;SDLK_EURO;
801+#endif
802+
803+
804 // Liefert einen String mit dem Namen der Taste zurueck:
805 const char* GetKeyString (SDLKey key)
806 {
807@@ -216,16 +226,6 @@
808 		case SDLK_y: return "Y";
809 		case SDLK_z: return "Z";
810 		case SDLK_DELETE: return "DELETE";
811-		case SDLK_KP0: return "KP0";
812-		case SDLK_KP1: return "KP1";
813-		case SDLK_KP2: return "KP2";
814-		case SDLK_KP3: return "KP3";
815-		case SDLK_KP4: return "KP4";
816-		case SDLK_KP5: return "KP5";
817-		case SDLK_KP6: return "KP6";
818-		case SDLK_KP7: return "KP7";
819-		case SDLK_KP8: return "KP8";
820-		case SDLK_KP9: return "KP9";
821 		case SDLK_KP_PERIOD: return "KP_PERIOD";
822 		case SDLK_KP_DIVIDE: return "KP_DIVIDE";
823 		case SDLK_KP_MULTIPLY: return "KP_MULTIPLY";
824@@ -257,9 +257,7 @@
825 		case SDLK_F13: return "F13";
826 		case SDLK_F14: return "F14";
827 		case SDLK_F15: return "F15";
828-		case SDLK_NUMLOCK: return "NUMLOCK";
829 		case SDLK_CAPSLOCK: return "CAPSLOCK";
830-		case SDLK_SCROLLOCK: return "SCROLLOCK";
831 		case SDLK_RSHIFT: return "RSHIFT";
832 		case SDLK_LSHIFT: return "LSHIFT";
833 		case SDLK_RCTRL: return "RCTRL";
834@@ -266,19 +264,11 @@
835 		case SDLK_LCTRL: return "LCTRL";
836 		case SDLK_RALT: return "RALT";
837 		case SDLK_LALT: return "LALT";
838-		case SDLK_RMETA: return "RMETA";
839-		case SDLK_LMETA: return "LMETA";
840-		case SDLK_LSUPER: return "LSUPER";
841-		case SDLK_RSUPER: return "RSUPER";
842 		case SDLK_MODE: return "MODE";
843-		case SDLK_COMPOSE: return "COMPOSE";
844 		case SDLK_HELP: return "HELP";
845-		case SDLK_PRINT: return "PRINT";
846 		case SDLK_SYSREQ: return "SYSREQ";
847-		case SDLK_BREAK: return "BREAK";
848 		case SDLK_MENU: return "MENU";
849 		case SDLK_POWER: return "POWER";
850-		case SDLK_EURO: return "EURO";
851 		case SDLK_UNDO: return "UNDO";
852 		default: return "?";
853 	}
854@@ -359,16 +349,6 @@
855 	if (!key.compare ("Y")) return SDLK_y;
856 	if (!key.compare ("Z")) return SDLK_z;
857 	if (!key.compare ("DELETE")) return SDLK_DELETE;
858-	if (!key.compare ("KP0")) return SDLK_KP0;
859-	if (!key.compare ("KP1")) return SDLK_KP1;
860-	if (!key.compare ("KP2")) return SDLK_KP2;
861-	if (!key.compare ("KP3")) return SDLK_KP3;
862-	if (!key.compare ("KP4")) return SDLK_KP4;
863-	if (!key.compare ("KP5")) return SDLK_KP5;
864-	if (!key.compare ("KP6")) return SDLK_KP6;
865-	if (!key.compare ("KP7")) return SDLK_KP7;
866-	if (!key.compare ("KP8")) return SDLK_KP8;
867-	if (!key.compare ("KP9")) return SDLK_KP9;
868 	if (!key.compare ("KP_PERIOD")) return SDLK_KP_PERIOD;
869 	if (!key.compare ("KP_DIVIDE")) return SDLK_KP_DIVIDE;
870 	if (!key.compare ("KP_MULTIPLY")) return SDLK_KP_MULTIPLY;
871@@ -400,9 +380,7 @@
872 	if (!key.compare ("F13")) return SDLK_F13;
873 	if (!key.compare ("F14")) return SDLK_F14;
874 	if (!key.compare ("F15")) return SDLK_F15;
875-	if (!key.compare ("NUMLOCK")) return SDLK_NUMLOCK;
876 	if (!key.compare ("CAPSLOCK")) return SDLK_CAPSLOCK;
877-	if (!key.compare ("SCROLLOCK")) return SDLK_SCROLLOCK;
878 	if (!key.compare ("RSHIFT")) return SDLK_RSHIFT;
879 	if (!key.compare ("LSHIFT")) return SDLK_LSHIFT;
880 	if (!key.compare ("RCTRL")) return SDLK_RCTRL;
881@@ -409,19 +387,11 @@
882 	if (!key.compare ("LCTRL")) return SDLK_LCTRL;
883 	if (!key.compare ("RALT")) return SDLK_RALT;
884 	if (!key.compare ("LALT")) return SDLK_LALT;
885-	if (!key.compare ("RMETA")) return SDLK_RMETA;
886-	if (!key.compare ("LMETA")) return SDLK_LMETA;
887-	if (!key.compare ("LSUPER")) return SDLK_LSUPER;
888-	if (!key.compare ("RSUPER")) return SDLK_RSUPER;
889 	if (!key.compare ("MODE")) return SDLK_MODE;
890-	if (!key.compare ("COMPOSE")) return SDLK_COMPOSE;
891 	if (!key.compare ("HELP")) return SDLK_HELP;
892-	if (!key.compare ("PRINT")) return SDLK_PRINT;
893 	if (!key.compare ("SYSREQ")) return SDLK_SYSREQ;
894-	if (!key.compare ("BREAK")) return SDLK_BREAK;
895 	if (!key.compare ("MENU")) return SDLK_MENU;
896 	if (!key.compare ("POWER")) return SDLK_POWER;
897-	if (!key.compare ("EURO")) return SDLK_EURO;
898 	if (!key.compare ("UNDO")) return SDLK_UNDO;
899 	return SDLK_UNKNOWN;
900 }
901Index: keys.h
902===================================================================
903--- keys.h	(revision 3442)
904+++ keys.h	(working copy)
905@@ -22,6 +22,10 @@
906 #include <string>
907 #include "defines.h"
908
909+#if 1 // TODO [SDL2]: use scancode or keycode ?
910+typedef SDL_Keycode SDLKey;
911+#endif
912+
913 // Globale Daten /////////////////////////////////////////////////////////////
914 class cKeysList
915 {
916Index: loaddata.cpp
917===================================================================
918--- loaddata.cpp	(revision 3442)
919+++ loaddata.cpp	(working copy)
920@@ -357,12 +357,12 @@
921 			if (pos == 0)   //need full line for first entry version information
922 			{
923 				SDL_BlitSurface (buffer, NULL, screen, NULL);
924-				SDL_UpdateRect (screen, rDest.x, rDest.y + rDest.h * pos, rDest.w + rDest2.w, rDest.h);
925+				Video.draw();
926 			}
927 			else
928 			{
929 				SDL_BlitSurface (buffer, &rSrc, screen, &rSrc);
930-				SDL_UpdateRect (screen, rDest.x, rDest.y + rDest.h * pos, rDest.w, rDest.h);
931+				Video.draw();
932 			}
933 			break;
934
935@@ -380,7 +380,7 @@
936 		rSrc = rDest2;
937 		rSrc.y = rDest2.y + rDest2.h * pos;
938 		SDL_BlitSurface (buffer, &rSrc, screen, &rSrc);
939-		SDL_UpdateRect (screen, rDest2.x, rDest2.y + rDest2.h * pos, rDest2.w, rDest2.h);
940+		Video.draw();
941 	}
942 }
943
944@@ -474,8 +474,8 @@
945
946 	dest[0] = LoadPCX (filepath);
947 	dest[1] = CloneSDLSurface (dest[0]);
948-	SDL_SetAlpha (dest[0], SDL_SRCALPHA, alpha);
949-	SDL_SetAlpha (dest[1], SDL_SRCALPHA, alpha);
950+	SDL_SetSurfaceAlphaMod (dest[0], alpha);
951+	SDL_SetSurfaceAlphaMod (dest[1], alpha);
952
953 	filepath.insert (0, "Effectalpha loaded: ");
954 	Log.write (filepath.c_str(), LOG_TYPE_DEBUG);
955@@ -607,7 +607,7 @@
956 	LoadEffectGraphicToSurface (fx_rocket, path, "rocket.pcx");
957 	LoadEffectAlphaToSurface (fx_dark_smoke, path, "dark_smoke.pcx", 100);
958 	LoadEffectAlphaToSurface (fx_tracks, path, "tracks.pcx", 100);
959-	LoadEffectAlphaToSurface (fx_corpse, path, "corpse.pcx", 255);
960+	LoadEffectAlphaToSurface (fx_corpse, path, "corpse.pcx", 254);
961 	LoadEffectAlphaToSurface (fx_absorb, path, "absorb.pcx", 150);
962 }
963
964@@ -855,17 +855,17 @@
965
966 	Log.write ("Shadowgraphics...", LOG_TYPE_DEBUG);
967 	// Shadow:
968-	GraphicsData.gfx_shadow = SDL_CreateRGBSurface (Video.getSurfaceType(), Video.getResolutionX(),
969-													Video.getResolutionY(), Video.getColDepth(), 0, 0, 0, 0);
970+	GraphicsData.gfx_shadow = SDL_CreateRGBSurface (0, Video.getResolutionX(), Video.getResolutionY(),
971+													Video.getColDepth(), 0, 0, 0, 0);
972 	SDL_FillRect (GraphicsData.gfx_shadow, NULL, 0x0);
973-	SDL_SetAlpha (GraphicsData.gfx_shadow, SDL_SRCALPHA, 50);
974-	GraphicsData.gfx_tmp = SDL_CreateRGBSurface (Video.getSurfaceType(), 128, 128, Video.getColDepth(), 0, 0, 0, 0);
975-	SDL_SetColorKey (GraphicsData.gfx_tmp, SDL_SRCCOLORKEY, 0xFF00FF);
976+	SDL_SetSurfaceAlphaMod (GraphicsData.gfx_shadow, 50);
977+	GraphicsData.gfx_tmp = SDL_CreateRGBSurface (0, 128, 128, Video.getColDepth(), 0, 0, 0, 0);
978+	SDL_SetColorKey (GraphicsData.gfx_tmp, SDL_TRUE, 0xFF00FF);
979
980 	// Glas:
981 	Log.write ("Glassgraphic...", LOG_TYPE_DEBUG);
982 	LoadGraphicToSurface (GraphicsData.gfx_destruction_glas, path, "destruction_glas.pcx");
983-	SDL_SetAlpha (GraphicsData.gfx_destruction_glas, SDL_SRCALPHA, 150);
984+	SDL_SetSurfaceAlphaMod (GraphicsData.gfx_destruction_glas, 150);
985
986 	// Waypoints:
987 	Log.write ("Waypointgraphics...", LOG_TYPE_DEBUG);
988@@ -922,7 +922,7 @@
989 	if (LoadGraphicToSurface (res_metal_org, path, "res.pcx") == 1)
990 	{
991 		res_metal = CloneSDLSurface (res_metal_org);
992-		SDL_SetColorKey (res_metal, SDL_SRCCOLORKEY, 0xFF00FF);
993+		SDL_SetColorKey (res_metal, SDL_TRUE, 0xFF00FF);
994 	}
995
996 	// gold
997@@ -929,7 +929,7 @@
998 	if (LoadGraphicToSurface (res_gold_org, path, "gold.pcx") == 1)
999 	{
1000 		res_gold = CloneSDLSurface (res_gold_org);
1001-		SDL_SetColorKey (res_gold, SDL_SRCCOLORKEY, 0xFF00FF);
1002+		SDL_SetColorKey (res_gold, SDL_TRUE, 0xFF00FF);
1003 	}
1004
1005 	// fuel
1006@@ -936,7 +936,7 @@
1007 	if (LoadGraphicToSurface (res_oil_org, path, "fuel.pcx") == 1)
1008 	{
1009 		res_oil = CloneSDLSurface (res_oil_org);
1010-		SDL_SetColorKey (res_oil, SDL_SRCCOLORKEY, 0xFF00FF);
1011+		SDL_SetColorKey (res_oil, SDL_TRUE, 0xFF00FF);
1012 	}
1013 }
1014
1015@@ -1040,8 +1040,8 @@
1016 			SDL_Rect rcDest;
1017 			for (int n = 0; n < 8; n++)
1018 			{
1019-				ui.img[n] = SDL_CreateRGBSurface (Video.getSurfaceType() | SDL_SRCCOLORKEY, 64 * 13, 64, Video.getColDepth(), 0, 0, 0, 0);
1020-				SDL_SetColorKey (ui.img[n], SDL_SRCCOLORKEY, 0x00FFFFFF);
1021+				ui.img[n] = SDL_CreateRGBSurface (0, 64 * 13, 64, Video.getColDepth(), 0, 0, 0, 0);
1022+				SDL_SetColorKey (ui.img[n], SDL_TRUE, 0x00FFFFFF);
1023 				SDL_FillRect (ui.img[n], NULL, 0x00FF00FF);
1024
1025 				for (int j = 0; j < 13; j++)
1026@@ -1066,16 +1066,16 @@
1027 						}
1028 					}
1029 				}
1030-				ui.img_org[n] = SDL_CreateRGBSurface (Video.getSurfaceType() | SDL_SRCCOLORKEY, 64 * 13, 64, Video.getColDepth(), 0, 0, 0, 0);
1031-				SDL_SetColorKey (ui.img[n], SDL_SRCCOLORKEY, 0x00FFFFFF);
1032+				ui.img_org[n] = SDL_CreateRGBSurface (0, 64 * 13, 64, Video.getColDepth(), 0, 0, 0, 0);
1033+				SDL_SetColorKey (ui.img[n], SDL_TRUE, 0x00FFFFFF);
1034 				SDL_FillRect (ui.img_org[n], NULL, 0x00FFFFFF);
1035 				SDL_BlitSurface (ui.img[n], NULL, ui.img_org[n], NULL);
1036
1037-				ui.shw[n] = SDL_CreateRGBSurface (Video.getSurfaceType() | SDL_SRCCOLORKEY, 64 * 13, 64, Video.getColDepth(), 0, 0, 0, 0);
1038-				SDL_SetColorKey (ui.shw[n], SDL_SRCCOLORKEY, 0x00FF00FF);
1039+				ui.shw[n] = SDL_CreateRGBSurface (0, 64 * 13, 64, Video.getColDepth(), 0, 0, 0, 0);
1040+				SDL_SetColorKey (ui.shw[n], SDL_TRUE, 0x00FF00FF);
1041 				SDL_FillRect (ui.shw[n], NULL, 0x00FF00FF);
1042-				ui.shw_org[n] = SDL_CreateRGBSurface (Video.getSurfaceType() | SDL_SRCCOLORKEY, 64 * 13, 64, Video.getColDepth(), 0, 0, 0, 0);
1043-				SDL_SetColorKey (ui.shw_org[n], SDL_SRCCOLORKEY, 0x00FF00FF);
1044+				ui.shw_org[n] = SDL_CreateRGBSurface (0, 64 * 13, 64, Video.getColDepth(), 0, 0, 0, 0);
1045+				SDL_SetColorKey (ui.shw_org[n], SDL_TRUE, 0x00FF00FF);
1046 				SDL_FillRect (ui.shw_org[n], NULL, 0x00FF00FF);
1047
1048 				rcDest.x = 3;
1049@@ -1091,8 +1091,8 @@
1050 				}
1051 				SDL_UnlockSurface (ui.shw_org[n]);
1052 				SDL_BlitSurface (ui.shw_org[n], NULL, ui.shw[n], NULL);
1053-				SDL_SetAlpha (ui.shw_org[n], SDL_SRCALPHA, 50);
1054-				SDL_SetAlpha (ui.shw[n], SDL_SRCALPHA, 50);
1055+				SDL_SetSurfaceAlphaMod (ui.shw_org[n], 50);
1056+				SDL_SetSurfaceAlphaMod (ui.shw[n], 50);
1057 			}
1058 		}
1059 		// load other vehicle graphics
1060@@ -1110,8 +1110,8 @@
1061 				{
1062 					ui.img_org[n] = LoadPCX (sTmpString);
1063 					ui.img[n] = CloneSDLSurface (ui.img_org[n]);
1064-					SDL_SetColorKey (ui.img_org[n], SDL_SRCCOLORKEY, 0xFFFFFF);
1065-					SDL_SetColorKey (ui.img[n], SDL_SRCCOLORKEY, 0xFFFFFF);
1066+					SDL_SetColorKey (ui.img_org[n], SDL_TRUE, 0xFFFFFF);
1067+					SDL_SetColorKey (ui.img[n], SDL_TRUE, 0xFFFFFF);
1068 				}
1069 				else
1070 				{
1071@@ -1125,7 +1125,7 @@
1072 				{
1073 					ui.shw_org[n] = LoadPCX (sTmpString);
1074 					ui.shw[n] = CloneSDLSurface (ui.shw_org[n]);
1075-					SDL_SetAlpha (ui.shw[n], SDL_SRCALPHA, 50);
1076+					SDL_SetSurfaceAlphaMod (ui.shw[n], 50);
1077 				}
1078 				else
1079 				{
1080@@ -1210,8 +1210,8 @@
1081 			{
1082 				ui.build_org = LoadPCX (sTmpString);
1083 				ui.build = CloneSDLSurface (ui.build_org);
1084-				SDL_SetColorKey (ui.build_org, SDL_SRCCOLORKEY, 0xFFFFFF);
1085-				SDL_SetColorKey (ui.build, SDL_SRCCOLORKEY, 0xFFFFFF);
1086+				SDL_SetColorKey (ui.build_org, SDL_TRUE, 0xFFFFFF);
1087+				SDL_SetColorKey (ui.build, SDL_TRUE, 0xFFFFFF);
1088 			}
1089 			else
1090 			{
1091@@ -1227,7 +1227,7 @@
1092 			{
1093 				ui.build_shw_org = LoadPCX (sTmpString);
1094 				ui.build_shw = CloneSDLSurface (ui.build_shw_org);
1095-				SDL_SetAlpha (ui.build_shw, SDL_SRCALPHA, 50);
1096+				SDL_SetSurfaceAlphaMod (ui.build_shw, 50);
1097 			}
1098 			else
1099 			{
1100@@ -1255,8 +1255,8 @@
1101 			{
1102 				ui.clear_small_org = LoadPCX (sTmpString);
1103 				ui.clear_small = CloneSDLSurface (ui.clear_small_org);
1104-				SDL_SetColorKey (ui.clear_small_org, SDL_SRCCOLORKEY, 0xFFFFFF);
1105-				SDL_SetColorKey (ui.clear_small, SDL_SRCCOLORKEY, 0xFFFFFF);
1106+				SDL_SetColorKey (ui.clear_small_org, SDL_TRUE, 0xFFFFFF);
1107+				SDL_SetColorKey (ui.clear_small, SDL_TRUE, 0xFFFFFF);
1108 			}
1109 			else
1110 			{
1111@@ -1272,7 +1272,7 @@
1112 			{
1113 				ui.clear_small_shw_org = LoadPCX (sTmpString);
1114 				ui.clear_small_shw = CloneSDLSurface (ui.clear_small_shw_org);
1115-				SDL_SetAlpha (ui.clear_small_shw, SDL_SRCALPHA, 50);
1116+				SDL_SetSurfaceAlphaMod (ui.clear_small_shw, 50);
1117 			}
1118 			else
1119 			{
1120@@ -1288,8 +1288,8 @@
1121 			{
1122 				ui.build_org = LoadPCX (sTmpString);
1123 				ui.build = CloneSDLSurface (ui.build_org);
1124-				SDL_SetColorKey (ui.build_org, SDL_SRCCOLORKEY, 0xFFFFFF);
1125-				SDL_SetColorKey (ui.build, SDL_SRCCOLORKEY, 0xFFFFFF);
1126+				SDL_SetColorKey (ui.build_org, SDL_TRUE, 0xFFFFFF);
1127+				SDL_SetColorKey (ui.build, SDL_TRUE, 0xFFFFFF);
1128 			}
1129 			else
1130 			{
1131@@ -1305,7 +1305,7 @@
1132 			{
1133 				ui.build_shw_org = LoadPCX (sTmpString);
1134 				ui.build_shw = CloneSDLSurface (ui.build_shw_org);
1135-				SDL_SetAlpha (ui.build_shw, SDL_SRCALPHA, 50);
1136+				SDL_SetSurfaceAlphaMod (ui.build_shw, 50);
1137 			}
1138 			else
1139 			{
1140@@ -1594,8 +1594,8 @@
1141 		{
1142 			ui.img_org = LoadPCX (sTmpString);
1143 			ui.img = CloneSDLSurface (ui.img_org);
1144-			SDL_SetColorKey (ui.img_org, SDL_SRCCOLORKEY, 0xFFFFFF);
1145-			SDL_SetColorKey (ui.img, SDL_SRCCOLORKEY, 0xFFFFFF);
1146+			SDL_SetColorKey (ui.img_org, SDL_TRUE, 0xFFFFFF);
1147+			SDL_SetColorKey (ui.img, SDL_TRUE, 0xFFFFFF);
1148 		}
1149 		else
1150 		{
1151@@ -1609,7 +1609,7 @@
1152 		{
1153 			ui.shw_org = LoadPCX (sTmpString);
1154 			ui.shw     = CloneSDLSurface (ui.shw_org);
1155-			SDL_SetAlpha (ui.shw, SDL_SRCALPHA, 50);
1156+			SDL_SetSurfaceAlphaMod (ui.shw, 50);
1157 		}
1158
1159 		// load video
1160@@ -1633,7 +1633,7 @@
1161 			{
1162 				ui.eff_org = LoadPCX (sTmpString);
1163 				ui.eff = CloneSDLSurface (ui.eff_org);
1164-				SDL_SetAlpha (ui.eff, SDL_SRCALPHA, 10);
1165+				SDL_SetSurfaceAlphaMod (ui.eff, 10);
1166 			}
1167 		}
1168 		else
1169@@ -1655,16 +1655,16 @@
1170 			b.isConnectorGraphic = true;
1171 			UnitsData.ptr_connector = ui.img;
1172 			UnitsData.ptr_connector_org = ui.img_org;
1173-			SDL_SetColorKey (UnitsData.ptr_connector, SDL_SRCCOLORKEY, 0xFF00FF);
1174+			SDL_SetColorKey (UnitsData.ptr_connector, SDL_TRUE, 0xFF00FF);
1175 			UnitsData.ptr_connector_shw = ui.shw;
1176 			UnitsData.ptr_connector_shw_org = ui.shw_org;
1177-			SDL_SetColorKey (UnitsData.ptr_connector_shw, SDL_SRCCOLORKEY, 0xFF00FF);
1178+			SDL_SetColorKey (UnitsData.ptr_connector_shw, SDL_TRUE, 0xFF00FF);
1179 		}
1180 		else if (b.ID == UnitsData.specialIDSmallBeton)
1181 		{
1182 			UnitsData.ptr_small_beton = ui.img;
1183 			UnitsData.ptr_small_beton_org = ui.img_org;
1184-			SDL_SetColorKey (UnitsData.ptr_small_beton, SDL_SRCCOLORKEY, 0xFF00FF);
1185+			SDL_SetColorKey (UnitsData.ptr_small_beton, SDL_TRUE, 0xFF00FF);
1186 		}
1187
1188 		// Check if there is more than one frame
1189@@ -1680,12 +1680,12 @@
1190 		UnitsData.dirt_big = CloneSDLSurface (UnitsData.dirt_big_org);
1191 		LoadGraphicToSurface (UnitsData.dirt_big_shw_org, cSettings::getInstance().getBuildingsPath().c_str(), "dirt_big_shw.pcx");
1192 		UnitsData.dirt_big_shw = CloneSDLSurface (UnitsData.dirt_big_shw_org);
1193-		if (UnitsData.dirt_big_shw) SDL_SetAlpha (UnitsData.dirt_big_shw, SDL_SRCALPHA, 50);
1194+		if (UnitsData.dirt_big_shw) SDL_SetSurfaceAlphaMod (UnitsData.dirt_big_shw, 50);
1195 		LoadGraphicToSurface (UnitsData.dirt_small_org, cSettings::getInstance().getBuildingsPath().c_str(), "dirt_small.pcx");
1196 		UnitsData.dirt_small = CloneSDLSurface (UnitsData.dirt_small_org);
1197 		LoadGraphicToSurface (UnitsData.dirt_small_shw_org, cSettings::getInstance().getBuildingsPath().c_str(), "dirt_small_shw.pcx");
1198 		UnitsData.dirt_small_shw = CloneSDLSurface (UnitsData.dirt_small_shw_org);
1199-		if (UnitsData.dirt_small_shw) SDL_SetAlpha (UnitsData.dirt_small_shw, SDL_SRCALPHA, 50);
1200+		if (UnitsData.dirt_small_shw) SDL_SetSurfaceAlphaMod (UnitsData.dirt_small_shw, 50);
1201 	}
1202 	return 1;
1203 }
1204Index: log.cpp
1205===================================================================
1206--- log.cpp	(revision 3449)
1207+++ log.cpp	(working copy)
1208@@ -104,7 +104,7 @@
1209 		fprintf (stderr, "(EE): Couldn't open maxr.log!\n Please check file/directory permissions\n");
1210 		return false;
1211 	}
1212-	if (blocks < 0)
1213+	if (blocks <= 0)
1214 	{
1215 		fprintf (stderr, "(EE): Couldn't read maxr.log!\n Please check file/directory permissions\n");
1216
1217@@ -173,9 +173,9 @@
1218 {
1219 	if (logfile)
1220 	{
1221-		int const wrote = SDL_RWwrite (logfile, str.c_str(), 1, (int) str.length());
1222+		const int wrote = SDL_RWwrite (logfile, str.c_str(), 1, (int) str.length());
1223 		std::cout << str;
1224-		if (wrote < 0)   //sanity check - was file writable?
1225+		if (wrote <= 0)   //sanity check - was file writable?
1226 		{
1227 			fprintf (stderr, "Couldn't write to maxr.log\nPlease check permissions for maxr.log\nLog message was:\n%s", str.c_str());
1228 			return -1;
1229Index: main.cpp
1230===================================================================
1231--- main.cpp	(revision 3442)
1232+++ main.cpp	(working copy)
1233@@ -27,7 +27,6 @@
1234 #include <SDL_thread.h>
1235 #include <SDL_net.h>
1236 #include <SDL_mixer.h>
1237-#include <SDL_getenv.h>
1238
1239 #define __main__
1240 #include "main.h"
1241@@ -111,7 +110,7 @@
1242
1243 	// load files
1244 	int loadingState = LOAD_GOING;
1245-	SDL_Thread* dataThread = SDL_CreateThread (LoadData, &loadingState);
1246+	SDL_Thread* dataThread = SDL_CreateThread (LoadData, "loadingData", &loadingState);
1247
1248 	SDL_Event event;
1249 	while (loadingState != LOAD_FINISHED)
1250@@ -124,8 +123,12 @@
1251 		}
1252 		while (SDL_PollEvent (&event))
1253 		{
1254-			if (event.type == SDL_ACTIVEEVENT && !DEDICATED_SERVER)
1255-				SDL_UpdateRect (screen, 0, 0, 0, 0);
1256+			if (!DEDICATED_SERVER
1257+				&& event.type == SDL_WINDOWEVENT
1258+				&& event.window.event == SDL_WINDOWEVENT_EXPOSED)
1259+			{
1260+				Video.draw();
1261+			}
1262 		}
1263 		SDL_Delay (100);
1264 	}
1265@@ -172,7 +175,6 @@
1266 	else
1267 	{
1268 		Video.setResolution (Video.getResolutionX(), Video.getResolutionY(), true);
1269-		SDL_ShowCursor (0);
1270 		Video.clearBuffer();
1271
1272 		mouse = new cMouse;
1273@@ -335,7 +337,7 @@
1274 	if (height > scr->h && dest) height = scr->h;
1275
1276 	// generate new surface if necessary
1277-	if (dest == NULL) surface = SDL_CreateRGBSurface (scr->flags, width, height, scr->format->BitsPerPixel, scr->format->Rmask, scr->format->Gmask, scr->format->Bmask, scr->format->Amask);
1278+	if (dest == NULL) surface = SDL_CreateRGBSurface (0, width, height, scr->format->BitsPerPixel, scr->format->Rmask, scr->format->Gmask, scr->format->Bmask, scr->format->Amask);
1279 	else
1280 	{
1281 		// else set the size of the old one
1282@@ -421,8 +423,8 @@
1283 SDL_Surface* CreatePfeil (int p1x, int p1y, int p2x, int p2y, int p3x, int p3y, unsigned int color, int size)
1284 {
1285 	SDL_Surface* sf;
1286-	sf = SDL_CreateRGBSurface (Video.getSurfaceType() | SDL_SRCCOLORKEY, size, size, Video.getColDepth(), 0, 0, 0, 0);
1287-	SDL_SetColorKey (sf, SDL_SRCCOLORKEY, 0x00FF00FF);
1288+	sf = SDL_CreateRGBSurface (0, size, size, Video.getColDepth(), 0, 0, 0, 0);
1289+	SDL_SetColorKey (sf, SDL_TRUE, 0x00FF00FF);
1290 	SDL_FillRect (sf, NULL, 0x00FF00FF);
1291 	SDL_LockSurface (sf);
1292
1293@@ -974,8 +976,8 @@
1294 	if (!dst || !src) return;
1295
1296 	//check surface formats
1297-	if (!dst->format->Amask) return;
1298-	if (src->format->Amask || ! (src->flags & SDL_SRCALPHA)) return;
1299+	if (!dst->format->Amask || src->format->Amask) return;
1300+	if (SDL_GetSurfaceAlphaMod(src, NULL) != 0) return;
1301
1302 	if (srcrect == NULL)
1303 	{
1304@@ -1037,7 +1039,8 @@
1305 	if (SDL_MUSTLOCK (dst)) SDL_LockSurface (dst);
1306
1307 	//setup needed variables
1308-	const Uint32 srcAlpha = src->format->alpha;
1309+	Uint8 srcAlpha = 0;
1310+	SDL_GetSurfaceAlphaMod (src, &srcAlpha);
1311 	const int srmask = src->format->Rmask;
1312 	const int sgmask = src->format->Gmask;
1313 	const int sbmask = src->format->Bmask;
1314@@ -1049,8 +1052,8 @@
1315 	const int gshift = src->format->Gshift - dst->format->Gshift;
1316 	const int bshift = src->format->Bshift - dst->format->Bshift;
1317 	const int ashift = dst->format->Ashift;
1318-	const Uint32 colorKey = src->format->colorkey;
1319-	const bool useColorKey = (src->flags & SDL_SRCCOLORKEY) != 0;
1320+	Uint32 colorKey = 0;
1321+	const bool useColorKey = SDL_GetColorKey (src, &colorKey) == 0;
1322
1323 	Uint32* dstPixel = static_cast<Uint32*> (dst->pixels) + dstrect->x + dstrect->y * dst->w;
1324 	Uint32* srcPixel = static_cast<Uint32*> (src->pixels) + srcrect->x + srcrect->y * src->w;
1325@@ -1107,7 +1110,8 @@
1326
1327 void blittAlphaSurface (SDL_Surface* src, SDL_Rect* srcrect, SDL_Surface* dst, SDL_Rect* dstrect)
1328 {
1329-	if (dst->format->Amask && (src->flags & SDL_SRCALPHA))
1330+	// TODO: [SDL2] special blitSurface seems useless.
1331+	if (dst->format->Amask && SDL_GetSurfaceAlphaMod(src, NULL) == 0)
1332 		blittPerSurfaceAlphaToAlphaChannel (src, srcrect, dst, dstrect);
1333 	else
1334 		SDL_BlitSurface (src, srcrect, dst, dstrect);
1335Index: map.cpp
1336===================================================================
1337--- map.cpp	(revision 3450)
1338+++ map.cpp	(working copy)
1339@@ -28,6 +28,14 @@
1340 #include "vehicles.h"
1341 #include "video.h"
1342
1343+#if 1 // TODO: [SDL2]: SDL_SetColors
1344+inline void SDL_SetColors (SDL_Surface* surface, SDL_Color* colors, int index, int size)
1345+{
1346+	SDL_SetPaletteColors (surface->format->palette, colors, index, size);
1347+}
1348+#endif
1349+
1350+
1351 sTerrain::sTerrain() :
1352 	water (false),
1353 	coast (false),
1354@@ -250,6 +258,8 @@
1355 		palette_shw[i].r = (unsigned char) (palette[i].r * 0.6f);
1356 		palette_shw[i].g = (unsigned char) (palette[i].g * 0.6f);
1357 		palette_shw[i].b = (unsigned char) (palette[i].b * 0.6f);
1358+		palette[i].a = 255;
1359+		palette_shw[i].a = 255;
1360 	}
1361
1362 	// Load necessary Terrain Graphics
1363@@ -314,13 +324,13 @@
1364 	return true;
1365 }
1366
1367-/*static*/SDL_Surface* cStaticMap::loadTerrGraph (SDL_RWops* fpMapFile, int iGraphicsPos, SDL_Color* Palette, int iNum)
1368+/*static*/SDL_Surface* cStaticMap::loadTerrGraph (SDL_RWops* fpMapFile, int iGraphicsPos, const SDL_Color (&colors)[256], int iNum)
1369 {
1370 	// Create new surface and copy palette
1371-	AutoSurface surface (SDL_CreateRGBSurface (SDL_SWSURFACE, 64, 64, 8, 0, 0, 0, 0));
1372+	AutoSurface surface (SDL_CreateRGBSurface (0, 64, 64, 8, 0, 0, 0, 0));
1373 	surface->pitch = surface->w;
1374
1375-	SDL_SetColors (surface, Palette, 0, 256);
1376+	SDL_SetPaletteColors (surface->format->palette, colors, 0, 256);
1377
1378 	// Go to position of filedata
1379 	SDL_RWseek (fpMapFile, iGraphicsPos + 64 * 64 * (iNum), SEEK_SET);
1380@@ -353,7 +363,7 @@
1381 	SDL_RWseek (mapFile, 64 * 64 * sGraphCount, SEEK_CUR);
1382 	SDL_RWread (mapFile, &Palette, 3, 256);
1383
1384-	AutoSurface mapSurface (SDL_CreateRGBSurface (SDL_SWSURFACE, size, size, 8, 0, 0, 0, 0));
1385+	AutoSurface mapSurface (SDL_CreateRGBSurface (0, size, size, 8, 0, 0, 0, 0));
1386 	mapSurface->pitch = mapSurface->w;
1387
1388 	mapSurface->format->palette->ncolors = 256;
1389@@ -388,20 +398,20 @@
1390 	//This is needed to make sure, that the pixeldata is copied 1:1
1391
1392 	//copy the normal terrains
1393-	terrains[iNum].sf_org = SDL_CreateRGBSurface (Video.getSurfaceType(), 64, 64, 8, 0, 0, 0, 0);
1394-	SDL_SetColors (terrains[iNum].sf_org, surface->format->palette->colors, 0, 256);
1395+	terrains[iNum].sf_org = SDL_CreateRGBSurface (0, 64, 64, 8, 0, 0, 0, 0);
1396+	SDL_SetPaletteColors (terrains[iNum].sf_org->format->palette, surface->format->palette->colors, 0, 256);
1397 	SDL_BlitSurface (surface, NULL, terrains[iNum].sf_org, NULL);
1398
1399-	terrains[iNum].sf = SDL_CreateRGBSurface (Video.getSurfaceType(), 64, 64, 8, 0, 0, 0, 0);
1400-	SDL_SetColors (terrains[iNum].sf, surface->format->palette->colors, 0, 256);
1401+	terrains[iNum].sf = SDL_CreateRGBSurface (0, 64, 64, 8, 0, 0, 0, 0);
1402+	SDL_SetPaletteColors (terrains[iNum].sf->format->palette, surface->format->palette->colors, 0, 256);
1403 	SDL_BlitSurface (surface, NULL, terrains[iNum].sf, NULL);
1404
1405 	//copy the terrains with fog
1406-	terrains[iNum].shw_org = SDL_CreateRGBSurface (Video.getSurfaceType(), 64, 64, 8, 0, 0, 0, 0);
1407+	terrains[iNum].shw_org = SDL_CreateRGBSurface (0, 64, 64, 8, 0, 0, 0, 0);
1408 	SDL_SetColors (terrains[iNum].shw_org, surface->format->palette->colors, 0, 256);
1409 	SDL_BlitSurface (surface, NULL, terrains[iNum].shw_org, NULL);
1410
1411-	terrains[iNum].shw = SDL_CreateRGBSurface (Video.getSurfaceType(), 64, 64, 8, 0, 0, 0, 0);
1412+	terrains[iNum].shw = SDL_CreateRGBSurface (0, 64, 64, 8, 0, 0, 0, 0);
1413 	SDL_SetColors (terrains[iNum].shw, surface->format->palette->colors, 0, 256);
1414 	SDL_BlitSurface (surface, NULL, terrains[iNum].shw, NULL);
1415
1416@@ -451,7 +461,7 @@
1417
1418 SDL_Surface* cStaticMap::createBigSurface (int sizex, int sizey) const
1419 {
1420-	SDL_Surface* mapSurface = SDL_CreateRGBSurface (Video.getSurfaceType(), sizex, sizey, Video.getColDepth(), 0, 0, 0, 0);
1421+	SDL_Surface* mapSurface = SDL_CreateRGBSurface (0, sizex, sizey, Video.getColDepth(), 0, 0, 0, 0);
1422
1423 	if (SDL_MUSTLOCK (mapSurface)) SDL_LockSurface (mapSurface);
1424 	for (int x = 0; x < mapSurface->w; ++x)
1425Index: map.h
1426===================================================================
1427--- map.h	(revision 3442)
1428+++ map.h	(working copy)
1429@@ -127,7 +127,7 @@
1430 	void scaleSurfaces (int pixelSize);
1431 	static SDL_Surface* loadMapPreview(const std::string& mapPath, int* mapSize = NULL);
1432 private:
1433-	static SDL_Surface* loadTerrGraph (SDL_RWops* fpMapFile, int iGraphicsPos, SDL_Color* Palette, int iNum);
1434+	static SDL_Surface* loadTerrGraph (SDL_RWops* fpMapFile, int iGraphicsPos, const SDL_Color (&colors)[256], int iNum);
1435 	void copySrfToTerData (SDL_Surface* surface, int iNum);
1436 private:
1437 	std::string filename;   // Name of the current map
1438Index: mapdownload.cpp
1439===================================================================
1440--- mapdownload.cpp	(revision 3450)
1441+++ mapdownload.cpp	(working copy)
1442@@ -269,7 +269,7 @@
1443 void cMapSender::runInThread()
1444 {
1445 	// the thread will quit, when it finished uploading the map
1446-	thread = SDL_CreateThread (mapSenderThreadFunction, this);
1447+	thread = SDL_CreateThread (mapSenderThreadFunction, "mapSender", this);
1448 }
1449
1450 //------------------------------------------------------------------------------
1451Index: menuitems.cpp
1452===================================================================
1453--- menuitems.cpp	(revision 3446)
1454+++ menuitems.cpp	(working copy)
1455@@ -442,10 +442,10 @@
1456 {
1457 	if (image_ != NULL)
1458 	{
1459-		image = SDL_CreateRGBSurface (Video.getSurfaceType() | SDL_SRCCOLORKEY, image_->w, image_->h, Video.getColDepth(), 0, 0, 0, 0);
1460+		image = SDL_CreateRGBSurface (0, image_->w, image_->h, Video.getColDepth(), 0, 0, 0, 0);
1461
1462 		SDL_FillRect (image, NULL, 0xFF00FF);
1463-		SDL_SetColorKey (image, SDL_SRCCOLORKEY, 0xFF00FF);
1464+		SDL_SetColorKey (image, SDL_TRUE, 0xFF00FF);
1465
1466 		SDL_BlitSurface (image_, NULL, image, NULL);
1467
1468@@ -702,8 +702,8 @@
1469 			src.y = isClicked ? 0 : 132;
1470 			break;
1471 	}
1472-	surface = SDL_CreateRGBSurface (Video.getSurfaceType() | SDL_SRCCOLORKEY, src.w, src.h, Video.getColDepth(), 0, 0, 0, 0);
1473-	SDL_SetColorKey (surface, SDL_SRCCOLORKEY, 0xFF00FF);
1474+	surface = SDL_CreateRGBSurface (0, src.w, src.h, Video.getColDepth(), 0, 0, 0, 0);
1475+	SDL_SetColorKey (surface, SDL_TRUE, 0xFF00FF);
1476 	SDL_FillRect (surface, NULL, 0xFF00FF);
1477 	if (buttonType >= BUTTON_TYPE_HUD_HELP && buttonType <= BUTTON_TYPE_HUD_STOP) SDL_BlitSurface (GraphicsData.gfx_hud_stuff, &src, surface, NULL);
1478 	else SDL_BlitSurface (GraphicsData.gfx_menu_stuff, &src, surface, NULL);
1479@@ -716,7 +716,6 @@
1480 	renewButtonSurface();
1481 	draw();
1482 	Video.draw();
1483-	mouse->draw (false, screen);
1484 }
1485
1486 int cMenuButton::getTextYOffset() const
1487@@ -899,7 +898,6 @@
1488 	}
1489
1490 	Video.draw();
1491-	mouse->draw (false, screen);
1492 }
1493
1494 void cMenuDestroyButton::animationCallback()
1495@@ -1048,7 +1046,7 @@
1496 	}
1497 	if (src.w > 0)
1498 	{
1499-		surface = SDL_CreateRGBSurface (Video.getSurfaceType(), src.w, src.h, Video.getColDepth(), 0, 0, 0, 0);
1500+		surface = SDL_CreateRGBSurface (0, src.w, src.h, Video.getColDepth(), 0, 0, 0, 0);
1501 		if (buttonType >= CHECKBOX_HUD_INDEX_00 && buttonType <= CHECKBOX_HUD_PLAYERS) SDL_BlitSurface (GraphicsData.gfx_hud_stuff, &src, surface, NULL);
1502 		else SDL_BlitSurface (GraphicsData.gfx_menu_stuff, &src, surface, NULL);
1503 	}
1504@@ -1070,7 +1068,6 @@
1505 	}
1506 	draw();
1507 	Video.draw();
1508-	mouse->draw (false, screen);
1509 	return true;
1510 }
1511
1512@@ -1112,7 +1109,7 @@
1513 			font->showText (position.x, position.y, text, fontType);
1514 			if (checked)
1515 			{
1516-				const Uint32 selection_color (0x00E3DACF);
1517+				const Uint32 selection_color (0xFFE3DACF);
1518 				const SDL_Rect dest = {Sint16 (position.x - 2), Sint16 (position.y - 1), Uint16 (position.w + 5), Uint16 (position.h + 2) };
1519 				DrawRectangle (buffer, dest, selection_color);
1520 			}
1521@@ -1209,7 +1206,7 @@
1522
1523 void cMenuRadioGroup::clicked (void* parent)
1524 {
1525-	mouse->GetPos();
1526+	mouse->updatePos();
1527 	for (unsigned int i = 0; i < buttonList.size(); i++)
1528 	{
1529 		if (buttonList[i]->overItem (mouse->x, mouse->y))
1530@@ -1252,8 +1249,8 @@
1531 void cMenuUnitListItem::init()
1532 {
1533 	const int UNIT_IMAGE_SIZE = 32;
1534-	surface = SDL_CreateRGBSurface (SDL_SRCCOLORKEY, UNIT_IMAGE_SIZE, UNIT_IMAGE_SIZE, Video.getColDepth(), 0, 0, 0, 0);
1535-	SDL_SetColorKey (surface, SDL_SRCCOLORKEY, 0x00FF00FF);
1536+	surface = SDL_CreateRGBSurface (0, UNIT_IMAGE_SIZE, UNIT_IMAGE_SIZE, Video.getColDepth(), 0, 0, 0, 0);
1537+	SDL_SetColorKey (surface, SDL_TRUE, 0x00FF00FF);
1538 	SDL_FillRect (surface, NULL, 0x00FF00FF);
1539 	SDL_Rect dest = {0, 0, 0, 0};
1540
1541@@ -1288,7 +1285,7 @@
1542 	if (selected)
1543 	{
1544 		const SDL_Rect dest = { Sint16 (position.x - 4), Sint16 (position.y - 4), 38, 38};
1545-		DrawSelectionCorner (buffer, dest, 8, 0x00E0E0E0);
1546+		DrawSelectionCorner (buffer, dest, 8, 0xFFE0E0E0);
1547 	}
1548
1549 	switch (displayType)
1550@@ -1484,7 +1481,7 @@
1551
1552 void cMenuUnitsList::released (void* parent)
1553 {
1554-	mouse->GetPos();
1555+	mouse->updatePos();
1556 	for (int i = offset; i < offset + maxDisplayUnits; i++)
1557 	{
1558 		if (i >= (int) unitsList.size()) break;
1559@@ -1674,7 +1671,7 @@
1560 	dest.x += src.w + 3;
1561 	SDL_Rect mark = { Sint16 (dest.x - src.w / 2), dest.y, 1, src.h };
1562
1563-	SDL_FillRect (buffer, &mark, 0xFC0000);
1564+	SDL_FillRect (buffer, &mark, 0xFFFC0000);
1565
1566 	if (symType == MENU_SYMBOLS_METAL)
1567 	{
1568@@ -1905,11 +1902,11 @@
1569 	if (drawLines)
1570 	{
1571 		SDL_Rect lineRect = { Sint16 (position.x + 2), Sint16 (position.y + 14), 153, 1 };
1572-		SDL_FillRect (buffer, &lineRect, 0x743904);
1573+		SDL_FillRect (buffer, &lineRect, 0xFF743904);
1574 		lineRect.y += 12;
1575-		SDL_FillRect (buffer, &lineRect, 0x743904);
1576+		SDL_FillRect (buffer, &lineRect, 0xFF743904);
1577 		lineRect.y += 12;
1578-		SDL_FillRect (buffer, &lineRect, 0x743904);
1579+		SDL_FillRect (buffer, &lineRect, 0xFF743904);
1580 	}
1581 	if (unit == NULL) return;
1582 	const sUnitData* data = &unit->data;
1583@@ -2127,7 +2124,7 @@
1584 	const int DETAIL_COLUMN_1 = dest.x + 27;
1585 	const int DETAIL_COLUMN_2 = dest.x + 42;
1586 	const int DETAIL_COLUMN_3 = dest.x + 95;
1587-#define DETAIL_DOLINEBREAK dest.y = y + 14; SDL_FillRect (buffer, &dest, 0xFC0000); y += 19;
1588+#define DETAIL_DOLINEBREAK dest.y = y + 14; SDL_FillRect (buffer, &dest, 0xFFFC0000); y += 19;
1589
1590 	if (data->canAttack)
1591 	{
1592@@ -2349,8 +2346,8 @@
1593 void cMenuMaterialBar::generateSurface()
1594 {
1595 	SDL_Rect src = { 114, 336, position.w, position.h };
1596-	surface = SDL_CreateRGBSurface (Video.getSurfaceType() | SDL_SRCCOLORKEY, src.w, src.h, Video.getColDepth(), 0, 0, 0, 0);
1597-	SDL_SetColorKey (surface, SDL_SRCCOLORKEY, 0xFF00FF);
1598+	surface = SDL_CreateRGBSurface (0, src.w, src.h, Video.getColDepth(), 0, 0, 0, 0);
1599+	SDL_SetColorKey (surface, SDL_TRUE, 0xFF00FF);
1600 	SDL_FillRect (surface, NULL, 0xFF00FF);
1601
1602 	switch (materialType)
1603@@ -2568,11 +2565,11 @@
1604 	position.h = src.h;
1605 	mouseXOff = mouseYOff = 0;
1606
1607-	surface = SDL_CreateRGBSurface (Video.getSurfaceType() | SDL_SRCCOLORKEY, position.w, position.h, Video.getColDepth(), 0, 0, 0, 0);
1608+	surface = SDL_CreateRGBSurface (0, position.w, position.h, Video.getColDepth(), 0, 0, 0, 0);
1609 	SDL_FillRect (surface, NULL, 0xFF00FF);
1610 	if (scrollerType == SCROLLER_TYPE_HUD_ZOOM) SDL_BlitSurface (GraphicsData.gfx_hud_stuff, &src, surface, NULL);
1611 	else SDL_BlitSurface (GraphicsData.gfx_menu_stuff, &src, surface, NULL);
1612-	SDL_SetColorKey (surface, SDL_SRCCOLORKEY, 0xFF00FF);
1613+	SDL_SetColorKey (surface, SDL_TRUE, 0xFF00FF);
1614 }
1615
1616 void cMenuScroller::draw()
1617@@ -2663,7 +2660,7 @@
1618 {
1619 	SDL_Rect src = { 234, 1, 16, 48};
1620 	SDL_Rect dest = { 0, 0, 0, 0 };
1621-	surface = SDL_CreateRGBSurface (Video.getSurfaceType(), 16, position.h - 28, Video.getColDepth(), 0, 0, 0, 0);
1622+	surface = SDL_CreateRGBSurface (0, 16, position.h - 28, Video.getColDepth(), 0, 0, 0, 0);
1623 	do
1624 	{
1625 		if (position.h - 28 - dest.y < 48) src.h = position.h - 28 - dest.x;
1626@@ -2961,7 +2958,7 @@
1627 	}
1628 }
1629
1630-bool cMenuLineEdit::handleKeyInput (SDL_keysym keysym, const string& ch, void* parent)
1631+bool cMenuLineEdit::handleKeyInput (const SDL_Keysym& keysym, cMenu* parent)
1632 {
1633 	if (readOnly) return false;
1634
1635@@ -2995,28 +2992,7 @@
1636 			if (wasKeyInput) wasKeyInput (parent);
1637 			break;
1638 		default: // no special key - handle as normal character:
1639-			if (keysym.unicode >= 32)
1640-			{
1641-				if (keysym.unicode >= 48 && keysym.unicode <= 57)
1642-				{
1643-					if (!takeNumerics) break;
1644-				}
1645-				else if (!takeChars) break;
1646-
1647-				text.insert (cursorPos, ch);
1648-				if (cursorPos < (int) text.length()) doPosIncrease (cursorPos, cursorPos);
1649-				if (cursorPos >= endOffset)
1650-				{
1651-					doPosIncrease (endOffset, endOffset);
1652-					while (font->getTextWide (text.substr (startOffset, endOffset - startOffset), fontType) > position.w - getBorderSize()) doPosIncrease (startOffset, startOffset);
1653-				}
1654-				else
1655-				{
1656-					if (font->getTextWide (text.substr (startOffset, endOffset - startOffset), fontType) > position.w - getBorderSize()) doPosDecrease (endOffset);
1657-					else doPosIncrease (endOffset, cursorPos);
1658-				}
1659-				if (wasKeyInput) wasKeyInput (parent);
1660-			}
1661+			addText (keysym, parent);
1662 			break;
1663 	}
1664 	parentMenu->draw();
1665@@ -3023,6 +2999,34 @@
1666 	return true;
1667 }
1668
1669+void cMenuLineEdit::addText (const SDL_Keysym& keysym, cMenu* parent)
1670+{
1671+	if (keysym.sym >= 32)
1672+	{
1673+		if (keysym.sym >= 48 && keysym.sym <= 57)
1674+		{
1675+			if (!takeNumerics) return;
1676+		}
1677+		else if (!takeChars) return;
1678+
1679+		std::string ch = cInput::getUTF16Char (keysym.sym);
1680+
1681+		text.insert (cursorPos, ch);
1682+		if (cursorPos < (int) text.length()) doPosIncrease (cursorPos, cursorPos);
1683+		if (cursorPos >= endOffset)
1684+		{
1685+			doPosIncrease (endOffset, endOffset);
1686+			while (font->getTextWide (text.substr (startOffset, endOffset - startOffset), fontType) > position.w - getBorderSize()) doPosIncrease (startOffset, startOffset);
1687+		}
1688+		else
1689+		{
1690+			if (font->getTextWide (text.substr (startOffset, endOffset - startOffset), fontType) > position.w - getBorderSize()) doPosDecrease (endOffset);
1691+			else doPosIncrease (endOffset, cursorPos);
1692+		}
1693+		if (wasKeyInput) wasKeyInput (parent);
1694+	}
1695+}
1696+
1697 void cMenuLineEdit::setReturnPressedFunc (void (*returnPressed_) (void*))
1698 {
1699 	returnPressed = returnPressed_;
1700@@ -3038,9 +3042,9 @@
1701 {
1702 	if (Video.getResolutionX() - HUD_TOTAL_WIDTH - 20 < 60) return;
1703
1704-	surface = SDL_CreateRGBSurface (Video.getSurfaceType(), Video.getResolutionX() - HUD_TOTAL_WIDTH - 20, 48, Video.getColDepth(), 0, 0, 0, 0);
1705+	surface = SDL_CreateRGBSurface (0, Video.getResolutionX() - HUD_TOTAL_WIDTH - 20, 48, Video.getColDepth(), 0, 0, 0, 0);
1706 	SDL_FillRect (surface, NULL, 0xFF00FF);
1707-	SDL_SetColorKey (surface, SDL_SRCCOLORKEY, 0xFF00FF);
1708+	SDL_SetColorKey (surface, SDL_TRUE, 0xFF00FF);
1709
1710 	SDL_Rect src = { 0, 0, 30, 48 };
1711 	SDL_Rect dest = { 0, 0, 0, 0 };
1712@@ -3118,14 +3122,14 @@
1713 {
1714 	SDL_Rect src = { 10, 0, 10, 10 };
1715
1716-	AutoSurface readySurface (SDL_CreateRGBSurface (Video.getSurfaceType() | SDL_SRCCOLORKEY, src.w, src.h, Video.getColDepth(), 0, 0, 0, 0));
1717-	SDL_SetColorKey (readySurface, SDL_SRCCOLORKEY, 0xFF00FF);
1718+	AutoSurface readySurface (SDL_CreateRGBSurface (0, src.w, src.h, Video.getColDepth(), 0, 0, 0, 0));
1719+	SDL_SetColorKey (readySurface, SDL_TRUE, 0xFF00FF);
1720 	SDL_FillRect (readySurface, NULL, 0xFF00FF);
1721 	SDL_BlitSurface (GraphicsData.gfx_player_ready, &src, readySurface, NULL);
1722
1723 	src.x -= 10;
1724-	AutoSurface notReadySurface (SDL_CreateRGBSurface (Video.getSurfaceType() | SDL_SRCCOLORKEY, src.w, src.h, Video.getColDepth(), 0, 0, 0, 0));
1725-	SDL_SetColorKey (notReadySurface, SDL_SRCCOLORKEY, 0xFF00FF);
1726+	AutoSurface notReadySurface (SDL_CreateRGBSurface (0, src.w, src.h, Video.getColDepth(), 0, 0, 0, 0));
1727+	SDL_SetColorKey (notReadySurface, SDL_TRUE, 0xFF00FF);
1728 	SDL_FillRect (notReadySurface, NULL, 0xFF00FF);
1729 	SDL_BlitSurface (GraphicsData.gfx_player_ready, &src, notReadySurface, NULL);
1730
1731@@ -3137,7 +3141,7 @@
1732 			if ( (*players) [i]->isReady()) playerReadys[index]->setImage (readySurface);
1733 			else playerReadys[index]->setImage (notReadySurface);
1734
1735-			AutoSurface colorSurface (SDL_CreateRGBSurface (Video.getSurfaceType() | SDL_SRCCOLORKEY, src.w, src.h, Video.getColDepth(), 0, 0, 0, 0));
1736+			AutoSurface colorSurface (SDL_CreateRGBSurface (0, src.w, src.h, Video.getColDepth(), 0, 0, 0, 0));
1737 			SDL_BlitSurface ( (*players) [i]->getColorSurface(), &src, colorSurface, NULL);
1738 			playerColors[index]->setImage (colorSurface);
1739
1740@@ -3420,7 +3424,7 @@
1741 			position.w = src.w;
1742 			position.h = src.h;
1743
1744-			surface = SDL_CreateRGBSurface (Video.getSurfaceType(), src.w, src.h, Video.getColDepth(), 0, 0, 0, 0);
1745+			surface = SDL_CreateRGBSurface (0, src.w, src.h, Video.getColDepth(), 0, 0, 0, 0);
1746 			SDL_BlitSurface (GraphicsData.gfx_menu_stuff, &src, surface, NULL);
1747
1748 			scroller = new cMenuScroller (x - 7, y - 7, cMenuScroller::SCROLLER_TYPE_HORI, this, &scrollerMoved);
1749@@ -3612,7 +3616,7 @@
1750 	{
1751 		const int selIndex = selected - index * maxItems;
1752 		const SDL_Rect rect = {Sint16 (position.x + 13), Sint16 (position.y + 26 + 55 * selIndex), 38, 38};
1753-		DrawSelectionCorner (buffer, rect, 8, 0x00E0E0E0);
1754+		DrawSelectionCorner (buffer, rect, 8, 0xFFE0E0E0);
1755 	}
1756 }
1757
1758@@ -3941,7 +3945,7 @@
1759 		{
1760 			int selIndex = selected - index * maxItems;
1761 			const SDL_Rect rect = {Sint16 (position.x + 15), Sint16 (position.y + 23 + 55 * selIndex), 450, 53 };
1762-			DrawRectangle (buffer, rect, 0x00E0E0E0);
1763+			DrawRectangle (buffer, rect, 0xFFE0E0E0);
1764 		}
1765 	}
1766 }
1767@@ -4112,8 +4116,8 @@
1768 	float zoomFactor = (float) UNIT_IMAGE_SIZE / (unit->data.isBig ? 128.0f : 64.0f);
1769 	SDL_Rect dest = { 0, 0, 0, 0};
1770
1771-	SDL_Surface* surface = SDL_CreateRGBSurface (SDL_SRCCOLORKEY, UNIT_IMAGE_SIZE, UNIT_IMAGE_SIZE, Video.getColDepth(), 0, 0, 0, 0);
1772-	SDL_SetColorKey (surface, SDL_SRCCOLORKEY, 0xFF00FF);
1773+	SDL_Surface* surface = SDL_CreateRGBSurface (0, UNIT_IMAGE_SIZE, UNIT_IMAGE_SIZE, Video.getColDepth(), 0, 0, 0, 0);
1774+	SDL_SetColorKey (surface, SDL_TRUE, 0xFF00FF);
1775 	//SDL_FillRect (surface, NULL, 0xFF00FF);
1776
1777 	if (unit->isABuilding())
1778Index: menuitems.h
1779===================================================================
1780--- menuitems.h	(revision 3446)
1781+++ menuitems.h	(working copy)
1782@@ -212,7 +212,7 @@
1783 	 *@param ch the encoded key
1784 	 *@param parent pointer to the calling menu
1785 	 */
1786-	virtual bool handleKeyInput (SDL_keysym keysym, const std::string& ch, void* parent) { return false; }
1787+	virtual bool handleKeyInput (const SDL_Keysym& keysym, cMenu* parent) { return false; }
1788
1789
1790 	/**
1791@@ -1028,6 +1028,7 @@
1792 	bool readOnly;
1793 	bool takeChars, takeNumerics;
1794
1795+	void addText (const SDL_Keysym& keysym, cMenu* parent);
1796 	void resetTextPosition();
1797 	void doPosIncrease (int& value, int pos);
1798 	void doPosDecrease (int& pos);
1799@@ -1055,7 +1056,7 @@
1800 	void setText (const std::string& text_);
1801 	const std::string& getText() const;
1802 	void setSize (int w, int h);
1803-	virtual bool handleKeyInput (SDL_keysym keysym, const std::string& ch, void* parent);
1804+	virtual bool handleKeyInput (const SDL_Keysym& keysym, cMenu* parent);
1805
1806 	void setReturnPressedFunc (void (*returnPressed_) (void*));
1807 };
1808Index: menus.cpp
1809===================================================================
1810--- menus.cpp	(revision 3450)
1811+++ menus.cpp	(working copy)
1812@@ -234,7 +234,6 @@
1813 	end = false;
1814 	terminate = false;
1815 	activeItem = NULL;
1816-	drawnEveryFrame = false;
1817
1818 	lastScreenResX = Video.getResolutionX();
1819 	lastScreenResY = Video.getResolutionY();
1820@@ -292,10 +291,13 @@
1821 		case MNU_BG_BLACK:
1822 			// fill the whole screen with black to prevent
1823 			// old garbage from menus that don't support resolutions > 640x480
1824-			SDL_FillRect (buffer, NULL, 0x000000);
1825+			SDL_FillRect (buffer, NULL, 0xFF000000);
1826 			break;
1827 		case MNU_BG_ALPHA:
1828-			if (cSettings::getInstance().isAlphaEffects() && firstDraw) SDL_BlitSurface (GraphicsData.gfx_shadow, NULL, buffer, NULL);
1829+			if (cSettings::getInstance().isAlphaEffects() && firstDraw)
1830+				SDL_BlitSurface (GraphicsData.gfx_shadow, NULL, buffer, NULL);
1831+			else
1832+				SDL_FillRect (buffer, NULL, SDL_MapRGBA (buffer->format, 0, 0, 0, 0));
1833 			break;
1834 		case MNU_BG_TRANSPARENT:
1835 			// do nothing here
1836@@ -318,9 +320,7 @@
1837
1838 	if (showScreen)
1839 	{
1840-		if (drawnEveryFrame) mouse->draw (true, buffer);
1841 		Video.draw();
1842-		if (!drawnEveryFrame) mouse->draw (false, screen);
1843 	}
1844 }
1845
1846@@ -327,8 +327,6 @@
1847 //------------------------------------------------------------------------------
1848 int cMenu::show (cClient* client)
1849 {
1850-	drawnEveryFrame = false;
1851-
1852 	mouse->SetCursor (CHand);
1853 	draw (true);
1854
1855@@ -357,11 +355,9 @@
1856 			lastResY = Video.getResolutionY();
1857 		}
1858
1859-		mouse->GetPos();
1860+		mouse->updatePos();
1861 		if (mouse->moved())
1862 		{
1863-			mouse->draw (true, screen);
1864-
1865 			for (unsigned int i = 0; i < menuItems.size(); i++)
1866 			{
1867 				cMenuItem* menuItem = menuItems[i];
1868@@ -406,7 +402,7 @@
1869 //------------------------------------------------------------------------------
1870 void cMenu::handleMouseInput (sMouseState mouseState)
1871 {
1872-	mouse->GetPos();
1873+	mouse->updatePos();
1874 	mouse->isDoubleClick = mouseState.isDoubleClick;
1875
1876 	for (size_t i = 0; i != menuItems.size(); ++i)
1877@@ -434,9 +430,9 @@
1878 }
1879
1880 //------------------------------------------------------------------------------
1881-void cMenu::handleKeyInput (SDL_KeyboardEvent& key, const string& ch)
1882+void cMenu::handleKeyInput (const SDL_KeyboardEvent& key)
1883 {
1884-	if (activeItem && key.state == SDL_PRESSED) activeItem->handleKeyInput (key.keysym, ch, this);
1885+	if (activeItem && key.state == SDL_PRESSED) activeItem->handleKeyInput (key.keysym, this);
1886 }
1887
1888 //------------------------------------------------------------------------------
1889@@ -539,7 +535,6 @@
1890 	menu->infoImage->setImage (surface);
1891 	menu->infoImage->draw();
1892 	Video.draw();
1893-	mouse->draw (false, screen);
1894 }
1895
1896 //------------------------------------------------------------------------------
1897@@ -1312,7 +1307,7 @@
1898 			const int MAPWINSIZE = 112;
1899 			const int SELECTED = 0x00C000;
1900 			const int UNSELECTED = 0x000000;
1901-			AutoSurface imageSurface (SDL_CreateRGBSurface (Video.getSurfaceType(), MAPWINSIZE + 8, MAPWINSIZE + 8, Video.getColDepth(), 0, 0, 0, 0));
1902+			AutoSurface imageSurface (SDL_CreateRGBSurface (0, MAPWINSIZE + 8, MAPWINSIZE + 8, Video.getColDepth(), 0, 0, 0, 0));
1903
1904 			if (selectedMapIndex == i + offset)
1905 			{
1906@@ -1461,7 +1456,7 @@
1907 			yCount = 1;
1908 		}
1909 		SDL_Surface* img = LoadPCX (clanLogoPaths[i].c_str());
1910-		SDL_SetColorKey (img, SDL_SRCCOLORKEY, 0xFF00FF);
1911+		SDL_SetColorKey (img, SDL_TRUE, 0xFF00FF);
1912 		clanImages[i] = new cMenuImage (position.x + 88 + xCount * 154 - (img ? (img->w / 2) : 0), position.y + 48 + yCount * 150, img);
1913 		clanImages[i]->setReleasedFunction (&clanSelected);
1914 		menuItems.push_back (clanImages[i]);
1915@@ -2215,9 +2210,9 @@
1916 	menu->landData.landingState = LANDING_POSITION_OK;
1917 	menu->backButton->setLocked (true);
1918 	{
1919-		AutoSurface circleSurface (SDL_CreateRGBSurface (Video.getSurfaceType() | SDL_SRCCOLORKEY, Video.getResolutionX() - 192, Video.getResolutionY() - 32, Video.getColDepth(), 0, 0, 0, 0));
1920+		AutoSurface circleSurface (SDL_CreateRGBSurface (0, Video.getResolutionX() - 192, Video.getResolutionY() - 32, Video.getColDepth(), 0, 0, 0, 0));
1921 		SDL_FillRect (circleSurface, NULL, 0xFF00FF);
1922-		SDL_SetColorKey (circleSurface, SDL_SRCCOLORKEY, 0xFF00FF);
1923+		SDL_SetColorKey (circleSurface, SDL_TRUE, 0xFF00FF);
1924
1925 		int posX = (int) (menu->landData.iLandX * fakx);
1926 		int posY = (int) (menu->landData.iLandY * faky);
1927@@ -2231,7 +2226,6 @@
1928
1929 	Video.draw();
1930 	mouse->SetCursor (CHand);
1931-	mouse->draw (false, screen);
1932
1933 	menu->hitPosition();
1934 }
1935@@ -2251,7 +2245,7 @@
1936 }
1937
1938 //------------------------------------------------------------------------------
1939-void cLandingMenu::handleKeyInput (SDL_KeyboardEvent& key, const string& ch)
1940+void cLandingMenu::handleKeyInput (const SDL_KeyboardEvent& key)
1941 {
1942 	if (key.keysym.sym == SDLK_ESCAPE && key.state == SDL_PRESSED)
1943 	{
1944@@ -2610,7 +2604,7 @@
1945 void cNetworkMenu::setColor (int color)
1946 {
1947 	SDL_Rect src = { 0, 0, 83, 10 };
1948-	AutoSurface colorSurface (SDL_CreateRGBSurface (Video.getSurfaceType() | SDL_SRCCOLORKEY, src.w, src.h, Video.getColDepth(), 0, 0, 0, 0));
1949+	AutoSurface colorSurface (SDL_CreateRGBSurface (0, src.w, src.h, Video.getColDepth(), 0, 0, 0, 0));
1950 	SDL_BlitSurface (OtherData.colors[color], &src, colorSurface, NULL);
1951 	colorImage->setImage (colorSurface);
1952 }
1953@@ -4608,7 +4602,7 @@
1954 				upgradeButtons[pos]->setLocked (true);
1955 			}
1956
1957-			SDL_Surface* surface = SDL_CreateRGBSurface (Video.getSurfaceType(), srcSurface->w, srcSurface->h, Video.getColDepth(), 0, 0, 0, 0);
1958+			SDL_Surface* surface = SDL_CreateRGBSurface (0, srcSurface->w, srcSurface->h, Video.getColDepth(), 0, 0, 0, 0);
1959 			SDL_BlitSurface (srcSurface, NULL, surface, NULL);
1960 			unitImages[pos]->setImage (surface);
1961
1962Index: menus.h
1963===================================================================
1964--- menus.h	(revision 3446)
1965+++ menus.h	(working copy)
1966@@ -192,7 +192,6 @@
1967 class cMenu
1968 {
1969 protected:
1970-	bool drawnEveryFrame;
1971 	/** When this is true the show-loop will be end and give 0 as return.
1972 	 * Should be used when the menu is closed by ok or done.
1973 	 */
1974@@ -276,7 +275,7 @@
1975 	 * delegates the keyinput to the active menuitem.
1976 	 *@author alzi
1977 	 */
1978-	virtual void handleKeyInput (SDL_KeyboardEvent& key, const std::string& ch);
1979+	virtual void handleKeyInput (const SDL_KeyboardEvent& key);
1980
1981 	/**
1982 	 * sends a netmessage to the given player.
1983@@ -657,7 +656,7 @@
1984 	cLandingMenu (cClient& client_, cStaticMap& map_);
1985
1986 private:
1987-	virtual void handleKeyInput (SDL_KeyboardEvent& key, const std::string& ch);
1988+	virtual void handleKeyInput (const SDL_KeyboardEvent& key);
1989 	virtual void handleNetMessages();
1990
1991 	void handleNetMessage (cNetMessage* message);
1992Index: mouse.cpp
1993===================================================================
1994--- mouse.cpp	(revision 3442)
1995+++ mouse.cpp	(working copy)
1996@@ -16,68 +16,33 @@
1997  *   Free Software Foundation, Inc.,                                       *
1998  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
1999  ***************************************************************************/
2000+
2001 #include "mouse.h"
2002+
2003 #include "main.h"
2004 #include "client.h"
2005 #include "settings.h"
2006 #include "hud.h"
2007
2008+#include <SDL.h>
2009
2010-cMouse::cMouse()
2011+cMouse::cMouse() : sdlCursor (NULL)
2012 {
2013-	visible = false;
2014 	cur = NULL;
2015-	LastX = -100;
2016-	LastY = -100;
2017 	x = 0;
2018 	y = 0;
2019 	isDoubleClick = false;
2020-	prevScreenX = 0;
2021-	prevScreenY = 0;
2022-
2023-	DrawX = 0;
2024-	DrawY = 0;
2025 }
2026
2027-// Malt die Maus, und wenn draw_back gesetzt ist, auch den alten Hintergrund:
2028-void cMouse::draw (bool draw_back, SDL_Surface* sf)
2029+cMouse::~cMouse()
2030 {
2031-	if (!visible || cur == NULL) return;
2032-	GetPos();
2033-
2034-	// restore old background
2035-	if (back && draw_back && LastX != -100)
2036-	{
2037-		SDL_Rect dest;
2038-		dest.x = LastX;
2039-		dest.y = LastY;
2040-		SDL_BlitSurface (back, NULL, sf, &dest);
2041-
2042-		SDL_UpdateRect (sf, dest.x, dest.y, dest.w, dest.h);
2043-	}
2044-
2045-	//change size of back surface if necessary, e.g. when the mouse cursor has changed
2046-	if (!back || back->h != cur->h || back->w != cur->w)
2047-	{
2048-		back = SDL_CreateRGBSurface (Video.getSurfaceType(), cur->w, cur->h, 32, 0, 0, 0, 0);
2049-	}
2050-
2051-	// store new background
2052-	GetBack (sf);
2053-	SDL_Rect dest;
2054-	dest.x = DrawX;
2055-	dest.y = DrawY;
2056-	LastX = DrawX;
2057-	LastY = DrawY;
2058-
2059-	//draw mouse
2060-	SDL_BlitSurface (cur, NULL, sf, &dest);
2061-	SDL_UpdateRect (sf, dest.x, dest.y, dest.w, dest.h);
2062+	if (sdlCursor) SDL_FreeCursor (sdlCursor);
2063 }
2064
2065 bool cMouse::SetCursor (eCursor const typ)
2066 {
2067 	const SDL_Surface* const lastCur = cur;
2068+
2069 	switch (typ)
2070 	{
2071 		default:
2072@@ -106,56 +71,50 @@
2073 		case CDisable:   cur = GraphicsData.gfx_Cdisable;    break;
2074 		case CActivate:  cur = GraphicsData.gfx_Cactivate;   break;
2075 	}
2076-	return lastCur != cur;
2077+	if (lastCur == cur)
2078+	{
2079+		return false;
2080+	}
2081+	if (sdlCursor) SDL_FreeCursor (sdlCursor);
2082+	int hotx = 0;
2083+	int hoty = 0;
2084+	getCursorOffset (hotx, hoty);
2085+	sdlCursor = SDL_CreateColorCursor (cur, hotx, hoty);
2086+	SDL_SetCursor (sdlCursor);
2087+	return true;
2088 }
2089
2090-// Liest den Hintergrund in das Back-Surface ein:
2091-void cMouse::GetBack (SDL_Surface* sf)
2092-{
2093-	SDL_Rect scr;
2094-	GetPos();
2095-	scr.x = DrawX;
2096-	scr.y = DrawY;
2097-	scr.w = back->w;
2098-	scr.h = back->h;
2099-	SDL_BlitSurface (sf, &scr, back, NULL);
2100-}
2101-
2102-void cMouse::restoreBack (SDL_Surface* sf)
2103-{
2104-	SDL_Rect dest;
2105-	dest.x = LastX;
2106-	dest.y = LastY;
2107-	SDL_BlitSurface (back, NULL, sf, &dest);
2108-}
2109-
2110 //updates the internal mouse position
2111-void cMouse::GetPos()
2112+void cMouse::updatePos()
2113 {
2114 	SDL_GetMouseState (&x, &y);
2115-
2116-	// Cursor Offset bestimmen:
2117-	int offX;
2118-	int offY;
2119-
2120-	getCursorOffset (offX, offY);
2121-
2122-	DrawX = x + offX;
2123-	DrawY = y + offY;
2124 }
2125
2126 // gets the cursor offset. transforms screenspace to clickspace
2127 void cMouse::getCursorOffset (int& x, int& y) const
2128 {
2129-	if (cur == GraphicsData.gfx_Cselect || cur == GraphicsData.gfx_Chelp || cur == GraphicsData.gfx_Cmove || cur == GraphicsData.gfx_Cmove_draft || cur == GraphicsData.gfx_Cno || cur == GraphicsData.gfx_Ctransf || cur == GraphicsData.gfx_Cband || cur == GraphicsData.gfx_Cload || cur == GraphicsData.gfx_Cmuni || cur == GraphicsData.gfx_Crepair || cur == GraphicsData.gfx_Cactivate)
2130+	if (cur == GraphicsData.gfx_Cselect
2131+		|| cur == GraphicsData.gfx_Chelp
2132+		|| cur == GraphicsData.gfx_Cmove
2133+		|| cur == GraphicsData.gfx_Cmove_draft
2134+		|| cur == GraphicsData.gfx_Cno
2135+		|| cur == GraphicsData.gfx_Ctransf
2136+		|| cur == GraphicsData.gfx_Cband
2137+		|| cur == GraphicsData.gfx_Cload
2138+		|| cur == GraphicsData.gfx_Cmuni
2139+		|| cur == GraphicsData.gfx_Crepair
2140+		|| cur == GraphicsData.gfx_Cactivate)
2141 	{
2142-		x = -12;
2143-		y = -12;
2144+		x = 12;
2145+		y = 12;
2146 	}
2147-	else if (cur == GraphicsData.gfx_Cattack || cur == GraphicsData.gfx_Csteal || cur == GraphicsData.gfx_Cdisable || cur == GraphicsData.gfx_Cattackoor)
2148+	else if (cur == GraphicsData.gfx_Cattack
2149+			 || cur == GraphicsData.gfx_Csteal
2150+			 || cur == GraphicsData.gfx_Cdisable
2151+			 || cur == GraphicsData.gfx_Cattackoor)
2152 	{
2153-		x = -19;
2154-		y = -16;
2155+		x = 19;
2156+		y = 16;
2157 	}
2158 	else
2159 	{
2160@@ -175,6 +134,16 @@
2161 	return moved;
2162 }
2163
2164+void cMouse::Show()
2165+{
2166+	SDL_ShowCursor (true);
2167+}
2168+
2169+void cMouse::Hide()
2170+{
2171+	SDL_ShowCursor (false);
2172+}
2173+
2174 // Liefert die Koordinaten der Kachel unter der Maus:
2175 int cMouse::getKachelX (const cGameGUI& gameGUI) const
2176 {
2177Index: mouse.h
2178===================================================================
2179--- mouse.h	(revision 3442)
2180+++ mouse.h	(working copy)
2181@@ -19,12 +19,13 @@
2182 #ifndef mouseH
2183 #define mouseH
2184
2185-#include "autosurface.h"
2186 #include "defines.h"
2187-#include <SDL.h>
2188
2189 class cGameGUI;
2190+struct SDL_Surface;
2191+struct SDL_Cursor;
2192
2193+
2194 // Die Mauszeigertypen ///////////////////////////////////////////////////////
2195 enum eCursor {CHand, CNo, CSelect, CMove, CPfeil1, CPfeil2, CPfeil3, CPfeil4, CPfeil6, CPfeil7, CPfeil8, CPfeil9, CHelp, CAttack, CBand, CTransf, CLoad, CMuni, CRepair, CSteal, CDisable, CActivate, CMoveDraft, CAttackOOR};
2196
2197@@ -33,22 +34,16 @@
2198 {
2199 public:
2200 	cMouse();
2201+	~cMouse();
2202
2203-	void draw (bool draw_back, SDL_Surface* sf);
2204-
2205 	// Set a new cursor.
2206 	bool SetCursor (eCursor);
2207
2208-	void GetBack (SDL_Surface* sf);
2209-	/**
2210-	* Draws the currently stored background to sf
2211-	*/
2212-	void restoreBack (SDL_Surface* sf);
2213-	void GetPos();
2214+	void updatePos();
2215 	void getCursorOffset (int& x, int& y) const;
2216 	bool moved();
2217-	void Show() {LastX = -100; visible = true;}
2218-	void Hide() {visible = false;}
2219+	void Show();
2220+	void Hide();
2221 	/**
2222 	* return the X Coordinate of the Cursor on the map
2223 	*/
2224@@ -57,19 +52,14 @@
2225 	* return the Y Coordinate of the Cursor on the map
2226 	*/
2227 	int getKachelY (const cGameGUI& gameGUI) const;
2228-private:
2229-	bool visible; // Gibt an, ob die Maus angezeigt werden soll.
2230+
2231 public:
2232 	SDL_Surface* cur; // Current Cursor.
2233 private:
2234-	AutoSurface back; // Zum Speichern des Maushintergrundes.
2235+	SDL_Cursor* sdlCursor;
2236 public:
2237 	int x, y; /** the pixel position of the cursor on the map */
2238 	bool isDoubleClick;
2239-private:
2240-	int prevScreenX, prevScreenY;
2241-	int LastX, LastY; // Die letzte Position der Maus.
2242-	int DrawX, DrawY; // Die Position, an die die Maus gezeichnet werden soll.
2243 };
2244
2245 // Die Maus //////////////////////////////////////////////////////////////////
2246Index: mveplayer.cpp
2247===================================================================
2248--- mveplayer.cpp	(revision 3442)
2249+++ mveplayer.cpp	(working copy)
2250@@ -24,18 +24,19 @@
2251 /*	MVEPlayer.c - Plays 8-bit Interplay MVE multimedia files.
2252 	Author: jarli
2253 */
2254-#include "autosurface.h"
2255+
2256 #include "mveplayer.h"
2257-#include <assert.h>
2258+
2259 #include "main.h"
2260+#include "autoptr.h"
2261+#include "autosurface.h"
2262 #include "video.h"
2263
2264-#ifdef _MSC_VER
2265 #include <SDL.h>
2266-#else
2267-#include <SDL.h>
2268-#endif
2269
2270+#include <cassert>
2271+#include <vector>
2272+
2273 /* define (potentially) handled opcode types */
2274 #define STOP_PLAYBACK			0x00
2275 #define FETCH_NEXT_CHUNK		0x01
2276@@ -50,6 +51,13 @@
2277 #define SET_DECODING_MAP		0x0F
2278 #define VIDEO_DATA				0x11
2279
2280+#if 1 // TODO: [SDL2]: SDL_SetColors
2281+inline void SDL_SetColors(SDL_Surface* surface, SDL_Color* colors, int index, int size)
2282+{
2283+	SDL_SetPaletteColors(surface->format->palette, colors, index, size);
2284+}
2285+#endif
2286+
2287 /**************************/
2288 /* internally used macros */
2289 /**************************/
2290@@ -61,24 +69,23 @@
2291 /* internally used structures */
2292 /******************************/
2293
2294-typedef struct CHUNK
2295+struct chunk
2296 {
2297 	Uint16 length;
2298 	Uint16 type;
2299-} chunk;
2300+};
2301
2302-typedef struct OPCODE
2303+struct opcode
2304 {
2305 	Uint16 length;
2306 	Uint8 type;
2307 	Uint8 version;
2308-} opcode;
2309+};
2310
2311-typedef struct BUFSTRUCT
2312+struct mvebuffer
2313 {
2314-	Uint32 length;
2315-	Uint8* data;
2316-} mvebuffer;
2317+	std::vector<Uint8> data;
2318+};
2319
2320 /********************/
2321 /* global variables */
2322@@ -85,19 +92,26 @@
2323 /********************/
2324
2325 /* flow control flags */
2326-Uint8 QUITTING = 0, PAUSED = 0;
2327+static Uint8 QUITTING = 0;
2328+static Uint8 PAUSED = 0;
2329
2330 /* timer flags */
2331-Uint8 TIMER_CREATED	= 0, TIMER_INIT = 0;
2332+static Uint8 TIMER_CREATED = 0;
2333+static Uint8 TIMER_INIT = 0;
2334
2335 /* audio flags */
2336-Uint8 AUDIO_PLAYING = 0, AUDIO_COMPRESSED = 0, AUDIO_STEREO = 0, SAMPLESIZE16 = 0;
2337+static Uint8 AUDIO_PLAYING = 0;
2338+static Uint8 AUDIO_COMPRESSED = 0;
2339+static Uint8 AUDIO_STEREO = 0;
2340+static Uint8 SAMPLESIZE16 = 0;
2341
2342 /* screen mvebuffers */
2343-Uint8* v_backbuf = NULL, *frame_hot = NULL, *frame_cold = NULL;
2344+static std::vector<Uint8> v_backbuf;
2345+static Uint8* frame_hot = NULL;
2346+static Uint8* frame_cold = NULL;
2347
2348 /* target time between frames */
2349-float ms_per_frame = 0;
2350+static float ms_per_frame = 0;
2351
2352 /***********************/
2353 /* function prototypes */
2354@@ -125,22 +139,24 @@
2355 	char fileTestString[26];
2356
2357 	/* timer vars */
2358-	Uint32 timer_rate = 0, current_time = 0;
2359-	Uint16 timer_subdivision = 0;
2360+	Uint32 current_time = 0;
2361 	float start_time = 0;
2362
2363 	/* audio variables */
2364-	SDL_AudioSpec* desired = NULL;
2365+	AutoPtr<SDL_AudioSpec> desired;
2366 	Uint16 file_audio_flags = 0;
2367-	mvebuffer audio_mvebuffer, audio_data_read, temp_audio_mvebuffer;
2368+	mvebuffer audio_mvebuffer;
2369+	mvebuffer audio_data_read;
2370
2371 	/* video variables */
2372 	Uint32 screen_mvebuffer_size = 0;
2373-	Uint16 width_blocks = 0, height_blocks = 0;
2374-	Uint8* map = NULL, *video = NULL, *temp = NULL;
2375-	SDL_Surface* screen = NULL;
2376-	SDL_Rect movie_screen;
2377-	const SDL_VideoInfo* initial_vid_state;
2378+	Uint16 width_blocks = 0;
2379+	Uint16 height_blocks = 0;
2380+	std::vector<Uint8> map;
2381+	std::vector<Uint8> video;
2382+	SDL_Window* sdlWindow = NULL;
2383+	SDL_Renderer* sdlRenderer = NULL;
2384+	SDL_Texture* sdlTexture = NULL;
2385
2386 	/* file handle */
2387 	SDL_RWops* mve = NULL;
2388@@ -149,17 +165,6 @@
2389 	chunk ch;
2390 	opcode op;
2391
2392-	/* a counting var */
2393-	Uint16 i = 0;
2394-
2395-	/* initialize audio mvebuffers */
2396-	audio_mvebuffer.data = NULL;
2397-	audio_mvebuffer.length = 0;
2398-	audio_data_read.data = NULL;
2399-	audio_data_read.length = 0;
2400-	temp_audio_mvebuffer.data = NULL;
2401-	temp_audio_mvebuffer.length = 0;
2402-
2403 	/******************************************/
2404 	/* validate MVE, init SDL, and begin read */
2405 	/******************************************/
2406@@ -172,7 +177,7 @@
2407 		return UNABLE_TO_OPEN_FILE;
2408
2409 	/* read the first 26 bytes */
2410-	if (SDL_RWread (mve, fileTestString, sizeof (char), idlen) < 0)
2411+	if (!SDL_RWread (mve, fileTestString, sizeof (char), idlen))
2412 		return FILE_TOO_SHORT;
2413
2414 	/* validate MVE idstring */
2415@@ -191,10 +196,6 @@
2416 	if (op.type > 0x15 || op.version > 3)
2417 		return MVE_CORRUPT;
2418
2419-	//set window to center of screen
2420-	static char cVideoPos[] = "SDL_VIDEO_CENTERED=1";
2421-	putenv (cVideoPos);
2422-
2423 	/* See if SDL is already initialized by MAXR main (audio shouldn't be) */
2424 	if (audio)
2425 	{
2426@@ -209,10 +210,6 @@
2427 		if (SDL_WasInit (SDL_INIT_VIDEO | SDL_INIT_TIMER) != (SDL_INIT_VIDEO | SDL_INIT_TIMER))
2428 			return SDL_INIT_FAILURE;
2429
2430-	/* save initial video state; we'll restore at the end */
2431-	if (!fullscreen)
2432-		initial_vid_state = SDL_GetVideoInfo();
2433-
2434 	// hide mouse in fullscreen
2435 	if (fullscreen)
2436 		SDL_ShowCursor (SDL_DISABLE);
2437@@ -241,35 +238,33 @@
2438 		switch (op.type)
2439 		{
2440 			case STOP_PLAYBACK:
2441-
2442+			{
2443 				QUITTING = !QUITTING;
2444-
2445 				break;
2446-
2447+			}
2448 			case FETCH_NEXT_CHUNK:
2449-
2450+			{
2451 				if (!SDL_RWread (mve, &ch, sizeof (ch), 1))
2452 					return CHUNK_READ_FAILED;
2453-
2454 				break;
2455-
2456+			}
2457 			case CREATE_TIMER:
2458-
2459+			{
2460 				/* get timer rate (uint32) */
2461-				timer_rate = SDL_ReadLE32 (mve);
2462+				const Uint32 timer_rate = SDL_ReadLE32 (mve);
2463
2464 				/* get timer subdivision (uint16) */
2465-				timer_subdivision = SDL_ReadLE16 (mve);
2466+				const Uint16 timer_subdivision = SDL_ReadLE16 (mve);
2467
2468-				ms_per_frame = (float) (timer_rate * timer_subdivision / 1000.0);
2469+				ms_per_frame = timer_rate * timer_subdivision / 1000.0f;
2470
2471 				TIMER_CREATED = 1;
2472 				TIMER_INIT = 1;
2473
2474 				break;
2475-
2476+			}
2477 			case INIT_AUDIO_BUFFERS:
2478-
2479+			{
2480 				if (!audio)
2481 				{
2482 					/* strip opcode data; don't know how to catch errors here */
2483@@ -277,9 +272,8 @@
2484 					break;
2485 				}
2486
2487-
2488 				/* init sdl audio settings */
2489-				desired = (SDL_AudioSpec*) malloc (sizeof (SDL_AudioSpec));
2490+				desired = new SDL_AudioSpec;
2491
2492 				/* strip the unknown word out */
2493 				SDL_ReadLE16 (mve);
2494@@ -315,8 +309,10 @@
2495 				if (op.version == 1)
2496 					AUDIO_COMPRESSED = (file_audio_flags & 0x04 ? 1 : 0);
2497
2498-				/* we're going to abort if is compressed and (not stereo or not AUDIO_S16) because we don't know what to do */
2499-				/* besides, we've never seen such an MVE before... */
2500+				// we're going to abort if is compressed
2501+				// and (not stereo or not AUDIO_S16)
2502+				// because we don't know what to do
2503+				// besides, we've never seen such an MVE before...
2504 				if (AUDIO_COMPRESSED && (!AUDIO_STEREO || !SAMPLESIZE16))
2505 					return CANNOT_PROCESS_AUDIO;
2506
2507@@ -327,9 +323,9 @@
2508 					SDL_ReadLE16 (mve);
2509
2510 				break;
2511-
2512+			}
2513 			case START_AUDIO:
2514-
2515+			{
2516 				if (!audio)
2517 					break;
2518
2519@@ -339,15 +335,16 @@
2520 					SDL_PauseAudio (0);
2521 				}
2522 				break;
2523-
2524+			}
2525 			case INIT_VIDEO_BUFFERS:
2526-
2527-				/* get the requested dimensions
2528-				note: this is in 8x8 pixel chunks so multiply by 8 to get requested screen pixels*/
2529+			{
2530+				// get the requested dimensions
2531+				// note: this is in 8x8 pixel chunks
2532+				// so multiply by 8 to get requested screen pixels
2533 				width_blocks = SDL_ReadLE16 (mve);
2534 				height_blocks = SDL_ReadLE16 (mve);
2535
2536-				/* ditch the rest of the opcode data*/
2537+				// ditch the rest of the opcode data
2538 				if (op.version > 0)
2539 				{
2540 					SDL_ReadLE16 (mve);
2541@@ -362,63 +359,56 @@
2542 				}
2543
2544 				/* initialize video mvebuffer to the actual movie dimensions */
2545-				frame_buf = SDL_CreateRGBSurface (Video.getSurfaceType(), width_blocks << 3, height_blocks << 3, 8, 0, 0, 0, 0);
2546+				frame_buf = SDL_CreateRGBSurface (0, width_blocks << 3, height_blocks << 3, 8, 0, 0, 0, 0);
2547
2548 				/* init movie screen rect for fullscreen purposes */
2549-				movie_screen.x = (screen->w - frame_buf->w) >> 1;
2550-				movie_screen.y = (screen->h - frame_buf->h) >> 1;
2551+				//movie_screen.x = (screen->w - frame_buf->w) >> 1;
2552+				//movie_screen.y = (screen->h - frame_buf->h) >> 1;
2553
2554-				/* erase old video backmvebuffer */
2555-				free (v_backbuf);
2556-
2557-				/* allocate memory for the backmvebuffers sufficient for the screen pixel mvebuffer */
2558+				// allocate memory for the backmvebuffers sufficient
2559+				// for the screen pixel mvebuffer
2560 				screen_mvebuffer_size = frame_buf->h * frame_buf->w;
2561
2562-				v_backbuf = (Uint8*) calloc (1, screen_mvebuffer_size << 1);
2563-				assert (v_backbuf);
2564+				v_backbuf.resize (screen_mvebuffer_size << 1);
2565
2566-				frame_hot = v_backbuf;
2567-				frame_cold = v_backbuf + screen_mvebuffer_size;
2568+				frame_hot = v_backbuf.data();
2569+				frame_cold = v_backbuf.data() + screen_mvebuffer_size;
2570
2571 				break;
2572-
2573+			}
2574 			case SEND_BUFFER_TO_DISPLAY:
2575-
2576+			{
2577 				/* write the decoded data to the frame_buf */
2578 				memcpy (frame_buf->pixels, frame_hot, screen_mvebuffer_size);
2579
2580-				/* send the mvebuffer to the screen mvebuffer */
2581-				if (SDL_MUSTLOCK (screen))
2582-					SDL_LockSurface (screen);
2583+				// TODO: [SDL2] replace SDL_CreateTextureFromSurface ?
2584+				sdlTexture = SDL_CreateTextureFromSurface(sdlRenderer, frame_buf);
2585+				//SDL_UpdateTexture(sdlTexture, NULL, frame_buf->pixels, frame_buf->pitch);
2586
2587-				if (fullscreen)
2588-					SDL_SoftStretch (frame_buf, NULL, screen, NULL);
2589-				else
2590-					SDL_BlitSurface (frame_buf, NULL, screen, &movie_screen);
2591+				SDL_RenderCopy(sdlRenderer, sdlTexture, NULL, NULL);
2592
2593-				if (SDL_MUSTLOCK (screen))
2594-					SDL_UnlockSurface (screen);
2595-
2596-				/* increment start time - this is now our target frame output time */
2597+				// increment start time
2598+				// this is now our target frame output time
2599 				start_time += ms_per_frame;
2600
2601 				/* what time is it now? */
2602 				current_time = SDL_GetTicks();
2603
2604-				/* if there's time to next scheduled update, force delay to our target output time */
2605+				// if there's time to next scheduled update,
2606+				// force delay to our target output time
2607 				if (current_time < start_time)
2608 					SDL_Delay ( (Uint32) (start_time - current_time));
2609
2610 				/* update the screen */
2611-				SDL_UpdateRect (screen, 0, 0, 0, 0);
2612+				SDL_RenderPresent(sdlRenderer);
2613
2614 				/* strip opcode data; don't know how to catch errors here */
2615 				mve->seek (mve, op.length, SEEK_CUR);
2616
2617 				break;
2618-
2619+			}
2620 			case AUDIO_FRAME:
2621-
2622+			{
2623 				if (!audio)
2624 				{
2625 					/* strip opcode data; don't know how to catch errors here */
2626@@ -430,18 +420,22 @@
2627 				SDL_ReadLE16 (mve);
2628 				SDL_ReadLE16 (mve);
2629
2630-				/* lock SDL out of the audio_mvebuffer; we'll release at the end */
2631+				// lock SDL out of the audio_mvebuffer;
2632+				// we'll release at the end
2633 				SDL_LockAudio();
2634
2635 				if (AUDIO_COMPRESSED)
2636 				{
2637-					/* send in the raw data via audio_data_read; it will be returned the same way */
2638-					/* read in the compressed data (should be op.length - 4 [the 4 being seq-index and stream-mask]) */
2639-					audio_data_read.length =  op.length - 4;
2640-					audio_data_read.data = (Uint8*) malloc (audio_data_read.length);
2641-					assert (audio_data_read.data != NULL);
2642+					// send in the raw data via audio_data_read;
2643+					// it will be returned the same way
2644
2645-					if (SDL_RWread (mve, audio_data_read.data, audio_data_read.length, 1) < 0)
2646+					// read in the compressed data
2647+					// (should be op.length - 4
2648+					//  [the 4 being seq-index and stream-mask])
2649+					const Uint32 length = op.length - 4;
2650+					audio_data_read.data.resize(length);
2651+
2652+					if (!SDL_RWread (mve, audio_data_read.data.data(), length, 1))
2653 						return AUDIO_FRAME_READ_FAILURE;
2654 					MVEPlayerDecodeAudio (&audio_data_read);
2655 				}
2656@@ -448,84 +442,96 @@
2657 				else
2658 				{
2659 					/* get the stream length */
2660-					audio_data_read.length = SDL_ReadLE16 (mve);
2661+					const Uint32 length = SDL_ReadLE16 (mve);
2662
2663 					/* allocate memory sufficient for the data read */
2664-					audio_data_read.data = (Uint8*) malloc (audio_data_read.length);
2665-					assert (audio_data_read.data != NULL);
2666+					audio_data_read.data.resize (length);
2667
2668 					/* get audio data */
2669-					if (SDL_RWread (mve, audio_data_read.data, audio_data_read.length, 1) < 0)
2670+					if (!SDL_RWread (mve, audio_data_read.data.data(), length, 1))
2671 						return AUDIO_FRAME_READ_FAILURE;
2672 				}
2673-				/* at this point, we have uncompressed audio in audio_data_read, along with appropriate lengths */
2674+				// at this point, we have uncompressed audio in audio_data_read,
2675+				// along with appropriate lengths
2676
2677-				/* create temp_audio_mvebuffer the size of old audio mvebuffer + new audio data */
2678-				temp_audio_mvebuffer.length = audio_data_read.length + audio_mvebuffer.length;
2679-				temp_audio_mvebuffer.data = (Uint8*) malloc (temp_audio_mvebuffer.length);
2680-				assert (temp_audio_mvebuffer.data != NULL);
2681+				// create temp_audio_mvebuffer
2682+				// the size of old audio mvebuffer + new audio data
2683+				mvebuffer temp_audio_mvebuffer;
2684+				temp_audio_mvebuffer.data.resize (audio_data_read.data.size() + audio_mvebuffer.data.size());
2685
2686 				/* copy old audio mvebuffer to temp_audio_mvebuffer */
2687-				memcpy (temp_audio_mvebuffer.data, audio_mvebuffer.data, audio_mvebuffer.length);
2688+				std::copy(audio_mvebuffer.data.begin(), audio_mvebuffer.data.end(),
2689+						  temp_audio_mvebuffer.data.begin());
2690
2691 				/* append new data to temp_audio_mvebuffer */
2692-				memcpy (temp_audio_mvebuffer.data + audio_mvebuffer.length, audio_data_read.data, audio_data_read.length);
2693+				std::copy (audio_data_read.data.begin(), audio_data_read.data.end(),
2694+						   temp_audio_mvebuffer.data.begin() + audio_mvebuffer.data.size());
2695
2696-				/* free audio mvebuffer */
2697-				free (audio_mvebuffer.data);
2698-
2699-				/* temp_audio_mvebuffer has the requested data, and audio_mvebuffer needs to have it. */
2700+				// temp_audio_mvebuffer has the requested data,
2701+				// and audio_mvebuffer needs to have it.
2702 				audio_mvebuffer.data = temp_audio_mvebuffer.data;
2703-				audio_mvebuffer.length = temp_audio_mvebuffer.length;
2704
2705 				/* let SDL have access to the audio_mvebuffer */
2706 				SDL_UnlockAudio();
2707
2708 				/* close off temp_audio_mvebuffer */
2709-				temp_audio_mvebuffer.data = NULL;
2710-				temp_audio_mvebuffer.length = 0;
2711+				temp_audio_mvebuffer.data.clear();
2712
2713 				/* close off audio_data_read */
2714-				free (audio_data_read.data);
2715-				audio_data_read.data = NULL;
2716-				audio_data_read.length = 0;
2717+				audio_data_read.data.clear();
2718
2719 				break;
2720-
2721+			}
2722 			case INIT_VIDEO_MODE:
2723-				/* Skip unused width and height. */
2724-				SDL_ReadLE16 (mve);
2725-				SDL_ReadLE16 (mve);
2726+			{
2727+				/*const Uint16 width =*/ SDL_ReadLE16 (mve);
2728+				/*onst Uint16 height =*/ SDL_ReadLE16 (mve);
2729
2730 				/* if we've been here before */
2731-				if (screen)
2732-					SDL_FreeSurface (screen);
2733+				if (sdlTexture) SDL_DestroyTexture (sdlTexture);
2734+				if (sdlRenderer) SDL_DestroyRenderer (sdlRenderer);
2735+				if (sdlWindow) SDL_DestroyWindow (sdlWindow);
2736
2737 				if (fullscreen)
2738-					screen = SDL_SetVideoMode (dwidth, dheight, 8, Video.getSurfaceType() | SDL_FULLSCREEN);
2739+				{
2740+					sdlWindow = SDL_CreateWindow("Video",
2741+												 SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
2742+												 0, 0,
2743+												 SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN_DESKTOP);
2744+				}
2745 				else
2746-					screen = SDL_SetVideoMode (dwidth, dheight, 8, Video.getSurfaceType());
2747+				{
2748+					sdlWindow = SDL_CreateWindow("Video",
2749+												 SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
2750+												 dwidth, dheight,
2751+												 SDL_WINDOW_OPENGL);
2752+					SDL_SetWindowIcon (sdlWindow, AutoSurface (SDL_LoadBMP (MAXR_ICON)));
2753+				}
2754+				sdlRenderer = SDL_CreateRenderer(sdlWindow, -1, 0);
2755+				//sdlTexture = SDL_CreateTexture(sdlRenderer,
2756+				//							   SDL_PIXELFORMAT_INDEX4MSB,
2757+				//							   SDL_TEXTUREACCESS_STREAMING,
2758+				//							   width, height);
2759
2760-				//SDL_WM_SetCaption(filename, NULL);
2761-
2762 				/* strip unknown flag word */
2763 				SDL_ReadLE16 (mve);
2764
2765 				break;
2766-
2767+			}
2768 			case SET_PALETTE:
2769 			{
2770-				Uint8 r = 0, g = 0, b = 0;
2771-				Uint16 palette_start = 0, numPalColors = 0;
2772+				Uint8 r = 0;
2773+				Uint8 g = 0;
2774+				Uint8 b = 0;
2775
2776 				/* get # of first entry to fill */
2777-				palette_start = SDL_ReadLE16 (mve);
2778+				const Uint16 palette_start = SDL_ReadLE16 (mve);
2779
2780 				/* get number of entries in palette */
2781-				numPalColors = SDL_ReadLE16 (mve);
2782+				const Uint16 numPalColors = SDL_ReadLE16 (mve);
2783
2784 				/* fill the palette */
2785-				for (i = 0; i < 256; i++)
2786+				for (int i = 0; i < 256; i++)
2787 				{
2788 					if (i < palette_start)
2789 					{
2790@@ -540,7 +546,8 @@
2791 						SDL_RWread (mve, &r, sizeof (Uint8), 1);
2792 						SDL_RWread (mve, &g, sizeof (Uint8), 1);
2793 						SDL_RWread (mve, &b, sizeof (Uint8), 1);
2794-						/* interplay divides the palette entries by 4; must multiply by 4. */
2795+						// interplay divides the palette entries by 4;
2796+						// must multiply by 4.
2797 						r <<= 2;
2798 						g <<= 2;
2799 						b <<= 2;
2800@@ -548,51 +555,38 @@
2801 					frame_buf->format->palette->colors[i].r = r;
2802 					frame_buf->format->palette->colors[i].g = g;
2803 					frame_buf->format->palette->colors[i].b = b;
2804-					frame_buf->format->palette->colors[i].unused = 0;
2805+					frame_buf->format->palette->colors[i].a = 255;
2806 				}
2807
2808 				/* install the palette in the screen surface */
2809-				SDL_SetColors (screen, frame_buf->format->palette->colors, 0, 256);
2810-
2811+				break;
2812 			}
2813-
2814-			break;
2815-
2816 			case SET_DECODING_MAP:
2817-
2818-				/* kill previous map */
2819-				free (map);
2820-
2821+			{
2822 				/* get new map */
2823-				map = (Uint8*) malloc (sizeof (Uint8) * op.length);
2824-				assert (map != NULL);
2825-				SDL_RWread (mve, map, op.length, 1);
2826+				map.resize (op.length);
2827+				SDL_RWread (mve, map.data(), op.length, 1);
2828 				break;
2829-
2830+			}
2831 			case VIDEO_DATA:
2832-
2833-				/* free the previously allocated video data array */
2834-				free (video);
2835-
2836+			{
2837 				/* allocate enough memory for the video data array */
2838-				video = (Uint8*) malloc (op.length);
2839-				assert (video != NULL);
2840+				video.resize (op.length);
2841
2842-				/* swap the frames so we draw next on the frame that was onscreen 1 frame ago */
2843-				temp = frame_cold;
2844-				frame_cold = frame_hot;
2845-				frame_hot = temp;
2846+				// swap the frames so we draw next on the frame
2847+				// that was onscreen 1 frame ago */
2848+				std::swap (frame_cold, frame_hot);
2849
2850 				/* read the data */
2851-				SDL_RWread (mve, video, op.length, 1);
2852+				SDL_RWread (mve, video.data(), op.length, 1);
2853
2854 				/* decode the video data and update the frame_hot pixel data */
2855-				MVEPlayerDecodeVideo (width_blocks, height_blocks, video, map);
2856+				MVEPlayerDecodeVideo (width_blocks, height_blocks, video.data(), map.data());
2857
2858 				break;
2859-
2860+			}
2861 			default:
2862-
2863+			{
2864 				/* are opcode parameters within known bounds? */
2865 				if (op.type > 0x15 || op.version > 3)
2866 					return MVE_CORRUPT;
2867@@ -601,6 +595,7 @@
2868 				mve->seek (mve, op.length, SEEK_CUR);
2869
2870 				break;
2871+			}
2872 		}
2873
2874 		/************************/
2875@@ -610,7 +605,6 @@
2876 		/* read opcode (trailing read) */
2877 		if (!SDL_RWread (mve, &op, sizeof (op), 1))
2878 			return OPCODE_READ_FAILED;
2879-
2880 	}
2881 	/***********/
2882 	/* cleanup */
2883@@ -624,37 +618,16 @@
2884 			SDL_PauseAudio (1);
2885 			SDL_CloseAudio();
2886 		}
2887-
2888-		/* free audio mvebuffers */
2889-		free (audio_mvebuffer.data);
2890-
2891-		free (audio_data_read.data);
2892-
2893-		free (temp_audio_mvebuffer.data);
2894-
2895-		/* free the audio_spec */
2896-		free (desired);
2897 	}
2898
2899-	/* free the decoding map */
2900-	free (map);
2901-
2902-	/* free the video data */
2903-	free (video);
2904-
2905-	/* free the video mvebuffers */
2906-	free (v_backbuf);
2907-
2908-	if (screen)
2909-		SDL_FreeSurface (screen);
2910-
2911 	/* close the file handle */
2912 	if (mve)
2913 		SDL_RWclose (mve);
2914
2915 	/* reset video mode to original */
2916-	if (!fullscreen)
2917-		SDL_SetVideoMode (initial_vid_state->current_w, initial_vid_state->current_h, initial_vid_state->vfmt->BitsPerPixel, SDL_ANYFORMAT);
2918+	if (sdlTexture) SDL_DestroyTexture (sdlTexture);
2919+	if (sdlRenderer) SDL_DestroyRenderer (sdlRenderer);
2920+	if (sdlWindow) SDL_DestroyWindow (sdlWindow);
2921
2922 	/* seems to have worked. */
2923 	return SUCCESS;
2924@@ -666,41 +639,11 @@
2925
2926 void MVEPlayerAudioCB (void* userdata, Uint8* stream, int len)
2927 {
2928-	Uint8* temp;
2929 	mvebuffer* audio_mvebuffer = reinterpret_cast<mvebuffer*> (userdata);
2930
2931-	if ( (Uint32) len > audio_mvebuffer->length)
2932-	{
2933-		/* give SDL what we have */
2934-		memcpy (stream, audio_mvebuffer->data, audio_mvebuffer->length);
2935-		/* and now we have nothing */
2936-		audio_mvebuffer->length = 0;
2937-	}
2938-	else
2939-	{
2940-		/* copy len bytes to stream */
2941-		memcpy (stream, audio_mvebuffer->data, len);
2942-
2943-		/* our mvebuffer length is now whatever we started with minus len */
2944-		audio_mvebuffer->length -= len;
2945-
2946-		/* now we need to store the data that wasn't read */
2947-		temp = (Uint8*) malloc (audio_mvebuffer->length);
2948-		assert (temp != NULL);
2949-
2950-		/* copy from data address + len length bytes
2951-		(which should be the start of the data that wasn't copied to stream) */
2952-		memcpy (temp, audio_mvebuffer->data + len, audio_mvebuffer->length);
2953-
2954-		/* free the memory of the audio_mvebuffer */
2955-		free (audio_mvebuffer->data);
2956-
2957-		/* assign the address of our stored data to the audio_mvebuffer's data */
2958-		audio_mvebuffer->data = temp;
2959-
2960-		/* close off temp */
2961-		temp = NULL;
2962-	}
2963+	len = std::min<size_t>(len, audio_mvebuffer->data.size());
2964+	std::copy(audio_mvebuffer->data.begin(), audio_mvebuffer->data.begin() + len, stream);
2965+	audio_mvebuffer->data.erase(audio_mvebuffer->data.begin(), audio_mvebuffer->data.begin() + len);
2966 }
2967
2968 /* Interplay DPCM table */
2969@@ -732,43 +675,40 @@
2970 	/* this only works for stereo dpcm at present */
2971
2972 	Sint16 sample[2];
2973-	Uint16 in_pos = 0, out_pos = 0;
2974+	Uint16 in_pos = 0;
2975+	Uint16 out_pos = 0;
2976 	Uint8 channel = 0;
2977 	mvebuffer out;
2978
2979 	/* in->data includes initial stream-len word */
2980 	/* uncompressed streamlen is stream-len bytes */
2981-	out.length = LE16 (in->data);
2982+	out.data.resize (LE16 (in->data.data()));
2983 	in_pos += 2;
2984-	out.data = (Uint8*) malloc (out.length);
2985-	assert (out.data != NULL);
2986
2987-	/* each byte in the input mvebuffer after the first four (two words: initial L and R values)
2988-	will be expanded to fill a word in the return mvebuffer after decompression.
2989-	The initial two words will be stored in return mvebuffer as-is. */
2990-	sample[0] = LE16 (in->data + in_pos);
2991+	// each byte in the input mvebuffer after the first four
2992+	// (two words: initial L and R values)
2993+	// will be expanded to fill a word
2994+	// in the return mvebuffer after decompression.
2995+	// The initial two words will be stored in return mvebuffer as-is.
2996+	sample[0] = LE16 (in->data.data() + in_pos);
2997 	in_pos += 2;
2998-	* (Sint16*) (out.data + out_pos) = sample[0];
2999+	* (Sint16*) (out.data.data() + out_pos) = sample[0];
3000 	out_pos += 2;
3001-	sample[1] = LE16 (in->data + in_pos);
3002+	sample[1] = LE16 (in->data.data() + in_pos);
3003 	in_pos += 2;
3004-	* (Sint16*) (out.data + out_pos) = sample[1];
3005+	* (Sint16*) (out.data.data() + out_pos) = sample[1];
3006 	out_pos += 2;
3007
3008-	while (in_pos < in->length)
3009+	while (in_pos < in->data.size())
3010 	{
3011-		sample[channel] += interplay_delta_table[* (in->data + in_pos++)];
3012-		* (Sint16*) (out.data + out_pos) = sample[channel];
3013+		sample[channel] += interplay_delta_table[* (in->data.data() + in_pos++)];
3014+		* (Sint16*) (out.data.data() + out_pos) = sample[channel];
3015 		out_pos += 2;
3016 		channel = !channel;
3017 	}
3018
3019-	/* free the original mvebuffer*/
3020-	free (in->data);
3021-
3022 	/* assign the incoming mvebuffer the outgoing data for return */
3023-	in->data = out.data;
3024-	in->length = out.length;
3025+	std::swap(in->data, out.data);
3026 }
3027
3028 /**************************************/
3029@@ -776,40 +716,46 @@
3030 /**************************************/
3031 void MVEPlayerDecodeVideo (Uint16 wblocks, Uint16 hblocks, Uint8* pData, Uint8* pMap)
3032 {
3033-	Uint8 encoding = 0, *map = NULL, *data = NULL, *new_frame = NULL, *current = NULL, *temp = NULL;
3034-	Uint16 pitch = 0;
3035-	Sint32 x, y, i, j;
3036+	Uint8 encoding = 0, *new_frame = NULL, *current = NULL, *temp = NULL;
3037+	Uint8* map = pMap;
3038
3039-	map = pMap;
3040-
3041 	/* there are 14 undocumented bytes at head of video stream */
3042-	data = pData + 14;
3043+	Uint8* data = pData + 14;
3044
3045-	pitch = wblocks << 3;
3046+	Uint16 pitch = wblocks << 3;
3047
3048 	/* for each row (of 8x8 pixel blocks) */
3049-	for (y = 0; y < hblocks; y++)
3050+	for (Sint16 y = 0; y < hblocks; y++)
3051 	{
3052 		/* for each column (of 8x8 pixel blocks) */
3053-		for (x = 0; x < wblocks; x++)
3054+		for (Sint16 x = 0; x < wblocks; x++)
3055 		{
3056-			/* assign the frame mvebuffer pointers to the addresses of the screen
3057-			mvebuffers so we can do pointer arithmetic on them such as incrementing.
3058-			current is the frame currently onscreen; new_frame is the frame under construction. */
3059+			// assign the frame mvebuffer pointers
3060+			// to the addresses of the screen
3061+			// mvebuffers so we can do pointer arithmetic on them
3062+			// such as incrementing.
3063+			// current is the frame currently onscreen;
3064+			// new_frame is the frame under construction.
3065
3066 			new_frame = frame_hot;
3067 			current = frame_cold;
3068
3069-			/* increment pixel pointer past the rendered area on the screen
3070-			y = number of rows, wblocks = number of blocks per row, 8 * 8 = pixel area of the block;
3071-			y * wblocks * 8 * 8 = all the complete rows of 8x8 pixel blocks rendered.
3072-			x * 8 = upper left pixel of the 8x8 block in this new row to be rendered at this time.
3073-			I felt like replacing the multiplications throughout this function with shift operations. */
3074+			// increment pixel pointer past the rendered area on the screen
3075+			// y = number of rows,
3076+			// wblocks = number of blocks per row,
3077+			// 8 * 8 = pixel area of the block;
3078+			// y * wblocks * 8 * 8 = all the complete rows
3079+			//  of 8x8 pixel blocks rendered.
3080+			// x * 8 = upper left pixel of the 8x8 block
3081+			// in this new row to be rendered at this time.
3082+			// I felt like replacing the multiplications
3083+			// throughout this function with shift operations.
3084
3085 			new_frame += (y * wblocks << 6) + (x << 3);
3086 			current += (y * wblocks << 6) + (x << 3);
3087
3088-			/* get the decoding map info for this block; low 4 bits if x is even, high 4 bits if x is odd */
3089+			// get the decoding map info for this block;
3090+			// low 4 bits if x is even, high 4 bits if x is odd
3091 			encoding = (*map >> ( (x & 1) << 2)) & 0x0f;
3092
3093 			/* if x is odd, increment the decoding map */
3094@@ -820,7 +766,7 @@
3095 			{
3096 				case 0x0:
3097
3098-					for (j = 0; j < 8; j++)
3099+					for (int j = 0; j < 8; j++)
3100 					{
3101 						memcpy (new_frame + j * pitch, current + j * pitch, 8);
3102 					}
3103@@ -832,6 +778,8 @@
3104 					break;
3105
3106 				case 0x2:
3107+				{
3108+					Sint32 i, j;
3109
3110 					temp = new_frame;
3111 					if (*data < 56)
3112@@ -848,15 +796,16 @@
3113
3114 					temp += j * pitch + i;
3115
3116-					for (j = 0; j < 8; j++)
3117+					for (int j = 0; j < 8; j++)
3118 					{
3119 						memcpy (new_frame + j * pitch, temp + j * pitch, 8);
3120 					}
3121
3122 					break;
3123-
3124+				}
3125 				case 0x3:
3126-
3127+				{
3128+					Sint32 i, j;
3129 					temp = new_frame;
3130 					if (*data < 56)
3131 					{
3132@@ -872,40 +821,40 @@
3133
3134 					temp += j * pitch + i;
3135
3136-					for (j = 0; j < 8; j++)
3137+					for (int j = 0; j < 8; j++)
3138 					{
3139 						memcpy (new_frame + j * pitch, temp + j * pitch, 8);
3140 					}
3141
3142 					break;
3143-
3144+				}
3145 				case 0x4:
3146-
3147-					i = -8 + (*data & 0xF);
3148-					j = -8 + (*data >> 4);
3149+				{
3150+					Sint32 i = -8 + (*data & 0xF);
3151+					Sint32 j = -8 + (*data >> 4);
3152 					data++;
3153
3154 					current += j * pitch + i;
3155
3156-					for (j = 0; j < 8; j++)
3157+					for (int j = 0; j < 8; j++)
3158 					{
3159 						memcpy (new_frame + j * pitch, current + j * pitch, 8);
3160 					}
3161
3162 					break;
3163-
3164+				}
3165 				case 0x5:
3166-
3167+				{
3168 					current += (Sint8) data[1] * pitch + (Sint8) data[0];
3169 					data += 2;
3170
3171-					for (j = 0; j < 8; j++)
3172+					for (int j = 0; j < 8; j++)
3173 					{
3174 						memcpy (new_frame + j * pitch, current + j * pitch, 8);
3175 					}
3176
3177 					break;
3178-
3179+				}
3180 				case 0x6:
3181
3182 					x += 2;
3183@@ -925,13 +874,13 @@
3184
3185 					if (p[0] <= p[1])
3186 					{
3187-						for (i = 0; i < 8; i++)
3188+						for (int i = 0; i < 8; i++)
3189 						{
3190 							b[i] = *data++;
3191 						}
3192-						for (j = 0; j < 8; j++)
3193+						for (int j = 0; j < 8; j++)
3194 						{
3195-							for (i = 0, mask = 1; i < 8; i++, mask <<= 1)
3196+							for (int i = 0, mask = 1; i < 8; i++, mask <<= 1)
3197 							{
3198 								new_frame[i] = p[!! (b[j] & mask)];
3199 							}
3200@@ -943,11 +892,11 @@
3201 						b[0] = *data++;
3202 						b[1] = *data++;
3203
3204-						for (j = 0; j < 4; j++)
3205+						for (int j = 0; j < 4; j++)
3206 						{
3207 							if (! (j % 2))
3208 								mask = 0x01;
3209-							for (i = 0; i < 4; i++, mask <<= 1)
3210+							for (int i = 0; i < 4; i++, mask <<= 1)
3211 							{
3212 								new_frame[i << 1] =
3213 									new_frame[ (i << 1) + 1] =
3214@@ -963,22 +912,22 @@
3215
3216 				case 0x8:
3217 				{
3218-					Uint8 p[8], b[8], mask = 1, k;
3219+					Uint8 p[8], b[8], mask = 1;
3220 					if (data[0] <= data[1])
3221 					{
3222-						for (j = 0; j < 4; j++)
3223+						for (int j = 0; j < 4; j++)
3224 						{
3225-							for (i = 0; i < 2; i++)
3226+							for (int i = 0; i < 2; i++)
3227 							{
3228 								p[i + (j << 1)] = *data++;
3229 							}
3230-							for (i = 0; i < 2; i++)
3231+							for (int i = 0; i < 2; i++)
3232 							{
3233 								b[i + (j << 1)] = *data++;
3234 							}
3235 						}
3236
3237-						for (k = 0; k < 4; k++)
3238+						for (int k = 0; k < 4; k++)
3239 						{
3240 							if (k == 2)
3241 							{
3242@@ -985,11 +934,11 @@
3243 								new_frame -= pitch << 3;
3244 								new_frame += 4;
3245 							}
3246-							for (j = 0; j < 4; j++)
3247+							for (int j = 0; j < 4; j++)
3248 							{
3249 								if (! (j & 1))
3250 									mask = 1;
3251-								for (i = 0; i < 4; i++)
3252+								for (int i = 0; i < 4; i++)
3253 								{
3254 									new_frame[i] = p[!! (b[ (j >> 1) + (k << 1)] & mask) + (k << 1)];
3255 									mask <<= 1;
3256@@ -1000,13 +949,13 @@
3257 					} /* if p0 <= p1 */
3258 					else
3259 					{
3260-						for (j = 0; j < 2; j++)
3261+						for (int j = 0; j < 2; j++)
3262 						{
3263-							for (i = 0; i < 2; i++)
3264+							for (int i = 0; i < 2; i++)
3265 							{
3266 								p[ (j << 1) + i] = *data++;
3267 							}
3268-							for (i = 0; i < 4; i++)
3269+							for (int i = 0; i < 4; i++)
3270 							{
3271 								b[ (j << 2) + i] = *data++;
3272 							}
3273@@ -1014,9 +963,9 @@
3274 						if (p[2] > p[3])
3275 						{
3276 							/* horizontally split block */
3277-							for (j = 0; j < 8; j++)
3278+							for (int j = 0; j < 8; j++)
3279 							{
3280-								for (i = 0, mask = 1; i < 8; i++, mask <<= 1)
3281+								for (int i = 0, mask = 1; i < 8; i++, mask <<= 1)
3282 								{
3283 									new_frame[i] = p[!! (b[j] & mask) + (j > 3 ? 2 : 0)];
3284 								}
3285@@ -1026,7 +975,7 @@
3286 						else
3287 						{
3288 							/* vertically split block */
3289-							for (k = 0; k < 2; k++)
3290+							for (int k = 0; k < 2; k++)
3291 							{
3292 								if (k == 1)
3293 								{
3294@@ -1033,10 +982,10 @@
3295 									new_frame -= pitch << 3;
3296 									new_frame += 4;
3297 								}
3298-								for (j = 0; j < 4; j++)
3299+								for (int j = 0; j < 4; j++)
3300 								{
3301 									mask = 1;
3302-									for (i = 0; i < 8; i++)
3303+									for (int i = 0; i < 8; i++)
3304 									{
3305 										new_frame[i % 4] = p[!! (b[j + (k << 2)] & mask) + (k << 1)];
3306 										mask <<= 1;
3307@@ -1055,20 +1004,20 @@
3308 				case 0x9:
3309 				{
3310 					Uint8 p[4], b[16];
3311-					for (i = 0; i < 4; i++)
3312+					for (int i = 0; i < 4; i++)
3313 					{
3314 						p[i] = *data++;
3315 					}
3316 					if (p[0] <= p[1] && p[2] <= p[3])
3317 					{
3318-						Uint16 mask;
3319-						for (i = 0; i < 16; i++)
3320+						for (int i = 0; i < 16; i++)
3321 						{
3322 							b[i] = *data++;
3323 						}
3324-						for (j = 0; j < 8; j++)
3325+						for (int j = 0; j < 8; j++)
3326 						{
3327-							for (i = 0, mask = 3; i < 8; i++, mask <<= 2)
3328+
3329+							for (Uint16 i = 0, mask = 3; i < 8; i++, mask <<= 2)
3330 							{
3331 								new_frame[i] = p[ (mask & (b[ (j << 1) + 1] << 8 | b[j << 1])) >> (i << 1)];
3332 							}
3333@@ -1078,14 +1027,14 @@
3334 					if (p[0] <= p[1] && p[2] > p[3])
3335 					{
3336 						Uint8 mask;
3337-						for (i = 0; i < 4; i++)
3338+						for (int i = 0; i < 4; i++)
3339 						{
3340 							b[i] = *data++;
3341 						}
3342-						for (j = 0; j < 8; j++)
3343+						for (int j = 0; j < 8; j++)
3344 						{
3345 							mask = 3;
3346-							for (i = 0; i < 8; i++)
3347+							for (int i = 0; i < 8; i++)
3348 							{
3349 								new_frame[i] = p[ (b[j >> 1] & mask) >> ( (i >> 1) << 1)];
3350 								if (i & 1)
3351@@ -1097,14 +1046,14 @@
3352 					if (p[0] > p[1] && p[2] <= p[3])
3353 					{
3354 						Uint8 mask;
3355-						for (i = 0; i < 8; i++)
3356+						for (int i = 0; i < 8; i++)
3357 						{
3358 							b[i] = *data++;
3359 						}
3360-						for (j = 0; j < 8; j++)
3361+						for (int j = 0; j < 8; j++)
3362 						{
3363 							mask = 3;
3364-							for (i = 0; i < 8; i++)
3365+							for (int i = 0; i < 8; i++)
3366 							{
3367 								new_frame[i] = p[ (b[j] & mask) >> ( (i >> 1) << 1)];
3368 								if (i & 1)
3369@@ -1116,14 +1065,14 @@
3370 					if (p[0] > p[1] && p[2] > p[3])
3371 					{
3372 						Uint16 mask;
3373-						for (i = 0; i < 8; i++)
3374+						for (int i = 0; i < 8; i++)
3375 						{
3376 							b[i] = *data++;
3377 						}
3378-						for (j = 0; j < 4; j++)
3379+						for (int j = 0; j < 4; j++)
3380 						{
3381 							mask = 3;
3382-							for (i = 0; i < 8; i++)
3383+							for (int i = 0; i < 8; i++)
3384 							{
3385 								new_frame[i] =
3386 									new_frame[i + pitch] = p[ ( (b[ (j << 1) + 1] << 8 | b[j << 1]) & mask) >> (i << 1)];
3387@@ -1138,25 +1087,25 @@
3388
3389 				case 0xA:
3390 				{
3391-					Uint8 p[16], b[16], mask, k;
3392+					Uint8 p[16], b[16];
3393 					if (data[0] <= data[1])
3394 					{
3395-						for (i = 0; i < 4; i++)
3396+						for (int i = 0; i < 4; i++)
3397 						{
3398-							for (j = 0; j < 4; j++)
3399+							for (int j = 0; j < 4; j++)
3400 							{
3401 								p[ (i << 2) + j] = *data++;
3402 							}
3403-							for (j = 0; j < 4; j++)
3404+							for (int j = 0; j < 4; j++)
3405 							{
3406 								b[ (i << 2) + j] = *data++;
3407 							}
3408 						}
3409-						for (k = 0; k < 4; k++)
3410+						for (int k = 0; k < 4; k++)
3411 						{
3412-							for (j = 0; j < 4; j++)
3413+							for (int j = 0; j < 4; j++)
3414 							{
3415-								for (i = 0, mask = 3; i < 4; i++, mask <<= 2)
3416+								for (Uint8 i = 0, mask = 3; i < 4; i++, mask <<= 2)
3417 								{
3418 									new_frame[i] = p[ ( (b[ (k << 2) + j] & mask) >> (i << 1)) + (k << 2)];
3419 								}
3420@@ -1171,13 +1120,13 @@
3421 					}
3422 					else
3423 					{
3424-						for (i = 0; i < 2; i++)
3425+						for (int i = 0; i < 2; i++)
3426 						{
3427-							for (j = 0; j < 4; j++)
3428+							for (int j = 0; j < 4; j++)
3429 							{
3430 								p[ (i << 2) + j] = *data++;
3431 							}
3432-							for (j = 0; j < 8; j++)
3433+							for (int j = 0; j < 8; j++)
3434 							{
3435 								b[ (i << 3) + j] = *data++;
3436 							}
3437@@ -1184,11 +1133,11 @@
3438 						}
3439 						if (p[4] <= p[5])
3440 						{
3441-							for (k = 0; k < 2; k++)
3442+							for (int k = 0; k < 2; k++)
3443 							{
3444-								for (j = 0; j < 8; j++)
3445+								for (int j = 0; j < 8; j++)
3446 								{
3447-									for (i = 0, mask = 3; i < 4; i++, mask <<= 2)
3448+									for (int i = 0, mask = 3; i < 4; i++, mask <<= 2)
3449 									{
3450 										new_frame[i] = p[ ( (b[j + (k << 3)] & mask) >> (i << 1)) + (k << 2)];
3451 									}
3452@@ -1203,11 +1152,11 @@
3453 						}
3454 						else
3455 						{
3456-							for (k = 0; k < 2; k++)
3457+							for (int k = 0; k < 2; k++)
3458 							{
3459-								for (j = 0; j < 4; j++)
3460+								for (int j = 0; j < 4; j++)
3461 								{
3462-									for (i = 0, mask = 3; i < 8; i++, mask <<= 2)
3463+									for (int i = 0, mask = 3; i < 8; i++, mask <<= 2)
3464 									{
3465 										if (i == 4)
3466 											mask = 3;
3467@@ -1225,9 +1174,9 @@
3468
3469 				case 0xB:
3470
3471-					for (j = 0; j < 8; j++)
3472+					for (int j = 0; j < 8; j++)
3473 					{
3474-						for (i = 0; i < 8; i++)
3475+						for (int i = 0; i < 8; i++)
3476 						{
3477 							new_frame[i] = *data++;
3478 						}
3479@@ -1239,13 +1188,13 @@
3480 				case 0xC:
3481 				{
3482 					Uint8 p[16];
3483-					for (i = 0; i < 16; i++)
3484+					for (int i = 0; i < 16; i++)
3485 					{
3486 						p[i] = *data++;
3487 					}
3488-					for (j = 0; j < 8; j++)
3489+					for (int j = 0; j < 8; j++)
3490 					{
3491-						for (i = 0; i < 8; i++)
3492+						for (int i = 0; i < 8; i++)
3493 						{
3494 							new_frame[i] = p[ (i >> 1) + ( (j >> 1) << 2)];
3495 						}
3496@@ -1258,13 +1207,13 @@
3497 				case 0xD:
3498 				{
3499 					Uint8 p[4];
3500-					for (i = 0; i < 4; i++)
3501+					for (int i = 0; i < 4; i++)
3502 					{
3503 						p[i] = *data++;
3504 					}
3505-					for (j = 0; j < 8; j++)
3506+					for (int j = 0; j < 8; j++)
3507 					{
3508-						for (i = 0; i < 8; i++)
3509+						for (int i = 0; i < 8; i++)
3510 						{
3511 							new_frame[i] = p[ ( (j > 3 ? 1 : 0) << 1) + (i > 3 ? 1 : 0)];
3512 						}
3513@@ -1276,7 +1225,7 @@
3514
3515 				case 0xE:
3516
3517-					for (j = 0; j < 8; j++)
3518+					for (int j = 0; j < 8; j++)
3519 					{
3520 						memset (new_frame + j * pitch, *data, 8);
3521 					}
3522@@ -1286,9 +1235,9 @@
3523
3524 				case 0xF:
3525
3526-					for (j = 0; j < 8; j++)
3527+					for (int j = 0; j < 8; j++)
3528 					{
3529-						for (i = 0; i < 8; i++)
3530+						for (int i = 0; i < 8; i++)
3531 							new_frame[i] = data[ ( (i + j) & 1)];
3532 						new_frame += pitch;
3533 					}
3534@@ -1305,8 +1254,10 @@
3535 /*************************************/
3536 void MVEPlayerEventHandler()
3537 {
3538-	/* event vars for determining pause, quit, or speed commands from user; declared static
3539-	so they retain their values between calls to MVEPlayerEventHandler (else nothing happens) */
3540+	// event vars for determining pause, quit, or speed commands from user;
3541+	// declared static
3542+	// so they retain their values between calls to MVEPlayerEventHandler
3543+	// (else nothing happens)
3544
3545 	static Uint8 keyin = 0;
3546 	static SDL_Event event;
3547@@ -1315,9 +1266,7 @@
3548 	{
3549 		switch (event.type)
3550 		{
3551-			case SDL_KEYDOWN:
3552-				keyin = event.key.keysym.sym;
3553-				break;
3554+			case SDL_KEYDOWN: keyin = event.key.keysym.sym; break;
3555 			case SDL_KEYUP:
3556 				if (event.key.keysym.sym == keyin)
3557 				{
3558@@ -1335,10 +1284,9 @@
3559 							else if (AUDIO_PLAYING)
3560 								SDL_PauseAudio (0);
3561 							break;
3562-							/* ToggleFullScreen does not work on my system so I cannot test it */
3563-							/*case SDLK_f:
3564-								SDL_WM_ToggleFullScreen(screen);
3565-								break;*/
3566+							// ToggleFullScreen does not work on my system
3567+							// so I cannot test it
3568+							//case SDLK_f: SDL_WM_ToggleFullScreen(screen); break;
3569 						default:
3570 							QUITTING = !QUITTING;
3571 							break;
3572Index: network.cpp
3573===================================================================
3574--- network.cpp	(revision 3442)
3575+++ network.cpp	(working copy)
3576@@ -88,7 +88,7 @@
3577 	bHost = false;
3578
3579 	bExit = false;
3580-	TCPHandleThread = SDL_CreateThread (CallbackHandleNetworkThread, this);
3581+	TCPHandleThread = SDL_CreateThread (CallbackHandleNetworkThread, "network", this);
3582 }
3583
3584 //------------------------------------------------------------------------
3585Index: pcx.cpp
3586===================================================================
3587--- pcx.cpp	(revision 3442)
3588+++ pcx.cpp	(working copy)
3589@@ -109,7 +109,7 @@
3590 	if (!FileExists (name.c_str()))
3591 	{
3592 		// File not found, create empty surface.
3593-		SDL_Surface* const s = SDL_CreateRGBSurface (Video.getSurfaceType(), 100, 20, Video.getColDepth(), 0, 0, 0, 0);
3594+		SDL_Surface* const s = SDL_CreateRGBSurface (0, 100, 20, Video.getColDepth(), 0, 0, 0, 0);
3595 		return s;
3596 	}
3597
3598@@ -117,7 +117,7 @@
3599 	if (!bufferedFile.open (name.c_str(), "rb"))
3600 	{
3601 		Log.write (SDL_GetError(), cLog::eLOG_TYPE_WARNING);  // Image corrupted, create empty surface.
3602-		SDL_Surface* const s = SDL_CreateRGBSurface (Video.getSurfaceType(), 100, 20, Video.getColDepth(), 0, 0, 0, 0);
3603+		SDL_Surface* const s = SDL_CreateRGBSurface (0, 100, 20, Video.getColDepth(), 0, 0, 0, 0);
3604 		return s;
3605 	}
3606 	// Load the image.
3607@@ -124,13 +124,13 @@
3608 	bufferedFile.seek (8, SEEK_SET);
3609 	Uint16       const x = bufferedFile.readLE16() + 1;
3610 	Uint16       const y = bufferedFile.readLE16() + 1;
3611-	SDL_Surface* const s = SDL_CreateRGBSurface (Video.getSurfaceType() | SDL_SRCCOLORKEY, x, y, 32, 0, 0, 0, 0);
3612+	SDL_Surface* const s = SDL_CreateRGBSurface (0, x, y, 32, 0, 0, 0, 0);
3613 	if (!s)
3614 	{
3615 		Log.write (SDL_GetError(), cLog::eLOG_TYPE_ERROR);
3616 		return NULL; //app will crash using this
3617 	}
3618-	SDL_SetColorKey (s, SDL_SRCCOLORKEY, 0xFF00FF);
3619+	SDL_SetColorKey (s, SDL_TRUE, 0xFF00FF);
3620
3621 	Uint32* const buf = static_cast<Uint32*> (s->pixels);
3622 	bufferedFile.seek (128, RW_SEEK_SET);
3623Index: SDL_flic.c
3624===================================================================
3625--- SDL_flic.c	(revision 3442)
3626+++ SDL_flic.c	(working copy)
3627@@ -28,9 +28,9 @@
3628              added function FLI_Version that returns the library version
3629 */
3630 #include "SDL_flic.h"
3631+#include <string.h>
3632 #include <setjmp.h>
3633 #include <stdlib.h>
3634-//#include <mem.h>
3635
3636 /* Library version. */
3637 #define FLI_MAJOR 1
3638@@ -46,6 +46,14 @@
3639 #define FLI_COPY     16
3640 #define FLI_PSTAMP   18
3641
3642+#if 1 // TODO: [SDL2]: SDL_SetColors
3643+inline void SDL_SetColors (SDL_Surface* surface, SDL_Color* colors, int index, int size)
3644+{
3645+	SDL_SetPaletteColors (surface->format->palette, colors, index, size);
3646+}
3647+#endif
3648+
3649+
3650 typedef struct {
3651         Uint32 size, type, numchunks;
3652 } FLI_Frame;
3653@@ -54,7 +62,7 @@
3654         Uint32 size, type, index;
3655 } FLI_Chunk;
3656
3657-static void readbuffer(FLI_Animation *flic, void *buffer, int size) {
3658+static void readbuffer(FLI_Animation *flic, void *buffer, unsigned int size) {
3659         if (SDL_RWread(flic->rwops, buffer, 1, size) != size)
3660                 longjmp(flic->error, FLI_READERROR);
3661 }
3662@@ -97,7 +105,7 @@
3663
3664 static void readheader(FLI_Animation *flic) {
3665         /* Skip size, we don't need it. */
3666-        SDL_RWseek(flic->rwops, 4, SEEK_CUR);
3667+        SDL_RWseek(flic->rwops, 4, RW_SEEK_CUR);
3668         /* Read and check magic. */
3669         flic->format = readu16(flic);
3670         if (flic->format != FLI_FLI && flic->format != FLI_FLC)
3671@@ -120,7 +128,7 @@
3672         /* Read the delay between frames. */
3673         flic->delay = (flic->format == FLI_FLI) ? readu16(flic) : readu32(flic);
3674         /* Skip rest of the header. */
3675-        SDL_RWseek(flic->rwops, (flic->format == FLI_FLI) ? 110 : 108, SEEK_CUR);
3676+        SDL_RWseek(flic->rwops, (flic->format == FLI_FLI) ? 110 : 108, RW_SEEK_CUR);
3677 }
3678
3679 static void readframe(FLI_Animation *flic, FLI_Frame *frame) {
3680@@ -135,7 +143,7 @@
3681         /* Read the number of chunks in this frame. */
3682         frame->numchunks = readu16(flic);
3683         /* Skip rest of the data. */
3684-        SDL_RWseek(flic->rwops, 8, SEEK_CUR);
3685+        SDL_RWseek(flic->rwops, 8, RW_SEEK_CUR);
3686 }
3687
3688 static void readchunk(FLI_Animation *flic, FLI_Chunk *chunk) {
3689@@ -357,7 +365,7 @@
3690         readframe(flic, &frame);
3691         /* If it's a prefix frame, skip it. */
3692         if (frame.type == 0xF100) {
3693-                SDL_RWseek(rwops, frame.size - 16, SEEK_CUR);
3694+                SDL_RWseek(rwops, frame.size - 16, RW_SEEK_CUR);
3695                 flic->offframe1 = SDL_RWtell(rwops);
3696                 flic->numframes--;
3697         }
3698@@ -393,7 +401,7 @@
3699                 return error;
3700         }
3701         /* Seek to the current frame. */
3702-        SDL_RWseek(flic->rwops, flic->offnextframe, SEEK_SET);
3703+        SDL_RWseek(flic->rwops, flic->offnextframe, RW_SEEK_SET);
3704         /* Read the current frame. */
3705         readframe(flic, &frame);
3706         /* Read and process each of the chunks of this frame. */
3707@@ -426,7 +434,7 @@
3708                                 break;
3709                         case FLI_PSTAMP:
3710                                 /* Ignore this chunk. */
3711-								SDL_RWseek( flic->rwops, chunk.size - 6, SEEK_CUR );
3712+								SDL_RWseek( flic->rwops, chunk.size - 6, RW_SEEK_CUR );
3713                                 break;
3714                         default:
3715                                 longjmp(flic->error, FLI_CORRUPTEDFILE);
3716@@ -457,7 +465,7 @@
3717         if (error != 0)
3718                 return error;
3719         /* Seek to the current frame. */
3720-        SDL_RWseek(flic->rwops, flic->offnextframe, SEEK_SET);
3721+        SDL_RWseek(flic->rwops, flic->offnextframe, RW_SEEK_SET);
3722         /* Read the current frame. */
3723         readframe(flic, &frame);
3724         /* Skip to the next frame without rendering. */
3725Index: server.cpp
3726===================================================================
3727--- server.cpp	(revision 3449)
3728+++ server.cpp	(working copy)
3729@@ -20,24 +20,6 @@
3730 #include <cassert>
3731 #include <set>
3732
3733-#ifdef _MSC_VER
3734-
3735-# define NOMINMAX // do not use min, max as macro
3736-# include <windows.h>
3737-const DWORD MS_VC_EXCEPTION = 0x406D1388;
3738-
3739-# pragma pack (push, 8)
3740-typedef struct tagTHREADNAME_INFO
3741-{
3742-	DWORD dwType; // Must be 0x1000.
3743-	LPCSTR szName; // Pointer to name (in user addr space).
3744-	DWORD dwThreadID; // Thread ID (-1=caller thread).
3745-	DWORD dwFlags; // Reserved for future use, must be zero.
3746-} THREADNAME_INFO;
3747-# pragma pack (pop)
3748-#endif
3749-
3750-
3751 #include "server.h"
3752
3753 #include "attackJobs.h"
3754@@ -71,22 +53,6 @@
3755 //------------------------------------------------------------------------------
3756 int CallbackRunServerThread (void* arg)
3757 {
3758-#if defined _MSC_VER && defined DEBUG //set a readable thread name for debugging
3759-	THREADNAME_INFO info;
3760-	info.dwType = 0x1000;
3761-	info.szName = "Server Thread";
3762-	info.dwThreadID = -1;
3763-	info.dwFlags = 0;
3764-
3765-	__try
3766-	{
3767-		RaiseException (MS_VC_EXCEPTION, 0, sizeof (info) / sizeof (ULONG_PTR), reinterpret_cast<ULONG_PTR*> (&info));
3768-	}
3769-	__except (EXCEPTION_EXECUTE_HANDLER)
3770-	{
3771-	}
3772-#endif
3773-
3774 	cServer* server = reinterpret_cast<cServer*> (arg);
3775 	server->run();
3776 	return 0;
3777@@ -116,7 +82,7 @@
3778 	if (!DEDICATED_SERVER)
3779 	{
3780 		if (network) network->setMessageReceiver (this);
3781-		serverThread = SDL_CreateThread (CallbackRunServerThread, this);
3782+		serverThread = SDL_CreateThread (CallbackRunServerThread, "server", this);
3783 	}
3784
3785 	gameTimer.maxEventQueueSize = MAX_SERVER_EVENT_COUNTER;
3786Index: servergame.cpp
3787===================================================================
3788--- servergame.cpp	(revision 3447)
3789+++ servergame.cpp	(working copy)
3790@@ -70,7 +70,7 @@
3791 //------------------------------------------------------------------------------
3792 void cServerGame::runInThread()
3793 {
3794-	thread = SDL_CreateThread (serverGameThreadFunction, this);
3795+	thread = SDL_CreateThread (serverGameThreadFunction, "servergame", this);
3796 }
3797
3798 //------------------------------------------------------------------------------
3799Index: unifonts.cpp
3800===================================================================
3801--- unifonts.cpp	(revision 3442)
3802+++ unifonts.cpp	(working copy)
3803@@ -148,21 +148,21 @@
3804 				else if (charset == CHARSET_ISO8559_1) unicodeplace = currentChar + 128 + 2 * 16;
3805 			}
3806 			else unicodeplace = iso8859_to_uni[currentChar];
3807-			chars[unicodeplace] = SDL_CreateRGBSurface (Video.getSurfaceType() | SDL_SRCCOLORKEY, Rect.w, Rect.h, 32, 0, 0, 0, 0);
3808+			chars[unicodeplace] = SDL_CreateRGBSurface (0, Rect.w, Rect.h, 32, 0, 0, 0, 0);
3809
3810 			// change color of smal fonts
3811 			switch (fonttype)
3812 			{
3813 				case FONT_LATIN_SMALL_RED:
3814-					SDL_SetColorKey (surface, SDL_SRCCOLORKEY, 0xf0d8b8);
3815+					SDL_SetColorKey (surface, SDL_TRUE, 0xf0d8b8);
3816 					SDL_FillRect (chars[unicodeplace], NULL, 0xe60000);
3817 					break;
3818 				case FONT_LATIN_SMALL_GREEN:
3819-					SDL_SetColorKey (surface, SDL_SRCCOLORKEY, 0xf0d8b8);
3820+					SDL_SetColorKey (surface, SDL_TRUE, 0xf0d8b8);
3821 					SDL_FillRect (chars[unicodeplace], NULL, 0x04ae04);
3822 					break;
3823 				case FONT_LATIN_SMALL_YELLOW:
3824-					SDL_SetColorKey (surface, SDL_SRCCOLORKEY, 0xf0d8b8);
3825+					SDL_SetColorKey (surface, SDL_TRUE, 0xf0d8b8);
3826 					SDL_FillRect (chars[unicodeplace], NULL, 0xdbde00);
3827 					break;
3828 				default:
3829@@ -170,7 +170,7 @@
3830 					break;
3831 			}
3832 			SDL_BlitSurface (surface, &Rect, chars[unicodeplace], NULL);
3833-			SDL_SetColorKey (chars[unicodeplace], SDL_SRCCOLORKEY, 0xFF00FF);
3834+			SDL_SetColorKey (chars[unicodeplace], SDL_TRUE, 0xFF00FF);
3835
3836 			//goto next character
3837 			currentChar++;
3838Index: vehicles.cpp
3839===================================================================
3840--- vehicles.cpp	(revision 3442)
3841+++ vehicles.cpp	(working copy)
3842@@ -216,12 +216,12 @@
3843 		}
3844 	}
3845
3846-	if (IsBuilding && !job && BigBetonAlpha < 255u)
3847+	if (IsBuilding && !job && BigBetonAlpha < 254u)
3848 	{
3849 		if (gameGUI.timer50ms)
3850 			BigBetonAlpha += 25;
3851
3852-		BigBetonAlpha = std::min (255u, BigBetonAlpha);
3853+		BigBetonAlpha = std::min (254u, BigBetonAlpha);
3854 	}
3855
3856 	// calculate screen position
3857@@ -287,7 +287,7 @@
3858 	// draw indication, when building is complete
3859 	if (IsBuilding && BuildRounds == 0 && owner == gameGUI.getClient()->getActivePlayer() && !BuildPath)
3860 	{
3861-		const Uint32 color = 0xFF00 - (0x1000 * (gameGUI.getAnimationSpeed() % 0x8));
3862+		const Uint32 color = 0xFF00FF00 - (0x1000 * (gameGUI.getAnimationSpeed() % 0x8));
3863 		const Uint16 max = data.isBig ? 2 * gameGUI.getTileSize() - 3 : gameGUI.getTileSize() - 3;
3864 		SDL_Rect d = {Sint16 (screenPosition.x + 2), Sint16 (screenPosition.y + 2), max, max};
3865
3866@@ -297,7 +297,7 @@
3867 	// Draw the colored frame if necessary
3868 	if (gameGUI.colorChecked())
3869 	{
3870-		const Uint32 color = *static_cast<Uint32*> (owner->getColorSurface()->pixels);
3871+		const Uint32 color = 0xFF000000 | *static_cast<Uint32*> (owner->getColorSurface()->pixels);
3872 		const Uint16 max = data.isBig ? 2 * gameGUI.getTileSize() - 1 : gameGUI.getTileSize() - 1;
3873
3874 		SDL_Rect d = {Sint16 (screenPosition.x + 1), Sint16 (screenPosition.y + 1), max, max};
3875@@ -307,7 +307,7 @@
3876 	// draw the group selected frame if necessary
3877 	if (groupSelected)
3878 	{
3879-		const Uint32 color = 0x00FFFF00;
3880+		const Uint32 color = 0xFFFFFF00;
3881 		const Uint16 tilesize = gameGUI.getTileSize() - 3;
3882 		SDL_Rect d = {Sint16 (screenPosition.x + 2), Sint16 (screenPosition.y + 2), tilesize, tilesize};
3883
3884@@ -320,7 +320,7 @@
3885 		const int len = max / 4;
3886 		max -= 3;
3887 		SDL_Rect d = {Sint16 (screenPosition.x + 2), Sint16 (screenPosition.y + 2), max, max};
3888-		DrawSelectionCorner(buffer, d, len, gameGUI.getBlinkColor());
3889+		DrawSelectionCorner(buffer, d, len, 0xFF000000 | gameGUI.getBlinkColor());
3890 	}
3891
3892 	// draw health bar
3893@@ -360,7 +360,7 @@
3894 	tmp.x += offset;
3895 	tmp.y += offset;
3896
3897-	SDL_SetAlpha (uiData->overlay, SDL_SRCALPHA, alpha);
3898+	SDL_SetSurfaceAlphaMod (uiData->overlay, alpha);
3899 	blitWithPreScale (uiData->overlay_org, uiData->overlay, &src, surface, &tmp, zoomFactor);
3900 }
3901
3902@@ -374,7 +374,7 @@
3903 		frameNr = client->getGameGUI().getAnimationSpeed() % (uiData->overlay_org->w / uiData->overlay_org->h);
3904 	}
3905
3906-	int alpha = 255;
3907+	int alpha = 254;
3908 	if (StartUp && cSettings::getInstance().isAlphaEffects())
3909 		alpha = StartUp;
3910 	drawOverlayAnimation (surface, dest, zoomFactor, frameNr, alpha);
3911@@ -388,7 +388,7 @@
3912 	const cMap& map = *client.getMap();
3913 	if (IsBuilding && data.isBig && (!map.isWaterOrCoast (PosX, PosY) || map.fields[map.getOffset (PosX, PosY)].getBaseBuilding()))
3914 	{
3915-		SDL_SetAlpha (GraphicsData.gfx_big_beton, SDL_SRCALPHA, BigBetonAlpha);
3916+		SDL_SetSurfaceAlphaMod (GraphicsData.gfx_big_beton, BigBetonAlpha);
3917 		CHECK_SCALING (GraphicsData.gfx_big_beton, GraphicsData.gfx_big_beton_org, zoomFactor);
3918 		SDL_BlitSurface (GraphicsData.gfx_big_beton, NULL, surface, &tmp);
3919 	}
3920@@ -409,7 +409,7 @@
3921 	src.x = 0;
3922 	src.y = 0;
3923 	tmp = dest;
3924-	SDL_SetAlpha (GraphicsData.gfx_tmp, SDL_SRCALPHA, 255);
3925+	SDL_SetSurfaceAlphaMod (GraphicsData.gfx_tmp, 254);
3926 	SDL_BlitSurface (GraphicsData.gfx_tmp, &src, surface, &tmp);
3927 }
3928
3929@@ -434,7 +434,7 @@
3930 	src.x = 0;
3931 	src.y = 0;
3932 	tmp = dest;
3933-	SDL_SetAlpha (GraphicsData.gfx_tmp, SDL_SRCALPHA, 255);
3934+	SDL_SetSurfaceAlphaMod (GraphicsData.gfx_tmp, 254);
3935 	SDL_BlitSurface (GraphicsData.gfx_tmp, &src, surface, &tmp);
3936 }
3937
3938@@ -442,8 +442,8 @@
3939 {
3940 	if (client.getMap()->isWater (PosX, PosY) && (data.isStealthOn & TERRAIN_SEA)) return;
3941
3942-	if (StartUp && cSettings::getInstance().isAlphaEffects()) SDL_SetAlpha (uiData->shw[dir], SDL_SRCALPHA, StartUp / 5);
3943-	else SDL_SetAlpha (uiData->shw[dir], SDL_SRCALPHA, 50);
3944+	if (StartUp && cSettings::getInstance().isAlphaEffects()) SDL_SetSurfaceAlphaMod (uiData->shw[dir], StartUp / 5);
3945+	else SDL_SetSurfaceAlphaMod (uiData->shw[dir], 50);
3946 	SDL_Rect tmp = dest;
3947
3948 	// draw shadow
3949@@ -491,7 +491,7 @@
3950 	src.y = 0;
3951 	SDL_Rect tmp = dest;
3952
3953-	SDL_SetAlpha (GraphicsData.gfx_tmp, SDL_SRCALPHA, alpha);
3954+	SDL_SetSurfaceAlphaMod (GraphicsData.gfx_tmp, alpha);
3955 	blittAlphaSurface (GraphicsData.gfx_tmp, &src, surface, &tmp);
3956 }
3957
3958@@ -523,7 +523,7 @@
3959 		render_shadow (*client, surface, dest, zoomFactor);
3960 	}
3961
3962-	int alpha = 255;
3963+	int alpha = 254;
3964 	if (client)
3965 	{
3966 		if (StartUp && cSettings::getInstance().isAlphaEffects())
3967Index: vehicles.h
3968===================================================================
3969--- vehicles.h	(revision 3442)
3970+++ vehicles.h	(working copy)
3971@@ -281,13 +281,13 @@
3972 	* draws the main image of the vehicle onto the passed surface
3973 	*/
3974 	void render (const cClient* client, SDL_Surface* surface, const SDL_Rect& dest, float zoomFactor, bool drawShadow);
3975-	void render_simple (SDL_Surface* surface, const SDL_Rect& dest, float zoomFactor, int alpha = 255);
3976+	void render_simple (SDL_Surface* surface, const SDL_Rect& dest, float zoomFactor, int alpha = 254);
3977 	/**
3978 	* draws the overlay animation of the vehicle on the given surface
3979 	*@author: eiko
3980 	*/
3981 	void drawOverlayAnimation (const cClient* client, SDL_Surface* surface, const SDL_Rect& dest, float zoomFactor);
3982-	void drawOverlayAnimation (SDL_Surface* surface, const SDL_Rect& dest, float zoomFactor, int frameNr, int alpha = 255);
3983+	void drawOverlayAnimation (SDL_Surface* surface, const SDL_Rect& dest, float zoomFactor, int frameNr, int alpha = 254);
3984
3985 	bool isUnitLoaded() const { return Loaded; }
3986 	/**
3987Index: video.cpp
3988===================================================================
3989--- video.cpp	(revision 3450)
3990+++ video.cpp	(working copy)
3991@@ -23,57 +23,65 @@
3992 #include "autosurface.h"
3993 #include "defines.h"
3994 #include "log.h"
3995+#include "mouse.h"
3996 #include "pcx.h"
3997
3998+#include <algorithm>
3999 #include <vector>
4000
4001+#include <SDL.h>
4002+
4003+// TODO: [SDL2] move static into Video
4004+
4005+static SDL_Window* sdlWindow;
4006+static SDL_Renderer* sdlRenderer;
4007+static SDL_Texture* sdlTexture;
4008+
4009 cVideo Video;
4010
4011-/**
4012-* Will store either our detected videomodes
4013-* or some generic video modes if auto-detection in doDetect() failed
4014-*/
4015-static std::vector<sVidMode> vVideoMode;
4016+/** Slashscreen width  */
4017+#define SPLASHWIDTH 500
4018+/** Slashscreen height  */
4019+#define SPLASHHEIGHT 420
4020+#define COLOURDEPTH 32
4021+/**Minimum video mode resultion we need */
4022+#define MINWIDTH 640
4023+#define MINHEIGHT 480
4024
4025-/**
4026- * Some possible video modes. Don't use external!'
4027- */
4028-static const sVidMode videoModes[] =
4029+struct sVidMode
4030 {
4031-	{ MINWIDTH, MINHEIGHT, 0 },
4032-	{  800,  600,  1 },
4033-	{  960,  720,  2 },
4034-	{ 1024,  768,  3 },
4035-	{ 1024,  960,  4 },
4036-	{ 1152,  864,  5 },
4037-	{ 1280,  960,  6 },
4038-	{ 1280, 1024,  7 },
4039-	{ 1040, 1050,  8 },
4040-	{ 1600, 1200,  9 },
4041-	{ 2048, 1536, 10 }, // unusual resolutions start here
4042-	{ 1024,  480, 11 }, // Sony VAIO Pocketbook
4043-	{ 1152,  768, 12 }, // Apple TiBook
4044-	{ 1280,  854, 13 }, // Apple TiBook
4045-	{  640,  400, 14 }, // generic 16:10 widescreen
4046-	{  800,  500, 15 }, // as found modern
4047-	{ 1024,  640, 16 }, // notebooks
4048-	{ 1280,  800, 17 },
4049-	{ 1680, 1050, 18 },
4050-	{ 1920, 1200, 19 },
4051-	{ 1400, 1050, 20 }, // samsung x20
4052-	{ 1440,  900, 21 },
4053-	{ 1024,  600, 22 } // EEE PC
4054+	unsigned int width;
4055+	unsigned int height;
4056 };
4057
4058+static bool operator < (const sVidMode& lhs, const sVidMode& rhs)
4059+{
4060+	if (lhs.width != rhs.width) return lhs.width < rhs.width;
4061+	return lhs.height < rhs.height;
4062+}
4063+
4064+static bool operator == (const sVidMode& lhs, const sVidMode& rhs)
4065+{
4066+	return lhs.width == rhs.width && lhs.height == rhs.height;
4067+}
4068+
4069+struct sVidData
4070+{
4071+	unsigned int width;
4072+	unsigned int height;
4073+	int iColDepth;
4074+	bool bWindowMode;
4075+};
4076+
4077 /**
4078-* Stores our actual video data
4079+* Will store detected videomodes
4080 */
4081-static sVidData videoData = { MINWIDTH, MINHEIGHT, 0, SDL_SWSURFACE, 32, false };
4082+static std::vector<sVidMode> vVideoMode;
4083
4084 /**
4085-* cvar for centered splash on screen
4086+* Stores our actual video data
4087 */
4088-static char cVideoPos[] = "SDL_VIDEO_CENTERED=1";
4089+static sVidData videoData = { MINWIDTH, MINHEIGHT, 32, false };
4090
4091 int cVideo::setResolution (int iWidth, int iHeight, bool bApply)
4092 {
4093@@ -118,16 +126,7 @@
4094 	}
4095 	else
4096 	{
4097-		const SDL_VideoInfo* vInfo = SDL_GetVideoInfo();
4098-		if (vInfo != NULL)
4099-		{
4100-			Uint8 uBpp = vInfo->vfmt->BitsPerPixel;
4101-
4102-			if (iDepth > (Uint32) uBpp)
4103-			{
4104-				Log.write ("cVideo: Desired bpp is higher than the display (" + iToStr (uBpp) + "bpp) has!", cLog::eLOG_TYPE_WARNING);
4105-			}
4106-		}
4107+		// TODO: [SDL2] : sanitycheck
4108 		videoData.iColDepth = iDepth;
4109 	}
4110 	return 0;
4111@@ -141,7 +140,7 @@
4112 int cVideo::setWindowMode (bool bWindowMode, bool bApply)
4113 {
4114 	videoData.bWindowMode = bWindowMode;
4115-	Log.write ("cVideo: Window mode settings changed to " + std::string (Video.getWindowMode() ? "windowmode" : "fullscreen"), cLog::eLOG_TYPE_DEBUG);
4116+	Log.write ("cVideo: Window mode settings changed to " + std::string (getWindowMode() ? "windowmode" : "fullscreen"), cLog::eLOG_TYPE_DEBUG);
4117
4118 	if (bApply)
4119 	{
4120@@ -155,54 +154,43 @@
4121 	// TODO: add sanity check to redraw function
4122 	SDL_BlitSurface (buffer, NULL, screen, NULL);
4123
4124-	if (getWindowMode())
4125-	{
4126-		SDL_UpdateRect (screen, 0, 0, 0, 0);
4127-	}
4128-	else
4129-	{
4130-		SDL_Flip (screen);
4131-	}
4132+	SDL_UpdateTexture(sdlTexture, NULL, screen->pixels, screen->pitch);
4133+	SDL_RenderClear(sdlRenderer);
4134+	SDL_RenderCopy(sdlRenderer, sdlTexture, NULL, NULL);
4135+	SDL_RenderPresent(sdlRenderer);
4136 }
4137
4138 int cVideo::applySettings()
4139 {
4140-	int oldX = MINWIDTH;
4141-	int oldY = MINHEIGHT;
4142-	int oldDepth = COLOURDEPTH;
4143-	Uint32 oldSurface = SDL_SWSURFACE;
4144-
4145-	if (screen != NULL)
4146-	{
4147-		oldX = screen->w;
4148-		oldY = screen->h;
4149-		oldDepth = screen->format->BitsPerPixel;
4150-		oldSurface = screen->flags;
4151-	}
4152-
4153 	Log.write ("cVideo: Applying new video settings", cLog::eLOG_TYPE_DEBUG);
4154-	screen = SDL_SetVideoMode (getResolutionX(), getResolutionY(), getColDepth(), getSurfaceType() | (getWindowMode() ? 0 : SDL_FULLSCREEN));
4155
4156-	if (screen == NULL)
4157+	SDL_SetWindowBordered(sdlWindow, SDL_TRUE);
4158+	SDL_SetWindowSize (sdlWindow, getResolutionX(), getResolutionY());
4159+	// TODO: [SDL2]: manage window mode correctly
4160+	if (SDL_SetWindowFullscreen (sdlWindow, !getWindowMode()) == -1)
4161 	{
4162-		Log.write ("cVideo:  => Failed. Reverting!", cLog::eLOG_TYPE_ERROR);
4163-		Log.write (SDL_GetError(), cLog::eLOG_TYPE_ERROR);
4164-		setResolution (oldX, oldY, false);
4165-		setColDepth (oldDepth);
4166-		// TODO: Don't know how to reset fullscreen mode proper from old values
4167-		Log.write ("cVideo: TODO: Don't know how to reset fullscreen mode proper from old values.", cLog::eLOG_TYPE_WARNING);
4168-		screen = SDL_SetVideoMode (oldX, oldY, oldDepth, oldSurface);
4169-		draw();
4170+		videoData.width = screen->w;
4171+		videoData.height = screen->h;
4172+		SDL_SetWindowSize (sdlWindow, getResolutionX(), getResolutionY());
4173 		return -1;
4174 	}
4175-	else
4176-	{
4177-		if (buffer) SDL_FreeSurface (buffer);
4178-		buffer = SDL_CreateRGBSurface (getSurfaceType(), getResolutionX(), getResolutionY(), getColDepth(), 0, 0, 0, 0);
4179-	}
4180+
4181+	if (screen) SDL_FreeSurface (screen);
4182+	screen = SDL_CreateRGBSurface (0, getResolutionX(), getResolutionY(), getColDepth(),
4183+								   0, 0, 0, 0);
4184+								   //0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
4185+	SDL_RenderSetLogicalSize(sdlRenderer, getResolutionX(), getResolutionY());
4186+	if (buffer) SDL_FreeSurface (buffer);
4187+	buffer = SDL_CreateRGBSurface (0, getResolutionX(), getResolutionY(), getColDepth(),
4188+								   //0, 0, 0, 0);
4189+								   0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
4190+	if (sdlTexture) SDL_DestroyTexture (sdlTexture);
4191+	sdlTexture = SDL_CreateTexture(sdlRenderer,
4192+								   SDL_PIXELFORMAT_ARGB8888,
4193+								   SDL_TEXTUREACCESS_STREAMING,
4194+								   getResolutionX(), getResolutionY());
4195 	draw();
4196 	return 0;
4197-
4198 }
4199
4200 void cVideo::clearBuffer()
4201@@ -215,22 +203,33 @@
4202  */
4203 void cVideo::initSplash()
4204 {
4205-	if (putenv (cVideoPos) != 0)  // set window to center of screen.
4206-	{
4207-		Log.write ("cVideo: Couldn't export SDL_VIDEO_CENTERED", cLog::eLOG_TYPE_WARNING);
4208-	}
4209+	AutoSurface splash (LoadPCX (SPLASH_BACKGROUND));
4210
4211-	buffer = LoadPCX (SPLASH_BACKGROUND);
4212-	SDL_WM_SetIcon (AutoSurface (SDL_LoadBMP (MAXR_ICON)), NULL);
4213+	std::string sVersion = PACKAGE_NAME " " PACKAGE_VERSION " " PACKAGE_REV " ";
4214
4215-	// BEGIN VERSION STRING
4216-	std::string sVersion = PACKAGE_NAME; sVersion += " ";
4217-	sVersion += PACKAGE_VERSION; sVersion += " ";
4218-	sVersion += PACKAGE_REV; sVersion += " ";
4219-	SDL_WM_SetCaption (sVersion.c_str(), 0);
4220-	// END VERSION STRING
4221+	sdlWindow = SDL_CreateWindow(sVersion.c_str(),
4222+								 SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
4223+								 getSplashW(), getSplashH(),
4224+								 SDL_WINDOW_BORDERLESS | SDL_WINDOW_OPENGL);
4225+	SDL_SetWindowIcon (sdlWindow, AutoSurface (SDL_LoadBMP (MAXR_ICON)));
4226+	SDL_SetWindowFullscreen (sdlWindow, !getWindowMode());
4227+	sdlRenderer = SDL_CreateRenderer(sdlWindow, -1, 0);
4228
4229-	screen = SDL_SetVideoMode (getSplashW(), getSplashH(), getColDepth(), getSurfaceType() | SDL_NOFRAME);
4230+	screen = SDL_CreateRGBSurface(0, getSplashW(), getSplashH(), getColDepth(),
4231+								  0, 0, 0, 0);
4232+	buffer = SDL_CreateRGBSurface(0, getSplashW(), getSplashH(), getColDepth(),
4233+								  0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
4234+
4235+	SDL_BlitSurface (splash, NULL, buffer, NULL);
4236+
4237+	sdlTexture = SDL_CreateTexture(sdlRenderer,
4238+								   SDL_PIXELFORMAT_ARGB8888,
4239+								   SDL_TEXTUREACCESS_STREAMING,
4240+								   getSplashW(), getSplashH());
4241+	// make the scaled rendering look smoother.
4242+	SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
4243+	SDL_RenderSetLogicalSize(sdlRenderer, getSplashW(), getSplashH());
4244+
4245 	draw();
4246 }
4247
4248@@ -249,106 +248,38 @@
4249 	return videoData.height;
4250 }
4251
4252-void cVideo::setSurfaceType (Uint32 iSurfaceType)
4253-{
4254-	// TODO: set all surfaces to new surface type
4255-	if (videoData.iSurfaceType != iSurfaceType)
4256-	{
4257-		Log.write ("cVideo: Surface type " + getSurfaceName (getSurfaceType()) + " overwritten with " + getSurfaceName (iSurfaceType), cLog::eLOG_TYPE_INFO);
4258-	}
4259-	videoData.iSurfaceType = iSurfaceType;
4260-}
4261-
4262-Uint32 cVideo::getSurfaceType() const
4263-{
4264-	return videoData.iSurfaceType;
4265-}
4266-
4267-int cVideo::getVideoNum() const
4268-{
4269-	return sizeof (videoModes) / sizeof (sVidMode);
4270-}
4271-
4272 std::string cVideo::getVideoMode (unsigned int iMode) const
4273 {
4274-	// if no valid mode is given we return minimal video mode
4275-	std::string sTmp = iToStr (getMinW()) + "x" + iToStr (getMinH());
4276-	bool bFound = false;
4277-
4278-	for (unsigned int i = 0; i < vVideoMode.size(); i++)
4279-	{
4280-		if (vVideoMode[i].mode == iMode)
4281-		{
4282-			sTmp = iToStr (vVideoMode[i].width) + "x" + iToStr (vVideoMode[i].height);
4283-			bFound = true;
4284-			break;
4285-		}
4286-	}
4287-
4288-	if (!bFound)
4289-	{
4290-		Log.write ("cVideo: Video mode " + iToStr (iMode) + " not found. Returning default video mode " + sTmp, cLog::eLOG_TYPE_WARNING);
4291-	}
4292-
4293-	return sTmp;
4294+	return iToStr (vVideoMode[iMode].width) + "x" + iToStr (vVideoMode[iMode].height);
4295 }
4296
4297-bool cVideo::doDetection()
4298+void cVideo::doDetection()
4299 {
4300 	Log.write ("cVideo: Screen resolution detection started. Results may vary!", cLog::eLOG_TYPE_INFO);
4301
4302-	const SDL_VideoInfo* vInfo = SDL_GetVideoInfo();
4303-	vVideoMode.clear();
4304-
4305-	// detect us some video modes. detection works in fullscreen only.
4306-	// we try HW and SW surfaces
4307-	SDL_Rect** rDetectedModes = SDL_ListModes (vInfo->vfmt, SDL_FULLSCREEN | getSurfaceType());
4308-
4309-	if (rDetectedModes == NULL)
4310+	const int displayIndex = sdlWindow ? SDL_GetWindowDisplayIndex (sdlWindow) : 0;
4311+	const unsigned int modeCount = SDL_GetNumDisplayModes(displayIndex);
4312+	/* Print and store detected modes */
4313+	for (unsigned int i = 0; i != modeCount; ++i)
4314 	{
4315-		// try SWSURFACE if HWSURFACE doesn't work and vice versa
4316-		switchSurface();
4317-		// try with SWSURFACE
4318-		rDetectedModes = SDL_ListModes (vInfo->vfmt, SDL_FULLSCREEN | getSurfaceType());
4319-		if (rDetectedModes == NULL)
4320-		{
4321-			Log.write ("cVideo: No video modes detected. Probably bad!", cLog::eLOG_TYPE_ERROR);
4322-			vVideoMode.resize (getVideoNum());
4323-			// write some default video modes
4324-			for (size_t i = 0; i != vVideoMode.size(); ++i)
4325-			{
4326-				Log.write ("cVideo: Offering default video mode " + iToStr (i) + " (" + getVideoMode (i) + ")", cLog::eLOG_TYPE_WARNING);
4327-				vVideoMode.at (i) = videoModes[i];
4328-			}
4329-			return false;
4330-		}
4331-		else
4332-		{
4333-			Log.write ("cVideo: Detected video modes with " + getSurfaceName (getSurfaceType()) + " and " + iToStr (vInfo->vfmt->BitsPerPixel) + " bpp", cLog::eLOG_TYPE_INFO);
4334-		}
4335-	}
4336-	else
4337-	{
4338-		Log.write ("cVideo: Detected video modes with " + getSurfaceName (getSurfaceType()) + " and " + iToStr (vInfo->vfmt->BitsPerPixel) + " bpp", cLog::eLOG_TYPE_INFO);
4339-	}
4340+		SDL_DisplayMode mode;
4341+		SDL_GetDisplayMode (displayIndex, i, &mode);
4342
4343-	/* Print and store detected modes */
4344-	for (unsigned int i = 0; rDetectedModes[i]; ++i)
4345-	{
4346 		// write detected video modes
4347 		// (don't write modes *below* the minimum mode'
4348-		if (rDetectedModes[i]->w >= MINWIDTH && rDetectedModes[i]->h >= MINHEIGHT)
4349+		if (mode.w >= MINWIDTH && mode.h >= MINHEIGHT)
4350 		{
4351-			sVidMode tmp = {rDetectedModes[i]->w, rDetectedModes[i]->h, i};
4352+			const sVidMode tmp = { unsigned (mode.w), unsigned (mode.h) };
4353 			vVideoMode.push_back (tmp);
4354-			Log.write ("cVideo: Offering detected video mode " + iToStr (i) + " (" + iToStr (rDetectedModes[i]->w) + "x" + iToStr (rDetectedModes[i]->h) + ")", cLog::eLOG_TYPE_INFO);
4355 		}
4356 	}
4357-
4358-	// sanity check on minimal needed screen resolution that we need at last
4359-	bHaveMinMode();
4360-
4361-	return true;
4362+	std::sort (vVideoMode.begin(), vVideoMode.end());
4363+	vVideoMode.erase (std::unique (vVideoMode.begin(), vVideoMode.end()), vVideoMode.end());
4364+	for (size_t i = 0; i != vVideoMode.size(); ++i)
4365+	{
4366+		sVidMode& mode = vVideoMode[i];
4367+		Log.write ("cVideo: Offering detected video mode " + iToStr (i) + " (" + iToStr (mode.width) + "x" + iToStr (mode.height) + ")", cLog::eLOG_TYPE_INFO);
4368+	}
4369 }
4370
4371 bool cVideo::bHaveMinMode() const
4372@@ -402,17 +333,3 @@
4373 {
4374 	return MINHEIGHT;
4375 }
4376-
4377-std::string cVideo::getSurfaceName (Uint32 iSurfaceType) const
4378-{
4379-	if (iSurfaceType == SDL_SWSURFACE) return "SDL_SWSURFACE";
4380-	else if (iSurfaceType == SDL_HWSURFACE) return "SDL_HWSURFACE";
4381-	else return "UNKNOWN";
4382-}
4383-
4384-void cVideo::switchSurface()
4385-{
4386-	if (getSurfaceType() == SDL_SWSURFACE) setSurfaceType (SDL_HWSURFACE);
4387-	else if (getSurfaceType() == SDL_HWSURFACE) setSurfaceType (SDL_SWSURFACE);
4388-	else Log.write ("cVideo: Can't' switch surface types. Unknown surface type " + iToStr (getSurfaceType()) + " detected.", cLog::eLOG_TYPE_ERROR);
4389-}
4390Index: video.h
4391===================================================================
4392--- video.h	(revision 3442)
4393+++ video.h	(working copy)
4394@@ -20,34 +20,17 @@
4395 #ifndef videoH
4396 #define videoH
4397
4398-#include <SDL.h>
4399 #include <string>
4400
4401+struct SDL_Surface;
4402
4403 // Screenbuffers //////////////////////////////////////////////////////////////
4404 EX SDL_Surface* screen; // Der Bildschirm
4405 EX SDL_Surface* buffer; // Der Bildschirm-Buffer
4406
4407-
4408-struct sVidMode
4409-{
4410-	unsigned int width;
4411-	unsigned int height;
4412-	unsigned int mode;
4413-};
4414-
4415-struct sVidData
4416-{
4417-	unsigned int width;
4418-	unsigned int height;
4419-	unsigned int mode;
4420-	Uint32 iSurfaceType;
4421-	int iColDepth;
4422-	bool bWindowMode;
4423-};
4424-
4425 /**
4426- * cVideo class. Stores videosettings (and can hopefully operate 'em too one day'):-)
4427+ * cVideo class.
4428+ * Stores videosettings (and can hopefully operate 'em too one day'):-)
4429  *
4430  * @author Bernd "beko" Kosmahl
4431  */
4432@@ -55,162 +38,125 @@
4433 {
4434 public:
4435 	/**
4436-	*Sets whether app should appear windowed or in fullscreen mode
4437-	*@param bWindowMode pass true if app should work in windowed mode<br>pass false it app should start in fullscreen
4438-	*@param bApply set to true if app should apply new windowMode too
4439-	*@return 0 on success
4440+	* Sets whether app should appear windowed or in fullscreen mode
4441+	* @param bWindowMode pass true if app should work in windowed mode
4442+	*                    pass false it app should start in fullscreen
4443+	* @param bApply set to true if app should apply new windowMode too
4444+	* @return 0 on success
4445 	*/
4446 	int setWindowMode (bool bWindowMode, bool bApply = false);
4447
4448 	/**
4449-	*Get whether app should appear windowed or in fullscreen mode
4450-	*@return  true if app should work in windowed mode<br>false it app should start in fullscreen
4451+	* Get whether app should appear windowed or in fullscreen mode
4452+	* @return  true if app should work in windowed mode
4453+	*          false it app should start in fullscreen
4454 	*/
4455 	bool getWindowMode() const;
4456
4457 	/**
4458-	*Set resolution/dimension of app window.
4459-	*@param iWidth desired window width
4460-	*@param iHeight desired window height
4461-	*@param bApply  set to true if app should apply new resolution too
4462-	*@return 0 on success
4463+	* Set resolution/dimension of app window.
4464+	* @param iWidth desired window width
4465+	* @param iHeight desired window height
4466+	* @param bApply  set to true if app should apply new resolution too
4467+	* @return 0 on success
4468 	*/
4469 	int setResolution (int iWidth, int iHeight, bool bApply = false);
4470
4471 	/**
4472-	*@deprecated for compat only - will be removed!
4473-	*@return stored window width
4474+	* @deprecated for compat only - will be removed!
4475+	* @return stored window width
4476 	*/
4477 	int getResolutionX() const;
4478
4479 	/**
4480-	*@deprecated for compat only - will be removed!
4481-	*@return stored window height
4482+	* @deprecated for compat only - will be removed!
4483+	* @return stored window height
4484 	*/
4485 	int getResolutionY() const;
4486
4487 	/**
4488-	*Sets colordepth
4489-	*@param iDepth colordepth to set. e.g. 32 (bpp)
4490-	*@return 0 on success
4491+	* Sets colordepth
4492+	* @param iDepth colordepth to set. e.g. 32 (bpp)
4493+	* @return 0 on success
4494 	*/
4495 	int setColDepth (unsigned int iDepth);
4496
4497 	/**
4498-	*Gets colordepth
4499-	@return colordepth
4500+	* Gets colordepth
4501+	* @return colordepth
4502 	*/
4503 	int getColDepth() const;
4504
4505 	/**
4506-	*Sets SurfaceType
4507-	*@param iSurfaceType surfacetype to set. e.g. SDL_HWSURFACE
4508+	* @return Detected videomodes
4509 	*/
4510-	void setSurfaceType (Uint32 iSurfaceType);
4511-
4512-	/**
4513-	*Gets SurfaceType
4514-	@return surfacetype e.g. SDL_HWSURFACE
4515-	*/
4516-	Uint32 getSurfaceType() const;
4517-
4518-	/**
4519-	*@return Detected videomodes
4520-	*/
4521 	int getVideoSize() const;
4522
4523 	/**
4524-	*@param iMode video mode num from video mode array
4525-	*@return Videomode as string widthxheight. If iMode is unknown minimal needed videomode will be returned.
4526+	* @param iMode video mode num from video mode array
4527+	* @return Videomode as string widthxheight.
4528+	*         If iMode is unknown minimal needed videomode will be returned.
4529 	*/
4530 	std::string getVideoMode (unsigned int iMode) const;
4531
4532 	/**
4533-	*Try to autodetect avail video modes from SDL. Might fail.
4534-	*@return true on success
4535+	* Try to autodetect availavle video modes from SDL.
4536 	*/
4537-	bool doDetection();
4538+	void doDetection();
4539
4540 	/**
4541-	*Check whether the provided mode is known to our video mode list
4542-	*@param width Screenwidth to look for
4543-	*@param height Screenheight to look for
4544-	*@return iMode or -1 on unknown mode
4545+	* Check whether the provided mode is known to our video mode list
4546+	* @param width Screenwidth to look for
4547+	* @param height Screenheight to look for
4548+	* @return iMode or -1 on unknown mode
4549 	*/
4550 	int validateMode (unsigned int iWidth, unsigned int iHeight) const;
4551
4552 	/**
4553-	*@return Splash width
4554+	* @return Splash width
4555 	*/
4556 	int getSplashW() const;
4557
4558 	/**
4559-	*@return Splash height
4560+	* @return Splash height
4561 	*/
4562 	int getSplashH() const;
4563
4564 	/**
4565-	*@return Minimal needed screen resolution width
4566+	* @return Minimal needed screen resolution width
4567 	*/
4568 	int getMinW() const;
4569
4570 	/**
4571-	*@return Minimal needed screen resolution height
4572+	* @return Minimal needed screen resolution height
4573 	*/
4574 	int getMinH() const;
4575
4576 	/**
4577-	*Inits our buffers and draws the splashscreen
4578+	* Inits our buffers and draws the splashscreen
4579 	*/
4580 	void initSplash();
4581
4582 	/**
4583-	*clears buffer (black)
4584+	* clears buffer (black)
4585 	*/
4586 	void clearBuffer();
4587
4588 	/**
4589-	*Blits or updates buffer to screen depending on windowmode
4590+	* Blits or updates buffer to screen depending on windowmode
4591 	*/
4592 	void draw();
4593
4594 private:
4595-
4596-	/** Slashscreen width  */
4597-#define SPLASHWIDTH 500
4598-	/** Slashscreen height  */
4599-#define SPLASHHEIGHT 420
4600-#define COLOURDEPTH 32
4601-	/**Minimum video mode resultion we need */
4602-#define MINWIDTH 640
4603-#define MINHEIGHT 480
4604 	/**
4605-	*@return Length of videomodes array
4606+	* Checks whether our minimal needed videomode has been autodetected
4607+	* @return true if mininal video mode looks valid
4608 	*/
4609-	int getVideoNum() const;
4610-
4611-	/**
4612-	* Just for readable log entries
4613-	*@param iSurfaceType surface type SDL_HWSURFACE or SDL_SWSURFACE
4614-	*@return Surface type as string e.g."SDL_HWSURFACE"
4615-	*/
4616-	std::string getSurfaceName (Uint32 iSurfaceType) const;
4617-
4618-	/**
4619-	*Switch SDL_HWSURFACE with SDL_SWSURFACE and vice versa
4620-	*/
4621-	void switchSurface();
4622-
4623-	/**
4624-	*Checks whether our minimal needed videomode has been autodetected
4625-	*@return true if mininal video mode looks valid
4626-	*/
4627 	bool bHaveMinMode() const;
4628
4629 	/**
4630-	*Applys current video settings
4631-	*@param bNoFrame set to true to start without window frame (e.g. for splashscreen)
4632-	*@return 0 on success
4633+	* Applys current video settings
4634+	* @return 0 on success
4635 	*/
4636 	int applySettings();
4637 };
4638