File browser - change thumbnails size with a slider
authorBastien Montagne <montagne29@wanadoo.fr>
Wed, 29 Apr 2015 19:25:34 +0000 (21:25 +0200)
committerBastien Montagne <montagne29@wanadoo.fr>
Wed, 29 Apr 2015 19:30:33 +0000 (21:30 +0200)
We can now scale from 32px up to 256px (default has been upgraded to 128px).
Thumbnails are now generated as 'large', i.e. 256px.

Previews are scaled up if necessary, unlike icons (for folders or files without preview images).

Note that .blend thumbnails themselves remain in 128px for now (they are embeded in .blend files,
not quite sure we want to make them four times bigger...).

Patch by DMS (Yaron Dames), with final edits by myself.

Reviewers: mont29

Subscribers: Severin, mont29

Differential Revision: https://developer.blender.org/D1260

release/scripts/startup/bl_ui/space_filebrowser.py
source/blender/blenloader/intern/versioning_270.c
source/blender/editors/space_file/file_draw.c
source/blender/editors/space_file/filelist.c
source/blender/editors/space_file/filesel.c
source/blender/imbuf/intern/thumbs.c
source/blender/makesdna/DNA_space_types.h
source/blender/makesrna/intern/rna_space.c

index 8acf8cfaef334d055f1f835c7a7a013a37411418..5da660fcb5fad9aba393073f89a03db129607a17 100644 (file)
@@ -53,6 +53,10 @@ class FILEBROWSER_HT_header(Header):
         # can be None when save/reload with a file selector open
         if params:
             layout.prop(params, "display_type", expand=True, text="")
+
+            if params.display_type == 'FILE_IMGDISPLAY':
+                layout.prop(params, "thumbnails_size")
+
             layout.prop(params, "sort_method", expand=True, text="")
 
             layout.prop(params, "show_hidden", text="", icon='FILE_HIDDEN')
index c8862870b92dd6393977a081a6e0828d5d24880c..2343ba06e75cfc4cb610f76e16469d134fdf4bc4 100644 (file)
@@ -799,4 +799,28 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
                        }
                }
        }
+
+       if (!MAIN_VERSION_ATLEAST(main, 274, 6)) {
+               bScreen *screen;
+
+               if (!DNA_struct_elem_find(fd->filesdna, "FileSelectParams", "int", "thumbnails_size")) {
+                       for (screen = main->screen.first; screen; screen = screen->id.next) {
+                               ScrArea *sa;
+
+                               for (sa = screen->areabase.first; sa; sa = sa->next) {
+                                       SpaceLink *sl;
+
+                                       for (sl = sa->spacedata.first; sl; sl = sl->next) {
+                                               if (sl->spacetype == SPACE_FILE) {
+                                                       SpaceFile *sfile = (SpaceFile *)sl;
+
+                                                       if (sfile->params) {
+                                                               sfile->params->thumbnails_size = 128;
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
 }
index 9763efbc7b55945bfc0c5701bae57e9b089ea9b6..d5b9c169192670cee4eb0943923037dc6bed783b 100644 (file)
@@ -329,6 +329,7 @@ static void file_draw_preview(uiBlock *block, struct direntry *file, int sx, int
        float fx, fy;
        float dx, dy;
        int xco, yco;
+       float ui_imbx, ui_imby;
        float scaledx, scaledy;
        float scale;
        int ex, ey;
@@ -336,23 +337,26 @@ static void file_draw_preview(uiBlock *block, struct direntry *file, int sx, int
 
        BLI_assert(imb != NULL);
 
-       if ((imb->x * UI_DPI_FAC > layout->prv_w) ||
-           (imb->y * UI_DPI_FAC > layout->prv_h))
+       ui_imbx = imb->x * UI_DPI_FAC;
+       ui_imby = imb->y * UI_DPI_FAC;
+       /* Unlike thumbnails, icons are not scaled up. */
+       if (((ui_imbx > layout->prv_w) || (ui_imby > layout->prv_h)) ||
+           (!is_icon && ((ui_imbx < layout->prv_w) || (ui_imby < layout->prv_h))))
        {
                if (imb->x > imb->y) {
                        scaledx = (float)layout->prv_w;
-                       scaledy =  ( (float)imb->y / (float)imb->x) * layout->prv_w;
+                       scaledy = ((float)imb->y / (float)imb->x) * layout->prv_w;
                        scale = scaledx / imb->x;
                }
                else {
                        scaledy = (float)layout->prv_h;
-                       scaledx =  ( (float)imb->x / (float)imb->y) * layout->prv_h;
+                       scaledx = ((float)imb->x / (float)imb->y) * layout->prv_h;
                        scale = scaledy / imb->y;
                }
        }
        else {
-               scaledx = (float)imb->x * UI_DPI_FAC;
-               scaledy = (float)imb->y * UI_DPI_FAC;
+               scaledx = ui_imbx;
+               scaledy = ui_imby;
                scale = UI_DPI_FAC;
        }
 
index 87e6183f4f8e1426217efeeb27bca3b0901ed29e..2853ee9c053f00751149892cf028e94908d64ab7 100644 (file)
@@ -1349,7 +1349,7 @@ static void thumbnails_startjob(void *tjv, short *stop, short *do_update, float
                else if (limg->flags & FILE_TYPE_FTFONT) {
                        source = THB_SOURCE_FONT;
                }
-               limg->img = IMB_thumb_manage(limg->path, THB_NORMAL, source);
+               limg->img = IMB_thumb_manage(limg->path, THB_LARGE, source);
                *do_update = true;
                PIL_sleep_ms(10);
                limg = limg->next;
index 6858f536e92c16868e145b5767fcecf6a7b2079c..d89e55cb55fb293a03d08ef199ccadb7ecd1d98a 100644 (file)
@@ -102,6 +102,8 @@ short ED_fileselect_set_params(SpaceFile *sfile)
                /* set path to most recently opened .blend */
                BLI_split_dirfile(G.main->name, sfile->params->dir, sfile->params->file, sizeof(sfile->params->dir), sizeof(sfile->params->file));
                sfile->params->filter_glob[0] = '\0';
+               /* set the default thumbnails size */
+               sfile->params->thumbnails_size = 128;
        }
 
        params = sfile->params;
@@ -527,8 +529,8 @@ void ED_fileselect_init_layout(struct SpaceFile *sfile, ARegion *ar)
        layout->textheight = textheight;
 
        if (params->display == FILE_IMGDISPLAY) {
-               layout->prv_w = 4.8f * UI_UNIT_X;
-               layout->prv_h = 4.8f * UI_UNIT_Y;
+               layout->prv_w = ((float)params->thumbnails_size / 20.0f) * UI_UNIT_X;
+               layout->prv_h = ((float)params->thumbnails_size / 20.0f) * UI_UNIT_Y;
                layout->tile_border_x = 0.3f * UI_UNIT_X;
                layout->tile_border_y = 0.3f * UI_UNIT_X;
                layout->prv_border_x = 0.3f * UI_UNIT_X;
index 2318553eecc66c91e7b925273b3983f37628dec3..a608aa0db34fd11fa77fe61ad0cd9acfd6b42931 100644 (file)
@@ -283,9 +283,14 @@ static bool thumbpath_from_uri(const char *uri, char *path, const int path_len,
 void IMB_thumb_makedirs(void)
 {
        char tpath[FILE_MAX];
+#if 0  /* UNUSED */
        if (get_thumb_dir(tpath, THB_NORMAL)) {
                BLI_dir_create_recursive(tpath);
        }
+#endif
+       if (get_thumb_dir(tpath, THB_LARGE)) {
+               BLI_dir_create_recursive(tpath);
+       }
        if (get_thumb_dir(tpath, THB_FAIL)) {
                BLI_dir_create_recursive(tpath);
        }
index 09651bdbf3ae46370f82d7c523491234c6c102ab..7812103537172189eba4a96cc99e53bc5684807c 100644 (file)
@@ -590,6 +590,7 @@ typedef struct FileSelectParams {
        int active_file;
        int sel_first;
        int sel_last;
+       int thumbnails_size;
 
        /* short */
        short type; /* XXXXX for now store type here, should be moved to the operator */
index fd03840b145440c93d805fa42eac926cffb61d1b..eade210f90d3b224b4559f250c204dfc0b76061b 100644 (file)
@@ -3788,6 +3788,12 @@ static void rna_def_fileselect_params(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Name Filter", "Filter by name, supports '*' wildcard");
        RNA_def_property_flag(prop, PROP_TEXTEDIT_UPDATE);
        RNA_def_property_update(prop, NC_SPACE | ND_SPACE_FILE_LIST, NULL);
+
+       prop = RNA_def_property(srna, "thumbnails_size", PROP_INT, PROP_PIXEL);
+       RNA_def_property_int_sdna(prop, NULL, "thumbnails_size");
+       RNA_def_property_range(prop, 32, 256);
+       RNA_def_property_ui_text(prop, "Thumbnails Size", "Change the size of the thumbnails");
+       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_FILE_LIST, NULL);
 }
 
 static void rna_def_filemenu_entry(BlenderRNA *brna)