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:
Diffstat (limited to 'source/blender/src')
-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
4 files changed, 207 insertions, 12 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();
}
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);
-
}
/***/