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 037cc22f879298a62091591c2c2397385c5d79f5..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"
@@ -461,13 +458,14 @@ static void vicon_move_down_draw(int x, int y, int w, int h, float UNUSED(alpha)
        glDisable(GL_LINE_SMOOTH);
 }
 
+#ifndef WITH_HEADLESS
 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
 
@@ -508,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");
@@ -524,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 */
@@ -588,7 +589,7 @@ static void init_internal_icons(void)
 
        IMB_freeImBuf(bbuf);
 }
-
+#endif // WITH_HEADLESS
 
 static void init_iconfile_list(struct ListBase *list)
 {
@@ -605,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++) {
@@ -658,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;
@@ -704,6 +707,7 @@ ListBase *UI_iconfile_list(void)
 
 void UI_icons_free(void)
 {
+#ifndef WITH_HEADLESS
        if(icongltex.id) {
                glDeleteTextures(1, &icongltex.id);
                icongltex.id= 0;
@@ -711,6 +715,7 @@ void UI_icons_free(void)
 
        free_iconfile_list(&iconfilelist);
        BKE_icons_free();
+#endif
 }
 
 void UI_icons_free_drawinfo(void *drawinfo)
@@ -739,6 +744,7 @@ static DrawInfo *icon_create_drawinfo(void)
        return di;
 }
 
+/* note!, returns unscaled by DPI, may need to multiply result by UI_DPI_ICON_FAC */
 int UI_icon_get_width(int icon_id)
 {
        Icon *icon = NULL;
@@ -748,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;
        }
        
@@ -773,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;
        }
        
@@ -792,10 +798,14 @@ int UI_icon_get_height(int icon_id)
 
 void UI_icons_init(int first_dyn_id)
 {
+#ifdef WITH_HEADLESS
+       (void)first_dyn_id;
+#else
        init_iconfile_list(&iconfilelist);
        BKE_icons_init(first_dyn_id);
        init_internal_icons();
        init_brush_icons();
+#endif
 }
 
 /* Render size for preview images and icons
@@ -817,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;
@@ -834,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;
        }       
 
@@ -850,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;
        }
@@ -940,18 +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= 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;
        }
 
@@ -965,8 +978,8 @@ static void icon_draw_size(float x, float y, int icon_id, float aspect, float al
        }
        
        /* scale width and height according to aspect */
-       w = (int)(draw_size/aspect + 0.5f);
-       h = (int)(draw_size/aspect + 0.5f);
+       w = (int)(fdraw_size/aspect + 0.5f);
+       h = (int)(fdraw_size/aspect + 0.5f);
        
        if(di->type == ICON_TYPE_VECTOR) {
                /* vector icons use the uiBlock transformation, they are not drawn
@@ -1009,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;
                }
@@ -1021,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;
@@ -1094,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;