diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-06-20 17:53:14 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-06-20 17:53:14 +0400 |
commit | a68ebbbccdf6bc1854c7a947685254ca912de7bf (patch) | |
tree | 93c2a524c3923d79b734e3ef68849a417487e7f8 /source | |
parent | 3511d72488501640fb9b38daff7cfed35e5beed2 (diff) |
RNA Fixes
* Python apis iterator didnt work, for example [f for f in mesh.faces] # failed.
* Python apis collection.items(), collections without names now return (index,value) pairs, better then returning nothing.
* bpy.ui and bpy.props modules were incorrectly named
* Mesh vertex colors red/blue needed to be swapped on getting/setting.
* Mesh vertex colors were not clamped.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/makesrna/intern/rna_mesh.c | 37 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 35 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_ui.c | 2 |
3 files changed, 43 insertions, 31 deletions
diff --git a/source/blender/makesrna/intern/rna_mesh.c b/source/blender/makesrna/intern/rna_mesh.c index 653f9d61fa5..5634740a4e6 100644 --- a/source/blender/makesrna/intern/rna_mesh.c +++ b/source/blender/makesrna/intern/rna_mesh.c @@ -80,76 +80,77 @@ static void rna_MEdge_crease_set(PointerRNA *ptr, float value) medge->crease= (char)(CLAMPIS(value*255.0f, 0, 255)); } +/* notice red and blue are swapped */ static void rna_MeshColor_color1_get(PointerRNA *ptr, float *values) { MCol *mcol= (MCol*)ptr->data; - values[0]= (&mcol[0].r)[0]/255.0f; + values[2]= (&mcol[0].r)[0]/255.0f; values[1]= (&mcol[0].r)[1]/255.0f; - values[2]= (&mcol[0].r)[2]/255.0f; + values[0]= (&mcol[0].r)[2]/255.0f; } static void rna_MeshColor_color1_set(PointerRNA *ptr, const float *values) { MCol *mcol= (MCol*)ptr->data; - (&mcol[0].r)[0]= (char)(CLAMPIS(values[0]*255.0f, 0, 255)); + (&mcol[0].r)[2]= (char)(CLAMPIS(values[0]*255.0f, 0, 255)); (&mcol[0].r)[1]= (char)(CLAMPIS(values[1]*255.0f, 0, 255)); - (&mcol[0].r)[2]= (char)(CLAMPIS(values[2]*255.0f, 0, 255)); + (&mcol[0].r)[0]= (char)(CLAMPIS(values[2]*255.0f, 0, 255)); } static void rna_MeshColor_color2_get(PointerRNA *ptr, float *values) { MCol *mcol= (MCol*)ptr->data; - values[0]= (&mcol[1].r)[0]/255.0f; + values[2]= (&mcol[1].r)[0]/255.0f; values[1]= (&mcol[1].r)[1]/255.0f; - values[2]= (&mcol[1].r)[2]/255.0f; + values[0]= (&mcol[1].r)[2]/255.0f; } static void rna_MeshColor_color2_set(PointerRNA *ptr, const float *values) { MCol *mcol= (MCol*)ptr->data; - (&mcol[1].r)[0]= (char)(CLAMPIS(values[0]*255.0f, 0, 255)); + (&mcol[1].r)[2]= (char)(CLAMPIS(values[0]*255.0f, 0, 255)); (&mcol[1].r)[1]= (char)(CLAMPIS(values[1]*255.0f, 0, 255)); - (&mcol[1].r)[2]= (char)(CLAMPIS(values[2]*255.0f, 0, 255)); + (&mcol[1].r)[0]= (char)(CLAMPIS(values[2]*255.0f, 0, 255)); } static void rna_MeshColor_color3_get(PointerRNA *ptr, float *values) { MCol *mcol= (MCol*)ptr->data; - values[0]= (&mcol[2].r)[0]/255.0f; + values[2]= (&mcol[2].r)[0]/255.0f; values[1]= (&mcol[2].r)[1]/255.0f; - values[2]= (&mcol[2].r)[2]/255.0f; + values[0]= (&mcol[2].r)[2]/255.0f; } static void rna_MeshColor_color3_set(PointerRNA *ptr, const float *values) { MCol *mcol= (MCol*)ptr->data; - (&mcol[2].r)[0]= (char)(CLAMPIS(values[0]*255.0f, 0, 255)); + (&mcol[2].r)[2]= (char)(CLAMPIS(values[0]*255.0f, 0, 255)); (&mcol[2].r)[1]= (char)(CLAMPIS(values[1]*255.0f, 0, 255)); - (&mcol[2].r)[2]= (char)(CLAMPIS(values[2]*255.0f, 0, 255)); + (&mcol[2].r)[0]= (char)(CLAMPIS(values[2]*255.0f, 0, 255)); } static void rna_MeshColor_color4_get(PointerRNA *ptr, float *values) { MCol *mcol= (MCol*)ptr->data; - values[0]= (&mcol[3].r)[0]/255.0f; + values[2]= (&mcol[3].r)[0]/255.0f; values[1]= (&mcol[3].r)[1]/255.0f; - values[2]= (&mcol[3].r)[2]/255.0f; + values[0]= (&mcol[3].r)[2]/255.0f; } static void rna_MeshColor_color4_set(PointerRNA *ptr, const float *values) { MCol *mcol= (MCol*)ptr->data; - (&mcol[3].r)[0]= (char)(CLAMPIS(values[0]*255.0f, 0, 255)); + (&mcol[3].r)[2]= (char)(CLAMPIS(values[0]*255.0f, 0, 255)); (&mcol[3].r)[1]= (char)(CLAMPIS(values[1]*255.0f, 0, 255)); - (&mcol[3].r)[2]= (char)(CLAMPIS(values[2]*255.0f, 0, 255)); + (&mcol[3].r)[0]= (char)(CLAMPIS(values[2]*255.0f, 0, 255)); } static int rna_Mesh_texspace_editable(PointerRNA *ptr) @@ -907,21 +908,25 @@ static void rna_def_mcol(BlenderRNA *brna) prop= RNA_def_property(srna, "color1", PROP_FLOAT, PROP_COLOR); RNA_def_property_array(prop, 3); + RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_float_funcs(prop, "rna_MeshColor_color1_get", "rna_MeshColor_color1_set", NULL); RNA_def_property_ui_text(prop, "Color 1", ""); prop= RNA_def_property(srna, "color2", PROP_FLOAT, PROP_COLOR); RNA_def_property_array(prop, 3); + RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_float_funcs(prop, "rna_MeshColor_color2_get", "rna_MeshColor_color2_set", NULL); RNA_def_property_ui_text(prop, "Color 2", ""); prop= RNA_def_property(srna, "color3", PROP_FLOAT, PROP_COLOR); RNA_def_property_array(prop, 3); + RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_float_funcs(prop, "rna_MeshColor_color3_get", "rna_MeshColor_color3_set", NULL); RNA_def_property_ui_text(prop, "Color 3", ""); prop= RNA_def_property(srna, "color4", PROP_FLOAT, PROP_COLOR); RNA_def_property_array(prop, 3); + RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_float_funcs(prop, "rna_MeshColor_color4_get", "rna_MeshColor_color4_set", NULL); RNA_def_property_ui_text(prop, "Color 4", ""); } diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 5727bb97483..e4c17e080b7 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -1011,22 +1011,30 @@ PyObject *pyrna_prop_items(BPy_PropertyRNA *self) CollectionPropertyIterator iter; PropertyRNA *nameprop; char name[256], *nameptr; + int i= 0; ret = PyList_New(0); RNA_property_collection_begin(&self->ptr, self->prop, &iter); for(; iter.valid; RNA_property_collection_next(&iter)) { - if(iter.ptr.data && (nameprop = RNA_struct_name_property(iter.ptr.type))) { - nameptr= RNA_property_string_get_alloc(&iter.ptr, nameprop, name, sizeof(name)); - + if(iter.ptr.data) { /* add to python list */ - item = Py_BuildValue("(NN)", PyUnicode_FromString( nameptr ), pyrna_struct_CreatePyObject(&iter.ptr)); + item= PyTuple_New(2); + if(nameprop = RNA_struct_name_property(iter.ptr.type)) { + nameptr= RNA_property_string_get_alloc(&iter.ptr, nameprop, name, sizeof(name)); + PyTuple_SET_ITEM(item, 0, PyUnicode_FromString( nameptr )); + if ((char *)&name != nameptr) + MEM_freeN(nameptr); + } + else { + PyTuple_SET_ITEM(item, 0, PyLong_FromSsize_t(i)); /* a bit strange but better then returning an empty list */ + } + PyTuple_SET_ITEM(item, 1, pyrna_struct_CreatePyObject(&iter.ptr)); + PyList_Append(ret, item); Py_DECREF(item); - /* done */ - if ((char *)&name != nameptr) - MEM_freeN(nameptr); + i++; } } RNA_property_collection_end(&iter); @@ -1039,23 +1047,22 @@ PyObject *pyrna_prop_items(BPy_PropertyRNA *self) PyObject *pyrna_prop_values(BPy_PropertyRNA *self) { PyObject *ret; + if (RNA_property_type(self->prop) != PROP_COLLECTION) { PyErr_SetString( PyExc_TypeError, "values() is only valid for collection types" ); ret = NULL; } else { PyObject *item; CollectionPropertyIterator iter; - PropertyRNA *nameprop; - + PropertyRNA *iterprop; ret = PyList_New(0); + //iterprop= RNA_struct_iterator_property(self->ptr.type); RNA_property_collection_begin(&self->ptr, self->prop, &iter); for(; iter.valid; RNA_property_collection_next(&iter)) { - if(iter.ptr.data && (nameprop = RNA_struct_name_property(iter.ptr.type))) { - item = pyrna_struct_CreatePyObject(&iter.ptr); - PyList_Append(ret, item); - Py_DECREF(item); - } + item = pyrna_struct_CreatePyObject(&iter.ptr); + PyList_Append(ret, item); + Py_DECREF(item); } RNA_property_collection_end(&iter); } diff --git a/source/blender/python/intern/bpy_ui.c b/source/blender/python/intern/bpy_ui.c index c15315ca350..088fe436c69 100644 --- a/source/blender/python/intern/bpy_ui.c +++ b/source/blender/python/intern/bpy_ui.c @@ -373,7 +373,7 @@ static struct PyMethodDef ui_methods[] = { #if PY_VERSION_HEX >= 0x03000000 static struct PyModuleDef ui_module = { PyModuleDef_HEAD_INIT, - "bpyui", + "bpy.ui", "", -1,/* multiple "initialization" just copies the module dict. */ ui_methods, |