Clear some compiler warnings by commenting some functions, adding others to headers.
[blender.git] / source / blender / editors / space_file / file_draw.c
index 719c29c3d3c6310d3fbb19b10b4bcb3c3416f8c7..79c1cce4656010cb5a8783cb174c33adb7760220 100644 (file)
  * ***** END GPL LICENSE BLOCK *****
  */
 
+#include <math.h>
 #include <string.h>
 
 #include "BLI_blenlib.h"
+#include "BLI_utildefines.h"
 #include "BLI_dynstr.h"
 #include "BLI_storage_types.h"
 #ifdef WIN32
@@ -77,7 +79,7 @@
 enum {
        B_FS_DIRNAME,
        B_FS_FILENAME
-} eFile_ButEvents;
+} /*eFile_ButEvents*/;
 
 
 static void do_file_buttons(bContext *C, void *UNUSED(arg), int event)
@@ -135,7 +137,7 @@ void file_draw_buttons(const bContext *C, ARegion *ar)
        ARegion*                  artmp;
        
        /* Initialize UI block. */
-       sprintf(name, "win %p", ar);
+       sprintf(name, "win %p", (void *)ar);
        block = uiBeginBlock(C, ar, name, UI_EMBOSS);
        uiBlockSetHandleFunc(block, do_file_buttons, NULL);
 
@@ -254,6 +256,8 @@ static int get_file_icon(struct direntry *file)
        }
        else if (file->flags & BLENDERFILE)
                return ICON_FILE_BLEND;
+       else if (file->flags & BLENDERFILE_BACKUP)
+               return ICON_FILE_BLEND;
        else if (file->flags & IMAGEFILE)
                return ICON_FILE_IMAGE;
        else if (file->flags & MOVIEFILE)
@@ -278,42 +282,37 @@ static void file_draw_icon(uiBlock *block, char *path, int sx, int sy, int icon,
 {
        uiBut *but;
        float x,y;
-       float alpha=1.0f;
+       /*float alpha=1.0f;*/
        
        x = (float)(sx);
        y = (float)(sy-height);
        
-       if (icon == ICON_FILE_BLANK) alpha = 0.375f;
+       /*if (icon == ICON_FILE_BLANK) alpha = 0.375f;*/
                
        but= uiDefIconBut(block, LABEL, 0, icon, x, y, width, height, NULL, 0.0, 0.0, 0, 0, "");
        uiButSetDragPath(but, path);
 }
 
 
-static void file_draw_string(int sx, int sy, const char* string, float width, int height, int flag)
+static void file_draw_string(int sx, int sy, const char* string, float width, int height, short align)
 {
        uiStyle *style= U.uistyles.first;
-       int soffs;
+       uiFontStyle fs = style->widgetlabel;
+       rcti rect;
        char fname[FILE_MAXFILE];
-       float sw;
-       float x,y;
 
+       fs.align = align;
 
        BLI_strncpy(fname,string, FILE_MAXFILE);
-       sw = file_shorten_string(fname, width, flag );
-
-       soffs = (width - sw) / 2;
-       x = (float)(sx);
-       y = (float)(sy-height);
+       file_shorten_string(fname, width+1.0, 0);
 
-       if (style->widget.kerning == 1)
-               BLF_enable(style->widget.uifont_id, BLF_KERNING_DEFAULT);
-
-       uiStyleFontSet(&style->widget);
-       BLF_position(style->widget.uifont_id, x, y, 0);
-       BLF_draw(style->widget.uifont_id, fname);
-       if (style->widget.kerning == 1)
-               BLF_disable(style->widget.uifont_id, BLF_KERNING_DEFAULT);
+       /* no text clipping needed, uiStyleFontDraw does it but is a bit too strict (for buttons it works) */
+       rect.xmin = sx;
+       rect.xmax = sx + ceil(width+4.0f);
+       rect.ymin = sy - height;
+       rect.ymax = sy;
+       
+       uiStyleFontDraw(&fs, &rect, fname);
 }
 
 void file_calc_previews(const bContext *C, ARegion *ar)
@@ -468,9 +467,11 @@ void file_draw_list(const bContext *C, ARegion *ar)
        int colorid = 0;
        int sx, sy;
        int offset;
+       int textwidth, textheight;
        int i;
-       float sw, spos;
        short is_icon;
+       short align;
+
 
        numfiles = filelist_numfiles(files);
        
@@ -493,6 +494,11 @@ void file_draw_list(const bContext *C, ARegion *ar)
                numfiles_layout += layout->columns;
        }
 
+       textwidth =( FILE_IMGDISPLAY == params->display) ? layout->tile_w : layout->column_widths[COLUMN_NAME];
+       textheight = layout->textheight*3.0/2.0 + 0.5;
+
+       align = ( FILE_IMGDISPLAY == params->display) ? UI_STYLE_TEXT_CENTER : UI_STYLE_TEXT_LEFT;
+
        for (i=offset; (i < numfiles) && (i<offset+numfiles_layout); ++i)
        {
                ED_fileselect_layout_tilepos(layout, i, &sx, &sy);
@@ -503,27 +509,6 @@ void file_draw_list(const bContext *C, ARegion *ar)
                
                UI_ThemeColor4(TH_TEXT);
 
-               
-               
-               if ( FILE_IMGDISPLAY == params->display ) {
-                       sw = file_string_width_shortened(file->relname, layout->tile_w);
-                       spos = sx + (layout->tile_w - sw)/2;
-               } else {
-                       sw = file_string_width(file->relname);
-                       spos = sx + ICON_DEFAULT_WIDTH + 4;
-               }       
-
-               if (file->flags & EDITING) {
-                       int but_width = (FILE_IMGDISPLAY == params->display) ? layout->tile_w : layout->column_widths[COLUMN_NAME];
-
-                       uiBut *but = uiDefBut(block, TEX, 1, "", spos, sy-layout->tile_h-3, 
-                               but_width, layout->textheight*2, sfile->params->renameedit, 1.0f, (float)sizeof(sfile->params->renameedit),0,0,"");
-                       uiButSetRenameFunc(but, renamebutton_cb, file);
-                       uiButSetFlag(but, UI_BUT_NO_UTF8); /* allow non utf8 names */
-                       if ( 0 == uiButActiveOnly(C, block, but)) {
-                               file->flags &= ~EDITING;
-                       }
-               }
 
                if (!(file->flags & EDITING)) {
                        if (params->active_file == i) {
@@ -546,58 +531,61 @@ void file_draw_list(const bContext *C, ARegion *ar)
                        }
                        
                        file_draw_preview(block, file, sx, sy, imb, layout, !is_icon && (file->flags & IMAGEFILE));
-
                } else {
                        file_draw_icon(block, file->path, sx, sy-3, get_file_icon(file), ICON_DEFAULT_WIDTH, ICON_DEFAULT_WIDTH);
+                       sx += ICON_DEFAULT_WIDTH + 4;
                }
 
                UI_ThemeColor4(TH_TEXT);
+
+               if (file->flags & EDITING) {
+                       uiBut *but = uiDefBut(block, TEX, 1, "", sx , sy-layout->tile_h-3, 
+                               textwidth, textheight, sfile->params->renameedit, 1.0f, (float)sizeof(sfile->params->renameedit),0,0,"");
+                       uiButSetRenameFunc(but, renamebutton_cb, file);
+                       uiButSetFlag(but, UI_BUT_NO_UTF8); /* allow non utf8 names */
+                       if ( 0 == uiButActiveOnly(C, block, but)) {
+                               file->flags &= ~EDITING;
+                       }
+               }
+
                if (!(file->flags & EDITING))  {
-                       // float name_width = (FILE_IMGDISPLAY == params->display) ? layout->tile_w : sw;
-                       file_draw_string(spos, sy, file->relname, sw, layout->tile_h, 0);
+                       int tpos = (FILE_IMGDISPLAY == params->display) ? sy - layout->tile_h + layout->textheight : sy;
+                       file_draw_string(sx+1, tpos, file->relname, textwidth, textheight, align);
                }
 
                if (params->display == FILE_SHORTDISPLAY) {
-                       spos += layout->column_widths[COLUMN_NAME] + 12;
+                       sx += layout->column_widths[COLUMN_NAME] + 12;
                        if (!(file->type & S_IFDIR)) {
-                               sw = file_string_width(file->size);
-                               file_draw_string(spos, sy, file->size, sw+1, layout->tile_h, 0);        
-                               spos += layout->column_widths[COLUMN_SIZE] + 12;
+                               file_draw_string(sx, sy, file->size, layout->column_widths[COLUMN_SIZE], layout->tile_h, align);        
+                               sx += layout->column_widths[COLUMN_SIZE] + 12;
                        }
                } else if (params->display == FILE_LONGDISPLAY) {
-                       spos += layout->column_widths[COLUMN_NAME] + 12;
+                       sx += layout->column_widths[COLUMN_NAME] + 12;
 
 #ifndef WIN32
                        /* rwx rwx rwx */
-                       sw = file_string_width(file->mode1);
-                       file_draw_string(spos, sy, file->mode1, sw, layout->tile_h, 0); 
-                       spos += layout->column_widths[COLUMN_MODE1] + 12;
+                       file_draw_string(sx, sy, file->mode1, layout->column_widths[COLUMN_MODE1], layout->tile_h, align); 
+                       sx += layout->column_widths[COLUMN_MODE1] + 12;
 
-                       sw = file_string_width(file->mode2);
-                       file_draw_string(spos, sy, file->mode2, sw, layout->tile_h, 0);
-                       spos += layout->column_widths[COLUMN_MODE2] + 12;
+                       file_draw_string(sx, sy, file->mode2, layout->column_widths[COLUMN_MODE2], layout->tile_h, align);
+                       sx += layout->column_widths[COLUMN_MODE2] + 12;
 
-                       sw = file_string_width(file->mode3);
-                       file_draw_string(spos, sy, file->mode3, sw, layout->tile_h, 0);
-                       spos += layout->column_widths[COLUMN_MODE3] + 12;
+                       file_draw_string(sx, sy, file->mode3, layout->column_widths[COLUMN_MODE3], layout->tile_h, align);
+                       sx += layout->column_widths[COLUMN_MODE3] + 12;
 
-                       sw = file_string_width(file->owner);
-                       file_draw_string(spos, sy, file->owner, sw, layout->tile_h, 0);
-                       spos += layout->column_widths[COLUMN_OWNER] + 12;
+                       file_draw_string(sx, sy, file->owner, layout->column_widths[COLUMN_OWNER] , layout->tile_h, align);
+                       sx += layout->column_widths[COLUMN_OWNER] + 12;
 #endif
 
-                       sw = file_string_width(file->date);
-                       file_draw_string(spos, sy, file->date, sw, layout->tile_h, 0);
-                       spos += layout->column_widths[COLUMN_DATE] + 12;
+                       file_draw_string(sx, sy, file->date, layout->column_widths[COLUMN_DATE], layout->tile_h, align);
+                       sx += layout->column_widths[COLUMN_DATE] + 12;
 
-                       sw = file_string_width(file->time);
-                       file_draw_string(spos, sy, file->time, sw, layout->tile_h, 0); 
-                       spos += layout->column_widths[COLUMN_TIME] + 12;
+                       file_draw_string(sx, sy, file->time, layout->column_widths[COLUMN_TIME] , layout->tile_h, align); 
+                       sx += layout->column_widths[COLUMN_TIME] + 12;
 
                        if (!(file->type & S_IFDIR)) {
-                               sw = file_string_width(file->size);
-                               file_draw_string(spos, sy, file->size, sw, layout->tile_h, 0);
-                               spos += layout->column_widths[COLUMN_SIZE] + 12;
+                               file_draw_string(sx, sy, file->size, layout->column_widths[COLUMN_SIZE], layout->tile_h, align);
+                               sx += layout->column_widths[COLUMN_SIZE] + 12;
                        }
                }
        }