Revision: 23824
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=23824
Author:   aligorith
Date:     2009-10-14 11:08:53 +0200 (Wed, 14 Oct 2009)

Log Message:
-----------
UI Templates: ('Any ID' Selector)

Added new template for choosing to use any type of ID-block. The first combo 
box allows you to choose the type of ID-block that gets used, and the second 
box allows you to choose the ID-block of the type specified by the first one.

This is currently used for setting the ID-block used for Keying Sets, but the 
main user for this was intended to be the Drivers UI. However, I still need to 
clear up a few button-event issues there before I can port this over.


Additional Bugfixes:
* Adding new Keying Set path was setting the active path wrong, meaning that 
you had to click on the list to get some response after adding
* Bone Groups list was being drawn too long by default (when empty)

Modified Paths:
--------------
    trunk/blender/release/scripts/ui/buttons_data_armature.py
    trunk/blender/release/scripts/ui/buttons_scene.py
    trunk/blender/source/blender/editors/animation/keyingsets.c
    trunk/blender/source/blender/editors/include/UI_interface.h
    trunk/blender/source/blender/editors/interface/interface_templates.c
    trunk/blender/source/blender/makesdna/DNA_anim_types.h
    trunk/blender/source/blender/makesrna/RNA_enum_types.h
    trunk/blender/source/blender/makesrna/intern/rna_ID.c
    trunk/blender/source/blender/makesrna/intern/rna_animation.c
    trunk/blender/source/blender/makesrna/intern/rna_fcurve.c
    trunk/blender/source/blender/makesrna/intern/rna_ui_api.c

Modified: trunk/blender/release/scripts/ui/buttons_data_armature.py
===================================================================
--- trunk/blender/release/scripts/ui/buttons_data_armature.py   2009-10-14 
09:08:48 UTC (rev 23823)
+++ trunk/blender/release/scripts/ui/buttons_data_armature.py   2009-10-14 
09:08:53 UTC (rev 23824)
@@ -88,7 +88,7 @@
                pose = ob.pose
                
                row = layout.row()
-               row.template_list(pose, "bone_groups", pose, 
"active_bone_group_index")
+               row.template_list(pose, "bone_groups", pose, 
"active_bone_group_index", rows=2)
                
                col = row.column(align=True)
                col.active = (ob.proxy == None)

Modified: trunk/blender/release/scripts/ui/buttons_scene.py
===================================================================
--- trunk/blender/release/scripts/ui/buttons_scene.py   2009-10-14 09:08:48 UTC 
(rev 23823)
+++ trunk/blender/release/scripts/ui/buttons_scene.py   2009-10-14 09:08:53 UTC 
(rev 23824)
@@ -527,7 +527,7 @@
                if ksp:
                        col = layout.column()
                        col.itemL(text="Target:")
-                       col.itemR(ksp, "id")
+                       col.template_any_ID(ksp, "id", "id_type")
                        col.itemR(ksp, "rna_path")
                        
                        

Modified: trunk/blender/source/blender/editors/animation/keyingsets.c
===================================================================
--- trunk/blender/source/blender/editors/animation/keyingsets.c 2009-10-14 
09:08:48 UTC (rev 23823)
+++ trunk/blender/source/blender/editors/animation/keyingsets.c 2009-10-14 
09:08:53 UTC (rev 23824)
@@ -219,7 +219,7 @@
        /* don't use the API method for this, since that checks on values... */
        ksp= MEM_callocN(sizeof(KS_Path), "KeyingSetPath Empty");
        BLI_addtail(&ks->paths, ksp);
-       ks->active_path= BLI_countlist(&ks->paths) + 1;
+       ks->active_path= BLI_countlist(&ks->paths);
        
        ksp->groupmode= KSP_GROUP_KSNAME; // XXX?
        

Modified: trunk/blender/source/blender/editors/include/UI_interface.h
===================================================================
--- trunk/blender/source/blender/editors/include/UI_interface.h 2009-10-14 
09:08:48 UTC (rev 23823)
+++ trunk/blender/source/blender/editors/include/UI_interface.h 2009-10-14 
09:08:53 UTC (rev 23824)
@@ -620,6 +620,8 @@
 void uiTemplateHeader(uiLayout *layout, struct bContext *C, int menus);
 void uiTemplateID(uiLayout *layout, struct bContext *C, struct PointerRNA 
*ptr, char *propname,
        char *newop, char *openop, char *unlinkop);
+void uiTemplateAnyID(uiLayout *layout, struct bContext *C, struct PointerRNA 
*ptr, char *propname, 
+       char *proptypename, char *text);
 uiLayout *uiTemplateModifier(uiLayout *layout, struct PointerRNA *ptr);
 uiLayout *uiTemplateConstraint(uiLayout *layout, struct PointerRNA *ptr);
 void uiTemplatePreview(uiLayout *layout, struct ID *id, struct ID *parent, 
struct MTex *slot);

Modified: trunk/blender/source/blender/editors/interface/interface_templates.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_templates.c        
2009-10-14 09:08:48 UTC (rev 23823)
+++ trunk/blender/source/blender/editors/interface/interface_templates.c        
2009-10-14 09:08:53 UTC (rev 23824)
@@ -152,6 +152,7 @@
 }
 
 /************************ ID Template ***************************/
+/* This is for browsing and editing the ID-blocks used */
 
 /* for new/open operators */
 void uiIDContextProperty(bContext *C, PointerRNA *ptr, PropertyRNA **prop)
@@ -390,7 +391,10 @@
 
        type= RNA_property_pointer_type(ptr, prop);
        template->idlb= wich_libbase(CTX_data_main(C), 
RNA_type_to_ID_code(type));
-
+       
+       /* create UI elements for this template
+        *      - template_ID makes a copy of the template data and assigns it 
to the relevant buttons
+        */
        if(template->idlb) {
                uiLayoutRow(layout, 1);
                block= uiLayoutGetBlock(layout);
@@ -400,6 +404,47 @@
        MEM_freeN(template);
 }
 
+/************************ ID Chooser Template ***************************/
+/* This is for selecting the type of ID-block to use, and then from the 
relevant type choosing the block to use */
+
+/* - propname: property identifier for property that ID-pointer gets stored to
+ * - proptypename: property identifier for property used to determine the type 
of ID-pointer that can be used
+ */
+void uiTemplateAnyID(uiLayout *layout, bContext *C, PointerRNA *ptr, char 
*propname, char *proptypename, char *text)
+{
+       PropertyRNA *propID, *propType;
+       uiLayout *row;
+       
+       /* get properties... */
+       propID= RNA_struct_find_property(ptr, propname);
+       propType= RNA_struct_find_property(ptr, proptypename);
+
+       if (!propID || RNA_property_type(propID) != PROP_POINTER) {
+               printf("uiTemplateAnyID: pointer property not found: %s\n", 
propname);
+               return;
+       }
+       if (!propType || RNA_property_type(propType) != PROP_ENUM) { 
+               printf("uiTemplateAnyID: pointer-type property not found: 
%s\n", proptypename);
+               return;
+       }
+       
+       /* Start drawing UI Elements using standard defines */
+       row= uiLayoutRow(layout, 1);
+       
+       /* Label - either use the provided text, or will become "ID-Block:" */
+       if (text)
+               uiItemL(row, text, 0);
+       else
+               uiItemL(row, "ID-Block:", 0);
+       
+       /* ID-Type Selector - just have a menu of icons */
+       // XXX should value really be 0?
+       uiItemFullR(row, "", 0, ptr, propType, 0, 0, UI_ITEM_R_ICON_ONLY);
+       
+       /* ID-Block Selector - just use pointer widget... */
+       uiItemFullR(row, "", 0, ptr, propID, 0, 0, 0);
+}
+
 /************************ Modifier Template *************************/
 
 #define ERROR_LIBDATA_MESSAGE "Can't edit external libdata"

Modified: trunk/blender/source/blender/makesdna/DNA_anim_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_anim_types.h      2009-10-14 
09:08:48 UTC (rev 23823)
+++ trunk/blender/source/blender/makesdna/DNA_anim_types.h      2009-10-14 
09:08:53 UTC (rev 23824)
@@ -246,7 +246,9 @@
        char *rna_path;         /* target channel to use as driver value */
        int array_index;        /* if applicable, the index of the RNA-array 
item to use as driver */
        
+       int idtype;                     /* type of ID-block that this target 
can use */
        int flags;                      /* flags for the validity of the target 
*/
+       int pad;
        
        char name[64];          /* name of the variable */
 } DriverTarget;

Modified: trunk/blender/source/blender/makesrna/RNA_enum_types.h
===================================================================
--- trunk/blender/source/blender/makesrna/RNA_enum_types.h      2009-10-14 
09:08:48 UTC (rev 23823)
+++ trunk/blender/source/blender/makesrna/RNA_enum_types.h      2009-10-14 
09:08:53 UTC (rev 23824)
@@ -29,6 +29,9 @@
 
 /* Types */
 
+extern EnumPropertyItem id_type_items[];
+
+
 extern EnumPropertyItem object_mode_items[];
 
 extern EnumPropertyItem proportional_falloff_items[];

Modified: trunk/blender/source/blender/makesrna/intern/rna_ID.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_ID.c       2009-10-14 
09:08:48 UTC (rev 23823)
+++ trunk/blender/source/blender/makesrna/intern/rna_ID.c       2009-10-14 
09:08:53 UTC (rev 23824)
@@ -33,6 +33,38 @@
 
 #include "rna_internal.h"
 
+/* enum of ID-block types 
+ * NOTE: need to keep this in line with the other defines for these
+ */
+EnumPropertyItem id_type_items[] = {
+       {ID_AC, "ACTION", ICON_ACTION, "Action", ""},
+       {ID_AR, "ARMATURE", ICON_ARMATURE_DATA, "Armature", ""},
+       {ID_BR, "BRUSH", ICON_BRUSH_DATA, "Brush", ""},
+       {ID_CA, "CAMERA", ICON_CAMERA_DATA, "Camera", ""},
+       {ID_CU, "CURVE", ICON_CURVE_DATA, "Curve", ""},
+       {ID_VF, "FONT", ICON_FONT_DATA, "Font", ""},
+       {ID_GD, "GREASEPENCIL", ICON_GREASEPENCIL, "Grease Pencil", ""},
+       {ID_GR, "GROUP", ICON_GROUP, "Group", ""},
+       {ID_IM, "IMAGE", ICON_IMAGE_DATA, "Image", ""},
+       {ID_KE, "KEY", ICON_SHAPEKEY_DATA, "Key", ""},
+       {ID_LA, "LAMP", ICON_LAMP_DATA, "Lamp", ""},
+       {ID_LI, "LIBRARY", 0, "Library", ""},
+       {ID_LT, "LATTICE", ICON_LATTICE_DATA, "Lattice", ""},
+       {ID_MA, "MATERIAL", ICON_MATERIAL_DATA, "Material", ""},
+       {ID_MB, "META", ICON_META_DATA, "MetaBall", ""},
+       {ID_ME, "MESH", ICON_MESH_DATA, "Mesh", ""},
+       {ID_NT, "NODETREE", 0, "NodeTree", ""},
+       {ID_OB, "OBJECT", ICON_OBJECT_DATA, "Object", ""},
+       {ID_PA, "PARTICLE", ICON_PARTICLE_DATA, "Particle", ""},
+       {ID_SCE, "SCENE", ICON_SCENE_DATA, "Scene", ""},
+       {ID_SCR, "SCREEN", 0, "Screen", ""},
+       {ID_SO, "SOUND", 0, "Sound", ""},
+       {ID_TXT, "TEXT", ICON_TEXT, "Text", ""},
+       {ID_TE, "TEXTURE", ICON_TEXTURE_DATA, "Texture", ""},
+       {ID_WO, "WORLD", ICON_WORLD_DATA, "World", ""},
+       {ID_WM, "WINDOWMANAGER", 0, "Window Manager", ""},
+       {0, NULL, 0, NULL, NULL}};
+
 #ifdef RNA_RUNTIME
 
 #include "BKE_idprop.h"

Modified: trunk/blender/source/blender/makesrna/intern/rna_animation.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_animation.c        
2009-10-14 09:08:48 UTC (rev 23823)
+++ trunk/blender/source/blender/makesrna/intern/rna_animation.c        
2009-10-14 09:08:53 UTC (rev 23824)
@@ -24,6 +24,7 @@
 
 #include <stdlib.h>
 
+#include "RNA_access.h"
 #include "RNA_define.h"
 #include "RNA_types.h"
 #include "RNA_enum_types.h"
@@ -63,6 +64,20 @@
        adt->action= value.data;
 }
 
+/* ****************************** */
+
+static StructRNA *rna_ksPath_id_typef(PointerRNA *ptr)
+{
+       KS_Path *ksp= (KS_Path*)ptr->data;
+       return ID_code_to_RNA_type(ksp->idtype);
+}
+
+static int rna_ksPath_id_editable(PointerRNA *ptr)
+{
+       KS_Path *ksp= (KS_Path*)ptr->data;
+       return (ksp->idtype)? PROP_EDITABLE : 0;
+}
+
 static void rna_ksPath_RnaPath_get(PointerRNA *ptr, char *value)
 {
        KS_Path *ksp= (KS_Path *)ptr->data;
@@ -96,6 +111,7 @@
                ksp->rna_path= NULL;
 }
 
+/* ****************************** */
 
 static int rna_KeyingSet_active_ksPath_editable(PointerRNA *ptr)
 {
@@ -153,8 +169,18 @@
        
        /* ID */
        prop= RNA_def_property(srna, "id", PROP_POINTER, PROP_NONE);
+       RNA_def_property_struct_type(prop, "ID");
+       RNA_def_property_flag(prop, PROP_EDITABLE);
+       RNA_def_property_editable_func(prop, "rna_ksPath_id_editable");
+       RNA_def_property_pointer_funcs(prop, NULL, NULL, "rna_ksPath_id_typef");
        RNA_def_property_ui_text(prop, "ID-Block", "ID-Block that keyframes for 
Keying Set should be added to (for Absolute Keying Sets only).");
        
+       prop= RNA_def_property(srna, "id_type", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_sdna(prop, NULL, "idtype");
+       RNA_def_property_enum_items(prop, id_type_items);
+       RNA_def_property_enum_default(prop, ID_OB);
+       RNA_def_property_ui_text(prop, "ID Type", "Type of ID-block that can be 
used.");
+       
        /* Group */

@@ Diff output truncated at 10240 characters. @@

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

Reply via email to