On Fri, 1 Jun 2018 08:37:40 -0700 (PDT) Umberto Carletti wrote:
UC> I want to put on my frame a toolbar with some icons and I would like to
UC> know what is the best way to resize them depending on the screen's PPI. I
UC> don't want the icons to look small on high PPI screens and large on low PPI
UC> screens.
This is an area where wxWidgets still needs some improvements. Currently
things work well automatically only under Mac, where you just need to
provide the normal and normal@2x icons and the right one will be selected
depending on whether high DPI is used or not. For MSW and Unix you
currently have to do something similar in your own code (hopefully this
will be fixed in wxWidgets 3.2).
UC> In particular where should I store the icons and in which format depending
UC> on the platform (MSW, GTK, OSX)?
The format to use is PNG (please ignore advice to use XPM or any other
format without alpha channel support) under all platforms. The location is
platform-dependent however: under macOS, the icons should be in
Contents/Resources subdirectory of your application bundle (it's also
possible to have language-specific resources, but let's keep things simple
for now). Under MSW, icons normally are embedded in the Windows resources,
but you need to use RCDATA resource type for PNG files and not ICON. Then
you can use wxBitmap ctor with wxBITMAP_TYPE_PNG_RESOURCE or the convenient
wxBITMAP_PNG() macro to load them easily.
Under Unix you can use either approach, i.e. you could look for the .png
files in some prefix-relative directory, or you can embed the files into
the program itself. In the latter case, you will find misc/scripts/png2c.py
useful -- and if you do it like this, wxBITMAP_PNG() will also work for you
under Unix (otherwise you'd have to use wxBITMAP_PNG_FROM_DATA() there).
UC> Should I provide multiple scale images or should I rescale in the program?
Rescaling will almost never give really good results, so the best is to
have the images at all the different sizes. It is often difficult to cover
all of them, e.g. just for macOS you're supposed to provide the icons in
sizes 16, 24, 32, 48, 64, 128, 256, 512 pixels as well as the high DPI
versions of all of those, because normally you're even supposed to use
different icons of size 2*N in normal DPI and N in high DPI. So in practice
you might have to live with scaling for at least some of them, but it's
better to do it once outside of the program rather than do it during the
run-time.
Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/