diff options
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/python/api2_2x/BGL.c | 1486 | ||||
-rw-r--r-- | source/blender/python/api2_2x/BGL.h | 424 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Blender.c | 7 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Camera.c | 771 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Camera.h | 2 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Draw.c | 741 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Draw.h | 306 | ||||
-rw-r--r-- | source/blender/python/api2_2x/EXPP_interface.c | 130 | ||||
-rw-r--r-- | source/blender/python/api2_2x/EXPP_interface.h | 35 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Image.c | 380 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Image.h | 15 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Lamp.c | 1447 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Lamp.h | 78 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Window.c | 200 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Window.h | 129 | ||||
-rw-r--r-- | source/blender/python/api2_2x/gen_utils.c | 15 | ||||
-rw-r--r-- | source/blender/python/api2_2x/gen_utils.h | 8 | ||||
-rw-r--r-- | source/blender/python/api2_2x/modules.h | 16 |
18 files changed, 4380 insertions, 1810 deletions
diff --git a/source/blender/python/api2_2x/BGL.c b/source/blender/python/api2_2x/BGL.c new file mode 100644 index 00000000000..858b343bfe8 --- /dev/null +++ b/source/blender/python/api2_2x/BGL.c @@ -0,0 +1,1486 @@ +/* + * + * ***** BEGIN GPL/BL DUAL 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. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * 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. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * This is a new part of Blender. + * + * Contributor(s): Willian P. Germano + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** +*/ + +/* This file is the Blender.BGL part of opy_draw.c, from the old + * bpython/intern dir, with minor changes to adapt it to the new Python + * implementation. The BGL submodule "wraps" OpenGL functions and constants, + * allowing script writers to make OpenGL calls in their Python scripts. */ + +#include "BGL.h" + +static int type_size(int type) +{ + switch (type) { + case GL_BYTE: + return sizeof(char); + case GL_SHORT: + return sizeof(short); + case GL_INT: + return sizeof(int); + case GL_FLOAT: + return sizeof(float); + } + return -1; +} + +static Buffer *make_buffer(int type, int ndimensions, int *dimensions) +{ + Buffer *buffer; + void *buf= NULL; + int i, size, length; + + length= 1; + for (i=0; i<ndimensions; i++) length*= dimensions[i]; + + size= type_size(type); + + buf= MEM_mallocN(length*size, "Buffer buffer"); + + buffer= (Buffer *) PyObject_NEW(Buffer, &Buffer_Type); + buffer->parent= NULL; + buffer->ndimensions= ndimensions; + buffer->dimensions= dimensions; + buffer->type= type; + buffer->buf.asvoid= buf; + + for (i= 0; i<length; i++) { + if (type==GL_BYTE) + buffer->buf.asbyte[i]= 0; + + else if (type==GL_SHORT) + buffer->buf.asshort[i]= 0; + + else if (type==GL_INT) + buffer->buf.asint[i]= 0; + + else if (type==GL_FLOAT) + buffer->buf.asfloat[i]= 0.0; + } + + return buffer; +} + +static PyObject *Method_Buffer (PyObject *self, PyObject *args) +{ + PyObject *length_ob= NULL, *template= NULL; + Buffer *buffer; + + int i, type; + int *dimensions = 0, ndimensions = 0; + + if (!PyArg_ParseTuple(args, "iO|O", &type, &length_ob, &template)) + return EXPP_ReturnPyObjError(PyExc_AttributeError, + "expected an int and one or two PyObjects"); + + if (type!=GL_BYTE && type!=GL_SHORT && type!=GL_INT && type!=GL_FLOAT) { + PyErr_SetString(PyExc_AttributeError, "type"); + return NULL; + } + + if (PyNumber_Check(length_ob)) { + ndimensions= 1; + dimensions= MEM_mallocN(ndimensions*sizeof(int), "Buffer dimensions"); + dimensions[0]= PyInt_AsLong(length_ob); + + } else if (PySequence_Check(length_ob)) { + ndimensions= PySequence_Length(length_ob); + dimensions= MEM_mallocN(ndimensions*sizeof(int), "Buffer dimensions"); + + for (i=0; i<ndimensions; i++) { + PyObject *ob= PySequence_GetItem(length_ob, i); + + if (!PyNumber_Check(ob)) dimensions[i]= 1; + else dimensions[i]= PyInt_AsLong(ob); + + Py_DECREF(ob); + } + } + + buffer= make_buffer(type, ndimensions, dimensions); + if (template && ndimensions) { + if (Buffer_ass_slice((PyObject *) buffer, 0, dimensions[0], template)) { + Py_DECREF(buffer); + return NULL; + } + } + + return (PyObject *) buffer; +} + +/*@ Buffer sequence methods */ + +static int Buffer_len(PyObject *self) +{ + Buffer *buf= (Buffer *) self; + + return buf->dimensions[0]; +} + +static PyObject *Buffer_item(PyObject *self, int i) +{ + Buffer *buf= (Buffer *) self; + + if (i >= buf->dimensions[0]) { + PyErr_SetString(PyExc_IndexError, "array index out of range"); + return NULL; + } + + if (buf->ndimensions==1) { + switch (buf->type) { + case GL_BYTE: return Py_BuildValue("b", buf->buf.asbyte[i]); + case GL_SHORT: return Py_BuildValue("h", buf->buf.asshort[i]); + case GL_INT: return Py_BuildValue("i", buf->buf.asint[i]); + case GL_FLOAT: return Py_BuildValue("f", buf->buf.asfloat[i]); + } + } else { + Buffer *newbuf; + int j, length, size; + + length= 1; + for (j=1; j<buf->ndimensions; j++) { + length*= buf->dimensions[j]; + } + size= type_size(buf->type); + + newbuf= (Buffer *) PyObject_NEW(Buffer, &Buffer_Type); + + Py_INCREF(self); + newbuf->parent= self; + + newbuf->ndimensions= buf->ndimensions-1; + newbuf->type= buf->type; + newbuf->buf.asvoid= buf->buf.asbyte + i*length*size; + + newbuf->dimensions= MEM_mallocN(newbuf->ndimensions*sizeof(int), + "Buffer dimensions"); + memcpy(newbuf->dimensions, buf->dimensions+1, + newbuf->ndimensions*sizeof(int)); + + return (PyObject *) newbuf; + } + + return NULL; +} + +static PyObject *Buffer_slice(PyObject *self, int begin, int end) +{ + Buffer *buf= (Buffer *) self; + PyObject *list; + int count; + + if (begin<0) begin= 0; + if (end>buf->dimensions[0]) end= buf->dimensions[0]; + if (begin>end) begin= end; + + list= PyList_New(end-begin); + + for (count= begin; count<end; count++) + PyList_SetItem(list, count-begin, Buffer_item(self, count)); + + return list; +} + +static int Buffer_ass_item(PyObject *self, int i, PyObject *v) +{ + Buffer *buf= (Buffer *) self; + + if (i >= buf->dimensions[0]) { + PyErr_SetString(PyExc_IndexError, "array assignment index out of range"); + return -1; + } + + if (buf->ndimensions!=1) { + PyObject *row= Buffer_item(self, i); + int ret; + + if (!row) return -1; + + ret= Buffer_ass_slice(row, 0, buf->dimensions[1], v); + Py_DECREF(row); + + return ret; + } + + if (buf->type==GL_BYTE) { + if (!PyArg_Parse(v, "b;Coordinates must be ints", &buf->buf.asbyte[i])) + return -1; + + } else if (buf->type==GL_SHORT) { + if (!PyArg_Parse(v, "h;Coordinates must be ints", &buf->buf.asshort[i])) + return -1; + + } else if (buf->type==GL_INT) { + if (!PyArg_Parse(v, "i;Coordinates must be ints", &buf->buf.asint[i])) + return -1; + + } else if (buf->type==GL_FLOAT) { + if (!PyArg_Parse(v, "f;Coordinates must be floats", &buf->buf.asfloat[i])) + return -1; + } + + return 0; +} + +static int Buffer_ass_slice(PyObject *self, int begin, int end, PyObject *seq) +{ + Buffer *buf= (Buffer *) self; + PyObject *item; + int count, err=0; + + if (begin<0) begin= 0; + if (end>buf->dimensions[0]) end= buf->dimensions[0]; + if (begin>end) begin= end; + + if (!PySequence_Check(seq)) { + PyErr_SetString(PyExc_TypeError, + "illegal argument type for built-in operation"); + return -1; + } + + if (PySequence_Length(seq)!=(end-begin)) { + PyErr_SetString(PyExc_TypeError, "size mismatch in assignment"); + return -1; + } + + for (count= begin; count<end; count++) { + item= PySequence_GetItem(seq, count-begin); + err= Buffer_ass_item(self, count, item); + Py_DECREF(item); + + if (err) break; + } + + return err; +} + +static void Buffer_dealloc(PyObject *self) +{ + Buffer *buf= (Buffer *) self; + + if (buf->parent) Py_DECREF(buf->parent); + else MEM_freeN(buf->buf.asvoid); + + MEM_freeN(buf->dimensions); + + PyMem_DEL(self); +} + +static PyObject *Buffer_tolist(PyObject *self) +{ + int i, len= ((Buffer *)self)->dimensions[0]; + PyObject *list= PyList_New(len); + + for (i=0; i<len; i++) { + PyList_SetItem(list, i, Buffer_item(self, i)); + } + + return list; +} + +static PyObject *Buffer_dimensions(PyObject *self) +{ + Buffer *buffer= (Buffer *) self; + PyObject *list= PyList_New(buffer->ndimensions); + int i; + + for (i= 0; i<buffer->ndimensions; i++) { + PyList_SetItem(list, i, PyInt_FromLong(buffer->dimensions[i])); + } + + return list; +} + +static PyObject *Buffer_getattr(PyObject *self, char *name) +{ + if (strcmp(name, "list")==0) return Buffer_tolist(self); + else if (strcmp(name, "dimensions")==0) return Buffer_dimensions(self); + + PyErr_SetString(PyExc_AttributeError, name); + return NULL; +} + +static PyObject *Buffer_repr(PyObject *self) +{ + PyObject *list= Buffer_tolist(self); + PyObject *repr= PyObject_Repr(list); + Py_DECREF(list); + + return repr; +} + +/* BGL_Wrap defined in BGL.h */ +#ifndef __APPLE__ +BGL_Wrap(2, Accum, void, (GLenum, GLfloat)) +BGL_Wrap(2, AlphaFunc, void, (GLenum, GLclampf)) +BGL_Wrap(3, AreTexturesResident, GLboolean, (GLsizei, GLuintP, GLbooleanP)) +BGL_Wrap(1, Begin, void, (GLenum)) +BGL_Wrap(2, BindTexture, void, (GLenum, GLuint)) +BGL_Wrap(7, Bitmap, void, (GLsizei, GLsizei, GLfloat, + GLfloat, GLfloat, GLfloat, GLubyteP)) +BGL_Wrap(2, BlendFunc, void, (GLenum, GLenum)) +BGL_Wrap(1, CallList, void, (GLuint)) +BGL_Wrap(3, CallLists, void, (GLsizei, GLenum, GLvoidP)) +BGL_Wrap(1, Clear, void, (GLbitfield)) +BGL_Wrap(4, ClearAccum, void, (GLfloat, GLfloat, GLfloat, GLfloat)) +BGL_Wrap(4, ClearColor, void, (GLclampf, GLclampf, GLclampf, GLclampf)) +BGL_Wrap(1, ClearDepth, void, (GLclampd)) +BGL_Wrap(1, ClearIndex, void, (GLfloat)) +BGL_Wrap(1, ClearStencil, void, (GLint)) +BGL_Wrap(2, ClipPlane, void, (GLenum, GLdoubleP)) +BGL_Wrap(3, Color3b, void, (GLbyte, GLbyte, GLbyte)) +BGL_Wrap(1, Color3bv, void, (GLbyteP)) +BGL_Wrap(3, Color3d, void, (GLdouble, GLdouble, GLdouble)) +BGL_Wrap(1, Color3dv, void, (GLdoubleP)) +BGL_Wrap(3, Color3f, void, (GLfloat, GLfloat, GLfloat)) +BGL_Wrap(1, Color3fv, void, (GLfloatP)) +BGL_Wrap(3, Color3i, void, (GLint, GLint, GLint)) +BGL_Wrap(1, Color3iv, void, (GLintP)) +BGL_Wrap(3, Color3s, void, (GLshort, GLshort, GLshort)) +BGL_Wrap(1, Color3sv, void, (GLshortP)) +BGL_Wrap(3, Color3ub, void, (GLubyte, GLubyte, GLubyte)) +BGL_Wrap(1, Color3ubv, void, (GLubyteP)) +BGL_Wrap(3, Color3ui, void, (GLuint, GLuint, GLuint)) +BGL_Wrap(1, Color3uiv, void, (GLuintP)) +BGL_Wrap(3, Color3us, void, (GLushort, GLushort, GLushort)) +BGL_Wrap(1, Color3usv, void, (GLushortP)) +BGL_Wrap(4, Color4b, void, (GLbyte, GLbyte, GLbyte, GLbyte)) +BGL_Wrap(1, Color4bv, void, (GLbyteP)) +BGL_Wrap(4, Color4d, void, (GLdouble, GLdouble, GLdouble, GLdouble)) +BGL_Wrap(1, Color4dv, void, (GLdoubleP)) +BGL_Wrap(4, Color4f, void, (GLfloat, GLfloat, GLfloat, GLfloat)) +BGL_Wrap(1, Color4fv, void, (GLfloatP)) +BGL_Wrap(4, Color4i, void, (GLint, GLint, GLint, GLint)) +BGL_Wrap(1, Color4iv, void, (GLintP)) +BGL_Wrap(4, Color4s, void, (GLshort, GLshort, GLshort, GLshort)) +BGL_Wrap(1, Color4sv, void, (GLshortP)) +BGL_Wrap(4, Color4ub, void, (GLubyte, GLubyte, GLubyte, GLubyte)) +BGL_Wrap(1, Color4ubv, void, (GLubyteP)) +BGL_Wrap(4, Color4ui, void, (GLuint, GLuint, GLuint, GLuint)) +BGL_Wrap(1, Color4uiv, void, (GLuintP)) +BGL_Wrap(4, Color4us, void, (GLushort, GLushort, GLushort, GLushort)) +BGL_Wrap(1, Color4usv, void, (GLushortP)) +BGL_Wrap(4, ColorMask, void, (GLboolean, GLboolean, GLboolean, GLboolean)) +BGL_Wrap(2, ColorMaterial, void, (GLenum, GLenum)) +BGL_Wrap(5, CopyPixels, void, (GLint, GLint, GLsizei, GLsizei, GLenum)) +BGL_Wrap(1, CullFace, void, (GLenum)) +BGL_Wrap(2, DeleteLists, void, (GLuint, GLsizei)) +BGL_Wrap(2, DeleteTextures, void, (GLsizei, GLuintP)) +BGL_Wrap(1, DepthFunc, void, (GLenum)) +BGL_Wrap(1, DepthMask, void, (GLboolean)) +BGL_Wrap(2, DepthRange, void, (GLclampd, GLclampd)) +BGL_Wrap(1, Disable, void, (GLenum)) +BGL_Wrap(1, DrawBuffer, void, (GLenum)) +BGL_Wrap(5, DrawPixels, void, (GLsizei, GLsizei, GLenum, GLenum, GLvoidP)) +BGL_Wrap(1, EdgeFlag, void, (GLboolean)) +BGL_Wrap(1, EdgeFlagv, void, (GLbooleanP)) +BGL_Wrap(1, Enable, void, (GLenum)) +BGL_Wrap(1, End, void, (void)) +BGL_Wrap(1, EndList, void, (void)) +BGL_Wrap(1, EvalCoord1d, void, (GLdouble)) +BGL_Wrap(1, EvalCoord1dv, void, (GLdoubleP)) +BGL_Wrap(1, EvalCoord1f, void, (GLfloat)) +BGL_Wrap(1, EvalCoord1fv, void, (GLfloatP)) +BGL_Wrap(2, EvalCoord2d, void, (GLdouble, GLdouble)) +BGL_Wrap(1, EvalCoord2dv, void, (GLdoubleP)) +BGL_Wrap(2, EvalCoord2f, void, (GLfloat, GLfloat)) +BGL_Wrap(1, EvalCoord2fv, void, (GLfloatP)) +BGL_Wrap(3, EvalMesh1, void, (GLenum, GLint, GLint)) +BGL_Wrap(5, EvalMesh2, void, (GLenum, GLint, GLint, GLint, GLint)) +BGL_Wrap(1, EvalPoint1, void, (GLint)) +BGL_Wrap(2, EvalPoint2, void, (GLint, GLint)) +BGL_Wrap(3, FeedbackBuffer, void, (GLsizei, GLenum, GLfloatP)) +BGL_Wrap(1, Finish, void, (void)) +BGL_Wrap(1, Flush, void, (void)) +BGL_Wrap(2, Fogf, void, (GLenum, GLfloat)) +BGL_Wrap(2, Fogfv, void, (GLenum, GLfloatP)) +BGL_Wrap(2, Fogi, void, (GLenum, GLint)) +BGL_Wrap(2, Fogiv, void, (GLenum, GLintP)) +BGL_Wrap(1, FrontFace, void, (GLenum)) +BGL_Wrap(6, Frustum, void, (GLdouble, GLdouble, + GLdouble, GLdouble, GLdouble, GLdouble)) +BGL_Wrap(1, GenLists, GLuint, (GLsizei)) +BGL_Wrap(2, GenTextures, void, (GLsizei, GLuintP)) +BGL_Wrap(2, GetBooleanv, void, (GLenum, GLbooleanP)) +BGL_Wrap(2, GetClipPlane, void, (GLenum, GLdoubleP)) +BGL_Wrap(2, GetDoublev, void, (GLenum, GLdoubleP)) +BGL_Wrap(1, GetError, GLenum, (void)) +BGL_Wrap(2, GetFloatv, void, (GLenum, GLfloatP)) +BGL_Wrap(2, GetIntegerv, void, (GLenum, GLintP)) +BGL_Wrap(3, GetLightfv, void, (GLenum, GLenum, GLfloatP)) +BGL_Wrap(3, GetLightiv, void, (GLenum, GLenum, GLintP)) +BGL_Wrap(3, GetMapdv, void, (GLenum, GLenum, GLdoubleP)) +BGL_Wrap(3, GetMapfv, void, (GLenum, GLenum, GLfloatP)) +BGL_Wrap(3, GetMapiv, void, (GLenum, GLenum, GLintP)) +BGL_Wrap(3, GetMaterialfv, void, (GLenum, GLenum, GLfloatP)) +BGL_Wrap(3, GetMaterialiv, void, (GLenum, GLenum, GLintP)) +BGL_Wrap(2, GetPixelMapfv, void, (GLenum, GLfloatP)) +BGL_Wrap(2, GetPixelMapuiv, void, (GLenum, GLuintP)) +BGL_Wrap(2, GetPixelMapusv, void, (GLenum, GLushortP)) +BGL_Wrap(1, GetPolygonStipple,void, (GLubyteP)) +BGL_Wrap(1, GetString, GLstring, (GLenum)) +BGL_Wrap(3, GetTexEnvfv, void, (GLenum, GLenum, GLfloatP)) +BGL_Wrap(3, GetTexEnviv, void, (GLenum, GLenum, GLintP)) +BGL_Wrap(3, GetTexGendv, void, (GLenum, GLenum, GLdoubleP)) +BGL_Wrap(3, GetTexGenfv, void, (GLenum, GLenum, GLfloatP)) +BGL_Wrap(3, GetTexGeniv, void, (GLenum, GLenum, GLintP)) +BGL_Wrap(5, GetTexImage, void, (GLenum, GLint, GLenum, GLenum, GLvoidP)) +BGL_Wrap(4, GetTexLevelParameterfv, void, (GLenum, GLint, GLenum, GLfloatP)) +BGL_Wrap(4, GetTexLevelParameteriv, void, (GLenum, GLint, GLenum, GLintP)) +BGL_Wrap(3, GetTexParameterfv, void, (GLenum, GLenum, GLfloatP)) +BGL_Wrap(3, GetTexParameteriv, void, (GLenum, GLenum, GLintP)) +BGL_Wrap(2, Hint, void, (GLenum, GLenum)) +BGL_Wrap(1, IndexMask, void, (GLuint)) +BGL_Wrap(1, Indexd, void, (GLdouble)) +BGL_Wrap(1, Indexdv, void, (GLdoubleP)) +BGL_Wrap(1, Indexf, void, (GLfloat)) +BGL_Wrap(1, Indexfv, void, (GLfloatP)) +BGL_Wrap(1, Indexi, void, (GLint)) +BGL_Wrap(1, Indexiv, void, (GLintP)) +BGL_Wrap(1, Indexs, void, (GLshort)) +BGL_Wrap(1, Indexsv, void, (GLshortP)) +BGL_Wrap(1, InitNames, void, (void)) +BGL_Wrap(1, IsEnabled, GLboolean, (GLenum)) +BGL_Wrap(1, IsList, GLboolean, (GLuint)) +BGL_Wrap(1, IsTexture, GLboolean, (GLuint)) +BGL_Wrap(2, LightModelf, void, (GLenum, GLfloat)) +BGL_Wrap(2, LightModelfv, void, (GLenum, GLfloatP)) +BGL_Wrap(2, LightModeli, void, (GLenum, GLint)) +BGL_Wrap(2, LightModeliv, void, (GLenum, GLintP)) +BGL_Wrap(3, Lightf, void, (GLenum, GLenum, GLfloat)) +BGL_Wrap(3, Lightfv, void, (GLenum, GLenum, GLfloatP)) +BGL_Wrap(3, Lighti, void, (GLenum, GLenum, GLint)) +BGL_Wrap(3, Lightiv, void, (GLenum, GLenum, GLintP)) +BGL_Wrap(2, LineStipple, void, (GLint, GLushort)) +BGL_Wrap(1, LineWidth, void, (GLfloat)) +BGL_Wrap(1, ListBase, void, (GLuint)) +BGL_Wrap(1, LoadIdentity, void, (void)) +BGL_Wrap(1, LoadMatrixd, void, (GLdoubleP)) +BGL_Wrap(1, LoadMatrixf, void, (GLfloatP)) +BGL_Wrap(1, LoadName, void, (GLuint)) +BGL_Wrap(1, LogicOp, void, (GLenum)) +BGL_Wrap(6, Map1d, void, (GLenum, GLdouble, GLdouble, + GLint, GLint, GLdoubleP)) +BGL_Wrap(6, Map1f, void, (GLenum, GLfloat, GLfloat, + GLint, GLint, GLfloatP)) +BGL_Wrap(10, Map2d, void, (GLenum, GLdouble, GLdouble, + GLint, GLint, GLdouble, GLdouble, GLint, GLint, GLdoubleP)) +BGL_Wrap(10, Map2f, void, (GLenum, GLfloat, GLfloat, + GLint, GLint, GLfloat, GLfloat, GLint, GLint, GLfloatP)) +BGL_Wrap(3, MapGrid1d, void, (GLint, GLdouble, GLdouble)) +BGL_Wrap(3, MapGrid1f, void, (GLint, GLfloat, GLfloat)) +BGL_Wrap(6, MapGrid2d, void, (GLint, GLdouble, GLdouble, + GLint, GLdouble, GLdouble)) +BGL_Wrap(6, MapGrid2f, void, (GLint, GLfloat, GLfloat, + GLint, GLfloat, GLfloat)) +BGL_Wrap(3, Materialf, void, (GLenum, GLenum, GLfloat)) +BGL_Wrap(3, Materialfv, void, (GLenum, GLenum, GLfloatP)) +BGL_Wrap(3, Materiali, void, (GLenum, GLenum, GLint)) +BGL_Wrap(3, Materialiv, void, (GLenum, GLenum, GLintP)) +BGL_Wrap(1, MatrixMode, void, (GLenum)) +BGL_Wrap(1, MultMatrixd, void, (GLdoubleP)) +BGL_Wrap(1, MultMatrixf, void, (GLfloatP)) +BGL_Wrap(2, NewList, void, (GLuint, GLenum)) +BGL_Wrap(3, Normal3b, void, (GLbyte, GLbyte, GLbyte)) +BGL_Wrap(1, Normal3bv, void, (GLbyteP)) +BGL_Wrap(3, Normal3d, void, (GLdouble, GLdouble, GLdouble)) +BGL_Wrap(1, Normal3dv, void, (GLdoubleP)) +BGL_Wrap(3, Normal3f, void, (GLfloat, GLfloat, GLfloat)) +BGL_Wrap(1, Normal3fv, void, (GLfloatP)) +BGL_Wrap(3, Normal3i, void, (GLint, GLint, GLint)) +BGL_Wrap(1, Normal3iv, void, (GLintP)) +BGL_Wrap(3, Normal3s, void, (GLshort, GLshort, GLshort)) +BGL_Wrap(1, Normal3sv, void, (GLshortP)) +BGL_Wrap(6, Ortho, void, (GLdouble, GLdouble, + GLdouble, GLdouble, GLdouble, GLdouble)) +BGL_Wrap(1, PassThrough, void, (GLfloat)) +BGL_Wrap(3, PixelMapfv, void, (GLenum, GLint, GLfloatP)) +BGL_Wrap(3, PixelMapuiv, void, (GLenum, GLint, GLuintP)) +BGL_Wrap(3, PixelMapusv, void, (GLenum, GLint, GLushortP)) +BGL_Wrap(2, PixelStoref, void, (GLenum, GLfloat)) +BGL_Wrap(2, PixelStorei, void, (GLenum, GLint)) +BGL_Wrap(2, PixelTransferf, void, (GLenum, GLfloat)) +BGL_Wrap(2, PixelTransferi, void, (GLenum, GLint)) +BGL_Wrap(2, PixelZoom, void, (GLfloat, GLfloat)) +BGL_Wrap(1, PointSize, void, (GLfloat)) +BGL_Wrap(2, PolygonMode, void, (GLenum, GLenum)) +BGL_Wrap(2, PolygonOffset, void, (GLfloat, GLfloat)) +BGL_Wrap(1, PolygonStipple, void, (GLubyteP)) +BGL_Wrap(1, PopAttrib, void, (void)) +BGL_Wrap(1, PopMatrix, void, (void)) +BGL_Wrap(1, PopName, void, (void)) +BGL_Wrap(3, PrioritizeTextures, void, (GLsizei, GLuintP, GLclampfP)) +BGL_Wrap(1, PushAttrib, void, (GLbitfield)) +BGL_Wrap(1, PushMatrix, void, (void)) +BGL_Wrap(1, PushName, void, (GLuint)) +BGL_Wrap(2, RasterPos2d, void, (GLdouble, GLdouble)) +BGL_Wrap(1, RasterPos2dv, void, (GLdoubleP)) +BGL_Wrap(2, RasterPos2f, void, (GLfloat, GLfloat)) +BGL_Wrap(1, RasterPos2fv, void, (GLfloatP)) +BGL_Wrap(2, RasterPos2i, void, (GLint, GLint)) +BGL_Wrap(1, RasterPos2iv, void, (GLintP)) +BGL_Wrap(2, RasterPos2s, void, (GLshort, GLshort)) +BGL_Wrap(1, RasterPos2sv, void, (GLshortP)) +BGL_Wrap(3, RasterPos3d, void, (GLdouble, GLdouble, GLdouble)) +BGL_Wrap(1, RasterPos3dv, void, (GLdoubleP)) +BGL_Wrap(3, RasterPos3f, void, (GLfloat, GLfloat, GLfloat)) +BGL_Wrap(1, RasterPos3fv, void, (GLfloatP)) +BGL_Wrap(3, RasterPos3i, void, (GLint, GLint, GLint)) +BGL_Wrap(1, RasterPos3iv, void, (GLintP)) +BGL_Wrap(3, RasterPos3s, void, (GLshort, GLshort, GLshort)) +BGL_Wrap(1, RasterPos3sv, void, (GLshortP)) +BGL_Wrap(4, RasterPos4d, void, (GLdouble, GLdouble, GLdouble, GLdouble)) +BGL_Wrap(1, RasterPos4dv, void, (GLdoubleP)) +BGL_Wrap(4, RasterPos4f, void, (GLfloat, GLfloat, GLfloat, GLfloat)) +BGL_Wrap(1, RasterPos4fv, void, (GLfloatP)) +BGL_Wrap(4, RasterPos4i, void, (GLint, GLint, GLint, GLint)) +BGL_Wrap(1, RasterPos4iv, void, (GLintP)) +BGL_Wrap(4, RasterPos4s, void, (GLshort, GLshort, GLshort, GLshort)) +BGL_Wrap(1, RasterPos4sv, void, (GLshortP)) +BGL_Wrap(1, ReadBuffer, void, (GLenum)) +BGL_Wrap(7, ReadPixels, void, (GLint, GLint, GLsizei, + GLsizei, GLenum, GLenum, GLvoidP)) +BGL_Wrap(4, Rectd, void, (GLdouble, GLdouble, GLdouble, GLdouble)) +BGL_Wrap(2, Rectdv, void, (GLdoubleP, GLdoubleP)) +BGL_Wrap(4, Rectf, void, (GLfloat, GLfloat, GLfloat, GLfloat)) +BGL_Wrap(2, Rectfv, void, (GLfloatP, GLfloatP)) +BGL_Wrap(4, Recti, void, (GLint, GLint, GLint, GLint)) +BGL_Wrap(2, Rectiv, void, (GLintP, GLintP)) +BGL_Wrap(4, Rects, void, (GLshort, GLshort, GLshort, GLshort)) +BGL_Wrap(2, Rectsv, void, (GLshortP, GLshortP)) +BGL_Wrap(1, RenderMode, GLint, (GLenum)) +BGL_Wrap(4, Rotated, void, (GLdouble, GLdouble, GLdouble, GLdouble)) +BGL_Wrap(4, Rotatef, void, (GLfloat, GLfloat, GLfloat, GLfloat)) +BGL_Wrap(3, Scaled, void, (GLdouble, GLdouble, GLdouble)) +BGL_Wrap(3, Scalef, void, (GLfloat, GLfloat, GLfloat)) +BGL_Wrap(4, Scissor, void, (GLint, GLint, GLsizei, GLsizei)) +BGL_Wrap(2, SelectBuffer, void, (GLsizei, GLuintP)) +BGL_Wrap(1, ShadeModel, void, (GLenum)) +BGL_Wrap(3, StencilFunc, void, (GLenum, GLint, GLuint)) +BGL_Wrap(1, StencilMask, void, (GLuint)) +BGL_Wrap(3, StencilOp, void, (GLenum, GLenum, GLenum)) +BGL_Wrap(1, TexCoord1d, void, (GLdouble)) +BGL_Wrap(1, TexCoord1dv, void, (GLdoubleP)) +BGL_Wrap(1, TexCoord1f, void, (GLfloat)) +BGL_Wrap(1, TexCoord1fv, void, (GLfloatP)) +BGL_Wrap(1, TexCoord1i, void, (GLint)) +BGL_Wrap(1, TexCoord1iv, void, (GLintP)) +BGL_Wrap(1, TexCoord1s, void, (GLshort)) +BGL_Wrap(1, TexCoord1sv, void, (GLshortP)) +BGL_Wrap(2, TexCoord2d, void, (GLdouble, GLdouble)) +BGL_Wrap(1, TexCoord2dv, void, (GLdoubleP)) +BGL_Wrap(2, TexCoord2f, void, (GLfloat, GLfloat)) +BGL_Wrap(1, TexCoord2fv, void, (GLfloatP)) +BGL_Wrap(2, TexCoord2i, void, (GLint, GLint)) +BGL_Wrap(1, TexCoord2iv, void, (GLintP)) +BGL_Wrap(2, TexCoord2s, void, (GLshort, GLshort)) +BGL_Wrap(1, TexCoord2sv, void, (GLshortP)) +BGL_Wrap(3, TexCoord3d, void, (GLdouble, GLdouble, GLdouble)) +BGL_Wrap(1, TexCoord3dv, void, (GLdoubleP)) +BGL_Wrap(3, TexCoord3f, void, (GLfloat, GLfloat, GLfloat)) +BGL_Wrap(1, TexCoord3fv, void, (GLfloatP)) +BGL_Wrap(3, TexCoord3i, void, (GLint, GLint, GLint)) +BGL_Wrap(1, TexCoord3iv, void, (GLintP)) +BGL_Wrap(3, TexCoord3s, void, (GLshort, GLshort, GLshort)) +BGL_Wrap(1, TexCoord3sv, void, (GLshortP)) +BGL_Wrap(4, TexCoord4d, void, (GLdouble, GLdouble, GLdouble, GLdouble)) +BGL_Wrap(1, TexCoord4dv, void, (GLdoubleP)) +BGL_Wrap(4, TexCoord4f, void, (GLfloat, GLfloat, GLfloat, GLfloat)) +BGL_Wrap(1, TexCoord4fv, void, (GLfloatP)) +BGL_Wrap(4, TexCoord4i, void, (GLint, GLint, GLint, GLint)) +BGL_Wrap(1, TexCoord4iv, void, (GLintP)) +BGL_Wrap(4, TexCoord4s, void, (GLshort, GLshort, GLshort, GLshort)) +BGL_Wrap(1, TexCoord4sv, void, (GLshortP)) +BGL_Wrap(3, TexEnvf, void, (GLenum, GLenum, GLfloat)) +BGL_Wrap(3, TexEnvfv, void, (GLenum, GLenum, GLfloatP)) +BGL_Wrap(3, TexEnvi, void, (GLenum, GLenum, GLint)) +BGL_Wrap(3, TexEnviv, void, (GLenum, GLenum, GLintP)) +BGL_Wrap(3, TexGend, void, (GLenum, GLenum, GLdouble)) +BGL_Wrap(3, TexGendv, void, (GLenum, GLenum, GLdoubleP)) +BGL_Wrap(3, TexGenf, void, (GLenum, GLenum, GLfloat)) +BGL_Wrap(3, TexGenfv, void, (GLenum, GLenum, GLfloatP)) +BGL_Wrap(3, TexGeni, void, (GLenum, GLenum, GLint)) +BGL_Wrap(3, TexGeniv, void, (GLenum, GLenum, GLintP)) +BGL_Wrap(8, TexImage1D, void, (GLenum, GLint, GLint, + GLsizei, GLint, GLenum, GLenum, GLvoidP)) +BGL_Wrap(9, TexImage2D, void, (GLenum, GLint, GLint, + GLsizei, GLsizei, GLint, GLenum, GLenum, GLvoidP)) +BGL_Wrap(3, TexParameterf, void, (GLenum, GLenum, GLfloat)) +BGL_Wrap(3, TexParameterfv, void, (GLenum, GLenum, GLfloatP)) +BGL_Wrap(3, TexParameteri, void, (GLenum, GLenum, GLint)) +BGL_Wrap(3, TexParameteriv, void, (GLenum, GLenum, GLintP)) +BGL_Wrap(3, Translated, void, (GLdouble, GLdouble, GLdouble)) +BGL_Wrap(3, Translatef, void, (GLfloat, GLfloat, GLfloat)) +BGL_Wrap(2, Vertex2d, void, (GLdouble, GLdouble)) +BGL_Wrap(1, Vertex2dv, void, (GLdoubleP)) +BGL_Wrap(2, Vertex2f, void, (GLfloat, GLfloat)) +BGL_Wrap(1, Vertex2fv, void, (GLfloatP)) +BGL_Wrap(2, Vertex2i, void, (GLint, GLint)) +BGL_Wrap(1, Vertex2iv, void, (GLintP)) +BGL_Wrap(2, Vertex2s, void, (GLshort, GLshort)) +BGL_Wrap(1, Vertex2sv, void, (GLshortP)) +BGL_Wrap(3, Vertex3d, void, (GLdouble, GLdouble, GLdouble)) +BGL_Wrap(1, Vertex3dv, void, (GLdoubleP)) +BGL_Wrap(3, Vertex3f, void, (GLfloat, GLfloat, GLfloat)) +BGL_Wrap(1, Vertex3fv, void, (GLfloatP)) +BGL_Wrap(3, Vertex3i, void, (GLint, GLint, GLint)) +BGL_Wrap(1, Vertex3iv, void, (GLintP)) +BGL_Wrap(3, Vertex3s, void, (GLshort, GLshort, GLshort)) +BGL_Wrap(1, Vertex3sv, void, (GLshortP)) +BGL_Wrap(4, Vertex4d, void, (GLdouble, GLdouble, GLdouble, GLdouble)) +BGL_Wrap(1, Vertex4dv, void, (GLdoubleP)) +BGL_Wrap(4, Vertex4f, void, (GLfloat, GLfloat, GLfloat, GLfloat)) +BGL_Wrap(1, Vertex4fv, void, (GLfloatP)) +BGL_Wrap(4, Vertex4i, void, (GLint, GLint, GLint, GLint)) +BGL_Wrap(1, Vertex4iv, void, (GLintP)) +BGL_Wrap(4, Vertex4s, void, (GLshort, GLshort, GLshort, GLshort)) +BGL_Wrap(1, Vertex4sv, void, (GLshortP)) +BGL_Wrap(4, Viewport, void, (GLint, GLint, GLsizei, GLsizei)) +#endif + +#undef MethodDef +#define MethodDef(func) {"gl"#func, Method_##func, METH_VARARGS} + +/* So that MethodDef(Accum) becomes: + * {"glAccum", Method_Accumfunc, METH_VARARGS} */ + +static struct PyMethodDef BGL_methods[] = { + {"Buffer", Method_Buffer, METH_VARARGS, Method_Buffer_doc}, +#ifndef __APPLE__ + MethodDef( Accum), + MethodDef( AlphaFunc), + MethodDef( AreTexturesResident), + MethodDef( Begin), + MethodDef( BindTexture), + MethodDef( Bitmap), + MethodDef( BlendFunc), + MethodDef( CallList), + MethodDef( CallLists), + MethodDef( Clear), + MethodDef( ClearAccum), + MethodDef( ClearColor), + MethodDef( ClearDepth), + MethodDef( ClearIndex), + MethodDef( ClearStencil), + MethodDef( ClipPlane), + MethodDef( Color3b), + MethodDef( Color3bv), + MethodDef( Color3d), + MethodDef( Color3dv), + MethodDef( Color3f), + MethodDef( Color3fv), + MethodDef( Color3i), + MethodDef( Color3iv), + MethodDef( Color3s), + MethodDef( Color3sv), + MethodDef( Color3ub), + MethodDef( Color3ubv), + MethodDef( Color3ui), + MethodDef( Color3uiv), + MethodDef( Color3us), + MethodDef( Color3usv), + MethodDef( Color4b), + MethodDef( Color4bv), + MethodDef( Color4d), + MethodDef( Color4dv), + MethodDef( Color4f), + MethodDef( Color4fv), + MethodDef( Color4i), + MethodDef( Color4iv), + MethodDef( Color4s), + MethodDef( Color4sv), + MethodDef( Color4ub), + MethodDef( Color4ubv), + MethodDef( Color4ui), + MethodDef( Color4uiv), + MethodDef( Color4us), + MethodDef( Color4usv), + MethodDef( ColorMask), + MethodDef( ColorMaterial), + MethodDef( CopyPixels), + MethodDef( CullFace), + MethodDef( DeleteLists), + MethodDef( DeleteTextures), + MethodDef( DepthFunc), + MethodDef( DepthMask), + MethodDef( DepthRange), + MethodDef( Disable), + MethodDef( DrawBuffer), + MethodDef( DrawPixels), + MethodDef( EdgeFlag), + MethodDef( EdgeFlagv), + MethodDef( Enable), + MethodDef( End), + MethodDef( EndList), + MethodDef( EvalCoord1d), + MethodDef( EvalCoord1dv), + MethodDef( EvalCoord1f), + MethodDef( EvalCoord1fv), + MethodDef( EvalCoord2d), + MethodDef( EvalCoord2dv), + MethodDef( EvalCoord2f), + MethodDef( EvalCoord2fv), + MethodDef( EvalMesh1), + MethodDef( EvalMesh2), + MethodDef( EvalPoint1), + MethodDef( EvalPoint2), + MethodDef( FeedbackBuffer), + MethodDef( Finish), + MethodDef( Flush), + MethodDef( Fogf), + MethodDef( Fogfv), + MethodDef( Fogi), + MethodDef( Fogiv), + MethodDef( FrontFace), + MethodDef( Frustum), + MethodDef( GenLists), + MethodDef( GenTextures), + MethodDef( GetBooleanv), + MethodDef( GetClipPlane), + MethodDef( GetDoublev), + MethodDef( GetError), + MethodDef( GetFloatv), + MethodDef( GetIntegerv), + MethodDef( GetLightfv), + MethodDef( GetLightiv), + MethodDef( GetMapdv), + MethodDef( GetMapfv), + MethodDef( GetMapiv), + MethodDef( GetMaterialfv), + MethodDef( GetMaterialiv), + MethodDef( GetPixelMapfv), + MethodDef( GetPixelMapuiv), + MethodDef( GetPixelMapusv), + MethodDef( GetPolygonStipple), + MethodDef( GetString), + MethodDef( GetTexEnvfv), + MethodDef( GetTexEnviv), + MethodDef( GetTexGendv), + MethodDef( GetTexGenfv), + MethodDef( GetTexGeniv), + MethodDef( GetTexImage), + MethodDef( GetTexLevelParameterfv), + MethodDef( GetTexLevelParameteriv), + MethodDef( GetTexParameterfv), + MethodDef( GetTexParameteriv), + MethodDef( Hint), + MethodDef( IndexMask), + MethodDef( Indexd), + MethodDef( Indexdv), + MethodDef( Indexf), + MethodDef( Indexfv), + MethodDef( Indexi), + MethodDef( Indexiv), + MethodDef( Indexs), + MethodDef( Indexsv), + MethodDef( InitNames), + MethodDef( IsEnabled), + MethodDef( IsList), + MethodDef( IsTexture), + MethodDef( LightModelf), + MethodDef( LightModelfv), + MethodDef( LightModeli), + MethodDef( LightModeliv), + MethodDef( Lightf), + MethodDef( Lightfv), + MethodDef( Lighti), + MethodDef( Lightiv), + MethodDef( LineStipple), + MethodDef( LineWidth), + MethodDef( ListBase), + MethodDef( LoadIdentity), + MethodDef( LoadMatrixd), + MethodDef( LoadMatrixf), + MethodDef( LoadName), + MethodDef( LogicOp), + MethodDef( Map1d), + MethodDef( Map1f), + MethodDef( Map2d), + MethodDef( Map2f), + MethodDef( MapGrid1d), + MethodDef( MapGrid1f), + MethodDef( MapGrid2d), + MethodDef( MapGrid2f), + MethodDef( Materialf), + MethodDef( Materialfv), + MethodDef( Materiali), + MethodDef( Materialiv), + MethodDef( MatrixMode), + MethodDef( MultMatrixd), + MethodDef( MultMatrixf), + MethodDef( NewList), + MethodDef( Normal3b), + MethodDef( Normal3bv), + MethodDef( Normal3d), + MethodDef( Normal3dv), + MethodDef( Normal3f), + MethodDef( Normal3fv), + MethodDef( Normal3i), + MethodDef( Normal3iv), + MethodDef( Normal3s), + MethodDef( Normal3sv), + MethodDef( Ortho), + MethodDef( PassThrough), + MethodDef( PixelMapfv), + MethodDef( PixelMapuiv), + MethodDef( PixelMapusv), + MethodDef( PixelStoref), + MethodDef( PixelStorei), + MethodDef( PixelTransferf), + MethodDef( PixelTransferi), + MethodDef( PixelZoom), + MethodDef( PointSize), + MethodDef( PolygonMode), + MethodDef( PolygonOffset), + MethodDef( PolygonStipple), + MethodDef( PopAttrib), + MethodDef( PopMatrix), + MethodDef( PopName), + MethodDef( PrioritizeTextures), + MethodDef( PushAttrib), + MethodDef( PushMatrix), + MethodDef( PushName), + MethodDef( RasterPos2d), + MethodDef( RasterPos2dv), + MethodDef( RasterPos2f), + MethodDef( RasterPos2fv), + MethodDef( RasterPos2i), + MethodDef( RasterPos2iv), + MethodDef( RasterPos2s), + MethodDef( RasterPos2sv), + MethodDef( RasterPos3d), + MethodDef( RasterPos3dv), + MethodDef( RasterPos3f), + MethodDef( RasterPos3fv), + MethodDef( RasterPos3i), + MethodDef( RasterPos3iv), + MethodDef( RasterPos3s), + MethodDef( RasterPos3sv), + MethodDef( RasterPos4d), + MethodDef( RasterPos4dv), + MethodDef( RasterPos4f), + MethodDef( RasterPos4fv), + MethodDef( RasterPos4i), + MethodDef( RasterPos4iv), + MethodDef( RasterPos4s), + MethodDef( RasterPos4sv), + MethodDef( ReadBuffer), + MethodDef( ReadPixels), + MethodDef( Rectd), + MethodDef( Rectdv), + MethodDef( Rectf), + MethodDef( Rectfv), + MethodDef( Recti), + MethodDef( Rectiv), + MethodDef( Rects), + MethodDef( Rectsv), + MethodDef( RenderMode), + MethodDef( Rotated), + MethodDef( Rotatef), + MethodDef( Scaled), + MethodDef( Scalef), + MethodDef( Scissor), + MethodDef( SelectBuffer), + MethodDef( ShadeModel), + MethodDef( StencilFunc), + MethodDef( StencilMask), + MethodDef( StencilOp), + MethodDef( TexCoord1d), + MethodDef( TexCoord1dv), + MethodDef( TexCoord1f), + MethodDef( TexCoord1fv), + MethodDef( TexCoord1i), + MethodDef( TexCoord1iv), + MethodDef( TexCoord1s), + MethodDef( TexCoord1sv), + MethodDef( TexCoord2d), + MethodDef( TexCoord2dv), + MethodDef( TexCoord2f), + MethodDef( TexCoord2fv), + MethodDef( TexCoord2i), + MethodDef( TexCoord2iv), + MethodDef( TexCoord2s), + MethodDef( TexCoord2sv), + MethodDef( TexCoord3d), + MethodDef( TexCoord3dv), + MethodDef( TexCoord3f), + MethodDef( TexCoord3fv), + MethodDef( TexCoord3i), + MethodDef( TexCoord3iv), + MethodDef( TexCoord3s), + MethodDef( TexCoord3sv), + MethodDef( TexCoord4d), + MethodDef( TexCoord4dv), + MethodDef( TexCoord4f), + MethodDef( TexCoord4fv), + MethodDef( TexCoord4i), + MethodDef( TexCoord4iv), + MethodDef( TexCoord4s), + MethodDef( TexCoord4sv), + MethodDef( TexEnvf), + MethodDef( TexEnvfv), + MethodDef( TexEnvi), + MethodDef( TexEnviv), + MethodDef( TexGend), + MethodDef( TexGendv), + MethodDef( TexGenf), + MethodDef( TexGenfv), + MethodDef( TexGeni), + MethodDef( TexGeniv), + MethodDef( TexImage1D), + MethodDef( TexImage2D), + MethodDef( TexParameterf), + MethodDef( TexParameterfv), + MethodDef( TexParameteri), + MethodDef( TexParameteriv), + MethodDef( Translated), + MethodDef( Translatef), + MethodDef( Vertex2d), + MethodDef( Vertex2dv), + MethodDef( Vertex2f), + MethodDef( Vertex2fv), + MethodDef( Vertex2i), + MethodDef( Vertex2iv), + MethodDef( Vertex2s), + MethodDef( Vertex2sv), + MethodDef( Vertex3d), + MethodDef( Vertex3dv), + MethodDef( Vertex3f), + MethodDef( Vertex3fv), + MethodDef( Vertex3i), + MethodDef( Vertex3iv), + MethodDef( Vertex3s), + MethodDef( Vertex3sv), + MethodDef( Vertex4d), + MethodDef( Vertex4dv), + MethodDef( Vertex4f), + MethodDef( Vertex4fv), + MethodDef( Vertex4i), + MethodDef( Vertex4iv), + MethodDef( Vertex4s), + MethodDef( Vertex4sv), + MethodDef( Viewport), +#endif + + {NULL, NULL} +}; + +PyObject *M_BGL_Init(void) +{ + PyObject *mod= Py_InitModule("Blender.BGL", BGL_methods); + PyObject *dict= PyModule_GetDict(mod); + +#define EXPP_ADDCONST(x) PyDict_SetItemString(dict, #x, PyInt_FromLong(x)) + +/* So, for example: + * EXPP_ADDCONST(GL_CURRENT_BIT) becomes + * PyDict_SetItemString(dict, "GL_CURRENT_BIT", PyInt_FromLong(GL_CURRENT_BIT)) */ + + EXPP_ADDCONST(GL_CURRENT_BIT); + EXPP_ADDCONST(GL_POINT_BIT); + EXPP_ADDCONST(GL_LINE_BIT); + EXPP_ADDCONST(GL_POLYGON_BIT); + EXPP_ADDCONST(GL_POLYGON_STIPPLE_BIT); + EXPP_ADDCONST(GL_PIXEL_MODE_BIT); + EXPP_ADDCONST(GL_LIGHTING_BIT); + EXPP_ADDCONST(GL_FOG_BIT); + EXPP_ADDCONST(GL_DEPTH_BUFFER_BIT); + EXPP_ADDCONST(GL_ACCUM_BUFFER_BIT); + EXPP_ADDCONST(GL_STENCIL_BUFFER_BIT); + EXPP_ADDCONST(GL_VIEWPORT_BIT); + EXPP_ADDCONST(GL_TRANSFORM_BIT); + EXPP_ADDCONST(GL_ENABLE_BIT); + EXPP_ADDCONST(GL_COLOR_BUFFER_BIT); + EXPP_ADDCONST(GL_HINT_BIT); + EXPP_ADDCONST(GL_EVAL_BIT); + EXPP_ADDCONST(GL_LIST_BIT); + EXPP_ADDCONST(GL_TEXTURE_BIT); + EXPP_ADDCONST(GL_SCISSOR_BIT); + EXPP_ADDCONST(GL_ALL_ATTRIB_BITS); + + EXPP_ADDCONST(GL_FALSE); + EXPP_ADDCONST(GL_TRUE); + + EXPP_ADDCONST(GL_POINTS); + EXPP_ADDCONST(GL_LINES); + EXPP_ADDCONST(GL_LINE_LOOP); + EXPP_ADDCONST(GL_LINE_STRIP); + EXPP_ADDCONST(GL_TRIANGLES); + EXPP_ADDCONST(GL_TRIANGLE_STRIP); + EXPP_ADDCONST(GL_TRIANGLE_FAN); + EXPP_ADDCONST(GL_QUADS); + EXPP_ADDCONST(GL_QUAD_STRIP); + EXPP_ADDCONST(GL_POLYGON); + + EXPP_ADDCONST(GL_ACCUM); + EXPP_ADDCONST(GL_LOAD); + EXPP_ADDCONST(GL_RETURN); + EXPP_ADDCONST(GL_MULT); + EXPP_ADDCONST(GL_ADD); + + EXPP_ADDCONST(GL_NEVER); + EXPP_ADDCONST(GL_LESS); + EXPP_ADDCONST(GL_EQUAL); + EXPP_ADDCONST(GL_LEQUAL); + EXPP_ADDCONST(GL_GREATER); + EXPP_ADDCONST(GL_NOTEQUAL); + EXPP_ADDCONST(GL_GEQUAL); + EXPP_ADDCONST(GL_ALWAYS); + + EXPP_ADDCONST(GL_ZERO); + EXPP_ADDCONST(GL_ONE); + EXPP_ADDCONST(GL_SRC_COLOR); + EXPP_ADDCONST(GL_ONE_MINUS_SRC_COLOR); + EXPP_ADDCONST(GL_SRC_ALPHA); + EXPP_ADDCONST(GL_ONE_MINUS_SRC_ALPHA); + EXPP_ADDCONST(GL_DST_ALPHA); + EXPP_ADDCONST(GL_ONE_MINUS_DST_ALPHA); + + EXPP_ADDCONST(GL_DST_COLOR); + EXPP_ADDCONST(GL_ONE_MINUS_DST_COLOR); + EXPP_ADDCONST(GL_SRC_ALPHA_SATURATE); + + EXPP_ADDCONST(GL_NONE); + EXPP_ADDCONST(GL_FRONT_LEFT); + EXPP_ADDCONST(GL_FRONT_RIGHT); + EXPP_ADDCONST(GL_BACK_LEFT); + EXPP_ADDCONST(GL_BACK_RIGHT); + EXPP_ADDCONST(GL_FRONT); + EXPP_ADDCONST(GL_BACK); + EXPP_ADDCONST(GL_LEFT); + EXPP_ADDCONST(GL_RIGHT); + EXPP_ADDCONST(GL_FRONT_AND_BACK); + EXPP_ADDCONST(GL_AUX0); + EXPP_ADDCONST(GL_AUX1); + EXPP_ADDCONST(GL_AUX2); + EXPP_ADDCONST(GL_AUX3); + + EXPP_ADDCONST(GL_NO_ERROR); + EXPP_ADDCONST(GL_INVALID_ENUM); + EXPP_ADDCONST(GL_INVALID_VALUE); + EXPP_ADDCONST(GL_INVALID_OPERATION); + EXPP_ADDCONST(GL_STACK_OVERFLOW); + EXPP_ADDCONST(GL_STACK_UNDERFLOW); + EXPP_ADDCONST(GL_OUT_OF_MEMORY); + + EXPP_ADDCONST(GL_2D); + EXPP_ADDCONST(GL_3D); + EXPP_ADDCONST(GL_3D_COLOR); + EXPP_ADDCONST(GL_3D_COLOR_TEXTURE); + EXPP_ADDCONST(GL_4D_COLOR_TEXTURE); + + EXPP_ADDCONST(GL_PASS_THROUGH_TOKEN); + EXPP_ADDCONST(GL_POINT_TOKEN); + EXPP_ADDCONST(GL_LINE_TOKEN); + EXPP_ADDCONST(GL_POLYGON_TOKEN); + EXPP_ADDCONST(GL_BITMAP_TOKEN); + EXPP_ADDCONST(GL_DRAW_PIXEL_TOKEN); + EXPP_ADDCONST(GL_COPY_PIXEL_TOKEN); + EXPP_ADDCONST(GL_LINE_RESET_TOKEN); + + EXPP_ADDCONST(GL_EXP); + EXPP_ADDCONST(GL_EXP2); + + EXPP_ADDCONST(GL_CW); + EXPP_ADDCONST(GL_CCW); + + EXPP_ADDCONST(GL_COEFF); + EXPP_ADDCONST(GL_ORDER); + EXPP_ADDCONST(GL_DOMAIN); + + EXPP_ADDCONST(GL_PIXEL_MAP_I_TO_I); + EXPP_ADDCONST(GL_PIXEL_MAP_S_TO_S); + EXPP_ADDCONST(GL_PIXEL_MAP_I_TO_R); + EXPP_ADDCONST(GL_PIXEL_MAP_I_TO_G); + EXPP_ADDCONST(GL_PIXEL_MAP_I_TO_B); + EXPP_ADDCONST(GL_PIXEL_MAP_I_TO_A); + EXPP_ADDCONST(GL_PIXEL_MAP_R_TO_R); + EXPP_ADDCONST(GL_PIXEL_MAP_G_TO_G); + EXPP_ADDCONST(GL_PIXEL_MAP_B_TO_B); + EXPP_ADDCONST(GL_PIXEL_MAP_A_TO_A); + + EXPP_ADDCONST(GL_CURRENT_COLOR); + EXPP_ADDCONST(GL_CURRENT_INDEX); + EXPP_ADDCONST(GL_CURRENT_NORMAL); + EXPP_ADDCONST(GL_CURRENT_TEXTURE_COORDS); + EXPP_ADDCONST(GL_CURRENT_RASTER_COLOR); + EXPP_ADDCONST(GL_CURRENT_RASTER_INDEX); + EXPP_ADDCONST(GL_CURRENT_RASTER_TEXTURE_COORDS); + EXPP_ADDCONST(GL_CURRENT_RASTER_POSITION); + EXPP_ADDCONST(GL_CURRENT_RASTER_POSITION_VALID); + EXPP_ADDCONST(GL_CURRENT_RASTER_DISTANCE); + EXPP_ADDCONST(GL_POINT_SMOOTH); + EXPP_ADDCONST(GL_POINT_SIZE); + EXPP_ADDCONST(GL_POINT_SIZE_RANGE); + EXPP_ADDCONST(GL_POINT_SIZE_GRANULARITY); + EXPP_ADDCONST(GL_LINE_SMOOTH); + EXPP_ADDCONST(GL_LINE_WIDTH); + EXPP_ADDCONST(GL_LINE_WIDTH_RANGE); + EXPP_ADDCONST(GL_LINE_WIDTH_GRANULARITY); + EXPP_ADDCONST(GL_LINE_STIPPLE); + EXPP_ADDCONST(GL_LINE_STIPPLE_PATTERN); + EXPP_ADDCONST(GL_LINE_STIPPLE_REPEAT); + EXPP_ADDCONST(GL_LIST_MODE); + EXPP_ADDCONST(GL_MAX_LIST_NESTING); + EXPP_ADDCONST(GL_LIST_BASE); + EXPP_ADDCONST(GL_LIST_INDEX); + EXPP_ADDCONST(GL_POLYGON_MODE); + EXPP_ADDCONST(GL_POLYGON_SMOOTH); + EXPP_ADDCONST(GL_POLYGON_STIPPLE); + EXPP_ADDCONST(GL_EDGE_FLAG); + EXPP_ADDCONST(GL_CULL_FACE); + EXPP_ADDCONST(GL_CULL_FACE_MODE); + EXPP_ADDCONST(GL_FRONT_FACE); + EXPP_ADDCONST(GL_LIGHTING); + EXPP_ADDCONST(GL_LIGHT_MODEL_LOCAL_VIEWER); + EXPP_ADDCONST(GL_LIGHT_MODEL_TWO_SIDE); + EXPP_ADDCONST(GL_LIGHT_MODEL_AMBIENT); + EXPP_ADDCONST(GL_SHADE_MODEL); + EXPP_ADDCONST(GL_COLOR_MATERIAL_FACE); + EXPP_ADDCONST(GL_COLOR_MATERIAL_PARAMETER); + EXPP_ADDCONST(GL_COLOR_MATERIAL); + EXPP_ADDCONST(GL_FOG); + EXPP_ADDCONST(GL_FOG_INDEX); + EXPP_ADDCONST(GL_FOG_DENSITY); + EXPP_ADDCONST(GL_FOG_START); + EXPP_ADDCONST(GL_FOG_END); + EXPP_ADDCONST(GL_FOG_MODE); + EXPP_ADDCONST(GL_FOG_COLOR); + EXPP_ADDCONST(GL_DEPTH_RANGE); + EXPP_ADDCONST(GL_DEPTH_TEST); + EXPP_ADDCONST(GL_DEPTH_WRITEMASK); + EXPP_ADDCONST(GL_DEPTH_CLEAR_VALUE); + EXPP_ADDCONST(GL_DEPTH_FUNC); + EXPP_ADDCONST(GL_ACCUM_CLEAR_VALUE); + EXPP_ADDCONST(GL_STENCIL_TEST); + EXPP_ADDCONST(GL_STENCIL_CLEAR_VALUE); + EXPP_ADDCONST(GL_STENCIL_FUNC); + EXPP_ADDCONST(GL_STENCIL_VALUE_MASK); + EXPP_ADDCONST(GL_STENCIL_FAIL); + EXPP_ADDCONST(GL_STENCIL_PASS_DEPTH_FAIL); + EXPP_ADDCONST(GL_STENCIL_PASS_DEPTH_PASS); + EXPP_ADDCONST(GL_STENCIL_REF); + EXPP_ADDCONST(GL_STENCIL_WRITEMASK); + EXPP_ADDCONST(GL_MATRIX_MODE); + EXPP_ADDCONST(GL_NORMALIZE); + EXPP_ADDCONST(GL_VIEWPORT); + EXPP_ADDCONST(GL_MODELVIEW_STACK_DEPTH); + EXPP_ADDCONST(GL_PROJECTION_STACK_DEPTH); + EXPP_ADDCONST(GL_TEXTURE_STACK_DEPTH); + EXPP_ADDCONST(GL_MODELVIEW_MATRIX); + EXPP_ADDCONST(GL_PROJECTION_MATRIX); + EXPP_ADDCONST(GL_TEXTURE_MATRIX); + EXPP_ADDCONST(GL_ATTRIB_STACK_DEPTH); + EXPP_ADDCONST(GL_ALPHA_TEST); + EXPP_ADDCONST(GL_ALPHA_TEST_FUNC); + EXPP_ADDCONST(GL_ALPHA_TEST_REF); + EXPP_ADDCONST(GL_DITHER); + EXPP_ADDCONST(GL_BLEND_DST); + EXPP_ADDCONST(GL_BLEND_SRC); + EXPP_ADDCONST(GL_BLEND); + EXPP_ADDCONST(GL_LOGIC_OP_MODE); + EXPP_ADDCONST(GL_LOGIC_OP); + EXPP_ADDCONST(GL_AUX_BUFFERS); + EXPP_ADDCONST(GL_DRAW_BUFFER); + EXPP_ADDCONST(GL_READ_BUFFER); + EXPP_ADDCONST(GL_SCISSOR_BOX); + EXPP_ADDCONST(GL_SCISSOR_TEST); + EXPP_ADDCONST(GL_INDEX_CLEAR_VALUE); + EXPP_ADDCONST(GL_INDEX_WRITEMASK); + EXPP_ADDCONST(GL_COLOR_CLEAR_VALUE); + EXPP_ADDCONST(GL_COLOR_WRITEMASK); + EXPP_ADDCONST(GL_INDEX_MODE); + EXPP_ADDCONST(GL_RGBA_MODE); + EXPP_ADDCONST(GL_DOUBLEBUFFER); + EXPP_ADDCONST(GL_STEREO); + EXPP_ADDCONST(GL_RENDER_MODE); + EXPP_ADDCONST(GL_PERSPECTIVE_CORRECTION_HINT); + EXPP_ADDCONST(GL_POINT_SMOOTH_HINT); + EXPP_ADDCONST(GL_LINE_SMOOTH_HINT); + EXPP_ADDCONST(GL_POLYGON_SMOOTH_HINT); + EXPP_ADDCONST(GL_FOG_HINT); + EXPP_ADDCONST(GL_TEXTURE_GEN_S); + EXPP_ADDCONST(GL_TEXTURE_GEN_T); + EXPP_ADDCONST(GL_TEXTURE_GEN_R); + EXPP_ADDCONST(GL_TEXTURE_GEN_Q); + EXPP_ADDCONST(GL_PIXEL_MAP_I_TO_I_SIZE); + EXPP_ADDCONST(GL_PIXEL_MAP_S_TO_S_SIZE); + EXPP_ADDCONST(GL_PIXEL_MAP_I_TO_R_SIZE); + EXPP_ADDCONST(GL_PIXEL_MAP_I_TO_G_SIZE); + EXPP_ADDCONST(GL_PIXEL_MAP_I_TO_B_SIZE); + EXPP_ADDCONST(GL_PIXEL_MAP_I_TO_A_SIZE); + EXPP_ADDCONST(GL_PIXEL_MAP_R_TO_R_SIZE); + EXPP_ADDCONST(GL_PIXEL_MAP_G_TO_G_SIZE); + EXPP_ADDCONST(GL_PIXEL_MAP_B_TO_B_SIZE); + EXPP_ADDCONST(GL_PIXEL_MAP_A_TO_A_SIZE); + EXPP_ADDCONST(GL_UNPACK_SWAP_BYTES); + EXPP_ADDCONST(GL_UNPACK_LSB_FIRST); + EXPP_ADDCONST(GL_UNPACK_ROW_LENGTH); + EXPP_ADDCONST(GL_UNPACK_SKIP_ROWS); + EXPP_ADDCONST(GL_UNPACK_SKIP_PIXELS); + EXPP_ADDCONST(GL_UNPACK_ALIGNMENT); + EXPP_ADDCONST(GL_PACK_SWAP_BYTES); + EXPP_ADDCONST(GL_PACK_LSB_FIRST); + EXPP_ADDCONST(GL_PACK_ROW_LENGTH); + EXPP_ADDCONST(GL_PACK_SKIP_ROWS); + EXPP_ADDCONST(GL_PACK_SKIP_PIXELS); + EXPP_ADDCONST(GL_PACK_ALIGNMENT); + EXPP_ADDCONST(GL_MAP_COLOR); + EXPP_ADDCONST(GL_MAP_STENCIL); + EXPP_ADDCONST(GL_INDEX_SHIFT); + EXPP_ADDCONST(GL_INDEX_OFFSET); + EXPP_ADDCONST(GL_RED_SCALE); + EXPP_ADDCONST(GL_RED_BIAS); + EXPP_ADDCONST(GL_ZOOM_X); + EXPP_ADDCONST(GL_ZOOM_Y); + EXPP_ADDCONST(GL_GREEN_SCALE); + EXPP_ADDCONST(GL_GREEN_BIAS); + EXPP_ADDCONST(GL_BLUE_SCALE); + EXPP_ADDCONST(GL_BLUE_BIAS); + EXPP_ADDCONST(GL_ALPHA_SCALE); + EXPP_ADDCONST(GL_ALPHA_BIAS); + EXPP_ADDCONST(GL_DEPTH_SCALE); + EXPP_ADDCONST(GL_DEPTH_BIAS); + EXPP_ADDCONST(GL_MAX_EVAL_ORDER); + EXPP_ADDCONST(GL_MAX_LIGHTS); + EXPP_ADDCONST(GL_MAX_CLIP_PLANES); + EXPP_ADDCONST(GL_MAX_TEXTURE_SIZE); + EXPP_ADDCONST(GL_MAX_PIXEL_MAP_TABLE); + EXPP_ADDCONST(GL_MAX_ATTRIB_STACK_DEPTH); + EXPP_ADDCONST(GL_MAX_MODELVIEW_STACK_DEPTH); + EXPP_ADDCONST(GL_MAX_NAME_STACK_DEPTH); + EXPP_ADDCONST(GL_MAX_PROJECTION_STACK_DEPTH); + EXPP_ADDCONST(GL_MAX_TEXTURE_STACK_DEPTH); + EXPP_ADDCONST(GL_MAX_VIEWPORT_DIMS); + EXPP_ADDCONST(GL_SUBPIXEL_BITS); + EXPP_ADDCONST(GL_INDEX_BITS); + EXPP_ADDCONST(GL_RED_BITS); + EXPP_ADDCONST(GL_GREEN_BITS); + EXPP_ADDCONST(GL_BLUE_BITS); + EXPP_ADDCONST(GL_ALPHA_BITS); + EXPP_ADDCONST(GL_DEPTH_BITS); + EXPP_ADDCONST(GL_STENCIL_BITS); + EXPP_ADDCONST(GL_ACCUM_RED_BITS); + EXPP_ADDCONST(GL_ACCUM_GREEN_BITS); + EXPP_ADDCONST(GL_ACCUM_BLUE_BITS); + EXPP_ADDCONST(GL_ACCUM_ALPHA_BITS); + EXPP_ADDCONST(GL_NAME_STACK_DEPTH); + EXPP_ADDCONST(GL_AUTO_NORMAL); + EXPP_ADDCONST(GL_MAP1_COLOR_4); + EXPP_ADDCONST(GL_MAP1_INDEX); + EXPP_ADDCONST(GL_MAP1_NORMAL); + EXPP_ADDCONST(GL_MAP1_TEXTURE_COORD_1); + EXPP_ADDCONST(GL_MAP1_TEXTURE_COORD_2); + EXPP_ADDCONST(GL_MAP1_TEXTURE_COORD_3); + EXPP_ADDCONST(GL_MAP1_TEXTURE_COORD_4); + EXPP_ADDCONST(GL_MAP1_VERTEX_3); + EXPP_ADDCONST(GL_MAP1_VERTEX_4); + EXPP_ADDCONST(GL_MAP2_COLOR_4); + EXPP_ADDCONST(GL_MAP2_INDEX); + EXPP_ADDCONST(GL_MAP2_NORMAL); + EXPP_ADDCONST(GL_MAP2_TEXTURE_COORD_1); + EXPP_ADDCONST(GL_MAP2_TEXTURE_COORD_2); + EXPP_ADDCONST(GL_MAP2_TEXTURE_COORD_3); + EXPP_ADDCONST(GL_MAP2_TEXTURE_COORD_4); + EXPP_ADDCONST(GL_MAP2_VERTEX_3); + EXPP_ADDCONST(GL_MAP2_VERTEX_4); + EXPP_ADDCONST(GL_MAP1_GRID_DOMAIN); + EXPP_ADDCONST(GL_MAP1_GRID_SEGMENTS); + EXPP_ADDCONST(GL_MAP2_GRID_DOMAIN); + EXPP_ADDCONST(GL_MAP2_GRID_SEGMENTS); + EXPP_ADDCONST(GL_TEXTURE_1D); + EXPP_ADDCONST(GL_TEXTURE_2D); + + EXPP_ADDCONST(GL_TEXTURE_WIDTH); + EXPP_ADDCONST(GL_TEXTURE_HEIGHT); + EXPP_ADDCONST(GL_TEXTURE_COMPONENTS); + EXPP_ADDCONST(GL_TEXTURE_BORDER_COLOR); + EXPP_ADDCONST(GL_TEXTURE_BORDER); + + EXPP_ADDCONST(GL_DONT_CARE); + EXPP_ADDCONST(GL_FASTEST); + EXPP_ADDCONST(GL_NICEST); + + EXPP_ADDCONST(GL_AMBIENT); + EXPP_ADDCONST(GL_DIFFUSE); + EXPP_ADDCONST(GL_SPECULAR); + EXPP_ADDCONST(GL_POSITION); + EXPP_ADDCONST(GL_SPOT_DIRECTION); + EXPP_ADDCONST(GL_SPOT_EXPONENT); + EXPP_ADDCONST(GL_SPOT_CUTOFF); + EXPP_ADDCONST(GL_CONSTANT_ATTENUATION); + EXPP_ADDCONST(GL_LINEAR_ATTENUATION); + EXPP_ADDCONST(GL_QUADRATIC_ATTENUATION); + + EXPP_ADDCONST(GL_COMPILE); + EXPP_ADDCONST(GL_COMPILE_AND_EXECUTE); + + EXPP_ADDCONST(GL_BYTE); + EXPP_ADDCONST(GL_UNSIGNED_BYTE); + EXPP_ADDCONST(GL_SHORT); + EXPP_ADDCONST(GL_UNSIGNED_SHORT); + EXPP_ADDCONST(GL_INT); + EXPP_ADDCONST(GL_UNSIGNED_INT); + EXPP_ADDCONST(GL_FLOAT); + EXPP_ADDCONST(GL_2_BYTES); + EXPP_ADDCONST(GL_3_BYTES); + EXPP_ADDCONST(GL_4_BYTES); + + EXPP_ADDCONST(GL_CLEAR); + EXPP_ADDCONST(GL_AND); + EXPP_ADDCONST(GL_AND_REVERSE); + EXPP_ADDCONST(GL_COPY); + EXPP_ADDCONST(GL_AND_INVERTED); + EXPP_ADDCONST(GL_NOOP); + EXPP_ADDCONST(GL_XOR); + EXPP_ADDCONST(GL_OR); + EXPP_ADDCONST(GL_NOR); + EXPP_ADDCONST(GL_EQUIV); + EXPP_ADDCONST(GL_INVERT); + EXPP_ADDCONST(GL_OR_REVERSE); + EXPP_ADDCONST(GL_COPY_INVERTED); + EXPP_ADDCONST(GL_OR_INVERTED); + EXPP_ADDCONST(GL_NAND); + EXPP_ADDCONST(GL_SET); + + EXPP_ADDCONST(GL_EMISSION); + EXPP_ADDCONST(GL_SHININESS); + EXPP_ADDCONST(GL_AMBIENT_AND_DIFFUSE); + EXPP_ADDCONST(GL_COLOR_INDEXES); + + EXPP_ADDCONST(GL_MODELVIEW); + EXPP_ADDCONST(GL_PROJECTION); + EXPP_ADDCONST(GL_TEXTURE); + + EXPP_ADDCONST(GL_COLOR); + EXPP_ADDCONST(GL_DEPTH); + EXPP_ADDCONST(GL_STENCIL); + + EXPP_ADDCONST(GL_COLOR_INDEX); + EXPP_ADDCONST(GL_STENCIL_INDEX); + EXPP_ADDCONST(GL_DEPTH_COMPONENT); + EXPP_ADDCONST(GL_RED); + EXPP_ADDCONST(GL_GREEN); + EXPP_ADDCONST(GL_BLUE); + EXPP_ADDCONST(GL_ALPHA); + EXPP_ADDCONST(GL_RGB); + EXPP_ADDCONST(GL_RGBA); + EXPP_ADDCONST(GL_LUMINANCE); + EXPP_ADDCONST(GL_LUMINANCE_ALPHA); + + EXPP_ADDCONST(GL_BITMAP); + + EXPP_ADDCONST(GL_POINT); + EXPP_ADDCONST(GL_LINE); + EXPP_ADDCONST(GL_FILL); + + EXPP_ADDCONST(GL_RENDER); + EXPP_ADDCONST(GL_FEEDBACK); + EXPP_ADDCONST(GL_SELECT); + + EXPP_ADDCONST(GL_FLAT); + EXPP_ADDCONST(GL_SMOOTH); + + EXPP_ADDCONST(GL_KEEP); + EXPP_ADDCONST(GL_REPLACE); + EXPP_ADDCONST(GL_INCR); + EXPP_ADDCONST(GL_DECR); + + EXPP_ADDCONST(GL_VENDOR); + EXPP_ADDCONST(GL_RENDERER); + EXPP_ADDCONST(GL_VERSION); + EXPP_ADDCONST(GL_EXTENSIONS); + + EXPP_ADDCONST(GL_S); + EXPP_ADDCONST(GL_T); + EXPP_ADDCONST(GL_R); + EXPP_ADDCONST(GL_Q); + + EXPP_ADDCONST(GL_MODULATE); + EXPP_ADDCONST(GL_DECAL); + + EXPP_ADDCONST(GL_TEXTURE_ENV_MODE); + EXPP_ADDCONST(GL_TEXTURE_ENV_COLOR); + + EXPP_ADDCONST(GL_TEXTURE_ENV); + + EXPP_ADDCONST(GL_EYE_LINEAR); + EXPP_ADDCONST(GL_OBJECT_LINEAR); + EXPP_ADDCONST(GL_SPHERE_MAP); + + EXPP_ADDCONST(GL_TEXTURE_GEN_MODE); + EXPP_ADDCONST(GL_OBJECT_PLANE); + EXPP_ADDCONST(GL_EYE_PLANE); + + EXPP_ADDCONST(GL_NEAREST); + EXPP_ADDCONST(GL_LINEAR); + + EXPP_ADDCONST(GL_NEAREST_MIPMAP_NEAREST); + EXPP_ADDCONST(GL_LINEAR_MIPMAP_NEAREST); + EXPP_ADDCONST(GL_NEAREST_MIPMAP_LINEAR); + EXPP_ADDCONST(GL_LINEAR_MIPMAP_LINEAR); + + EXPP_ADDCONST(GL_TEXTURE_MAG_FILTER); + EXPP_ADDCONST(GL_TEXTURE_MIN_FILTER); + EXPP_ADDCONST(GL_TEXTURE_WRAP_S); + EXPP_ADDCONST(GL_TEXTURE_WRAP_T); + + EXPP_ADDCONST(GL_CLAMP); + EXPP_ADDCONST(GL_REPEAT); + + EXPP_ADDCONST(GL_CLIP_PLANE0); + EXPP_ADDCONST(GL_CLIP_PLANE1); + EXPP_ADDCONST(GL_CLIP_PLANE2); + EXPP_ADDCONST(GL_CLIP_PLANE3); + EXPP_ADDCONST(GL_CLIP_PLANE4); + EXPP_ADDCONST(GL_CLIP_PLANE5); + + EXPP_ADDCONST(GL_LIGHT0); + EXPP_ADDCONST(GL_LIGHT1); + EXPP_ADDCONST(GL_LIGHT2); + EXPP_ADDCONST(GL_LIGHT3); + EXPP_ADDCONST(GL_LIGHT4); + EXPP_ADDCONST(GL_LIGHT5); + EXPP_ADDCONST(GL_LIGHT6); + EXPP_ADDCONST(GL_LIGHT7); + + EXPP_ADDCONST(GL_POLYGON_OFFSET_UNITS); + EXPP_ADDCONST(GL_POLYGON_OFFSET_POINT); + EXPP_ADDCONST(GL_POLYGON_OFFSET_LINE); + EXPP_ADDCONST(GL_POLYGON_OFFSET_FILL); + EXPP_ADDCONST(GL_POLYGON_OFFSET_FACTOR); + + EXPP_ADDCONST(GL_TEXTURE_PRIORITY); + EXPP_ADDCONST(GL_TEXTURE_RESIDENT); + EXPP_ADDCONST(GL_TEXTURE_BINDING_1D); + EXPP_ADDCONST(GL_TEXTURE_BINDING_2D); + + return mod; +} diff --git a/source/blender/python/api2_2x/BGL.h b/source/blender/python/api2_2x/BGL.h new file mode 100644 index 00000000000..2da80b4555c --- /dev/null +++ b/source/blender/python/api2_2x/BGL.h @@ -0,0 +1,424 @@ +/* + * + * ***** BEGIN GPL/BL DUAL 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. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * 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. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * This is a new part of Blender. + * + * Contributor(s): Willian P. Germano + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** +*/ + +/* This is the Blender.BGL part of opy_draw.c, from the old bpython/intern + * dir, with minor changes to adapt it to the new Python implementation. + * The BGL submodule "wraps" OpenGL functions and constants, allowing script + * writers to make OpenGL calls in their Python scripts for Blender. The + * more important original comments are marked with an @ symbol. */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#ifdef WIN32 +#include "BLI_winstuff.h" +#endif + +#include "MEM_guardedalloc.h" + +#include "BMF_Api.h" + +#include "DNA_screen_types.h" +#include "DNA_space_types.h" +#include "DNA_text_types.h" + +#include "BKE_global.h" + +#include "BIF_gl.h" +#include "BIF_screen.h" +#include "BIF_space.h" +#include "BIF_interface.h" +#include "BIF_mywindow.h" + +#include "interface.h" +#include "mydevice.h" /*@ for all the event constants */ + +#include "Python.h" + +#include "gen_utils.h" +#include "modules.h" + +/*@ Buffer Object */ +/*@ For Python access to OpenGL functions requiring a pointer. */ + +typedef struct _Buffer { + PyObject_VAR_HEAD + + PyObject *parent; + + int type; /* GL_BYTE, GL_SHORT, GL_INT, GL_FLOAT */ + int ndimensions; + int *dimensions; + + union { + char *asbyte; + short *asshort; + int *asint; + float *asfloat; + + void *asvoid; + } buf; +} Buffer; + +static int type_size(int type); +static Buffer *make_buffer(int type, int ndimensions, int *dimensions); +static int Buffer_ass_slice(PyObject *self, int begin, int end, PyObject *seq); + +static char Method_Buffer_doc[]= +"(type, dimensions, [template]) - Create a new Buffer object\n\n\ +(type) - The format to store data in\n\ +(dimensions) - An int or sequence specifying the dimensions of the buffer\n\ +[template] - A sequence of matching dimensions to the buffer to be created\n\ + which will be used to initialize the Buffer.\n\n\ +If a template is not passed in all fields will be initialized to 0.\n\n\ +The type should be one of GL_BYTE, GL_SHORT, GL_INT, or GL_FLOAT.\n\ +If the dimensions are specified as an int a linear buffer will be\n\ +created. If a sequence is passed for the dimensions the buffer\n\ +will have len(sequence) dimensions, where the size for each dimension\n\ +is determined by the value in the sequence at that index.\n\n\ +For example, passing [100, 100] will create a 2 dimensional\n\ +square buffer. Passing [16, 16, 32] will create a 3 dimensional\n\ +buffer which is twice as deep as it is wide or high."; + +static PyObject *Method_Buffer (PyObject *self, PyObject *args); + +/* Buffer sequence methods */ + +static int Buffer_len(PyObject *self); +static PyObject *Buffer_item(PyObject *self, int i); +static PyObject *Buffer_slice(PyObject *self, int begin, int end); +static int Buffer_ass_item(PyObject *self, int i, PyObject *v); +static int Buffer_ass_slice(PyObject *self, int begin, int end, PyObject *seq); + +static PySequenceMethods Buffer_SeqMethods = { + (inquiry) Buffer_len, /*sq_length*/ + (binaryfunc) 0, /*sq_concat*/ + (intargfunc) 0, /*sq_repeat*/ + (intargfunc) Buffer_item, /*sq_item*/ + (intintargfunc) Buffer_slice, /*sq_slice*/ + (intobjargproc) Buffer_ass_item, /*sq_ass_item*/ + (intintobjargproc) Buffer_ass_slice, /*sq_ass_slice*/ +}; + +static void Buffer_dealloc(PyObject *self); +static PyObject *Buffer_tolist(PyObject *self); +static PyObject *Buffer_dimensions(PyObject *self); +static PyObject *Buffer_getattr(PyObject *self, char *name); +static PyObject *Buffer_repr(PyObject *self); + +PyTypeObject Buffer_Type = { + PyObject_HEAD_INIT(&PyType_Type) + 0, /*ob_size*/ + "Buffer", /*tp_name*/ + sizeof(Buffer), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + (destructor) Buffer_dealloc, /*tp_dealloc*/ + (printfunc) 0, /*tp_print*/ + (getattrfunc) Buffer_getattr, /*tp_getattr*/ + (setattrfunc) 0, /*tp_setattr*/ + (cmpfunc) 0, /*tp_compare*/ + (reprfunc) Buffer_repr, /*tp_repr*/ + 0, /*tp_as_number*/ + &Buffer_SeqMethods, /*tp_as_sequence*/ +}; + +#ifndef __APPLE__ +/*@ By golly George! It looks like fancy pants macro time!!! */ + +/* +#define int_str "i" +#define int_var(number) bgl_int##number +#define int_ref(number) &bgl_int##number +#define int_def(number) int int_var(number) + +#define float_str "f" +#define float_var(number) bgl_float##number +#define float_ref(number) &bgl_float##number +#define float_def(number) float float_var(number) +*/ + +/* TYPE_str is the string to pass to Py_ArgParse (for the format) */ +/* TYPE_var is the name to pass to the GL function */ +/* TYPE_ref is the pointer to pass to Py_ArgParse (to store in) */ +/* TYPE_def is the C initialization of the variable */ + +#define void_str "" +#define void_var(num) +#define void_ref(num) &bgl_var##num +#define void_def(num) char bgl_var##num + +#define buffer_str "O!" +#define buffer_var(number) (bgl_buffer##number)->buf.asvoid +#define buffer_ref(number) &Buffer_Type, &bgl_buffer##number +#define buffer_def(number) Buffer *bgl_buffer##number + +/* GL Pointer fields, handled by buffer type */ +/* GLdoubleP, GLfloatP, GLintP, GLuintP, GLshortP */ + +#define GLbooleanP_str "O!" +#define GLbooleanP_var(number) (bgl_buffer##number)->buf.asvoid +#define GLbooleanP_ref(number) &Buffer_Type, &bgl_buffer##number +#define GLbooleanP_def(number) Buffer *bgl_buffer##number + +#define GLbyteP_str "O!" +#define GLbyteP_var(number) (bgl_buffer##number)->buf.asvoid +#define GLbyteP_ref(number) &Buffer_Type, &bgl_buffer##number +#define GLbyteP_def(number) Buffer *bgl_buffer##number + +#define GLubyteP_str "O!" +#define GLubyteP_var(number) (bgl_buffer##number)->buf.asvoid +#define GLubyteP_ref(number) &Buffer_Type, &bgl_buffer##number +#define GLubyteP_def(number) Buffer *bgl_buffer##number + +#define GLintP_str "O!" +#define GLintP_var(number) (bgl_buffer##number)->buf.asvoid +#define GLintP_ref(number) &Buffer_Type, &bgl_buffer##number +#define GLintP_def(number) Buffer *bgl_buffer##number + +#define GLuintP_str "O!" +#define GLuintP_var(number) (bgl_buffer##number)->buf.asvoid +#define GLuintP_ref(number) &Buffer_Type, &bgl_buffer##number +#define GLuintP_def(number) Buffer *bgl_buffer##number + +#define GLshortP_str "O!" +#define GLshortP_var(number) (bgl_buffer##number)->buf.asvoid +#define GLshortP_ref(number) &Buffer_Type, &bgl_buffer##number +#define GLshortP_def(number) Buffer *bgl_buffer##number + +#define GLushortP_str "O!" +#define GLushortP_var(number) (bgl_buffer##number)->buf.asvoid +#define GLushortP_ref(number) &Buffer_Type, &bgl_buffer##number +#define GLushortP_def(number) Buffer *bgl_buffer##number + +#define GLfloatP_str "O!" +#define GLfloatP_var(number) (bgl_buffer##number)->buf.asvoid +#define GLfloatP_ref(number) &Buffer_Type, &bgl_buffer##number +#define GLfloatP_def(number) Buffer *bgl_buffer##number + +#define GLdoubleP_str "O!" +#define GLdoubleP_var(number) (bgl_buffer##number)->buf.asvoid +#define GLdoubleP_ref(number) &Buffer_Type, &bgl_buffer##number +#define GLdoubleP_def(number) Buffer *bgl_buffer##number + +#define GLclampfP_str "O!" +#define GLclampfP_var(number) (bgl_buffer##number)->buf.asvoid +#define GLclampfP_ref(number) &Buffer_Type, &bgl_buffer##number +#define GLclampfP_def(number) Buffer *bgl_buffer##number + +#define GLvoidP_str "O!" +#define GLvoidP_var(number) (bgl_buffer##number)->buf.asvoid +#define GLvoidP_ref(number) &Buffer_Type, &bgl_buffer##number +#define GLvoidP_def(number) Buffer *bgl_buffer##number + +#define buffer_str "O!" +#define buffer_var(number) (bgl_buffer##number)->buf.asvoid +#define buffer_ref(number) &Buffer_Type, &bgl_buffer##number +#define buffer_def(number) Buffer *bgl_buffer##number + +/*@The standard GL typedefs are used as prototypes, we can't + * use the GL type directly because Py_ArgParse expects normal + * C types. + * + * Py_ArgParse doesn't grok writing into unsigned variables, + * so we use signed everything (even stuff that should be unsigned. + */ + +/* typedef unsigned int GLenum; */ +#define GLenum_str "i" +#define GLenum_var(num) bgl_var##num +#define GLenum_ref(num) &bgl_var##num +#define GLenum_def(num) /* unsigned */ int GLenum_var(num) + +/* typedef unsigned int GLboolean; */ +#define GLboolean_str "b" +#define GLboolean_var(num) bgl_var##num +#define GLboolean_ref(num) &bgl_var##num +#define GLboolean_def(num) /* unsigned */ char GLboolean_var(num) + +/* typedef unsigned int GLbitfield; */ +#define GLbitfield_str "i" +#define GLbitfield_var(num) bgl_var##num +#define GLbitfield_ref(num) &bgl_var##num +#define GLbitfield_def(num) /* unsigned */ int GLbitfield_var(num) + +/* typedef signed char GLbyte; */ +#define GLbyte_str "b" +#define GLbyte_var(num) bgl_var##num +#define GLbyte_ref(num) &bgl_var##num +#define GLbyte_def(num) signed char GLbyte_var(num) + +/* typedef short GLshort; */ +#define GLshort_str "h" +#define GLshort_var(num) bgl_var##num +#define GLshort_ref(num) &bgl_var##num +#define GLshort_def(num) short GLshort_var(num) + +/* typedef int GLint; */ +#define GLint_str "i" +#define GLint_var(num) bgl_var##num +#define GLint_ref(num) &bgl_var##num +#define GLint_def(num) int GLint_var(num) + +/* typedef int GLsizei; */ +#define GLsizei_str "i" +#define GLsizei_var(num) bgl_var##num +#define GLsizei_ref(num) &bgl_var##num +#define GLsizei_def(num) int GLsizei_var(num) + +/* typedef unsigned char GLubyte; */ +#define GLubyte_str "b" +#define GLubyte_var(num) bgl_var##num +#define GLubyte_ref(num) &bgl_var##num +#define GLubyte_def(num) /* unsigned */ char GLubyte_var(num) + +/* typedef unsigned short GLushort; */ +#define GLushort_str "h" +#define GLushort_var(num) bgl_var##num +#define GLushort_ref(num) &bgl_var##num +#define GLushort_def(num) /* unsigned */ short GLushort_var(num) + +/* typedef unsigned int GLuint; */ +#define GLuint_str "i" +#define GLuint_var(num) bgl_var##num +#define GLuint_ref(num) &bgl_var##num +#define GLuint_def(num) /* unsigned */ int GLuint_var(num) + +/* typedef float GLfloat; */ +#define GLfloat_str "f" +#define GLfloat_var(num) bgl_var##num +#define GLfloat_ref(num) &bgl_var##num +#define GLfloat_def(num) float GLfloat_var(num) + +/* typedef float GLclampf; */ +#define GLclampf_str "f" +#define GLclampf_var(num) bgl_var##num +#define GLclampf_ref(num) &bgl_var##num +#define GLclampf_def(num) float GLclampf_var(num) + +/* typedef double GLdouble; */ +#define GLdouble_str "d" +#define GLdouble_var(num) bgl_var##num +#define GLdouble_ref(num) &bgl_var##num +#define GLdouble_def(num) double GLdouble_var(num) + +/* typedef double GLclampd; */ +#define GLclampd_str "d" +#define GLclampd_var(num) bgl_var##num +#define GLclampd_ref(num) &bgl_var##num +#define GLclampd_def(num) double GLclampd_var(num) + +/* typedef void GLvoid; */ +/* #define GLvoid_str "" */ +/* #define GLvoid_var(num) bgl_var##num */ +/* #define GLvoid_ref(num) &bgl_var##num */ +/* #define GLvoid_def(num) char bgl_var##num */ + +#define arg_def1(a1) a1##_def(1) +#define arg_def2(a1, a2) arg_def1(a1); a2##_def(2) +#define arg_def3(a1, a2, a3) arg_def2(a1, a2); a3##_def(3) +#define arg_def4(a1, a2, a3, a4) arg_def3(a1, a2, a3); a4##_def(4) +#define arg_def5(a1, a2, a3, a4, a5) arg_def4(a1, a2, a3, a4); a5##_def(5) +#define arg_def6(a1, a2, a3, a4, a5, a6)arg_def5(a1, a2, a3, a4, a5); a6##_def(6) +#define arg_def7(a1, a2, a3, a4, a5, a6, a7)arg_def6(a1, a2, a3, a4, a5, a6); a7##_def(7) +#define arg_def8(a1, a2, a3, a4, a5, a6, a7, a8)arg_def7(a1, a2, a3, a4, a5, a6, a7); a8##_def(8) +#define arg_def9(a1, a2, a3, a4, a5, a6, a7, a8, a9)arg_def8(a1, a2, a3, a4, a5, a6, a7, a8); a9##_def(9) +#define arg_def10(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)arg_def9(a1, a2, a3, a4, a5, a6, a7, a8, a9); a10##_def(10) + +#define arg_var1(a1) a1##_var(1) +#define arg_var2(a1, a2) arg_var1(a1), a2##_var(2) +#define arg_var3(a1, a2, a3) arg_var2(a1, a2), a3##_var(3) +#define arg_var4(a1, a2, a3, a4) arg_var3(a1, a2, a3), a4##_var(4) +#define arg_var5(a1, a2, a3, a4, a5) arg_var4(a1, a2, a3, a4), a5##_var(5) +#define arg_var6(a1, a2, a3, a4, a5, a6)arg_var5(a1, a2, a3, a4, a5), a6##_var(6) +#define arg_var7(a1, a2, a3, a4, a5, a6, a7)arg_var6(a1, a2, a3, a4, a5, a6), a7##_var(7) +#define arg_var8(a1, a2, a3, a4, a5, a6, a7, a8)arg_var7(a1, a2, a3, a4, a5, a6, a7), a8##_var(8) +#define arg_var9(a1, a2, a3, a4, a5, a6, a7, a8, a9)arg_var8(a1, a2, a3, a4, a5, a6, a7, a8), a9##_var(9) +#define arg_var10(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)arg_var9(a1, a2, a3, a4, a5, a6, a7, a8, a9), a10##_var(10) + +#define arg_ref1(a1) a1##_ref(1) +#define arg_ref2(a1, a2) arg_ref1(a1), a2##_ref(2) +#define arg_ref3(a1, a2, a3) arg_ref2(a1, a2), a3##_ref(3) +#define arg_ref4(a1, a2, a3, a4) arg_ref3(a1, a2, a3), a4##_ref(4) +#define arg_ref5(a1, a2, a3, a4, a5) arg_ref4(a1, a2, a3, a4), a5##_ref(5) +#define arg_ref6(a1, a2, a3, a4, a5, a6)arg_ref5(a1, a2, a3, a4, a5), a6##_ref(6) +#define arg_ref7(a1, a2, a3, a4, a5, a6, a7)arg_ref6(a1, a2, a3, a4, a5, a6), a7##_ref(7) +#define arg_ref8(a1, a2, a3, a4, a5, a6, a7, a8)arg_ref7(a1, a2, a3, a4, a5, a6, a7), a8##_ref(8) +#define arg_ref9(a1, a2, a3, a4, a5, a6, a7, a8, a9)arg_ref8(a1, a2, a3, a4, a5, a6, a7, a8), a9##_ref(9) +#define arg_ref10(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)arg_ref9(a1, a2, a3, a4, a5, a6, a7, a8, a9), a10##_ref(10) + +#define arg_str1(a1) a1##_str +#define arg_str2(a1, a2) arg_str1(a1) a2##_str +#define arg_str3(a1, a2, a3) arg_str2(a1, a2) a3##_str +#define arg_str4(a1, a2, a3, a4) arg_str3(a1, a2, a3) a4##_str +#define arg_str5(a1, a2, a3, a4, a5) arg_str4(a1, a2, a3, a4) a5##_str +#define arg_str6(a1, a2, a3, a4, a5, a6)arg_str5(a1, a2, a3, a4, a5) a6##_str +#define arg_str7(a1, a2, a3, a4, a5, a6, a7)arg_str6(a1, a2, a3, a4, a5, a6) a7##_str +#define arg_str8(a1, a2, a3, a4, a5, a6, a7, a8)arg_str7(a1, a2, a3, a4, a5, a6, a7) a8##_str +#define arg_str9(a1, a2, a3, a4, a5, a6, a7, a8, a9)arg_str8(a1, a2, a3, a4, a5, a6, a7, a8) a9##_str +#define arg_str10(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)arg_str9(a1, a2, a3, a4, a5, a6, a7, a8, a9) a10##_str + +#define ret_def_void +#define ret_set_void +#define ret_ret_void return EXPP_incr_ret(Py_None) + +#define ret_def_GLint int ret_int +#define ret_set_GLint ret_int= +#define ret_ret_GLint return PyInt_FromLong(ret_int); + +#define ret_def_GLuint unsigned int ret_uint +#define ret_set_GLuint ret_uint= +#define ret_ret_GLuint return PyInt_FromLong((long) ret_uint); + +#define ret_def_GLenum unsigned int ret_uint +#define ret_set_GLenum ret_uint= +#define ret_ret_GLenum return PyInt_FromLong((long) ret_uint); + +#define ret_def_GLboolean unsigned char ret_bool +#define ret_set_GLboolean ret_bool= +#define ret_ret_GLboolean return PyInt_FromLong((long) ret_bool); + +#define ret_def_GLstring const unsigned char *ret_str; +#define ret_set_GLstring ret_str= +#define ret_ret_GLstring return PyString_FromString(ret_str); + +#define BGL_Wrap(nargs, funcname, ret, arg_list) \ +static PyObject *Method_##funcname (PyObject *self, PyObject *args) {\ + arg_def##nargs arg_list; \ + ret_def_##ret; \ + if(!PyArg_ParseTuple(args, arg_str##nargs arg_list, arg_ref##nargs arg_list)) return NULL;\ + ret_set_##ret gl##funcname (arg_var##nargs arg_list);\ + ret_ret_##ret; \ +} + +#endif + +PyObject *M_BGL_Init(void); diff --git a/source/blender/python/api2_2x/Blender.c b/source/blender/python/api2_2x/Blender.c index 22dc43771ae..dcc4a0dfe7e 100644 --- a/source/blender/python/api2_2x/Blender.c +++ b/source/blender/python/api2_2x/Blender.c @@ -193,7 +193,10 @@ void initBlender (void) g_blenderdict = dict; PyDict_SetItemString (dict, "Object", initObject()); PyDict_SetItemString (dict, "Camera", M_Camera_Init()); - PyDict_SetItemString (dict, "Lamp", M_Lamp_Init()); - PyDict_SetItemString (dict, "Image", M_Image_Init()); + PyDict_SetItemString (dict, "Lamp", M_Lamp_Init()); + PyDict_SetItemString (dict, "Image", M_Image_Init()); + PyDict_SetItemString (dict, "Window", M_Window_Init()); + PyDict_SetItemString (dict, "Draw", M_Draw_Init()); + PyDict_SetItemString (dict, "BGL", M_BGL_Init()); } diff --git a/source/blender/python/api2_2x/Camera.c b/source/blender/python/api2_2x/Camera.c index f3f7ba6d4a8..81646cae727 100644 --- a/source/blender/python/api2_2x/Camera.c +++ b/source/blender/python/api2_2x/Camera.c @@ -38,78 +38,50 @@ static PyObject *M_Camera_New(PyObject *self, PyObject *args, PyObject *keywords) { char *type_str = "persp"; /* "persp" is type 0, "ortho" is type 1 */ - char *name_str = "Data"; + char *name_str = "CamData"; static char *kwlist[] = {"type_str", "name_str", NULL}; - C_Camera *cam; - PyObject *type, *name; - int type_int; + C_Camera *pycam; /* for Camera Data object wrapper in Python */ + Camera *blcam; /* for actual Camera Data we create in Blender */ char buf[21]; printf ("In Camera_New()\n"); if (!PyArg_ParseTupleAndKeywords(args, keywords, "|ss", kwlist, &type_str, &name_str)) - { - /* We expected string(s) (or nothing) as argument, but we didn't get it. */ - return (PythonReturnErrorObject (PyExc_AttributeError, + /* We expected string(s) (or nothing) as argument, but we didn't get that. */ + return (EXPP_ReturnPyObjError (PyExc_AttributeError, "expected zero, one or two strings as arguments")); - } - if (strcmp (type_str, "persp") == 0) - type_int = EXPP_CAM_TYPE_PERSP; + blcam = add_camera(); /* first create the Camera Data in Blender */ + + if (blcam) /* now create the wrapper obj in Python */ + pycam = (C_Camera *)PyObject_NEW(C_Camera, &Camera_Type); else - { - if (strcmp (type_str, "ortho") == 0) - { - type_int = EXPP_CAM_TYPE_ORTHO; - } - else - { - return (PythonReturnErrorObject (PyExc_AttributeError, - "unknown camera type")); - } - } + return (EXPP_ReturnPyObjError (PyExc_RuntimeError, + "couldn't create Camera Data in Blender")); - cam = (C_Camera *)CameraCreatePyObject(NULL); + if (pycam == NULL) + return (EXPP_ReturnPyObjError (PyExc_MemoryError, + "couldn't create Camera Data object")); - if (cam == NULL) - { - return (PythonReturnErrorObject (PyExc_MemoryError, - "couldn't create Camera Data object")); - } - cam->linked = 0; /* only Camera Data, not linked */ + pycam->camera = blcam; /* link Python camera wrapper to Blender Camera */ - type = PyInt_FromLong(type_int); - if (type) - { - CameraSetAttr(cam, "type", type); - } + if (strcmp (type_str, "persp") == 0) /* default, no need to set, so */ + /*blcam->type = (short)EXPP_CAM_TYPE_PERSP*/; /* we comment this line */ + else if (strcmp (type_str, "ortho") == 0) + blcam->type = (short)EXPP_CAM_TYPE_ORTHO; else - { - Py_DECREF((PyObject *)cam); - return (PythonReturnErrorObject (PyExc_MemoryError, - "couldn't create PyString")); - } - - if (strcmp(name_str, "Data") == 0) - { - return (PyObject *)cam; - } + return (EXPP_ReturnPyObjError (PyExc_AttributeError, + "unknown camera type")); - PyOS_snprintf(buf, sizeof(buf), "%s", name_str); - name = PyString_FromString(buf); - if (name) - { - CameraSetAttr(cam, "name", name); - } - else - { - Py_DECREF((PyObject *)cam); - return (PythonReturnErrorObject (PyExc_MemoryError, - "couldn't create PyString")); + if (strcmp(name_str, "CamData") == 0) + return (PyObject *)pycam; + else { /* user gave us a name for the camera, use it */ + PyOS_snprintf(buf, sizeof(buf), "%s", name_str); + rename_id(&blcam->id, buf); /* proper way in Blender */ } - return (PyObject *)cam; + return (PyObject *)pycam; } /*****************************************************************************/ @@ -124,35 +96,31 @@ static PyObject *M_Camera_Get(PyObject *self, PyObject *args) printf ("In Camera_Get()\n"); if (!PyArg_ParseTuple(args, "s", &name)) - { - return (PythonReturnErrorObject (PyExc_AttributeError, + return (EXPP_ReturnPyObjError (PyExc_AttributeError, "expected string argument")); - } - /* Use the name to search for the camera requested. */ + /* Use the name to search for the camera requested */ wanted_cam = NULL; cam_iter = G.main->camera.first; - while ((cam_iter) && (wanted_cam == NULL)) - { - if (strcmp (name, GetIdName (&(cam_iter->id))) == 0) - { - wanted_cam = (C_Camera *)CameraCreatePyObject(cam_iter); - cam_iter = cam_iter->id.next; + while ((cam_iter) && (wanted_cam == NULL)) { + + if (strcmp (name, cam_iter->id.name+2) == 0) { + wanted_cam = (C_Camera *)PyObject_NEW(C_Camera, &Camera_Type); + if (wanted_cam) wanted_cam->camera = cam_iter; } + + cam_iter = cam_iter->id.next; } - if (wanted_cam == NULL) - { - /* No camera exists with the name specified in the argument name. */ + if (wanted_cam == NULL) { /* Requested camera doesn't exist */ char error_msg[64]; PyOS_snprintf(error_msg, sizeof(error_msg), "Camera \"%s\" not found", name); - return (PythonReturnErrorObject (PyExc_NameError, error_msg)); + return (EXPP_ReturnPyObjError (PyExc_NameError, error_msg)); } - wanted_cam->linked = 1; /* TRUE: linked to a Blender Camera Object */ - return ((PyObject*)wanted_cam); + return (PyObject*)wanted_cam; } /*****************************************************************************/ @@ -160,13 +128,13 @@ static PyObject *M_Camera_Get(PyObject *self, PyObject *args) /*****************************************************************************/ PyObject *M_Camera_Init (void) { - PyObject *module; + PyObject *submodule; printf ("In M_Camera_Init()\n"); + submodule = Py_InitModule3("Blender.Camera", + M_Camera_methods, M_Camera_doc); - module = Py_InitModule3("Camera", M_Camera_methods, M_Camera_doc); - - return (module); + return (submodule); } /*****************************************************************************/ @@ -174,137 +142,86 @@ PyObject *M_Camera_Init (void) /*****************************************************************************/ static PyObject *Camera_getName(C_Camera *self) { - PyObject *attr; - attr = PyDict_GetItemString(self->dict, "name"); - if (attr) - { - Py_INCREF(attr); - return attr; - } - return (PythonReturnErrorObject (PyExc_RuntimeError, + PyObject *attr = PyString_FromString(self->camera->id.name+2); + + if (attr) return attr; + + return (EXPP_ReturnPyObjError (PyExc_RuntimeError, "couldn't get Camera.name attribute")); } static PyObject *Camera_getType(C_Camera *self) -{ - PyObject *attr; +{ + PyObject *attr = PyInt_FromLong(self->camera->type); - attr = PyDict_GetItemString(self->dict, "type"); - if (attr) - { - Py_INCREF(attr); - return attr; - } - return (PythonReturnErrorObject (PyExc_RuntimeError, + if (attr) return attr; + + return (EXPP_ReturnPyObjError (PyExc_RuntimeError, "couldn't get Camera.type attribute")); } static PyObject *Camera_getMode(C_Camera *self) { - PyObject *attr; + PyObject *attr = PyInt_FromLong(self->camera->flag); - attr = PyDict_GetItemString(self->dict, "mode"); - if (attr) - { - Py_INCREF(attr); - return attr; - } - return (PythonReturnErrorObject (PyExc_RuntimeError, + if (attr) return attr; + + return (EXPP_ReturnPyObjError (PyExc_RuntimeError, "couldn't get Camera.Mode attribute")); } static PyObject *Camera_getLens(C_Camera *self) { - PyObject *attr; + PyObject *attr = PyFloat_FromDouble(self->camera->lens); - attr = PyDict_GetItemString(self->dict, "lens"); - if (attr) - { - Py_INCREF(attr); - return attr; - } - return (PythonReturnErrorObject (PyExc_RuntimeError, + if (attr) return attr; + + return (EXPP_ReturnPyObjError (PyExc_RuntimeError, "couldn't get Camera.lens attribute")); } static PyObject *Camera_getClipStart(C_Camera *self) { - PyObject *attr; + PyObject *attr = PyFloat_FromDouble(self->camera->clipsta); - attr = PyDict_GetItemString(self->dict, "clipStart"); - if (attr) - { - Py_INCREF(attr); - return attr; - } - return (PythonReturnErrorObject (PyExc_RuntimeError, + if (attr) return attr; + + return (EXPP_ReturnPyObjError (PyExc_RuntimeError, "couldn't get Camera.clipStart attribute")); } static PyObject *Camera_getClipEnd(C_Camera *self) { - PyObject *attr; + PyObject *attr = PyFloat_FromDouble(self->camera->clipend); - attr = PyDict_GetItemString(self->dict, "clipEnd"); - if (attr) - { - Py_INCREF(attr); - return attr; - } - return (PythonReturnErrorObject (PyExc_RuntimeError, + if (attr) return attr; + + return (EXPP_ReturnPyObjError (PyExc_RuntimeError, "couldn't get Camera.clipEnd attribute")); } static PyObject *Camera_getDrawSize(C_Camera *self) { - PyObject *attr; + PyObject *attr = PyFloat_FromDouble(self->camera->drawsize); - attr = PyDict_GetItemString(self->dict, "drawSize"); - if (attr) - { - Py_INCREF(attr); - return attr; - } - return (PythonReturnErrorObject (PyExc_RuntimeError, + if (attr) return attr; + + return (EXPP_ReturnPyObjError (PyExc_RuntimeError, "couldn't get Camera.drawSize attribute")); } static PyObject *Camera_rename(C_Camera *self, PyObject *args) { - char *name_str; - char buf[21]; - PyObject *name; + char *name; + char buf[21]; - if (!PyArg_ParseTuple(args, "s", &name_str)) - { - return (PythonReturnErrorObject (PyExc_AttributeError, + if (!PyArg_ParseTuple(args, "s", &name)) + return (EXPP_ReturnPyObjError (PyExc_AttributeError, "expected string argument")); - } - - PyOS_snprintf(buf, sizeof(buf), "%s", name_str); - - if (self->linked) - { - /* update the Blender Camera, too */ - ID *tmp_id = &self->camera->id; - rename_id(tmp_id, buf); - PyOS_snprintf(buf, sizeof(buf), "%s", tmp_id->name+2);/* may have changed */ - } - name = PyString_FromString(buf); + PyOS_snprintf(buf, sizeof(buf), "%s", name); - if (!name) - { - return (PythonReturnErrorObject (PyExc_MemoryError, - "couldn't create PyString Object")); - } - - if (PyDict_SetItemString(self->dict, "name", name) != 0) - { - Py_DECREF(name); - return (PythonReturnErrorObject (PyExc_RuntimeError, - "couldn't set Camera.name attribute")); - } + rename_id(&self->camera->id, buf); Py_INCREF(Py_None); return Py_None; @@ -312,45 +229,19 @@ static PyObject *Camera_rename(C_Camera *self, PyObject *args) static PyObject *Camera_setType(C_Camera *self, PyObject *args) { - short value; - char *type_str; - PyObject *type; + char *type; - if (!PyArg_ParseTuple(args, "s", &type_str)) - { - return (PythonReturnErrorObject (PyExc_AttributeError, + if (!PyArg_ParseTuple(args, "s", &type)) + return (EXPP_ReturnPyObjError (PyExc_AttributeError, "expected string argument")); - } - if (strcmp (type_str, "persp") == 0) - value = EXPP_CAM_TYPE_PERSP; - else if (strcmp (type_str, "ortho") == 0) - value = EXPP_CAM_TYPE_ORTHO; + if (strcmp (type, "persp") == 0) + self->camera->type = (short)EXPP_CAM_TYPE_PERSP; + else if (strcmp (type, "ortho") == 0) + self->camera->type = (short)EXPP_CAM_TYPE_ORTHO; else - { - return (PythonReturnErrorObject (PyExc_AttributeError, + return (EXPP_ReturnPyObjError (PyExc_AttributeError, "unknown camera type")); - } - - type = PyInt_FromLong(value); - if (!type) - { - return (PythonReturnErrorObject (PyExc_MemoryError, - "couldn't create PyInt Object")); - } - - if (PyDict_SetItemString(self->dict, "type", type) != 0) - { - Py_DECREF(type); - return (PythonReturnErrorObject (PyExc_RuntimeError, - "couldn't set Camera.type attribute")); - } - - if (self->linked) - { - /* update the Blender Camera, too */ - self->camera->type = value; - } Py_INCREF(Py_None); return Py_None; @@ -364,42 +255,16 @@ static PyObject *Camera_setType(C_Camera *self, PyObject *args) static PyObject *Camera_setIntType(C_Camera *self, PyObject *args) { short value; - PyObject *type; - if (!PyArg_ParseTuple(args, "i", &value)) - { - return (PythonReturnErrorObject (PyExc_AttributeError, + if (!PyArg_ParseTuple(args, "h", &value)) + return (EXPP_ReturnPyObjError (PyExc_AttributeError, "expected int argument: 0 or 1")); - } if (value == 0 || value == 1) - { - type = PyInt_FromLong(value); - } + self->camera->type = value; else - { - return (PythonReturnErrorObject (PyExc_AttributeError, + return (EXPP_ReturnPyObjError (PyExc_AttributeError, "expected int argument: 0 or 1")); - } - - if (!type) - { - return (PythonReturnErrorObject (PyExc_MemoryError, - "couldn't create PyInt Object")); - } - - if (PyDict_SetItemString(self->dict, "type", type) != 0) - { - Py_DECREF(type); - return (PythonReturnErrorObject (PyExc_RuntimeError, - "could not set Camera.type attribute")); - } - - if (self->linked) - { - /* update the Blender Camera, too */ - self->camera->type = value; - } Py_INCREF(Py_None); return Py_None; @@ -409,56 +274,32 @@ static PyObject *Camera_setMode(C_Camera *self, PyObject *args) { char *mode_str1 = NULL, *mode_str2 = NULL; short flag = 0; - PyObject *mode; if (!PyArg_ParseTuple(args, "|ss", &mode_str1, &mode_str2)) - { - return (PythonReturnErrorObject (PyExc_AttributeError, + return (EXPP_ReturnPyObjError (PyExc_AttributeError, "expected one or two strings as arguments")); - } - if (mode_str1 != NULL) - { + if (mode_str1 != NULL) { if (strcmp(mode_str1, "showLimits") == 0) - flag |= EXPP_CAM_MODE_SHOWLIMITS; + flag |= (short)EXPP_CAM_MODE_SHOWLIMITS; else if (strcmp(mode_str1, "showMist") == 0) - flag |= EXPP_CAM_MODE_SHOWMIST; + flag |= (short)EXPP_CAM_MODE_SHOWMIST; else - { - return (PythonReturnErrorObject (PyExc_AttributeError, + return (EXPP_ReturnPyObjError (PyExc_AttributeError, "first argument is an unknown camera flag")); - } - if (mode_str2 != NULL) - { + if (mode_str2 != NULL) { if (strcmp(mode_str2, "showLimits") == 0) - flag |= EXPP_CAM_MODE_SHOWLIMITS; + flag |= (short)EXPP_CAM_MODE_SHOWLIMITS; else if (strcmp(mode_str2, "showMist") == 0) - flag |= EXPP_CAM_MODE_SHOWMIST; + flag |= (short)EXPP_CAM_MODE_SHOWMIST; else - { - return (PythonReturnErrorObject (PyExc_AttributeError, + return (EXPP_ReturnPyObjError (PyExc_AttributeError, "second argument is an unknown camera flag")); - } } } - - mode = PyInt_FromLong(flag); - if (!mode) - { - return (PythonReturnErrorObject (PyExc_MemoryError, - "couldn't create PyInt Object")); - } - if (PyDict_SetItemString(self->dict, "mode", mode) != 0) - { - Py_DECREF(mode); - return (PythonReturnErrorObject (PyExc_RuntimeError, - "couldn't set Camera.mode attribute")); - } - - if (self->linked) /* update the Blender Camera, too */ - self->camera->flag = flag; + self->camera->flag = flag; Py_INCREF(Py_None); return Py_None; @@ -469,42 +310,16 @@ static PyObject *Camera_setMode(C_Camera *self, PyObject *args) static PyObject *Camera_setIntMode(C_Camera *self, PyObject *args) { short value; - PyObject *mode; if (!PyArg_ParseTuple(args, "h", &value)) - { - return (PythonReturnErrorObject (PyExc_AttributeError, + return (EXPP_ReturnPyObjError (PyExc_AttributeError, "expected int argument in [0,3]")); - } if (value >= 0 && value <= 3) - { - mode = PyInt_FromLong(value); - } + self->camera->flag = value; else - { - return (PythonReturnErrorObject (PyExc_AttributeError, + return (EXPP_ReturnPyObjError (PyExc_AttributeError, "expected int argument in [0,3]")); - } - - if (!mode) - { - return (PythonReturnErrorObject (PyExc_MemoryError, - "couldn't create PyInt object")); - } - - if (PyDict_SetItemString(self->dict, "mode", mode) != 0) - { - Py_DECREF(mode); - return (PythonReturnErrorObject (PyExc_RuntimeError, - "could not set Camera.mode attribute")); - } - - if (self->linked) - { - /* update the Blender Camera, too */ - self->camera->flag = value; - } Py_INCREF(Py_None); return Py_None; @@ -513,35 +328,14 @@ static PyObject *Camera_setIntMode(C_Camera *self, PyObject *args) static PyObject *Camera_setLens(C_Camera *self, PyObject *args) { float value; - PyObject *lens; if (!PyArg_ParseTuple(args, "f", &value)) - { - return (PythonReturnErrorObject (PyExc_AttributeError, + return (EXPP_ReturnPyObjError (PyExc_AttributeError, "expected float argument")); - } - value = EXPP_ClampFloat (value, EXPP_CAM_LENS_MIN, EXPP_CAM_LENS_MAX); - lens = PyFloat_FromDouble(value); - if (!lens) - { - return (PythonReturnErrorObject (PyExc_MemoryError, - "couldn't create PyFloat Object")); - } - - if (PyDict_SetItemString(self->dict, "lens", lens) != 0) - { - Py_DECREF(lens); - return (PythonReturnErrorObject (PyExc_RuntimeError, - "couldn't set Camera.lens attribute")); - } + self->camera->lens = EXPP_ClampFloat (value, + EXPP_CAM_LENS_MIN, EXPP_CAM_LENS_MAX); - if (self->linked) - { - /* update the Blender Camera, too */ - self->camera->lens = value; - } - Py_INCREF(Py_None); return Py_None; } @@ -549,37 +343,14 @@ static PyObject *Camera_setLens(C_Camera *self, PyObject *args) static PyObject *Camera_setClipStart(C_Camera *self, PyObject *args) { float value; - PyObject *clipStart; if (!PyArg_ParseTuple(args, "f", &value)) - { - return (PythonReturnErrorObject (PyExc_AttributeError, - "expected a float number as argument")); - } - - value = EXPP_ClampFloat (value, EXPP_CAM_CLIPSTART_MIN, - EXPP_CAM_CLIPSTART_MAX); - - clipStart = PyFloat_FromDouble(value); - if (!clipStart) - { - return (PythonReturnErrorObject (PyExc_MemoryError, - "couldn't create PyFloat Object")); - } + return (EXPP_ReturnPyObjError (PyExc_AttributeError, + "expected float argument")); - if (PyDict_SetItemString(self->dict, "clipStart", clipStart) != 0) - { - Py_DECREF(clipStart); - return (PythonReturnErrorObject (PyExc_RuntimeError, - "couldn't set Camera.clipStart attribute")); - } + self->camera->clipsta = EXPP_ClampFloat (value, + EXPP_CAM_CLIPSTART_MIN, EXPP_CAM_CLIPSTART_MAX); - if (self->linked) - { - /* update the Blender Camera, too */ - self->camera->clipsta = value; - } - Py_INCREF(Py_None); return Py_None; } @@ -587,35 +358,13 @@ static PyObject *Camera_setClipStart(C_Camera *self, PyObject *args) static PyObject *Camera_setClipEnd(C_Camera *self, PyObject *args) { float value; - PyObject *clipEnd; if (!PyArg_ParseTuple(args, "f", &value)) - { - return (PythonReturnErrorObject (PyExc_AttributeError, - "expected a float number as argument")); - } - - value = EXPP_ClampFloat (value, EXPP_CAM_CLIPEND_MIN, EXPP_CAM_CLIPEND_MAX); - - clipEnd = PyFloat_FromDouble(value); - if (!clipEnd) - { - return (PythonReturnErrorObject (PyExc_MemoryError, - "couldn't create PyFloat Object")); - } + return (EXPP_ReturnPyObjError (PyExc_AttributeError, + "expected float argument")); - if (PyDict_SetItemString(self->dict, "clipEnd", clipEnd) != 0) - { - Py_DECREF(clipEnd); - return (PythonReturnErrorObject (PyExc_RuntimeError, - "couldn't set Camera.clipEnd attribute")); - } - - if (self->linked) - { - /* update the Blender Camera, too */ - self->camera->clipend = value; - } + self->camera->clipend = EXPP_ClampFloat (value, + EXPP_CAM_CLIPEND_MIN, EXPP_CAM_CLIPEND_MAX); Py_INCREF(Py_None); return Py_None; @@ -624,233 +373,103 @@ static PyObject *Camera_setClipEnd(C_Camera *self, PyObject *args) static PyObject *Camera_setDrawSize(C_Camera *self, PyObject *args) { float value; - PyObject *drawSize; if (!PyArg_ParseTuple(args, "f", &value)) - { - return (PythonReturnErrorObject (PyExc_AttributeError, + return (EXPP_ReturnPyObjError (PyExc_AttributeError, "expected a float number as argument")); - } - - value = EXPP_ClampFloat (value, EXPP_CAM_DRAWSIZE_MIN, - EXPP_CAM_DRAWSIZE_MAX); - drawSize = PyFloat_FromDouble(value); - if (!drawSize) - { - return (PythonReturnErrorObject (PyExc_MemoryError, - "couldn't create PyFloat Object")); - } - - if (PyDict_SetItemString(self->dict, "drawSize", drawSize) != 0) - { - Py_DECREF(drawSize); - return (PythonReturnErrorObject (PyExc_RuntimeError, - "couldn't set Camera.drawSize attribute")); - } - - if (self->linked) - { - /* update the Blender Camera, too */ - self->camera->drawsize = value; - } + self->camera->drawsize = EXPP_ClampFloat (value, + EXPP_CAM_DRAWSIZE_MIN, EXPP_CAM_DRAWSIZE_MAX); Py_INCREF(Py_None); return Py_None; } /*****************************************************************************/ -/* Function: CameraCreatePyObject */ -/* Description: This function will create a new C_Camera. If the Camera */ -/* struct passed to it is not NULL, it'll use its attributes. */ -/*****************************************************************************/ -PyObject *CameraCreatePyObject (Camera *blenderCam) -{ - PyObject *name, *type, *mode; - PyObject *lens, *clipStart, *clipEnd, *drawSize; - PyObject *Types, *persp, *ortho; - PyObject *Modes, *showLimits, *showMist; - C_Camera *cam; - - printf ("In CameraCreatePyObject\n"); - - cam = (C_Camera *)PyObject_NEW(C_Camera, &Camera_Type); - - if (cam == NULL) - { - return NULL; - } - - cam->dict = PyDict_New(); - - if (cam->dict == NULL) - { - Py_DECREF((PyObject *)cam); - return NULL; - } - - if (blenderCam == NULL) - { - /* Not linked to a Camera Object yet */ - name = PyString_FromString("Data"); - type = PyInt_FromLong(EXPP_CAM_TYPE); - mode = PyInt_FromLong(EXPP_CAM_MODE); - lens = PyFloat_FromDouble(EXPP_CAM_LENS); - clipStart = PyFloat_FromDouble(EXPP_CAM_CLIPSTART); - clipEnd = PyFloat_FromDouble(EXPP_CAM_CLIPEND); - drawSize = PyFloat_FromDouble(EXPP_CAM_DRAWSIZE); - } - else - { - /* Camera Object available, get its attributes directly */ - name = PyString_FromString(blenderCam->id.name+2); - type = PyInt_FromLong(blenderCam->type); - mode = PyInt_FromLong(blenderCam->flag); - lens = PyFloat_FromDouble(blenderCam->lens); - clipStart = PyFloat_FromDouble(blenderCam->clipsta); - clipEnd = PyFloat_FromDouble(blenderCam->clipend); - drawSize = PyFloat_FromDouble(blenderCam->drawsize); - } - - Types = constant_New(); - persp = PyInt_FromLong(EXPP_CAM_TYPE_PERSP); - ortho = PyInt_FromLong(EXPP_CAM_TYPE_ORTHO); - - Modes = constant_New(); - showLimits = PyInt_FromLong(EXPP_CAM_MODE_SHOWLIMITS); - showMist = PyInt_FromLong(EXPP_CAM_MODE_SHOWMIST); - - if (name == NULL || type == NULL || mode == NULL|| lens == NULL || - clipStart == NULL || clipEnd == NULL || drawSize == NULL || - Types == NULL || persp == NULL || ortho == NULL || - Modes == NULL || showLimits == NULL || showMist == NULL) - { - /* Some object creation has gone wrong. Clean up. */ - goto fail; - } - - if ((PyDict_SetItemString(cam->dict, "name", name) != 0) || - (PyDict_SetItemString(cam->dict, "type", type) != 0) || - (PyDict_SetItemString(cam->dict, "mode", mode) != 0) || - (PyDict_SetItemString(cam->dict, "lens", lens) != 0) || - (PyDict_SetItemString(cam->dict, "clipStart", clipStart) != 0) || - (PyDict_SetItemString(cam->dict, "clipEnd", clipEnd) != 0) || - (PyDict_SetItemString(cam->dict, "drawSize", drawSize) != 0) || - (PyDict_SetItemString(cam->dict, "Types", Types) != 0) || - (PyDict_SetItemString(cam->dict, "Modes", Modes) != 0) || - (PyDict_SetItemString(cam->dict, "__members__", - PyDict_Keys(cam->dict)) != 0)) - { - /* One or more value setting actions has gone wwrong. Clean up. */ - goto fail; - } - - if ((PyDict_SetItemString(((C_constant *)Types)->dict, - "persp", persp) != 0) || - (PyDict_SetItemString(((C_constant *)Types)->dict, - "ortho", ortho) != 0) || - (PyDict_SetItemString(((C_constant *)Modes)->dict, - "showLimits", showLimits) != 0) || - (PyDict_SetItemString(((C_constant *)Modes)->dict, - "showMist", showMist) != 0)) - { - /* One or more value setting actions has gone wwrong. Clean up. */ - goto fail; - } - - cam->camera = blenderCam; /* it's NULL when creating only camera "data" */ - return ((PyObject*)cam); - -fail: - Py_XDECREF(name); - Py_XDECREF(type); - Py_XDECREF(mode); - Py_XDECREF(lens); - Py_XDECREF(clipStart); - Py_XDECREF(clipEnd); - Py_XDECREF(drawSize); - Py_XDECREF(Types); - Py_XDECREF(persp); - Py_XDECREF(ortho); - Py_XDECREF(Modes); - Py_XDECREF(showLimits); - Py_XDECREF(showMist); - Py_DECREF(cam->dict); - Py_DECREF((PyObject *)cam); - return NULL; -} - -/*****************************************************************************/ /* Function: CameraDeAlloc */ /* Description: This is a callback function for the C_Camera type. It is */ /* the destructor function. */ /*****************************************************************************/ static void CameraDeAlloc (C_Camera *self) { - Py_DECREF(self->dict); PyObject_DEL (self); } /*****************************************************************************/ /* Function: CameraGetAttr */ /* Description: This is a callback function for the C_Camera type. It is */ -/* the function that accesses C_Camera member variables and */ +/* the function that accesses C_Camera "member variables" and */ /* methods. */ /*****************************************************************************/ -static PyObject* CameraGetAttr (C_Camera *cam, char *name) +static PyObject *CameraGetAttr (C_Camera *self, char *name) { - /* first try the attributes dictionary */ - if (cam->dict) - { - PyObject *v = PyDict_GetItemString(cam->dict, name); - if (v) - { - Py_INCREF(v); /* was a borrowed ref */ - return v; - } + PyObject *attr = Py_None; + + if (strcmp(name, "name") == 0) + attr = PyString_FromString(self->camera->id.name+2); + else if (strcmp(name, "type") == 0) + attr = PyInt_FromLong(self->camera->type); + else if (strcmp(name, "mode") == 0) + attr = PyInt_FromLong(self->camera->flag); + else if (strcmp(name, "lens") == 0) + attr = PyFloat_FromDouble(self->camera->lens); + else if (strcmp(name, "clipStart") == 0) + attr = PyFloat_FromDouble(self->camera->clipsta); + else if (strcmp(name, "clipEnd") == 0) + attr = PyFloat_FromDouble(self->camera->clipend); + else if (strcmp(name, "drawSize") == 0) + attr = PyFloat_FromDouble(self->camera->drawsize); + + else if (strcmp(name, "Types") == 0) { + attr = Py_BuildValue("{s:h,s:h}", "persp", EXPP_CAM_TYPE_PERSP, + "ortho", EXPP_CAM_TYPE_ORTHO); + } + + else if (strcmp(name, "Modes") == 0) { + attr = Py_BuildValue("{s:h,s:h}", "showLimits", EXPP_CAM_MODE_SHOWLIMITS, + "showMist", EXPP_CAM_MODE_SHOWMIST); + } + + else if (strcmp(name, "__members__") == 0) { + attr = Py_BuildValue("[s,s,s,s,s,s,s,s,s]", + "name", "type", "mode", "lens", "clipStart", + "clipEnd", "drawSize", "Types", "Modes"); } + if (!attr) + return (EXPP_ReturnPyObjError (PyExc_MemoryError, + "couldn't create PyObject")); + + if (attr != Py_None) return attr; /* member attribute found, return it */ + /* not an attribute, search the methods table */ - return Py_FindMethod(C_Camera_methods, (PyObject *)cam, name); + return Py_FindMethod(C_Camera_methods, (PyObject *)self, name); } /*****************************************************************************/ /* Function: CameraSetAttr */ /* Description: This is a callback function for the C_Camera type. It is the */ -/* function that changes Camera Data members values. If this */ -/* data is linked to a Blender Camera, it also gets updated. */ +/* function that sets Camera Data attributes (member variables).*/ /*****************************************************************************/ static int CameraSetAttr (C_Camera *self, char *name, PyObject *value) { PyObject *valtuple; PyObject *error = NULL; - if (self->dict == NULL) - { - return -1; - } - /* We're playing a trick on the Python API users here. Even if they use - * Camera.member = val instead of Camera.setMember(value), we end up using the + * Camera.member = val instead of Camera.setMember(val), we end up using the * function anyway, since it already has error checking, clamps to the right * interval and updates the Blender Camera structure when necessary. */ - valtuple = PyTuple_New(1); /* the set* functions expect a tuple */ +/* First we put "value" in a tuple, because we want to pass it to functions + * that only accept PyTuples. Using "N" doesn't increment value's ref count */ + valtuple = Py_BuildValue("(N)", value); - if (!valtuple) - { - return EXPP_intError(PyExc_MemoryError, + if (!valtuple) /* everything OK with our PyObject? */ + return EXPP_ReturnIntError(PyExc_MemoryError, "CameraSetAttr: couldn't create PyTuple"); - } - - if (PyTuple_SetItem(valtuple, 0, value) != 0) - { - Py_DECREF(value); /* PyTuple_SetItem incref's value even when it fails */ - Py_DECREF(valtuple); - return EXPP_intError(PyExc_RuntimeError, - "CameraSetAttr: couldn't fill tuple"); - } +/* Now we just compare "name" with all possible C_Camera member variables */ if (strcmp (name, "name") == 0) error = Camera_rename (self, valtuple); else if (strcmp (name, "type") == 0) @@ -865,24 +484,30 @@ static int CameraSetAttr (C_Camera *self, char *name, PyObject *value) error = Camera_setClipEnd (self, valtuple); else if (strcmp (name, "drawSize") == 0) error = Camera_setDrawSize (self, valtuple); - else - { - /* Error: no such member in the Camera Data structure */ - Py_DECREF(value); + + else { /* Error */ Py_DECREF(valtuple); - return (EXPP_intError (PyExc_KeyError, - "attribute not found")); - } - if (error == Py_None) - { - return 0; /* normal exit */ + if ((strcmp (name, "Types") == 0) || /* user tried to change a */ + (strcmp (name, "Modes") == 0)) /* constant dict type ... */ + return (EXPP_ReturnIntError (PyExc_AttributeError, + "constant dictionary -- cannot be changed")); + + else /* ... or no member with the given name was found */ + return (EXPP_ReturnIntError (PyExc_KeyError, + "attribute not found")); } - Py_DECREF(value); +/* valtuple won't be returned to the caller, so we need to DECREF it */ Py_DECREF(valtuple); - return -1; + if (error != Py_None) return -1; + +/* Py_None was incref'ed by the called Camera_set* function. We probably + * don't need to decref Py_None (!), but since Python/C API manual tells us + * to treat it like any other PyObject regarding ref counting ... */ + Py_DECREF(Py_None); + return 0; /* normal exit */ } /*****************************************************************************/ @@ -892,18 +517,7 @@ static int CameraSetAttr (C_Camera *self, char *name, PyObject *value) /*****************************************************************************/ static int CameraPrint(C_Camera *self, FILE *fp, int flags) { - char *lstate = "unlinked"; - char *name; - - if (self->linked) - { - lstate = "linked"; - } - - name = PyString_AsString(Camera_getName(self)); - - fprintf(fp, "[Camera \"%s\" (%s)]", name, lstate); - + fprintf(fp, "[Camera \"%s\"]", self->camera->id.name+2); return 0; } @@ -914,18 +528,5 @@ static int CameraPrint(C_Camera *self, FILE *fp, int flags) /*****************************************************************************/ static PyObject *CameraRepr (C_Camera *self) { - char buf[64]; - char *lstate = "unlinked"; - char *name; - - if (self->linked) - { - lstate = "linked"; - } - - name = PyString_AsString(Camera_getName(self)); - - PyOS_snprintf(buf, sizeof(buf), "[Camera \"%s\" (%s)]", name, lstate); - - return PyString_FromString(buf); + return PyString_FromString(self->camera->id.name+2); } diff --git a/source/blender/python/api2_2x/Camera.h b/source/blender/python/api2_2x/Camera.h index 4f8d1a304b3..dd5b087924a 100644 --- a/source/blender/python/api2_2x/Camera.h +++ b/source/blender/python/api2_2x/Camera.h @@ -126,9 +126,7 @@ struct PyMethodDef M_Camera_methods[] = { /*****************************************************************************/ typedef struct { PyObject_HEAD - PyObject *dict; Camera *camera; - int linked; } C_Camera; /*****************************************************************************/ diff --git a/source/blender/python/api2_2x/Draw.c b/source/blender/python/api2_2x/Draw.c new file mode 100644 index 00000000000..04b26bf20be --- /dev/null +++ b/source/blender/python/api2_2x/Draw.c @@ -0,0 +1,741 @@ +/* + * + * ***** BEGIN GPL/BL DUAL 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. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * 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. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * This is a new part of Blender. + * + * Contributor(s): Willian P. Germano + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** +*/ + +/* This file is the Blender.Draw part of opy_draw.c, from the old + * bpython/intern dir, with minor changes to adapt it to the new Python + * implementation. Non-trivial original comments are marked with an + * @ symbol at their beginning. */ + +#include "Draw.h" + +static void Button_dealloc(PyObject *self) +{ + Button *but= (Button*) self; + + if(but->type==3) MEM_freeN(but->val.asstr); + + PyMem_DEL(self); +} + +static PyObject *Button_getattr(PyObject *self, char *name) +{ + Button *but= (Button*) self; + + if(strcmp(name, "val") == 0) { + if (but->type==1) + return Py_BuildValue("i", but->val.asint); + else if (but->type==2) + return Py_BuildValue("f", but->val.asfloat); + else if (but->type==3) + return Py_BuildValue("s", but->val.asstr); + } + + PyErr_SetString(PyExc_AttributeError, name); + return NULL; +} + +static int Button_setattr(PyObject *self, char *name, PyObject *v) +{ + Button *but= (Button*) self; + + if(strcmp(name, "val") == 0) { + if (but->type==1) + PyArg_Parse(v, "i", &but->val.asint); + else if (but->type==2) + PyArg_Parse(v, "f", &but->val.asfloat); + else if (but->type==3) { + char *newstr; + + PyArg_Parse(v, "s", &newstr); + strncpy(but->val.asstr, newstr, but->slen); + } + } else { + PyErr_SetString(PyExc_AttributeError, name); + return -1; + } + + return 0; +} + +static PyObject *Button_repr(PyObject *self) +{ + return PyObject_Repr(Button_getattr(self, "val")); +} + +static Button *newbutton (void) +{ + Button *but= (Button *) PyObject_NEW(Button, &Button_Type); + + return but; +} + +/* GUI interface routines */ + +static void exit_pydraw(SpaceText *st) +{ + scrarea_queue_redraw(st->area); + + if (st) { + Py_XDECREF((PyObject *) st->py_draw); + Py_XDECREF((PyObject *) st->py_event); + Py_XDECREF((PyObject *) st->py_button); + + st->py_draw= st->py_event= st->py_button= NULL; + } +} + +static void exec_callback(SpaceText *st, PyObject *callback, PyObject *args) +{ + PyObject *result= PyEval_CallObject(callback, args); + + if (result==NULL) { + st->text->compiled= NULL; + PyErr_Print(); + exit_pydraw(st); + } + Py_XDECREF(result); + Py_DECREF(args); +} + +/*@ the handler for drawing routines (see Register method) */ + +void EXPP_spacetext_do_pywin_draw(SpaceText *st) +{ + uiBlock *block; + char butblock[20]; + + sprintf(butblock, "win %d", curarea->win); + block= uiNewBlock(&curarea->uiblocks, butblock, UI_EMBOSSX, + UI_HELV, curarea->win); + + if (st->py_draw) { + glPushAttrib(GL_ALL_ATTRIB_BITS); + exec_callback(st, st->py_draw, Py_BuildValue("()")); + glPopAttrib(); + } else { + glClearColor(0.4375, 0.4375, 0.4375, 0.0); + glClear(GL_COLOR_BUFFER_BIT); + } + + uiDrawBlock(block); + + curarea->win_swap= WIN_BACK_OK; +} + +/*@ the handler for button event routines (see Register method) */ + +static void spacetext_do_pywin_buttons(SpaceText *st, unsigned short event) +{ + if (st->py_button) { + exec_callback(st, st->py_button, Py_BuildValue("(i)", event)); + } +} + +/*@ calls the generic event handling methods registered with Register */ + +void EXPP_spacetext_do_pywin_event(SpaceText *st, unsigned short event, short val) +{ + if (event==QKEY && G.qual & (LR_ALTKEY|LR_CTRLKEY|LR_SHIFTKEY)) { + exit_pydraw(st); + return; + } + + if (val) { + if (uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0; + + if (event==UI_BUT_EVENT) { + spacetext_do_pywin_buttons(st, val); + } + } + + if (st->py_event) { + exec_callback(st, st->py_event, Py_BuildValue("(ii)", event, val)); + } +} + +int EXPP_spacetext_is_pywin(SpaceText *st) +{ + return (st->py_draw || st->py_event || st->py_button); +} + +#define EXPP_TRY(x) if((!(x))) \ + return EXPP_ReturnPyObjError(PyExc_AttributeError, "in module Blender.Draw") + +static PyObject *Method_Exit (PyObject *self, PyObject *args) +{ + SpaceText *st= curarea->spacedata.first; +#ifdef CLEAR_NAMESPACE + PyObject *d; +#endif + EXPP_TRY(PyArg_ParseTuple(args, "")); + + exit_pydraw(st); +#ifdef CLEAR_NAMESPACE + d = st->py_globaldict; /* The current window's global namespace dictionary */ + if (d) { + PyDict_Clear(d); + Py_DECREF(d); /* release dictionary */ + } +#endif + + return EXPP_incr_ret(Py_None); +} + +static PyObject *Method_Register (PyObject *self, PyObject *args) +{ + PyObject *newdrawc= NULL, *neweventc= NULL, *newbuttonc= NULL; + SpaceText *st= curarea->spacedata.first; + + EXPP_TRY(PyArg_ParseTuple(args, "O|OO", &newdrawc, + &neweventc, &newbuttonc)); + + /*@This is a hack again: + * Every python script should actually do a global variable cleanup at + * the end of execution. + * For scripts registering GUI callbacks, this does not work, because + * the global namespace of the interpreter still needs to be accessed + * from the callback. + * Workaround: a text object has a flag which allows the global name + * space to be cleared at the end of the script. This flag should be + * normally set when executed with Alt-P. For a script registering with + * the GUI though, clear the flag and set it when the GUI mode is left + * (Method_Exit). + */ + +/* EXPP_debug(("--- disable clear namespace")); */ + + st->flags &= ~ST_CLEAR_NAMESPACE; + + + if (!PyCallable_Check(newdrawc)) newdrawc= NULL; + if (!PyCallable_Check(neweventc)) neweventc= NULL; + if (!PyCallable_Check(newbuttonc)) newbuttonc= NULL; + + if (!(newdrawc || neweventc || newbuttonc)) + return EXPP_incr_ret(Py_None); + + exit_pydraw(st); + + Py_XINCREF(newdrawc); + Py_XINCREF(neweventc); + Py_XINCREF(newbuttonc); + + st->py_draw= newdrawc; + st->py_event= neweventc; + st->py_button= newbuttonc; + + scrarea_queue_redraw(st->area); + + return EXPP_incr_ret(Py_None); +} + +static PyObject *Method_Redraw (PyObject *self, PyObject *args) +{ + int after= 0; + + EXPP_TRY(PyArg_ParseTuple(args, "|i", &after)); + + if (after) addafterqueue(curarea->win, REDRAW, 1); + else scrarea_queue_winredraw(curarea); + + return EXPP_incr_ret(Py_None); +} + +static PyObject *Method_Draw (PyObject *self, PyObject *args) +{ + /*@ If forced drawing is disable queue a redraw event instead */ + if (EXPP_disable_force_draw) { + scrarea_queue_winredraw(curarea); + return EXPP_incr_ret(Py_None); + } + + EXPP_TRY(PyArg_ParseTuple(args, "")); + + scrarea_do_windraw(curarea); + + screen_swapbuffers(); + + return EXPP_incr_ret(Py_None); +} + +static PyObject *Method_Create (PyObject *self, PyObject *args) +{ + Button *but; + PyObject *in; + + EXPP_TRY(PyArg_ParseTuple(args, "O", &in)); + + but= newbutton(); + if(PyFloat_Check(in)) { + but->type= 2; + but->val.asfloat= PyFloat_AsDouble(in); + } else if (PyInt_Check(in)) { + but->type= 1; + but->val.asint= PyInt_AsLong(in); + } else if (PyString_Check(in)) { + char *newstr= PyString_AsString(in); + + but->type= 3; + but->slen= strlen(newstr); + but->val.asstr= MEM_mallocN(but->slen+1, "button string"); + + strcpy(but->val.asstr, newstr); + } + + return (PyObject *) but; +} + +static uiBlock *Get_uiBlock(void) +{ + char butblock[32]; + + sprintf(butblock, "win %d", curarea->win); + + return uiGetBlock(butblock, curarea); +} + +static PyObject *Method_Button (PyObject *self, PyObject *args) +{ + uiBlock *block; + char *name, *tip= NULL; + int event; + int x, y, w, h; + + EXPP_TRY(PyArg_ParseTuple(args, "siiiii|s", &name, &event, + &x, &y, &w, &h, &tip)); + + block= Get_uiBlock(); + + if(block) uiDefBut(block, BUT, event, name, x, y, w, h, + 0, 0, 0, 0, 0, tip); + + return EXPP_incr_ret(Py_None); +} + +static PyObject *Method_Menu (PyObject *self, PyObject *args) +{ + uiBlock *block; + char *name, *tip= NULL; + int event, def; + int x, y, w, h; + Button *but; + + EXPP_TRY(PyArg_ParseTuple(args, "siiiiii|s", &name, &event, + &x, &y, &w, &h, &def, &tip)); + + but= newbutton(); + but->type= 1; + but->val.asint= def; + + block= Get_uiBlock(); + if(block) uiDefButI(block, MENU, event, name, x, y, w, h, + &but->val.asint, 0, 0, 0, 0, tip); + + return (PyObject *) but; +} + +static PyObject *Method_Toggle (PyObject *self, PyObject *args) +{ + uiBlock *block; + char *name, *tip= NULL; + int event; + int x, y, w, h, def; + Button *but; + + EXPP_TRY(PyArg_ParseTuple(args, "siiiiii|s", &name, &event, + &x, &y, &w, &h, &def, &tip)); + + but= newbutton(); + but->type= 1; + but->val.asint= def; + + block= Get_uiBlock(); + if(block) uiDefButI(block, TOG, event, name, x, y, w, h, + &but->val.asint, 0, 0, 0, 0, tip); + + return (PyObject *) but; +} + +/*@DO NOT TOUCH THIS FUNCTION ! + Redrawing a slider inside its own callback routine is actually forbidden + with the current toolkit architecture (button routines are not reentrant). + But it works anyway. + XXX This is condemned to be dinosource in future - it's a hack. + */ + +static void py_slider_update(void *butv, void *data2_unused) +{ + uiBut *but= butv; + + EXPP_disable_force_draw= 1; + /*@ + Disable forced drawing, otherwise the button object which + is still being used might be deleted + */ + +/*@ UIfrontbuf = 0; + spacetext_do_pywin_buttons(curarea->spacedata.first, but->retval); */ + + g_window_redrawn = 0; + curarea->win_swap= WIN_BACK_OK; + UIfrontbuf = 1; + spacetext_do_pywin_buttons(curarea->spacedata.first, uiButGetRetVal(but)); + UIfrontbuf = 0; + + if (!g_window_redrawn) /*@ if Redraw already called */ + M_Window_Redraw(0, Py_BuildValue("(i)", SPACE_VIEW3D)); + + EXPP_disable_force_draw= 0; +} + +static PyObject *Method_Slider (PyObject *self, PyObject *args) +{ + uiBlock *block; + char *name, *tip= NULL; + int event; + int x, y, w, h, realtime=1; + Button *but; + PyObject *mino, *maxo, *inio; + + EXPP_TRY(PyArg_ParseTuple(args, "siiiiiOOO|is", &name, &event, + &x, &y, &w, &h, &inio, &mino, &maxo, &realtime, &tip)); + + + but= newbutton(); + if (PyFloat_Check(inio)) { + float ini, min, max; + + ini= PyFloat_AsDouble(inio); + min= PyFloat_AsDouble(mino); + max= PyFloat_AsDouble(maxo); + + but->type= 2; + but->val.asfloat= ini; + + block= Get_uiBlock(); + if(block) { + uiBut *ubut; + ubut= uiDefButF(block, NUMSLI, event, name, x, y, w, h, + &but->val.asfloat, min, max, 0, 0, tip); + if (realtime) uiButSetFunc(ubut, py_slider_update, ubut, NULL); + } + } + else { + int ini, min, max; + + ini= PyInt_AsLong(inio); + min= PyInt_AsLong(mino); + max= PyInt_AsLong(maxo); + + but->type= 1; + but->val.asint= ini; + + block= Get_uiBlock(); + if(block) { + uiBut *ubut; + ubut= uiDefButI(block, NUMSLI, event, name, x, y, w, h, + &but->val.asint, min, max, 0, 0, tip); + if (realtime) uiButSetFunc(ubut, py_slider_update, ubut, NULL); + } + } + return (PyObject *) but; +} + +static PyObject *Method_Scrollbar (PyObject *self, PyObject *args) +{ + char *tip= NULL; + uiBlock *block; + int event; + int x, y, w, h, realtime=1; + Button *but; + PyObject *mino, *maxo, *inio; + float ini, min, max; + + EXPP_TRY(PyArg_ParseTuple(args, "iiiiiOOO|is", &event, &x, &y, &w, &h, &inio, &mino, &maxo, &realtime, &tip)); + + if (!PyNumber_Check(inio) || !PyNumber_Check(inio) || !PyNumber_Check(inio)) + return EXPP_ReturnPyObjError (PyExc_AttributeError, + "expected numbers for initial, min, and max"); + + but= newbutton(); + + if (PyFloat_Check(inio)) but->type= 2; + else but->type= 1; + + ini= PyFloat_AsDouble(inio); + min= PyFloat_AsDouble(mino); + max= PyFloat_AsDouble(maxo); + + if (but->type==2) { + but->val.asfloat= ini; + block= Get_uiBlock(); + if(block) { + uiBut *ubut; + ubut= uiDefButF(block, SCROLL, event, "", x, y, w, h, + &but->val.asfloat, min, max, 0, 0, tip); + if (realtime) uiButSetFunc(ubut, py_slider_update, ubut, NULL); + } + } else { + but->val.asint= ini; + block= Get_uiBlock(); + if(block) { + uiBut *ubut; + ubut= uiDefButI(block, SCROLL, event, "", x, y, w, h, + &but->val.asint, min, max, 0, 0, tip); + if (realtime) uiButSetFunc(ubut, py_slider_update, ubut, NULL); + } + } + + return (PyObject *) but; +} + +static PyObject *Method_Number (PyObject *self, PyObject *args) +{ + uiBlock *block; + char *name, *tip= NULL; + int event; + int x, y, w, h; + Button *but; + PyObject *mino, *maxo, *inio; + + EXPP_TRY(PyArg_ParseTuple(args, "siiiiiOOO|s", &name, &event, + &x, &y, &w, &h, &inio, &mino, &maxo, &tip)); + + but= newbutton(); + + if (PyFloat_Check(inio)) { + float ini, min, max; + + ini= PyFloat_AsDouble(inio); + min= PyFloat_AsDouble(mino); + max= PyFloat_AsDouble(maxo); + + but->type= 2; + but->val.asfloat= ini; + + block= Get_uiBlock(); + if(block) uiDefButF(block, NUM, event, name, x, y, w, h, + &but->val.asfloat, min, max, 0, 0, tip); + } else { + int ini, min, max; + + ini= PyInt_AsLong(inio); + min= PyInt_AsLong(mino); + max= PyInt_AsLong(maxo); + + but->type= 1; + but->val.asint= ini; + + block= Get_uiBlock(); + if(block) uiDefButI(block, NUM, event, name, x, y, w, h, + &but->val.asint, min, max, 0, 0, tip); + } + + return (PyObject *) but; +} + +static PyObject *Method_String (PyObject *self, PyObject *args) +{ + uiBlock *block; + char *name, *tip= NULL, *newstr; + int event; + int x, y, w, h, len; + Button *but; + + EXPP_TRY(PyArg_ParseTuple(args, "siiiiisi|s", &name, &event, + &x, &y, &w, &h, &newstr, &len, &tip)); + + but= newbutton(); + but->type= 3; + but->slen= len; + but->val.asstr= MEM_mallocN(len+1, "button string"); + + strncpy(but->val.asstr, newstr, len); + but->val.asstr[len]= 0; + + block= Get_uiBlock(); + if(block) uiDefBut(block, TEX, event, name, x, y, w, h, + but->val.asstr, 0, len, 0, 0, tip); + + return (PyObject *) but; +} + +static PyObject *Method_Text (PyObject *self, PyObject *args) +{ + char *text; + + EXPP_TRY(PyArg_ParseTuple(args, "s", &text)); + + BMF_DrawString(G.font, text); + + return EXPP_incr_ret(Py_None); +} + +PyObject *M_Draw_Init (void) +{ + PyObject *submodule, *dict; + + printf("In M_Draw_Init()\n"); + + submodule = Py_InitModule3("Blender.Draw", Draw_methods, Draw_doc); + + dict= PyModule_GetDict(submodule); + +#define EXPP_ADDCONST(x) \ + PyDict_SetItemString(dict, #x, PyInt_FromLong(x)) + +/* So, for example: + * EXPP_ADDCONST(LEFTMOUSE) becomes + * PyDict_SetItemString(dict, "LEFTMOUSE", PyInt_FromLong(LEFTMOUSE)) */ + + EXPP_ADDCONST(LEFTMOUSE); + EXPP_ADDCONST(MIDDLEMOUSE); + EXPP_ADDCONST(RIGHTMOUSE); + EXPP_ADDCONST(MOUSEX); + EXPP_ADDCONST(MOUSEY); + EXPP_ADDCONST(TIMER0); + EXPP_ADDCONST(TIMER1); + EXPP_ADDCONST(TIMER2); + EXPP_ADDCONST(TIMER3); + EXPP_ADDCONST(KEYBD); + EXPP_ADDCONST(RAWKEYBD); + EXPP_ADDCONST(REDRAW); + EXPP_ADDCONST(INPUTCHANGE); + EXPP_ADDCONST(QFULL); + EXPP_ADDCONST(WINFREEZE); + EXPP_ADDCONST(WINTHAW); + EXPP_ADDCONST(WINCLOSE); + EXPP_ADDCONST(WINQUIT); +#ifndef IRISGL + EXPP_ADDCONST(Q_FIRSTTIME); +#endif + EXPP_ADDCONST(AKEY); + EXPP_ADDCONST(BKEY); + EXPP_ADDCONST(CKEY); + EXPP_ADDCONST(DKEY); + EXPP_ADDCONST(EKEY); + EXPP_ADDCONST(FKEY); + EXPP_ADDCONST(GKEY); + EXPP_ADDCONST(HKEY); + EXPP_ADDCONST(IKEY); + EXPP_ADDCONST(JKEY); + EXPP_ADDCONST(KKEY); + EXPP_ADDCONST(LKEY); + EXPP_ADDCONST(MKEY); + EXPP_ADDCONST(NKEY); + EXPP_ADDCONST(OKEY); + EXPP_ADDCONST(PKEY); + EXPP_ADDCONST(QKEY); + EXPP_ADDCONST(RKEY); + EXPP_ADDCONST(SKEY); + EXPP_ADDCONST(TKEY); + EXPP_ADDCONST(UKEY); + EXPP_ADDCONST(VKEY); + EXPP_ADDCONST(WKEY); + EXPP_ADDCONST(XKEY); + EXPP_ADDCONST(YKEY); + EXPP_ADDCONST(ZKEY); + EXPP_ADDCONST(ZEROKEY); + EXPP_ADDCONST(ONEKEY); + EXPP_ADDCONST(TWOKEY); + EXPP_ADDCONST(THREEKEY); + EXPP_ADDCONST(FOURKEY); + EXPP_ADDCONST(FIVEKEY); + EXPP_ADDCONST(SIXKEY); + EXPP_ADDCONST(SEVENKEY); + EXPP_ADDCONST(EIGHTKEY); + EXPP_ADDCONST(NINEKEY); + EXPP_ADDCONST(CAPSLOCKKEY); + EXPP_ADDCONST(LEFTCTRLKEY); + EXPP_ADDCONST(LEFTALTKEY); + EXPP_ADDCONST(RIGHTALTKEY); + EXPP_ADDCONST(RIGHTCTRLKEY); + EXPP_ADDCONST(RIGHTSHIFTKEY); + EXPP_ADDCONST(LEFTSHIFTKEY); + EXPP_ADDCONST(ESCKEY); + EXPP_ADDCONST(TABKEY); + EXPP_ADDCONST(RETKEY); + EXPP_ADDCONST(SPACEKEY); + EXPP_ADDCONST(LINEFEEDKEY); + EXPP_ADDCONST(BACKSPACEKEY); + EXPP_ADDCONST(DELKEY); + EXPP_ADDCONST(SEMICOLONKEY); + EXPP_ADDCONST(PERIODKEY); + EXPP_ADDCONST(COMMAKEY); + EXPP_ADDCONST(QUOTEKEY); + EXPP_ADDCONST(ACCENTGRAVEKEY); + EXPP_ADDCONST(MINUSKEY); + EXPP_ADDCONST(SLASHKEY); + EXPP_ADDCONST(BACKSLASHKEY); + EXPP_ADDCONST(EQUALKEY); + EXPP_ADDCONST(LEFTBRACKETKEY); + EXPP_ADDCONST(RIGHTBRACKETKEY); + EXPP_ADDCONST(LEFTARROWKEY); + EXPP_ADDCONST(DOWNARROWKEY); + EXPP_ADDCONST(RIGHTARROWKEY); + EXPP_ADDCONST(UPARROWKEY); + EXPP_ADDCONST(PAD2); + EXPP_ADDCONST(PAD4); + EXPP_ADDCONST(PAD6); + EXPP_ADDCONST(PAD8); + EXPP_ADDCONST(PAD1); + EXPP_ADDCONST(PAD3); + EXPP_ADDCONST(PAD5); + EXPP_ADDCONST(PAD7); + EXPP_ADDCONST(PAD9); + EXPP_ADDCONST(PADPERIOD); + EXPP_ADDCONST(PADSLASHKEY); + EXPP_ADDCONST(PADASTERKEY); + EXPP_ADDCONST(PAD0); + EXPP_ADDCONST(PADMINUS); + EXPP_ADDCONST(PADENTER); + EXPP_ADDCONST(PADPLUSKEY); + EXPP_ADDCONST(F1KEY); + EXPP_ADDCONST(F2KEY); + EXPP_ADDCONST(F3KEY); + EXPP_ADDCONST(F4KEY); + EXPP_ADDCONST(F5KEY); + EXPP_ADDCONST(F6KEY); + EXPP_ADDCONST(F7KEY); + EXPP_ADDCONST(F8KEY); + EXPP_ADDCONST(F9KEY); + EXPP_ADDCONST(F10KEY); + EXPP_ADDCONST(F11KEY); + EXPP_ADDCONST(F12KEY); + EXPP_ADDCONST(PAUSEKEY); + EXPP_ADDCONST(INSERTKEY); + EXPP_ADDCONST(HOMEKEY); + EXPP_ADDCONST(PAGEUPKEY); + EXPP_ADDCONST(PAGEDOWNKEY); + EXPP_ADDCONST(ENDKEY); + + return submodule; +} diff --git a/source/blender/python/api2_2x/Draw.h b/source/blender/python/api2_2x/Draw.h new file mode 100644 index 00000000000..2220a48c4c4 --- /dev/null +++ b/source/blender/python/api2_2x/Draw.h @@ -0,0 +1,306 @@ +/* + * + * ***** BEGIN GPL/BL DUAL 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. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * 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. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * This is a new part of Blender. + * + * Contributor(s): Willian P. Germano + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** +*/ + +/* The code in Draw.[ch] and BGL.[ch] comes from opy_draw.c in the old + * bpython/intern dir, with minor modifications to suit the current + * implementation. Important original comments are marked with an @ symbol. */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#ifdef WIN32 +#include "BLI_winstuff.h" +#endif + +#include "MEM_guardedalloc.h" + +#include "BMF_Api.h" + +#include "DNA_screen_types.h" +#include "DNA_space_types.h" +#include "DNA_text_types.h" + +#include "BKE_global.h" + +#include "BIF_gl.h" +#include "BIF_screen.h" +#include "BIF_space.h" +#include "BIF_interface.h" +#include "BIF_mywindow.h" + +#include "interface.h" +#include "mydevice.h" /*@ for all the event constants */ + +#include "Python.h" + +#include "gen_utils.h" +#include "modules.h" + +/*@ hack to flag that window redraw has happened inside slider callback: */ +int EXPP_disable_force_draw; + +/* From Window.h, used here by py_slider_update() */ +PyObject *M_Window_Redraw(PyObject *self, PyObject *args); + +/* This one was an extern in BPY_main.h, but only opy_draw.c was using it */ +int g_window_redrawn; + +static char Draw_doc[] = +"Module Blender.Draw ... XXX improve this"; + +static void exit_pydraw (SpaceText *st); +static uiBlock *Get_uiBlock (void); +void initDraw (void); + +/* Button Object */ + +typedef struct _Button { + PyObject_VAR_HEAD + + int type; /*@ 1 == int, 2 == float, 3 == string */ + int slen; /*@ length of string (if type == 3) */ + union { + int asint; + float asfloat; + char *asstr; + } val; +} Button; + +static void Button_dealloc(PyObject *self); +static PyObject *Button_getattr(PyObject *self, char *name); +static int Button_setattr(PyObject *self, char *name, PyObject *v); +static PyObject *Button_repr(PyObject *self); + +PyTypeObject Button_Type = +{ + PyObject_HEAD_INIT(&PyType_Type) + 0, /*ob_size*/ + "Button", /*tp_name*/ + sizeof(Button), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + (destructor) Button_dealloc, /*tp_dealloc*/ + (printfunc) 0, /*tp_print*/ + (getattrfunc) Button_getattr, /*tp_getattr*/ + (setattrfunc) Button_setattr, /*tp_setattr*/ + (cmpfunc) 0, /*tp_cmp*/ + (reprfunc) Button_repr, /*tp_repr*/ +}; + +static Button *newbutton (void); + +/* GUI interface routines */ + +static void exit_pydraw(SpaceText *st); +static void exec_callback(SpaceText *st, PyObject *callback, PyObject *args); +void EXPP_spacetext_do_pywin_draw(SpaceText *st); +static void spacetext_do_pywin_buttons(SpaceText *st, unsigned short event); +void EXPP_spacetext_do_pywin_event(SpaceText *st, unsigned short event, short val); +int EXPP_spacetext_is_pywin(SpaceText *st); + +static char Method_Exit_doc[] = +"() - Exit the windowing interface"; + +static PyObject *Method_Exit (PyObject *self, PyObject *args); + +static char Method_Register_doc[] = +"(draw, event, button) - Register callbacks for windowing\n\n\ +(draw) A function to draw the screen, taking no arguments\n\ +(event) A function to handle events, taking 2 arguments (evt, val)\n\ + (evt) The event number\n\ + (val) The value modifier (for key and mouse press/release)\n\ +(button) A function to handle button events, taking 1 argument (evt)\n\ + (evt) The button number\n\n\ +A None object can be passed if a callback is unused."; + +static PyObject *Method_Register (PyObject *self, PyObject *args); + +static char Method_Redraw_doc[] = +"([after]) - Queue a redraw event\n\n\ +[after=0] Determines whether the redraw is processed before\n\ +or after other input events.\n\n\ +Redraw events are buffered so that regardless of how many events\n\ +are queued the window only receives one redraw event."; + +static PyObject *Method_Redraw (PyObject *self, PyObject *args); + +static char Method_Draw_doc[] = +"() - Force an immediate redraw\n\n\ +Forced redraws are not buffered, in other words the window is redrawn\n\ +exactly once for everytime this function is called."; + +static PyObject *Method_Draw (PyObject *self, PyObject *args); + +static char Method_Create_doc[] = +"(value) - Create a default Button object\n\ +\n\ +(value) - The value to store in the button\n\ +\n\ +Valid values are ints, floats, and strings"; + +static PyObject *Method_Create (PyObject *self, PyObject *args); + +static uiBlock *Get_uiBlock(void); + +static char Method_Button_doc[] = +"(name, event, x, y, width, height, [tooltip]) - Create a new Button \ +(push) button\n\n\ +(name) A string to display on the button\n\ +(event) The event number to pass to the button event function when activated\n\ +(x, y) The lower left coordinate of the button\n\ +(width, height) The button width and height\n\ +[tooltip=""] The button's tooltip"; + +static PyObject *Method_Button (PyObject *self, PyObject *args); + +static char Method_Menu_doc[] = +"(name, event, x, y, width, height, default, [tooltip]) - Create a new Menu \ +button\n\n\ +(name) A string to display on the button\n\ +(event) The event number to pass to the button event function when activated\n\ +(x, y) The lower left coordinate of the button\n\ +(width, height) The button width and height\n\ +(default) The number of the option to be selected by default\n\ +[tooltip=""] The button's tooltip\n\n\ +The menu options are specified through the name of the\n\ +button. Options are followed by a format code and seperated\n\ +by the '|' (pipe) character.\n\ +Valid format codes are\n\ + %t - The option should be used as the title\n\ + %xN - The option should set the integer N in the button value."; + +static PyObject *Method_Menu (PyObject *self, PyObject *args); + +static char Method_Toggle_doc[] = +"(name, event, x, y, width, height, default, [tooltip]) - Create a new Toggle \ +button\n\n\ +(name) A string to display on the button\n\ +(event) The event number to pass to the button event function when activated\n\ +(x, y) The lower left coordinate of the button\n\ +(width, height) The button width and height\n\ +(default) An integer (0 or 1) specifying the default state\n\ +[tooltip=""] The button's tooltip"; + +static PyObject *Method_Toggle (PyObject *self, PyObject *args); +static void py_slider_update(void *butv, void *data2_unused); + +static char Method_Slider_doc[] = +"(name, event, x, y, width, height, initial, min, max, [update, tooltip]) - \ +Create a new Slider button\n\n\ +(name) A string to display on the button\n\ +(event) The event number to pass to the button event function when activated\n\ +(x, y) The lower left coordinate of the button\n\ +(width, height) The button width and height\n\ +(initial, min, max) Three values (int or float) specifying the initial \ + and limit values.\n\ +[update=1] A value controlling whether the slider will emit events as it \ +is edited.\n\ + A non-zero value (default) enables the events. A zero value supresses them.\n\ +[tooltip=""] The button's tooltip"; + +static PyObject *Method_Slider (PyObject *self, PyObject *args); + +static char Method_Scrollbar_doc[] = +"(event, x, y, width, height, initial, min, max, [update, tooltip]) - Create a \ +new Scrollbar\n\n\ +(event) The event number to pass to the button event function when activated\n\ +(x, y) The lower left coordinate of the button\n\ +(width, height) The button width and height\n\ +(initial, min, max) Three values (int or float) specifying the initial and limit values.\n\ +[update=1] A value controlling whether the slider will emit events as it is edited.\n\ + A non-zero value (default) enables the events. A zero value supresses them.\n\ +[tooltip=""] The button's tooltip"; + +static PyObject *Method_Scrollbar (PyObject *self, PyObject *args); + +static char Method_Number_doc[] = +"(name, event, x, y, width, height, initial, min, max, [tooltip]) - Create a \ +new Number button\n\n\ +(name) A string to display on the button\n\ +(event) The event number to pass to the button event function when activated\n\ +(x, y) The lower left coordinate of the button\n\ +(width, height) The button width and height\n\ +(initial, min, max) Three values (int or float) specifying the initial and \ +limit values.\n\ +[tooltip=""] The button's tooltip"; + +static PyObject *Method_Number (PyObject *self, PyObject *args); + +static char Method_String_doc[] = +"(name, event, x, y, width, height, initial, length, [tooltip]) - Create a \ +new String button\n\n\ +(name) A string to display on the button\n\ +(event) The event number to pass to the button event function when activated\n\ +(x, y) The lower left coordinate of the button\n\ +(width, height) The button width and height\n\ +(initial) The string to display initially\n\ +(length) The maximum input length\n\ +[tooltip=""] The button's tooltip"; + +static PyObject *Method_String (PyObject *self, PyObject *args); + +static char Method_Text_doc[] = +"(text) - Draw text onscreen\n\n\ +(text) The text to draw\n"; + +static PyObject *Method_Text (PyObject *self, PyObject *args); + +#define _MethodDef(func, prefix) \ + {#func, prefix##_##func, METH_VARARGS, prefix##_##func##_doc} + +/* So that _MethodDef(delete, Scene) expands to: + * {"delete", Scene_delete, METH_VARARGS, Scene_delete_doc} */ + +#undef MethodDef +#define MethodDef(func) _MethodDef(func, Method) + +static struct PyMethodDef Draw_methods[] = { + MethodDef(Create), + MethodDef(Button), + MethodDef(Toggle), + MethodDef(Menu), + MethodDef(Slider), + MethodDef(Scrollbar), + MethodDef(Number), + MethodDef(String), + + MethodDef(Text), + + MethodDef(Exit), + MethodDef(Redraw), + MethodDef(Draw), + MethodDef(Register), + + {NULL, NULL} +}; + +PyObject *M_Draw_Init (void); + diff --git a/source/blender/python/api2_2x/EXPP_interface.c b/source/blender/python/api2_2x/EXPP_interface.c new file mode 100644 index 00000000000..e879532864e --- /dev/null +++ b/source/blender/python/api2_2x/EXPP_interface.c @@ -0,0 +1,130 @@ +/* + * + * ***** BEGIN GPL/BL DUAL 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. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * 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. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * This is a new part of Blender. + * + * Contributor(s): Michel Selten + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** +*/ + +#include <stdio.h> + +#include <Python.h> + +#include <BKE_global.h> +#include <BKE_main.h> +#include <DNA_ID.h> +#include <DNA_camera_types.h> +#include <DNA_lamp_types.h> +#include <DNA_material_types.h> +#include <DNA_object_types.h> +#include <DNA_scene_types.h> +#include <DNA_scriptlink_types.h> +#include <DNA_world_types.h> + +#include "gen_utils.h" +#include "modules.h" + +void initBlenderApi2_2x (void) +{ + printf ("initBlenderApi2_2x\n"); + g_blenderdict = NULL; + initBlender (); +} + +ScriptLink * setScriptLinks(ID *id, short event) +{ + ScriptLink * scriptlink; + PyObject * link; + Object * object; + int obj_id; + + obj_id = MAKE_ID2 (id->name[0], id->name[1]); + printf ("In setScriptLinks (id=%s, event=%d)\n",id->name, event); + + switch (obj_id) + { + case ID_OB: + object = GetObjectByName (GetIdName (id)); + if (object == NULL) + { + return NULL; + } + link = ObjectCreatePyObject (object); + scriptlink = &(object->scriptlink); + break; + case ID_LA: + scriptlink = NULL; + Py_INCREF(Py_None); + link = Py_None; + break; + case ID_CA: + scriptlink = NULL; + Py_INCREF(Py_None); + link = Py_None; + break; + case ID_MA: + scriptlink = NULL; + Py_INCREF(Py_None); + link = Py_None; + break; + case ID_WO: + scriptlink = NULL; + Py_INCREF(Py_None); + link = Py_None; + break; + case ID_SCE: + scriptlink = NULL; + Py_INCREF(Py_None); + link = Py_None; + break; + default: + Py_INCREF(Py_None); + link = Py_None; + return NULL; + } + + if (scriptlink == NULL) + { + /* This is probably not an internal error anymore :) +TODO: Check this + printf ("Internal error, unable to create PyBlock for script link\n"); + */ + Py_INCREF(Py_False); + PyDict_SetItemString(g_blenderdict, "bylink", Py_False); + return NULL; + } + else + { + Py_INCREF(Py_True); + PyDict_SetItemString(g_blenderdict, "bylink", Py_True); + } + + PyDict_SetItemString(g_blenderdict, "link", link); + PyDict_SetItemString(g_blenderdict, "event", + Py_BuildValue("s", event_to_name(event))); + + return (scriptlink); +} diff --git a/source/blender/python/api2_2x/EXPP_interface.h b/source/blender/python/api2_2x/EXPP_interface.h new file mode 100644 index 00000000000..e61e6c2d2dc --- /dev/null +++ b/source/blender/python/api2_2x/EXPP_interface.h @@ -0,0 +1,35 @@ +/* + * + * ***** BEGIN GPL/BL DUAL 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. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * 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. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * This is a new part of Blender. + * + * Contributor(s): Michel Selten + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** +*/ + +#include <DNA_ID.h> + +void initBlenderApi2_2x (void); +ScriptLink * setScriptLinks(ID *id, short event); diff --git a/source/blender/python/api2_2x/Image.c b/source/blender/python/api2_2x/Image.c index 4d8ae7480c2..03e9557c6e9 100644 --- a/source/blender/python/api2_2x/Image.c +++ b/source/blender/python/api2_2x/Image.c @@ -39,8 +39,8 @@ static PyObject *M_Image_New(PyObject *self, PyObject *args, PyObject *keywords) { printf ("In Image_New() - unimplemented in 2.25\n"); - Py_INCREF(Py_None); - return Py_None; + Py_INCREF(Py_None); + return Py_None; } /*****************************************************************************/ @@ -51,14 +51,12 @@ static PyObject *M_Image_Get(PyObject *self, PyObject *args) { char *name; Image *img_iter; - C_Image *wanted_img; + C_Image *wanted_img; printf ("In Image_Get()\n"); if (!PyArg_ParseTuple(args, "s", &name)) - { - return (PythonReturnErrorObject (PyExc_AttributeError, + return (EXPP_ReturnPyObjError (PyExc_AttributeError, "expected string argument")); - } /* Use the name to search for the image requested. */ wanted_img = NULL; @@ -66,10 +64,12 @@ static PyObject *M_Image_Get(PyObject *self, PyObject *args) while ((img_iter) && (wanted_img == NULL)) { - if (strcmp (name, GetIdName (&(img_iter->id))) == 0) - wanted_img = (C_Image *)ImageCreatePyObject(img_iter); + if (strcmp (name, img_iter->id.name+2) == 0) { + wanted_img = (C_Image *)PyObject_NEW(C_Image, &Image_Type); + if (wanted_img) wanted_img->image = img_iter; + } - img_iter = img_iter->id.next; + img_iter = img_iter->id.next; } if (wanted_img == NULL) { @@ -77,34 +77,38 @@ static PyObject *M_Image_Get(PyObject *self, PyObject *args) char error_msg[64]; PyOS_snprintf(error_msg, sizeof(error_msg), "Image \"%s\" not found", name); - return (PythonReturnErrorObject (PyExc_NameError, error_msg)); + return (EXPP_ReturnPyObjError (PyExc_NameError, error_msg)); } - return ((PyObject*)wanted_img); + return (PyObject*)wanted_img; } static PyObject *M_Image_Load(PyObject *self, PyObject *args) { - char *fname; - Image *img_ptr; - C_Image *img; + char *fname; + Image *img_ptr; + C_Image *img; printf ("In Image_Load()\n"); - + if (!PyArg_ParseTuple(args, "s", &fname)) - { - return (PythonReturnErrorObject (PyExc_AttributeError, + return (EXPP_ReturnPyObjError (PyExc_AttributeError, "expected string argument")); - } - - img_ptr = add_image(fname); - if (!img_ptr) - return (PythonReturnErrorObject (PyExc_IOError, - "couldn't load image")); + + img = (C_Image *)PyObject_NEW(C_Image, &Image_Type); + + if (!img) + return (EXPP_ReturnPyObjError (PyExc_MemoryError, + "couldn't create PyObject Image_Type")); - img = (C_Image *)ImageCreatePyObject(img_ptr); + img_ptr = add_image(fname); + if (!img_ptr) + return (EXPP_ReturnPyObjError (PyExc_IOError, + "couldn't load image")); - return (PyObject *)img; + img->image = img_ptr; + + return (PyObject *)img; } /*****************************************************************************/ @@ -126,186 +130,75 @@ PyObject *M_Image_Init (void) /*****************************************************************************/ static PyObject *Image_getName(C_Image *self) { - PyObject *attr; - attr = PyDict_GetItemString(self->dict, "name"); - if (attr) { - Py_INCREF(attr); - return attr; - } - return (PythonReturnErrorObject (PyExc_RuntimeError, - "couldn't get Image.name attribute")); + PyObject *attr = PyString_FromString(self->image->id.name+2); + + if (attr) return attr; + + return (EXPP_ReturnPyObjError (PyExc_RuntimeError, + "couldn't get Image.name attribute")); } static PyObject *Image_getFilename(C_Image *self) { - PyObject *attr; - attr = PyDict_GetItemString(self->dict, "filename"); - if (attr) { - Py_INCREF(attr); - return attr; - } - return (PythonReturnErrorObject (PyExc_RuntimeError, - "couldn't get Image.filename attribute")); + PyObject *attr = PyString_FromString(self->image->name); + + if (attr) return attr; + + return (EXPP_ReturnPyObjError (PyExc_RuntimeError, + "couldn't get Image.filename attribute")); } static PyObject *Image_rename(C_Image *self, PyObject *args) { - char *name_str; - char buf[21]; - ID *tmp_id; - PyObject *name; - - if (!PyArg_ParseTuple(args, "s", &name_str)) - return (PythonReturnErrorObject (PyExc_AttributeError, - "expected string argument")); - - PyOS_snprintf(buf, sizeof(buf), "%s", name_str); - - /* update the Blender Image, too */ - tmp_id = &self->image->id; - rename_id(tmp_id, buf); - PyOS_snprintf(buf, sizeof(buf), "%s", tmp_id->name+2);/* may have changed */ - - name = PyString_FromString(buf); - - if (!name) - return (PythonReturnErrorObject (PyExc_MemoryError, - "couldn't create PyString Object")); - - if (PyDict_SetItemString(self->dict, "name", name) != 0) { - Py_DECREF(name); - return (PythonReturnErrorObject (PyExc_RuntimeError, - "couldn't set Image.name attribute")); - } - - Py_INCREF(Py_None); - return Py_None; + char *name; + char buf[21]; + + if (!PyArg_ParseTuple(args, "s", &name)) + return (EXPP_ReturnPyObjError (PyExc_AttributeError, + "expected string argument")); + + PyOS_snprintf(buf, sizeof(buf), "%s", name); + + rename_id(&self->image->id, buf); + + Py_INCREF(Py_None); + return Py_None; } static PyObject *Image_setXRep(C_Image *self, PyObject *args) { - short value; - PyObject *rep; - - if (!PyArg_ParseTuple(args, "h", &value)) - return (PythonReturnErrorObject (PyExc_AttributeError, - "expected int argument in [1,16]")); - - if (value >= EXPP_IMAGE_REP_MIN || value <= EXPP_IMAGE_REP_MAX) - rep = PyInt_FromLong(value); - else - return (PythonReturnErrorObject (PyExc_AttributeError, - "expected int argument in [1,16]")); - - if (!rep) - return (PythonReturnErrorObject (PyExc_MemoryError, - "couldn't create PyInt Object")); - - if (PyDict_SetItemString(self->dict, "xrep", rep) != 0) { - Py_DECREF(rep); - return (PythonReturnErrorObject (PyExc_RuntimeError, - "could not set Image.xrep attribute")); - } - - /* update the Blender Image, too */ - self->image->xrep = value; - - Py_INCREF(Py_None); - return Py_None; + short value; + + if (!PyArg_ParseTuple(args, "h", &value)) + return (EXPP_ReturnPyObjError (PyExc_AttributeError, + "expected int argument in [1,16]")); + + if (value >= EXPP_IMAGE_REP_MIN || value <= EXPP_IMAGE_REP_MAX) + self->image->xrep = value; + else + return (EXPP_ReturnPyObjError (PyExc_AttributeError, + "expected int argument in [1,16]")); + + Py_INCREF(Py_None); + return Py_None; } static PyObject *Image_setYRep(C_Image *self, PyObject *args) { - short value; - PyObject *rep; - - if (!PyArg_ParseTuple(args, "h", &value)) - return (PythonReturnErrorObject (PyExc_AttributeError, - "expected int argument in [1,16]")); - - if (value >= EXPP_IMAGE_REP_MIN || value <= EXPP_IMAGE_REP_MAX) - rep = PyInt_FromLong(value); - else - return (PythonReturnErrorObject (PyExc_AttributeError, - "expected int argument in [1,16]")); - - if (!rep) - return (PythonReturnErrorObject (PyExc_MemoryError, - "couldn't create PyInt Object")); - - if (PyDict_SetItemString(self->dict, "yrep", rep) != 0) { - Py_DECREF(rep); - return (PythonReturnErrorObject (PyExc_RuntimeError, - "could not set Image.yrep attribute")); - } - - /* update the Blender Image, too */ - self->image->yrep = value; - - Py_INCREF(Py_None); - return Py_None; -} + short value; -/*****************************************************************************/ -/* Function: ImageCreatePyObject */ -/* Description: This function will create a new C_Image. If the Image */ -/* struct passed to it is not NULL, it'll use its attributes. */ -/*****************************************************************************/ -PyObject *ImageCreatePyObject (Image *blenderImage) -{ - PyObject *name, *filename, *xrep, *yrep; - C_Image *img; - - printf ("In ImageCreatePyObject\n"); - - img = (C_Image *)PyObject_NEW(C_Image, &Image_Type); - - if (img == NULL) - return NULL; - - img->dict = PyDict_New(); - - if (img->dict == NULL) { - Py_DECREF((PyObject *)img); - return NULL; - } - /*branch currently unused*/ - if (blenderImage == NULL) { /* Not linked to an Image Object yet */ - name = PyString_FromString("DATA"); - filename = PyString_FromString(""); - xrep = PyInt_FromLong(EXPP_IMAGE_REP); /* rep default is 1, of course */ - yrep = PyInt_FromLong(EXPP_IMAGE_REP); - } - else { /* Image Object available, get its attributes directly */ - name = PyString_FromString(blenderImage->id.name+2); - filename = PyString_FromString(blenderImage->name); - xrep = PyInt_FromLong(blenderImage->xrep); - yrep = PyInt_FromLong(blenderImage->yrep); - } - - if (name == NULL || filename == NULL || - xrep == NULL || yrep == NULL) - goto fail; - - if ((PyDict_SetItemString(img->dict, "name", name) != 0) || - (PyDict_SetItemString(img->dict, "filename", filename) != 0) || - (PyDict_SetItemString(img->dict, "xrep", xrep) != 0) || - (PyDict_SetItemString(img->dict, "yrep", yrep) != 0) || - (PyDict_SetItemString(img->dict, "__members__", - PyDict_Keys(img->dict)) != 0)) - goto fail; - - img->image = blenderImage; /* it's NULL when creating only image "data" */ - return ((PyObject*)img); - -fail: - Py_XDECREF(name); - Py_XDECREF(filename); - Py_XDECREF(xrep); - Py_XDECREF(yrep); - Py_DECREF(img->dict); - Py_DECREF((PyObject *)img); - return NULL; + if (!PyArg_ParseTuple(args, "h", &value)) + return (EXPP_ReturnPyObjError (PyExc_AttributeError, + "expected int argument in [1,16]")); + + if (value >= EXPP_IMAGE_REP_MIN || value <= EXPP_IMAGE_REP_MAX) + self->image->yrep = value; + else + return (EXPP_ReturnPyObjError (PyExc_AttributeError, + "expected int argument in [1,16]")); + + Py_INCREF(Py_None); + return Py_None; } /*****************************************************************************/ @@ -315,7 +208,6 @@ fail: /*****************************************************************************/ static void ImageDeAlloc (C_Image *self) { - Py_DECREF(self->dict); PyObject_DEL (self); } @@ -325,18 +217,31 @@ static void ImageDeAlloc (C_Image *self) /* the function that accesses C_Image member variables and */ /* methods. */ /*****************************************************************************/ -static PyObject* ImageGetAttr (C_Image *img, char *name) -{/* first try the attributes dictionary */ - if (img->dict) { - PyObject *v = PyDict_GetItemString(img->dict, name); - if (v) { - Py_INCREF(v); /* was a borrowed ref */ - return v; - } - } - -/* not an attribute, search the methods table */ - return Py_FindMethod(C_Image_methods, (PyObject *)img, name); +static PyObject* ImageGetAttr (C_Image *self, char *name) +{ + PyObject *attr = Py_None; + + if (strcmp(name, "name") == 0) + attr = PyString_FromString(self->image->id.name+2); + else if (strcmp(name, "filename") == 0) + attr = PyString_FromString(self->image->name); + else if (strcmp(name, "xrep") == 0) + attr = PyInt_FromLong(self->image->xrep); + else if (strcmp(name, "yrep") == 0) + attr = PyInt_FromLong(self->image->yrep); + + else if (strcmp(name, "__members__") == 0) + attr = Py_BuildValue("[s,s,s,s]", + "name", "filename", "xrep", "yrep"); + + if (!attr) + return (EXPP_ReturnPyObjError (PyExc_MemoryError, + "couldn't create PyObject")); + + if (attr != Py_None) return attr; /* attribute found, return its value */ + + /* not an attribute, search the methods table */ + return Py_FindMethod(C_Image_methods, (PyObject *)self, name); } /*****************************************************************************/ @@ -347,48 +252,39 @@ static PyObject* ImageGetAttr (C_Image *img, char *name) /*****************************************************************************/ static int ImageSetAttr (C_Image *self, char *name, PyObject *value) { - PyObject *valtuple; - PyObject *error = NULL; - - if (self->dict == NULL) return -1; + PyObject *valtuple; + PyObject *error = NULL; /* We're playing a trick on the Python API users here. Even if they use * Image.member = val instead of Image.setMember(value), we end up using the * function anyway, since it already has error checking, clamps to the right * interval and updates the Blender Image structure when necessary. */ - valtuple = PyTuple_New(1); /* the set* functions expect a tuple */ + valtuple = Py_BuildValue("(N)", value); /* the set* functions expect a tuple */ - if (!valtuple) - return EXPP_intError(PyExc_MemoryError, - "ImageSetAttr: couldn't create PyTuple"); + if (!valtuple) + return EXPP_ReturnIntError(PyExc_MemoryError, + "ImageSetAttr: couldn't create PyTuple"); - if (PyTuple_SetItem(valtuple, 0, value) != 0) { - Py_DECREF(value); /* PyTuple_SetItem incref's value even when it fails */ - Py_DECREF(valtuple); - return EXPP_intError(PyExc_RuntimeError, - "ImageSetAttr: couldn't fill tuple"); - } - - if (strcmp (name, "name") == 0) + if (strcmp (name, "name") == 0) error = Image_rename (self, valtuple); - else if (strcmp (name, "xrep") == 0) - error = Image_setXRep (self, valtuple); - else if (strcmp (name, "yrep") == 0) - error = Image_setYRep (self, valtuple); - else { /* Error: no such member in the Image Data structure */ - Py_DECREF(value); - Py_DECREF(valtuple); - return (EXPP_intError (PyExc_KeyError, - "attribute not found or immutable")); - } - - if (error == Py_None) return 0; /* normal exit */ - - Py_DECREF(value); - Py_DECREF(valtuple); - - return -1; + else if (strcmp (name, "xrep") == 0) + error = Image_setXRep (self, valtuple); + else if (strcmp (name, "yrep") == 0) + error = Image_setYRep (self, valtuple); + else { /* Error: no such member in the Image Data structure */ + Py_DECREF(value); + Py_DECREF(valtuple); + return (EXPP_ReturnIntError (PyExc_KeyError, + "attribute not found or immutable")); + } + + Py_DECREF(valtuple); + + if (error != Py_None) return -1; + + Py_DECREF(Py_None); /* incref'ed by the called set* function */ + return 0; /* normal exit */ } /*****************************************************************************/ @@ -398,12 +294,7 @@ static int ImageSetAttr (C_Image *self, char *name, PyObject *value) /*****************************************************************************/ static int ImagePrint(C_Image *self, FILE *fp, int flags) { - char *name; - - name = PyString_AsString(Image_getName(self)); - - fprintf(fp, "[Image \"%s\"]", name); - + fprintf(fp, "[Image \"%s\"]", self->image->id.name+2); return 0; } @@ -414,12 +305,5 @@ static int ImagePrint(C_Image *self, FILE *fp, int flags) /*****************************************************************************/ static PyObject *ImageRepr (C_Image *self) { - char buf[64]; - char *name; - - name = PyString_AsString(Image_getName(self)); - - PyOS_snprintf(buf, sizeof(buf), "[Image \"%s\"]", name); - - return PyString_FromString(buf); + return PyString_FromString(self->image->id.name+2); } diff --git a/source/blender/python/api2_2x/Image.h b/source/blender/python/api2_2x/Image.h index e783a324796..c92a0f00b0a 100644 --- a/source/blender/python/api2_2x/Image.h +++ b/source/blender/python/api2_2x/Image.h @@ -55,7 +55,7 @@ /* Python API function prototypes for the Image module. */ /*****************************************************************************/ static PyObject *M_Image_New (PyObject *self, PyObject *args, - PyObject *keywords); + PyObject *keywords); static PyObject *M_Image_Get (PyObject *self, PyObject *args); static PyObject *M_Image_Load (PyObject *self, PyObject *args); @@ -96,8 +96,7 @@ struct PyMethodDef M_Image_methods[] = { /*****************************************************************************/ typedef struct { PyObject_HEAD - PyObject *dict; - Image *image; + Image *image; } C_Image; /*****************************************************************************/ @@ -115,15 +114,15 @@ static PyObject *Image_setYRep(C_Image *self, PyObject *args); static PyMethodDef C_Image_methods[] = { /* name, method, flags, doc */ {"getName", (PyCFunction)Image_getName, METH_NOARGS, - "() - Return Image Data name"}, + "() - Return Image Data name"}, {"getFilename", (PyCFunction)Image_getFilename, METH_VARARGS, - "() - Return Image Data filename"}, + "() - Return Image Data filename"}, {"rename", (PyCFunction)Image_rename, METH_VARARGS, - "(str) - Change Image Data name"}, + "(str) - Change Image Data name"}, {"setXRep", (PyCFunction)Image_setXRep, METH_VARARGS, - "(int) - Change Image Data x repetition value"}, + "(int) - Change Image Data x repetition value"}, {"setYRep", (PyCFunction)Image_setYRep, METH_VARARGS, - "(int) - Change Image Data y repetition value"}, + "(int) - Change Image Data y repetition value"}, {0} }; diff --git a/source/blender/python/api2_2x/Lamp.c b/source/blender/python/api2_2x/Lamp.c index 7247b411ef1..142323bb994 100644 --- a/source/blender/python/api2_2x/Lamp.c +++ b/source/blender/python/api2_2x/Lamp.c @@ -38,59 +38,52 @@ static PyObject *M_Lamp_New(PyObject *self, PyObject *args, PyObject *keywords) { char *type_str = "Lamp"; - char *name_str = "Data"; + char *name_str = "LampData"; static char *kwlist[] = {"type_str", "name_str", NULL}; - C_Lamp *lamp; - PyObject *type, *name; - int type_int; - char buf[21]; + C_Lamp *py_lamp; /* for Lamp Data object wrapper in Python */ + Lamp *bl_lamp; /* for actual Lamp Data we create in Blender */ + char buf[21]; printf ("In Lamp_New()\n"); if (!PyArg_ParseTupleAndKeywords(args, keywords, "|ss", kwlist, - &type_str, &name_str)) - return (PythonReturnErrorObject (PyExc_AttributeError, + &type_str, &name_str)) + return (EXPP_ReturnPyObjError (PyExc_AttributeError, "expected string(s) or empty argument")); - if (!strcmp (type_str, "Lamp")) - type_int = EXPP_LAMP_TYPE_LAMP; - else if (!strcmp (type_str, "Sun")) - type_int = EXPP_LAMP_TYPE_SUN; - else if (!strcmp (type_str, "Spot")) - type_int = EXPP_LAMP_TYPE_SPOT; - else if (!strcmp (type_str, "Hemi")) - type_int = EXPP_LAMP_TYPE_HEMI; - else - return (PythonReturnErrorObject (PyExc_AttributeError, + bl_lamp = add_lamp(); /* first create in Blender */ + if (bl_lamp) /* now create the wrapper obj in Python */ + py_lamp = (C_Lamp *)PyObject_NEW(C_Lamp, &Lamp_Type); + else + return (EXPP_ReturnPyObjError (PyExc_RuntimeError, + "couldn't create Lamp Data in Blender")); + + if (py_lamp == NULL) + return (EXPP_ReturnPyObjError (PyExc_MemoryError, + "couldn't create Lamp Data object")); + + py_lamp->lamp = bl_lamp; /* link Python lamp wrapper with Blender Lamp */ + + if (strcmp (type_str, "Lamp") == 0) + bl_lamp->type = (short)EXPP_LAMP_TYPE_LAMP; + else if (strcmp (type_str, "Sun") == 0) + bl_lamp->type = (short)EXPP_LAMP_TYPE_SUN; + else if (strcmp (type_str, "Spot") == 0) + bl_lamp->type = (short)EXPP_LAMP_TYPE_SPOT; + else if (strcmp (type_str, "Hemi") == 0) + bl_lamp->type = (short)EXPP_LAMP_TYPE_HEMI; + else + return (EXPP_ReturnPyObjError (PyExc_AttributeError, "unknown lamp type")); - lamp = (C_Lamp *)LampCreatePyObject(NULL); - - if (lamp == NULL) - return (PythonReturnErrorObject (PyExc_MemoryError, - "couldn't create Lamp Data object")); - - type = PyInt_FromLong(type_int); - if (type) LampSetAttr(lamp, "type", type); - else { - Py_DECREF((PyObject *)lamp); - return (PythonReturnErrorObject (PyExc_MemoryError, - "couldn't create Python string")); - } - - if (strcmp(name_str, "Data") == 0) - return (PyObject *)lamp; - - PyOS_snprintf(buf, sizeof(buf), "%s", name_str); - name = PyString_FromString(buf); - if (name) LampSetAttr(lamp, "name", name); - else { - Py_DECREF((PyObject *)lamp); - return (PythonReturnErrorObject (PyExc_MemoryError, - "couldn't create Python string")); - } - - return (PyObject *)lamp; + if (strcmp(name_str, "LampData") == 0) + return (PyObject *)py_lamp; + else { /* user gave us a name for the lamp, use it */ + PyOS_snprintf(buf, sizeof(buf), "%s", name_str); + rename_id(&bl_lamp->id, buf); + } + + return (PyObject *)py_lamp; } /*****************************************************************************/ @@ -99,14 +92,14 @@ static PyObject *M_Lamp_New(PyObject *self, PyObject *args, PyObject *keywords) /*****************************************************************************/ static PyObject *M_Lamp_Get(PyObject *self, PyObject *args) { - char *name; + char *name; Lamp *lamp_iter; - C_Lamp *wanted_lamp; + C_Lamp *wanted_lamp; printf ("In Lamp_Get()\n"); if (!PyArg_ParseTuple(args, "s", &name)) { - return (PythonReturnErrorObject (PyExc_AttributeError, + return (EXPP_ReturnPyObjError (PyExc_AttributeError, "expected string argument")); } @@ -116,21 +109,22 @@ static PyObject *M_Lamp_Get(PyObject *self, PyObject *args) while ((lamp_iter) && (wanted_lamp == NULL)) { - if (strcmp (name, GetIdName (&(lamp_iter->id))) == 0) - wanted_lamp = (C_Lamp *)LampCreatePyObject(lamp_iter); + if (strcmp (name, lamp_iter->id.name+2) == 0) { + wanted_lamp = (C_Lamp *)PyObject_NEW(C_Lamp, &Lamp_Type); + if (wanted_lamp) wanted_lamp->lamp = lamp_iter; + } - lamp_iter = lamp_iter->id.next; + lamp_iter = lamp_iter->id.next; } - if (wanted_lamp == NULL) { - /* No lamp exists with the name specified in the argument name. */ + if (wanted_lamp == NULL) {/* Requested Lamp doesn't exist */ char error_msg[64]; PyOS_snprintf(error_msg, sizeof(error_msg), "Lamp \"%s\" not found", name); - return (PythonReturnErrorObject (PyExc_NameError, error_msg)); + return (EXPP_ReturnPyObjError (PyExc_NameError, error_msg)); } - wanted_lamp->linked = 1; /* TRUE: linked to a Blender Lamp Object */ - return ((PyObject*)wanted_lamp); + + return (PyObject*)wanted_lamp; } /*****************************************************************************/ @@ -152,256 +146,213 @@ PyObject *M_Lamp_Init (void) /*****************************************************************************/ static PyObject *Lamp_getName(C_Lamp *self) { - PyObject *attr; - attr = PyDict_GetItemString(self->dict, "name"); - if (attr) { - Py_INCREF(attr); - return attr; - } - return (PythonReturnErrorObject (PyExc_RuntimeError, - "couldn't get Lamp.name attribute")); + PyObject *attr = PyString_FromString(self->lamp->id.name+2); + + if (attr) return attr; + + return (EXPP_ReturnPyObjError (PyExc_RuntimeError, + "couldn't get Lamp.name attribute")); } static PyObject *Lamp_getType(C_Lamp *self) { - PyObject *attr; - attr = PyDict_GetItemString(self->dict, "type"); - if (attr) { - Py_INCREF(attr); - return attr; - } - return (PythonReturnErrorObject (PyExc_RuntimeError, + PyObject *attr = PyInt_FromLong(self->lamp->type); + + if (attr) return attr; + + return (EXPP_ReturnPyObjError (PyExc_RuntimeError, "couldn't get Lamp.type attribute")); } static PyObject *Lamp_getMode(C_Lamp *self) -{/* XXX improve this, add the constants to the Lamp dict */ - PyObject *attr; - attr = PyDict_GetItemString(self->dict, "mode"); - if (attr) { - Py_INCREF(attr); - return attr; - } - return (PythonReturnErrorObject (PyExc_RuntimeError, +{ + PyObject *attr = PyInt_FromLong(self->lamp->mode); + + if (attr) return attr; + + return (EXPP_ReturnPyObjError (PyExc_RuntimeError, "couldn't get Lamp.mode attribute")); } static PyObject *Lamp_getSamples(C_Lamp *self) { - PyObject *attr; - attr = PyDict_GetItemString(self->dict, "samples"); - if (attr) { - Py_INCREF(attr); - return attr; - } - return (PythonReturnErrorObject (PyExc_RuntimeError, + PyObject *attr = PyInt_FromLong(self->lamp->samp); + + if (attr) return attr; + + return (EXPP_ReturnPyObjError (PyExc_RuntimeError, "couldn't get Lamp.samples attribute")); } static PyObject *Lamp_getBufferSize(C_Lamp *self) { - PyObject *attr; - attr = PyDict_GetItemString(self->dict, "bufferSize"); - if (attr) { - Py_INCREF(attr); - return attr; - } - return (PythonReturnErrorObject (PyExc_RuntimeError, + PyObject *attr = PyInt_FromLong(self->lamp->bufsize); + + if (attr) return attr; + + return (EXPP_ReturnPyObjError (PyExc_RuntimeError, "couldn't get Lamp.bufferSize attribute")); } static PyObject *Lamp_getHaloStep(C_Lamp *self) { - PyObject *attr; - attr = PyDict_GetItemString(self->dict, "haloStep"); - if (attr) { - Py_INCREF(attr); - return attr; - } - return (PythonReturnErrorObject (PyExc_RuntimeError, + PyObject *attr = PyInt_FromLong(self->lamp->shadhalostep); + + if (attr) return attr; + + return (EXPP_ReturnPyObjError (PyExc_RuntimeError, "couldn't get Lamp.haloStep attribute")); } static PyObject *Lamp_getEnergy(C_Lamp *self) { - PyObject *attr; - attr = PyDict_GetItemString(self->dict, "energy"); - if (attr) { - Py_INCREF(attr); - return attr; - } - return (PythonReturnErrorObject (PyExc_RuntimeError, + PyObject *attr = PyFloat_FromDouble(self->lamp->energy); + + if (attr) return attr; + + return (EXPP_ReturnPyObjError (PyExc_RuntimeError, "couldn't get Lamp.energy attribute")); } static PyObject *Lamp_getDist(C_Lamp *self) { - PyObject *attr; - attr = PyDict_GetItemString(self->dict, "dist"); - if (attr) { - Py_INCREF(attr); - return attr; - } - return (PythonReturnErrorObject (PyExc_RuntimeError, + PyObject *attr = PyFloat_FromDouble(self->lamp->dist); + + if (attr) return attr; + + return (EXPP_ReturnPyObjError (PyExc_RuntimeError, "couldn't get Lamp.dist attribute")); } static PyObject *Lamp_getSpotSize(C_Lamp *self) { - PyObject *attr; - attr = PyDict_GetItemString(self->dict, "spotSize"); - if (attr) { - Py_INCREF(attr); - return attr; - } - return (PythonReturnErrorObject (PyExc_RuntimeError, + PyObject *attr = PyFloat_FromDouble(self->lamp->spotsize); + + if (attr) return attr; + + return (EXPP_ReturnPyObjError (PyExc_RuntimeError, "couldn't get Lamp.spotSize attribute")); } static PyObject *Lamp_getSpotBlend(C_Lamp *self) { - PyObject *attr; - attr = PyDict_GetItemString(self->dict, "spotBlend"); - if (attr) { - Py_INCREF(attr); - return attr; - } - return (PythonReturnErrorObject (PyExc_RuntimeError, + PyObject *attr = PyFloat_FromDouble(self->lamp->spotblend); + + if (attr) return attr; + + return (EXPP_ReturnPyObjError (PyExc_RuntimeError, "couldn't get Lamp.spotBlend attribute")); } static PyObject *Lamp_getClipStart(C_Lamp *self) { - PyObject *attr; - attr = PyDict_GetItemString(self->dict, "clipStart"); - if (attr) { - Py_INCREF(attr); - return attr; - } - return (PythonReturnErrorObject (PyExc_RuntimeError, + PyObject *attr = PyFloat_FromDouble(self->lamp->clipsta); + + if (attr) return attr; + + return (EXPP_ReturnPyObjError (PyExc_RuntimeError, "couldn't get Lamp.clipStart attribute")); } static PyObject *Lamp_getClipEnd(C_Lamp *self) { - PyObject *attr; - attr = PyDict_GetItemString(self->dict, "clipEnd"); - if (attr) { - Py_INCREF(attr); - return attr; - } - return (PythonReturnErrorObject (PyExc_RuntimeError, + PyObject *attr = PyFloat_FromDouble(self->lamp->clipend); + + if (attr) return attr; + + return (EXPP_ReturnPyObjError (PyExc_RuntimeError, "couldn't get Lamp.clipEnd attribute")); } static PyObject *Lamp_getBias(C_Lamp *self) { - PyObject *attr; - attr = PyDict_GetItemString(self->dict, "bias"); - if (attr) { - Py_INCREF(attr); - return attr; - } - return (PythonReturnErrorObject (PyExc_RuntimeError, + PyObject *attr = PyFloat_FromDouble(self->lamp->bias); + + if (attr) return attr; + + return (EXPP_ReturnPyObjError (PyExc_RuntimeError, "couldn't get Lamp.bias attribute")); } static PyObject *Lamp_getSoftness(C_Lamp *self) { - PyObject *attr; - attr = PyDict_GetItemString(self->dict, "softness"); - if (attr) { - Py_INCREF(attr); - return attr; - } - return (PythonReturnErrorObject (PyExc_RuntimeError, + PyObject *attr = PyFloat_FromDouble(self->lamp->soft); + + if (attr) return attr; + + return (EXPP_ReturnPyObjError (PyExc_RuntimeError, "couldn't get Lamp.softness attribute")); } static PyObject *Lamp_getHaloInt(C_Lamp *self) { - PyObject *attr; - attr = PyDict_GetItemString(self->dict, "haloInt"); - if (attr) { - Py_INCREF(attr); - return attr; - } - return (PythonReturnErrorObject (PyExc_RuntimeError, + PyObject *attr = PyFloat_FromDouble(self->lamp->haint); + + if (attr) return attr; + + return (EXPP_ReturnPyObjError (PyExc_RuntimeError, "couldn't get Lamp.haloInt attribute")); } - + +static PyObject *Lamp_getQuad1(C_Lamp *self) +{ /* should we complain if Lamp is not of type Quad? */ + PyObject *attr = PyFloat_FromDouble(self->lamp->att1); + + if (attr) return attr; + + return (EXPP_ReturnPyObjError (PyExc_RuntimeError, + "couldn't get Lamp.quad1 attribute")); +} + +static PyObject *Lamp_getQuad2(C_Lamp *self) +{ /* should we complain if Lamp is not of type Quad? */ + PyObject *attr = PyFloat_FromDouble(self->lamp->att2); + + if (attr) return attr; + + return (EXPP_ReturnPyObjError (PyExc_RuntimeError, + "couldn't get Lamp.quad2 attribute")); +} + static PyObject *Lamp_rename(C_Lamp *self, PyObject *args) { - char *name_str; - char buf[21]; - PyObject *name; - - if (!PyArg_ParseTuple(args, "s", &name_str)) - return (PythonReturnErrorObject (PyExc_AttributeError, - "expected string argument")); - - PyOS_snprintf(buf, sizeof(buf), "%s", name_str); - - if (self->linked) { /* update the Blender Lamp, too */ - ID *tmp_id = &self->lamp->id; - rename_id(tmp_id, buf); - PyOS_snprintf(buf, sizeof(buf), "%s", tmp_id->name+2);/* may have changed */ - } - - name = PyString_FromString(buf); - - if (!name) - return (PythonReturnErrorObject (PyExc_MemoryError, - "couldn't create PyString Object")); - - if (PyDict_SetItemString(self->dict, "name", name) != 0) { - Py_DECREF(name); - return (PythonReturnErrorObject (PyExc_RuntimeError, - "couldn't set Lamp.name attribute")); - } - - Py_INCREF(Py_None); - return Py_None; + char *name; + char buf[21]; + + if (!PyArg_ParseTuple(args, "s", &name)) + return (EXPP_ReturnPyObjError (PyExc_AttributeError, + "expected string argument")); + + PyOS_snprintf(buf, sizeof(buf), "%s", name); + + rename_id(&self->lamp->id, buf); + + Py_INCREF(Py_None); + return Py_None; } static PyObject *Lamp_setType(C_Lamp *self, PyObject *args) { - short value; - char *type_str; - PyObject *type; - - if (!PyArg_ParseTuple(args, "s", &type_str)) - return (PythonReturnErrorObject (PyExc_AttributeError, - "expected one string argument")); - - if (strcmp (type_str, "Lamp") == 0) - value = EXPP_LAMP_TYPE_LAMP; - else if (strcmp (type_str, "Sun") == 0) - value = EXPP_LAMP_TYPE_SUN; - else if (strcmp (type_str, "Spot") == 0) - value = EXPP_LAMP_TYPE_SPOT; - else if (strcmp (type_str, "Hemi") == 0) - value = EXPP_LAMP_TYPE_HEMI; - else - return (PythonReturnErrorObject (PyExc_AttributeError, - "unknown lamp type")); - - type = PyInt_FromLong(value); - if (!type) - return (PythonReturnErrorObject (PyExc_MemoryError, - "couldn't create PyInt Object")); + char *type; - if (PyDict_SetItemString(self->dict, "type", type) != 0) { - Py_DECREF(type); - return (PythonReturnErrorObject (PyExc_AttributeError, - "couldn't set Lamp.type attribute")); - } + if (!PyArg_ParseTuple(args, "s", &type)) + return (EXPP_ReturnPyObjError (PyExc_AttributeError, + "expected string argument")); - if (self->linked) /* update the Blender Lamp, too */ - self->lamp->type = value; + if (strcmp (type, "Lamp") == 0) + self->lamp->type = (short)EXPP_LAMP_TYPE_LAMP; + else if (strcmp (type, "Sun") == 0) + self->lamp->type = (short)EXPP_LAMP_TYPE_SUN; + else if (strcmp (type, "Spot") == 0) + self->lamp->type = (short)EXPP_LAMP_TYPE_SPOT; + else if (strcmp (type, "Hemi") == 0) + self->lamp->type = (short)EXPP_LAMP_TYPE_HEMI; + else + return (EXPP_ReturnPyObjError (PyExc_AttributeError, + "unknown lamp type")); - Py_INCREF(Py_None); - return Py_None; + Py_INCREF(Py_None); + return Py_None; } /* This one is 'private'. It is not really a method, just a helper function for @@ -411,720 +362,332 @@ static PyObject *Lamp_setType(C_Lamp *self, PyObject *args) * argument, this function should receive an int (0 or 1). */ static PyObject *Lamp_setIntType(C_Lamp *self, PyObject *args) { - short value; - PyObject *type; - - if (!PyArg_ParseTuple(args, "h", &value)) - return (PythonReturnErrorObject (PyExc_AttributeError, - "expected int argument in [0,3]")); - - if (value >= 0 && value <= 3) - type = PyInt_FromLong(value); - else - return (PythonReturnErrorObject (PyExc_AttributeError, - "expected int argument in [0,3]")); - - if (!type) - return (PythonReturnErrorObject (PyExc_MemoryError, - "couldn't create PyInt Object")); - - if (PyDict_SetItemString(self->dict, "type", type) != 0) { - Py_DECREF(type); - return (PythonReturnErrorObject (PyExc_RuntimeError, - "could not set Lamp.type attribute")); - } - - if (self->linked) /* update the Blender Lamp, too */ + short value; + + if (!PyArg_ParseTuple(args, "h", &value)) + return (EXPP_ReturnPyObjError (PyExc_AttributeError, + "expected int argument in [0,3]")); + + if (value >= 0 && value <= 3) self->lamp->type = value; + else + return (EXPP_ReturnPyObjError (PyExc_AttributeError, + "expected int argument in [0,3]")); - Py_INCREF(Py_None); - return Py_None; + Py_INCREF(Py_None); + return Py_None; } static PyObject *Lamp_setMode(C_Lamp *self, PyObject *args) {/* Quad, Sphere, Shadows, Halo, Layer, Negative, OnlyShadow, Square */ - char *m[8] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; - short i, flag = 0; - PyObject *mode; + char *m[8] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; + short i, flag = 0; - if (!PyArg_ParseTuple(args, "|ssssssss", &m[0], &m[1], &m[2], - &m[3], &m[4], &m[5], &m[6], &m[7])) - return (PythonReturnErrorObject (PyExc_AttributeError, + if (!PyArg_ParseTuple(args, "|ssssssss", &m[0], &m[1], &m[2], + &m[3], &m[4], &m[5], &m[6], &m[7])) + return (EXPP_ReturnPyObjError (PyExc_AttributeError, "expected string argument(s)")); - for (i = 0; i < 8; i++) { - if (m[i] == NULL) break; - if (strcmp(m[i], "Shadows") == 0) - flag |= EXPP_LAMP_MODE_SHADOWS; - else if (strcmp(m[i], "Halo") == 0) - flag |= EXPP_LAMP_MODE_HALO; - else if (strcmp(m[i], "Layer") == 0) - flag |= EXPP_LAMP_MODE_LAYER; - else if (strcmp(m[i], "Quad") == 0) - flag |= EXPP_LAMP_MODE_QUAD; - else if (strcmp(m[i], "Negative") == 0) - flag |= EXPP_LAMP_MODE_NEGATIVE; - else if (strcmp(m[i], "OnlyShadow") == 0) - flag |= EXPP_LAMP_MODE_ONLYSHADOW; - else if (strcmp(m[i], "Sphere") == 0) - flag |= EXPP_LAMP_MODE_SPHERE; - else if (strcmp(m[i], "Square") == 0) - flag |= EXPP_LAMP_MODE_SQUARE; - else - return (PythonReturnErrorObject (PyExc_AttributeError, - "unknown lamp flag argument")); - } - - mode = PyInt_FromLong(flag); - if (!mode) - return (PythonReturnErrorObject (PyExc_MemoryError, - "couldn't create PyInt Object")); - - if (PyDict_SetItemString(self->dict, "mode", mode) != 0) { - Py_DECREF(mode); - return (PythonReturnErrorObject (PyExc_RuntimeError, - "couldn't set Lamp.mode attribute")); - } - - if (self->linked) /* update the Blender Lamp, too */ - self->lamp->mode = flag; - - Py_INCREF(Py_None); - return Py_None; + for (i = 0; i < 8; i++) { + if (m[i] == NULL) break; + if (strcmp(m[i], "Shadows") == 0) + flag |= (short)EXPP_LAMP_MODE_SHADOWS; + else if (strcmp(m[i], "Halo") == 0) + flag |= (short)EXPP_LAMP_MODE_HALO; + else if (strcmp(m[i], "Layer") == 0) + flag |= (short)EXPP_LAMP_MODE_LAYER; + else if (strcmp(m[i], "Quad") == 0) + flag |= (short)EXPP_LAMP_MODE_QUAD; + else if (strcmp(m[i], "Negative") == 0) + flag |= (short)EXPP_LAMP_MODE_NEGATIVE; + else if (strcmp(m[i], "OnlyShadow") == 0) + flag |= (short)EXPP_LAMP_MODE_ONLYSHADOW; + else if (strcmp(m[i], "Sphere") == 0) + flag |= (short)EXPP_LAMP_MODE_SPHERE; + else if (strcmp(m[i], "Square") == 0) + flag |= (short)EXPP_LAMP_MODE_SQUARE; + else + return (EXPP_ReturnPyObjError (PyExc_AttributeError, + "unknown lamp flag argument")); + } + + self->lamp->mode = flag; + + Py_INCREF(Py_None); + return Py_None; } /* Another helper function, for the same reason. * (See comment before Lamp_setIntType above). */ static PyObject *Lamp_setIntMode(C_Lamp *self, PyObject *args) { - short value; - PyObject *mode; + short value; - if (!PyArg_ParseTuple(args, "h", &value)) - return (PythonReturnErrorObject (PyExc_AttributeError, - "expected int argument")); + if (!PyArg_ParseTuple(args, "h", &value)) + return (EXPP_ReturnPyObjError (PyExc_AttributeError, + "expected int argument")); /* well, with so many flag bits, we just accept any short int, no checking */ - mode = PyInt_FromLong(value); - - if (!mode) - return (PythonReturnErrorObject (PyExc_AttributeError, - "couldn't create PyInt object")); + self->lamp->mode = value; - if (PyDict_SetItemString(self->dict, "mode", mode) != 0) { - Py_DECREF(mode); - return (PythonReturnErrorObject (PyExc_RuntimeError, - "could not set Lamp.mode attribute")); - } - - if (self->linked) /* update the Blender Lamp, too */ - self->lamp->mode = value; - - Py_INCREF(Py_None); - return Py_None; + Py_INCREF(Py_None); + return Py_None; } static PyObject *Lamp_setSamples(C_Lamp *self, PyObject *args) { - short value; - PyObject *samples; - - if (!PyArg_ParseTuple(args, "h", &value)) - return (PythonReturnErrorObject (PyExc_AttributeError, - "expected int argument in [1,16]")); - - if (value >= EXPP_LAMP_SAMPLES_MIN && - value <= EXPP_LAMP_SAMPLES_MAX) - samples = PyInt_FromLong(value); - else - return (PythonReturnErrorObject (PyExc_AttributeError, - "expected int argument in [1,16]")); - - if (!samples) - return (PythonReturnErrorObject (PyExc_MemoryError, - "couldn't create PyInt Object")); - - if (PyDict_SetItemString(self->dict, "samples", samples) != 0) { - Py_DECREF(samples); - return (PythonReturnErrorObject (PyExc_RuntimeError, - "could not set Lamp.samples attribute")); - } - - if (self->linked) /* update the Blender Lamp, too */ + short value; + + if (!PyArg_ParseTuple(args, "h", &value)) + return (EXPP_ReturnPyObjError (PyExc_AttributeError, + "expected int argument in [1,16]")); + + if (value >= EXPP_LAMP_SAMPLES_MIN && + value <= EXPP_LAMP_SAMPLES_MAX) self->lamp->samp = value; + else + return (EXPP_ReturnPyObjError (PyExc_AttributeError, + "expected int argument in [1,16]")); - Py_INCREF(Py_None); - return Py_None; + Py_INCREF(Py_None); + return Py_None; } static PyObject *Lamp_setBufferSize(C_Lamp *self, PyObject *args) { - short value; - PyObject *bufferSize; - - if (!PyArg_ParseTuple(args, "h", &value)) - return (PythonReturnErrorObject (PyExc_AttributeError, - "expected int argument, any of [512, 768, 1024, 1536, 2560]")); - - switch (value) { - case 512: - case 768: - case 1024: - case 1536: - case 2560: - bufferSize = PyInt_FromLong(value); - break; - default: - return (PythonReturnErrorObject (PyExc_AttributeError, - "expected int argument, any of [512, 768, 1024, 1536, 2560]")); - } - - if (!bufferSize) - return (PythonReturnErrorObject (PyExc_MemoryError, - "couldn't create PyInt Object")); - - if (PyDict_SetItemString(self->dict, "bufferSize", bufferSize) != 0) { - Py_DECREF(bufferSize); - return (PythonReturnErrorObject (PyExc_RuntimeError, - "could not set Lamp.bufferSize attribute")); - } - - if (self->linked) /* update the Blender Lamp, too */ - self->lamp->bufsize = value; - - Py_INCREF(Py_None); - return Py_None; + short value; + + if (!PyArg_ParseTuple(args, "h", &value)) + return (EXPP_ReturnPyObjError (PyExc_AttributeError, + "expected int argument, any of [512, 768, 1024, 1536, 2560]")); + + switch (value) { + case 512: + case 768: + case 1024: + case 1536: + case 2560: + self->lamp->bufsize = value; + break; + default: + return (EXPP_ReturnPyObjError (PyExc_AttributeError, + "expected int argument, any of [512, 768, 1024, 1536, 2560]")); + } + + Py_INCREF(Py_None); + return Py_None; } static PyObject *Lamp_setHaloStep(C_Lamp *self, PyObject *args) { - short value; - PyObject *haloStep; + short value; - if (!PyArg_ParseTuple(args, "h", &value)) - return (PythonReturnErrorObject (PyExc_AttributeError, + if (!PyArg_ParseTuple(args, "h", &value)) + return (EXPP_ReturnPyObjError (PyExc_AttributeError, "expected int argument in [0,12]")); - if (value >= EXPP_LAMP_HALOSTEP_MIN && - value <= EXPP_LAMP_HALOSTEP_MAX) - haloStep = PyInt_FromLong(value); - else - return (PythonReturnErrorObject (PyExc_AttributeError, - "expected int argument in [0,12]")); - - if (!haloStep) - return (PythonReturnErrorObject (PyExc_MemoryError, - "couldn't create PyInt Object")); - - if (PyDict_SetItemString(self->dict, "haloStep", haloStep) != 0) { - Py_DECREF(haloStep); - return (PythonReturnErrorObject (PyExc_RuntimeError, - "couldn't set Lamp.haloStep attribute")); - } - - if (self->linked) /* update the Blender Lamp, too */ + if (value >= EXPP_LAMP_HALOSTEP_MIN && + value <= EXPP_LAMP_HALOSTEP_MAX) self->lamp->shadhalostep = value; - - Py_INCREF(Py_None); - return Py_None; + else + return (EXPP_ReturnPyObjError (PyExc_AttributeError, + "expected int argument in [0,12]")); + + Py_INCREF(Py_None); + return Py_None; } static PyObject *Lamp_setColorComponent(C_Lamp *self, char *key, PyObject *args) { - float value; - PyObject *component; - - if (!PyArg_ParseTuple(args, "f", &value)) - return (PythonReturnErrorObject (PyExc_AttributeError, + float value; + + if (!PyArg_ParseTuple(args, "f", &value)) + return (EXPP_ReturnPyObjError (PyExc_AttributeError, "expected float argument in [0.0, 1.0]")); - value = EXPP_ClampFloat (value, 0.0, 1.0); - component = PyFloat_FromDouble(value); - - if (!component) - return (PythonReturnErrorObject (PyExc_MemoryError, - "couldn't create PyFloat Object")); - - if (PyDict_SetItemString(self->dict, key, component) != 0) { - Py_DECREF(component); - return (PythonReturnErrorObject (PyExc_RuntimeError, - "couldn't set Lamp color component attribute")); - } - - if (self->linked) { /* update the Blender Lamp, too */ - if (!strcmp(key, "R")) - self->lamp->r = value; - else if (!strcmp(key, "G")) - self->lamp->g = value; - else if (!strcmp(key, "B")) - self->lamp->b = value; - } - - Py_INCREF(Py_None); - return Py_None; + value = EXPP_ClampFloat (value, 0.0, 1.0); + + if (!strcmp(key, "R")) + self->lamp->r = value; + else if (!strcmp(key, "G")) + self->lamp->g = value; + else if (!strcmp(key, "B")) + self->lamp->b = value; + + Py_INCREF(Py_None); + return Py_None; } static PyObject *Lamp_setEnergy(C_Lamp *self, PyObject *args) { - float value; - PyObject *energy; - - if (!PyArg_ParseTuple(args, "f", &value)) - return (PythonReturnErrorObject (PyExc_AttributeError, + float value; + + if (!PyArg_ParseTuple(args, "f", &value)) + return (EXPP_ReturnPyObjError (PyExc_AttributeError, "expected float argument")); - value = EXPP_ClampFloat (value, EXPP_LAMP_ENERGY_MIN, EXPP_LAMP_ENERGY_MAX); - energy = PyFloat_FromDouble(value); + value = EXPP_ClampFloat (value, EXPP_LAMP_ENERGY_MIN, EXPP_LAMP_ENERGY_MAX); + self->lamp->energy = value; - if (!energy) - return (PythonReturnErrorObject (PyExc_MemoryError, - "couldn't create PyFloat Object")); - - if (PyDict_SetItemString(self->dict, "energy", energy) != 0) { - Py_DECREF(energy); - return (PythonReturnErrorObject (PyExc_RuntimeError, - "couldn't set Lamp.energy attribute")); - } - - if (self->linked) /* update the Blender Lamp, too */ - self->lamp->energy = value; - - Py_INCREF(Py_None); - return Py_None; + Py_INCREF(Py_None); + return Py_None; } static PyObject *Lamp_setDist(C_Lamp *self, PyObject *args) { - float value; - PyObject *dist; - - if (!PyArg_ParseTuple(args, "f", &value)) - return (PythonReturnErrorObject (PyExc_AttributeError, + float value; + + if (!PyArg_ParseTuple(args, "f", &value)) + return (EXPP_ReturnPyObjError (PyExc_AttributeError, "expected float argument")); - value = EXPP_ClampFloat (value, EXPP_LAMP_DIST_MIN, EXPP_LAMP_DIST_MAX); - dist = PyFloat_FromDouble(value); - - if (!dist) - return (PythonReturnErrorObject (PyExc_MemoryError, - "couldn't create PyFloat Object")); - - if (PyDict_SetItemString(self->dict, "dist", dist) != 0) { - Py_DECREF(dist); - return (PythonReturnErrorObject (PyExc_RuntimeError, - "couldn't set Lamp.dist attribute")); - } - - if (self->linked) /* update the Blender Lamp, too */ - self->lamp->dist = value; - - Py_INCREF(Py_None); - return Py_None; + value = EXPP_ClampFloat (value, EXPP_LAMP_DIST_MIN, EXPP_LAMP_DIST_MAX); + self->lamp->dist = value; + + Py_INCREF(Py_None); + return Py_None; } static PyObject *Lamp_setSpotSize(C_Lamp *self, PyObject *args) { - float value; - PyObject *spotSize; - - if (!PyArg_ParseTuple(args, "f", &value)) - return (PythonReturnErrorObject (PyExc_AttributeError, + float value; + + if (!PyArg_ParseTuple(args, "f", &value)) + return (EXPP_ReturnPyObjError (PyExc_AttributeError, "expected float argument")); - value = EXPP_ClampFloat (value, EXPP_LAMP_SPOTSIZE_MIN, EXPP_LAMP_SPOTSIZE_MAX); - spotSize = PyFloat_FromDouble(value); - - if (!spotSize) - return (PythonReturnErrorObject (PyExc_MemoryError, - "couldn't create PyFloat Object")); - - if (PyDict_SetItemString(self->dict, "spotSize", spotSize) != 0) { - Py_DECREF(spotSize); - return (PythonReturnErrorObject (PyExc_RuntimeError, - "couldn't set Lamp.spotSize attribute")); - } - - if (self->linked) /* update the Blender Lamp, too */ - self->lamp->spotsize = value; - - Py_INCREF(Py_None); - return Py_None; + value = EXPP_ClampFloat (value, EXPP_LAMP_SPOTSIZE_MIN, EXPP_LAMP_SPOTSIZE_MAX); + self->lamp->spotsize = value; + + Py_INCREF(Py_None); + return Py_None; } static PyObject *Lamp_setSpotBlend(C_Lamp *self, PyObject *args) { - float value; - PyObject *spotBlend; - - if (!PyArg_ParseTuple(args, "f", &value)) - return (PythonReturnErrorObject (PyExc_AttributeError, + float value; + + if (!PyArg_ParseTuple(args, "f", &value)) + return (EXPP_ReturnPyObjError (PyExc_AttributeError, "expected float argument")); - value = EXPP_ClampFloat (value, EXPP_LAMP_SPOTBLEND_MIN, - EXPP_LAMP_SPOTBLEND_MAX); - spotBlend = PyFloat_FromDouble(value); - - if (!spotBlend) - return (PythonReturnErrorObject (PyExc_MemoryError, - "couldn't create PyFloat Object")); - - if (PyDict_SetItemString(self->dict, "spotBlend", spotBlend) != 0) { - Py_DECREF(spotBlend); - return (PythonReturnErrorObject (PyExc_RuntimeError, - "couldn't set Lamp.spotBlend attribute")); - } - - if (self->linked) /* update the Blender Lamp, too */ - self->lamp->spotblend = value; - - Py_INCREF(Py_None); - return Py_None; + value = EXPP_ClampFloat (value, EXPP_LAMP_SPOTBLEND_MIN, + EXPP_LAMP_SPOTBLEND_MAX); + self->lamp->spotblend = value; + + Py_INCREF(Py_None); + return Py_None; } static PyObject *Lamp_setClipStart(C_Lamp *self, PyObject *args) { - float value; - PyObject *clipStart; - - if (!PyArg_ParseTuple(args, "f", &value)) - return (PythonReturnErrorObject (PyExc_AttributeError, + float value; + + if (!PyArg_ParseTuple(args, "f", &value)) + return (EXPP_ReturnPyObjError (PyExc_AttributeError, "expected a float number as argument")); - - value = EXPP_ClampFloat (value, EXPP_LAMP_CLIPSTART_MIN, - EXPP_LAMP_CLIPSTART_MAX); - - clipStart = PyFloat_FromDouble(value); - - if (!clipStart) - return (PythonReturnErrorObject (PyExc_MemoryError, - "couldn't create PyFloat Object")); - - if (PyDict_SetItemString(self->dict, "clipStart", clipStart) != 0) { - Py_DECREF(clipStart); - return (PythonReturnErrorObject (PyExc_RuntimeError, - "couldn't set Lamp.clipStart attribute")); - } - - if (self->linked) /* update the Blender Lamp, too */ - self->lamp->clipsta = value; - - Py_INCREF(Py_None); - return Py_None; + + value = EXPP_ClampFloat (value, EXPP_LAMP_CLIPSTART_MIN, + EXPP_LAMP_CLIPSTART_MAX); + self->lamp->clipsta = value; + + Py_INCREF(Py_None); + return Py_None; } static PyObject *Lamp_setClipEnd(C_Lamp *self, PyObject *args) { - float value; - PyObject *clipEnd; - - if (!PyArg_ParseTuple(args, "f", &value)) - return (PythonReturnErrorObject (PyExc_AttributeError, + float value; + + if (!PyArg_ParseTuple(args, "f", &value)) + return (EXPP_ReturnPyObjError (PyExc_AttributeError, "expected a float number as argument")); value = EXPP_ClampFloat (value, EXPP_LAMP_CLIPEND_MIN, - EXPP_LAMP_CLIPEND_MAX); - - clipEnd = PyFloat_FromDouble(value); - - if (!clipEnd) - return (PythonReturnErrorObject (PyExc_MemoryError, - "couldn't create PyFloat Object")); - - if (PyDict_SetItemString(self->dict, "clipEnd", clipEnd) != 0) { - Py_DECREF(clipEnd); - return (PythonReturnErrorObject (PyExc_RuntimeError, - "couldn't set Lamp.clipEnd attribute")); - } - - if (self->linked) /* update the Blender Lamp, too */ - self->lamp->clipend = value; - - Py_INCREF(Py_None); - return Py_None; + EXPP_LAMP_CLIPEND_MAX); + self->lamp->clipend = value; + + Py_INCREF(Py_None); + return Py_None; } static PyObject *Lamp_setBias(C_Lamp *self, PyObject *args) { - float value; - PyObject *bias; - - if (!PyArg_ParseTuple(args, "f", &value)) - return (PythonReturnErrorObject (PyExc_AttributeError, + float value; + + if (!PyArg_ParseTuple(args, "f", &value)) + return (EXPP_ReturnPyObjError (PyExc_AttributeError, "expected a float number as argument")); value = EXPP_ClampFloat (value, EXPP_LAMP_BIAS_MIN, EXPP_LAMP_BIAS_MAX); + self->lamp->bias = value; - bias = PyFloat_FromDouble(value); - - if (!bias) - return (PythonReturnErrorObject (PyExc_MemoryError, - "couldn't create PyFloat Object")); - - if (PyDict_SetItemString(self->dict, "bias", bias) != 0) { - Py_DECREF(bias); - return (PythonReturnErrorObject (PyExc_RuntimeError, - "couldn't set Lamp.bias attribute")); - } - - if (self->linked) /* update the Blender Lamp, too */ - self->lamp->bias = value; - - Py_INCREF(Py_None); - return Py_None; + Py_INCREF(Py_None); + return Py_None; } static PyObject *Lamp_setSoftness(C_Lamp *self, PyObject *args) { - float value; - PyObject *softness; - - if (!PyArg_ParseTuple(args, "f", &value)) - return (PythonReturnErrorObject (PyExc_AttributeError, + float value; + + if (!PyArg_ParseTuple(args, "f", &value)) + return (EXPP_ReturnPyObjError (PyExc_AttributeError, "expected a float number as argument")); value = EXPP_ClampFloat (value, EXPP_LAMP_SOFTNESS_MIN, - EXPP_LAMP_SOFTNESS_MAX); - - softness = PyFloat_FromDouble(value); - - if (!softness) - return (PythonReturnErrorObject (PyExc_MemoryError, - "couldn't create PyFloat Object")); - - if (PyDict_SetItemString(self->dict, "softness", softness) != 0) { - Py_DECREF(softness); - return (PythonReturnErrorObject (PyExc_RuntimeError, - "couldn't set Lamp.softness attribute")); - } - - if (self->linked) /* update the Blender Lamp, too */ - self->lamp->soft = value; - - Py_INCREF(Py_None); - return Py_None; + EXPP_LAMP_SOFTNESS_MAX); + self->lamp->soft = value; + + Py_INCREF(Py_None); + return Py_None; } static PyObject *Lamp_setHaloInt(C_Lamp *self, PyObject *args) { - float value; - PyObject *haloInt; - - if (!PyArg_ParseTuple(args, "f", &value)) - return (PythonReturnErrorObject (PyExc_AttributeError, + float value; + + if (!PyArg_ParseTuple(args, "f", &value)) + return (EXPP_ReturnPyObjError (PyExc_AttributeError, "expected a float number as argument")); value = EXPP_ClampFloat (value, EXPP_LAMP_HALOINT_MIN, - EXPP_LAMP_HALOINT_MAX); - - haloInt = PyFloat_FromDouble(value); - - if (!haloInt) - return (PythonReturnErrorObject (PyExc_MemoryError, - "couldn't create PyFloat Object")); - - if (PyDict_SetItemString(self->dict, "haloInt", haloInt) != 0) { - Py_DECREF(haloInt); - return (PythonReturnErrorObject (PyExc_RuntimeError, - "couldn't set Lamp.haloInt attribute")); - } - - if (self->linked) /* update the Blender Lamp, too */ - self->lamp->haint = value; - - Py_INCREF(Py_None); - return Py_None; + EXPP_LAMP_HALOINT_MAX); + self->lamp->haint = value; + + Py_INCREF(Py_None); + return Py_None; } -/*****************************************************************************/ -/* Function: LampCreatePyObject */ -/* Description: This function will create a new C_Lamp. If the Lamp */ -/* struct passed to it is not NULL, it'll use its attributes. */ -/*****************************************************************************/ -PyObject *LampCreatePyObject (Lamp *blenderLamp) +static PyObject *Lamp_setQuad1(C_Lamp *self, PyObject *args) { - PyObject *name, *type, *mode, *R, *G, *B, *energy, *dist; - PyObject *spotSize, *spotBlend, *clipStart, *clipEnd; - PyObject *bias, *softness, *samples, *bufferSize; - PyObject *haloInt, *haloStep; - PyObject *Types, *Lamp, *Sun, *Spot, *Hemi; - PyObject *Modes, *Shadows, *Halo, *Layer, *Quad; - PyObject *Negative, *OnlyShadow, *Sphere, *Square; - C_Lamp *lamp; - - printf ("In LampCreatePyObject\n"); - - lamp = (C_Lamp *)PyObject_NEW(C_Lamp, &Lamp_Type); - - if (lamp == NULL) - return NULL; - - lamp->linked = 0; - lamp->dict = PyDict_New(); - - if (lamp->dict == NULL) { - Py_DECREF((PyObject *)lamp); - return NULL; - } - - if (blenderLamp == NULL) { /* Not linked to a Lamp Object yet */ - name = PyString_FromString("Data"); - type = PyInt_FromLong(EXPP_LAMP_TYPE); - mode = PyInt_FromLong(EXPP_LAMP_MODE); - samples = PyInt_FromLong(EXPP_LAMP_SAMPLES); - bufferSize = PyInt_FromLong(EXPP_LAMP_BUFFERSIZE); - haloStep = PyInt_FromLong(EXPP_LAMP_HALOSTEP); - R = PyFloat_FromDouble(1.0); - G = PyFloat_FromDouble(1.0); - B = PyFloat_FromDouble(1.0); - energy = PyFloat_FromDouble(EXPP_LAMP_ENERGY); - dist = PyFloat_FromDouble(EXPP_LAMP_DIST); - spotSize = PyFloat_FromDouble(EXPP_LAMP_SPOTSIZE); - spotBlend = PyFloat_FromDouble(EXPP_LAMP_SPOTBLEND); - clipStart = PyFloat_FromDouble(EXPP_LAMP_CLIPSTART); - clipEnd = PyFloat_FromDouble(EXPP_LAMP_CLIPEND); - bias = PyFloat_FromDouble(EXPP_LAMP_BIAS); - softness = PyFloat_FromDouble(EXPP_LAMP_SOFTNESS); - haloInt = PyFloat_FromDouble(EXPP_LAMP_HALOINT); - } - else { /* Lamp Object available, get its attributes directly */ - name = PyString_FromString(blenderLamp->id.name+2); - type = PyInt_FromLong(blenderLamp->type); - mode = PyInt_FromLong(blenderLamp->mode); - samples = PyInt_FromLong(blenderLamp->samp); - bufferSize = PyInt_FromLong(blenderLamp->bufsize); - haloStep = PyInt_FromLong(blenderLamp->shadhalostep); - R = PyFloat_FromDouble(blenderLamp->r); - G = PyFloat_FromDouble(blenderLamp->g); - B = PyFloat_FromDouble(blenderLamp->b); - energy = PyFloat_FromDouble(blenderLamp->energy); - dist = PyFloat_FromDouble(blenderLamp->dist); - spotSize = PyFloat_FromDouble(blenderLamp->spotsize); - spotBlend = PyFloat_FromDouble(blenderLamp->spotblend); - clipStart = PyFloat_FromDouble(blenderLamp->clipsta); - clipEnd = PyFloat_FromDouble(blenderLamp->clipend); - bias = PyFloat_FromDouble(blenderLamp->bias); - softness = PyFloat_FromDouble(blenderLamp->soft); - haloInt = PyFloat_FromDouble(blenderLamp->haint); - /*there's shadspotsize, too ... plus others, none in 2.25*/ - } - - Types = constant_New(); - Lamp = PyInt_FromLong(EXPP_LAMP_TYPE_LAMP); - Sun = PyInt_FromLong(EXPP_LAMP_TYPE_SUN); - Spot = PyInt_FromLong(EXPP_LAMP_TYPE_SPOT); - Hemi = PyInt_FromLong(EXPP_LAMP_TYPE_HEMI); - - Modes = constant_New(); - Shadows = PyInt_FromLong(EXPP_LAMP_MODE_SHADOWS); - Halo = PyInt_FromLong(EXPP_LAMP_MODE_HALO); - Layer = PyInt_FromLong(EXPP_LAMP_MODE_LAYER); - Quad = PyInt_FromLong(EXPP_LAMP_MODE_QUAD); - Negative = PyInt_FromLong(EXPP_LAMP_MODE_NEGATIVE); - OnlyShadow = PyInt_FromLong(EXPP_LAMP_MODE_ONLYSHADOW); - Sphere = PyInt_FromLong(EXPP_LAMP_MODE_SPHERE); - Square = PyInt_FromLong(EXPP_LAMP_MODE_SQUARE); - - if (name == NULL || type == NULL || mode == NULL || - samples == NULL || bufferSize == NULL || haloStep == NULL || - R == NULL || G == NULL || B == NULL || energy == NULL || - dist == NULL || spotSize == NULL || spotBlend == NULL || - clipStart == NULL || clipEnd == NULL || bias == NULL || - softness == NULL || haloInt == NULL || Types == NULL || - Lamp == NULL || Sun == NULL || Spot == NULL || Hemi == NULL || - Modes == NULL || Shadows == NULL || Halo == NULL || - Layer == NULL || Quad == NULL || Negative == NULL || - OnlyShadow == NULL || Sphere == NULL || Square == NULL) /* ack! */ - goto fail; - - if ((PyDict_SetItemString(lamp->dict, "name", name) != 0) || - (PyDict_SetItemString(lamp->dict, "type", type) != 0) || - (PyDict_SetItemString(lamp->dict, "mode", mode) != 0) || - (PyDict_SetItemString(lamp->dict, "samples", samples) != 0) || - (PyDict_SetItemString(lamp->dict, "bufferSize", bufferSize) != 0) || - (PyDict_SetItemString(lamp->dict, "R", R) != 0) || - (PyDict_SetItemString(lamp->dict, "G", G) != 0) || - (PyDict_SetItemString(lamp->dict, "B", B) != 0) || - (PyDict_SetItemString(lamp->dict, "energy", energy) != 0) || - (PyDict_SetItemString(lamp->dict, "dist", dist) != 0) || - (PyDict_SetItemString(lamp->dict, "spotSize", spotSize) != 0) || - (PyDict_SetItemString(lamp->dict, "spotBlend", spotBlend) != 0) || - (PyDict_SetItemString(lamp->dict, "clipStart", clipStart) != 0) || - (PyDict_SetItemString(lamp->dict, "clipEnd", clipEnd) != 0) || - (PyDict_SetItemString(lamp->dict, "bias", bias) != 0) || - (PyDict_SetItemString(lamp->dict, "softness", softness) != 0) || - (PyDict_SetItemString(lamp->dict, "haloInt", haloInt) != 0) || - (PyDict_SetItemString(lamp->dict, "haloStep", haloStep) != 0) || - (PyDict_SetItemString(lamp->dict, "Types", Types) != 0) || - (PyDict_SetItemString(lamp->dict, "Modes", Modes) != 0) || - (PyDict_SetItemString(lamp->dict, "__members__", - PyDict_Keys(lamp->dict)) != 0)) - goto fail; - - if ((PyDict_SetItemString(((C_constant *)Types)->dict, - "Lamp", Lamp) != 0) || - (PyDict_SetItemString(((C_constant *)Types)->dict, - "Sun", Sun) != 0) || - (PyDict_SetItemString(((C_constant *)Types)->dict, - "Spot", Spot) != 0) || - (PyDict_SetItemString(((C_constant *)Types)->dict, - "Hemi", Hemi) != 0) || - (PyDict_SetItemString(((C_constant *)Modes)->dict, - "Shadows", Shadows) != 0) || - (PyDict_SetItemString(((C_constant *)Modes)->dict, - "Halo", Halo) != 0) || - (PyDict_SetItemString(((C_constant *)Modes)->dict, - "Layer", Layer) != 0) || - (PyDict_SetItemString(((C_constant *)Modes)->dict, - "Quad", Quad) != 0) || - (PyDict_SetItemString(((C_constant *)Modes)->dict, - "Negative", Negative) != 0) || - (PyDict_SetItemString(((C_constant *)Modes)->dict, - "OnlyShadow", OnlyShadow) != 0) || - (PyDict_SetItemString(((C_constant *)Modes)->dict, - "Sphere", Sphere) != 0) || - (PyDict_SetItemString(((C_constant *)Modes)->dict, - "Square", Square) != 0)) - goto fail; - - lamp->lamp = blenderLamp; /* it's NULL when creating only lamp "data" */ - return ((PyObject*)lamp); - -fail: - Py_XDECREF(name); - Py_XDECREF(type); - Py_XDECREF(mode); - Py_XDECREF(samples); - Py_XDECREF(bufferSize); - Py_XDECREF(R); - Py_XDECREF(G); - Py_XDECREF(B); - Py_XDECREF(energy); - Py_XDECREF(dist); - Py_XDECREF(spotSize); - Py_XDECREF(spotBlend); - Py_XDECREF(clipStart); - Py_XDECREF(clipEnd); - Py_XDECREF(bias); - Py_XDECREF(softness); - Py_XDECREF(haloInt); - Py_XDECREF(haloStep); - Py_XDECREF(Types); - Py_XDECREF(Lamp); - Py_XDECREF(Sun); - Py_XDECREF(Spot); - Py_XDECREF(Hemi); - Py_XDECREF(Modes); - Py_XDECREF(Shadows); - Py_XDECREF(Halo); - Py_XDECREF(Layer); - Py_XDECREF(Quad); - Py_XDECREF(Negative); - Py_XDECREF(OnlyShadow); - Py_XDECREF(Sphere); - Py_XDECREF(Square); - Py_DECREF(lamp->dict); - Py_DECREF((PyObject *)lamp); - return NULL; + float value; + + if (!PyArg_ParseTuple(args, "f", &value)) + return (EXPP_ReturnPyObjError (PyExc_AttributeError, + "expected a float number as argument")); + + value = EXPP_ClampFloat (value, EXPP_LAMP_QUAD1_MIN, + EXPP_LAMP_QUAD1_MAX); + self->lamp->att1 = value; + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject *Lamp_setQuad2(C_Lamp *self, PyObject *args) +{ + float value; + + if (!PyArg_ParseTuple(args, "f", &value)) + return (EXPP_ReturnPyObjError (PyExc_AttributeError, + "expected a float number as argument")); + + value = EXPP_ClampFloat (value, EXPP_LAMP_QUAD2_MIN, + EXPP_LAMP_QUAD2_MAX); + self->lamp->att2 = value; + + Py_INCREF(Py_None); + return Py_None; } /*****************************************************************************/ @@ -1134,7 +697,6 @@ fail: /*****************************************************************************/ static void LampDeAlloc (C_Lamp *self) { - Py_DECREF(self->dict); PyObject_DEL (self); } @@ -1144,17 +706,89 @@ static void LampDeAlloc (C_Lamp *self) /* the function that accesses C_Lamp member variables and */ /* methods. */ /*****************************************************************************/ -static PyObject* LampGetAttr (C_Lamp *lamp, char *name) -{/* first try the attributes dictionary */ - if (lamp->dict) { - PyObject *v = PyDict_GetItemString(lamp->dict, name); - if (v) { - Py_INCREF(v); /* was a borrowed ref */ - return v; - } - } -/* not an attribute, search the methods table */ - return Py_FindMethod(C_Lamp_methods, (PyObject *)lamp, name); +static PyObject* LampGetAttr (C_Lamp *self, char *name) +{ + PyObject *attr = Py_None; + + if (strcmp(name, "name") == 0) + attr = PyString_FromString(self->lamp->id.name+2); + else if (strcmp(name, "type") == 0) + attr = PyInt_FromLong(self->lamp->type); + else if (strcmp(name, "mode") == 0) + attr = PyInt_FromLong(self->lamp->mode); + else if (strcmp(name, "samples") == 0) + attr = PyInt_FromLong(self->lamp->samp); + else if (strcmp(name, "bufferSize") == 0) + attr = PyInt_FromLong(self->lamp->bufsize); + else if (strcmp(name, "haloStep") == 0) + attr = PyInt_FromLong(self->lamp->shadhalostep); + else if (strcmp(name, "R") == 0) + attr = PyFloat_FromDouble(self->lamp->r); + else if (strcmp(name, "G") == 0) + attr = PyFloat_FromDouble(self->lamp->g); + else if (strcmp(name, "B") == 0) + attr = PyFloat_FromDouble(self->lamp->b); + else if (strcmp(name, "energy") == 0) + attr = PyFloat_FromDouble(self->lamp->energy); + else if (strcmp(name, "dist") == 0) + attr = PyFloat_FromDouble(self->lamp->dist); + else if (strcmp(name, "spotSize") == 0) + attr = PyFloat_FromDouble(self->lamp->spotsize); + else if (strcmp(name, "spotBlend") == 0) + attr = PyFloat_FromDouble(self->lamp->spotblend); + else if (strcmp(name, "clipStart") == 0) + attr = PyFloat_FromDouble(self->lamp->clipsta); + else if (strcmp(name, "clipEnd") == 0) + attr = PyFloat_FromDouble(self->lamp->clipend); + else if (strcmp(name, "bias") == 0) + attr = PyFloat_FromDouble(self->lamp->bias); + else if (strcmp(name, "softness") == 0) + attr = PyFloat_FromDouble(self->lamp->soft); + else if (strcmp(name, "haloInt") == 0) + attr = PyFloat_FromDouble(self->lamp->haint); + else if (strcmp(name, "quad1") == 0) + attr = PyFloat_FromDouble(self->lamp->att1); + else if (strcmp(name, "quad2") == 0) + attr = PyFloat_FromDouble(self->lamp->att2); + + else if (strcmp(name, "Types") == 0) { + attr = Py_BuildValue("{s:h,s:h,s:h,s:h}", + "Lamp", EXPP_LAMP_TYPE_LAMP, + "Sun" , EXPP_LAMP_TYPE_SUN, + "Spot", EXPP_LAMP_TYPE_SPOT, + "Hemi", EXPP_LAMP_TYPE_HEMI); + } + + else if (strcmp(name, "Modes") == 0) { + attr = Py_BuildValue("{s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h}", + "Shadows", EXPP_LAMP_MODE_SHADOWS, + "Halo", EXPP_LAMP_MODE_HALO, + "Layer", EXPP_LAMP_MODE_LAYER, + "Quad", EXPP_LAMP_MODE_QUAD, + "Negative", EXPP_LAMP_MODE_NEGATIVE, + "OnlyShadow", EXPP_LAMP_MODE_ONLYSHADOW, + "Sphere", EXPP_LAMP_MODE_SPHERE, + "Square", EXPP_LAMP_MODE_SQUARE); + } + + else if (strcmp(name, "__members__") == 0) { + /* 22 entries */ + attr = Py_BuildValue("[s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s]", + "name", "type", "mode", "samples", "bufferSize", + "haloStep", "R", "G", "B", "energy", "dist", + "spotSize", "spotBlend", "clipStart", "clipEnd", + "bias", "softness", "haloInt", "quad1", "quad2", + "Types", "Modes"); + } + + if (!attr) + return (EXPP_ReturnPyObjError (PyExc_MemoryError, + "couldn't create PyObject")); + + if (attr != Py_None) return attr; /* member attribute found, return it */ + + /* not an attribute, search the methods table */ + return Py_FindMethod(C_Lamp_methods, (PyObject *)self, name); } /*****************************************************************************/ @@ -1165,78 +799,75 @@ static PyObject* LampGetAttr (C_Lamp *lamp, char *name) /*****************************************************************************/ static int LampSetAttr (C_Lamp *self, char *name, PyObject *value) { - PyObject *valtuple; - PyObject *error = NULL; - - if (self->dict == NULL) return -1; - -/* We're playing a trick on the Python API users here. Even if they use - * Lamp.member = val instead of Lamp.setMember(value), we end up using the - * function anyway, since it already has error checking, clamps to the right - * interval and updates the Blender Lamp structure when necessary. */ + PyObject *valtuple; + PyObject *error = NULL; - valtuple = PyTuple_New(1); /* the set* functions expect a tuple */ + valtuple = Py_BuildValue("(N)", value); /* the set* functions expect a tuple */ - if (!valtuple) - return EXPP_intError(PyExc_MemoryError, - "LampSetAttr: couldn't create tuple"); + if (!valtuple) + return EXPP_ReturnIntError(PyExc_MemoryError, + "LampSetAttr: couldn't create tuple"); - if (PyTuple_SetItem(valtuple, 0, value) != 0) { - Py_DECREF(value); /* PyTuple_SetItem incref's value even when it fails */ - Py_DECREF(valtuple); - return EXPP_intError(PyExc_MemoryError, - "LampSetAttr: couldn't fill tuple"); - } - - if (strcmp (name, "name") == 0) + if (strcmp (name, "name") == 0) error = Lamp_rename (self, valtuple); - else if (strcmp (name, "type") == 0) + else if (strcmp (name, "type") == 0) error = Lamp_setIntType (self, valtuple); /* special case */ - else if (strcmp (name, "mode") == 0) + else if (strcmp (name, "mode") == 0) error = Lamp_setIntMode (self, valtuple); /* special case */ - else if (strcmp (name, "samples") == 0) + else if (strcmp (name, "samples") == 0) error = Lamp_setSamples (self, valtuple); - else if (strcmp (name, "bufferSize") == 0) + else if (strcmp (name, "bufferSize") == 0) error = Lamp_setBufferSize (self, valtuple); - else if (strcmp (name, "haloStep") == 0) + else if (strcmp (name, "haloStep") == 0) error = Lamp_setHaloStep (self, valtuple); - else if (strcmp (name, "R") == 0) + else if (strcmp (name, "R") == 0) error = Lamp_setColorComponent (self, "R", valtuple); - else if (strcmp (name, "G") == 0) + else if (strcmp (name, "G") == 0) error = Lamp_setColorComponent (self, "G", valtuple); - else if (strcmp (name, "B") == 0) + else if (strcmp (name, "B") == 0) error = Lamp_setColorComponent (self, "B", valtuple); - else if (strcmp (name, "energy") == 0) + else if (strcmp (name, "energy") == 0) error = Lamp_setEnergy (self, valtuple); - else if (strcmp (name, "dist") == 0) + else if (strcmp (name, "dist") == 0) error = Lamp_setDist (self, valtuple); - else if (strcmp (name, "spotSize") == 0) + else if (strcmp (name, "spotSize") == 0) error = Lamp_setSpotSize (self, valtuple); - else if (strcmp (name, "spotBlend") == 0) + else if (strcmp (name, "spotBlend") == 0) error = Lamp_setSpotBlend (self, valtuple); - else if (strcmp (name, "clipStart") == 0) + else if (strcmp (name, "clipStart") == 0) error = Lamp_setClipStart (self, valtuple); - else if (strcmp (name, "clipEnd") == 0) + else if (strcmp (name, "clipEnd") == 0) error = Lamp_setClipEnd (self, valtuple); - else if (strcmp (name, "bias") == 0) + else if (strcmp (name, "bias") == 0) error = Lamp_setBias (self, valtuple); - else if (strcmp (name, "softness") == 0) + else if (strcmp (name, "softness") == 0) error = Lamp_setSoftness (self, valtuple); - else if (strcmp (name, "haloInt") == 0) + else if (strcmp (name, "haloInt") == 0) error = Lamp_setHaloInt (self, valtuple); - else { /* Error: no such member in the Lamp Data structure */ - Py_DECREF(value); - Py_DECREF(valtuple); - return (EXPP_intError (PyExc_AttributeError, - "attribute not found")); - } - - if (error == Py_None) return 0; /* normal exit */ + else if (strcmp (name, "quad1") == 0) + error = Lamp_setQuad1 (self, valtuple); + else if (strcmp (name, "quad2") == 0) + error = Lamp_setQuad2 (self, valtuple); + + else { /* Error */ + Py_DECREF(valtuple); + + if ((strcmp (name, "Types") == 0) || /* user tried to change a */ + (strcmp (name, "Modes") == 0)) /* constant dict type ... */ + return (EXPP_ReturnIntError (PyExc_AttributeError, + "constant dictionary -- cannot be changed")); + + else /* ... or no member with the given name was found */ + return (EXPP_ReturnIntError (PyExc_KeyError, + "attribute not found")); + } - Py_DECREF(value); - Py_DECREF(valtuple); + Py_DECREF(valtuple); + + if (error != Py_None) return -1; - return -1; + Py_DECREF(Py_None); /* was incref'ed by the called Lamp_set* function */ + return 0; /* normal exit */ } /*****************************************************************************/ @@ -1246,16 +877,7 @@ static int LampSetAttr (C_Lamp *self, char *name, PyObject *value) /*****************************************************************************/ static int LampPrint(C_Lamp *self, FILE *fp, int flags) { - char *lstate = "unlinked"; - char *name; - - if (self->linked) - lstate = "linked"; - - name = PyString_AsString(Lamp_getName(self)); - - fprintf(fp, "[Lamp \"%s\" (%s)]", name, lstate); - + fprintf(fp, "[Lamp \"%s\"]", self->lamp->id.name+2); return 0; } @@ -1266,16 +888,5 @@ static int LampPrint(C_Lamp *self, FILE *fp, int flags) /*****************************************************************************/ static PyObject *LampRepr (C_Lamp *self) { - char buf[64]; - char *lstate = "unlinked"; - char *name; - - if (self->linked) - lstate = "linked"; - - name = PyString_AsString(Lamp_getName(self)); - - PyOS_snprintf(buf, sizeof(buf), "[Lamp \"%s\" (%s)]", name, lstate); - - return PyString_FromString(buf); + return PyString_FromString(self->lamp->id.name+2); } diff --git a/source/blender/python/api2_2x/Lamp.h b/source/blender/python/api2_2x/Lamp.h index 4139bea5b91..1e5913ece44 100644 --- a/source/blender/python/api2_2x/Lamp.h +++ b/source/blender/python/api2_2x/Lamp.h @@ -109,7 +109,7 @@ #define EXPP_LAMP_HALOSTEP 0 #define EXPP_LAMP_HALOSTEP_MIN 0 #define EXPP_LAMP_HALOSTEP_MAX 12 -#define EXPP_LAMP_QUAD1 0.0 /* Not implemented yet ( and not in 2.25) */ +#define EXPP_LAMP_QUAD1 0.0 #define EXPP_LAMP_QUAD1_MIN 0.0 #define EXPP_LAMP_QUAD1_MAX 1.0 #define EXPP_LAMP_QUAD2 1.0 @@ -162,9 +162,7 @@ struct PyMethodDef M_Lamp_methods[] = { /*****************************************************************************/ typedef struct { PyObject_HEAD - PyObject *dict; - Lamp *lamp; - int linked; + Lamp *lamp; } C_Lamp; /*****************************************************************************/ @@ -185,6 +183,8 @@ static PyObject *Lamp_getClipEnd(C_Lamp *self); static PyObject *Lamp_getBias(C_Lamp *self); static PyObject *Lamp_getSoftness(C_Lamp *self); static PyObject *Lamp_getHaloInt(C_Lamp *self); +static PyObject *Lamp_getQuad1(C_Lamp *self); +static PyObject *Lamp_getQuad2(C_Lamp *self); static PyObject *Lamp_rename(C_Lamp *self, PyObject *args); static PyObject *Lamp_setType(C_Lamp *self, PyObject *args); static PyObject *Lamp_setIntType(C_Lamp *self, PyObject *args); @@ -202,8 +202,10 @@ static PyObject *Lamp_setClipEnd(C_Lamp *self, PyObject *args); static PyObject *Lamp_setBias(C_Lamp *self, PyObject *args); static PyObject *Lamp_setSoftness(C_Lamp *self, PyObject *args); static PyObject *Lamp_setHaloInt(C_Lamp *self, PyObject *args); +static PyObject *Lamp_setQuad1(C_Lamp *self, PyObject *args); +static PyObject *Lamp_setQuad2(C_Lamp *self, PyObject *args); static PyObject *Lamp_setColorComponent(C_Lamp *self, char *key, - PyObject *args); + PyObject *args); /*****************************************************************************/ /* Python C_Lamp methods table: */ @@ -211,64 +213,72 @@ static PyObject *Lamp_setColorComponent(C_Lamp *self, char *key, static PyMethodDef C_Lamp_methods[] = { /* name, method, flags, doc */ {"getName", (PyCFunction)Lamp_getName, METH_NOARGS, - "() - return Lamp name"}, + "() - return Lamp name"}, {"getType", (PyCFunction)Lamp_getType, METH_NOARGS, - "() - return Lamp type -\n\t\ + "() - return Lamp type -\n\t\ 'Lamp':0, 'Sun':1, 'Spot':2, 'Hemi':3"}, {"getMode", (PyCFunction)Lamp_getMode, METH_NOARGS, - "() - return Lamp mode flags (or'ed value)"}, + "() - return Lamp mode flags (or'ed value)"}, {"getSamples", (PyCFunction)Lamp_getSamples, METH_NOARGS, - "() - return Lamp samples value"}, + "() - return Lamp samples value"}, {"getBufferSize", (PyCFunction)Lamp_getBufferSize, METH_NOARGS, - "() - return Lamp buffer size value"}, + "() - return Lamp buffer size value"}, {"getHaloStep", (PyCFunction)Lamp_getHaloStep, METH_NOARGS, - "() - return Lamp halo step value"}, + "() - return Lamp halo step value"}, {"getEnergy", (PyCFunction)Lamp_getEnergy, METH_NOARGS, - "() - return Lamp energy value"}, + "() - return Lamp energy value"}, {"getDist", (PyCFunction)Lamp_getDist, METH_NOARGS, - "() - return Lamp clipping distance value"}, + "() - return Lamp clipping distance value"}, {"getSpotSize", (PyCFunction)Lamp_getSpotSize, METH_NOARGS, - "() - return Lamp spot size value"}, + "() - return Lamp spot size value"}, {"getSpotBlend", (PyCFunction)Lamp_getSpotBlend, METH_NOARGS, - "() - return Lamp spot blend value"}, + "() - return Lamp spot blend value"}, {"getClipStart", (PyCFunction)Lamp_getClipStart, METH_NOARGS, - "() - return Lamp clip start value"}, + "() - return Lamp clip start value"}, {"getClipEnd", (PyCFunction)Lamp_getClipEnd, METH_NOARGS, - "() - return Lamp clip end value"}, + "() - return Lamp clip end value"}, {"getBias", (PyCFunction)Lamp_getBias, METH_NOARGS, - "() - return Lamp bias value"}, + "() - return Lamp bias value"}, {"getSoftness", (PyCFunction)Lamp_getSoftness, METH_NOARGS, - "() - return Lamp softness value"}, + "() - return Lamp softness value"}, {"getHaloInt", (PyCFunction)Lamp_getHaloInt, METH_NOARGS, - "() - return Lamp halo intensity value"}, + "() - return Lamp halo intensity value"}, + {"getQuad1", (PyCFunction)Lamp_getQuad1, METH_NOARGS, + "() - return light intensity value #1 for a Quad Lamp"}, + {"getQuad2", (PyCFunction)Lamp_getQuad2, METH_NOARGS, + "() - return light intensity value #2 for a Quad Lamp"}, {"rename", (PyCFunction)Lamp_rename, METH_VARARGS, - "(str) - rename Lamp"}, + "(str) - rename Lamp"}, {"setType", (PyCFunction)Lamp_setType, METH_VARARGS, - "(str) - change Lamp type, which can be 'persp' or 'ortho'"}, + "(str) - change Lamp type, which can be 'persp' or 'ortho'"}, {"setMode", (PyCFunction)Lamp_setMode, METH_VARARGS, - "([up to eight str's]) - Set Lamp mode flag(s)"}, + "([up to eight str's]) - Set Lamp mode flag(s)"}, {"setSamples", (PyCFunction)Lamp_setSamples, METH_VARARGS, - "(int) - change Lamp samples value"}, + "(int) - change Lamp samples value"}, {"setBufferSize", (PyCFunction)Lamp_setBufferSize, METH_VARARGS, - "(int) - change Lamp buffer size value"}, + "(int) - change Lamp buffer size value"}, {"setHaloStep", (PyCFunction)Lamp_setHaloStep, METH_VARARGS, - "(int) - change Lamp halo step value"}, + "(int) - change Lamp halo step value"}, {"setEnergy", (PyCFunction)Lamp_setEnergy, METH_VARARGS, - "(float) - change Lamp energy value"}, + "(float) - change Lamp energy value"}, {"setSpotSize", (PyCFunction)Lamp_setSpotSize, METH_VARARGS, - "(float) - change Lamp spot size value"}, + "(float) - change Lamp spot size value"}, {"setSpotBlend", (PyCFunction)Lamp_setHaloStep, METH_VARARGS, - "(float) - change Lamp spot blend value"}, + "(float) - change Lamp spot blend value"}, {"setClipStart", (PyCFunction)Lamp_setClipStart, METH_VARARGS, - "(float) - change Lamp clip start value"}, + "(float) - change Lamp clip start value"}, {"setClipEnd", (PyCFunction)Lamp_setClipEnd, METH_VARARGS, - "(float) - change Lamp clip end value"}, + "(float) - change Lamp clip end value"}, {"setBias", (PyCFunction)Lamp_setBias, METH_VARARGS, - "(float) - change Lamp draw size value"}, + "(float) - change Lamp draw size value"}, {"setSoftness", (PyCFunction)Lamp_setSoftness, METH_VARARGS, - "(float) - change Lamp softness value"}, + "(float) - change Lamp softness value"}, {"setHaloInt", (PyCFunction)Lamp_setHaloInt, METH_VARARGS, - "(float) - change Lamp halo intensity value"}, + "(float) - change Lamp halo intensity value"}, + {"setQuad1", (PyCFunction)Lamp_setQuad1, METH_VARARGS, + "(float) - change light intensity value #1 for a Quad Lamp"}, + {"setQuad2", (PyCFunction)Lamp_setQuad2, METH_VARARGS, + "(float) - change light intensity value #2 for a Quad Lamp"}, {0} }; diff --git a/source/blender/python/api2_2x/Window.c b/source/blender/python/api2_2x/Window.c new file mode 100644 index 00000000000..66374a3f992 --- /dev/null +++ b/source/blender/python/api2_2x/Window.c @@ -0,0 +1,200 @@ +/* + * + * ***** BEGIN GPL/BL DUAL 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. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * 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. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * This is a new part of Blender. + * + * Contributor(s): Willian P. Germano + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** +*/ + +#include "Window.h" + +/* Many parts of the code here come from the older bpython implementation + * (file opy_window.c) */ + +/*****************************************************************************/ +/* Function: M_Window_Redraw */ +/* Python equivalent: Blender.Window.Redraw */ +/*****************************************************************************/ +PyObject *M_Window_Redraw(PyObject *self, PyObject *args) +{ /* not static so py_slider_update in Draw.[ch] can use it */ + ScrArea *tempsa, *sa; + SpaceText *st; + int wintype = SPACE_VIEW3D; + short redraw_all = 0; + + if (!PyArg_ParseTuple(args, "|i", &wintype)) + return (EXPP_ReturnPyObjError (PyExc_AttributeError, + "expected int argument (or nothing)")); + + if (wintype < 0) + redraw_all = 1; + + if (!during_script()) { /* XXX check this */ + tempsa= curarea; + sa = G.curscreen->areabase.first; + + while (sa) { + + if (sa->spacetype == wintype || redraw_all) { + /* don't force-redraw Text window (Python GUI) when + redraw is called out of a slider update */ + if (sa->spacetype == SPACE_TEXT) { + st = sa->spacedata.first; + if (st->text->flags & TXT_FOLLOW) /* follow cursor display */ + pop_space_text(st); + if (/*disable_force_draw*/0) { /* XXX Blender.Draw ... */ + scrarea_queue_redraw(sa); + } + + + } else { + scrarea_do_windraw(sa); + if (sa->headwin) scrarea_do_headdraw(sa); + } + } + + sa= sa->next; + } + + if (curarea != tempsa) areawinset (tempsa->win); + + if (curarea->headwin) scrarea_do_headdraw (curarea); + + screen_swapbuffers(); + } + + Py_INCREF(Py_None); + return Py_None; +} + +/*****************************************************************************/ +/* Function: M_Window_RedrawAll */ +/* Python equivalent: Blender.Window.RedrawAll */ +/*****************************************************************************/ +static PyObject *M_Window_RedrawAll(PyObject *self, PyObject *args) +{ + return M_Window_Redraw(self, Py_BuildValue("(i)", -1)); +} + +/*****************************************************************************/ +/* Function: M_Window_QRedrawAll */ +/* Python equivalent: Blender.Window.QRedrawAll */ +/*****************************************************************************/ +static PyObject *M_Window_QRedrawAll(PyObject *self, PyObject *args) +{ + allqueue(REDRAWALL, 0); + + Py_INCREF(Py_None); + return Py_None; +} + +/*****************************************************************************/ +/* Function: M_Window_FileSelector */ +/* Python equivalent: Blender.Window.FileSelector */ +/*****************************************************************************/ + +/* This is the callback to "activate_fileselect" below. It receives the + * selected filename and (using it as argument) calls the Python callback + * provided by the script writer and stored in EXPP_FS_PyCallback. */ + +static void getSelectedFile(char *name) +{ + if (EXPP_FS_PyCallback) { + PyObject_CallFunction((PyObject *)EXPP_FS_PyCallback, "s", name); + EXPP_FS_PyCallback = NULL; + } +} + +static PyObject *M_Window_FileSelector(PyObject *self, PyObject *args) +{ + char *title = "SELECT FILE"; + if (!PyArg_ParseTuple(args, "O!|s", + &PyFunction_Type, &EXPP_FS_PyCallback, &title)) + return (EXPP_ReturnPyObjError (PyExc_AttributeError, + "\nexpected a callback function (and optionally a string) as argument(s)")); + + activate_fileselect(FILE_BLENDER, title, G.sce, getSelectedFile); + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject *M_Window_ImageSelector(PyObject *self, PyObject *args) +{ + char *title = "SELECT IMAGE"; + if (!PyArg_ParseTuple(args, "O!|s", + &PyFunction_Type, &EXPP_FS_PyCallback, &title)) + return (EXPP_ReturnPyObjError (PyExc_AttributeError, + "\nexpected a callback function (and optionally a string) as argument(s)")); + + activate_imageselect(FILE_BLENDER, title, G.sce, getSelectedFile); + + Py_INCREF(Py_None); + return Py_None; +} + +/*****************************************************************************/ +/* Function: M_Window_DrawProgressbar */ +/* Python equivalent: Blender.Window.DrawProgressbar */ +/*****************************************************************************/ +static PyObject *M_Window_DrawProgressbar(PyObject *self, PyObject *args) +{ + float done; + char *info = 0; + int retval; + + if(!PyArg_ParseTuple(args, "fs", &done, &info)) + return (EXPP_ReturnPyObjError (PyExc_AttributeError, + "expected a float and a string as arguments")); + + retval = progress_bar(done, info); + + return Py_BuildValue("i", retval); +} + +/*****************************************************************************/ +/* Function: M_Window_Init */ +/*****************************************************************************/ +PyObject *M_Window_Init (void) +{ + PyObject *submodule, *Types; + + printf ("In M_Window_Init()\n"); + + submodule = Py_InitModule3("Blender.Window", M_Window_methods, M_Window_doc); + + Types = Py_BuildValue("{s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h}", + "VIEW3D", SPACE_VIEW3D, "IPO", SPACE_IPO, "OOPS", SPACE_OOPS, + "BUTS", SPACE_BUTS, "FILE", SPACE_FILE, "IMAGE", SPACE_IMAGE, + "INFO", SPACE_INFO, "SEQ", SPACE_SEQ, "IMASEL", SPACE_IMASEL, + "SOUND", SPACE_SOUND, "ACTION", SPACE_ACTION, + "TEXT", SPACE_TEXT, "NLA", SPACE_NLA); + + if (Types) PyModule_AddObject(submodule, "Types", Types); + + return submodule; +} + diff --git a/source/blender/python/api2_2x/Window.h b/source/blender/python/api2_2x/Window.h new file mode 100644 index 00000000000..2fc649bd2a9 --- /dev/null +++ b/source/blender/python/api2_2x/Window.h @@ -0,0 +1,129 @@ +/* + * + * ***** BEGIN GPL/BL DUAL 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. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * 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. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * This is a new part of Blender. + * + * Contributor(s): Willian P. Germano + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** +*/ + +#ifndef EXPP_WINDOW_H +#define EXPP_WINDOW_H + +#include <Python.h> +#include <stdio.h> + +#include <BKE_global.h> +#include <BKE_object.h> /* for during_script() */ +#include <BIF_usiblender.h> +#include <BIF_mywindow.h> +#include <BSE_headerbuttons.h> +#include <BSE_filesel.h> +#include <BIF_screen.h> +#include <BIF_space.h> +#include <BIF_drawtext.h> +#include <mydevice.h> +#include <DNA_view3d_types.h> +#include <DNA_screen_types.h> +#include <DNA_space_types.h> +#include <DNA_text_types.h> + +#include "gen_utils.h" +#include "modules.h" + +/* Used in Draw.c */ +int EXPP_disable_force_draw= 0; + +/* Callback used by the file and image selector access functions */ +static PyObject *(*EXPP_FS_PyCallback)(PyObject *arg) = NULL; + +/*****************************************************************************/ +/* Python API function prototypes for the Window module. */ +/*****************************************************************************/ +PyObject *M_Window_Redraw (PyObject *self, PyObject *args); +static PyObject *M_Window_RedrawAll (PyObject *self, PyObject *args); +static PyObject *M_Window_QRedrawAll (PyObject *self, PyObject *args); +static PyObject *M_Window_FileSelector (PyObject *self, PyObject *args); +static PyObject *M_Window_ImageSelector (PyObject *self, PyObject *args); +static PyObject *M_Window_DrawProgressbar (PyObject *self, PyObject *args); + +/*****************************************************************************/ +/* The following string definitions are used for documentation strings. */ +/* In Python these will be written to the console when doing a */ +/* Blender.Window.__doc__ */ +/*****************************************************************************/ +char M_Window_doc[] = +"The Blender Window module\n\n"; + +char M_Window_Redraw_doc[] = +"() - Force a redraw of a specific Window Type (see Window.Types)"; + +char M_Window_RedrawAll_doc[] = +"() - Redraw all windows"; + +char M_Window_QRedrawAll_doc[] = +"() - Redraw all windows by queue event"; + +char M_Window_FileSelector_doc[] = +"(callback [, title]) - Open a file selector window.\n\ +The selected filename is used as argument to a function callback f(name)\n\ +that you must provide. 'title' is optional and defaults to 'SELECT FILE'.\n\n\ +Example:\n\n\ +import Blender\n\n\ +def my_function(filename):\n\ + print 'The selected file was: ', filename\n\n\ +Blender.Window.FileSelector(my_function, 'SAVE FILE')\n"; + +char M_Window_ImageSelector_doc[] = +"(callback [, title]) - Open an image selector window.\n\ +The selected filename is used as argument to a function callback f(name)\n\ +that you must provide. 'title' is optional and defaults to 'SELECT IMAGE'.\n\n\ +Example:\n\n\ +import Blender\n\n\ +def my_function(filename):\n\ + print 'The selected image file was: ', filename\n\n\ +Blender.Window.ImageSelector(my_function, 'LOAD IMAGE')\n"; + +char M_Window_DrawProgressbar_doc[] = +"(done, text) - Draw a progressbar.\n\ +'done' is a float value <= 1.0, 'text' contains info about what is\n\ +currently being done."; + +/*****************************************************************************/ +/* Python method structure definition for Blender.Window module: */ +/*****************************************************************************/ +struct PyMethodDef M_Window_methods[] = { + {"Redraw", M_Window_Redraw, METH_VARARGS, M_Window_Redraw_doc}, + {"RedrawAll", M_Window_RedrawAll, METH_VARARGS, M_Window_RedrawAll_doc}, + {"QRedrawAll", M_Window_QRedrawAll, METH_VARARGS, M_Window_QRedrawAll_doc}, + {"FileSelector", M_Window_FileSelector, METH_VARARGS, M_Window_FileSelector_doc}, + {"ImageSelector", M_Window_ImageSelector, METH_VARARGS, + M_Window_ImageSelector_doc}, + {"DrawProgressbar", M_Window_DrawProgressbar, METH_VARARGS, + M_Window_DrawProgressbar_doc}, + {NULL, NULL, 0, NULL} +}; + +#endif /* EXPP_WINDOW_H */ diff --git a/source/blender/python/api2_2x/gen_utils.c b/source/blender/python/api2_2x/gen_utils.c index a5ccb9cf620..3f6f34c28f6 100644 --- a/source/blender/python/api2_2x/gen_utils.c +++ b/source/blender/python/api2_2x/gen_utils.c @@ -78,7 +78,13 @@ PyObject * PythonReturnErrorObject (PyObject * type, char * error_msg) return (NULL); } -int EXPP_intError (PyObject *type, char *error_msg) +PyObject *EXPP_ReturnPyObjError (PyObject * type, char * error_msg) +{ /* same as above, just to change its name smoothly */ + PyErr_SetString (type, error_msg); + return NULL; +} + +int EXPP_ReturnIntError (PyObject *type, char *error_msg) { PyErr_SetString (type, error_msg); return -1; @@ -86,7 +92,7 @@ int EXPP_intError (PyObject *type, char *error_msg) /*****************************************************************************/ /* Description: This function increments the reference count of the given */ -/* Python object. */ +/* Python object (usually Py_None) and returns it. */ /*****************************************************************************/ PyObject * PythonIncRef (PyObject *object) { @@ -94,6 +100,11 @@ PyObject * PythonIncRef (PyObject *object) return (object); } +PyObject *EXPP_incr_ret (PyObject *object) +{ + Py_INCREF (object); + return (object); +} /*****************************************************************************/ /* Description: This function maps the event identifier to a string. */ /*****************************************************************************/ diff --git a/source/blender/python/api2_2x/gen_utils.h b/source/blender/python/api2_2x/gen_utils.h index c7ce089c07c..803cd64bca1 100644 --- a/source/blender/python/api2_2x/gen_utils.h +++ b/source/blender/python/api2_2x/gen_utils.h @@ -37,9 +37,11 @@ int StringEqual (char * string1, char * string2); char * GetIdName (ID *id); PyObject * PythonReturnErrorObject (PyObject * type, char * error_msg); PyObject * PythonIncRef (PyObject *object); -char * event_to_name(short event); -float EXPP_ClampFloat(float value, float min, float max); -int EXPP_intError(PyObject *type, char *error_msg); +PyObject * EXPP_incr_ret (PyObject *object); +char * event_to_name (short event); +float EXPP_ClampFloat (float value, float min, float max); +int EXPP_ReturnIntError (PyObject *type, char *error_msg); +PyObject *EXPP_ReturnPyObjError (PyObject * type, char * error_msg); /* The following functions may need to be moved to the respective BKE or */ /* DNA modules. */ diff --git a/source/blender/python/api2_2x/modules.h b/source/blender/python/api2_2x/modules.h index 639021ce5b2..20ea92cf2d7 100644 --- a/source/blender/python/api2_2x/modules.h +++ b/source/blender/python/api2_2x/modules.h @@ -41,11 +41,11 @@ extern PyObject *g_blenderdict; void initBlender (void); -PyObject* initObject (void); -PyObject* ObjectCreatePyObject (struct Object *obj); -PyObject* M_Camera_Init (void); -PyObject* CameraCreatePyObject (struct Camera *cam); -PyObject* M_Lamp_Init (void); -PyObject* LampCreatePyObject (struct Lamp *lamp); -PyObject* M_Image_Init (void); -PyObject* ImageCreatePyObject (struct Image *img); +PyObject *initObject (void); +PyObject *ObjectCreatePyObject (struct Object *obj); +PyObject *M_Camera_Init (void); +PyObject *M_Lamp_Init (void); +PyObject *M_Image_Init (void); +PyObject *M_Window_Init (void); +PyObject *M_Draw_Init (void); +PyObject *M_BGL_Init (void); |