- small fix in Sys.c to compile on Windows:

Thanks Florian Eggenberger for telling us about it. And Greg McBride for
   pointing a possible fix.
- Draw.Text and Draw.GetStringWidth updated:
   Now they accept an optional second parameter to set font size and Draw.Text
   returns the drawn string width.
- Partially fixed the update() and PutRaw() bugs in NMesh:
   A total fix will require bigger changes, but what was done (unless buggy)
   takes care of the common cases.
This commit is contained in:
2003-07-01 05:19:14 +00:00
parent 14b4ed4e8d
commit fad2aeb3fb
7 changed files with 138 additions and 112 deletions

View File

@@ -623,7 +623,7 @@ static PyObject *Method_String (PyObject *self, PyObject *args)
static PyObject *Method_GetStringWidth (PyObject *self, PyObject *args)
{
char *text;
char *font_str = NULL;
char *font_str = "normal";
struct BMF_Font *font;
PyObject *width;
@@ -631,13 +631,12 @@ static PyObject *Method_GetStringWidth (PyObject *self, PyObject *args)
return EXPP_ReturnPyObjError (PyExc_TypeError,
"expected one or two string arguments");
if (!font_str) font = (&G)->font;
else if (!strcmp (font_str, "normal")) font = (&G)->font;
if (!strcmp (font_str, "normal")) font = (&G)->font;
else if (!strcmp (font_str, "small" )) font = (&G)->fonts;
else if (!strcmp (font_str, "tiny" )) font = (&G)->fontss;
else
return EXPP_ReturnPyObjError (PyExc_AttributeError,
"\"font\" must be: 'normal' (same as None), 'small' or 'tiny'.");
"\"font\" must be: 'normal' (default), 'small' or 'tiny'.");
width = PyInt_FromLong(BMF_GetStringWidth (font, text));
@@ -664,11 +663,11 @@ static PyObject *Method_Text (PyObject *self, PyObject *args)
else if (!strcmp (font_str, "tiny" )) font = (&G)->fontss;
else
return EXPP_ReturnPyObjError (PyExc_AttributeError,
"\"font\" must be: 'normal' (same as None), 'small' or 'tiny'.");
"\"font\" must be: 'normal' (default), 'small' or 'tiny'.");
BMF_DrawString(font, text);
return EXPP_incr_ret(Py_None);
return PyInt_FromLong (BMF_GetStringWidth (font, text));
}
PyObject *Draw_Init (void)

View File

@@ -266,11 +266,14 @@ new String button\n\n\
static PyObject *Method_String (PyObject *self, PyObject *args);
static char Method_GetStringWidth_doc[] =
"(text) - Return the width in pixels of the given string";
"(text, font = 'normal') - Return the width in pixels of the given string\n\
(font) The font type: 'normal' (default), 'small' or 'tiny'.";
static char Method_Text_doc[] =
"(text) - Draw text onscreen\n\n\
(text) The text to draw\n";
"(text, font = 'normal') - Draw text onscreen\n\n\
(text) The text to draw\n\
(font) The font type: 'normal' (default), 'small' or 'tiny'.\n\n\
NEW! - This function now returns the width of the drawn string.";
static PyObject *Method_GetStringWidth (PyObject *self, PyObject *args);
static PyObject *Method_Text (PyObject *self, PyObject *args);

View File

@@ -24,7 +24,7 @@
*
* This is a new part of Blender.
*
* Contributor(s): Willian P. Germano
* Contributor(s): Willian P. Germano, Michel Selten
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
@@ -143,7 +143,8 @@ struct PyMethodDef M_Material_methods[] = {
/* Function: M_Material_New */
/* Python equivalent: Blender.Material.New */
/*****************************************************************************/
static PyObject *M_Material_New(PyObject *self, PyObject *args, PyObject *keywords)
static PyObject *M_Material_New(PyObject *self, PyObject *args,
PyObject *keywords)
{
char *name = "Mat";
static char *kwlist[] = {"name", NULL};
@@ -1462,3 +1463,19 @@ int EXPP_synchronizeMaterialLists (Object *object, void *data)
/* No synchronization is needed; they're of equal length */
return 1;
}
void EXPP_incr_mats_us (Material **matlist, int len)
{
int i;
Material *mat;
if (len <= 0) return;
for (i = 0; i < len; i++) {
mat = matlist[i];
if (mat) mat->id.us++;
}
return;
}

View File

@@ -46,7 +46,7 @@ void mesh_update(Mesh *mesh)
static void NMCol_dealloc(PyObject *self)
{
PyObject_DEL(self); /* XXX PyObject_Del ?*/
PyObject_DEL(self);
}
static BPy_NMCol *newcol (char r, char g, char b, char a)
@@ -670,6 +670,9 @@ static PyObject *NMesh_update(PyObject *self, PyObject *args)
nmesh->mesh = Mesh_fromNMesh(nmesh);
}
mesh->mat = EXPP_newMaterialList_fromPyList(nmesh->materials);
EXPP_incr_mats_us(mesh->mat, PyList_Size (nmesh->materials));
nmesh_updateMaterials(nmesh);
/**@ This is another ugly fix due to the weird material handling of blender.
* it makes sure that object material lists get updated (by their length)
@@ -1574,12 +1577,14 @@ static PyObject *M_NMesh_PutRaw(PyObject *self, PyObject *args)
if (ob) { // we created a new object
NMesh_assignMaterials_toObject(nmesh, ob);
//return DataBlock_fromData(ob); /* XXX fix this */
return EXPP_incr_ret (Py_None);
}
else
else {
mesh->mat = EXPP_newMaterialList_fromPyList(nmesh->materials);
EXPP_incr_mats_us (mesh->mat, PyList_Size (nmesh->materials));
return EXPP_incr_ret (Py_None);
}
}
#undef MethodDef
#define MethodDef(func) \

View File

@@ -64,7 +64,7 @@
#include "vector.h"
#include "constant.h"
#include "gen_utils.h"
#include "modules.h"
/* EXPP PyType Objects */

View File

@@ -31,7 +31,7 @@
#include "Sys.h"
static PyObject *g_sysmodule = Py_None; /* pointer to Blender.sys module */
static PyObject *g_sysmodule = NULL; /* pointer to Blender.sys module */
PyObject *sys_Init (void)
{

View File

@@ -36,6 +36,7 @@
#include <DNA_scene_types.h>
#include <DNA_object_types.h>
#include <DNA_mesh_types.h>
#include <DNA_camera_types.h>
#include <DNA_lamp_types.h>
#include <DNA_curve_types.h>
@@ -78,8 +79,8 @@ PyObject * Types_Init (void);
/* NMesh Data */
PyObject * NMesh_Init (void);
PyObject * NMesh_CreatePyObject (struct Camera *cam);
Camera * NMesh_FromPyObject (PyObject *pyobj);
PyObject * NMesh_CreatePyObject (Mesh *me);
Mesh * NMesh_FromPyObject (PyObject *pyobj);
int NMesh_CheckPyObject (PyObject *pyobj);
/* Material */
@@ -90,6 +91,7 @@ Material **EXPP_newMaterialList_fromPyList (PyObject *list);
Material **EXPP_newMaterialList(int len);
int EXPP_releaseMaterialList (Material **matlist, int len);
int EXPP_synchronizeMaterialLists (Object *object, void *data);
void EXPP_incr_mats_us (Material **matlist, int len);
PyObject * EXPP_PyList_fromMaterialList(Material **matlist, int len);
/* Camera Data */