From e58d6d7b84074ba709cf88e9a3d538f2978193f1 Mon Sep 17 00:00:00 2001
From: Oliver Bock <oliver.bock@aei.mpg.de>
Date: Wed, 15 Oct 2008 15:00:26 +0200
Subject: [PATCH] Added window icon

---
 src/framework/WindowManager.cpp |  23 +++++++++++++++++++++++
 src/framework/WindowManager.h   |  18 ++++++++++++++++++
 src/starsphere/EaH.bmp.res      | Bin 0 -> 3126 bytes
 src/starsphere/main.cpp         |  13 +++++++++++--
 src/starsphere/resources.orc    |   1 +
 5 files changed, 53 insertions(+), 2 deletions(-)
 create mode 100644 src/starsphere/EaH.bmp.res

diff --git a/src/framework/WindowManager.cpp b/src/framework/WindowManager.cpp
index e8df303..179d653 100644
--- a/src/framework/WindowManager.cpp
+++ b/src/framework/WindowManager.cpp
@@ -371,6 +371,29 @@ void WindowManager::setWindowIcon(const string filename) const
 	}
 }
 
+void WindowManager::setWindowIcon(const unsigned char *data, const int size) const
+{
+	// prepare data buffer structure
+	SDL_RWops *buffer = SDL_RWFromMem((void*) data, size);
+
+	if(buffer != NULL) {
+		// load BMP from prepared data buffer
+		SDL_Surface *surface = SDL_LoadBMP_RW(buffer, 1);
+
+		if(surface != NULL) {
+			// set window icon
+			SDL_WM_SetIcon(surface, NULL);
+			SDL_FreeSurface(surface);
+		}
+		else {
+			cerr << "Could not create window icon surface: " << SDL_GetError() << endl;
+		}
+	}
+	else {
+		cerr << "Could not prepare window icon data: " << SDL_GetError() << endl;
+	}
+}
+
 void WindowManager::toggleFullscreen()
 {
 	// toggle fullscreen bit and reset video mode
diff --git a/src/framework/WindowManager.h b/src/framework/WindowManager.h
index 2b80dff..32b4bdf 100644
--- a/src/framework/WindowManager.h
+++ b/src/framework/WindowManager.h
@@ -133,10 +133,28 @@ public:
 	/**
 	 * \brief Set the main window's icon
 	 *
+	 * This method uses the provided filename to load a bitmap (BMP) image
+	 * from disk which in turn is displayed as the main window's icon.
+	 *
+	 * Note: The icon should have a size of 32x32 pixels!
+	 *
 	 * \param filename The new icon's filename
 	 */
 	void setWindowIcon(const string filename) const;
 
+	/**
+	 * \brief Set the main window's icon
+	 *
+	 * This method uses the provided raw data pointer to load a bitmap (BMP) image
+	 * from memory which in turn is displayed as the main window's icon.
+	 *
+	 * Note: The icon should have a size of 32x32 pixels!
+	 *
+	 * \param data Pointer to the bitmap data buffer
+	 * \param size Size of the bitmap data buffer
+	 */
+	void setWindowIcon(const unsigned char *data, const int size) const;
+
 	/**
 	 * \brief Toggles the fullscreen state of the main window
 	 *
diff --git a/src/starsphere/EaH.bmp.res b/src/starsphere/EaH.bmp.res
new file mode 100644
index 0000000000000000000000000000000000000000..3fd2c9f65dbcef70daf906ef885013fb30263403
GIT binary patch
literal 3126
zcmZ?rHRE9b12YB&1`P%V1_dZ)WRL)hGw?7l2y;U)M1X<8jqL<Uh;8S8k`PITyRn@h
z$#Axv|Iy61W7}ZGKLHQoZ`+C=33cvZTk#t13}o}o_*?Z9J&iDczP`Q|aX>{yMO|H8
zD5L~#1>Afy{?=W)cK!bS`#%NX_wV0JmMqcI(gOJc98(bU9oTjRITcf2Fhc9suV0Of
zjQHEOLV^flz8%|!%A6?(MHH}p|NgD%6~s303XRM^di1DJ-4wRXKk=J?@#4j%$|;2@
zJ!mMUZ6;Qf-Z?v^ZDv^Gbg9xFh{+HVSNKFnN1F*W*|BXvLu?Bk;zKLm!d;Hvd?O<x
zEB*-(+mT6#F5*duUd;F%5c8ec4scFB1WJ2TFR*R=N{lavcfSkU1~Z9dbxTWKU0n%%
z8=j<YDw^-ib|5!5_sNqd|NsC0@Zm#hYO0Eg3Kh+_U|X<#`*wJ?+qP|+mX;PV=GTX?
z)rYVZ`>=J?<-oQ7|Nq~}$SA>?A0k^H!j|UDws-GdxPslgcWc@x>ejOnL=Y1QnqTh6
z*3r@N<Hrw(6;<senmL>V4cDy)Ii48z*N3p>`tZjGng^tK*oGPDMoSQ5I7#M1e5zT@
zrc+HgSm3rpbP)_6h_d<+5=@3z0ntc*^PQcYt#m~bT?A6xg^`hF0zW~dRgUl`F89x!
zJJ;6M*2c!h9u-*O1r`<->gwuBu0n7taG4KDhrdV!@87?lIB}x7y1HfpKmPECm`?`z
z_3Kw%U0pQu%l+7@3!=#|4XYL{19i<b9%T2|hp+`YYrcN{8moGe1g~7VqT{Lv&m)lV
zhmf&;CXJ<u9d$W)P-#aFR#efQU(ubPTbt+{X##OMgoKz3C(HdnWnHlkPExa&4G+>O
bX46N_-EfnMWI$X+JV~UnaAm}s3{eRHo2WdR

literal 0
HcmV?d00001

diff --git a/src/starsphere/main.cpp b/src/starsphere/main.cpp
index df13f6e..112becb 100644
--- a/src/starsphere/main.cpp
+++ b/src/starsphere/main.cpp
@@ -72,8 +72,9 @@ int main(int argc, char **argv)
         exit(1);
     }
 
-	// create font resource instance
+	// create font and icon resource instances
 	const Resource *fontResource = factory.createInstance("FontSansSerif");
+	const Resource *iconResource = factory.createInstance("AppIconBMP");
 
 	if(fontResource == NULL) {
 		cerr << "Font resource could not be loaded!" << endl;
@@ -88,6 +89,14 @@ int main(int argc, char **argv)
 		exit(1);
 	}
 
+	if(iconResource != NULL && iconResource->data()->size() > 0) {
+		window.setWindowIcon(&iconResource->data()->at(0), iconResource->data()->size());
+		delete iconResource;
+	}
+	else {
+		cerr << "Icon resource could not be loaded! Continuing anyway..." << endl;
+	}
+
     window.setWindowCaption("Einstein@Home");
 
     // register starsphere as event observer
@@ -106,7 +115,7 @@ int main(int argc, char **argv)
 			window.toggleFullscreen();
 #ifdef __APPLE__
             SetMacSSLevel();
-#endif    
+#endif
 		}
 	}
 
diff --git a/src/starsphere/resources.orc b/src/starsphere/resources.orc
index 82517aa..9c151b6 100644
--- a/src/starsphere/resources.orc
+++ b/src/starsphere/resources.orc
@@ -21,3 +21,4 @@
 # Resource specification of: Einstein@Home graphics application
 
 FontSansSerif|LiberationSans-Regular.ttf.res
+AppIconBMP|EaH.bmp.res
-- 
GitLab