Skip to content

Commit

Permalink
Show the window icon with SDL 2.
Browse files Browse the repository at this point in the history
  • Loading branch information
mordante committed Mar 9, 2014
1 parent 7a0873f commit 546ba04
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/game_controller.cpp
Expand Up @@ -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
}
Expand Down Expand Up @@ -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;
}
Expand Down
5 changes: 5 additions & 0 deletions src/sdl/window.cpp
Expand Up @@ -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_;
Expand Down
14 changes: 14 additions & 0 deletions src/sdl/window.hpp
Expand Up @@ -24,6 +24,8 @@

#if SDL_VERSION_ATLEAST(2, 0, 0)

#include "sdl_utils.hpp"

#include <boost/noncopyable.hpp>

#include <SDL_video.h>
Expand Down Expand Up @@ -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. ***** ***** *****/

Expand Down
5 changes: 2 additions & 3 deletions src/video.cpp
Expand Up @@ -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

Expand Down

0 comments on commit 546ba04

Please sign in to comment.