diff options
author | Andrea Weikert <elubie@gmx.net> | 2010-11-14 13:48:36 +0300 |
---|---|---|
committer | Andrea Weikert <elubie@gmx.net> | 2010-11-14 13:48:36 +0300 |
commit | 2e84732228c749f4d7932ab3a4fe60c95f7d19ac (patch) | |
tree | 0b5a086b0e52ba765993c228532521e252ed09f1 /source/blender | |
parent | 27f607f86d270a124c6558ebf7d94ef705ec4da8 (diff) |
== filebrowser ==
* drawing code cleanup.
* list drawing code now uses uiStyleFontDraw like buttons etc.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/space_file/file_draw.c | 112 | ||||
-rw-r--r-- | source/blender/editors/space_file/file_intern.h | 2 | ||||
-rw-r--r-- | source/blender/editors/space_file/filesel.c | 16 |
3 files changed, 62 insertions, 68 deletions
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c index 37b3a0e05fa..fc825ea03a7 100644 --- a/source/blender/editors/space_file/file_draw.c +++ b/source/blender/editors/space_file/file_draw.c @@ -290,23 +290,26 @@ static void file_draw_icon(uiBlock *block, char *path, int sx, int sy, int icon, } -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) { - int soffs; char fname[FILE_MAXFILE]; + rcti rect; float sw; - float x,y; + uiStyle *style= U.uistyles.first; + uiFontStyle fs = style->widgetlabel; + 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); + sw = file_shorten_string(fname, width+1, 0 ); - UI_DrawString(x,y, fname); + rect.xmin = sx; + rect.xmax = sx + width; + rect.ymin = sy - height; + rect.ymax = sy; + + uiStyleFontDraw(&fs, &rect, fname); } void file_calc_previews(const bContext *C, ARegion *ar) @@ -461,9 +464,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); @@ -486,6 +491,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); @@ -496,27 +506,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) { @@ -539,58 +528,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(spos, 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(spos, 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(spos, 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(spos, 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; } } } diff --git a/source/blender/editors/space_file/file_intern.h b/source/blender/editors/space_file/file_intern.h index 3217b5ba4f6..0bc9a6e8db8 100644 --- a/source/blender/editors/space_file/file_intern.h +++ b/source/blender/editors/space_file/file_intern.h @@ -93,7 +93,7 @@ void file_operator_to_sfile(struct SpaceFile *sfile, struct wmOperator *op); /* filesel.c */ -float file_shorten_string(char* string, float w, int flag); +float file_shorten_string(char* string, float w, int front); float file_string_width(const char* str); float file_string_width_shortened(const char* str, float width); diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c index 471a1784f02..af823654b9d 100644 --- a/source/blender/editors/space_file/filesel.c +++ b/source/blender/editors/space_file/filesel.c @@ -79,6 +79,7 @@ #include "RNA_access.h" #include "UI_interface.h" +#include "UI_interface_icons.h" #include "file_intern.h" #include "filelist.h" @@ -380,7 +381,7 @@ static void column_widths(struct FileList* files, struct FileLayout* layout) if (file) { int len; len = file_string_width(file->relname); - if (len > layout->column_widths[COLUMN_NAME]) layout->column_widths[COLUMN_NAME] = len + 20; + if (len > layout->column_widths[COLUMN_NAME]) layout->column_widths[COLUMN_NAME] = len; len = file_string_width(file->date); if (len > layout->column_widths[COLUMN_DATE]) layout->column_widths[COLUMN_DATE] = len; len = file_string_width(file->time); @@ -452,11 +453,12 @@ void ED_fileselect_init_layout(struct SpaceFile *sfile, struct ARegion *ar) column_widths(sfile->files, layout); if (params->display == FILE_SHORTDISPLAY) { - maxlen = layout->column_widths[COLUMN_NAME] + 12 + - layout->column_widths[COLUMN_SIZE]; - maxlen += 20; // for icon + maxlen = ICON_DEFAULT_WIDTH + 4 + + layout->column_widths[COLUMN_NAME] + 12 + + layout->column_widths[COLUMN_SIZE] + 12; } else { - maxlen = layout->column_widths[COLUMN_NAME] + 12 + + maxlen = ICON_DEFAULT_WIDTH + 4 + + layout->column_widths[COLUMN_NAME] + 12 + #ifndef WIN32 layout->column_widths[COLUMN_MODE1] + 12 + layout->column_widths[COLUMN_MODE2] + 12 + @@ -465,8 +467,8 @@ void ED_fileselect_init_layout(struct SpaceFile *sfile, struct ARegion *ar) #endif layout->column_widths[COLUMN_DATE] + 12 + layout->column_widths[COLUMN_TIME] + 12 + - layout->column_widths[COLUMN_SIZE]; - maxlen += 20; // for icon + layout->column_widths[COLUMN_SIZE] + 12; + } layout->tile_w = maxlen; if(layout->rows > 0) |