Show the window icon with SDL 2.

This commit is contained in:
Mark de Wever 2014-03-09 14:59:36 +01:00
parent 7a0873f0aa
commit 546ba048c2
4 changed files with 27 additions and 6 deletions

View file

@ -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;
}

View file

@ -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_;

View file

@ -24,6 +24,8 @@
#if SDL_VERSION_ATLEAST(2, 0, 0)
#include "sdl_utils.hpp"
#include <boost/noncopyable.hpp>
#include <SDL_video.h>
@ -105,6 +107,18 @@ public:
*/
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. ***** ***** *****/

View file

@ -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