Commit: 52ec96251692a5e5a8f452eecb9e52e9ee7465c8
Author: Julian Eisel
Date:   Thu Dec 1 16:43:57 2016 +0100
Branches: blender2.8
https://developer.blender.org/rB52ec96251692a5e5a8f452eecb9e52e9ee7465c8

UI: Previews for screen layouts

Basically all this does is drawing layout previews into the opened layout 
search menu.
https://youtu.be/RHYWtZP7pyA

The previews are drawn using offscreen rendering so they can't use 
multi-threading (yet!). But that shouldn't be an issue since only a handful of 
previews are drawn at the same time. Normally we only need to redraw the 
preview if a screen layout was changed. Would be nice if PreviewImage could 
store if it supports threaded rendering.
Previews are saved in files, might be useful if you later want to support 
appending layouts.
Adds a new file screen_draw.c.

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

M       release/scripts/startup/bl_ui/space_info.py
M       source/blender/blenkernel/intern/icons.c
M       source/blender/blenkernel/intern/screen.c
M       source/blender/blenloader/intern/readfile.c
M       source/blender/blenloader/intern/writefile.c
M       source/blender/editors/include/ED_screen.h
M       source/blender/editors/interface/interface_icons.c
M       source/blender/editors/interface/interface_regions.c
M       source/blender/editors/interface/interface_templates.c
M       source/blender/editors/render/render_preview.c
M       source/blender/editors/screen/CMakeLists.txt
A       source/blender/editors/screen/screen_draw.c
M       source/blender/editors/screen/screen_edit.c
M       source/blender/editors/screen/screen_ops.c
M       source/blender/makesdna/DNA_screen_types.h
M       source/blender/windowmanager/intern/wm_window.c

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

diff --git a/release/scripts/startup/bl_ui/space_info.py 
b/release/scripts/startup/bl_ui/space_info.py
index 780dc4c..d77113e 100644
--- a/release/scripts/startup/bl_ui/space_info.py
+++ b/release/scripts/startup/bl_ui/space_info.py
@@ -40,7 +40,7 @@ class INFO_HT_header(Header):
             layout.operator("screen.back_to_previous", icon='SCREEN_BACK', 
text="Back to Previous")
             layout.separator()
         else:
-            layout.template_ID(context.window, "screen", new="screen.new", 
unlink="screen.delete")
+            layout.template_ID_preview(context.window, "screen", 
new="screen.new", unlink="screen.delete", rows=2, cols=6)
             layout.template_ID(context.screen, "scene", new="scene.new", 
unlink="scene.delete")
 
         layout.separator()
diff --git a/source/blender/blenkernel/intern/icons.c 
b/source/blender/blenkernel/intern/icons.c
index 7669c4b..70cf0d5 100644
--- a/source/blender/blenkernel/intern/icons.c
+++ b/source/blender/blenkernel/intern/icons.c
@@ -42,6 +42,7 @@
 #include "DNA_material_types.h"
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
 #include "DNA_texture_types.h"
 #include "DNA_world_types.h"
 #include "DNA_brush_types.h"
@@ -252,6 +253,7 @@ PreviewImage **BKE_previewimg_id_get_p(ID *id)
                ID_PRV_CASE(ID_OB, Object);
                ID_PRV_CASE(ID_GR, Group);
                ID_PRV_CASE(ID_SCE, Scene);
+               ID_PRV_CASE(ID_SCR, bScreen);
 #undef ID_PRV_CASE
        }
 
diff --git a/source/blender/blenkernel/intern/screen.c 
b/source/blender/blenkernel/intern/screen.c
index 1482056..c5d00d6 100644
--- a/source/blender/blenkernel/intern/screen.c
+++ b/source/blender/blenkernel/intern/screen.c
@@ -50,6 +50,7 @@
 #include "BLI_utildefines.h"
 #include "BLI_rect.h"
 
+#include "BKE_icons.h"
 #include "BKE_idprop.h"
 #include "BKE_screen.h"
 
@@ -394,6 +395,8 @@ void BKE_screen_free(bScreen *sc)
        BLI_freelistN(&sc->vertbase);
        BLI_freelistN(&sc->edgebase);
        BLI_freelistN(&sc->areabase);
+
+       BKE_previewimg_free(&sc->preview);
 }
 
 /* for depsgraph */
diff --git a/source/blender/blenloader/intern/readfile.c 
b/source/blender/blenloader/intern/readfile.c
index cca9338..605ccd3 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -6567,6 +6567,8 @@ static bool direct_link_screen(FileData *fd, bScreen *sc)
        sc->mainwin = sc->subwinactive= 0;      /* indices */
        sc->swap = 0;
 
+       sc->preview = direct_link_preview_image(fd, sc->preview);
+
        /* edges */
        for (se = sc->edgebase.first; se; se = se->next) {
                se->v1 = newdataadr(fd, se->v1);
diff --git a/source/blender/blenloader/intern/writefile.c 
b/source/blender/blenloader/intern/writefile.c
index d8097f1..169ca10 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -2781,6 +2781,8 @@ static void write_screens(WriteData *wd, ListBase 
*scrbase)
                writestruct(wd, ID_SCRN, bScreen, 1, sc);
                write_iddata(wd, &sc->id);
 
+               write_previews(wd, sc->preview);
+
                /* direct data */
                for (sv = sc->vertbase.first; sv; sv = sv->next) {
                        writestruct(wd, DATA, ScrVert, 1, sv);
diff --git a/source/blender/editors/include/ED_screen.h 
b/source/blender/editors/include/ED_screen.h
index ec09add..f5f66a0 100644
--- a/source/blender/editors/include/ED_screen.h
+++ b/source/blender/editors/include/ED_screen.h
@@ -36,6 +36,8 @@
 #include "DNA_view2d_types.h"
 #include "DNA_view3d_types.h"
 
+#include "BLI_compiler_attrs.h"
+
 struct wmWindowManager;
 struct wmWindow;
 struct wmNotifier;
@@ -47,6 +49,7 @@ struct bScreen;
 struct ARegion;
 struct uiBlock;
 struct rcti;
+struct Main;
 
 /* regions */
 void    ED_region_do_listen(struct bScreen *sc, struct ScrArea *sa, struct 
ARegion *ar, struct wmNotifier *note);
@@ -118,6 +121,7 @@ void    ED_screen_full_restore(struct bContext *C, ScrArea 
*sa);
 struct ScrArea *ED_screen_state_toggle(struct bContext *C, struct wmWindow 
*win, struct ScrArea *sa, const short state);
 void    ED_screens_header_tools_menu_create(struct bContext *C, struct 
uiLayout *layout, void *arg);
 bool    ED_screen_stereo3d_required(struct bScreen *screen);
+void    ED_screen_preview_render(const struct bScreen *screen, int size_x, int 
size_y, unsigned int *r_rect) ATTR_NONNULL();
 
 /* anim */
 void    ED_update_for_newframe(struct Main *bmain, struct Scene *scene, int 
mute);
diff --git a/source/blender/editors/interface/interface_icons.c 
b/source/blender/editors/interface/interface_icons.c
index c0360d9..3d22a26 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.c
@@ -851,12 +851,15 @@ void ui_icon_ensure_deferred(const bContext *C, const int 
icon_id, const bool bi
                                {
                                        ID *id = (icon->type != 0) ? icon->obj 
: NULL;
                                        PreviewImage *prv = id ? 
BKE_previewimg_id_ensure(id) : icon->obj;
+                                       /* Using jobs for screen previews 
crashes due to offscreen rendering.
+                                        * XXX would be nicer if PreviewImage 
could store if it supports jobs */
+                                       const bool use_jobs = !id || 
(GS(id->name) != ID_SCR);
 
                                        if (prv) {
                                                const int size = big ? 
ICON_SIZE_PREVIEW : ICON_SIZE_ICON;
 
                                                if (id || (prv->tag & 
PRV_TAG_DEFFERED) != 0) {
-                                                       
ui_id_preview_image_render_size(C, NULL, id, prv, size, true);
+                                                       
ui_id_preview_image_render_size(C, NULL, id, prv, size, use_jobs);
                                                }
                                        }
                                        break;
@@ -1169,7 +1172,7 @@ void UI_id_icon_render(const bContext *C, Scene *scene, 
ID *id, const bool big,
        }
 }
 
-static void ui_id_brush_render(const bContext *C, ID *id)
+static void ui_id_icon_render(const bContext *C, ID *id, bool use_jobs)
 {
        PreviewImage *pi = BKE_previewimg_id_ensure(id);
        enum eIconSizes i;
@@ -1181,7 +1184,7 @@ static void ui_id_brush_render(const bContext *C, ID *id)
                /* check if rect needs to be created; changed
                 * only set by dynamic icons */
                if (((pi->flag[i] & PRV_CHANGED) || !pi->rect[i])) {
-                       icon_set_image(C, NULL, id, pi, i, true);
+                       icon_set_image(C, NULL, id, pi, i, use_jobs);
                        pi->flag[i] &= ~PRV_CHANGED;
                }
        }
@@ -1194,7 +1197,7 @@ static int ui_id_brush_get_icon(const bContext *C, ID *id)
 
        if (br->flag & BRUSH_CUSTOM_ICON) {
                BKE_icon_id_ensure(id);
-               ui_id_brush_render(C, id);
+               ui_id_icon_render(C, id, true);
        }
        else {
                Object *ob = CTX_data_active_object(C);
@@ -1241,6 +1244,15 @@ static int ui_id_brush_get_icon(const bContext *C, ID 
*id)
        return id->icon_id;
 }
 
+static int ui_id_screen_get_icon(const bContext *C, ID *id)
+{
+       BKE_icon_id_ensure(id);
+       /* Don't use jobs here, offscreen rendering doesn't like this and 
crashes. */
+       ui_id_icon_render(C, id, false);
+
+       return id->icon_id;
+}
+
 int ui_id_icon_get(const bContext *C, ID *id, const bool big)
 {
        int iconid = 0;
@@ -1259,6 +1271,9 @@ int ui_id_icon_get(const bContext *C, ID *id, const bool 
big)
                        /* checks if not exists, or changed */
                        UI_id_icon_render(C, NULL, id, big, true);
                        break;
+               case ID_SCR:
+                       iconid = ui_id_screen_get_icon(C, id);
+                       break;
                default:
                        break;
        }
diff --git a/source/blender/editors/interface/interface_regions.c 
b/source/blender/editors/interface/interface_regions.c
index 4669782..62bab15 100644
--- a/source/blender/editors/interface/interface_regions.c
+++ b/source/blender/editors/interface/interface_regions.c
@@ -1059,7 +1059,7 @@ int ui_searchbox_autocomplete(bContext *C, ARegion *ar, 
uiBut *but, char *str)
        return match;
 }
 
-static void ui_searchbox_region_draw_cb(const bContext *UNUSED(C), ARegion *ar)
+static void ui_searchbox_region_draw_cb(const bContext *C, ARegion *ar)
 {
        uiSearchboxData *data = ar->regiondata;
        
@@ -1077,6 +1077,9 @@ static void ui_searchbox_region_draw_cb(const bContext 
*UNUSED(C), ARegion *ar)
                if (data->preview) {
                        /* draw items */
                        for (a = 0; a < data->items.totitem; a++) {
+                               /* ensure icon is up-to-date */
+                               ui_icon_ensure_deferred(C, 
data->items.icons[a], data->preview);
+
                                ui_searchbox_butrect(&rect, data, a);
                                
                                /* widget itself */
diff --git a/source/blender/editors/interface/interface_templates.c 
b/source/blender/editors/interface/interface_templates.c
index 80784e8..9527ddc 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -415,17 +415,30 @@ static void template_ID(
                type = idptr.type;
 
        if (flag & UI_ID_PREVIEWS) {
+               ARegion *region = CTX_wm_region(C);
+               const bool use_big_size = (region->regiontype != 
RGN_TYPE_HEADER); /* silly check, could be more generic */
+               /* Ugly exception for screens here, drawing their preview in 
icon size looks ugly/useless */
+               const bool use_preview_icon = use_big_size || (id && 
(GS(id->name) != ID_SCR));
+               const short width = UI_UNIT_X * (use_big_size ? 6 : 1.6f);
+               const short height = UI_UNIT_Y * (use_big_size ? 6: 1);
+
                template->preview = true;
 
-               but = uiDefBlockButN(block, id_search_menu, 
MEM_dupallocN(template), "", 0, 0, UI_UNIT_X * 6, UI_UNIT_Y * 6,
+               but = uiDefBlockButN(block, id_search_menu, 
MEM_dupallocN(template), "", 0, 0, width, height,
                                     TIP_(template_id_browse_tip(type)));
-               ui_def_but_icon(but, id ? ui_id_icon_get(C, id, true) : 
RNA_struct_ui_icon(type),
-                               UI_HAS_ICON | UI_BUT_ICON_PREVIEW);
+               if (use_preview_icon) {
+                       ui_def_but_icon(but, ui_id_icon_get(C, id, 
use_big_size), UI_HAS_ICON | UI_BUT_ICON_PREVIEW);
+               }
+               else {
+                       ui_def_but_icon(but, RNA_struct_ui_icon(type), 
UI_HAS_ICON);
+                       UI_but_drawflag_enable(but, UI_BUT_ICON_LEFT);
+               }
 
                if ((idfrom && idfrom->lib) || !editable)
                        UI_but_flag_enable(but, UI_BUT_DISABLED);
-               
-               uiLayoutRow(layout, true);
+               if (use_big_size) {
+                       uiLayoutRow(layout, true);
+               }
        }
        else if (flag & UI_ID_BROWSE) {
                but = uiDefBlockButN(block, id_search_menu, 
MEM_dupallocN(template), "", 0, 0, UI_UNIT_X * 1.6, UI_UNIT_Y,
diff --git a/source/blender/editors/render/render_preview.c 
b/source/blender/editors/render/render_preview.c
index 87c08dc..c48e142 100644
--- a/source/blender/editors/render/render_preview.c
+++ b/source/blender/editors/render/render_preview.c
@@ -94,6 +94,7 @@
 
 #include "ED_datafiles.h"
 #include "ED_render.h"
+#include "ED_screen.h"
 
 

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to