RNA minor changes

* Added start of lamp wrapping (code by Michael Fox).
* Add back Object.data, was crashing with unknown data type.
* Added support for using consecutive variables like float r, g, b;
  as an array without writing a manual get/set function.
* Also note the RNA documentation is updated now to be more
  about how to define RNA and use it, including some diagrams.

http://wiki.blender.org/index.php/BlenderDev/Blender2.5/RNA
This commit is contained in:
2008-11-18 10:57:06 +00:00
parent 8c84a43385
commit c3da1af01c
8 changed files with 150 additions and 49 deletions

View File

@@ -186,6 +186,7 @@ static void rna_label(CellRNA *cell, rcti *rct, uiBlock *block)
PropertyType type;
PropertyRNA *prop;
char *vectoritem[4]= {"x", "y", "z", "w"};
char *quatitem[4]= {"w", "x", "y", "z"};
char *coloritem[4]= {"r", "g", "b", "a"};
char item[32];
int arraylength;
@@ -199,7 +200,9 @@ static void rna_label(CellRNA *cell, rcti *rct, uiBlock *block)
uiDefBut(block, LABEL, 0, (char*)RNA_property_ui_name(prop, &cell->ptr), rct->xmin, rct->ymin, rct->xmax-rct->xmin, rct->ymax-rct->ymin, 0, 0, 0, 0, 0, (char*)RNA_property_ui_description(prop, &cell->ptr));
}
else if (type != PROP_COLLECTION) {
if(arraylength <= 4 && (subtype == PROP_VECTOR || subtype == PROP_ROTATION))
if(arraylength == 4 && subtype == PROP_ROTATION)
sprintf(item, " %s", quatitem[cell->index]);
else if(arraylength <= 4 && (subtype == PROP_VECTOR || subtype == PROP_ROTATION))
sprintf(item, " %s", vectoritem[cell->index]);
else if(arraylength <= 4 && subtype == PROP_COLOR)
sprintf(item, " %s", coloritem[cell->index]);

View File

@@ -129,12 +129,18 @@ static char *rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *pr
fprintf(f, "static %s %s(PointerRNA *ptr, int index)\n", rna_type_type(prop), func);
fprintf(f, "{\n");
fprintf(f, " %s *data= (%s*)ptr->data;\n", dp->dnastructname, dp->dnastructname);
if(prop->type == PROP_BOOLEAN && dp->booleanbit && dp->dnaarraylength==1)
fprintf(f, " return ((data->%s & (%d<<index)) != 0);\n", dp->dnaname, dp->booleanbit);
else if(prop->type == PROP_BOOLEAN && dp->booleanbit)
fprintf(f, " return ((data->%s[index] & %d) != 0);\n", dp->dnaname, dp->booleanbit);
else
fprintf(f, " return (%s)(data->%s[index]);\n", rna_type_type(prop), dp->dnaname);
if(dp->dnaarraylength == 1) {
if(prop->type == PROP_BOOLEAN && dp->booleanbit)
fprintf(f, " return ((data->%s & (%d<<index)) != 0);\n", dp->dnaname, dp->booleanbit);
else
fprintf(f, " return (%s)((&data->%s)[index]);\n", rna_type_type(prop), dp->dnaname);
}
else {
if(prop->type == PROP_BOOLEAN && dp->booleanbit)
fprintf(f, " return ((data->%s[index] & %d) != 0);\n", dp->dnaname, dp->booleanbit);
else
fprintf(f, " return (%s)(data->%s[index]);\n", rna_type_type(prop), dp->dnaname);
}
fprintf(f, "}\n\n");
}
else {
@@ -214,17 +220,25 @@ static char *rna_def_property_set_func(FILE *f, StructRNA *srna, PropertyRNA *pr
fprintf(f, "static void %s(PointerRNA *ptr, int index, %s value)\n", func, rna_type_type(prop));
fprintf(f, "{\n");
fprintf(f, " %s *data= (%s*)ptr->data;\n", dp->dnastructname, dp->dnastructname);
if(prop->type == PROP_BOOLEAN && dp->booleanbit && dp->dnaarraylength==1) {
fprintf(f, " if(value) data->%s |= (%d<<index);\n", dp->dnaname, dp->booleanbit);
fprintf(f, " else data->%s &= ~(%d<<index);\n", dp->dnaname, dp->booleanbit);
}
else if(prop->type == PROP_BOOLEAN && dp->booleanbit) {
fprintf(f, " if(value) data->%s[index] |= %d;\n", dp->dnaname, dp->booleanbit);
fprintf(f, " else data->%s[index] &= ~%d;\n", dp->dnaname, dp->booleanbit);
if(dp->dnaarraylength == 1) {
if(prop->type == PROP_BOOLEAN && dp->booleanbit) {
fprintf(f, " if(value) data->%s |= (%d<<index);\n", dp->dnaname, dp->booleanbit);
fprintf(f, " else data->%s &= ~(%d<<index);\n", dp->dnaname, dp->booleanbit);
}
else {
rna_clamp_value(f, prop);
fprintf(f, " (&data->%s)[index]= value;\n", dp->dnaname);
}
}
else {
rna_clamp_value(f, prop);
fprintf(f, " data->%s[index]= value;\n", dp->dnaname);
if(prop->type == PROP_BOOLEAN && dp->booleanbit) {
fprintf(f, " if(value) data->%s[index] |= %d;\n", dp->dnaname, dp->booleanbit);
fprintf(f, " else data->%s[index] &= ~%d;\n", dp->dnaname, dp->booleanbit);
}
else {
rna_clamp_value(f, prop);
fprintf(f, " data->%s[index]= value;\n", dp->dnaname);
}
}
fprintf(f, "}\n\n");
}
@@ -577,11 +591,14 @@ static void rna_generate_struct(BlenderRNA *brna, StructRNA *srna, FILE *f)
BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
unsigned int i;
if(bprop->defaultarray) {
if(prop->arraylength) {
fprintf(f, "static int rna_%s_%s_default[%d] = {", srna->identifier, prop->identifier, prop->arraylength);
for(i=0; i<prop->arraylength; i++) {
fprintf(f, "%d", bprop->defaultarray[i]);
if(bprop->defaultarray)
fprintf(f, "%d", bprop->defaultarray[i]);
else
fprintf(f, "%d", bprop->defaultvalue);
if(i != prop->arraylength-1)
fprintf(f, ", ");
}
@@ -594,11 +611,14 @@ static void rna_generate_struct(BlenderRNA *brna, StructRNA *srna, FILE *f)
IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
unsigned int i;
if(iprop->defaultarray) {
if(prop->arraylength) {
fprintf(f, "static int rna_%s_%s_default[%d] = {", srna->identifier, prop->identifier, prop->arraylength);
for(i=0; i<prop->arraylength; i++) {
fprintf(f, "%d", iprop->defaultarray[i]);
if(iprop->defaultarray)
fprintf(f, "%d", iprop->defaultarray[i]);
else
fprintf(f, "%d", iprop->defaultvalue);
if(i != prop->arraylength-1)
fprintf(f, ", ");
}
@@ -611,11 +631,14 @@ static void rna_generate_struct(BlenderRNA *brna, StructRNA *srna, FILE *f)
FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
unsigned int i;
if(fprop->defaultarray) {
if(prop->arraylength) {
fprintf(f, "static float rna_%s_%s_default[%d] = {", srna->identifier, prop->identifier, prop->arraylength);
for(i=0; i<prop->arraylength; i++) {
rna_float_print(f, fprop->defaultarray[i]);
if(fprop->defaultarray)
rna_float_print(f, fprop->defaultarray[i]);
else
rna_float_print(f, fprop->defaultvalue);
if(i != prop->arraylength-1)
fprintf(f, ", ");
}
@@ -646,14 +669,14 @@ static void rna_generate_struct(BlenderRNA *brna, StructRNA *srna, FILE *f)
case PROP_BOOLEAN: {
BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
fprintf(f, "\t%s, %s, %s, %s, %d, ", rna_function_string(bprop->get), rna_function_string(bprop->set), rna_function_string(bprop->getarray), rna_function_string(bprop->setarray), bprop->defaultvalue);
if(bprop->defaultarray) fprintf(f, "rna_%s_%s_default\n", srna->name, prop->identifier);
if(prop->arraylength) fprintf(f, "rna_%s_%s_default\n", srna->identifier, prop->identifier);
else fprintf(f, "NULL\n");
break;
}
case PROP_INT: {
IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
fprintf(f, "\t%s, %s, %s, %s, %d, %d, %d, %d, %d,\n\t%d, \n", rna_function_string(iprop->get), rna_function_string(iprop->set), rna_function_string(iprop->getarray), rna_function_string(iprop->setarray), iprop->softmin, iprop->softmax, iprop->hardmin, iprop->hardmax, iprop->step, iprop->defaultvalue);
if(iprop->defaultarray) fprintf(f, "rna_%s_%s_default\n", srna->name, prop->identifier);
fprintf(f, "\t%s, %s, %s, %s, %d, %d, %d, %d, %d,\n\t%d, ", rna_function_string(iprop->get), rna_function_string(iprop->set), rna_function_string(iprop->getarray), rna_function_string(iprop->setarray), iprop->softmin, iprop->softmax, iprop->hardmin, iprop->hardmax, iprop->step, iprop->defaultvalue);
if(prop->arraylength) fprintf(f, "rna_%s_%s_default\n", srna->identifier, prop->identifier);
else fprintf(f, "NULL\n");
break;
}
@@ -667,7 +690,7 @@ static void rna_generate_struct(BlenderRNA *brna, StructRNA *srna, FILE *f)
rna_float_print(f, fprop->step); fprintf(f, ", ");
rna_float_print(f, fprop->precision); fprintf(f, ", ");
rna_float_print(f, fprop->defaultvalue); fprintf(f, ", ");
if(fprop->defaultarray) fprintf(f, "rna_%s_%s_default\n", srna->name, prop->identifier);
if(prop->arraylength) fprintf(f, "rna_%s_%s_default\n", srna->identifier, prop->identifier);
else fprintf(f, "NULL\n");
break;
}
@@ -745,6 +768,7 @@ RNAProcessItem PROCESS_ITEMS[]= {
{"rna_object.c", RNA_def_object},
{"rna_rna.c", RNA_def_rna},
{"rna_scene.c", RNA_def_scene},
{"rna_lamp.c", RNA_def_lamp},
{NULL, NULL}};
static int rna_preprocess(char *basedirectory, FILE *f)

View File

@@ -478,10 +478,8 @@ void RNA_property_pointer_get(PropertyRNA *prop, PointerRNA *ptr, PointerRNA *r_
r_ptr->data= pprop->get(ptr);
if(r_ptr->data) {
r_ptr->type= RNA_property_pointer_type(prop, ptr);
if(r_ptr->data && (r_ptr->type= RNA_property_pointer_type(prop, ptr)))
rna_pointer_inherit_id(ptr, r_ptr);
}
else
memset(r_ptr, 0, sizeof(*r_ptr));
}
@@ -532,10 +530,8 @@ static void rna_property_collection_get(PropertyRNA *prop, CollectionPropertyIte
r_ptr->data= cprop->get(iter);
if(r_ptr->data) {
r_ptr->type= rna_property_collection_type(prop, iter);
if(r_ptr->data && (r_ptr->type= rna_property_collection_type(prop, iter)))
rna_pointer_inherit_id(&iter->parent, r_ptr);
}
else
memset(r_ptr, 0, sizeof(*r_ptr));
}

View File

@@ -88,6 +88,7 @@ extern StructRNA RNA_Main;
extern StructRNA RNA_Mesh;
extern StructRNA RNA_Object;
extern StructRNA RNA_Scene;
extern StructRNA RNA_Lamp;
extern StructRNA RNA_Struct;
void RNA_def_ID(struct StructRNA *srna);
@@ -98,6 +99,7 @@ void RNA_def_mesh(struct BlenderRNA *brna);
void RNA_def_object(struct BlenderRNA *brna);
void RNA_def_rna(struct BlenderRNA *brna);
void RNA_def_scene(struct BlenderRNA *brna);
void RNA_def_lamp(struct BlenderRNA *brna);
/* Internal Functions */

View File

@@ -0,0 +1,70 @@
/**
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Contributor(s): Blender Foundation (2008).
*
* ***** END GPL LICENSE BLOCK *****
*/
#include <stdlib.h>
#include "RNA_define.h"
#include "RNA_types.h"
#include "rna_internal.h"
#include "DNA_lamp_types.h"
#ifdef RNA_RUNTIME
#else
void RNA_def_lamp(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
static EnumPropertyItem prop_type_items[] = {{LA_LOCAL, "LOCAL", "Local"}, {LA_SUN, "SUN", "Sun"}, {LA_SPOT, "SPOT", "Spot"}, {LA_HEMI, "HEMI", "Hemi"}, {LA_AREA, "AREA", "Area"}, {0, NULL, NULL}};
srna= RNA_def_struct(brna, "Lamp", "Lamp");
RNA_def_ID(srna);
prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_items(prop, prop_type_items);
RNA_def_property_ui_text(prop, "Type", "Type of Lamp.");
prop= RNA_def_property(srna, "dist", PROP_FLOAT, PROP_NONE);
RNA_def_property_range(prop, 0.0f , 9999.0f);
RNA_def_property_ui_text(prop, "Distance", "Distance that the lamp emits light.");
prop= RNA_def_property(srna, "energy", PROP_FLOAT, PROP_NONE);
RNA_def_property_range(prop, 0.0f , 10.0f);
RNA_def_property_ui_text(prop, "Energy", "Amount of light that the lamp emits.");
prop= RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR);
RNA_def_property_float_sdna(prop, NULL, "r");
RNA_def_property_array(prop, 3);
RNA_def_property_ui_text(prop, "Color", "Lamp color.");
RNA_def_property_ui_range(prop, 0.0f , 1.0f, 10.0f, 3.0f);
}
#endif

View File

@@ -46,6 +46,12 @@ static void rna_Main_object_begin(CollectionPropertyIterator *iter, PointerRNA *
rna_iterator_listbase_begin(iter, &bmain->object);
}
static void rna_Main_lamp_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
Main *bmain= (Main*)ptr->data;
rna_iterator_listbase_begin(iter, &bmain->lamp);
}
#if 0
static void rna_Main_library_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
@@ -97,11 +103,7 @@ static void rna_Main_latt_begin(CollectionPropertyIterator *iter, PointerRNA *pt
rna_iterator_listbase_begin(iter, &bmain->latt);
}
static void rna_Main_lamp_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
Main *bmain= (Main*)ptr->data;
rna_iterator_listbase_begin(iter, &bmain->lamp);
}
static void rna_Main_camera_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
@@ -210,6 +212,7 @@ void RNA_def_main(BlenderRNA *brna)
{"scenes", "Scene", "rna_Main_scene_begin", "Scenes", "Scene datablocks."},
{"objects", "Object", "rna_Main_object_begin", "Objects", "Object datablocks."},
{"meshes", "Mesh", "rna_Main_mesh_begin", "Meshes", "Mesh datablocks."},
{"lamps", "Lamp", "rna_Main_lamp_begin", "Lamps", "Lamp datablocks."},
{NULL, NULL, NULL, NULL, NULL},
{"libraries", "Library", "rna_Main_library_begin", "Libraries", "Library datablocks."},
{"curves", "Curve", "rna_Main_curve_begin", "Curves", "Curve datablocks."},
@@ -218,7 +221,6 @@ void RNA_def_main(BlenderRNA *brna)
{"textures", "Texture", "rna_Main_tex_begin", "Textures", "Texture datablocks."},
{"images", "Image", "rna_Main_image_begin", "Images", "Image datablocks."},
{"lattices", "Lattice", "rna_Main_latt_begin", "Lattices", "Lattice datablocks."},
{"lamps", "Lamp", "rna_Main_lamp_begin", "Lamps", "Lamp datablocks."},
{"cameras", "Camera", "rna_Main_camera_begin", "Cameras", "Camera datablocks."},
{"ipos", "Ipo", "rna_Main_ipo_begin", "Ipos", "Ipo datablocks."},
{"keys", "Key", "rna_Main_key_begin", "Keys", "Key datablocks."},

View File

@@ -34,7 +34,6 @@
#ifdef RNA_RUNTIME
#if 0
static StructRNA *rna_Object_data_type(PointerRNA *ptr)
{
Object *ob= (Object*)ptr->data;
@@ -44,6 +43,8 @@ static StructRNA *rna_Object_data_type(PointerRNA *ptr)
return NULL;
case OB_MESH:
return &RNA_Mesh;
case OB_LAMP:
return &RNA_Lamp;
#if 0
case OB_CURVE:
return &RNA_Curve;
@@ -66,7 +67,6 @@ static StructRNA *rna_Object_data_type(PointerRNA *ptr)
return NULL;
}
}
#endif
#else
@@ -79,9 +79,9 @@ void RNA_def_object(BlenderRNA *brna)
RNA_def_ID(srna);
/*prop= RNA_def_property(srna, "data", PROP_POINTER, PROP_NONE);
prop= RNA_def_property(srna, "data", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_funcs(prop, NULL, "rna_Object_data_type", NULL);
RNA_def_property_ui_text(prop, "Data", "Object data."); */
RNA_def_property_ui_text(prop, "Data", "Object data.");
prop= RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "Object");
@@ -90,6 +90,10 @@ void RNA_def_object(BlenderRNA *brna)
prop= RNA_def_property(srna, "track", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "Object");
RNA_def_property_ui_text(prop, "Track", "Object being tracked to define the rotation (Old Track).");
prop= RNA_def_property(srna, "loc", PROP_FLOAT, PROP_VECTOR);
RNA_def_property_ui_text(prop, "Location", "Location of the object.");
}
#endif

View File

@@ -424,14 +424,14 @@ static void rna_def_property(StructRNA *srna)
RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
RNA_def_property_enum_items(prop, subtype_items);
RNA_def_property_enum_funcs(prop, "rna_Property_subtype_get", NULL);
RNA_def_property_ui_text(prop, "Sub Type", "Sub type indicating the interpretation of the property.");
RNA_def_property_ui_text(prop, "Subtype", "Semantic interpretation of the property.");
}
static void rna_def_number_property(StructRNA *srna, PropertyType type)
{
PropertyRNA *prop;
prop= RNA_def_property(srna, "array_length", PROP_INT, PROP_NONE);
prop= RNA_def_property(srna, "array_length", PROP_INT, PROP_UNSIGNED);
RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
RNA_def_property_int_funcs(prop, "rna_Property_array_length_get", NULL);
RNA_def_property_ui_text(prop, "Array Length", "Maximum length of the array, 0 means unlimited.");
@@ -463,14 +463,14 @@ static void rna_def_number_property(StructRNA *srna, PropertyType type)
else RNA_def_property_float_funcs(prop, "rna_FloatProperty_soft_max_get", NULL);
RNA_def_property_ui_text(prop, "Soft Maximum", "Maximum value used by buttons.");
prop= RNA_def_property(srna, "step", type, PROP_NONE);
prop= RNA_def_property(srna, "step", type, PROP_UNSIGNED);
RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
if(type == PROP_INT) RNA_def_property_int_funcs(prop, "rna_IntProperty_step_get", NULL);
else RNA_def_property_float_funcs(prop, "rna_FloatProperty_step_get", NULL);
RNA_def_property_ui_text(prop, "Step", "Step size used by number buttons, for floats 1/100th of the step size.");
if(type == PROP_FLOAT) {
prop= RNA_def_property(srna, "precision", PROP_INT, PROP_NONE);
prop= RNA_def_property(srna, "precision", PROP_INT, PROP_UNSIGNED);
RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
RNA_def_property_int_funcs(prop, "rna_FloatProperty_precision_get", NULL);
RNA_def_property_ui_text(prop, "Precision", "Number of digits after the dot used by buttons.");
@@ -500,7 +500,7 @@ static void rna_def_enum_property(BlenderRNA *brna, StructRNA *srna)
RNA_def_property_string_funcs(prop, "rna_EnumPropertyItem_identifier_get", "rna_EnumPropertyItem_identifier_length", NULL);
RNA_def_property_ui_text(prop, "Identifier", "Unique name used in the code and scripting.");
prop= RNA_def_property(srna, "value", PROP_INT, PROP_NONE);
prop= RNA_def_property(srna, "value", PROP_INT, PROP_UNSIGNED);
RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
RNA_def_property_int_funcs(prop, "rna_EnumPropertyItem_value_get", NULL);
RNA_def_property_ui_text(prop, "Value", "Value of the item.");
@@ -569,7 +569,7 @@ void RNA_def_rna(BlenderRNA *brna)
srna= RNA_def_struct(brna, "StringProperty", "String Definition");
rna_def_property(srna);
prop= RNA_def_property(srna, "max_length", PROP_INT, PROP_NONE);
prop= RNA_def_property(srna, "max_length", PROP_INT, PROP_UNSIGNED);
RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
RNA_def_property_int_funcs(prop, "rna_StringProperty_max_length_get", NULL);
RNA_def_property_ui_text(prop, "Maximum Length", "Maximum length of the string, 0 means unlimited.");
@@ -603,7 +603,7 @@ void rna_def_builtin_properties(StructRNA *srna)
RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
RNA_def_property_struct_type(prop, "Struct");
RNA_def_property_pointer_funcs(prop, "rna_builtin_type_get", NULL, NULL);
RNA_def_property_ui_text(prop, "Type", "RNA type definition.");
RNA_def_property_ui_text(prop, "RNA", "RNA type definition.");
}
#endif