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

Author Topic: Window::setIcon(...) documentation  (Read 5109 times)

0 Members and 1 Guest are viewing this topic.

Austin J

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
Window::setIcon(...) documentation
« on: November 12, 2015, 09:11:02 pm »
Currently the documentation plainly states "Change the window's icon." This has worked great for me on Windows before to easily set a window's icon, even make the icon embedded in the executable if I want to. SFML aims to support other OS's however.

I decided to try to use setIcon() on Ubuntu 15.04 two ways. First using an imported C - struct from Gimp, then using a loaded image
Code: [Select]
window.setIcon(img.width, img.height, img.pixel_data) // pseudo code and unsurprisingly it didn't work, to get my own window icon I had to create a .desktop file for it to use. I don't develop on OSX, but from what I can tell it doesn't support embedded icons either.

Now don't think I'm stating "SFML needs to make setIcon() work on these other platforms." I don't think that's feasible at least for Linux as if I'm not mistaken, there's no standard way to handle it.

To be honest, I don't think I would have ever even added Window::setIcon(...) personally. It's already implemented, and to me that's fine. I do find it a niche user feature for Windows however. The documentation makes no mention about any of this.

In a nutshell, I'm not suggesting a change in the implementation of Window::setIcon(..) or that it be removed. I'm suggesting that maybe the documentation should in some way acknowledge the platform limitations of the method instead. 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: Window::setIcon(...) documentation
« Reply #1 on: November 12, 2015, 10:12:55 pm »
"it didn't work" is not a problem description. What are you expectations and what happened or didn't happen?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Austin J

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
Re: Window::setIcon(...) documentation
« Reply #2 on: November 13, 2015, 01:08:20 am »
"it didn't work" is not a problem description. What are you expectations and what happened or didn't happen?

Did you actually read what I wrote, or is your only interest being condescending and aggressive? I'm not trying to troubleshoot anything.

My expectation was that it would not work as a matter of fact. Like I said, setting a window icon on Linux is quite different from Windows. There is no standard for reading from an embedded image to set the icon. I don't see how SFML could be expected to get around this. I tested it on Linux anyways to see if my expectation would be wrong, but like I expected it had no result.

sf::Window::setIcon(...) is presented like it's a standard working feature for any platform. If it has platform limitations it should probably documented.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Window::setIcon(...) documentation
« Reply #3 on: November 13, 2015, 01:49:32 am »
So you're saying that setting an icon with an array containing RGBA data did not change the icon at runtime?

Window::setIcon() should work on Windows, Linux and OS X. So if calling the function has no effect, then that's a bug and some more information would be required, i.e. window manager, compilable and minimal code example, and maybe a screenshot of what you're actually seeing. :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Austin J

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
Re: Window::setIcon(...) documentation
« Reply #4 on: November 13, 2015, 02:55:18 am »
Apologies, I assumed Linux was probably not targetted.

So you're saying that setting an icon with an array containing RGBA data did not change the icon at runtime?

Indeed, it has no effect. It doesn't cause any ill effects either, essentially using Window::setIcon() causes my program to run no differently than if I left it out completely.

The first way I tried using it was by exporting it as a C structure from Gimp. I did make sure for it to export as RGBA by telling it to also save the alpha channel. Naturally I'll exclude the majority of this source as the actual pixel data exported is massive. The first small section is what is important anyway.

Code: [Select]

static const struct {
unsigned int width; // = 64
unsigned int height; // = 64
unsigned int bytes_per_pixel; // = 4 I'd say this makes it fairly certain it's RGBA
unsigned char pixel_data[width * height * bytes_per_pixel + 1]; // u8 array
} feudal_forge_icon = { 64, 64, 4,
// afterwards pixel_data gets defined by a giant exported array also generated by Gimp

};

After including the header file,

Code: [Select]
// Note there are exclusions
Engine::Engine()
{
    m_window.create(sf::VideoMode(800, 600, 32), "Feudal Forge", sf::Style::Default, initContextSettings());
   
    m_window.setIcon( feudal_forge_icon.width, feudal_forge_icon.height, feudal_forge_icon.pixel_data);
}

After seeing this didn't work ( and note I have gotten this to work before on Windows) I decided to try loading the icon from memory.

Code: [Select]
// Note there are exclusions
bool Engine::init(...)
{
    m_icon.loadFromFile("icon.png");

    // The window has already been created in the constructor
    m_window.setIcon(m_icon.getSize().x, m_icon.getSize().y, m_icon.getPixelsPtr());
}

Using this method led to the exact same thing. The icon didn't change, but there wasn't any crash, error message, etc.

Really to replicate my situation you can throw out 99% of my program.

If you'd like to try to compile my first example, you'll need the header file with the embedded image. I'll go ahead and link that. After you have it, it should work with this ( to save you time )

Code: [Select]

#include<SFML/Graphics.hpp>
#include<FeudalForgeIcon.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(640, 480, 32), "Icon Test");

    window.setIcon( feudal_forge_icon.width, feudal_forge_icon.height, feudal_forge_icon.pixel_data );

   while(window.isOpen())
    {
        sf::Event evt;
        while(window.pollEvent(evt))
        {
            if(evt.type == sf::Event::Closed) { window.close(); }
        }

        window.clear();

        window.display();
    }
}


For the second method I tried, I'm sure you can make some minor change to the above code.

I'd include the image directly but it's too large to just throw in the thread, so please look at the attachment.

You can see my icon at the bottom there.

As for the other method, it looks exactly the same.

Other Info:

Ubuntu 15.04 - Unity

Intel i5 - 2.4 ghz
Intel HD Integrated graphics Sandybridge Mobile
(I'm using the latest graphics drivers I can get from the Intel Graphics Installer)
RAM 6gb
« Last Edit: November 13, 2015, 02:59:39 am by Austin J »

 

anything