changeset 61:18c2a21ac0ad

allow clients to set a custom window title and icon
author spq@33b003aa-7bff-0310-803a-e67f0ece8222
date Wed, 16 Jul 2008 12:37:41 +0000
parents 1de7e6740a4a
children a5a677837306
files engine/core/controller/engine.cpp engine/core/controller/engine.i engine/core/controller/enginesettings.cpp engine/core/controller/enginesettings.h engine/core/video/opengl/renderbackendopengl.cpp engine/core/video/opengl/renderbackendopengl.h engine/core/video/renderbackend.h engine/core/video/sdl/renderbackendsdl.cpp engine/core/video/sdl/renderbackendsdl.h
diffstat 9 files changed, 56 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/engine/core/controller/engine.cpp	Tue Jul 15 20:12:30 2008 +0000
+++ b/engine/core/controller/engine.cpp	Wed Jul 16 12:37:41 2008 +0000
@@ -192,7 +192,9 @@
 			m_settings.getScreenWidth(),
 			m_settings.getScreenHeight(),
 			static_cast<unsigned char>(m_settings.getBitsPerPixel()),
-			m_settings.isFullScreen());
+			m_settings.isFullScreen(),
+			m_settings.getWindowTitle(),
+			m_settings.getWindowIcon());
 		FL_LOG(_log, "Main screen created");
 
 #ifdef HAVE_OPENGL
--- a/engine/core/controller/engine.i	Tue Jul 15 20:12:30 2008 +0000
+++ b/engine/core/controller/engine.i	Wed Jul 16 12:37:41 2008 +0000
@@ -69,6 +69,10 @@
 		std::string getDefaultFontGlyphs() const;
 		void setImageChunkingSize(unsigned int size);
 		unsigned int getImageChunkingSize();
+		void setWindowTitle(const std::string& title);
+		std::string getWindowTitle() const;
+		void setWindowIcon(const std::string& icon);
+		std::string getWindowIcon() const;
 		
 	private:
 		EngineSettings();
--- a/engine/core/controller/enginesettings.cpp	Tue Jul 15 20:12:30 2008 +0000
+++ b/engine/core/controller/enginesettings.cpp	Wed Jul 16 12:37:41 2008 +0000
@@ -44,6 +44,8 @@
 		m_sldremovefakealpha(false),
 		m_screenwidth(800),
 		m_screenheight(600),
+		m_windowtitle("FIFE"),
+		m_windowicon(""),
 		m_defaultfontpath(""),
 		m_defaultfontsize(8),
 		m_defaultfontglyphs(""),
@@ -136,5 +138,14 @@
 	void EngineSettings::setDefaultFontGlyphs(const std::string& defaultfontglyphs) {
 		m_defaultfontglyphs = defaultfontglyphs;
 	}
+	
+	void EngineSettings::setWindowTitle(const std::string& title) {
+		m_windowtitle = title;
+	}
+	
+	void EngineSettings::setWindowIcon(const std::string& icon) {
+		m_windowicon = icon;
+	}
+	
 }
 
--- a/engine/core/controller/enginesettings.h	Tue Jul 15 20:12:30 2008 +0000
+++ b/engine/core/controller/enginesettings.h	Wed Jul 16 12:37:41 2008 +0000
@@ -181,8 +181,19 @@
 		unsigned int getImageChunkingSize() {
 			return m_image_chunking_size;
 		}
+
+		void setWindowTitle(const std::string& title);
+
+		std::string getWindowTitle() const {
+			return m_windowtitle;
+		}
 	
-	
+		void setWindowIcon(const std::string& icon);
+
+		std::string getWindowIcon() const {
+			return m_windowicon;
+		}
+		
 	private:
 		unsigned int m_bitsperpixel;
 		bool m_fullscreen;
@@ -191,6 +202,9 @@
 		bool m_sldremovefakealpha;
 		unsigned int m_screenwidth;
 		unsigned int m_screenheight;
+		std::string m_windowtitle;
+		std::string m_windowicon;
+		
 		
 		std::string m_defaultfontpath;
 		unsigned int m_defaultfontsize;
--- a/engine/core/video/opengl/renderbackendopengl.cpp	Tue Jul 15 20:12:30 2008 +0000
+++ b/engine/core/video/opengl/renderbackendopengl.cpp	Wed Jul 16 12:37:41 2008 +0000
@@ -32,6 +32,7 @@
 #include "fife_opengl.h"
 #include "glimage.h"
 #include "renderbackendopengl.h"
+#include "SDL_image.h"
 
 namespace FIFE {
 
@@ -62,7 +63,7 @@
 		SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); // temporary hack
 	}
 
-	Image* RenderBackendOpenGL::createMainScreen(unsigned int width, unsigned int height, unsigned char bitsPerPixel, bool fs) {
+	Image* RenderBackendOpenGL::createMainScreen(unsigned int width, unsigned int height, unsigned char bitsPerPixel, bool fs, const std::string& title, const std::string& icon) {
 		delete m_screen;
 		m_screen = 0;
 
@@ -71,6 +72,13 @@
 			flags |= SDL_FULLSCREEN;
 		}
 
+		if(icon != "") {
+			SDL_Surface *img = IMG_Load(icon.c_str());
+			if(img != NULL) {
+				SDL_WM_SetIcon(img, 0);
+			}
+		}
+
 		SDL_Surface* screen = NULL;
 
 		if( 0 == bitsPerPixel ) {
@@ -98,7 +106,7 @@
 			screen = SDL_SetVideoMode(width, height, bitsPerPixel, flags);
 		}
 
-		SDL_WM_SetCaption("FIFE", 0);
+		SDL_WM_SetCaption(title.c_str(), 0);
 
 		if (!screen) {
 			throw SDLException(SDL_GetError());
--- a/engine/core/video/opengl/renderbackendopengl.h	Tue Jul 15 20:12:30 2008 +0000
+++ b/engine/core/video/opengl/renderbackendopengl.h	Wed Jul 16 12:37:41 2008 +0000
@@ -45,7 +45,7 @@
 		void startFrame();
 		void endFrame();
 		void init();
-		Image* createMainScreen(unsigned int width, unsigned int height, unsigned char bitsPerPixel, bool fullscreen);
+		Image* createMainScreen(unsigned int width, unsigned int height, unsigned char bitsPerPixel, bool fullscreen, const std::string& title, const std::string& icon);
 		Image* createImage(const uint8_t* data, unsigned int width, unsigned int height);
 		Image* createImage(SDL_Surface* surface);
  		bool putPixel(int x, int y, int r, int g, int b);
--- a/engine/core/video/renderbackend.h	Tue Jul 15 20:12:30 2008 +0000
+++ b/engine/core/video/renderbackend.h	Wed Jul 16 12:37:41 2008 +0000
@@ -86,7 +86,7 @@
 		 * @param fullscreen Use fullscreen mode?
 		 * @return The new Screen Image
 		 */
-		virtual Image* createMainScreen(unsigned int width, unsigned int height, unsigned char bitsPerPixel, bool fullscreen) = 0;
+		virtual Image* createMainScreen(unsigned int width, unsigned int height, unsigned char bitsPerPixel, bool fullscreen, const std::string& title, const std::string& icon) = 0;
 
 		/** Creates an Image suitable for this renderbackend.
 		 * @param data Pointer to the imagedata (needs to be in RGBA, 8 bits per channel).
--- a/engine/core/video/sdl/renderbackendsdl.cpp	Tue Jul 15 20:12:30 2008 +0000
+++ b/engine/core/video/sdl/renderbackendsdl.cpp	Wed Jul 16 12:37:41 2008 +0000
@@ -34,6 +34,7 @@
 
 #include "renderbackendsdl.h"
 #include "sdlimage.h"
+#include "SDL_image.h"
 
 namespace FIFE {
 	static Logger _log(LM_VIDEO);
@@ -58,12 +59,19 @@
 		SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); // temporary hack
 	}
 
-	Image* RenderBackendSDL::createMainScreen(unsigned int width, unsigned int height, unsigned char bitsPerPixel, bool fs) {
+	Image* RenderBackendSDL::createMainScreen(unsigned int width, unsigned int height, unsigned char bitsPerPixel, bool fs, const std::string& title, const std::string& icon) {
 		Uint32 flags = 0;
 		if (fs) {
 			flags |= SDL_FULLSCREEN;
 		}
 
+		if(icon != "") {
+			SDL_Surface *img = IMG_Load(icon.c_str());
+			if(img != NULL) {
+				SDL_WM_SetIcon(img, 0);
+			}
+		}
+
 		SDL_Surface* screen = NULL;
 
 		if( 0 == bitsPerPixel ) {
@@ -100,7 +108,7 @@
 			<< "Videomode " << width << "x" << height
 			<< " at " << int(screen->format->BitsPerPixel) << " bpp");
 
-		SDL_WM_SetCaption("FIFE", NULL);
+		SDL_WM_SetCaption(title.c_str(), NULL);
 
 		if (!screen) {
 			throw SDLException(SDL_GetError());
--- a/engine/core/video/sdl/renderbackendsdl.h	Tue Jul 15 20:12:30 2008 +0000
+++ b/engine/core/video/sdl/renderbackendsdl.h	Wed Jul 16 12:37:41 2008 +0000
@@ -47,7 +47,7 @@
 		void startFrame();
 		void endFrame();
 		void init();
-		Image* createMainScreen(unsigned int width, unsigned int height, unsigned char bitsPerPixel, bool fullscreen);
+		Image* createMainScreen(unsigned int width, unsigned int height, unsigned char bitsPerPixel, bool fullscreen, const std::string& title, const std::string& icon);
 		Image* createImage(const uint8_t* data, unsigned int width, unsigned int height);
 		Image* createImage(SDL_Surface* surface);
  		bool putPixel(int x, int y, int r, int g, int b);