Dynamic icon file loading and themeability
Closed, ArchivedPublic


This patch allows icon files (.png) to be loaded into Blender dynamically, without having to go through the tedious and technical process of compiling them in. It also makes them part of the theme settings so they can be attached as part of a theme and saved in the default .B.blend.

Icons are scanned dynamically from disk. To add new icon files so they are available in the menu, create a folder underneath your .blender folder called 'icons' and drop the PNG file in there. They will then appear in a menu in: User Preferences -> Themes -> UI & Buttons -> Icon File.

The location of the icons folder will differ from platform to platform. On *nix and Mac OS X, it should be in $HOME/.blender/icons , on windows it will be different based on installation. Of course the fact that this .blender folder is only available through the terminal on Mac OS X is annoying and ugly, but is a separate issue that should be resolved...

Anyways, to prevent scanning the disk every time the icon menu is drawn, the available icon files are cached in a list, which is re-generated whever the icons are initialised - on startup, and whenever a selection from the menu is made (i.e. when a new icon file is chosen). A useful side effect of this, is that you can re-load an icon file dynamically while Blender is running just by choosing it again from the menu.

If the icon filename that's stored in the theme settings doesn't exist for some reason, Blender will revert to the built-in icons.

There are a few reasons for this patch:

1) Working on icons for Blender has a huge barrier to entry. Even though creating icons is a job best done by a designer, the process to do so is highly technical (compile datatoc, convert blenderbuttons to c format, compile blender, etc). This means that working on icons for Blender is out of most designer's reach, leaving the job mostly to people who have the technical knowledge to do so, but generally aren't the best icon designers :) This patch makes it much easier to work on creating icons for Blender as all you need to do is save the icon file somewhere without even needing to compile Blender, and it can even be reloaded to check the icons in context while Blender is still running.

Also, as well as making it easier for people to work on icons for the default Blender, having the ability to have customised icons will also allow people to make their own personal themes, perhaps customised for various operating systems' look and feel. Even if these are unofficial, hopefully it may get people interested and active in creating icons for Blender, which may be useful for the project at large.

2) Blender's icons are in dire need of an update. They are totally dated, inconsistent with each other, don't have guidelines for how they should look in various situations, and so on. It would be a good idea to really go back to basics and analyse this and make some sweeping changes for a new default icon set, perhaps involving changing the metaphors, colours or shapes used. Some conservatives may not like or want to get used to this, so this patch provides a way for them to keep using and maintain an 'old-school' icon set if they want.


There are a couple of implementation details that may be useful for a reviewer to know about, perhaps they are ok, perhaps there are better ways of doing things:

* The icon file cache is just a static global ListBase in interface_icons.c. I tried attaching it to the G struct but things started going crazy, like Blender not being able to open the .B.blend and start up.

* I changed the order of things initialising in BIF_init() (usiblender.c). Previously, the BIF_resources_init() was executed inside initbuttion(), before BIF_read_homefile() (which loads the theme information from the .B.blend). Because of this, it wasn't possible to decide on which icon to load based on the theme, since that information wasn't available. I checked through the code and didn't see anything that looked dangerous about it, so I moved BIF_resources_init() out to BIF_init() and after BIF_read_homefile(). This is working just fine for me, but I thought I'd mention it just in case...