Merge branch 'master' into blender2.8
[blender.git] / source / blender / editors / interface / interface_templates.c
index 131584dd405d3f59697e45bfdaf402dcf2cb3804..e3a71feb1a9a4bb23471036dbeea0098fe1a5de9 100644 (file)
@@ -58,6 +58,8 @@
 #include "BKE_depsgraph.h"
 #include "BKE_global.h"
 #include "BKE_idcode.h"
+#include "BKE_idprop.h"
+#include "BKE_layer.h"
 #include "BKE_library.h"
 #include "BKE_linestyle.h"
 #include "BKE_main.h"
@@ -417,17 +419,31 @@ 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) {
+                       int icon = id ? ui_id_icon_get(C, id, use_big_size) : RNA_struct_ui_icon(type);
+                       ui_def_but_icon(but, icon, 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,
@@ -3720,6 +3736,7 @@ void uiTemplateKeymapItemProperties(uiLayout *layout, PointerRNA *ptr)
        if (propptr.data) {
                uiBut *but = uiLayoutGetBlock(layout)->buttons.last;
 
+               WM_operator_properties_sanitize(&propptr, false);
                template_keymap_item_properties(layout, NULL, &propptr);
 
                /* attach callbacks to compensate for missing properties update,
@@ -3736,6 +3753,60 @@ void uiTemplateKeymapItemProperties(uiLayout *layout, PointerRNA *ptr)
        }
 }
 
+/********************************* Overrides *************************************/
+
+void uiTemplateOverrideProperty(uiLayout *layout, struct PointerRNA *collection_props_ptr, struct PointerRNA *scene_props_ptr, const char *name, const char *custom_template)
+{
+       bool is_set = false;
+       uiLayout *row, *col;
+
+       PointerRNA *ptr;
+       PropertyRNA *prop;
+
+       IDProperty *collection_props = collection_props_ptr->data;
+
+       if (IDP_GetPropertyFromGroup(collection_props, name)) {
+               prop = RNA_struct_find_property(collection_props_ptr, name);
+               ptr = collection_props_ptr;
+               is_set = RNA_property_is_set(ptr, prop);
+       }
+       else {
+               /* property doesn't exist yet */
+               prop = RNA_struct_find_property(scene_props_ptr, name);
+               ptr = scene_props_ptr;
+       }
+
+       row = uiLayoutRow(layout, false);
+       col = uiLayoutColumn(row, false);
+
+       uiLayoutSetEnabled(col, is_set);
+
+       if (custom_template && STREQ(custom_template, "icon_view")) {
+               uiTemplateIconView(col, ptr, name, false, 5.0f);
+       }
+       else {
+               uiItemFullR(col, ptr, prop, -1, 0, 0, NULL, ICON_NONE);
+       }
+
+       col = uiLayoutColumn(row, false);
+       uiBut *but;
+       uiBlock *block = uiLayoutGetBlock(col);
+       UI_block_emboss_set(block, UI_EMBOSS_NONE);
+
+       if (is_set) {
+               but = uiDefIconButO(block, UI_BTYPE_BUT, "UI_OT_unuse_property_button", WM_OP_EXEC_DEFAULT, ICON_X, 0, 0, UI_UNIT_X, UI_UNIT_Y, NULL);
+       }
+       else {
+               but = uiDefIconButO(block, UI_BTYPE_BUT, "UI_OT_use_property_button", WM_OP_EXEC_DEFAULT, ICON_ZOOMIN, 0, 0, UI_UNIT_X, UI_UNIT_Y, NULL);
+               /* XXX - Using existing data struct to pass another RNAPointer */
+               but->rnasearchpoin = *scene_props_ptr;
+       }
+
+       but->rnapoin = *collection_props_ptr;
+       but->rnaprop = prop;
+       UI_block_emboss_set(block, UI_EMBOSS);
+}
+
 /********************************* Color management *************************************/
 
 void uiTemplateColorspaceSettings(uiLayout *layout, PointerRNA *ptr, const char *propname)