style chang, made mainly because I wanted to be able to add breakpoints to MEM_freeN...
[blender.git] / source / blender / editors / interface / interface_icons.c
index 412c0233c352f36dd54b6bb4c43f2c0d4650ba6a..3feda5d4db411783aa19c8c723ff1a17bf3362c4 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id$
- *
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
@@ -47,7 +45,6 @@
 
 #include "BLI_math.h"
 #include "BLI_blenlib.h"
-#include "BLI_storage_types.h"
 #include "BLI_utildefines.h"
 
 #include "DNA_brush_types.h"
@@ -465,10 +462,10 @@ static void vicon_move_down_draw(int x, int y, int w, int h, float UNUSED(alpha)
 static void init_brush_icons(void)
 {
 
-#define INIT_BRUSH_ICON(icon_id, name)                                      \
-       bbuf = IMB_ibImageFromMemory((unsigned char*)datatoc_ ##name## _png, \
-                                    datatoc_ ##name## _png_size, IB_rect);  \
-       def_internal_icon(bbuf, icon_id, 0, 0, w, ICON_TYPE_BUFFER);         \
+#define INIT_BRUSH_ICON(icon_id, name)                                         \
+       bbuf = IMB_ibImageFromMemory((unsigned char*)datatoc_ ##name## _png,       \
+                                        datatoc_ ##name## _png_size, IB_rect, "<brush icon>");    \
+       def_internal_icon(bbuf, icon_id, 0, 0, w, ICON_TYPE_BUFFER);               \
        IMB_freeImBuf(bbuf);
        // end INIT_BRUSH_ICON
 
@@ -509,10 +506,10 @@ static void init_brush_icons(void)
 
 static void init_internal_icons(void)
 {
-       bTheme *btheme= U.themes.first;
+       bTheme *btheme= UI_GetTheme();
        ImBuf *bbuf= NULL;
        int x, y, icontype;
-       char iconfilestr[FILE_MAXDIR+FILE_MAXFILE];
+       char iconfilestr[FILE_MAX];
        
        if ((btheme!=NULL) && btheme->tui.iconfile[0]) {
                char *icondir= BLI_get_folder(BLENDER_DATAFILES, "icons");
@@ -525,9 +522,12 @@ static void init_internal_icons(void)
                                bbuf= NULL;
                        }
                }
+               else {
+                       printf("%s: 'icons' data path not found, continuing\n", __func__);
+               }
        }
        if(bbuf==NULL)
-               bbuf = IMB_ibImageFromMemory((unsigned char*)datatoc_blenderbuttons, datatoc_blenderbuttons_size, IB_rect);
+               bbuf = IMB_ibImageFromMemory((unsigned char*)datatoc_blender_icons_png, datatoc_blender_icons_png_size, IB_rect, "<blender icons>");
 
        if(bbuf) {
                /* free existing texture if any */
@@ -606,11 +606,11 @@ static void init_iconfile_list(struct ListBase *list)
        if(icondir==NULL)
                return;
        
-       /* since BLI_getdir changes the current working directory, restore it 
+       /* since BLI_dir_contents changes the current working directory, restore it 
           back to old value afterwards */
-       if(!BLI_getwdN(olddir, sizeof(olddir))) 
+       if(!BLI_current_working_dir(olddir, sizeof(olddir))) 
                restoredir = 0;
-       totfile = BLI_getdir(icondir, &dir);
+       totfile = BLI_dir_contents(icondir, &dir);
        if (restoredir && !chdir(olddir)) {} /* fix warning about checking return value */
 
        for(i=0; i<totfile; i++) {
@@ -659,13 +659,15 @@ static void init_iconfile_list(struct ListBase *list)
                }
        }
        
-       /* free temporary direntry structure that's been created by BLI_getdir() */
+       /* free temporary direntry structure that's been created by BLI_dir_contents() */
        i= totfile-1;
        
        for(; i>=0; i--){
                MEM_freeN(dir[i].relname);
                MEM_freeN(dir[i].path);
-               if (dir[i].string) MEM_freeN(dir[i].string);
+               if (dir[i].string) {
+                       MEM_freeN(dir[i].string);
+               }
        }
        free(dir);
        dir= NULL;
@@ -752,7 +754,7 @@ int UI_icon_get_width(int icon_id)
        
        if (icon==NULL) {
                if (G.f & G_DEBUG)
-                       printf("UI_icon_get_width: Internal error, no icon for icon ID: %d\n", icon_id);
+                       printf("%s: Internal error, no icon for icon ID: %d\n", __func__, icon_id);
                return 0;
        }
        
@@ -777,7 +779,7 @@ int UI_icon_get_height(int icon_id)
        
        if (icon==NULL) {
                if (G.f & G_DEBUG)
-                       printf("UI_icon_get_height: Internal error, no icon for icon ID: %d\n", icon_id);
+                       printf("%s: Internal error, no icon for icon ID: %d\n", __func__, icon_id);
                return 0;
        }
        
@@ -825,7 +827,7 @@ static void icon_create_rect(struct PreviewImage* prv_img, enum eIconSizes size)
 
        if (!prv_img) {
                if (G.f & G_DEBUG)
-                       printf("Error: requested preview image does not exist");
+                       printf("%s, error: requested preview image does not exist", __func__);
        }
        if (!prv_img->rect[size]) {
                prv_img->w[size] = render_size;
@@ -842,7 +844,7 @@ static void icon_set_image(bContext *C, ID *id, PreviewImage* prv_img, enum eIco
 {
        if (!prv_img) {
                if (G.f & G_DEBUG)
-                       printf("No preview image for this ID: %s\n", id->name);
+                       printf("%s: no preview image for this ID: %s\n", __func__, id->name);
                return;
        }       
 
@@ -858,7 +860,7 @@ static void icon_draw_rect(float x, float y, int w, int h, float UNUSED(aspect),
 
        /* sanity check */
        if(w<=0 || h<=0 || w>2000 || h>2000) {
-               printf("icon_draw_rect: icons are %i x %i pixels?\n", w, h);
+               printf("%s: icons are %i x %i pixels?\n", __func__, w, h);
                BLI_assert(!"invalid icon size");
                return;
        }
@@ -948,19 +950,21 @@ static int get_draw_size(enum eIconSizes size)
        return 0;
 }
 
-static void icon_draw_size(float x, float y, int icon_id, float aspect, float alpha, float *rgb, enum eIconSizes size, int draw_size, int UNUSED(nocreate), int is_preview)
+static void icon_draw_size(float x, float y, int icon_id, float aspect, float alpha, float *rgb, enum eIconSizes size, int draw_size, int UNUSED(nocreate), short is_preview)
 {
+       bTheme *btheme= UI_GetTheme();
        Icon *icon = NULL;
        DrawInfo *di = NULL;
        IconImage *iimg;
-       float fdraw_size= UI_DPI_ICON_FAC*draw_size;
+       float fdraw_size= is_preview ? draw_size : (draw_size * UI_DPI_ICON_FAC);
        int w, h;
        
        icon = BKE_icon_get(icon_id);
+       alpha *= btheme->tui.icon_alpha;
        
        if (icon==NULL) {
                if (G.f & G_DEBUG)
-                       printf("icon_draw_mipmap: Internal error, no icon for icon ID: %d\n", icon_id);
+                       printf("%s: Internal error, no icon for icon ID: %d\n", __func__, icon_id);
                return;
        }
 
@@ -1018,9 +1022,9 @@ static void ui_id_icon_render(bContext *C, ID *id, int big)
                {
                        /* create the rect if necessary */                              
                        
-                       icon_set_image(C, id, pi, 0);           /* icon size */
+                       icon_set_image(C, id, pi, ICON_SIZE_ICON);              /* icon size */
                        if (big)
-                               icon_set_image(C, id, pi, 1);   /* bigger preview size */
+                               icon_set_image(C, id, pi, ICON_SIZE_PREVIEW);   /* bigger preview size */
                        
                        pi->changed[0] = 0;
                }
@@ -1030,7 +1034,7 @@ static void ui_id_icon_render(bContext *C, ID *id, int big)
 static void ui_id_brush_render(bContext *C, ID *id)
 {
        PreviewImage *pi = BKE_previewimg_get(id); 
-       int i;
+       enum eIconSizes i;
        
        if(!pi)
                return;
@@ -1103,8 +1107,7 @@ int ui_id_icon_get(bContext *C, ID *id, int big)
        int iconid= 0;
        
        /* icon */
-       switch(GS(id->name))
-       {
+       switch(GS(id->name)) {
                case ID_BR:
                        iconid= ui_id_brush_get_icon(C, id);
                        break;