41
42
#include "Texture.h"
42
43
#include "constant.h"
43
44
#include "gen_utils.h"
47
47
/*****************************************************************************/
48
48
/* Python BPy_MTex methods declarations: */
49
49
/*****************************************************************************/
50
static PyObject *MTex_setTex(BPy_MTex *self, PyObject *args);
50
static PyObject *MTex_setTex( BPy_MTex * self, PyObject * args );
52
52
/*****************************************************************************/
53
53
/* Python method structure definition for Blender.Texture.MTex module: */
54
54
/*****************************************************************************/
55
55
struct PyMethodDef M_MTex_methods[] = {
59
59
/*****************************************************************************/
60
60
/* Python BPy_MTex methods table: */
61
61
/*****************************************************************************/
62
62
static PyMethodDef BPy_MTex_methods[] = {
63
/* name, method, flags, doc */
64
{"setTex", (PyCFunction)MTex_setTex, METH_VARARGS,
65
"(i) - Set MTex Texture"},
63
/* name, method, flags, doc */
64
{"setTex", ( PyCFunction ) MTex_setTex, METH_VARARGS,
65
"(i) - Set MTex Texture"},
69
69
/*****************************************************************************/
70
70
/* Python MTex_Type callback function prototypes: */
71
71
/*****************************************************************************/
72
static void MTex_dealloc (BPy_MTex *self);
73
static int MTex_setAttr (BPy_MTex *self, char *name, PyObject *v);
74
static int MTex_compare (BPy_MTex *a, BPy_MTex *b);
75
static PyObject *MTex_getAttr (BPy_MTex *self, char *name);
76
static PyObject *MTex_repr (BPy_MTex *self);
72
static void MTex_dealloc( BPy_MTex * self );
73
static int MTex_setAttr( BPy_MTex * self, char *name, PyObject * v );
74
static int MTex_compare( BPy_MTex * a, BPy_MTex * b );
75
static PyObject *MTex_getAttr( BPy_MTex * self, char *name );
76
static PyObject *MTex_repr( BPy_MTex * self );
79
79
/*****************************************************************************/
80
80
/* Python MTex_Type structure definition: */
81
81
/*****************************************************************************/
82
PyTypeObject MTex_Type =
84
PyObject_HEAD_INIT(NULL)
86
"Blender MTex", /* tp_name */
87
sizeof (BPy_MTex), /* tp_basicsize */
90
(destructor)MTex_dealloc, /* tp_dealloc */
92
(getattrfunc)MTex_getAttr, /* tp_getattr */
93
(setattrfunc)MTex_setAttr, /* tp_setattr */
94
(cmpfunc)MTex_compare, /* tp_compare */
95
(reprfunc)MTex_repr, /* tp_repr */
97
0, /* tp_as_sequence */
98
0, /* tp_as_mapping */
82
PyTypeObject MTex_Type = {
83
PyObject_HEAD_INIT( NULL )
85
"Blender MTex", /* tp_name */
86
sizeof( BPy_MTex ), /* tp_basicsize */
89
( destructor ) MTex_dealloc, /* tp_dealloc */
91
( getattrfunc ) MTex_getAttr, /* tp_getattr */
92
( setattrfunc ) MTex_setAttr, /* tp_setattr */
93
( cmpfunc ) MTex_compare, /* tp_compare */
94
( reprfunc ) MTex_repr, /* tp_repr */
96
0, /* tp_as_sequence */
97
0, /* tp_as_mapping */
108
PyObject *MTex_Init (void)
112
MTex_Type.ob_type = &PyType_Type;
114
submodule = Py_InitModule("Blender.Texture.MTex", M_MTex_methods);
119
PyObject *MTex_CreatePyObject (MTex *mtex)
123
pymtex = (BPy_MTex *) PyObject_NEW (BPy_MTex, &MTex_Type);
125
return EXPP_ReturnPyObjError (PyExc_MemoryError,
126
"couldn't create BPy_MTex PyObject");
129
return (PyObject *) pymtex;
132
MTex *MTex_FromPyObject (PyObject *pyobj)
134
return ((BPy_MTex *)pyobj)->mtex;
138
int MTex_CheckPyObject (PyObject *pyobj)
140
return (pyobj->ob_type == &MTex_Type);
107
PyObject *MTex_Init( void )
111
MTex_Type.ob_type = &PyType_Type;
113
submodule = Py_InitModule( "Blender.Texture.MTex", M_MTex_methods );
118
PyObject *MTex_CreatePyObject( MTex * mtex )
122
pymtex = ( BPy_MTex * ) PyObject_NEW( BPy_MTex, &MTex_Type );
124
return EXPP_ReturnPyObjError( PyExc_MemoryError,
125
"couldn't create BPy_MTex PyObject" );
128
return ( PyObject * ) pymtex;
131
MTex *MTex_FromPyObject( PyObject * pyobj )
133
return ( ( BPy_MTex * ) pyobj )->mtex;
137
int MTex_CheckPyObject( PyObject * pyobj )
139
return ( pyobj->ob_type == &MTex_Type );
145
144
/* Python BPy_MTex methods: */
146
145
/*****************************************************************************/
148
static PyObject *MTex_setTex(BPy_MTex *self, PyObject *args)
150
BPy_Texture *pytex = NULL;
151
if (!PyArg_ParseTuple(args, "O!", &Texture_Type, &pytex))
152
return EXPP_ReturnPyObjError (PyExc_TypeError,
153
"expected Texture argument");
156
self->mtex->tex->id.us--;
158
self->mtex->tex = Texture_FromPyObject((PyObject*)pytex);
164
static void MTex_dealloc (BPy_MTex *self)
169
static PyObject *MTex_getAttr (BPy_MTex *self, char *name)
171
if (STREQ(name, "tex"))
174
return Texture_CreatePyObject (self->mtex->tex);
181
else if (STREQ(name, "texco"))
182
return PyInt_FromLong(self->mtex->texco);
183
else if (STREQ(name, "mapto"))
184
return PyInt_FromLong(self->mtex->mapto);
186
else if (STREQ(name, "__members__"))
187
return Py_BuildValue("[s,s,s]", "tex", "texco", "mapto");
189
/* not an attribute, search the methods table */
190
return Py_FindMethod(BPy_MTex_methods, (PyObject *)self, name);
193
static int MTex_setAttr (BPy_MTex *self, char *name, PyObject *value)
196
PyObject *error = NULL;
198
/* Put "value" in a tuple, because we want to pass it to functions *
199
* that only accept PyTuples. */
200
valtuple = Py_BuildValue("(O)", value);
202
return EXPP_ReturnIntError(PyExc_MemoryError,
203
"MTex_setAttr: couldn't create PyTuple");
205
if (STREQ(name, "tex"))
206
error = MTex_setTex(self, valtuple);
207
else if (STREQ(name, "texco"))
209
if (PyInt_Check(value))
211
int texco = PyInt_AsLong(value);
212
/* TODO: sanity-check this input! */
213
self->mtex->texco = texco;
214
Py_INCREF (Py_None); /* because we decref it below */
218
else if (STREQ(name, "mapto"))
220
if (PyInt_Check(value))
222
int mapto = PyInt_AsLong(value);
223
/* TODO: sanity-check this input! */
224
self->mtex->mapto = mapto;
225
Py_INCREF (Py_None); /* because we decref it below */
233
return EXPP_ReturnIntError (PyExc_KeyError, "attribute not found");
236
Py_DECREF (valtuple);
238
if (error != Py_None) return -1;
240
/* Py_None was INCREF'd by the set*() function, so we need to DECREF it */
246
static int MTex_compare (BPy_MTex *a, BPy_MTex *b)
248
return (a->mtex == b->mtex) ? 0 : -1;
251
static PyObject *MTex_repr (BPy_MTex *self)
253
return PyString_FromFormat("[MTex]");
147
static PyObject *MTex_setTex( BPy_MTex * self, PyObject * args )
149
BPy_Texture *pytex = NULL;
150
if( !PyArg_ParseTuple( args, "O!", &Texture_Type, &pytex ) )
151
return EXPP_ReturnPyObjError( PyExc_TypeError,
152
"expected Texture argument" );
154
if( self->mtex->tex )
155
self->mtex->tex->id.us--;
157
self->mtex->tex = Texture_FromPyObject( ( PyObject * ) pytex );
159
Py_INCREF( Py_None );
163
static void MTex_dealloc( BPy_MTex * self )
165
PyObject_DEL( self );
168
static PyObject *MTex_getAttr( BPy_MTex * self, char *name )
170
if( STREQ( name, "tex" ) ) {
171
if( self->mtex->tex )
172
return Texture_CreatePyObject( self->mtex->tex );
174
Py_INCREF( Py_None );
177
} else if( STREQ( name, "texco" ) )
178
return PyInt_FromLong( self->mtex->texco );
179
else if( STREQ( name, "mapto" ) )
180
return PyInt_FromLong( self->mtex->mapto );
182
else if( STREQ( name, "__members__" ) )
183
return Py_BuildValue( "[s,s,s]", "tex", "texco", "mapto" );
185
/* not an attribute, search the methods table */
186
return Py_FindMethod( BPy_MTex_methods, ( PyObject * ) self, name );
189
static int MTex_setAttr( BPy_MTex * self, char *name, PyObject * value )
192
PyObject *error = NULL;
194
/* Put "value" in a tuple, because we want to pass it to functions *
195
* that only accept PyTuples. */
196
valtuple = Py_BuildValue( "(O)", value );
198
return EXPP_ReturnIntError( PyExc_MemoryError,
199
"MTex_setAttr: couldn't create PyTuple" );
201
if( STREQ( name, "tex" ) )
202
error = MTex_setTex( self, valtuple );
203
else if( STREQ( name, "texco" ) ) {
204
if( PyInt_Check( value ) ) {
205
int texco = PyInt_AsLong( value );
206
/* TODO: sanity-check this input! */
207
self->mtex->texco = texco;
208
Py_INCREF( Py_None ); /* because we decref it below */
211
} else if( STREQ( name, "mapto" ) ) {
212
if( PyInt_Check( value ) ) {
213
int mapto = PyInt_AsLong( value );
214
/* TODO: sanity-check this input! */
215
self->mtex->mapto = mapto;
216
Py_INCREF( Py_None ); /* because we decref it below */
223
Py_DECREF( valtuple );
224
return EXPP_ReturnIntError( PyExc_KeyError,
225
"attribute not found" );
228
Py_DECREF( valtuple );
230
if( error != Py_None )
233
/* Py_None was INCREF'd by the set*() function, so we need to DECREF it */
234
Py_DECREF( Py_None );
239
static int MTex_compare( BPy_MTex * a, BPy_MTex * b )
241
return ( a->mtex == b->mtex ) ? 0 : -1;
244
static PyObject *MTex_repr( BPy_MTex * self )
246
return PyString_FromFormat( "[MTex]" );