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/src/interface_icons.c
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/src/interface_icons.c')
-rw-r--r--source/blender/src/interface_icons.c136
1 files changed, 133 insertions, 3 deletions
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();
}