From 546ba048c2a7552fa745add77a6ec093018dd390 Mon Sep 17 00:00:00 2001 From: Mark de Wever Date: Sun, 9 Mar 2014 14:59:36 +0100 Subject: [PATCH] Show the window icon with SDL 2. --- src/game_controller.cpp | 9 ++++++--- src/sdl/window.cpp | 5 +++++ src/sdl/window.hpp | 14 ++++++++++++++ src/video.cpp | 5 ++--- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/game_controller.cpp b/src/game_controller.cpp index c0bd8a5620fa..6ce7406ce94b 100644 --- a/src/game_controller.cpp +++ b/src/game_controller.cpp @@ -353,9 +353,7 @@ bool game_controller::init_video() surface icon(image::get_image("game-icon.png", image::UNSCALED)); if(icon != NULL) { ///must be called after SDL_Init() and before setting video mode -#if SDL_VERSION_ATLEAST(2, 0, 0) - CVideo::set_window_icon(icon); -#else +#if !SDL_VERSION_ATLEAST(2, 0, 0) SDL_WM_SetIcon(icon,NULL); #endif } @@ -399,6 +397,11 @@ bool game_controller::init_video() } #if SDL_VERSION_ATLEAST(2, 0, 0) CVideo::set_window_title(wm_title_string); +#if !(defined(__APPLE__)) + if(icon != NULL) { + CVideo::set_window_icon(icon); + } +#endif #endif return true; } diff --git a/src/sdl/window.cpp b/src/sdl/window.cpp index dc8304cb643d..616f33521b7d 100644 --- a/src/sdl/window.cpp +++ b/src/sdl/window.cpp @@ -78,6 +78,11 @@ void twindow::set_title(const std::string& title) SDL_SetWindowTitle(window_, title.c_str()); } +void twindow::set_icon(const surface& icon) +{ + SDL_SetWindowIcon(window_, icon); +} + twindow::operator SDL_Window*() { return window_; diff --git a/src/sdl/window.hpp b/src/sdl/window.hpp index a7762369eca2..d0eb5f950f78 100644 --- a/src/sdl/window.hpp +++ b/src/sdl/window.hpp @@ -24,6 +24,8 @@ #if SDL_VERSION_ATLEAST(2, 0, 0) +#include "sdl_utils.hpp" + #include #include @@ -105,6 +107,18 @@ class twindow : private boost::noncopyable */ void set_title(const std::string& title); + /** + * Sets the icon of the window. + * + * This is a wrapper for @ref SDL_SetWindowIcon. + * + * @note The @p icon is a @ref SDL_Surface and not a @ref SDL_Texture, this + * is part of the SDL 2 API. + * + * @param icon  The new icon for the window. + */ + void set_icon(const surface& icon); + /***** ***** ***** Conversion operators. ***** ***** *****/ diff --git a/src/video.cpp b/src/video.cpp index 9c22835de562..7ec12afc3183 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -550,9 +550,8 @@ void CVideo::set_window_title(const std::string& title) void CVideo::set_window_icon(surface& icon) { - if(window) { - SDL_SetWindowIcon(window, icon); - } + assert(main_window); + main_window->set_icon(icon); } #endif