diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-04-19 17:37:59 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-04-19 17:37:59 +0400 |
commit | adff6aeb1c749183921c0facd373972bbeb874b4 (patch) | |
tree | 07987d408713eee8a3dd8bb5cb4ecf3c112de654 /source/blender/makesrna/intern/rna_rna.c | |
parent | d880257d165888638b7c924fb6ef7071343b783e (diff) |
RNA: Generic Type Registration
The Python API to define Panels and Operators is based on subclassing,
this makes that system more generic, and based on RNA. Hopefully that
will make it easy to make various parts of Blender more extensible.
* The system simply uses RNA properties and functions and marks them
with REGISTER to make them part of the type registration process.
Additionally, the struct must provide a register/unregister callback
to create/free the PanelType or similar.
* From the python side there were some small changes, mainly that
registration now goes trough bpy.types.register instead of
bpy.ui.addPanel.
* Only Panels have been wrapped this way now. Check rna_ui.c to see
how this code works. There's still some rough edges and possibilities
to make it cleaner, though it works without any manual python code.
* Started some docs here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/RNATypeRegistration
* Also changed some RNA_property and RNA_struct functions to not
require a PointerRNA anymore, where they were not required (which
is actually the cause of most changed files).
Diffstat (limited to 'source/blender/makesrna/intern/rna_rna.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_rna.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/source/blender/makesrna/intern/rna_rna.c b/source/blender/makesrna/intern/rna_rna.c index ae0a44f9ac2..f7039d9c756 100644 --- a/source/blender/makesrna/intern/rna_rna.c +++ b/source/blender/makesrna/intern/rna_rna.c @@ -368,6 +368,18 @@ static int rna_Property_array_length_get(PointerRNA *ptr) return prop->arraylength; } +static int rna_Property_registered_get(PointerRNA *ptr) +{ + PropertyRNA *prop= (PropertyRNA*)ptr->data; + return prop->flag & PROP_REGISTER; +} + +static int rna_Property_registered_optional_get(PointerRNA *ptr) +{ + PropertyRNA *prop= (PropertyRNA*)ptr->data; + return prop->flag & PROP_REGISTER_OPTIONAL; +} + static int rna_IntProperty_hard_min_get(PointerRNA *ptr) { PropertyRNA *prop= (PropertyRNA*)ptr->data; @@ -529,6 +541,18 @@ static void rna_Function_parameters_begin(CollectionPropertyIterator *iter, Poin rna_iterator_listbase_begin(iter, &((FunctionRNA*)ptr->data)->cont.properties, rna_property_builtin); } +static int rna_Function_registered_get(PointerRNA *ptr) +{ + FunctionRNA *func= (FunctionRNA*)ptr->data; + return func->flag & FUNC_REGISTER; +} + +static int rna_Function_registered_optional_get(PointerRNA *ptr) +{ + FunctionRNA *func= (FunctionRNA*)ptr->data; + return func->flag & FUNC_REGISTER_OPTIONAL; +} + /* Blender RNA */ static void rna_BlenderRNA_structs_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) @@ -655,6 +679,16 @@ static void rna_def_property(BlenderRNA *brna) RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_boolean_funcs(prop, "rna_Property_editable_get", NULL); RNA_def_property_ui_text(prop, "Editable", "Property is editable through RNA."); + + prop= RNA_def_property(srna, "registered", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_boolean_funcs(prop, "rna_Property_registered_get", NULL); + RNA_def_property_ui_text(prop, "Registered", "Property is registerd as part of type registration."); + + prop= RNA_def_property(srna, "registered_optional", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_boolean_funcs(prop, "rna_Property_registered_optional_get", NULL); + RNA_def_property_ui_text(prop, "Registered Optionally", "Property is optionally registerd as part of type registration."); } static void rna_def_function(BlenderRNA *brna) @@ -681,6 +715,16 @@ static void rna_def_function(BlenderRNA *brna) RNA_def_property_struct_type(prop, "Property"); RNA_def_property_collection_funcs(prop, "rna_Function_parameters_begin", "rna_iterator_listbase_next", "rna_iterator_listbase_end", "rna_iterator_listbase_get", 0, 0, 0); RNA_def_property_ui_text(prop, "Parameters", "Parameters for the function."); + + prop= RNA_def_property(srna, "registered", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_boolean_funcs(prop, "rna_Function_registered_get", NULL); + RNA_def_property_ui_text(prop, "Registered", "Function is registerd as callback as part of type registration."); + + prop= RNA_def_property(srna, "registered_optional", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_boolean_funcs(prop, "rna_Function_registered_optional_get", NULL); + RNA_def_property_ui_text(prop, "Registered Optionally", "Function is optionally registerd as callback part of type registration."); } static void rna_def_number_property(StructRNA *srna, PropertyType type) |