[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [32891] trunk/blender/source/blender/ editors/space_file: == filebrowser ==

Andrea Weikert elubie at gmx.net
Sat Nov 6 18:03:11 CET 2010


Revision: 32891
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=32891
Author:   elubie
Date:     2010-11-06 18:03:11 +0100 (Sat, 06 Nov 2010)

Log Message:
-----------
== filebrowser ==
Center Text underneath the icons in thumbnail view. (Small request from Sergey)

Modified Paths:
--------------
    trunk/blender/source/blender/editors/space_file/file_draw.c
    trunk/blender/source/blender/editors/space_file/file_intern.h
    trunk/blender/source/blender/editors/space_file/filesel.c

Modified: trunk/blender/source/blender/editors/space_file/file_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_file/file_draw.c	2010-11-06 16:17:49 UTC (rev 32890)
+++ trunk/blender/source/blender/editors/space_file/file_draw.c	2010-11-06 17:03:11 UTC (rev 32891)
@@ -240,57 +240,7 @@
 	uiRoundBox(sx, sy - height, sx + width, sy, 5);
 }
 
-#define FILE_SHORTEN_END				0
-#define FILE_SHORTEN_FRONT				1
 
-static float shorten_string(char* string, float w, int flag)
-{	
-	char temp[FILE_MAX];
-	short shortened = 0;
-	float sw = 0;
-	float pad = 0;
-
-	if (w <= 0) {
-		*string = '\0';
-		return 0.0;
-	}
-
-	sw = file_string_width(string);
-	if (flag == FILE_SHORTEN_FRONT) {
-		char *s = string;
-		BLI_strncpy(temp, "...", 4);
-		pad = file_string_width(temp);
-		while ((*s) && (sw+pad>w)) {
-			s++;
-			sw = file_string_width(s);
-			shortened = 1;
-		}
-		if (shortened) {
-			int slen = strlen(s);			
-			BLI_strncpy(temp+3, s, slen+1);
-			temp[slen+4] = '\0';
-			BLI_strncpy(string, temp, slen+4);
-		}
-	} else {
-		char *s = string;
-		while (sw>w) {
-			int slen = strlen(string);
-			string[slen-1] = '\0';
-			sw = file_string_width(s);
-			shortened = 1;
-		}
-
-		if (shortened) {
-			int slen = strlen(string);
-			if (slen > 3) {
-				BLI_strncpy(string+slen-3, "...", 4);				
-			}
-		}
-	}
-	
-	return sw;
-}
-
 static int get_file_icon(struct direntry *file)
 {
 	if (file->type & S_IFDIR) {
@@ -350,7 +300,7 @@
 
 
 	BLI_strncpy(fname,string, FILE_MAXFILE);
-	sw = shorten_string(fname, width, flag );
+	sw = file_shorten_string(fname, width, flag );
 
 	soffs = (width - sw) / 2;
 	x = (float)(sx);
@@ -548,9 +498,16 @@
 		
 		UI_ThemeColor4(TH_TEXT);
 
-		spos = ( FILE_IMGDISPLAY == params->display ) ? sx : sx + ICON_DEFAULT_WIDTH + 4;
+		
+		
+		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;
+		}	
 
-		sw = file_string_width(file->relname);
 		if (file->flags & EDITING) {
 			int but_width = (FILE_IMGDISPLAY == params->display) ? layout->tile_w : layout->column_widths[COLUMN_NAME];
 
@@ -591,15 +548,15 @@
 
 		UI_ThemeColor4(TH_TEXT);
 		if (!(file->flags & EDITING))  {
-			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);
+			// float name_width = (FILE_IMGDISPLAY == params->display) ? layout->tile_w : sw;
+			file_draw_string(spos, sy, file->relname, sw, layout->tile_h, 0);
 		}
 
 		if (params->display == FILE_SHORTDISPLAY) {
 			spos += 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, FILE_SHORTEN_END);	
+				file_draw_string(spos, sy, file->size, sw+1, layout->tile_h, 0);	
 				spos += layout->column_widths[COLUMN_SIZE] + 12;
 			}
 		} else if (params->display == FILE_LONGDISPLAY) {
@@ -608,33 +565,33 @@
 #ifndef WIN32
 			/* rwx rwx rwx */
 			sw = file_string_width(file->mode1);
-			file_draw_string(spos, sy, file->mode1, sw, layout->tile_h, FILE_SHORTEN_END); 
+			file_draw_string(spos, sy, file->mode1, sw, layout->tile_h, 0); 
 			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);
+			file_draw_string(spos, sy, file->mode2, sw, layout->tile_h, 0);
 			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);
+			file_draw_string(spos, sy, file->mode3, sw, layout->tile_h, 0);
 			spos += layout->column_widths[COLUMN_MODE3] + 12;
 
 			sw = file_string_width(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, 0);
 			spos += layout->column_widths[COLUMN_OWNER] + 12;
 #endif
 
 			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, 0);
 			spos += layout->column_widths[COLUMN_DATE] + 12;
 
 			sw = file_string_width(file->time);
-			file_draw_string(spos, sy, file->time, sw, layout->tile_h, FILE_SHORTEN_END); 
+			file_draw_string(spos, sy, file->time, sw, layout->tile_h, 0); 
 			spos += 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, FILE_SHORTEN_END);
+				file_draw_string(spos, sy, file->size, sw, layout->tile_h, 0);
 				spos += layout->column_widths[COLUMN_SIZE] + 12;
 			}
 		}

Modified: trunk/blender/source/blender/editors/space_file/file_intern.h
===================================================================
--- trunk/blender/source/blender/editors/space_file/file_intern.h	2010-11-06 16:17:49 UTC (rev 32890)
+++ trunk/blender/source/blender/editors/space_file/file_intern.h	2010-11-06 17:03:11 UTC (rev 32891)
@@ -93,7 +93,10 @@
 
 
 /* filesel.c */
+float file_shorten_string(char* string, float w, int flag);
 float file_string_width(const char* str);
+float file_string_width_shortened(const char* str, float width);
+
 float file_font_pointsize();
 void file_change_dir(bContext *C, int checkdir);
 int file_select_match(struct SpaceFile *sfile, const char *pattern);

Modified: trunk/blender/source/blender/editors/space_file/filesel.c
===================================================================
--- trunk/blender/source/blender/editors/space_file/filesel.c	2010-11-06 16:17:49 UTC (rev 32890)
+++ trunk/blender/source/blender/editors/space_file/filesel.c	2010-11-06 17:03:11 UTC (rev 32891)
@@ -283,6 +283,57 @@
 	}
 }
 
+/* Shorten a string to a given width w. 
+   If front is set, shorten from the front,
+   otherwise shorten from the end. */
+float file_shorten_string(char* string, float w, int front)
+{	
+	char temp[FILE_MAX];
+	short shortened = 0;
+	float sw = 0;
+	float pad = 0;
+
+	if (w <= 0) {
+		*string = '\0';
+		return 0.0;
+	}
+
+	sw = file_string_width(string);
+	if (front == 1) {
+		char *s = string;
+		BLI_strncpy(temp, "...", 4);
+		pad = file_string_width(temp);
+		while ((*s) && (sw+pad>w)) {
+			s++;
+			sw = file_string_width(s);
+			shortened = 1;
+		}
+		if (shortened) {
+			int slen = strlen(s);			
+			BLI_strncpy(temp+3, s, slen+1);
+			temp[slen+4] = '\0';
+			BLI_strncpy(string, temp, slen+4);
+		}
+	} else {
+		char *s = string;
+		while (sw>w) {
+			int slen = strlen(string);
+			string[slen-1] = '\0';
+			sw = file_string_width(s);
+			shortened = 1;
+		}
+
+		if (shortened) {
+			int slen = strlen(string);
+			if (slen > 3) {
+				BLI_strncpy(string+slen-3, "...", 4);				
+			}
+		}
+	}
+	
+	return sw;
+}
+
 float file_string_width(const char* str)
 {
 	uiStyle *style= U.uistyles.first;
@@ -290,6 +341,16 @@
 	return BLF_width(style->widget.uifont_id, (char *)str);
 }
 
+/* gives the exact width of the string after being shortened to
+   the maximum width. Assumes shortening from the end of the string. */
+float file_string_width_shortened(const char* str, float width)
+{
+	char fname[FILE_MAXFILE];
+
+	BLI_strncpy(fname, str, FILE_MAXFILE);
+	return file_shorten_string(fname, width, 0 );
+}
+
 float file_font_pointsize()
 {
 	float s;





More information about the Bf-blender-cvs mailing list