Undo revision 23130 which was a merge with 2.5, a messy one because I did something...
[blender.git] / source / blender / editors / space_file / file_draw.c
index 00024ff..5a07c6a 100644 (file)
@@ -353,9 +353,59 @@ void file_calc_previews(const bContext *C, ARegion *ar)
        UI_view2d_totRect_set(v2d, sfile->layout->width, sfile->layout->height);
 }
 
-static void file_draw_preview(short sx, short sy, ImBuf *imb, FileLayout *layout, short dropshadow)
+void file_draw_previews(const bContext *C, ARegion *ar)
 {
-       if (imb) {
+       SpaceFile *sfile= CTX_wm_space_file(C);
+       FileSelectParams* params= ED_fileselect_get_params(sfile);
+       FileLayout* layout= ED_fileselect_get_layout(sfile, ar);
+       View2D *v2d= &ar->v2d;
+       struct FileList* files = sfile->files;
+       int numfiles;
+       struct direntry *file;
+       short sx, sy;
+       ImBuf* imb=0;
+       int i;
+       int colorid = 0;
+       int offset;
+       int is_icon;
+
+       if (!files) return;
+
+       filelist_imgsize(files,sfile->layout->prv_w,sfile->layout->prv_h);
+       numfiles = filelist_numfiles(files);
+
+       sx = v2d->cur.xmin + layout->tile_border_x;
+       sy = v2d->cur.ymax - layout->tile_border_y;
+       
+       offset = ED_fileselect_layout_offset(layout, 0, 0);
+       if (offset<0) offset=0;
+       for (i=offset; (i < numfiles) && (i < (offset+(layout->rows+2)*layout->columns)); ++i)
+       {
+               ED_fileselect_layout_tilepos(layout, i, &sx, &sy);
+               sx += v2d->tot.xmin+2;
+               sy = v2d->tot.ymax - sy;
+               file = filelist_file(files, i); 
+
+               if (file->flags & ACTIVE) {
+                       colorid = TH_HILITE;
+                       draw_tile(sx - 1, sy, sfile->layout->tile_w + 1, sfile->layout->tile_h, colorid,0);
+               } else if (params->active_file == i) {
+                       colorid = TH_ACTIVE;
+                       draw_tile(sx - 1, sy, sfile->layout->tile_w + 1, sfile->layout->tile_h, colorid,0);
+               }
+               
+               if ( (file->flags & IMAGEFILE) /* || (file->flags & MOVIEFILE) */)
+               {                       
+                       filelist_loadimage(files, i);
+               }
+               is_icon = 0;
+               imb = filelist_getimage(files, i);
+               if (!imb) {
+                       imb = filelist_geticon(files,i);
+                       is_icon = 1;
+               }
+
+               if (imb) {
                        float fx, fy;
                        float dx, dy;
                        short xco, yco;
@@ -383,15 +433,15 @@ static void file_draw_preview(short sx, short sy, ImBuf *imb, FileLayout *layout
                        ey = (short)scaledy;
                        fx = ((float)layout->prv_w - (float)ex)/2.0f;
                        fy = ((float)layout->prv_h - (float)ey)/2.0f;
-                       dx = (fx + 0.5f + layout->prv_border_x);
-                       dy = (fy + 0.5f - layout->prv_border_y);
+                       dx = (fx + 0.5f + sfile->layout->prv_border_x);
+                       dy = (fy + 0.5f - sfile->layout->prv_border_y);
                        xco = (float)sx + dx;
-                       yco = (float)sy - layout->prv_h + dy;
+                       yco = (float)sy - sfile->layout->prv_h + dy;
 
                        glBlendFunc(GL_SRC_ALPHA,  GL_ONE_MINUS_SRC_ALPHA);
                        
                        /* shadow */
-                       if (dropshadow)
+                       if (!is_icon && (file->flags & IMAGEFILE))
                                uiDrawBoxShadow(220, xco, yco, xco + ex, yco + ey);
                        
                        glEnable(GL_BLEND);
@@ -401,7 +451,7 @@ static void file_draw_preview(short sx, short sy, ImBuf *imb, FileLayout *layout
                        glaDrawPixelsTexScaled(xco, yco, imb->x, imb->y, GL_UNSIGNED_BYTE, imb->rect, scale, scale);
                        
                        /* border */
-                       if (dropshadow) {
+                       if (!is_icon && (file->flags & IMAGEFILE)) {
                                glColor4f(0.0f, 0.0f, 0.0f, 0.4f);
                                fdrawbox(xco, yco, xco + ex, yco + ey);
                        }
@@ -409,6 +459,41 @@ static void file_draw_preview(short sx, short sy, ImBuf *imb, FileLayout *layout
                        glDisable(GL_BLEND);
                        imb = 0;
                }
+
+               /* shadow */
+               UI_ThemeColorShade(TH_BACK, -20);
+               
+               
+               if (S_ISDIR(file->type)) {
+                       glColor4f(1.0f, 1.0f, 0.9f, 1.0f);
+               }
+               else if (file->flags & IMAGEFILE) {
+                       UI_ThemeColor(TH_SEQ_IMAGE);
+               }
+               else if (file->flags & MOVIEFILE) {
+                       UI_ThemeColor(TH_SEQ_MOVIE);
+               }
+               else if (file->flags & BLENDERFILE) {
+                       UI_ThemeColor(TH_SEQ_SCENE);
+               }
+               else {
+                       if (params->active_file == i) {
+                               UI_ThemeColor(TH_GRID); /* grid used for active text */
+                       } else if (file->flags & ACTIVE) {
+                               UI_ThemeColor(TH_TEXT_HI);                      
+                       } else {
+                               UI_ThemeColor(TH_TEXT);
+                       }
+               }
+
+               file_draw_string(sx + layout->prv_border_x, sy+4, file->relname, layout->tile_w, layout->tile_h, FILE_SHORTEN_END);
+
+               if (!sfile->loadimage_timer)
+                       sfile->loadimage_timer= WM_event_add_window_timer(CTX_wm_window(C), TIMER1, 1.0/30.0);  /* max 30 frames/sec. */
+
+       }
+
+       uiSetRoundBox(0);
 }
 
 static void renamebutton_cb(bContext *C, void *arg1, char *oldname)
@@ -438,39 +523,6 @@ static void renamebutton_cb(bContext *C, void *arg1, char *oldname)
        }
 }
 
-
-static void draw_background(FileLayout *layout, View2D *v2d)
-{
-       int i;
-       short sy;
-
-       /* alternating flat shade background */
-       for (i=0; (i <= layout->rows); i+=2)
-       {
-               sy = v2d->cur.ymax - i*(layout->tile_h+2*layout->tile_border_y) - layout->tile_border_y;
-
-               UI_ThemeColorShade(TH_BACK, -7);
-               glRectf(v2d->cur.xmin, sy, v2d->cur.xmax, sy+layout->tile_h+2*layout->tile_border_y);
-               
-       }
-}
-
-static void draw_dividers(FileLayout *layout, View2D *v2d)
-{
-       short sx;
-
-       /* vertical column dividers */
-       sx = v2d->tot.xmin;
-       while (sx < v2d->cur.xmax) {
-               sx += (layout->tile_w+2*layout->tile_border_x);
-               
-               UI_ThemeColorShade(TH_BACK, 30);
-               sdrawline(sx+1,  v2d->cur.ymax - layout->tile_border_y ,  sx+1,  v2d->cur.ymin); 
-               UI_ThemeColorShade(TH_BACK, -30);
-               sdrawline(sx,  v2d->cur.ymax - layout->tile_border_y ,  sx,  v2d->cur.ymin); 
-       }
-}
-
 void file_draw_list(const bContext *C, ARegion *ar)
 {
        SpaceFile *sfile= CTX_wm_space_file(C);
@@ -479,7 +531,6 @@ void file_draw_list(const bContext *C, ARegion *ar)
        View2D *v2d= &ar->v2d;
        struct FileList* files = sfile->files;
        struct direntry *file;
-       ImBuf *imb;
        int numfiles;
        int numfiles_layout;
        int colorid = 0;
@@ -487,7 +538,6 @@ void file_draw_list(const bContext *C, ARegion *ar)
        int offset;
        int i;
        float sw, spos;
-       short is_icon;
 
        numfiles = filelist_numfiles(files);
        
@@ -497,11 +547,26 @@ void file_draw_list(const bContext *C, ARegion *ar)
        offset = ED_fileselect_layout_offset(layout, 0, 0);
        if (offset<0) offset=0;
 
-       if (params->display != FILE_IMGDISPLAY) {
+       /* alternating flat shade background */
+       for (i=0; (i <= layout->rows); i+=2)
+       {
+               sx = v2d->cur.xmin;
+               sy = v2d->cur.ymax - i*(layout->tile_h+2*layout->tile_border_y) - layout->tile_border_y;
 
-               draw_background(layout, v2d);
+               UI_ThemeColorShade(TH_BACK, -7);
+               glRectf(v2d->cur.xmin, sy, v2d->cur.xmax, sy+layout->tile_h+2*layout->tile_border_y);
+               
+       }
        
-               draw_dividers(layout, v2d);
+       /* vertical column dividers */
+       sx = v2d->tot.xmin;
+       while (sx < ar->v2d.cur.xmax) {
+               sx += (sfile->layout->tile_w+2*sfile->layout->tile_border_x);
+               
+               UI_ThemeColorShade(TH_BACK, 30);
+               sdrawline(sx+1,  ar->v2d.cur.ymax - layout->tile_border_y ,  sx+1,  ar->v2d.cur.ymin); 
+               UI_ThemeColorShade(TH_BACK, -30);
+               sdrawline(sx,  ar->v2d.cur.ymax - layout->tile_border_y ,  sx,  ar->v2d.cur.ymin); 
        }
 
        sx = ar->v2d.cur.xmin + layout->tile_border_x;
@@ -529,33 +594,16 @@ void file_draw_list(const bContext *C, ARegion *ar)
                }
 
                spos = sx;
-
-               if ( FILE_IMGDISPLAY == params->display ) {
-                       if ( (file->flags & IMAGEFILE) /* || (file->flags & MOVIEFILE) */) {                    
-                               filelist_loadimage(files, i);
-                       }
-                       is_icon = 0;
-                       imb = filelist_getimage(files, i);
-                       if (!imb) {
-                               imb = filelist_geticon(files,i);
-                               is_icon = 1;
-                       }
-                       
-                       file_draw_preview(sx, sy, imb, layout, !is_icon && (file->flags & IMAGEFILE));
-
-               } else {
-                               file_draw_icon(spos, sy-3, get_file_icon(file), ICON_DEFAULT_WIDTH, ICON_DEFAULT_WIDTH);
-                               spos += ICON_DEFAULT_WIDTH + 4;
-               }
-
+               file_draw_icon(spos, sy-3, get_file_icon(file), ICON_DEFAULT_WIDTH, ICON_DEFAULT_WIDTH);
+               spos += ICON_DEFAULT_WIDTH + 4;
+               
                UI_ThemeColor4(TH_TEXT);
-
+               
                sw = file_string_width(file->relname);
                if (file->flags & EDITING) {
-                       short but_width = (FILE_IMGDISPLAY == params->display) ? layout->tile_w : layout->column_widths[COLUMN_NAME];
                        uiBlock *block = uiBeginBlock(C, ar, "FileName", UI_EMBOSS);
                        uiBut *but = uiDefBut(block, TEX, 1, "", spos, sy-layout->tile_h-3, 
-                               but_width, layout->textheight*2, file->relname, 1.0f, (float)FILE_MAX,0,0,"");
+                               layout->column_widths[COLUMN_NAME], layout->tile_h, file->relname, 1.0f, (float)FILE_MAX,0,0,"");
                        uiButSetRenameFunc(but, renamebutton_cb, file);
                        if ( 0 == uiButActiveOnly(C, block, but)) {
                                file->flags &= ~EDITING;
@@ -563,42 +611,36 @@ void file_draw_list(const bContext *C, ARegion *ar)
                        uiEndBlock(C, block);
                        uiDrawBlock(C, block);
                } else {
-                       float name_width = (FILE_IMGDISPLAY == params->display) ? layout->tile_w : sw;
-                       file_draw_string(spos, sy, file->relname, name_width, layout->tile_h, FILE_SHORTEN_END);
+                       file_draw_string(spos, sy, file->relname, sw, layout->tile_h, FILE_SHORTEN_END);
                }
-
-               uiSetRoundBox(0);
-
-               if (params->display == FILE_SHORTDISPLAY) {
-                       spos += layout->column_widths[COLUMN_NAME] + 12;
+               spos += layout->column_widths[COLUMN_NAME] + 12;
+               if (params->display == FILE_SHOWSHORT) {
                        if (!(file->type & S_IFDIR)) {
                                sw = file_string_width(file->size);
                                spos += layout->column_widths[COLUMN_SIZE] + 12 - sw;
                                file_draw_string(spos, sy, file->size, sw+1, layout->tile_h, FILE_SHORTEN_END); 
                        }
-               } else if (params->display == FILE_LONGDISPLAY) {
-                       spos += layout->column_widths[COLUMN_NAME] + 12;
-
-#ifndef WIN32
+               } else {
+#if 0 // XXX TODO: add this for non-windows systems
                        /* rwx rwx rwx */
                        spos += 20;
-                       sw = file_string_width(file->mode1);
-                       file_draw_string(spos, sy, file->mode1, sw, layout->tile_h, FILE_SHORTEN_END); 
-                       spos += layout->column_widths[COLUMN_MODE1] + 12;
-
-                       sw = file_string_width(file->mode2);
-                       file_draw_string(spos, sy, file->mode2, sw, layout->tile_h, FILE_SHORTEN_END);
-                       spos += layout->column_widths[COLUMN_MODE2] + 12;
-
-                       sw = file_string_width(file->mode3);
-                       file_draw_string(spos, sy, file->mode3, sw, layout->tile_h, FILE_SHORTEN_END);
-                       spos += layout->column_widths[COLUMN_MODE3] + 12;
+                       sw = UI_GetStringWidth(file->mode1);
+                       file_draw_string(spos, sy, file->mode1, sw, layout->tile_h); 
+                       
+                       spos += 30;
+                       sw = UI_GetStringWidth(file->mode2);
+                       file_draw_string(spos, sy, file->mode2, sw, layout->tile_h);
 
-                       sw = file_string_width(file->owner);
-                       file_draw_string(spos, sy, file->owner, sw, layout->tile_h, FILE_SHORTEN_END);
-                       spos += layout->column_widths[COLUMN_OWNER] + 12;
+                       spos += 30;
+                       sw = UI_GetStringWidth(file->mode3);
+                       file_draw_string(spos, sy, file->mode3, sw, layout->tile_h);
+                       
+                       spos += 30;
+                       sw = UI_GetStringWidth(file->owner);
+                       file_draw_string(spos, sy, file->owner, sw, layout->tile_h);
 #endif
 
+                       
                        sw = file_string_width(file->date);
                        file_draw_string(spos, sy, file->date, sw, layout->tile_h, FILE_SHORTEN_END);
                        spos += layout->column_widths[COLUMN_DATE] + 12;
@@ -614,9 +656,6 @@ void file_draw_list(const bContext *C, ARegion *ar)
                        }
                }
        }
-
-       if (!sfile->loadimage_timer)
-               sfile->loadimage_timer= WM_event_add_window_timer(CTX_wm_window(C), TIMER1, 1.0/30.0);  /* max 30 frames/sec. */
 }