* Dynamic icon file loading and themeability

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.

Icon files should be stored in $HOME/.blender/icons/ . This really sucks on
Mac since it's hidden in the finder, but it's a separate issue. We need a
better system of finding things like this, python scripts etc, perhaps a
nice wrapped function something like BLI_getresourcedir(), then it's easy to
do platform specific stuff there, like using ~/Library/Application Data on Mac.

More info and docs in the patch tracker @
https://projects.blender.org/tracker/index.php?func=detail&aid=5334&group_id=9&atid=127
This commit is contained in:
2006-12-29 04:46:47 +00:00
parent 37c42e2949
commit 376ee50d3e
8 changed files with 222 additions and 13 deletions

View File

@@ -112,6 +112,7 @@
#include "BIF_gl.h"
#include "BIF_imasel.h"
#include "BIF_interface.h"
#include "BIF_interface_icons.h"
#include "BIF_meshtools.h"
#include "BIF_mywindow.h"
#include "BIF_oops.h"
@@ -2688,6 +2689,42 @@ static void space_sound_button_function(int event)
}
#endif
static char *iconfile_menu(void)
{
static char string[512];
char *str = string;
IconFile *ifile;
ListBase *iconfilelist = BIF_iconfile_list();
str += sprintf(str, "Built-in %%x0|%%l|");
for(ifile=iconfilelist->first; ifile; ifile=ifile->next) {
str += sprintf(str, "%s %%x%d|", ifile->filename, ifile->index);
}
return string;
}
static void set_userdef_iconfile_cb(void *menuindex, void *unused2)
{
bTheme *btheme= U.themes.first;
IconFile *ifile;
ListBase *iconfilelist = BIF_iconfile_list();
int index = *((int *)menuindex);
if (index==0) {
BLI_strncpy(btheme->tui.iconfile, "", sizeof(btheme->tui.iconfile));
return;
}
for(ifile=iconfilelist->first; ifile; ifile=ifile->next) {
if (index == ifile->index) {
BLI_strncpy(btheme->tui.iconfile, ifile->filename, sizeof(btheme->tui.iconfile));
}
}
}
/* needed for event; choose new 'curmain' resets it... */
static short th_curcol= TH_BACK;
static char *th_curcol_ptr= NULL;
@@ -2700,6 +2737,8 @@ static void info_user_themebuts(uiBlock *block, short y1, short y2, short y3)
static short cur=1, curmain=2;
short a, tot=0, isbuiltin= 0;
char string[21*32], *strp, *col;
/* for choosing an icon image based on index in the cached list */
static int iconfileindex=0;
y3= y2+23; /* exception! */
@@ -2730,7 +2769,8 @@ static void info_user_themebuts(uiBlock *block, short y1, short y2, short y3)
strcat(string, bt->name);
if(btheme->next) strcat(string, " |");
}
uiDefButS(block, MENU, B_UPDATE_THEME, string, 45,y3,200,20, &cur, 0, 0, 0, 0, "Current theme");
uiDefButS(block, MENU, B_UPDATE_THEME_ICONS, string, 45,y3,200,20, &cur, 0, 0, 0, 0, "Current theme");
/* add / delete / name */
@@ -2789,12 +2829,23 @@ static void info_user_themebuts(uiBlock *block, short y1, short y2, short y3)
}
else if(th_curcol==TH_BUT_DRAWTYPE) {
uiBlockBeginAlign(block);
uiDefButC(block, ROW, B_UPDATE_THEME, "Minimal", 465,y3,100,20, col, 2.0, (float) TH_MINIMAL, 0, 0, "");
uiDefButC(block, ROW, B_UPDATE_THEME, "Shaded", 565,y3,100,20, col, 2.0, (float) TH_SHADED, 0, 0, "");
uiDefButC(block, ROW, B_UPDATE_THEME, "Rounded", 465,y2,100,20, col, 2.0, (float) TH_ROUNDED, 0, 0, "");
uiDefButC(block, ROW, B_UPDATE_THEME, "OldSkool", 565,y2,100,20, col, 2.0, (float) TH_OLDSKOOL, 0, 0, "");
uiDefButC(block, ROW, B_UPDATE_THEME, "Shaded", 465,y2,80,20, col, 2.0, (float) TH_SHADED, 0, 0, "");
uiDefButC(block, ROW, B_UPDATE_THEME, "Rounded", 545,y2,80,20, col, 2.0, (float) TH_ROUNDED, 0, 0, "");
uiDefButC(block, ROW, B_UPDATE_THEME, "Minimal", 625,y2,80,20, col, 2.0, (float) TH_MINIMAL, 0, 0, "");
uiDefButC(block, ROW, B_UPDATE_THEME, "OldSkool", 705,y2,80,20, col, 2.0, (float) TH_OLDSKOOL, 0, 0, "");
uiBlockEndAlign(block);
}
else if(th_curcol==TH_ICONFILE) {
uiBut *but;
/* set the icon file menu to the correct icon file index for what's stored in the theme values */
iconfileindex= BIF_iconfile_get_index(btheme->tui.iconfile);
but = uiDefButI(block, MENU, B_UPDATE_THEME_ICONS, iconfile_menu(),
465,y2,200,20, &iconfileindex, 0, 0, 0, 0, "The icon PNG file to use, searching in .blender/icons");
uiButSetFunc(but, set_userdef_iconfile_cb, &iconfileindex, NULL);
}
else {
uiBlockBeginAlign(block);
if ELEM8(th_curcol, TH_PANEL, TH_LAMP, TH_FACE, TH_FACE_SELECT, TH_MENU_BACK, TH_MENU_HILITE, TH_MENU_ITEM, TH_NODE) {
@@ -3653,6 +3704,11 @@ static void winqreadinfospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
else if(val==B_UPDATE_THEME) {
allqueue(REDRAWALL, 0);
}
else if(val==B_UPDATE_THEME_ICONS) {
BIF_icons_free();
BIF_icons_init(BIFICONID_LAST+1);
allqueue(REDRAWALL, 0);
}
else if(val==B_CHANGE_THEME) {
th_curcol= TH_BACK; /* backdrop color is always there... */
addqueue(sa->win, REDRAW, 1);