Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Ebb <matt@mke3.net>2006-12-29 07:46:47 +0300
committerMatt Ebb <matt@mke3.net>2006-12-29 07:46:47 +0300
commit376ee50d3e94c01707ae433e3642ec685e3b25cd (patch)
tree5c833717be4ef9f7d140d6ac99ddc9171b491fa1 /source/blender
parent37c42e2949fc3ed9bdc0e25ab2a79fe8cd573842 (diff)
* 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
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/include/BIF_interface_icons.h11
-rw-r--r--source/blender/include/BIF_resources.h1
-rw-r--r--source/blender/include/BIF_space.h1
-rw-r--r--source/blender/makesdna/DNA_userdef_types.h3
-rw-r--r--source/blender/src/interface_icons.c136
-rw-r--r--source/blender/src/resources.c9
-rw-r--r--source/blender/src/space.c66
-rw-r--r--source/blender/src/usiblender.c8
8 files changed, 222 insertions, 13 deletions
diff --git a/source/blender/include/BIF_interface_icons.h b/source/blender/include/BIF_interface_icons.h
index 45f00dfb591..c69fa122099 100644
--- a/source/blender/include/BIF_interface_icons.h
+++ b/source/blender/include/BIF_interface_icons.h
@@ -40,6 +40,13 @@ struct Tex;
struct Lamp;
struct Material;
+typedef struct IconFile {
+ struct IconFile *next, *prev;
+ char filename[80]; // FILE_MAXFILE size
+ int index;
+} IconFile;
+
+
#define ICON_DEFAULT_HEIGHT 16
/*
@@ -55,4 +62,8 @@ void BIF_icon_draw_aspect_blended(float x, float y, int icon_id, float aspect, i
void BIF_icons_free();
void BIF_icons_free_drawinfo(void *drawinfo);
+struct ListBase *BIF_iconfile_list(void);
+int BIF_iconfile_get_index(char *filename);
+
+
#endif /* BIF_ICONS_H */
diff --git a/source/blender/include/BIF_resources.h b/source/blender/include/BIF_resources.h
index ed458fb3695..7a8dc73632a 100644
--- a/source/blender/include/BIF_resources.h
+++ b/source/blender/include/BIF_resources.h
@@ -460,6 +460,7 @@ enum {
TH_CUSTOM,
TH_BUT_TEXTFIELD_HI,
+ TH_ICONFILE,
TH_THEMEUI,
// common colors among spaces
diff --git a/source/blender/include/BIF_space.h b/source/blender/include/BIF_space.h
index 1e84dba39cb..884f0459abf 100644
--- a/source/blender/include/BIF_space.h
+++ b/source/blender/include/BIF_space.h
@@ -84,6 +84,7 @@ struct SpaceOops;
#define B_CHANGE_THEME 3306
#define B_THEME_COPY 3307
#define B_THEME_PASTE 3308
+#define B_UPDATE_THEME_ICONS 3309
#define B_RECALCLIGHT 3310
diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h
index 4394dec339c..53570a80220 100644
--- a/source/blender/makesdna/DNA_userdef_types.h
+++ b/source/blender/makesdna/DNA_userdef_types.h
@@ -61,7 +61,8 @@ typedef struct ThemeUI {
char menu_text_hi[4];
char but_drawtype;
- char pad1[3];
+ char pad[3];
+ char iconfile[80]; // FILE_MAXFILE length
} ThemeUI;
diff --git a/source/blender/src/interface_icons.c b/source/blender/src/interface_icons.c
index 568907c77e7..b71cd9b0052 100644
--- a/source/blender/src/interface_icons.c
+++ b/source/blender/src/interface_icons.c
@@ -45,6 +45,8 @@
#include "MEM_guardedalloc.h"
#include "BLI_arithb.h"
+#include "BLI_blenlib.h"
+#include "BLI_storage_types.h"
#include "DNA_material_types.h"
#include "DNA_texture_types.h"
@@ -59,6 +61,7 @@
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
+#include "DNA_userdef_types.h"
#include "BKE_global.h"
#include "BKE_material.h"
@@ -94,6 +97,9 @@
#define ICON_RENDERSIZE 32
#define ICON_MIPMAPS 8
+#define ICON_IMAGE_W 512
+#define ICON_IMAGE_H 256
+
#define ICON_GRID_COLS 25
#define ICON_GRID_ROWS 12
@@ -111,6 +117,15 @@ typedef struct DrawInfo {
unsigned int *rect;
} DrawInfo;
+
+/* ******************* STATIC LOCAL VARS ******************* */
+/* static here to cache results of icon directory scan, so it's not
+ * scanning the filesystem each time the menu is drawn */
+static struct ListBase iconfilelist = {0, 0};
+
+
+/* **************************************************** */
+
static void def_internal_icon(ImBuf *bbuf, int icon_id, int xofs, int yofs)
{
Icon *new_icon = NULL;
@@ -513,9 +528,31 @@ static void prepare_internal_icons(ImBuf *bbuf)
static void init_internal_icons()
{
- ImBuf *bbuf= IMB_ibImageFromMemory((int *)datatoc_blenderbuttons, datatoc_blenderbuttons_size, IB_rect);
+ bTheme *btheme= U.themes.first;
+ ImBuf *bbuf;
+ char iconfilestr[FILE_MAXDIR+FILE_MAXFILE];
+ char filenamestr[FILE_MAXFILE+16]; // 16 == strlen(".blender/icons/")+1
int x, y;
-
+
+ if ((btheme!=NULL) && (strlen(btheme->tui.iconfile) > 0)) {
+
+#ifdef WIN32
+ sprintf(filenamestr, "icons/%s", btheme->tui.iconfile);
+#else
+ sprintf(filenamestr, ".blender/icons/%s", btheme->tui.iconfile);
+#endif
+
+ BLI_make_file_string("/", iconfilestr, BLI_gethome(), filenamestr);
+
+ if (BLI_exists(iconfilestr)) {
+ bbuf = IMB_loadiffname(iconfilestr, IB_rect);
+ } else {
+ bbuf = IMB_ibImageFromMemory((int *)datatoc_blenderbuttons, datatoc_blenderbuttons_size, IB_rect);
+ }
+ } else {
+ bbuf = IMB_ibImageFromMemory((int *)datatoc_blenderbuttons, datatoc_blenderbuttons_size, IB_rect);
+ }
+
prepare_internal_icons(bbuf);
for (y=0; y<ICON_GRID_ROWS; y++) {
@@ -540,9 +577,102 @@ static void init_internal_icons()
}
+static void init_iconfile_list(struct ListBase *list)
+{
+ char icondirstr[FILE_MAXDIR];
+ char iconfilestr[FILE_MAXDIR+FILE_MAXFILE];
+ IconFile *ifile;
+ ImBuf *bbuf;
+ struct direntry *dir;
+ int totfile, i, index=1;
+ int ifilex, ifiley;
+
+ list->first = list->last = NULL;
+
+#ifdef WIN32
+ BLI_make_file_string("/", icondirstr, BLI_gethome(), "icons");
+#else
+ BLI_make_file_string("/", icondirstr, BLI_gethome(), ".blender/icons");
+#endif
+
+ totfile = BLI_getdir(icondirstr, &dir);
+
+ for(i=0; i<totfile; i++) {
+ if( (dir[i].type & S_IFREG) ) {
+ char *filename = dir[i].relname;
+
+ if(BLI_testextensie(filename, ".png")) {
+
+ /* check to see if the image is the right size, continue if not */
+ sprintf(iconfilestr, "%s/%s", icondirstr, filename);
+ if(BLI_exists(iconfilestr)) bbuf = IMB_loadiffname(iconfilestr, IB_rect);
+
+ ifilex = bbuf->x;
+ ifiley = bbuf->y;
+ IMB_freeImBuf(bbuf);
+
+ if ((ifilex != ICON_IMAGE_W) || (ifiley != ICON_IMAGE_H))
+ continue;
+
+ /* found a potential icon file, so make an entry for it in the cache list */
+ ifile = MEM_callocN(sizeof(IconFile), "IconFile");
+
+ BLI_strncpy(ifile->filename, filename, sizeof(ifile->filename));
+ ifile->index = index;
+
+ BLI_addtail(list, ifile);
+
+ index++;
+ }
+ }
+ }
+
+ /* free temporary direntry structure that's been created by BLI_getdir() */
+ i= totfile-1;
+
+ for(; i>=0; i--){
+ MEM_freeN(dir[i].relname);
+ if (dir[i].string) MEM_freeN(dir[i].string);
+ }
+ free(dir);
+ dir= 0;
+}
+
+static void free_iconfile_list(struct ListBase *list)
+{
+ IconFile *ifile=NULL, *next_ifile=NULL;
+
+ for(ifile=list->first; ifile; ifile=next_ifile) {
+ next_ifile = ifile->next;
+ BLI_freelinkN(list, ifile);
+ }
+}
+
+int BIF_iconfile_get_index(char *filename)
+{
+ IconFile *ifile;
+ ListBase *list=&(iconfilelist);
+
+ for(ifile=list->first; ifile; ifile=ifile->next) {
+ if ( BLI_streq(filename, ifile->filename)) {
+ return ifile->index;
+ }
+ }
+
+ return 0;
+}
+
+ListBase *BIF_iconfile_list(void)
+{
+ ListBase *list=&(iconfilelist);
+
+ return list;
+}
+
void BIF_icons_free()
{
+ free_iconfile_list(&iconfilelist);
BKE_icons_free();
}
@@ -625,7 +755,7 @@ int BIF_icon_get_height(int icon_id)
void BIF_icons_init(int first_dyn_id)
{
-
+ init_iconfile_list(&iconfilelist);
BKE_icons_init(first_dyn_id);
init_internal_icons();
}
diff --git a/source/blender/src/resources.c b/source/blender/src/resources.c
index ac12a0df14c..e1146951ea7 100644
--- a/source/blender/src/resources.c
+++ b/source/blender/src/resources.c
@@ -133,7 +133,10 @@ char *BIF_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colorid)
case TH_BUT_DRAWTYPE:
cp= &btheme->tui.but_drawtype; break;
-
+
+ case TH_ICONFILE:
+ cp= btheme->tui.iconfile; break;
+
case TH_REDALERT:
cp= alert; break;
case TH_CUSTOM:
@@ -360,6 +363,8 @@ void BIF_InitTheme(void)
SETCOL(btheme->tui.menu_text_hi, 255, 255, 255, 255);
btheme->tui.but_drawtype= TH_SHADED;
+ BLI_strncpy(btheme->tui.iconfile, "", sizeof(btheme->tui.iconfile));
+
/* space view3d */
SETCOL(btheme->tv3d.back, 115, 115, 115, 255);
SETCOL(btheme->tv3d.text, 0, 0, 0, 255);
@@ -547,6 +552,8 @@ char *BIF_ThemeColorsPup(int spacetype)
str += sprintf(str, "Menu Text Highlight %%x%d|", TH_MENU_TEXT_HI);
str += sprintf(str, "%%l|");
str += sprintf(str, "Drawtype %%x%d|", TH_BUT_DRAWTYPE);
+ str += sprintf(str, "%%l|");
+ str += sprintf(str, "Icon File %%x%d|", TH_ICONFILE);
}
else {
// first defaults for each space
diff --git a/source/blender/src/space.c b/source/blender/src/space.c
index d592916d098..8a787691331 100644
--- a/source/blender/src/space.c
+++ b/source/blender/src/space.c
@@ -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);
diff --git a/source/blender/src/usiblender.c b/source/blender/src/usiblender.c
index e6ee2a59f4a..31d3fedd14f 100644
--- a/source/blender/src/usiblender.c
+++ b/source/blender/src/usiblender.c
@@ -320,6 +320,9 @@ static void init_userdef_file(void)
SETCOL(btheme->tseq.transition, 162, 95, 111, 255);
SETCOL(btheme->tseq.meta, 109, 145, 131, 255);
}
+ if(!(btheme->tui.iconfile)) {
+ BLI_strncpy(btheme->tui.iconfile, "", sizeof(btheme->tui.iconfile));
+ }
}
/* set defaults for 3D View rotating axis indicator */
@@ -815,8 +818,6 @@ static void initbuttons(void)
BMF_GetFont(BMF_kHelvetica12),
BMF_GetFont(BMF_kHelvetica10),
BMF_GetFont(BMF_kHelveticaBold8));
-
- BIF_resources_init();
glClearColor(.7f, .7f, .6f, 0.0);
@@ -849,11 +850,12 @@ void BIF_init(void)
BIF_preview_init_dbase();
BIF_read_homefile();
+
+ BIF_resources_init(); /* after homefile, to dynamically load an icon file based on theme settings */
init_gl_stuff(); /* drawview.c, after homefile */
readBlog();
strcpy(G.lib, G.sce);
-
}
/***/