forked from bartvdbraak/blender
* Added submodule Window, including FileSelector and ImageSelector:
Most of the code comes from bpython/intern/opy_window.c, but two new functions were added, to access the file and image selector windows in Blender. * Added submodules Draw (gui) and BGL (OpenGL wrapper): The code comes from bpython/intern/opy_draw.c, with minor changes to integrate it in the new implementation. * Made changes to Camera, Lamp and Image submodules: The implementation was improved. These files should be good starting points for interested new coders to look at, now. * Renamed interface.[ch] to EXPP_interface.[ch] to avoid conflict: There is another interface.h file in source/blender/include.
This commit is contained in:
parent
f20e95b73a
commit
1e891f844a
1486
source/blender/python/api2_2x/BGL.c
Normal file
1486
source/blender/python/api2_2x/BGL.c
Normal file
File diff suppressed because it is too large
Load Diff
424
source/blender/python/api2_2x/BGL.h
Normal file
424
source/blender/python/api2_2x/BGL.h
Normal file
@ -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);
|
@ -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());
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -126,9 +126,7 @@ struct PyMethodDef M_Camera_methods[] = {
|
||||
/*****************************************************************************/
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
PyObject *dict;
|
||||
Camera *camera;
|
||||
int linked;
|
||||
} C_Camera;
|
||||
|
||||
/*****************************************************************************/
|
||||
|
741
source/blender/python/api2_2x/Draw.c
Normal file
741
source/blender/python/api2_2x/Draw.c
Normal file
@ -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;
|
||||
}
|
306
source/blender/python/api2_2x/Draw.h
Normal file
306
source/blender/python/api2_2x/Draw.h
Normal file
@ -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);
|
||||
|
130
source/blender/python/api2_2x/EXPP_interface.c
Normal file
130
source/blender/python/api2_2x/EXPP_interface.c
Normal file
@ -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);
|
||||
}
|
35
source/blender/python/api2_2x/EXPP_interface.h
Normal file
35
source/blender/python/api2_2x/EXPP_interface.h
Normal file
@ -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);
|
@ -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);
|
||||
|
||||
img = (C_Image *)ImageCreatePyObject(img_ptr);
|
||||
if (!img)
|
||||
return (EXPP_ReturnPyObjError (PyExc_MemoryError,
|
||||
"couldn't create PyObject Image_Type"));
|
||||
|
||||
return (PyObject *)img;
|
||||
img_ptr = add_image(fname);
|
||||
if (!img_ptr)
|
||||
return (EXPP_ReturnPyObjError (PyExc_IOError,
|
||||
"couldn't load image"));
|
||||
|
||||
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;
|
||||
char *name;
|
||||
char buf[21];
|
||||
|
||||
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 */
|
||||
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);
|
||||
|
||||
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;
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *Image_setXRep(C_Image *self, PyObject *args)
|
||||
{
|
||||
short value;
|
||||
PyObject *rep;
|
||||
short value;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "h", &value))
|
||||
return (PythonReturnErrorObject (PyExc_AttributeError,
|
||||
"expected int argument in [1,16]"));
|
||||
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)
|
||||
rep = PyInt_FromLong(value);
|
||||
else
|
||||
return (PythonReturnErrorObject (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]"));
|
||||
|
||||
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;
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *Image_setYRep(C_Image *self, PyObject *args)
|
||||
{
|
||||
short value;
|
||||
PyObject *rep;
|
||||
short value;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "h", &value))
|
||||
return (PythonReturnErrorObject (PyExc_AttributeError,
|
||||
"expected int argument in [1,16]"));
|
||||
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)
|
||||
rep = PyInt_FromLong(value);
|
||||
else
|
||||
return (PythonReturnErrorObject (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]"));
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* 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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
static PyObject* ImageGetAttr (C_Image *self, char *name)
|
||||
{
|
||||
PyObject *attr = Py_None;
|
||||
|
||||
/* not an attribute, search the methods table */
|
||||
return Py_FindMethod(C_Image_methods, (PyObject *)img, name);
|
||||
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"));
|
||||
}
|
||||
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"));
|
||||
}
|
||||
|
||||
if (error == Py_None) return 0; /* normal exit */
|
||||
Py_DECREF(valtuple);
|
||||
|
||||
Py_DECREF(value);
|
||||
Py_DECREF(valtuple);
|
||||
if (error != Py_None) return -1;
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -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}
|
||||
};
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -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}
|
||||
};
|
||||
|
||||
|
200
source/blender/python/api2_2x/Window.c
Normal file
200
source/blender/python/api2_2x/Window.c
Normal file
@ -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;
|
||||
}
|
||||
|
129
source/blender/python/api2_2x/Window.h
Normal file
129
source/blender/python/api2_2x/Window.h
Normal file
@ -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 */
|
@ -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. */
|
||||
/*****************************************************************************/
|
||||
|
@ -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. */
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user