Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: set icon?  (Read 3844 times)

0 Members and 1 Guest are viewing this topic.

Anthony11

  • Newbie
  • *
  • Posts: 38
    • View Profile
set icon?
« on: July 16, 2015, 05:13:05 pm »
how can i set an icon of window to a .ico file?

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: set icon?
« Reply #1 on: July 16, 2015, 05:39:21 pm »
As far as I know SFML does not support ICO files.
But you can use a PNG.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: set icon?
« Reply #2 on: July 16, 2015, 06:15:32 pm »
sf::Window::setIcon() takes a pointer to an array of pixels (in a specific order). An sf::Image stores its data in an array of pixels (in that required order) and can return a pointer to them.
Therefore, any of sf::Image's file formats can be used to set the window's icon.
From sf::Image::loadFromFile():
Quote
The supported image formats are bmp, png, tga, jpg, gif, psd, hdr and pic.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Anthony11

  • Newbie
  • *
  • Posts: 38
    • View Profile
Re: set icon?
« Reply #3 on: July 16, 2015, 07:07:28 pm »
well then, is it possible to set it from resource then?

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: set icon?
« Reply #4 on: July 16, 2015, 07:34:59 pm »
It depends on your definition of the word resource. If you mean a resource such as a file (you can use the method above) or an sf::Texture (you can use loadFromImage in combination with the above method). However, if you mean Windows' definition of resource (e.g. a script linking external resources), you'll be using Windows-specific code (becomes non-cross-platform).
If you are looking for to only Windows-specific, you should look at this or that. SFML can give you the window's handle (HWND) using sf::Window::getSystemHandle().
This may also be of help (still Windows-specific).
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: set icon?
« Reply #5 on: July 16, 2015, 08:47:33 pm »
You can also embed the pixel data using a const uint8[] right in your code, which is essentially like your resource, but cross-platform (although a bit tricky to update).