Revision: 28590
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=28590
Author:   campbellbarton
Date:     2010-05-05 08:38:49 +0200 (Wed, 05 May 2010)

Log Message:
-----------
[#22177] Adding BLF to the BGE and exposing BLF_load as blf.load
from Mitchell Stokes (moguri) 

also updated blf docs

Modified Paths:
--------------
    trunk/blender/source/blender/python/generic/blf_api.c
    trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp
    trunk/blender/source/gameengine/Ketsji/KX_PythonInit.h

Modified: trunk/blender/source/blender/python/generic/blf_api.c
===================================================================
--- trunk/blender/source/blender/python/generic/blf_api.c       2010-05-05 
02:07:26 UTC (rev 28589)
+++ trunk/blender/source/blender/python/generic/blf_api.c       2010-05-05 
06:38:49 UTC (rev 28590)
@@ -30,7 +30,16 @@
 static char py_blf_position_doc[] =
 ".. function:: position(fontid, x, y, z)\n"
 "\n"
-"   Set the position for drawing text.\n";
+"   Set the position for drawing text.\n"
+"\n"
+"   :arg fontid: The id of the typeface as returned by :func:`blf.load`, for 
default font use 0.\n"
+"   :type fontid: int\n"
+"   :arg x: X axis position to draw the text.\n"
+"   :type x: float\n"
+"   :arg y: Y axis position to draw the text.\n"
+"   :type y: float\n"
+"   :arg z: Z axis position to draw the text.\n"
+"   :type x: float\n";
 
 static PyObject *py_blf_position(PyObject *self, PyObject *args)
 {
@@ -51,6 +60,8 @@
 "\n"
 "   Set the size and dpi for drawing text.\n"
 "\n"
+"   :arg fontid: The id of the typeface as returned by :func:`blf.load`, for 
default font use 0.\n"
+"   :type fontid: int\n"
 "   :arg size: Point size of the font.\n"
 "   :type size: int\n"
 "   :arg dpi: dots per inch value to use for drawing.\n"
@@ -74,6 +85,8 @@
 "\n"
 "   Set the aspect for drawing text.\n"
 "\n"
+"   :arg fontid: The id of the typeface as returned by :func:`blf.load`, for 
default font use 0.\n"
+"   :type fontid: int\n"
 "   :arg aspect: The aspect ratio for text drawing to use.\n"
 "   :type aspect: float\n";
 
@@ -96,6 +109,8 @@
 "\n"
 "   Set the blur radius for drawing text.\n"
 "\n"
+"   :arg fontid: The id of the typeface as returned by :func:`blf.load`, for 
default font use 0.\n"
+"   :type fontid: int\n"
 "   :arg radius: The radius for blurring text (in pixels).\n"
 "   :type radius: int\n";
 
@@ -117,6 +132,8 @@
 "\n"
 "   Draw text in the current context.\n"
 "\n"
+"   :arg fontid: The id of the typeface as returned by :func:`blf.load`, for 
default font use 0.\n"
+"   :type fontid: int\n"
 "   :arg text: the text to draw.\n"
 "   :type text: string\n";
 
@@ -138,6 +155,8 @@
 "\n"
 "   Return the width and hight of the text.\n"
 "\n"
+"   :arg fontid: The id of the typeface as returned by :func:`blf.load`, for 
default font use 0.\n"
+"   :type fontid: int\n"
 "   :arg text: the text to draw.\n"
 "   :type text: string\n"
 "   :return: the width and height of the text.\n"
@@ -164,7 +183,18 @@
 static char py_blf_clipping_doc[] =
 ".. function:: clipping(fontid, xmin, ymin, xmax, ymax)\n"
 "\n"
-"   Set the clipping, enable/disable using CLIPPING.\n";
+"   Set the clipping, enable/disable using CLIPPING.\n"
+"\n"
+"   :arg fontid: The id of the typeface as returned by :func:`blf.load`, for 
default font use 0.\n"
+"   :type fontid: int\n"
+"   :arg xmin: Clip the drawing area by these bounds.\n"
+"   :type xmin: float\n"
+"   :arg ymin: Clip the drawing area by these bounds.\n"
+"   :type ymin: float\n"
+"   :arg xmax: Clip the drawing area by these bounds.\n"
+"   :type xmax: float\n"
+"   :arg ymax: Clip the drawing area by these bounds.\n"
+"   :type ymax: float\n";
 
 static PyObject *py_blf_clipping(PyObject *self, PyObject *args)
 {
@@ -184,6 +214,8 @@
 "\n"
 "   Disable option.\n"
 "\n"
+"   :arg fontid: The id of the typeface as returned by :func:`blf.load`, for 
default font use 0.\n"
+"   :type fontid: int\n"
 "   :arg option: One of ROTATION, CLIPPING, SHADOW or KERNING_DEFAULT.\n"
 "   :type option: int\n";
 
@@ -204,6 +236,8 @@
 "\n"
 "   Enable option.\n"
 "\n"
+"   :arg fontid: The id of the typeface as returned by :func:`blf.load`, for 
default font use 0.\n"
+"   :type fontid: int\n"
 "   :arg option: One of ROTATION, CLIPPING, SHADOW or KERNING_DEFAULT.\n"
 "   :type option: int\n";
 
@@ -224,6 +258,8 @@
 "\n"
 "   Set the text rotation angle, enable/disable using ROTATION.\n"
 "\n"
+"   :arg fontid: The id of the typeface as returned by :func:`blf.load`, for 
default font use 0.\n"
+"   :type fontid: int\n"
 "   :arg angle: The angle for text drawing to use.\n"
 "   :type aspect: float\n";
 
@@ -245,8 +281,16 @@
 "\n"
 "   Shadow options, enable/disable using SHADOW .\n"
 "\n"
+"   :arg fontid: The id of the typeface as returned by :func:`blf.load`, for 
default font use 0.\n"
+"   :type fontid: int\n"
 "   :arg level: The blur level, can be 3, 5 or 0.\n"
-"   :type level: int\n";
+"   :type level: int\n"
+"   :arg r: Shadow color (red channel 0.0 - 1.0).\n"
+"   :type r: float\n"
+"   :arg g: Shadow color (green channel 0.0 - 1.0).\n"
+"   :type g: float\n"
+"   :arg b: Shadow color (blue channel 0.0 - 1.0).\n"
+"   :type b: float\n";
 
 static PyObject *py_blf_shadow(PyObject *self, PyObject *args)
 {
@@ -269,7 +313,14 @@
 static char py_blf_shadow_offset_doc[] =
 ".. function:: shadow_offset(fontid, x, y)\n"
 "\n"
-"   Set the offset for shadow text.\n";
+"   Set the offset for shadow text.\n"
+"\n"
+"   :arg fontid: The id of the typeface as returned by :func:`blf.load`, for 
default font use 0.\n"
+"   :type fontid: int\n"
+"   :arg x: Vertical shadow offset value in pixels.\n"
+"   :type x: float\n"
+"   :arg y: Horizontal shadow offset value in pixels.\n"
+"   :type y: float\n";
 
 static PyObject *py_blf_shadow_offset(PyObject *self, PyObject *args)
 {
@@ -283,6 +334,27 @@
        Py_RETURN_NONE;
 }
 
+static char py_blf_load_doc[] =
+".. function:: load(filename)\n"
+"\n"
+"   Load a new font.\n"
+"\n"
+"   :arg filename: the filename of the font.\n"
+"   :type text: string\n"
+"   :return: the new font's fontid or -1 if there was an error.\n"
+"   :rtype: integer\n";
+
+static PyObject *py_blf_load(PyObject *self, PyObject *args)
+{
+       int fontid = 0;
+       char* filename;
+
+       if (!PyArg_ParseTuple(args, "s:blf.load", &filename))
+               return NULL;
+
+       return PyLong_FromLong(BLF_load(filename));
+}
+
 /*----------------------------MODULE INIT-------------------------*/
 struct PyMethodDef BLF_methods[] = {
        {"aspect", (PyCFunction) py_blf_aspect, METH_VARARGS, 
py_blf_aspect_doc},
@@ -297,6 +369,7 @@
        {"shadow", (PyCFunction) py_blf_shadow, METH_VARARGS, 
py_blf_shadow_doc},
        {"shadow_offset", (PyCFunction) py_blf_shadow_offset, METH_VARARGS, 
py_blf_shadow_offset_doc},
        {"size", (PyCFunction) py_blf_size, METH_VARARGS, py_blf_size_doc},
+       {"load", (PyCFunction) py_blf_load, METH_VARARGS, py_blf_load_doc},
        {NULL, NULL, 0, NULL}
 };
 

Modified: trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp    2010-05-05 
02:07:26 UTC (rev 28589)
+++ trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp    2010-05-05 
06:38:49 UTC (rev 28590)
@@ -41,6 +41,7 @@
        #include "mathutils.h" // Blender.Mathutils module copied here so the 
blenderlayer can use.
        #include "geometry.h" // Blender.Geometry module copied here so the 
blenderlayer can use.
        #include "bgl.h"
+       #include "blf_api.h"
 
        #include "marshal.h" /* python header for loading/saving dicts */
 }
@@ -1981,6 +1982,7 @@
        initMathutils();
        initGeometry();
        initBGL();
+       initBLF();
 
 #ifdef WITH_FFMPEG
        initVideoTexture();
@@ -2306,6 +2308,11 @@
        return BGL_Init();
 }
 
+PyObject* initBLF()
+{
+       return BLF_Init();
+}
+
 // utility function for loading and saving the globalDict
 int saveGamePythonConfig( char **marshal_buffer)
 {

Modified: trunk/blender/source/gameengine/Ketsji/KX_PythonInit.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_PythonInit.h      2010-05-05 
02:07:26 UTC (rev 28589)
+++ trunk/blender/source/gameengine/Ketsji/KX_PythonInit.h      2010-05-05 
06:38:49 UTC (rev 28590)
@@ -47,6 +47,7 @@
 PyObject*      initMathutils();
 PyObject*      initGeometry();
 PyObject*      initBGL();
+PyObject*      initBLF();
 PyObject*      initVideoTexture(void); 
 void           exitGamePlayerPythonScripting();
 PyObject*      initGamePythonScripting(const STR_String& progname, 
TPythonSecurityLevel level, struct Main *maggie);


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to