diff options
author | Andrea Weikert <elubie@gmx.net> | 2009-03-08 16:14:12 +0300 |
---|---|---|
committer | Andrea Weikert <elubie@gmx.net> | 2009-03-08 16:14:12 +0300 |
commit | 403b3763a8048f88f8f589167c1f70b876999795 (patch) | |
tree | a243f78f3ff9f23cd7d8bec9e7c4567509e2a90b /source/blender/editors/space_file | |
parent | c20b4d661863b62089f0819d1079920bc5f2a62d (diff) |
2.5 filebrowser
still WIP commit, so Matt can do UI design
- cleaned up filebrowser drawing and selection
- selection bugfix
Diffstat (limited to 'source/blender/editors/space_file')
-rw-r--r-- | source/blender/editors/space_file/file_draw.c | 287 | ||||
-rw-r--r-- | source/blender/editors/space_file/file_header.c | 5 | ||||
-rw-r--r-- | source/blender/editors/space_file/file_intern.h | 3 | ||||
-rw-r--r-- | source/blender/editors/space_file/file_ops.c | 55 | ||||
-rw-r--r-- | source/blender/editors/space_file/filelist.c | 16 | ||||
-rw-r--r-- | source/blender/editors/space_file/filelist.h | 1 | ||||
-rw-r--r-- | source/blender/editors/space_file/filesel.c | 109 | ||||
-rw-r--r-- | source/blender/editors/space_file/space_file.c | 15 |
8 files changed, 306 insertions, 185 deletions
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c index 72da15ccd9d..10c556a087d 100644 --- a/source/blender/editors/space_file/file_draw.c +++ b/source/blender/editors/space_file/file_draw.c @@ -240,70 +240,21 @@ static void file_draw_string(short sx, short sy, char* string, short width, shor } -/* returns max number of rows in view */ -static int file_view_rows(SpaceFile* sfile, View2D *v2d) -{ - int height= (v2d->cur.ymax - v2d->cur.ymin - 2*sfile->tile_border_y); - return height / (sfile->tile_h + 2*sfile->tile_border_y); -} - -/* returns max number of columns in view */ -static int file_view_columns(SpaceFile* sfile, View2D *v2d) -{ - int width= (v2d->cur.xmax - v2d->cur.xmin - 2*sfile->tile_border_x); - return width / (sfile->tile_w + 2*sfile->tile_border_x); -} - void file_calc_previews(const bContext *C, ARegion *ar) { SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C); - FileSelectParams* params = ED_fileselect_get_params(sfile); View2D *v2d= &ar->v2d; - int width=0, height=0; - int rows, columns; - - if (params->display == FILE_IMGDISPLAY) { - sfile->prv_w = 96; - sfile->prv_h = 96; - sfile->tile_border_x = 4; - sfile->tile_border_y = 4; - sfile->prv_border_x = 4; - sfile->prv_border_y = 4; - sfile->tile_w = sfile->prv_w + 2*sfile->prv_border_x; - sfile->tile_h = sfile->prv_h + 4*sfile->prv_border_y + U.fontsize*3/2; - width= (v2d->cur.xmax - v2d->cur.xmin - 2*sfile->tile_border_x); - columns= file_view_columns(sfile, v2d); - if(columns) - rows= filelist_numfiles(sfile->files)/columns + 1; // XXX dirty, modulo is zero - else - rows= filelist_numfiles(sfile->files) + 1; // XXX dirty, modulo is zero - height= rows*(sfile->tile_h+2*sfile->tile_border_y) + sfile->tile_border_y*2; - } else { - sfile->prv_w = 0; - sfile->prv_h = 0; - sfile->tile_border_x = 8; - sfile->tile_border_y = 2; - sfile->prv_border_x = 0; - sfile->prv_border_y = 0; - sfile->tile_w = 240; - sfile->tile_h = U.fontsize*3/2; - height= v2d->cur.ymax - v2d->cur.ymin; - rows = file_view_rows(sfile, v2d); - if(rows) - columns = filelist_numfiles(sfile->files)/rows + 1; // XXX dirty, modulo is zero - else - columns = filelist_numfiles(sfile->files) + 1; // XXX dirty, modulo is zero - - width = columns * (sfile->tile_w + 2*sfile->tile_border_x) + sfile->tile_border_x*2; - } - - UI_view2d_totRect_set(v2d, width, height); + + ED_fileselect_init_layout(sfile, ar); + UI_view2d_totRect_set(v2d, sfile->layout->width, sfile->layout->height); } void file_draw_previews(const bContext *C, ARegion *ar) { SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C); FileSelectParams* params= ED_fileselect_get_params(sfile); + FileLayout* layout= ED_fileselect_get_layout(sfile, ar); + View2D *v2d= &ar->v2d; static double lasttime= 0; struct FileList* files = sfile->files; @@ -319,97 +270,66 @@ void file_draw_previews(const bContext *C, ARegion *ar) int colorid = 0; int todo; int offset; - int columns; - int rows; if (!files) return; type = filelist_gettype(files); - filelist_imgsize(files,sfile->prv_w,sfile->prv_h); + filelist_imgsize(files,sfile->layout->prv_w,sfile->layout->prv_h); numfiles = filelist_numfiles(files); todo = 0; if (lasttime < 0.001) lasttime = PIL_check_seconds_timer(); - sx = v2d->cur.xmin + sfile->tile_border_x; - sy = v2d->cur.ymax - sfile->tile_border_y; - columns = file_view_columns(sfile, v2d); - rows = file_view_rows(sfile, v2d); - - offset = columns*(-v2d->cur.ymax-sfile->tile_border_y)/(sfile->tile_h+sfile->tile_border_y); - offset = (offset/columns-1)*columns; + 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+(rows+2)*columns)); ++i) + for (i=offset; (i < numfiles) && (i < (offset+(layout->rows+2)*layout->columns)); ++i) { - sx = v2d->tot.xmin + sfile->tile_border_x + ((i)%columns)*(sfile->tile_w+2*sfile->tile_border_x); - sy = v2d->tot.ymax - sfile->tile_border_y - ((i)/columns)*(sfile->tile_h+2*sfile->tile_border_y); + ED_fileselect_layout_tilepos(layout, i, &sx, &sy); + sx += v2d->tot.xmin+2; + sy = v2d->tot.ymax - sy; file = filelist_file(files, i); if (params->active_file == i) { colorid = TH_ACTIVE; - draw_tile(sx - 1, sy, sfile->tile_w + 1, sfile->tile_h, colorid,0); + draw_tile(sx - 1, sy, sfile->layout->tile_w + 1, sfile->layout->tile_h, colorid,0); } else if (file->flags & ACTIVE) { colorid = TH_HILITE; - draw_tile(sx - 1, sy, sfile->tile_w + 1, sfile->tile_h, colorid,0); + draw_tile(sx - 1, sy, sfile->layout->tile_w + 1, sfile->layout->tile_h, colorid,0); } else { colorid = TH_BACK; - draw_tile(sx, sy, sfile->tile_w, sfile->tile_h, colorid, -5); + draw_tile(sx, sy, sfile->layout->tile_w, sfile->layout->tile_h, colorid, -5); } -#if 0 - if ( type == FILE_MAIN) { - ID *id; - int icon_id = 0; - int idcode; - idcode= groupname_to_code(sfile->dir); - if (idcode == ID_MA || idcode == ID_TE || idcode == ID_LA || idcode == ID_WO || idcode == ID_IM) { - id = (ID *)file->poin; - icon_id = BKE_icon_getid(id); - } - if (icon_id) { - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - if (do_load) { - UI_icon_draw_preview(sx+2*TILE_BORDER_X, sy-simasel->prv_w-TILE_BORDER_X, icon_id, 0); - } else { - UI_icon_draw_preview(sx+2*TILE_BORDER_X, sy-simasel->prv_w-TILE_BORDER_X, icon_id, 1); - todo++; - } - - glDisable(GL_BLEND); - } - } - else { -#endif - if ( (file->flags & IMAGEFILE) /* || (file->flags & MOVIEFILE) */) - { - if (do_load) { - filelist_loadimage(files, i); - } else { - todo++; - } - imb = filelist_getimage(files, i); + if ( (file->flags & IMAGEFILE) /* || (file->flags & MOVIEFILE) */) + { + if (do_load) { + filelist_loadimage(files, i); } else { - imb = filelist_getimage(files, i); + todo++; } + imb = filelist_getimage(files, i); + } else { + imb = filelist_getimage(files, i); + } + + if (imb) { + float fx = ((float)layout->prv_w - (float)imb->x)/2.0f; + float fy = ((float)layout->prv_h - (float)imb->y)/2.0f; + short dx = (short)(fx + 0.5f + sfile->layout->prv_border_x); + short dy = (short)(fy + 0.5f - sfile->layout->prv_border_y); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + // glaDrawPixelsSafe((float)sx+8 + dx, (float)sy - imgwidth + dy - 8, imb->x, imb->y, imb->x, GL_RGBA, GL_UNSIGNED_BYTE, imb->rect); + glColor4f(1.0, 1.0, 1.0, 1.0); + glaDrawPixelsTex((float)sx + dx, (float)sy - sfile->layout->prv_h + dy, imb->x, imb->y,GL_UNSIGNED_BYTE, imb->rect); + glDisable(GL_BLEND); + imb = 0; + } - if (imb) { - float fx = ((float)sfile->prv_w - (float)imb->x)/2.0f; - float fy = ((float)sfile->prv_h - (float)imb->y)/2.0f; - short dx = (short)(fx + 0.5f + sfile->prv_border_x); - short dy = (short)(fy + 0.5f - sfile->prv_border_y); - - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - // glaDrawPixelsSafe((float)sx+8 + dx, (float)sy - imgwidth + dy - 8, imb->x, imb->y, imb->x, GL_RGBA, GL_UNSIGNED_BYTE, imb->rect); - glColor4f(1.0, 1.0, 1.0, 1.0); - glaDrawPixelsTex((float)sx + dx, (float)sy - sfile->prv_h + dy, imb->x, imb->y,GL_UNSIGNED_BYTE, imb->rect); - glDisable(GL_BLEND); - imb = 0; - } -#if 0 - } -#endif if (type == FILE_MAIN) { glColor4f(1.0f, 1.0f, 1.0f, 1.0f); } @@ -437,7 +357,7 @@ void file_draw_previews(const bContext *C, ARegion *ar) } } - file_draw_string(sx + sfile->prv_border_x, sy+U.fontsize*3/2, file->relname, sfile->tile_w, sfile->tile_h); + file_draw_string(sx + layout->prv_border_x, sy+U.fontsize*3/2, file->relname, layout->tile_w, layout->tile_h); 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. */ @@ -451,6 +371,8 @@ void file_draw_list(const bContext *C, ARegion *ar) { SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(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; struct direntry *file; int numfiles; @@ -459,44 +381,45 @@ void file_draw_list(const bContext *C, ARegion *ar) int offset; short type; int i; - int rows; - float sw; + float sw, spos; numfiles = filelist_numfiles(files); type = filelist_gettype(files); - sx = ar->v2d.tot.xmin + sfile->tile_border_x/2; - sy = ar->v2d.cur.ymax - sfile->tile_border_y; + sx = ar->v2d.tot.xmin + layout->tile_border_x/2; + sy = ar->v2d.cur.ymax - layout->tile_border_y; - rows = (ar->v2d.cur.ymax - ar->v2d.cur.ymin - 2*sfile->tile_border_y) / (sfile->tile_h+sfile->tile_border_y); - offset = rows*(sx - sfile->tile_border_x)/(sfile->tile_w+sfile->tile_border_x); - offset = (offset/rows-1)*rows; + offset = ED_fileselect_layout_offset(layout, 0, 0); + if (offset<0) offset=0; while (sx < ar->v2d.cur.xmax) { - sx += (sfile->tile_w+sfile->tile_border_x); + sx += (sfile->layout->tile_w+2*sfile->layout->tile_border_x); glColor4ub(0xB0,0xB0,0xB0, 0xFF); - sdrawline(sx+1, ar->v2d.cur.ymax - sfile->tile_border_y , sx+1, ar->v2d.cur.ymin + sfile->tile_border_y); + sdrawline(sx+1, ar->v2d.cur.ymax - layout->tile_border_y , sx+1, ar->v2d.cur.ymin + layout->tile_border_y); glColor4ub(0x30,0x30,0x30, 0xFF); - sdrawline(sx, ar->v2d.cur.ymax - sfile->tile_border_y , sx, ar->v2d.cur.ymin + sfile->tile_border_y); + sdrawline(sx, ar->v2d.cur.ymax - layout->tile_border_y , sx, ar->v2d.cur.ymin + layout->tile_border_y); } - sx = ar->v2d.cur.xmin + sfile->tile_border_x; - sy = ar->v2d.cur.ymax - sfile->tile_border_y; + + sx = ar->v2d.cur.xmin + layout->tile_border_x; + sy = ar->v2d.cur.ymax - layout->tile_border_y; + if (offset<0) offset=0; for (i=offset; (i < numfiles); ++i) { - sy = ar->v2d.tot.ymax-sfile->tile_border_y - (i%rows)*(sfile->tile_h+sfile->tile_border_y); - sx = 2 + ar->v2d.tot.xmin +sfile->tile_border_x + (i/rows)*(sfile->tile_w+sfile->tile_border_x); + ED_fileselect_layout_tilepos(layout, i, &sx, &sy); + sx += v2d->tot.xmin+2; + sy = v2d->tot.ymax - sy; file = filelist_file(files, i); if (params->active_file == i) { if (file->flags & ACTIVE) colorid= TH_HILITE; else colorid = TH_BACK; - draw_tile(sx-2, sy-3, sfile->tile_w+2, sfile->tile_h, colorid,20); + draw_tile(sx-2, sy-3, layout->tile_w+2, sfile->layout->tile_h, colorid,20); } else if (file->flags & ACTIVE) { colorid = TH_HILITE; - draw_tile(sx-2, sy-3, sfile->tile_w+2, sfile->tile_h, colorid,0); + draw_tile(sx-2, sy-3, layout->tile_w+2, sfile->layout->tile_h, colorid,0); } else { /* colorid = TH_PANEL; @@ -513,9 +436,38 @@ void file_draw_list(const bContext *C, ARegion *ar) UI_ThemeColor4(TH_TEXT); } + spos = sx; sw = UI_GetStringWidth(G.font, file->size, 0); - file_draw_string(sx, sy, file->relname, sfile->tile_w - sw - 5, sfile->tile_h); - file_draw_string(sx + sfile->tile_w - sw, sy, file->size, sfile->tile_w - sw, sfile->tile_h); + file_draw_string(spos, sy, file->relname, layout->tile_w - sw - 5, layout->tile_h); + spos += filelist_maxnamelen(sfile->files); + if (params->display != FILE_SHOWSHORT) { +#if 0 // XXX TODO: add this for non-windows systems + /* rwx rwx rwx */ + x += 20; glRasterPos2i(x, y); + BMF_DrawString(G.font, files->mode1); + + x += 30; glRasterPos2i(x, y); + BMF_DrawString(G.font, files->mode2); + + x += 30; glRasterPos2i(x, y); + BMF_DrawString(G.font, files->mode3); + + /* owner time date */ + x += 30; glRasterPos2i(x, y); + BMF_DrawString(G.font, files->owner); +#endif + spos += 60; + sw = UI_GetStringWidth(G.font, file->time, 0); + file_draw_string(spos, sy, file->time, sw, layout->tile_h); + spos += sw; + spos += 50; + sw = UI_GetStringWidth(G.font, file->date, 0); + file_draw_string(spos, sy, file->date, sw, layout->tile_h); + + } + + file_draw_string(sx + layout->tile_w - 2*layout->tile_border_x - sw - 4, sy, file->size, layout->tile_w - layout->tile_border_x - sw - 5, layout->tile_h); + } } @@ -531,41 +483,40 @@ void file_draw_fsmenu(const bContext *C, ARegion *ar) int bmwidth = ar->v2d.cur.xmax - ar->v2d.cur.xmin - 2*TILE_BORDER_X; int fontsize = U.fontsize; - if (params->flag & FILE_BOOKMARKS) { sx = ar->v2d.cur.xmin + TILE_BORDER_X; sy = ar->v2d.cur.ymax-2*TILE_BORDER_Y; for (i=0; i< nentries && (sy > ar->v2d.cur.ymin) ;++i) { char *fname = fsmenu_get_entry(i); - if (fname) { - int sl; - BLI_strncpy(bookmark, fname, FILE_MAX); - - sl = strlen(bookmark)-1; - while (bookmark[sl] == '\\' || bookmark[sl] == '/') { - bookmark[sl] = '\0'; - sl--; - } - if (params->active_bookmark == i ) { - glColor4ub(0, 0, 0, 100); - UI_ThemeColor(TH_HILITE); - uiSetRoundBox(15); - uiRoundBox(sx, sy - linestep, sx + bmwidth, sy, 6); - // glRecti(sx, sy - linestep, sx + bmwidth, sy); - UI_ThemeColor(TH_TEXT_HI); - } else { - UI_ThemeColor(TH_TEXT); - } - - file_draw_string(sx, sy, bookmark, bmwidth, fontsize); - sy -= linestep; + if (fname) { + int sl; + BLI_strncpy(bookmark, fname, FILE_MAX); + + sl = strlen(bookmark)-1; + while (bookmark[sl] == '\\' || bookmark[sl] == '/') { + bookmark[sl] = '\0'; + sl--; + } + if (params->active_bookmark == i ) { + glColor4ub(0, 0, 0, 100); + UI_ThemeColor(TH_HILITE); + uiSetRoundBox(15); + uiRoundBox(sx, sy - linestep, sx + bmwidth, sy, 6); + // glRecti(sx, sy - linestep, sx + bmwidth, sy); + UI_ThemeColor(TH_TEXT_HI); } else { - glColor4ub(0xB0,0xB0,0xB0, 0xFF); - sdrawline(sx, sy-1-fontsize/2 , sx + bmwidth, sy-1-fontsize/2); - glColor4ub(0x30,0x30,0x30, 0xFF); - sdrawline(sx, sy-fontsize/2 , sx + bmwidth, sy - fontsize/2); - sy -= linestep; + UI_ThemeColor(TH_TEXT); } + + file_draw_string(sx, sy, bookmark, bmwidth, fontsize); + sy -= linestep; + } else { + glColor4ub(0xB0,0xB0,0xB0, 0xFF); + sdrawline(sx, sy-1-fontsize/2 , sx + bmwidth, sy-1-fontsize/2); + glColor4ub(0x30,0x30,0x30, 0xFF); + sdrawline(sx, sy-fontsize/2 , sx + bmwidth, sy - fontsize/2); + sy -= linestep; } } + } diff --git a/source/blender/editors/space_file/file_header.c b/source/blender/editors/space_file/file_header.c index be734ec971d..1e4feeed405 100644 --- a/source/blender/editors/space_file/file_header.c +++ b/source/blender/editors/space_file/file_header.c @@ -152,7 +152,10 @@ void file_header_buttons(const bContext *C, ARegion *ar) xco+=XIC+10; if (sfile->params->type != FILE_MAIN) { - uiDefIconButBitS(block, TOG, FILE_BOOKMARKS, B_RELOADIMASELDIR, ICON_BOOKMARKS,xco+=XIC,0,XIC,YIC, ¶ms->flag, 0, 0, 0, 0, "Toggles Bookmarks on/off"); + uiBlockBeginAlign(block); + // uiDefIconButBitS(block, TOG, FILE_BOOKMARKS, B_RELOADIMASELDIR, ICON_BOOKMARKS,xco+=XIC,0,XIC,YIC, ¶ms->flag, 0, 0, 0, 0, "Toggles Bookmarks on/off"); + uiDefIconButO(block, TOG, "FILE_OT_bookmark_toggle", WM_OP_INVOKE_DEFAULT, ICON_BOOKMARKS, xco,yco,20,20, "Toggle Bookmarks"); + uiBlockEndAlign(block); xco+=XIC+10; } diff --git a/source/blender/editors/space_file/file_intern.h b/source/blender/editors/space_file/file_intern.h index e47387a2d22..1c39e1d685e 100644 --- a/source/blender/editors/space_file/file_intern.h +++ b/source/blender/editors/space_file/file_intern.h @@ -34,6 +34,8 @@ /* file_header.c */ void file_header_buttons(const bContext *C, ARegion *ar); +/* file_ops.c */ +struct ARegion *file_buttons_region(struct ScrArea *sa); /* file_draw.c */ #define TILE_BORDER_X 8 @@ -58,6 +60,7 @@ void FILE_OT_loadimages(struct wmOperatorType *ot); void FILE_OT_exec(struct wmOperatorType *ot); void FILE_OT_cancel(struct wmOperatorType *ot); void FILE_OT_parent(struct wmOperatorType *ot); +void FILE_OT_bookmark_toggle(struct wmOperatorType *ot); int file_exec(bContext *C, struct wmOperator *unused); int file_cancel_exec(bContext *C, struct wmOperator *unused); diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index ae989194527..f280da2497e 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -69,19 +69,15 @@ static int find_file_mouse_hor(SpaceFile *sfile, struct ARegion* ar, short x, short y) { float fx,fy; - int offsetx, offsety; - int columns; int active_file = -1; int numfiles = filelist_numfiles(sfile->files); View2D* v2d = &ar->v2d; UI_view2d_region_to_view(v2d, x, y, &fx, &fy); - offsetx = (fx - (v2d->cur.xmin+sfile->tile_border_x))/(sfile->tile_w + 2*sfile->tile_border_x); - offsety = (v2d->tot.ymax - sfile->tile_border_y - fy)/(sfile->tile_h + 2*sfile->tile_border_y); - columns = (v2d->cur.xmax - v2d->cur.xmin) / (sfile->tile_w+ 2*sfile->tile_border_x); - active_file = offsetx + columns*offsety; + active_file = ED_fileselect_layout_offset(sfile->layout, v2d->tot.xmin + fx, v2d->tot.ymax - fy); + printf("FINDFILE %d\n", active_file); if ( (active_file < 0) || (active_file >= numfiles) ) { active_file = -1; @@ -96,15 +92,12 @@ static int find_file_mouse_vert(SpaceFile *sfile, struct ARegion* ar, short x, s float fx,fy; int active_file = -1; int numfiles = filelist_numfiles(sfile->files); - int rows; View2D* v2d = &ar->v2d; UI_view2d_region_to_view(v2d, x, y, &fx, &fy); - offsetx = (fx-sfile->tile_border_x)/(sfile->tile_w + sfile->tile_border_x); - offsety = (v2d->cur.ymax-fy-sfile->tile_border_y)/(sfile->tile_h + sfile->tile_border_y); - rows = (v2d->cur.ymax - v2d->cur.ymin - 2*sfile->tile_border_y) / (sfile->tile_h+sfile->tile_border_y); - active_file = rows*offsetx + offsety; + active_file = ED_fileselect_layout_offset(sfile->layout, v2d->tot.xmin + fx, v2d->tot.ymax - fy); + if ( (active_file < 0) || (active_file >= numfiles) ) { active_file = -1; @@ -135,7 +128,7 @@ static void file_select(SpaceFile* sfile, FileSelectParams* params, ARegion* ar, int numfiles = filelist_numfiles(sfile->files); params->selstate = NOTACTIVE; - if (params->display) { + if ( (params->display == FILE_IMGDISPLAY) || (params->display == FILE_LONGDISPLAY) ) { first_file = find_file_mouse_hor(sfile, ar, rect->xmin, rect->ymax); last_file = find_file_mouse_hor(sfile, ar, rect->xmax, rect->ymin); } else { @@ -154,6 +147,8 @@ static void file_select(SpaceFile* sfile, FileSelectParams* params, ARegion* ar, } } + printf("Selecting %d %d\n", first_file, last_file); + /* make the last file active */ if (last_file >= 0 && last_file < numfiles) { struct direntry* file = filelist_file(sfile->files, last_file); @@ -417,7 +412,7 @@ int file_hilight_set(SpaceFile *sfile, ARegion *ar, int mx, int my) numfiles = filelist_numfiles(sfile->files); params = ED_fileselect_get_params(sfile); - if (params->display == FILE_IMGDISPLAY) { + if ( (params->display == FILE_IMGDISPLAY) || (params->display == FILE_LONGDISPLAY)) { actfile = find_file_mouse_hor(sfile, ar, mx , my); } else { actfile = find_file_mouse_vert(sfile, ar, mx, my); @@ -522,6 +517,7 @@ int file_parent_exec(bContext *C, wmOperator *unused) } + void FILE_OT_parent(struct wmOperatorType *ot) { /* identifiers */ @@ -533,5 +529,38 @@ void FILE_OT_parent(struct wmOperatorType *ot) ot->poll= ED_operator_file_active; /* <- important, handler is on window level */ } +struct ARegion *file_buttons_region(struct ScrArea *sa) +{ + ARegion *ar, *arnew; + + for(ar= sa->regionbase.first; ar; ar= ar->next) + if(ar->regiontype==RGN_TYPE_CHANNELS) + return ar; + return NULL; +} +int file_bookmark_toggle_exec(bContext *C, wmOperator *unused) +{ + ScrArea *sa= CTX_wm_area(C); + ARegion *ar= file_buttons_region(sa); + + if(ar) { + ar->flag ^= RGN_FLAG_HIDDEN; + ar->v2d.flag &= ~V2D_IS_INITIALISED; /* XXX should become hide/unhide api? */ + + ED_area_initialize(CTX_wm_manager(C), CTX_wm_window(C), sa); + ED_area_tag_redraw(sa); + } + return OPERATOR_FINISHED; +} +void FILE_OT_bookmark_toggle(struct wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Toggle Bookmarks"; + ot->idname= "FILE_OT_bookmark_toggle"; + + /* api callbacks */ + ot->exec= file_bookmark_toggle_exec; + ot->poll= ED_operator_file_active; /* <- important, handler is on window level */ +} diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c index 384fb2141c3..c52f2bc0132 100644 --- a/source/blender/editors/space_file/filelist.c +++ b/source/blender/editors/space_file/filelist.c @@ -82,6 +82,7 @@ #include "PIL_time.h" +#include "UI_text.h" #include "filelist.h" @@ -121,6 +122,7 @@ typedef struct FileList short hide_dot; unsigned int filter; short changed; + int maxnamelen; ListBase loadimages; ListBase threads; } FileList; @@ -676,10 +678,16 @@ void filelist_setfilter(struct FileList* filelist, unsigned int filter) filelist->filter = filter; } +int filelist_maxnamelen(struct FileList* filelist) +{ + return filelist->maxnamelen; +} + void filelist_readdir(struct FileList* filelist) { char wdir[FILE_MAX]; int finished = 0; + int i; if (!filelist) return; filelist->fidx = 0; @@ -711,6 +719,14 @@ void filelist_readdir(struct FileList* filelist) BLI_init_threads(&filelist->threads, exec_loadimages, 2); } } + + filelist->maxnamelen = 0; + for (i=0; (i < filelist->numfiles); ++i) + { + struct direntry* file = filelist_file(filelist, i); + int len = UI_GetStringWidth(G.font, file->relname,0)+UI_GetStringWidth(G.font, file->size,0); + if (len > filelist->maxnamelen) filelist->maxnamelen = len; + } } int filelist_empty(struct FileList* filelist) diff --git a/source/blender/editors/space_file/filelist.h b/source/blender/editors/space_file/filelist.h index e71bcbddb86..a6d0d9897f1 100644 --- a/source/blender/editors/space_file/filelist.h +++ b/source/blender/editors/space_file/filelist.h @@ -64,6 +64,7 @@ void filelist_loadimage_timer(struct FileList* filelist); struct ImBuf * filelist_getimage(struct FileList* filelist, int index); short filelist_changed(struct FileList* filelist); void filelist_readdir(struct FileList* filelist); +int filelist_maxnamelen(struct FileList* filelist); int filelist_empty(struct FileList* filelist); void filelist_parent(struct FileList* filelist); diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c index f2eb7ad58ea..f4f512ff8c2 100644 --- a/source/blender/editors/space_file/filesel.c +++ b/source/blender/editors/space_file/filesel.c @@ -58,6 +58,8 @@ #include "BKE_screen.h" #include "BKE_global.h" +#include "DNA_userdef_types.h" + #include "ED_screen.h" #include "ED_util.h" #include "ED_fileselect.h" @@ -79,7 +81,7 @@ FileSelectParams* ED_fileselect_get_params(struct SpaceFile *sfile) { if (!sfile->params) { - ED_fileselect_set_params(sfile, FILE_UNIX, "", "/", 0, 0, 0); + ED_fileselect_set_params(sfile, FILE_UNIX, "", "/", 0, FILE_SHORTDISPLAY, 0); } return sfile->params; } @@ -132,3 +134,108 @@ void ED_fileselect_reset_params(SpaceFile *sfile) sfile->params->flag = 0; sfile->params->title[0] = '\0'; } + + +int ED_fileselect_layout_offset(FileLayout* layout, int x, int y) +{ + int offsetx, offsety; + int active_file; + + offsetx = (x)/(layout->tile_w + 2*layout->tile_border_x); + offsety = (y)/(layout->tile_h + 2*layout->tile_border_y); + + if (layout->flag & FILE_LAYOUT_HOR) + active_file = layout->rows*offsetx + offsety; + else + active_file = offsetx + layout->columns*offsety; + printf("OFFSET %d %d %d %d %d\n", x,y, offsetx, offsety, active_file); + return active_file; +} + +void ED_fileselect_layout_tilepos(FileLayout* layout, int tile, short *x, short *y) +{ + if (layout->flag == FILE_LAYOUT_HOR) { + *x = layout->tile_border_x + (tile/layout->rows)*(layout->tile_w+2*layout->tile_border_x); + *y = layout->tile_border_y + (tile%layout->rows)*(layout->tile_h+2*layout->tile_border_y); + } else { + *x = layout->tile_border_x + ((tile)%layout->columns)*(layout->tile_w+2*layout->tile_border_x); + *y = layout->tile_border_y + ((tile)/layout->columns)*(layout->tile_h+2*layout->tile_border_y); + } +} + + +void ED_fileselect_init_layout(struct SpaceFile *sfile, struct ARegion *ar) +{ + FileSelectParams* params = ED_fileselect_get_params(sfile); + View2D *v2d= &ar->v2d; + int width=0, height=0; + int rows, columns; + int i; + int maxlen = 0; + int numfiles = filelist_numfiles(sfile->files); + + if (sfile->layout == 0) { + sfile->layout = MEM_callocN(sizeof(struct FileLayout), "file_layout"); + } + + if (params->display == FILE_IMGDISPLAY) { + sfile->layout->prv_w = 96; + sfile->layout->prv_h = 96; + sfile->layout->tile_border_x = 4; + sfile->layout->tile_border_y = 4; + sfile->layout->prv_border_x = 4; + sfile->layout->prv_border_y = 4; + sfile->layout->tile_w = sfile->layout->prv_w + 2*sfile->layout->prv_border_x; + sfile->layout->tile_h = sfile->layout->prv_h + 4*sfile->layout->prv_border_y + U.fontsize*3/2; + sfile->layout->width= (v2d->cur.xmax - v2d->cur.xmin - 2*sfile->layout->tile_border_x); + sfile->layout->columns= sfile->layout->width / (sfile->layout->tile_w + 2*sfile->layout->tile_border_x); + if(sfile->layout->columns) + sfile->layout->rows= numfiles/sfile->layout->columns + 1; // XXX dirty, modulo is zero + else + sfile->layout->rows= numfiles + 1; // XXX dirty, modulo is zero + sfile->layout->height= sfile->layout->rows*(sfile->layout->tile_h+2*sfile->layout->tile_border_y) + sfile->layout->tile_border_y*2; + sfile->layout->flag = FILE_LAYOUT_VER; + } else if (params->display == FILE_SHORTDISPLAY) { + sfile->layout->prv_w = 0; + sfile->layout->prv_h = 0; + sfile->layout->tile_border_x = 8; + sfile->layout->tile_border_y = 2; + sfile->layout->prv_border_x = 0; + sfile->layout->prv_border_y = 0; + sfile->layout->tile_w = 240; + sfile->layout->tile_h = U.fontsize*3/2; + sfile->layout->height= v2d->cur.ymax - v2d->cur.ymin; + sfile->layout->rows = sfile->layout->height / (sfile->layout->tile_h + 2*sfile->layout->tile_border_y);; + + maxlen = filelist_maxnamelen(sfile->files); + sfile->layout->tile_w = maxlen + 100; + if(sfile->layout->rows > 0) + sfile->layout->columns = numfiles/sfile->layout->rows + 1; // XXX dirty, modulo is zero + else + sfile->layout->columns = numfiles + 1; // XXX dirty, modulo is zero + sfile->layout->width = sfile->layout->columns * (sfile->layout->tile_w + 2*sfile->layout->tile_border_x) + sfile->layout->tile_border_x*2; + sfile->layout->flag = FILE_LAYOUT_HOR; + } else { + sfile->layout->prv_w = 0; + sfile->layout->prv_h = 0; + sfile->layout->tile_border_x = 8; + sfile->layout->tile_border_y = 1; + sfile->layout->prv_border_x = 0; + sfile->layout->prv_border_y = 0; + sfile->layout->tile_w = v2d->cur.xmax - v2d->cur.xmin - 2*sfile->layout->tile_border_x; + sfile->layout->tile_h = U.fontsize*3/2; + sfile->layout->width= (v2d->cur.xmax - v2d->cur.xmin + 2*sfile->layout->tile_border_x); + sfile->layout->rows= numfiles; + sfile->layout->columns= 1; + sfile->layout->height= sfile->layout->rows*(sfile->layout->tile_h+2*sfile->layout->tile_border_y) + sfile->layout->tile_border_y*2; + sfile->layout->flag = FILE_LAYOUT_VER; + } +} + +FileLayout* ED_fileselect_get_layout(struct SpaceFile *sfile, struct ARegion *ar) +{ + if (!sfile->layout) { + ED_fileselect_init_layout(sfile, ar); + } + return sfile->layout; +}
\ No newline at end of file diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c index 70d7ad9cde5..da7b61b5ee7 100644 --- a/source/blender/editors/space_file/space_file.c +++ b/source/blender/editors/space_file/space_file.c @@ -62,6 +62,7 @@ #include "UI_resources.h" #include "UI_view2d.h" + #include "ED_markers.h" #include "ED_fileselect.h" @@ -90,6 +91,7 @@ static SpaceLink *file_new(const bContext *C) BLI_addtail(&sfile->regionbase, ar); ar->regiontype= RGN_TYPE_CHANNELS; ar->alignment= RGN_ALIGN_LEFT; + ar->flag |= RGN_FLAG_HIDDEN; /* ui list region */ ar= MEM_callocN(sizeof(ARegion), "ui area for file"); @@ -128,6 +130,11 @@ static void file_free(SpaceLink *sl) MEM_freeN(sfile->params); sfile->params= NULL; } + + if (sfile->layout) { + MEM_freeN(sfile->layout); + sfile->layout = NULL; + } } @@ -153,6 +160,9 @@ static SpaceLink *file_duplicate(SpaceLink *sl) filelist_setdir(sfilen->files, sfilen->params->dir); filelist_settype(sfilen->files, sfilen->params->type); } + if (sfileo->layout) { + sfilen->layout= MEM_dupallocN(sfileo->layout); + } return (SpaceLink *)sfilen; } @@ -209,7 +219,7 @@ static void file_main_area_draw(const bContext *C, ARegion *ar) glClear(GL_COLOR_BUFFER_BIT); /* Allow dynamically sliders to be set, saves notifiers etc. */ - if (sfile->params && (sfile->params->display == FILE_IMGDISPLAY) ) + if (sfile->params && ( (sfile->params->display == FILE_IMGDISPLAY) || (sfile->params->display == FILE_LONGDISPLAY)) ) v2d->scroll = V2D_SCROLL_RIGHT; else v2d->scroll = V2D_SCROLL_BOTTOM; @@ -256,6 +266,7 @@ void file_operatortypes(void) WM_operatortype_append(FILE_OT_exec); WM_operatortype_append(FILE_OT_cancel); WM_operatortype_append(FILE_OT_parent); + WM_operatortype_append(FILE_OT_bookmark_toggle); } /* NOTE: do not add .blend file reading on this level */ @@ -392,7 +403,7 @@ void ED_spacetype_file(void) /* regions: ui */ art= MEM_callocN(sizeof(ARegionType), "spacetype file region"); art->regionid = RGN_TYPE_UI; - art->minsizey= 100; + art->minsizey= 80; art->keymapflag= ED_KEYMAP_UI; art->init= file_ui_area_init; art->draw= file_ui_area_draw; |