[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29327] branches/blender2.4/source/blender /python/api2_2x: added API support for Background Image: Windows.GetBgImage (), Windows.SetBgImage(image)

Remigiusz Fiedler migius at gmx.net
Tue Jun 8 02:02:43 CEST 2010


Revision: 29327
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29327
Author:   migius
Date:     2010-06-08 02:02:42 +0200 (Tue, 08 Jun 2010)

Log Message:
-----------
added API support for Background Image: Windows.GetBgImage(), Windows.SetBgImage(image)

Modified Paths:
--------------
    branches/blender2.4/source/blender/python/api2_2x/Window.c
    branches/blender2.4/source/blender/python/api2_2x/doc/Window.py

Modified: branches/blender2.4/source/blender/python/api2_2x/Window.c
===================================================================
--- branches/blender2.4/source/blender/python/api2_2x/Window.c	2010-06-07 23:50:43 UTC (rev 29326)
+++ branches/blender2.4/source/blender/python/api2_2x/Window.c	2010-06-08 00:02:42 UTC (rev 29327)
@@ -32,7 +32,9 @@
 
 #include "BDR_editobject.h"	/* enter / leave editmode */
 #include "BKE_global.h"
+#include "BKE_image.h"		/* for SetBgImage()  */
 #include "BKE_main.h"
+#include "BKE_library.h"		/* for SetBgImage()  */
 #include "BKE_object.h"		/* for during_script() and during_scriptlink() */
 #include "BKE_scene.h"		/* scene_find_camera() */
 #include "BIF_mywindow.h"
@@ -52,6 +54,7 @@
 #include "DNA_object_types.h"
 #include "mydevice.h"
 #include "blendef.h"		/* OBACT */
+#include "Image.h"		/* for GetBgImage()  */
 #include "windowTheme.h"
 #include "Mathutils.h"
 #include "constant.h"
@@ -82,6 +85,8 @@
 static PyObject *M_Window_RedrawAll( PyObject * self, PyObject * args );
 static PyObject *M_Window_QRedrawAll( PyObject * self, PyObject * args );
 static PyObject *M_Window_DrawProgressBar( PyObject * self, PyObject * args );
+static PyObject *M_Window_GetBgImage( PyObject * self ); 
+static PyObject *M_Window_SetBgImage( PyObject * self, PyObject * args ); 
 static PyObject *M_Window_GetCursorPos( PyObject * self );
 static PyObject *M_Window_SetCursorPos( PyObject * self, PyObject * args );
 static PyObject *M_Window_WaitCursor( PyObject * self, PyObject * args );
@@ -165,6 +170,12 @@
 'done' is a float value <= 1.0, 'text' contains info about what is\n\
 currently being done.";
 
+static char M_Window_GetBgImage_doc[] =
+	"() - Get the current Background Image.";
+
+static char M_Window_SetBgImage_doc[] =
+	"(Blender Image) - Set Background Image.";
+
 static char M_Window_GetCursorPos_doc[] =
 	"() - Get the current 3d cursor position as a list of three floats.";
 
@@ -332,6 +343,10 @@
 	 M_Window_DrawProgressBar_doc},
 	{"drawProgressBar", M_Window_DrawProgressBar, METH_VARARGS,
 	 M_Window_DrawProgressBar_doc},
+	{"GetBgImage", ( PyCFunction ) M_Window_GetBgImage, METH_NOARGS,
+	 M_Window_GetBgImage_doc},
+	{"SetBgImage", ( PyCFunction ) M_Window_SetBgImage, METH_VARARGS,
+	 M_Window_SetBgImage_doc},
 	{"GetCursorPos", ( PyCFunction ) M_Window_GetCursorPos, METH_NOARGS,
 	 M_Window_GetCursorPos_doc},
 	{"SetCursorPos", M_Window_SetCursorPos, METH_VARARGS,
@@ -671,6 +686,52 @@
 }
 
 /*****************************************************************************/
+/* Function:   M_Window_GetBgImage					*/
+/* Python equivalent:	Blender.Window.GetBgImage			*/
+/* code borrowed from Texture.py -Texture_getImage( )	*/
+/*****************************************************************************/
+static PyObject *M_Window_GetBgImage	( PyObject * self )
+{
+	if( G.vd && G.vd->bgpic  && G.vd->bgpic->ima)
+		return Image_CreatePyObject( G.vd->bgpic->ima );
+
+	Py_RETURN_NONE;
+}
+
+/*****************************************************************************/
+/* Function:   M_Window_SetBgImage					*/
+/* Python equivalent:	Blender.Window.SetBgImage			*/
+/* code borrowed from Texture.py -Texture_setImage( )	*/
+/*****************************************************************************/
+static PyObject *M_Window_SetBgImage	( PyObject * self , PyObject * args)
+{
+	PyObject *value;
+	Image *blimg = NULL;
+	
+	PyArg_ParseTuple(args, "O", &value);
+	
+	if ( value && value != Py_None && !BPy_Image_Check(value) )
+		return EXPP_ReturnPyObjError( PyExc_TypeError,
+					      "expected an Image or None" );
+
+	if( G.vd &&  G.vd->bgpic->ima ) {
+		G.vd->bgpic->ima->id.us--;
+		G.vd->bgpic->ima = NULL;
+	}
+
+	if ( value == NULL || value == Py_None )
+		Py_RETURN_NONE;
+
+	blimg = Image_FromPyObject( value );
+
+	G.vd->bgpic->ima = blimg;
+	BKE_image_signal(blimg, &G.vd->bgpic->iuser, IMA_SIGNAL_RELOAD );
+	id_us_plus( &blimg->id );
+
+	Py_RETURN_NONE;
+}
+
+/*****************************************************************************/
 /* Function:   M_Window_GetCursorPos					*/
 /* Python equivalent:	Blender.Window.GetCursorPos			*/
 /*****************************************************************************/

Modified: branches/blender2.4/source/blender/python/api2_2x/doc/Window.py
===================================================================
--- branches/blender2.4/source/blender/python/api2_2x/doc/Window.py	2010-06-07 23:50:43 UTC (rev 29326)
+++ branches/blender2.4/source/blender/python/api2_2x/doc/Window.py	2010-06-08 00:02:42 UTC (rev 29327)
@@ -224,6 +224,20 @@
 	@param pivot: constant - Window.PivotTypes
 	"""
 
+def GetBgImage():
+	"""
+	Get the Background Image from current 3D-View (or None).
+	@return: Blender Image or None
+	"""
+
+def SetBgImage(image):
+	"""
+	Set the Image as Background Image of current 3D-View.
+	@param image: The new Image.
+	@type image: Blender Image or None.
+	@None resets/turn off Background Image.
+	"""
+
 def WaitCursor (bool):
   """
   Set cursor to wait or back to normal mode.





More information about the Bf-blender-cvs mailing list