[Bf-blender-cvs] [6199ce8] asset-experiments: Reworked from scratch 'icon over previews' feature.
Bastien Montagne
noreply at git.blender.org
Sun Jan 25 15:33:57 CET 2015
Commit: 6199ce89a89c8199f51f921c0029443688d55d67
Author: Bastien Montagne
Date: Sun Jan 25 15:30:46 2015 +0100
Branches: asset-experiments
https://developer.blender.org/rB6199ce89a89c8199f51f921c0029443688d55d67
Reworked from scratch 'icon over previews' feature.
Previous implementation was horribly complicated in the end... sigh.
===================================================================
M source/blender/editors/include/UI_interface_icons.h
M source/blender/editors/interface/interface_icons.c
M source/blender/editors/space_file/file_draw.c
M source/blender/editors/space_file/filelist.c
M source/blender/editors/space_file/filelist.h
===================================================================
diff --git a/source/blender/editors/include/UI_interface_icons.h b/source/blender/editors/include/UI_interface_icons.h
index 6aa6f59..549ee99 100644
--- a/source/blender/editors/include/UI_interface_icons.h
+++ b/source/blender/editors/include/UI_interface_icons.h
@@ -85,7 +85,9 @@ int UI_iconfile_get_index(const char *filename);
struct PreviewImage *UI_icon_to_preview(int icon_id);
+#if 0
struct ImBuf *UI_icon_to_imbuf(int icon_id);
+#endif
int UI_rnaptr_icon_get(struct bContext *C, struct PointerRNA *ptr, int rnaicon, const bool big);
diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c
index 0f62aee..f1287c0 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.c
@@ -988,6 +988,7 @@ PreviewImage *UI_icon_to_preview(int icon_id)
return NULL;
}
+#if 0 /* Unused in the end, is it worth keeping it still?
/* Shall always return straight alpha! */
ImBuf *UI_icon_to_imbuf(int icon_id)
{
@@ -1051,6 +1052,7 @@ ImBuf *UI_icon_to_imbuf(int icon_id)
return imbuf;
}
+#endif
static void icon_draw_rect(float x, float y, int w, int h, float UNUSED(aspect), int rw, int rh,
unsigned int *rect, float alpha, const float rgb[3], const bool is_preview)
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c
index be4a7bd..465c84f 100644
--- a/source/blender/editors/space_file/file_draw.c
+++ b/source/blender/editors/space_file/file_draw.c
@@ -287,7 +287,7 @@ void file_calc_previews(const bContext *C, ARegion *ar)
}
static void file_draw_preview(uiBlock *block, struct FileList *files, const int index,
- int sx, int sy, ImBuf *imb, FileLayout *layout, bool dropshadow, bool drag)
+ int sx, int sy, ImBuf *imb, int icon, FileLayout *layout, bool dropshadow, bool drag)
{
if (imb) {
uiBut *but;
@@ -339,6 +339,10 @@ static void file_draw_preview(uiBlock *block, struct FileList *files, const int
glColor4f(1.0, 1.0, 1.0, 1.0);
glaDrawPixelsTexScaled((float)xco, (float)yco, imb->x, imb->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, imb->rect, scale, scale);
+ if (icon) {
+ UI_icon_draw((float)xco, (float)yco, icon);
+ }
+
/* border */
if (dropshadow) {
glColor4f(0.0f, 0.0f, 0.0f, 0.4f);
@@ -349,7 +353,7 @@ static void file_draw_preview(uiBlock *block, struct FileList *files, const int
if (drag) {
struct direntry *file = filelist_file(files, index);
but = uiDefBut(block, UI_BTYPE_LABEL, 0, "", xco, yco, ex, ey, NULL, 0.0, 0.0, 0, 0, "");
- UI_but_drag_set_image(but, file->path, filelist_geticon(files, index), imb, scale);
+ UI_but_drag_set_image(but, file->path, filelist_geticon(files, index, true), imb, scale);
}
glDisable(GL_BLEND);
@@ -511,17 +515,18 @@ void file_draw_list(const bContext *C, ARegion *ar)
do_drag = !(STREQ(file->relname, "..") || STREQ(file->relname, "."));
if (FILE_IMGDISPLAY == params->display) {
+ const int icon = filelist_geticon(files, i, false);
is_icon = 0;
imb = filelist_getimage(files, i);
if (!imb) {
imb = filelist_geticon_image(files, i);
is_icon = 1;
}
-
- file_draw_preview(block, files, i, sx, sy, imb, layout, !is_icon && (file->flags & FILE_TYPE_IMAGE), do_drag);
+
+ file_draw_preview(block, files, i, sx, sy, imb, icon, layout, !is_icon && (file->flags & FILE_TYPE_IMAGE), do_drag);
}
else {
- file_draw_icon(block, file->path, sx, sy - (UI_UNIT_Y / 6), filelist_geticon(files, i),
+ file_draw_icon(block, file->path, sx, sy - (UI_UNIT_Y / 6), filelist_geticon(files, i, true),
ICON_DEFAULT_WIDTH_SCALE, ICON_DEFAULT_HEIGHT_SCALE, do_drag);
sx += ICON_DEFAULT_WIDTH_SCALE + 0.2f * UI_UNIT_X;
}
diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index 1fcb66f..0f893ad 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -204,14 +204,10 @@ struct FileList;
typedef struct FileImage {
struct FileImage *next, *prev;
char path[FILE_MAX];
- char relname[FILE_MAX];
unsigned int flags;
- unsigned int type;
int index;
short done;
ImBuf *img;
- ImBuf *org_img;
- ImBuf *icon;
} FileImage;
typedef struct FileListFilter {
@@ -770,21 +766,27 @@ ImBuf *filelist_geticon_image(struct FileList *filelist, const int index)
return filelist_geticon_image_ex(file->type, file->flags, file->relname);
}
-static int filelist_geticon_ex(const unsigned int type, const unsigned int flags, const char *path, const char *relname, const bool ignore_libdir)
+static int filelist_geticon_ex(
+ const unsigned int type, const unsigned int flags, const char *path, const char *relname,
+ const bool is_main, const bool ignore_libdir)
{
if (type & S_IFDIR && !(ignore_libdir && (flags & (FILE_TYPE_BLENDERLIB | FILE_TYPE_BLENDER)))) {
if (strcmp(relname, "..") == 0) {
- return ICON_FILE_PARENT;
+ return is_main ? ICON_FILE_PARENT : ICON_NONE;
}
- if (flags & FILE_TYPE_APPLICATIONBUNDLE) {
+ else if (flags & FILE_TYPE_APPLICATIONBUNDLE) {
return ICON_UGLYPACKAGE;
}
- if (flags & FILE_TYPE_BLENDER) {
+ else if (flags & FILE_TYPE_BLENDER) {
return ICON_FILE_BLEND;
}
- return ICON_FILE_FOLDER;
+ else if (is_main) {
+ /* Do not return icon for folders if icons are not 'main' draw type (e.g. when used over previews). */
+ return ICON_FILE_FOLDER;
+ }
}
- else if (flags & FILE_TYPE_BLENDER)
+
+ if (flags & FILE_TYPE_BLENDER)
return ICON_FILE_BLEND;
else if (flags & FILE_TYPE_BLENDER_BACKUP)
return ICON_FILE_BACKUP;
@@ -869,14 +871,14 @@ static int filelist_geticon_ex(const unsigned int type, const unsigned int flags
}
}
}
- return ICON_FILE_BLANK;
+ return is_main ? ICON_FILE_BLANK : ICON_NONE;
}
-int filelist_geticon(struct FileList *filelist, const int index)
+int filelist_geticon(struct FileList *filelist, const int index, const bool is_main)
{
struct direntry *file = filelist_geticon_get_file(filelist, index);
- return filelist_geticon_ex(file->type, file->flags, file->path, file->relname, false);
+ return filelist_geticon_ex(file->type, file->flags, file->path, file->relname, is_main, false);
}
/* ********** Main ********** */
@@ -1925,9 +1927,6 @@ static void thumbnail_joblist_free(ThumbnailJob *tj)
if ((limg->img) && (!limg->done)) {
IMB_freeImBuf(limg->img);
}
- if (limg->icon) {
- IMB_freeImBuf(limg->icon);
- }
}
BLI_freelistN(&tj->loadimages);
}
@@ -1941,17 +1940,11 @@ static void thumbnails_startjob(void *tjv, short *stop, short *do_update, float
tj->do_update = do_update;
while ((*stop == 0) && (limg)) {
- ImBuf *img = limg->org_img;
if (limg->flags & FILE_TYPE_IMAGE) {
- img = IMB_thumb_manage(limg->path, THB_NORMAL, THB_SOURCE_IMAGE);
+ limg->img = IMB_thumb_manage(limg->path, THB_NORMAL, THB_SOURCE_IMAGE);
}
else if (limg->flags & (FILE_TYPE_BLENDER | FILE_TYPE_BLENDER_BACKUP)) {
- img = IMB_thumb_manage(limg->path, THB_NORMAL, THB_SOURCE_BLEND);
- }
- else if (limg->flags & FILE_TYPE_BLENDERLIB) {
- if (!img) {
- img = IMB_dupImBuf(filelist_geticon_image_ex(limg->type, limg->flags, limg->relname));
- }
+ limg->img = IMB_thumb_manage(limg->path, THB_NORMAL, THB_SOURCE_BLEND);
}
else if (limg->flags & FILE_TYPE_MOVIE) {
limg->img = IMB_thumb_manage(limg->path, THB_NORMAL, THB_SOURCE_MOVIE);
@@ -1961,36 +1954,6 @@ static void thumbnails_startjob(void *tjv, short *stop, short *do_update, float
limg->flags |= FILE_TYPE_MOVIE_ICON;
}
}
- if (img && limg->icon) {
- /* When we overlay an icon over an image, we want that image to be always the same size,
- * otherwise icon will be scaled up or down in UI, which is ugly! */
- if (!ELEM(PREVIEW_RENDER_DEFAULT_HEIGHT, img->x, img->y)) {
- unsigned int newx, newy;
-
- /* Only scale down... */
- if ((img->x > img->y) && (img->x > PREVIEW_RENDER_DEFAULT_HEIGHT)) {
- newx = (unsigned int)((float)img->y / (float)img->x * (float)PREVIEW_RENDER_DEFAULT_HEIGHT);
- newy = PREVIEW_RENDER_DEFAULT_HEIGHT;
- IMB_scaleImBuf(img, newx, newy);
- }
- else if ((img->y > img->x) && (img->y > PREVIEW_RENDER_DEFAULT_HEIGHT)) {
- newx = PREVIEW_RENDER_DEFAULT_HEIGHT;
- newy = (unsigned int)((float)img->x / (float)img->y * (float)PREVIEW_RENDER_DEFAULT_HEIGHT);
- IMB_scaleImBuf(img, newx, newy);
- }
- /* Else, center in new picture with the right dimension. */
- else {
- ImBuf *timg = IMB_allocImBuf(PREVIEW_RENDER_DEFAULT_HEIGHT, PREVIEW_RENDER_DEFAULT_HEIGHT, 4, IB_rect);
- IMB_rectcpy(timg, img, (timg->x - img->x) / 2, (timg->y - img->y) / 2, 0, 0, img->x, img->y);
- IMB_freeImBuf(img);
- img = timg;
- }
- }
- IMB_rectblend(img, img, limg->icon, NULL, NULL, NULL, 0.0f,
- img->x - limg->icon->x, img->y - limg->icon->y, 0, 0, 0, 0,
- limg->icon->x, limg->icon->y, IMB_BLEND_MIX, false);
- }
- limg->img = img;
*do_update = true;
PIL_sleep_ms(1);
limg = limg->next;
@@ -2050,40 +2013,14 @@ void thumbnails_start(FileList *filelist, const bContext *C)
if (!filelist->filelist[idx].path) {
continue;
}
- /* for blenlib items we overlay the ID type's icon... */
- if (!filelist->filelist[idx].image || (filelist->filelist[idx].flags & FILE_TYPE_BLENDERLIB)) {
- if ((filelist->filelist[idx].flags & (FILE_TYPE_IMAGE | FILE_TYPE_MOVIE | FILE_TYPE_BLENDER | FILE_TYPE_BLENDER_BACKUP | FILE_TYPE_BLENDERLIB))) {
+ if (!filelist->filelist[idx].image) {
+ if (filelist->filelist[idx].flags & (FILE_TYPE_IMAGE | FILE_TYPE_MOVIE |
+ FILE_TYPE_BLENDER | FILE_TYPE_BLENDER_BACKUP))
+ {
FileImage *limg = MEM_callocN(sizeof(FileImage), "loadimage");
BLI_strncpy(limg->path, filelist->filelist[idx].path, sizeof(limg->path));
- BLI_strncpy(limg->relname, filelist->filelist[idx].relname, sizeof(limg->relname));
- if (filelist->filelist[idx].image) {
- limg->org_img = IMB_dupImBuf(filelist->filelist[idx
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list