[Bf-blender-cvs] [8540656] asset-experiments: FileBrowser: enhance handling of most compact drawing by also reducing size of static strings like file size.

Bastien Montagne noreply at git.blender.org
Mon May 4 17:01:29 CEST 2015


Commit: 85406569e14a9d1bb1378e23488b0f197c3773fa
Author: Bastien Montagne
Date:   Mon May 4 17:00:45 2015 +0200
Branches: asset-experiments
https://developer.blender.org/rB85406569e14a9d1bb1378e23488b0f197c3773fa

FileBrowser: enhance handling of most compact drawing by also reducing size of static strings like file size.

===================================================================

M	source/blender/blenlib/BLI_fileops.h
M	source/blender/blenlib/intern/BLI_filelist.c
M	source/blender/editors/include/ED_fileselect.h
M	source/blender/editors/space_file/file_draw.c
M	source/blender/editors/space_file/file_intern.h
M	source/blender/editors/space_file/filesel.c

===================================================================

diff --git a/source/blender/blenlib/BLI_fileops.h b/source/blender/blenlib/BLI_fileops.h
index 0a043ea..5f4c74a 100644
--- a/source/blender/blenlib/BLI_fileops.h
+++ b/source/blender/blenlib/BLI_fileops.h
@@ -97,10 +97,12 @@ void BLI_filelist_duplicate(struct direntry **dest_filelist, struct direntry *sr
 void BLI_filelist_entry_free(struct direntry *entry);
 void BLI_filelist_free(struct direntry *filelist, unsigned int nrentries);
 
-void BLI_filelist_entry_size_to_string(struct stat *st, const uint64_t sz, char r_size[]);
-void BLI_filelist_entry_mode_to_string(struct stat *st, char r_mode1[], char r_mode2[], char r_mode3[]);
-void BLI_filelist_entry_owner_to_string(struct stat *st, char r_owner[]);
-void BLI_filelist_entry_datetime_to_string(struct stat *st, const int64_t ts, char r_time[], char r_date[]);
+void BLI_filelist_entry_size_to_string(struct stat *st, const uint64_t sz, const bool compact, char r_size[]);
+void BLI_filelist_entry_mode_to_string(
+        struct stat *st, const bool compact, char r_mode1[], char r_mode2[], char r_mode3[]);
+void BLI_filelist_entry_owner_to_string(struct stat *st, const bool compact, char r_owner[]);
+void BLI_filelist_entry_datetime_to_string(
+        struct stat *st, const int64_t ts, const bool compact, char r_time[], char r_date[]);
 
 /* Files */
 
diff --git a/source/blender/blenlib/intern/BLI_filelist.c b/source/blender/blenlib/intern/BLI_filelist.c
index d5f1e96..6602377 100644
--- a/source/blender/blenlib/intern/BLI_filelist.c
+++ b/source/blender/blenlib/intern/BLI_filelist.c
@@ -239,7 +239,8 @@ unsigned int BLI_filelist_dir_contents(const char *dirname,  struct direntry **f
  * Convert given entry's size into human-readable strings.
  *
  */
-void BLI_filelist_entry_size_to_string(struct stat *st, const uint64_t sz, char r_size[FILELIST_DIRENTRY_SIZE_LEN])
+void BLI_filelist_entry_size_to_string(
+        struct stat *st, const uint64_t sz, const bool compact, char r_size[static FILELIST_DIRENTRY_SIZE_LEN])
 {
 	double size;
 	const char *fmt;
@@ -253,15 +254,15 @@ void BLI_filelist_entry_size_to_string(struct stat *st, const uint64_t sz, char
 
 	if (size > 1024.0 * 1024.0 * 1024.0) {
 		size /= (1024.0 * 1024.0 * 1024.0);
-		fmt = "%.2f GiB";
+		fmt = compact ? "%.0f G" : "%.2f GiB";
 	}
 	else if (size > 1024.0 * 1024.0) {
 		size /= (1024.0 * 1024.0);
-		fmt = "%.2f MiB";
+		fmt = compact ? "%.0f M" : "%.2f MiB";
 	}
 	else if (size > 1024.0) {
 		size /= 1024.0;
-		fmt = "%.2f KiB";
+		fmt = compact ? "%.0f K" : "%.2f KiB";
 	}
 	else {
 		fmt = "%.0f B";
@@ -275,8 +276,8 @@ void BLI_filelist_entry_size_to_string(struct stat *st, const uint64_t sz, char
  *
  */
 void BLI_filelist_entry_mode_to_string(
-        struct stat *st, char r_mode1[FILELIST_DIRENTRY_MODE_LEN],
-        char r_mode2[FILELIST_DIRENTRY_MODE_LEN], char r_mode3[FILELIST_DIRENTRY_MODE_LEN])
+        struct stat *st, const bool UNUSED(compact), char r_mode1[static FILELIST_DIRENTRY_MODE_LEN],
+        char r_mode2[static FILELIST_DIRENTRY_MODE_LEN], char r_mode3[static FILELIST_DIRENTRY_MODE_LEN])
 {
 	const char *types[8] = {"---", "--x", "-w-", "-wx", "r--", "r-x", "rw-", "rwx"};
 
@@ -311,7 +312,8 @@ void BLI_filelist_entry_mode_to_string(
  * Convert given entry's owner into human-readable strings.
  *
  */
-void BLI_filelist_entry_owner_to_string(struct stat *st, char r_owner[FILELIST_DIRENTRY_OWNER_LEN])
+void BLI_filelist_entry_owner_to_string(
+        struct stat *st, const bool UNUSED(compact), char r_owner[static FILELIST_DIRENTRY_OWNER_LEN])
 {
 #ifdef WIN32
 	strcpy(r_owner, "unknown");
@@ -331,7 +333,8 @@ void BLI_filelist_entry_owner_to_string(struct stat *st, char r_owner[FILELIST_D
  * Convert given entry's time into human-readable strings.
  */
 void BLI_filelist_entry_datetime_to_string(
-        struct stat *st, const int64_t ts, char r_time[FILELIST_DIRENTRY_TIME_LEN], char r_date[FILELIST_DIRENTRY_DATE_LEN])
+        struct stat *st, const int64_t ts, const bool compact,
+        char r_time[static FILELIST_DIRENTRY_TIME_LEN], char r_date[static FILELIST_DIRENTRY_DATE_LEN])
 {
 	const struct tm *tm = localtime(st ? &st->st_mtime : &ts);
 	const time_t zero = 0;
@@ -345,7 +348,7 @@ void BLI_filelist_entry_datetime_to_string(
 		strftime(r_time, sizeof(*r_time) * FILELIST_DIRENTRY_TIME_LEN, "%H:%M", tm);
 	}
 	if (r_date) {
-		strftime(r_date, sizeof(*r_date) * FILELIST_DIRENTRY_DATE_LEN, "%d-%b-%y", tm);
+		strftime(r_date, sizeof(*r_date) * FILELIST_DIRENTRY_DATE_LEN, compact ? "%d/%m/%y" : "%d-%b-%y", tm);
 	}
 }
 
diff --git a/source/blender/editors/include/ED_fileselect.h b/source/blender/editors/include/ED_fileselect.h
index bfc78fc..84d37c6 100644
--- a/source/blender/editors/include/ED_fileselect.h
+++ b/source/blender/editors/include/ED_fileselect.h
@@ -67,6 +67,9 @@ typedef struct FileLayout {
 	int dirty;
 	int textheight;
 	float column_widths[MAX_FILE_COLUMN];
+
+	/* When we change display size, we may have to update static strings like size of files... */
+	short curr_size;
 } FileLayout;
 
 typedef struct FileSelection {
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c
index 0e0f478..2d0fc8c 100644
--- a/source/blender/editors/space_file/file_draw.c
+++ b/source/blender/editors/space_file/file_draw.c
@@ -479,6 +479,8 @@ void file_draw_list(const bContext *C, ARegion *ar)
 	short align;
 	bool do_drag;
 	int column_space = 0.6f * UI_UNIT_X;
+	const bool small_size = SMALL_SIZE_CHECK(params->thumbnail_size);
+	const bool update_stat_strings = small_size != SMALL_SIZE_CHECK(layout->curr_size);
 
 	numfiles = filelist_numfiles(files);
 	
@@ -582,12 +584,14 @@ void file_draw_list(const bContext *C, ARegion *ar)
 			}
 
 			but = uiDefBut(block, UI_BTYPE_TEXT, 1, "", sx, sy - layout->tile_h - 0.15f * UI_UNIT_X,
-			               width, textheight, sfile->params->renameedit, 1.0f, (float)sizeof(sfile->params->renameedit), 0, 0, "");
+			               width, textheight, sfile->params->renameedit, 1.0f,
+			               (float)sizeof(sfile->params->renameedit), 0, 0, "");
 			UI_but_func_rename_set(but, renamebutton_cb, file);
 			UI_but_flag_enable(but, UI_BUT_NO_UTF8); /* allow non utf8 names */
 			UI_but_flag_disable(but, UI_BUT_UNDO);
 			if (false == UI_but_active_only(C, ar, block, but)) {
-				file_selflag = filelist_entry_select_set(sfile->files, file, FILE_SEL_REMOVE, FILE_SEL_EDITING, CHECK_ALL);
+				file_selflag = filelist_entry_select_set(
+				                   sfile->files, file, FILE_SEL_REMOVE, FILE_SEL_EDITING, CHECK_ALL);
 			}
 		}
 
@@ -599,18 +603,20 @@ void file_draw_list(const bContext *C, ARegion *ar)
 		if (params->display == FILE_SHORTDISPLAY) {
 			sx += (int)layout->column_widths[COLUMN_NAME] + column_space;
 			if (!(file->typeflag & FILE_TYPE_DIR)) {
-				if (file->entry->size_str[0] == '\0') {
-					BLI_filelist_entry_size_to_string(NULL, file->entry->size, file->entry->size_str);
+				if ((file->entry->size_str[0] == '\0') || update_stat_strings) {
+					BLI_filelist_entry_size_to_string(NULL, file->entry->size, small_size, file->entry->size_str);
 				}
-				file_draw_string(sx, sy, file->entry->size_str, layout->column_widths[COLUMN_SIZE], layout->tile_h, align);
+				file_draw_string(
+				            sx, sy, file->entry->size_str, layout->column_widths[COLUMN_SIZE], layout->tile_h, align);
 				sx += (int)layout->column_widths[COLUMN_SIZE] + column_space;
 			}
 		}
 		else if (params->display == FILE_LONGDISPLAY) {
 			sx += (int)layout->column_widths[COLUMN_NAME] + column_space;
 
-			if (file->entry->date_str[0] == '\0') {
-				BLI_filelist_entry_datetime_to_string(NULL, file->entry->time, file->entry->time_str, file->entry->date_str);
+			if ((file->entry->date_str[0] == '\0') || update_stat_strings) {
+				BLI_filelist_entry_datetime_to_string(
+				            NULL, file->entry->time, small_size, file->entry->time_str, file->entry->date_str);
 			}
 			file_draw_string(sx, sy, file->entry->date_str, layout->column_widths[COLUMN_DATE], layout->tile_h, align);
 			sx += (int)layout->column_widths[COLUMN_DATE] + column_space;
@@ -618,10 +624,11 @@ void file_draw_list(const bContext *C, ARegion *ar)
 			sx += (int)layout->column_widths[COLUMN_TIME] + column_space;
 
 			if (!(file->typeflag & FILE_TYPE_DIR)) {
-				if (file->entry->size_str[0] == '\0') {
-					BLI_filelist_entry_size_to_string(NULL, file->entry->size, file->entry->size_str);
+				if ((file->entry->size_str[0] == '\0') || update_stat_strings) {
+					BLI_filelist_entry_size_to_string(NULL, file->entry->size, small_size, file->entry->size_str);
 				}
-				file_draw_string(sx, sy, file->entry->size_str, layout->column_widths[COLUMN_SIZE], layout->tile_h, align);
+				file_draw_string(
+				            sx, sy, file->entry->size_str, layout->column_widths[COLUMN_SIZE], layout->tile_h, align);
 				sx += (int)layout->column_widths[COLUMN_SIZE] + column_space;
 			}
 		}
@@ -630,4 +637,5 @@ void file_draw_list(const bContext *C, ARegion *ar)
 	UI_block_end(C, block);
 	UI_block_draw(C, block);
 
+	layout->curr_size = params->thumbnail_size;
 }
diff --git a/source/blender/editors/space_file/file_intern.h b/source/blender/editors/space_file/file_intern.h
index f1fd4e2..f6f82cd 100644
--- a/source/blender/editors/space_file/file_intern.h
+++ b/source/blender/editors/space_file/file_intern.h
@@ -48,6 +48,8 @@ struct ARegion *file_tools_region(struct ScrArea *sa);
 #define IMASEL_BUTTONS_HEIGHT (UI_UNIT_Y * 2)
 #define IMASEL_BUTTONS_MARGIN (UI_UNIT_Y / 6)
 
+#define SMALL_SIZE_CHECK(_size) ((_size) < 64)  /* Related to FileSelectParams.thumbnail_size. */
+
 void file_draw_buttons(const bContext *C, ARegion *ar);
 void file_calc_previews(const bContext *C, ARegion *ar);
 void file_draw_list(const bContext *C, ARegion *ar);
diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c
index a2bf5bc..f03ae4c 100644
--- a/source/blender/editors/space_file/filesel.c
+++ b/source/blender/editors/space_file/filesel.c
@@ -485,6 +485,7 @@ float file_font_pointsize(void)
 static void column_widths(FileSelectParams *params, struct FileLayout *layout)
 {
 	int i;
+	const bool small_size = SMALL_SIZE_C

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list