grass image
[home] -> [blender] -> Blender Dynamic Icons

[home]
---
[news]
[links]
---
[demos]
[gallery]
---
[tutorials]
---
[e-mail]

Blender Dynamic Icons

Overview of the functionality

The Blender UI is enhanced by showing small icons in the popup menu for materials, textures, lamps and world as well as in the popup menus for images. This adds a visual clue for the user in addition to the name of the material or texture that is shown in the menu. Since the Panels in the buttons window can be scaled, the icons have to be scaled accordingly.

icons for the material popup

Testbuild binary

You can take a look at the testbuild for Windows for a preview: Windows Build

Please be aware that this is for testing purposes only and purely experimental. IT IS NOT RECOMMENDED TO USE THIS BUILD IN DAILY PRODUCTION WORK!!!

The patch

Download Dynamic Icon Patch

Applying the patch:

Step 1: Apply the patch

interface_icons.patch is the patch that has to be applied with the patch utility.

The patch been done from the directory /blender with cvs diff -u source/blender , so it has to be applied with patch -p0 <interface_icons.patch

Step 2: Add the four new files to your project file, makefile, etc...

The patch adds the files to the scons build system, so should be compilable out of the box with scons.

Integration of the functionality

The idea is to reuse the preview drawing code by extending it to use any size for the preview and allow it to only render on a smallrect without displaying it on screen. The icons will be rendered at a small size (32x32) so this should be fast enough to calculate up to 30 icons, which is the max number of icons that is shown at one time in the popup menu. Calculating of the icon rect only happens when a material or texture has changed and of course also just before they are shown for the first time.

The rendering of the preview only needs to be slightly enhanced for this by making it flexible enough to render at different sizes. For future work on an image browser for those previews, the interface has been cleaned up too, pulling out a function that takes a n UI block and an area to render the preview on dynamically.

The icon images themselves are stored in a 32x32 rect inside the icon struct, which in turn is stored in a hashtable with the icon id as the key and a pointer to the struct Icon as value.

The Blender UI code accesses the icons uniformly through an integer icon-id, where the lower numbers are reserved for the default icons, keeping the BIFiconID they have now. The current (static) icons with the BIFIconID are stored in the hash table as well, the icon id mapping 1:1 to the new icon id. This means the dynamic icons start with an id somewhere after the BIFICONID_LAST.

The objects (like materials, textures etc) store their icon id inside their struct ID. They also manage the lifetime of the icons, by removing it from the hashtable when they get deallocated (undo and file reload etc.)

Interface / API for the icons

The functionality is separated in two main requirements, the first one to provide a container to store and retrieve the icons, which is handled in blenkernel (BKE_icons.h and BKE_icons.c) since the library needs access to remove and free the icons.

void BKE_icons_init(int first_dyn_id);

/* return icon id for library object or create new icon if not found */
int BKE_icon_getid(struct ID* id);

/* retrieve icon for id */
struct DynIcon* BKE_icon_get(int icon_id);

/* set icon for id if not already defined */
/* used for inserting the internal icons */
void BKE_icon_set(int icon_id, struct DynIcon* icon);

/* remove icon and free data if library object becomes invalid */
void BKE_icon_delete(struct ID* id);

/* report changes - icon needs to be recalculated */
void BKE_icon_changed(int icon_id);

/* free all icons */
void BKE_icons_free();

The second requirement block is the actual calculation and rendering of the icon which is handled in the main blender src (BIF_preview_icons.h and BIF_preview_icons.c)

/* Initialize the default icons */
void BIF_icons_init(int first_dyn_id);

/* Retrieve width and height */
int BIF_icon_get_width(int icon_id);
int BIF_icon_get_height(int icon_id);

/* Set aspect for correct scaling */
void BIF_icon_set_aspect(int icon_id, float aspect);

/* draw the icon using glDrawPixel */
void BIF_draw_icon(int x, int y, int icon_id);
void BIF_draw_icon_blended(int x, int y, int icon_id, int colorid, int shade);

/* free the icons */
void BIF_icons_free();
void BIF_icons_free_drawinfo(void *drawinfo);

Changed Interface / API for the preview render

/* stores rendered preview  - is also used for icons */
typedef struct RenderInfo {
	int pr_rectx;
	int pr_recty;		
	unsigned int* rect; 
	short cury;
} RenderInfo;

/* called from the buttons window for the preview */
void	BIF_previewrender_buts	(struct SpaceButs *sbuts);

/* Render the preview
 * a) into the ri->rect
 * b) draw it in the area using the block UIMat
 if doDraw is false, the preview is not drawn and the function is not dynamic,
 so no events are processed. Hopefully fast enough 32x32 icons */
 
void BIF_previewrender ( struct ID* id, 
    struct RenderInfo *ri, 
    struct ScrArea *area, 
    struct uiBlock* block, 
    int doDraw
);

BIF_previewrender should be able to be called with a valid Material, texture, lamp or world and drawn in the ScrArea area using the UIMat of the uiBlock. The resulting preview is also returned in the rect member of the RenderInfo struct. This should give the minimal interface that is needed to later on to render the previews in the image browser/preview browser

Some more pictures

icons for the material popup icons for the material popup icons for the material popup icons for the material popup

Planned further work

  • Enhance the image browser, so it shows the previews of materials, textures etc.
  • The image browser won't use the icons directly, but use a RenderInfo pointer for each entry in the filelist to temporarily store the preview, which will be drawn dynamically like in the current preview panel now.

This is the result of an early experimental stage of the image selector showing some materials.

icons for the material popup

Page created November 2005 by Andrea Weikert