Commit: 33060f829a0318957ee3d47e2e5fb1b9e7b50a07
Author: Lukas Tönne
Date:   Tue Mar 3 12:01:27 2015 +0100
Branches: alembic_pointcache
https://developer.blender.org/rB33060f829a0318957ee3d47e2e5fb1b9e7b50a07

Use a uiTemplate function for showing cache library items instead of
python code to unify symbols.

This is necessary because the operator for adding new items (as opposed
to the enable/disable button) cannot be shown with the same checkbox
button. The UI template function can display a custom button for the
operator, so the look becomes less confusing.

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

M       release/scripts/startup/bl_ui/properties_scene.py
M       source/blender/editors/include/UI_interface.h
M       source/blender/editors/interface/interface_templates.c
M       source/blender/makesrna/RNA_access.h
M       source/blender/makesrna/intern/rna_ui_api.c
M       source/blenderplayer/bad_level_call_stubs/stubs.c

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

diff --git a/release/scripts/startup/bl_ui/properties_scene.py 
b/release/scripts/startup/bl_ui/properties_scene.py
index b2053dd..2dbf144 100644
--- a/release/scripts/startup/bl_ui/properties_scene.py
+++ b/release/scripts/startup/bl_ui/properties_scene.py
@@ -475,33 +475,6 @@ class SCENE_PT_cache_manager(SceneButtonsPanel, Panel):
     def poll(cls, context):
         return True
 
-    def draw_cache_item_button(self, context, layout, item, ob, type, 
index=-1):
-        if not item:
-            sub = layout.row()
-            sub.context_pointer_set("cache_object", ob)
-            props = sub.operator("cachelibrary.item_enable", text="", 
icon='ZOOMIN', emboss=True)
-            props.type = type
-            props.index = index
-        else:
-            layout.prop(item, "enabled", text="")
-
-    def draw_cache_item(self, context, layout, cachelib, ob, item, type, 
index=-1, enabled=True):
-        from bpy.types import CacheItem
-
-        buttons = layout.row()
-        buttons.enabled = enabled
-
-        self.draw_cache_item_button(context, buttons, item, ob, type, index)
-        
-        sub = buttons.column()
-        sub.enabled = bool(item and item.enabled)
-        name = item.name if item else CacheItem.get_name(ob, type, index)
-
-        row = sub.row()
-        row.label(text=name, icon=self.item_type_icon[type])
-
-        return sub
-
     def draw_cachelib(self, context, layout, cachelib):
         # imitate template_ID without an actual pointer property
         row = layout.row(align=True)
@@ -545,7 +518,7 @@ class SCENE_PT_cache_manager(SceneButtonsPanel, Panel):
                 if indent:
                     row.label("  " * indent)
 
-                sub = self.draw_cache_item(context, row, cachelib, ob, item, 
item_type, item_index, enable)
+                row.template_cache_library_item(cachelib, ob, item_type, 
item_index, enable)
 
 
     def draw(self, context):
diff --git a/source/blender/editors/include/UI_interface.h 
b/source/blender/editors/include/UI_interface.h
index b1bb48b..527fa12 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -75,6 +75,7 @@ struct ImBuf;
 struct bNodeTree;
 struct bNode;
 struct bNodeSocket;
+struct CacheLibrary;
 struct wmDropBox;
 struct wmDrag;
 struct wmEvent;
@@ -907,6 +908,8 @@ void uiTemplateReportsBanner(uiLayout *layout, struct 
bContext *C);
 void uiTemplateKeymapItemProperties(uiLayout *layout, struct PointerRNA *ptr);
 void uiTemplateComponentMenu(uiLayout *layout, struct PointerRNA *ptr, const 
char *propname, const char *name);
 void uiTemplateNodeSocket(uiLayout *layout, struct bContext *C, float *color);
+uiLayout *uiTemplateCacheLibraryItem(uiLayout *layout, struct bContext *C, 
struct CacheLibrary *cachelib,
+                                     struct Object *ob, int type, int index, 
int enabled);
 
 /* Default UIList class name, keep in sync with its declaration in 
bl_ui/__init__.py */
 #define UI_UL_DEFAULT_CLASS_NAME "UI_UL_list"
diff --git a/source/blender/editors/interface/interface_templates.c 
b/source/blender/editors/interface/interface_templates.c
index d44f8b1..6e427fd 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -31,6 +31,7 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "DNA_cache_library_types.h"
 #include "DNA_node_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_object_types.h"
@@ -49,6 +50,7 @@
 #include "BLF_api.h"
 #include "BLF_translation.h"
 
+#include "BKE_cache_library.h"
 #include "BKE_colortools.h"
 #include "BKE_context.h"
 #include "BKE_depsgraph.h"
@@ -73,6 +75,7 @@
 #include "ED_util.h"
 
 #include "RNA_access.h"
+#include "RNA_enum_types.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
@@ -3698,3 +3701,56 @@ void uiTemplateNodeSocket(uiLayout *layout, bContext 
*UNUSED(C), float *color)
        
        UI_block_align_end(block);
 }
+
+/************************* Cache Library Item **************************/
+
+static void cache_item_button(uiLayout *layout, bContext *UNUSED(C), 
CacheLibrary *cachelib, CacheItem *item, Object *ob, int type, int index)
+{
+       if (item) {
+               PointerRNA itemptr;
+               RNA_pointer_create((ID *)cachelib, &RNA_CacheItem, item, 
&itemptr);
+               
+               uiItemR(layout, &itemptr, "enabled", 0, "", ICON_NONE);
+       }
+       else {
+               uiLayout *row = uiLayoutRow(layout, false);
+               uiBlock *block = uiLayoutGetBlock(row);
+               uiBut *but;
+               PointerRNA obptr;
+               PointerRNA *opptr;
+               
+               RNA_id_pointer_create((ID *)ob, &obptr);
+               uiLayoutSetContextPointer(row, "cache_object", &obptr);
+               
+               but = uiDefButO(block, UI_BTYPE_CHECKBOX, 
"CACHELIBRARY_OT_item_enable", WM_OP_EXEC_DEFAULT, "",
+                               0, 0, UI_UNIT_X, UI_UNIT_Y, NULL);
+               opptr = UI_but_operator_ptr_get(but);
+               RNA_enum_set(opptr, "type", type);
+               RNA_int_set(opptr, "index", index);
+       }
+}
+
+uiLayout *uiTemplateCacheLibraryItem(uiLayout *layout, bContext *C, 
CacheLibrary *cachelib,
+                                     Object *ob, int type, int index, int 
enabled)
+{
+       CacheItem *item = BKE_cache_library_find_item(cachelib, ob, type, 
index);
+       
+       uiLayout *row, *sub, *subrow;
+       char name[2*MAX_NAME];
+       int icon = ICON_NONE;
+       
+       row = uiLayoutRow(layout, false);
+       uiLayoutSetEnabled(row, enabled);
+       
+       cache_item_button(row, C, cachelib, item, ob, type, index);
+       
+       sub = uiLayoutColumn(row, false);
+       uiLayoutSetEnabled(sub, item && (item->flag & CACHE_ITEM_ENABLED));
+       BKE_cache_item_name(ob, type, index, name);
+       
+       subrow = uiLayoutRow(sub, false);
+       RNA_enum_icon_from_value(cache_library_item_type_items, type, &icon);
+       uiItemL(subrow, name, icon);
+       
+       return sub;
+}
diff --git a/source/blender/makesrna/RNA_access.h 
b/source/blender/makesrna/RNA_access.h
index 4ebb238..bf21189 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -95,6 +95,7 @@ extern StructRNA RNA_Brush;
 extern StructRNA RNA_BrushTextureSlot;
 extern StructRNA RNA_BuildModifier;
 extern StructRNA RNA_MeshCacheModifier;
+extern StructRNA RNA_CacheItem;
 extern StructRNA RNA_CacheLibrary;
 extern StructRNA RNA_Camera;
 extern StructRNA RNA_CastModifier;
diff --git a/source/blender/makesrna/intern/rna_ui_api.c 
b/source/blender/makesrna/intern/rna_ui_api.c
index fea8b63..a7cf7b1 100644
--- a/source/blender/makesrna/intern/rna_ui_api.c
+++ b/source/blender/makesrna/intern/rna_ui_api.c
@@ -899,6 +899,19 @@ void RNA_api_ui_layout(StructRNA *srna)
        RNA_def_function_ui_description(func, "Node Socket Icon");
        RNA_def_function_flag(func, FUNC_USE_CONTEXT);
        RNA_def_float_array(func, "color", 4, node_socket_color_default, 0.0f, 
1.0f, "Color", "", 0.0f, 1.0f);
+
+       /* cache library item */
+       func = RNA_def_function(srna, "template_cache_library_item", 
"uiTemplateCacheLibraryItem");
+       RNA_def_function_ui_description(func, "Cache Library Item");
+       RNA_def_function_flag(func, FUNC_USE_CONTEXT);
+       RNA_def_pointer(func, "cachelib", "CacheLibrary", "Cache Library", 
"Cache library containing the item");
+       RNA_def_pointer(func, "object", "Object", "Object", "Object to cache");
+       parm = RNA_def_enum(func, "type", cache_library_item_type_items, 0, 
"Type", "Type of cached data");
+       RNA_def_property_flag(parm, PROP_REQUIRED);
+       RNA_def_int(func, "index", -1, -1, INT_MAX, "Index", "Index of cached 
data", -1, INT_MAX);
+       RNA_def_boolean(func, "enabled", true, "Enabled", "Enable the item");
+       parm = RNA_def_pointer(func, "layout", "UILayout", "", "Sub-layout to 
put items in");
+       RNA_def_function_return(func, parm);
 }
 
 #endif
diff --git a/source/blenderplayer/bad_level_call_stubs/stubs.c 
b/source/blenderplayer/bad_level_call_stubs/stubs.c
index e431963..654ba4f 100644
--- a/source/blenderplayer/bad_level_call_stubs/stubs.c
+++ b/source/blenderplayer/bad_level_call_stubs/stubs.c
@@ -582,6 +582,8 @@ void uiTemplateColormanagedViewSettings(struct uiLayout 
*layout, struct bContext
 void uiTemplateComponentMenu(struct uiLayout *layout, struct PointerRNA *ptr, 
const char *propname, const char *name) RET_NONE
 void uiTemplateNodeSocket(struct uiLayout *layout, struct bContext *C, float 
*color) RET_NONE
 void uiTemplatePalette(struct uiLayout *layout, struct PointerRNA *ptr, const 
char *propname, int color) RET_NONE
+struct uiLayout *uiTemplateCacheLibraryItem(struct uiLayout *layout, struct 
bContext *C, struct CacheLibrary *cachelib,
+                                            struct Object *ob, int type, int 
index, int enabled) RET_NULL
 
 /* rna render */
 struct RenderResult *RE_engine_begin_result(RenderEngine *engine, int x, int 
y, int w, int h, const char *layername) RET_NULL

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to