Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2006-10-05 19:56:11 +0400
committerCampbell Barton <ideasman42@gmail.com>2006-10-05 19:56:11 +0400
commit4811ba51edb612241185466792815724518d92c5 (patch)
treedc71cda6151a8a974639a9aa588d269e1992516b /source
parent3bd71e9ad50fc002e4dacd0b869dadb9a580f2e5 (diff)
Python API
added list like access to mesh face colors so you can say col[0] = 255 instead of col.r= 255 more importantly 'for ch in col' and 'tuple(col)'
Diffstat (limited to 'source')
-rw-r--r--source/blender/python/api2_2x/Mesh.c73
1 files changed, 72 insertions, 1 deletions
diff --git a/source/blender/python/api2_2x/Mesh.c b/source/blender/python/api2_2x/Mesh.c
index 1bdb6ee679f..bd8545aad3b 100644
--- a/source/blender/python/api2_2x/Mesh.c
+++ b/source/blender/python/api2_2x/Mesh.c
@@ -813,6 +813,66 @@ static PyGetSetDef BPy_MCol_getseters[] = {
{NULL,NULL,NULL,NULL,NULL} /* Sentinel */
};
+
+/*----------------------------object[]---------------------------
+ sequence accessor (get)*/
+static PyObject *MCol_item(BPy_MCol * self, int i)
+{
+ unsigned char param;
+ PyObject *attr;
+ switch (i) {
+ case 0:
+ param = self->color->r;
+ break;
+ case 1:
+ param = self->color->g;
+ break;
+ case 2:
+ param = self->color->b;
+ break;
+ case 3:
+ param = self->color->a;
+ break;
+ default:
+ return EXPP_ReturnPyObjError(PyExc_IndexError,
+ "vector[index] = x: assignment index out of range\n");
+ }
+
+ attr = PyInt_FromLong( param );
+ if( attr )
+ return attr;
+
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "PyInt_FromLong() failed");
+}
+
+/*----------------------------object[]-------------------------
+ sequence accessor (set)*/
+static int MCol_ass_item(BPy_MCol * self, int i, PyObject * value)
+{
+ unsigned char *param;
+
+ switch (i) {
+ case 0:
+ param = (unsigned char *)&self->color->r;
+ break;
+ case 1:
+ param = (unsigned char *)&self->color->g;
+ break;
+ case 2:
+ param = (unsigned char *)&self->color->b;
+ break;
+ case 3:
+ param = (unsigned char *)&self->color->a;
+ break;
+ default:
+ {
+ return EXPP_ReturnIntError( PyExc_RuntimeError, "Index out of range" );
+ }
+ }
+ return EXPP_setIValueClamped( value, param, 0, 255, 'b' );
+}
+
/************************************************************************
*
* Python MCol_Type methods
@@ -831,6 +891,17 @@ static PyObject *MCol_repr( BPy_MCol * self )
(int)self->color->r, (int)self->color->a );
}
+/*-----------------PROTCOL DECLARATIONS--------------------------*/
+static PySequenceMethods MCol_SeqMethods = {
+ (inquiry) NULL, /* sq_length */
+ (binaryfunc) NULL, /* sq_concat */
+ (intargfunc) NULL, /* sq_repeat */
+ (intargfunc) MCol_item, /* sq_item */
+ (intintargfunc) NULL, /* sq_slice */
+ (intobjargproc) MCol_ass_item, /* sq_ass_item */
+ (intintobjargproc) NULL, /* sq_ass_slice */
+};
+
/************************************************************************
*
* Python MCol_Type structure definition
@@ -857,7 +928,7 @@ PyTypeObject MCol_Type = {
/* Method suites for standard classes */
NULL, /* PyNumberMethods *tp_as_number; */
- NULL, /* PySequenceMethods *tp_as_sequence; */
+ &MCol_SeqMethods, /* PySequenceMethods *tp_as_sequence; */
NULL, /* PyMappingMethods *tp_as_mapping; */
/* More standard operations (here for binary compatibility) */