2.5: RNA. Default values were not set when calling functions, this
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Tue, 18 Aug 2009 12:56:43 +0000 (12:56 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Tue, 18 Aug 2009 12:56:43 +0000 (12:56 +0000)
is fixed now. Also added option for spaces without menus in the
header in uiTemplateHeader.

source/blender/editors/include/UI_interface.h
source/blender/editors/interface/interface_templates.c
source/blender/makesrna/intern/rna_access.c
source/blender/makesrna/intern/rna_ui_api.c

index cc3b243d38d37e60bef25c6a699d37af5bd81158..8da2702b603b5d2d8a9b7004da933d6eef2f0fd4 100644 (file)
@@ -625,7 +625,7 @@ uiLayout *uiLayoutSplit(uiLayout *layout, float percentage);
 uiBlock *uiLayoutFreeBlock(uiLayout *layout);
 
 /* templates */
-void uiTemplateHeader(uiLayout *layout, struct bContext *C);
+void uiTemplateHeader(uiLayout *layout, struct bContext *C, int menus);
 void uiTemplateID(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, char *propname,
        char *newop, char *unlinkop);
 uiLayout *uiTemplateModifier(uiLayout *layout, struct PointerRNA *ptr);
index 1a5c11789831d08f18ec4b93b44092bf73e3fc46..0ee21cbcf77b9ec91f75dd33b304001241d8a7d2 100644 (file)
@@ -56,12 +56,13 @@ void ui_template_fix_linking()
 
 /********************** Header Template *************************/
 
-void uiTemplateHeader(uiLayout *layout, bContext *C)
+void uiTemplateHeader(uiLayout *layout, bContext *C, int menus)
 {
        uiBlock *block;
        
        block= uiLayoutFreeBlock(layout);
-       ED_area_header_standardbuttons(C, block, 0);
+       if(menus) ED_area_header_standardbuttons(C, block, 0);
+       else ED_area_header_switchbutton(C, block, 0);
 }
 
 /********************** Search Callbacks *************************/
index 54cde57a54ff14542507c06808478ab6f1af71e6..c2f1f31a4bc0d6869f6a02789652b7295418dca4 100644 (file)
@@ -2844,8 +2844,10 @@ const struct ListBase *RNA_function_defined_parameters(FunctionRNA *func)
 ParameterList *RNA_parameter_list_create(ParameterList *parms, PointerRNA *ptr, FunctionRNA *func)
 {
        PropertyRNA *parm;
-       int tot= 0;
+       void *data;
+       int tot= 0, size;
 
+       /* allocate data */
        for(parm= func->cont.properties.first; parm; parm= parm->next)
                tot+= rna_parameter_size(parm);
 
@@ -2853,6 +2855,44 @@ ParameterList *RNA_parameter_list_create(ParameterList *parms, PointerRNA *ptr,
        parms->func= func;
        parms->tot= tot;
 
+       /* set default values */
+       data= parms->data;
+
+       for(parm= func->cont.properties.first; parm; parm= parm->next) {
+               size= rna_parameter_size(parm);
+
+               if(!(parm->flag & PROP_REQUIRED)) {
+                       switch(parm->type) {
+                               case PROP_BOOLEAN:
+                                       if(parm->arraylength) memcpy(data, &((BooleanPropertyRNA*)parm)->defaultarray, size);
+                                       else memcpy(data, &((BooleanPropertyRNA*)parm)->defaultvalue, size);
+                                       break;
+                               case PROP_INT:
+                                       if(parm->arraylength) memcpy(data, &((IntPropertyRNA*)parm)->defaultarray, size);
+                                       else memcpy(data, &((IntPropertyRNA*)parm)->defaultvalue, size);
+                                       break;
+                               case PROP_FLOAT:
+                                       if(parm->arraylength) memcpy(data, &((FloatPropertyRNA*)parm)->defaultarray, size);
+                                       else memcpy(data, &((FloatPropertyRNA*)parm)->defaultvalue, size);
+                                       break;
+                               case PROP_ENUM:
+                                       memcpy(data, &((EnumPropertyRNA*)parm)->defaultvalue, size);
+                                       break;
+                               case PROP_STRING: {
+                                       const char *defvalue= ((StringPropertyRNA*)parm)->defaultvalue;
+                                       if(defvalue && defvalue[0])
+                                               memcpy(data, &defvalue, size);
+                                       break;
+                               }
+                               case PROP_POINTER:
+                               case PROP_COLLECTION:
+                                       break;
+                       }
+               }
+
+               data= ((char*)data) + size;
+       }
+
        return parms;
 }
 
index 40d300315f5319cbe980397521110c366707ee83..f9287bddc101f7ec9c84c6c8686e52c178f44812 100644 (file)
@@ -119,7 +119,7 @@ void RNA_api_ui_layout(StructRNA *srna)
        func= RNA_def_function(srna, "split", "uiLayoutSplit");
        parm= RNA_def_pointer(func, "layout", "UILayout", "", "Sub-layout to put items in.");
        RNA_def_function_return(func, parm);
-       RNA_def_float(func, "percentage", 0.5f, 0.0f, 1.0f, "Percentage", "Percentage of width to split at.", 0.0f, 1.0f);
+       RNA_def_float(func, "percentage", 0.0f, 0.0f, 1.0f, "Percentage", "Percentage of width to split at.", 0.0f, 1.0f);
 
        /* items */
        func= RNA_def_function(srna, "itemR", "uiItemR");
@@ -220,6 +220,7 @@ void RNA_api_ui_layout(StructRNA *srna)
        /* templates */
        func= RNA_def_function(srna, "template_header", "uiTemplateHeader");
        RNA_def_function_flag(func, FUNC_USE_CONTEXT);
+       RNA_def_boolean(func, "menus", 1, "", "The header has menus, and should show menu expander.");
 
        func= RNA_def_function(srna, "template_ID", "uiTemplateID");
        RNA_def_function_flag(func, FUNC_USE_CONTEXT);