From 25cb8208b686e7551495571f5e21db88120f8db5 Mon Sep 17 00:00:00 2001
From: Carsten Teibes <dev@f4ke.de>
Date: Sun, 5 May 2019 22:55:38 +0200
Subject: [PATCH 35/36] Set window caption to current level name

---
 src/io/gfx/video.cpp                | 37 ++++++++++++++++++++++++++++-
 src/io/gfx/video.h                  |  3 ++-
 src/jj1bonuslevel/jj1bonuslevel.cpp |  3 +++
 src/jj1level/jj1level.cpp           |  2 ++
 src/jj1level/jj1levelload.cpp       | 11 ++++++++-
 5 files changed, 53 insertions(+), 3 deletions(-)

--- a/src/io/gfx/video.cpp
+++ b/src/io/gfx/video.cpp
@@ -166,7 +166,7 @@ bool Video::init (int width, int height,
 
 	}
 
-	SDL_WM_SetCaption("OpenJazz", NULL);
+	setTitle(NULL);
 
 	findMaxResolution();
 
@@ -354,6 +354,41 @@ int Video::getHeight () {
 
 }
 
+
+/**
+ * Sets the window title.
+ *
+ * @param the title or NULL, to use default
+ */
+void Video::setTitle (const char *title) {
+
+	const char titleBase[] = "OpenJazz";
+	char *windowTitle = NULL;
+	int titleLen = strlen(titleBase) + 1;
+
+	if (title != NULL) {
+
+		titleLen = strlen(titleBase) + 3 + strlen(title) + 1;
+
+	}
+
+	windowTitle = new char[titleLen];
+
+	strcpy(windowTitle, titleBase);
+
+	if (title != NULL) {
+
+		strcat(windowTitle, " - ");
+		strcat(windowTitle, title);
+
+	}
+
+	SDL_WM_SetCaption(windowTitle, NULL);
+
+	delete[] windowTitle;
+
+}
+
 
 #ifdef SCALE
 /**
--- a/src/io/gfx/video.h
+++ b/src/io/gfx/video.h
@@ -123,7 +123,7 @@ class Video {
 
 		bool       init                  (int width, int height, bool startFullscreen);
 
-		bool       reset                (int width, int height);
+		bool       reset                 (int width, int height);
 
 		void       setPalette            (SDL_Color *palette);
 		SDL_Color* getPalette            ();
@@ -134,6 +134,7 @@ class Video {
 		int        getMaxHeight          ();
 		int        getWidth              ();
 		int        getHeight             ();
+		void       setTitle              (const char *title);
 #ifdef SCALE
 		int        getScaleFactor        ();
 		int        setScaleFactor        (int newScaleFactor);
--- a/src/jj1bonuslevel/jj1bonuslevel.cpp
+++ b/src/jj1bonuslevel/jj1bonuslevel.cpp
@@ -378,6 +378,7 @@ JJ1BonusLevel::JJ1BonusLevel (Game* owne
 
 	multiplayer = multi;
 
+	video.setTitle("BONUS LEVEL");
 
 	return;
 
@@ -398,6 +399,8 @@ JJ1BonusLevel::~JJ1BonusLevel () {
 
 	delete font;
 
+	video.setTitle(NULL);
+
 	return;
 
 }
--- a/src/jj1level/jj1level.cpp
+++ b/src/jj1level/jj1level.cpp
@@ -147,6 +147,8 @@ JJ1Level::~JJ1Level () {
 
 	resampleSounds();
 
+	video.setTitle(NULL);
+
 	return;
 
 }
--- a/src/jj1level/jj1levelload.cpp
+++ b/src/jj1level/jj1levelload.cpp
@@ -415,6 +415,7 @@ int JJ1Level::load (char* fileName, bool
 	unsigned char* buffer;
 	const char* ext;
 	char* string = NULL;
+	char* levelname = NULL;
 	int tiles;
 	int count, x, y, type;
 	unsigned char startX, startY;
@@ -489,6 +490,9 @@ int JJ1Level::load (char* fileName, bool
 
 	}
 
+	levelname = new char[strlen(string) + 14];
+	strcpy(levelname, string);
+
 	switch (fileName[5]) {
 
 		case '0':
@@ -507,6 +511,7 @@ int JJ1Level::load (char* fileName, bool
 
 			string[0] = 0;
 			ext = "SECRET LEVEL";
+			strcat(levelname, " ");
 
 			break;
 
@@ -518,9 +523,13 @@ int JJ1Level::load (char* fileName, bool
 
 	}
 
-	video.setPalette(menuPalette);
+	strcat(levelname, ext);
 
+	video.setPalette(menuPalette);
 	video.clearScreen(0);
+	video.setTitle(levelname);
+
+	delete[] levelname;
 
 	x = (canvasW >> 1) - ((strlen(string) + strlen(ext)) << 2);
 	x = fontmn2->showString("LOADING ", x - 60, (canvasH >> 1) - 16);
