forked from bartvdbraak/blender
2.5 filebrowser
* code cleanup: remove duplication in drawing, join list and preview drawing
This commit is contained in:
parent
1772a0a62f
commit
c1100361e2
@ -65,6 +65,7 @@ typedef struct FileLayout
|
|||||||
short height;
|
short height;
|
||||||
short flag;
|
short flag;
|
||||||
short dirty;
|
short dirty;
|
||||||
|
short textheight;
|
||||||
float column_widths[MAX_FILE_COLUMN];
|
float column_widths[MAX_FILE_COLUMN];
|
||||||
} FileLayout;
|
} FileLayout;
|
||||||
|
|
||||||
|
@ -353,59 +353,9 @@ void file_calc_previews(const bContext *C, ARegion *ar)
|
|||||||
UI_view2d_totRect_set(v2d, sfile->layout->width, sfile->layout->height);
|
UI_view2d_totRect_set(v2d, sfile->layout->width, sfile->layout->height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void file_draw_previews(const bContext *C, ARegion *ar)
|
static void file_draw_preview(short sx, short sy, ImBuf *imb, FileLayout *layout, short dropshadow)
|
||||||
{
|
{
|
||||||
SpaceFile *sfile= CTX_wm_space_file(C);
|
if (imb) {
|
||||||
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 fx, fy;
|
||||||
float dx, dy;
|
float dx, dy;
|
||||||
short xco, yco;
|
short xco, yco;
|
||||||
@ -433,15 +383,15 @@ void file_draw_previews(const bContext *C, ARegion *ar)
|
|||||||
ey = (short)scaledy;
|
ey = (short)scaledy;
|
||||||
fx = ((float)layout->prv_w - (float)ex)/2.0f;
|
fx = ((float)layout->prv_w - (float)ex)/2.0f;
|
||||||
fy = ((float)layout->prv_h - (float)ey)/2.0f;
|
fy = ((float)layout->prv_h - (float)ey)/2.0f;
|
||||||
dx = (fx + 0.5f + sfile->layout->prv_border_x);
|
dx = (fx + 0.5f + layout->prv_border_x);
|
||||||
dy = (fy + 0.5f - sfile->layout->prv_border_y);
|
dy = (fy + 0.5f - layout->prv_border_y);
|
||||||
xco = (float)sx + dx;
|
xco = (float)sx + dx;
|
||||||
yco = (float)sy - sfile->layout->prv_h + dy;
|
yco = (float)sy - layout->prv_h + dy;
|
||||||
|
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
/* shadow */
|
/* shadow */
|
||||||
if (!is_icon && (file->flags & IMAGEFILE))
|
if (dropshadow)
|
||||||
uiDrawBoxShadow(220, xco, yco, xco + ex, yco + ey);
|
uiDrawBoxShadow(220, xco, yco, xco + ex, yco + ey);
|
||||||
|
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
@ -451,7 +401,7 @@ void file_draw_previews(const bContext *C, ARegion *ar)
|
|||||||
glaDrawPixelsTexScaled(xco, yco, imb->x, imb->y, GL_UNSIGNED_BYTE, imb->rect, scale, scale);
|
glaDrawPixelsTexScaled(xco, yco, imb->x, imb->y, GL_UNSIGNED_BYTE, imb->rect, scale, scale);
|
||||||
|
|
||||||
/* border */
|
/* border */
|
||||||
if (!is_icon && (file->flags & IMAGEFILE)) {
|
if (dropshadow) {
|
||||||
glColor4f(0.0f, 0.0f, 0.0f, 0.4f);
|
glColor4f(0.0f, 0.0f, 0.0f, 0.4f);
|
||||||
fdrawbox(xco, yco, xco + ex, yco + ey);
|
fdrawbox(xco, yco, xco + ex, yco + ey);
|
||||||
}
|
}
|
||||||
@ -459,41 +409,6 @@ void file_draw_previews(const bContext *C, ARegion *ar)
|
|||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
imb = 0;
|
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)
|
static void renamebutton_cb(bContext *C, void *arg1, char *oldname)
|
||||||
@ -523,6 +438,39 @@ 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)
|
void file_draw_list(const bContext *C, ARegion *ar)
|
||||||
{
|
{
|
||||||
SpaceFile *sfile= CTX_wm_space_file(C);
|
SpaceFile *sfile= CTX_wm_space_file(C);
|
||||||
@ -531,6 +479,7 @@ void file_draw_list(const bContext *C, ARegion *ar)
|
|||||||
View2D *v2d= &ar->v2d;
|
View2D *v2d= &ar->v2d;
|
||||||
struct FileList* files = sfile->files;
|
struct FileList* files = sfile->files;
|
||||||
struct direntry *file;
|
struct direntry *file;
|
||||||
|
ImBuf *imb;
|
||||||
int numfiles;
|
int numfiles;
|
||||||
int numfiles_layout;
|
int numfiles_layout;
|
||||||
int colorid = 0;
|
int colorid = 0;
|
||||||
@ -538,6 +487,7 @@ void file_draw_list(const bContext *C, ARegion *ar)
|
|||||||
int offset;
|
int offset;
|
||||||
int i;
|
int i;
|
||||||
float sw, spos;
|
float sw, spos;
|
||||||
|
short is_icon;
|
||||||
|
|
||||||
numfiles = filelist_numfiles(files);
|
numfiles = filelist_numfiles(files);
|
||||||
|
|
||||||
@ -547,26 +497,11 @@ void file_draw_list(const bContext *C, ARegion *ar)
|
|||||||
offset = ED_fileselect_layout_offset(layout, 0, 0);
|
offset = ED_fileselect_layout_offset(layout, 0, 0);
|
||||||
if (offset<0) offset=0;
|
if (offset<0) offset=0;
|
||||||
|
|
||||||
/* alternating flat shade background */
|
if (params->display != FILE_IMGDISPLAY) {
|
||||||
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;
|
|
||||||
|
|
||||||
UI_ThemeColorShade(TH_BACK, -7);
|
draw_background(layout, v2d);
|
||||||
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;
|
sx = ar->v2d.cur.xmin + layout->tile_border_x;
|
||||||
@ -594,16 +529,33 @@ void file_draw_list(const bContext *C, ARegion *ar)
|
|||||||
}
|
}
|
||||||
|
|
||||||
spos = sx;
|
spos = sx;
|
||||||
file_draw_icon(spos, sy-3, get_file_icon(file), ICON_DEFAULT_WIDTH, ICON_DEFAULT_WIDTH);
|
|
||||||
spos += ICON_DEFAULT_WIDTH + 4;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
UI_ThemeColor4(TH_TEXT);
|
UI_ThemeColor4(TH_TEXT);
|
||||||
|
|
||||||
sw = file_string_width(file->relname);
|
sw = file_string_width(file->relname);
|
||||||
if (file->flags & EDITING) {
|
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);
|
uiBlock *block = uiBeginBlock(C, ar, "FileName", UI_EMBOSS);
|
||||||
uiBut *but = uiDefBut(block, TEX, 1, "", spos, sy-layout->tile_h-3,
|
uiBut *but = uiDefBut(block, TEX, 1, "", spos, sy-layout->tile_h-3,
|
||||||
layout->column_widths[COLUMN_NAME], layout->tile_h, file->relname, 1.0f, (float)FILE_MAX,0,0,"");
|
but_width, layout->textheight*2, file->relname, 1.0f, (float)FILE_MAX,0,0,"");
|
||||||
uiButSetRenameFunc(but, renamebutton_cb, file);
|
uiButSetRenameFunc(but, renamebutton_cb, file);
|
||||||
if ( 0 == uiButActiveOnly(C, block, but)) {
|
if ( 0 == uiButActiveOnly(C, block, but)) {
|
||||||
file->flags &= ~EDITING;
|
file->flags &= ~EDITING;
|
||||||
@ -611,36 +563,42 @@ void file_draw_list(const bContext *C, ARegion *ar)
|
|||||||
uiEndBlock(C, block);
|
uiEndBlock(C, block);
|
||||||
uiDrawBlock(C, block);
|
uiDrawBlock(C, block);
|
||||||
} else {
|
} else {
|
||||||
file_draw_string(spos, sy, file->relname, sw, layout->tile_h, FILE_SHORTEN_END);
|
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);
|
||||||
}
|
}
|
||||||
spos += layout->column_widths[COLUMN_NAME] + 12;
|
|
||||||
if (params->display == FILE_SHOWSHORT) {
|
uiSetRoundBox(0);
|
||||||
|
|
||||||
|
if (params->display == FILE_SHORTDISPLAY) {
|
||||||
|
spos += layout->column_widths[COLUMN_NAME] + 12;
|
||||||
if (!(file->type & S_IFDIR)) {
|
if (!(file->type & S_IFDIR)) {
|
||||||
sw = file_string_width(file->size);
|
sw = file_string_width(file->size);
|
||||||
spos += layout->column_widths[COLUMN_SIZE] + 12 - sw;
|
spos += layout->column_widths[COLUMN_SIZE] + 12 - sw;
|
||||||
file_draw_string(spos, sy, file->size, sw+1, layout->tile_h, FILE_SHORTEN_END);
|
file_draw_string(spos, sy, file->size, sw+1, layout->tile_h, FILE_SHORTEN_END);
|
||||||
}
|
}
|
||||||
} else {
|
} else if (params->display == FILE_LONGDISPLAY) {
|
||||||
#if 0 // XXX TODO: add this for non-windows systems
|
spos += layout->column_widths[COLUMN_NAME] + 12;
|
||||||
|
|
||||||
|
#ifndef WIN32
|
||||||
/* rwx rwx rwx */
|
/* rwx rwx rwx */
|
||||||
spos += 20;
|
spos += 20;
|
||||||
sw = UI_GetStringWidth(file->mode1);
|
sw = file_string_width(file->mode1);
|
||||||
file_draw_string(spos, sy, file->mode1, sw, layout->tile_h);
|
file_draw_string(spos, sy, file->mode1, sw, layout->tile_h, FILE_SHORTEN_END);
|
||||||
|
spos += layout->column_widths[COLUMN_MODE1] + 12;
|
||||||
|
|
||||||
spos += 30;
|
sw = file_string_width(file->mode2);
|
||||||
sw = UI_GetStringWidth(file->mode2);
|
file_draw_string(spos, sy, file->mode2, sw, layout->tile_h, FILE_SHORTEN_END);
|
||||||
file_draw_string(spos, sy, file->mode2, sw, layout->tile_h);
|
spos += layout->column_widths[COLUMN_MODE2] + 12;
|
||||||
|
|
||||||
spos += 30;
|
sw = file_string_width(file->mode3);
|
||||||
sw = UI_GetStringWidth(file->mode3);
|
file_draw_string(spos, sy, file->mode3, sw, layout->tile_h, FILE_SHORTEN_END);
|
||||||
file_draw_string(spos, sy, file->mode3, sw, layout->tile_h);
|
spos += layout->column_widths[COLUMN_MODE3] + 12;
|
||||||
|
|
||||||
spos += 30;
|
sw = file_string_width(file->owner);
|
||||||
sw = UI_GetStringWidth(file->owner);
|
file_draw_string(spos, sy, file->owner, sw, layout->tile_h, FILE_SHORTEN_END);
|
||||||
file_draw_string(spos, sy, file->owner, sw, layout->tile_h);
|
spos += layout->column_widths[COLUMN_OWNER] + 12;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
sw = file_string_width(file->date);
|
sw = file_string_width(file->date);
|
||||||
file_draw_string(spos, sy, file->date, sw, layout->tile_h, FILE_SHORTEN_END);
|
file_draw_string(spos, sy, file->date, sw, layout->tile_h, FILE_SHORTEN_END);
|
||||||
spos += layout->column_widths[COLUMN_DATE] + 12;
|
spos += layout->column_widths[COLUMN_DATE] + 12;
|
||||||
@ -656,6 +614,9 @@ 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. */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -287,6 +287,7 @@ void ED_fileselect_init_layout(struct SpaceFile *sfile, struct ARegion *ar)
|
|||||||
numfiles = filelist_numfiles(sfile->files);
|
numfiles = filelist_numfiles(sfile->files);
|
||||||
textheight = file_font_pointsize();
|
textheight = file_font_pointsize();
|
||||||
layout = sfile->layout;
|
layout = sfile->layout;
|
||||||
|
layout->textheight = textheight;
|
||||||
|
|
||||||
if (params->display == FILE_IMGDISPLAY) {
|
if (params->display == FILE_IMGDISPLAY) {
|
||||||
layout->prv_w = 96;
|
layout->prv_w = 96;
|
||||||
|
@ -310,12 +310,7 @@ static void file_main_area_draw(const bContext *C, ARegion *ar)
|
|||||||
file_hilight_set(sfile, ar, event->x, event->y);
|
file_hilight_set(sfile, ar, event->x, event->y);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params->display == FILE_IMGDISPLAY) {
|
file_draw_list(C, ar);
|
||||||
file_draw_previews(C, ar);
|
|
||||||
} else {
|
|
||||||
file_draw_list(C, ar);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* reset view matrix */
|
/* reset view matrix */
|
||||||
UI_view2d_view_restore(C);
|
UI_view2d_view_restore(C);
|
||||||
|
Loading…
Reference in New Issue
Block a user