PyAPI
curve - added curve_type() to return the curve type BPyModule & gen_library - works with text3d now, can also make new text3d through bpy.curves.new Added Draw.Label() so scripts can draw can using freetype. widgetwizard - use Draw.Label
This commit is contained in:
@@ -114,6 +114,7 @@
|
||||
#include "DNA_space_types.h"
|
||||
#include "DNA_screen_types.h"
|
||||
|
||||
extern VFont *get_builtin_font(void);
|
||||
|
||||
static PyObject *LibBlockSeq_CreatePyObject( Link *iter, int type )
|
||||
{
|
||||
@@ -393,9 +394,9 @@ Mesh *add_mesh__internal(char *name)
|
||||
PyObject *LibBlockSeq_new(BPy_LibBlockSeq *self, PyObject * args, PyObject *kwd)
|
||||
{
|
||||
ID *id = NULL;
|
||||
char *name=NULL, *filename=NULL, *ipo_type;
|
||||
char *name=NULL, *filename=NULL, *data_type=NULL;
|
||||
int img_width=256, img_height=256;
|
||||
short ipo_code = 0;
|
||||
short data_code = 0;
|
||||
int user_count = 0;
|
||||
|
||||
/* Load from file */
|
||||
@@ -461,37 +462,37 @@ PyObject *LibBlockSeq_new(BPy_LibBlockSeq *self, PyObject * args, PyObject *kwd)
|
||||
"one string and two ints expected as arguments" );
|
||||
CLAMP(img_width, 4, 5000);
|
||||
CLAMP(img_height, 4, 5000);
|
||||
|
||||
} else if (self->type == ID_IP) {
|
||||
/* IPO, needs name and type strings */
|
||||
if( !PyArg_ParseTuple( args, "ss", &name, &ipo_type ) )
|
||||
|
||||
} else if (self->type == ID_CU) {
|
||||
/* Curve, needs name and type strings */
|
||||
if( !PyArg_ParseTuple( args, "ss", &name, &data_type ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"two strings expected as arguments" );
|
||||
|
||||
if( !strcmp( ipo_type, "Object" ) )
|
||||
ipo_code = ID_OB;
|
||||
else if( !strcmp( ipo_type, "Camera" ) )
|
||||
ipo_code = ID_CA;
|
||||
else if( !strcmp( ipo_type, "World" ) )
|
||||
ipo_code = ID_WO;
|
||||
else if( !strcmp( ipo_type, "Material" ) )
|
||||
ipo_code = ID_MA;
|
||||
else if( !strcmp( ipo_type, "Texture" ) )
|
||||
ipo_code = ID_TE;
|
||||
else if( !strcmp( ipo_type, "Lamp" ) )
|
||||
ipo_code = ID_LA;
|
||||
else if( !strcmp( ipo_type, "Action" ) )
|
||||
ipo_code = ID_PO;
|
||||
else if( !strcmp( ipo_type, "Constraint" ) )
|
||||
ipo_code = ID_CO;
|
||||
else if( !strcmp( ipo_type, "Sequence" ) )
|
||||
ipo_code = ID_SEQ;
|
||||
else if( !strcmp( ipo_type, "Curve" ) )
|
||||
ipo_code = ID_CU;
|
||||
else if( !strcmp( ipo_type, "Key" ) )
|
||||
ipo_code = ID_KE;
|
||||
else
|
||||
if( !strcmp( data_type, "Curve" ) ) data_code = OB_CURVE;
|
||||
else if( !strcmp( data_type, "Text3d" ) ) data_code = OB_FONT;/*
|
||||
else if( !strcmp( data_type, "Surf" ) ) data_code = OB_SURF;*/
|
||||
else return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"Second argument for Curve type incorrect\t\nmust be a string in (Curve or Text - Surf is not supported yet)" );
|
||||
|
||||
} else if (self->type == ID_IP) {
|
||||
/* IPO, needs name and type strings */
|
||||
if( !PyArg_ParseTuple( args, "ss", &name, &data_type ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"two strings expected as arguments" );
|
||||
|
||||
if( !strcmp( data_type, "Object" ) ) data_code = ID_OB;
|
||||
else if( !strcmp( data_type, "Camera" ) ) data_code = ID_CA;
|
||||
else if( !strcmp( data_type, "World" ) ) data_code = ID_WO;
|
||||
else if( !strcmp( data_type, "Material" ) ) data_code = ID_MA;
|
||||
else if( !strcmp( data_type, "Texture" ) ) data_code = ID_TE;
|
||||
else if( !strcmp( data_type, "Lamp" ) ) data_code = ID_LA;
|
||||
else if( !strcmp( data_type, "Action" ) ) data_code = ID_PO;
|
||||
else if( !strcmp( data_type, "Constraint" ) ) data_code = ID_CO;
|
||||
else if( !strcmp( data_type, "Sequence" ) ) data_code = ID_SEQ;
|
||||
else if( !strcmp( data_type, "Curve" ) ) data_code = ID_CU;
|
||||
else if( !strcmp( data_type, "Key" ) ) data_code = ID_KE;
|
||||
else return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"Second argument for IPO type incorrect\t\nmust be a string in (Object, Camera, World, Material, Texture, Lamp, Action, Sequence, Curve, Key)" );
|
||||
|
||||
} else {
|
||||
@@ -513,7 +514,18 @@ PyObject *LibBlockSeq_new(BPy_LibBlockSeq *self, PyObject * args, PyObject *kwd)
|
||||
id = (ID *)add_mesh__internal( name );
|
||||
break;
|
||||
case ID_CU:
|
||||
id = (ID *)add_curve( name, OB_CURVE );
|
||||
id = (ID *)add_curve( name, data_code );
|
||||
if (data_code==OB_FONT) {
|
||||
Text3d *text3d = (Text3d *)id;
|
||||
text3d->vfont= get_builtin_font();
|
||||
text3d->vfont->id.us++;
|
||||
text3d->str= MEM_mallocN(sizeof(wchar_t), "str");
|
||||
text3d->str[0] = '\0';
|
||||
text3d->totbox= text3d->actbox= 1;
|
||||
text3d->tb= MEM_callocN(MAXTEXTBOX*sizeof(TextBox), "textbox");
|
||||
text3d->tb[0].w = text3d->tb[0].h = 0.0;
|
||||
|
||||
} /*else { CURVE - Dont need to do anything } */
|
||||
break;
|
||||
case ID_MB:
|
||||
id = (ID *)add_mball( name );
|
||||
@@ -543,7 +555,7 @@ PyObject *LibBlockSeq_new(BPy_LibBlockSeq *self, PyObject * args, PyObject *kwd)
|
||||
id = (ID *)add_camera( name );
|
||||
break;
|
||||
case ID_IP:
|
||||
id = (ID *)add_ipo( name, ipo_code );
|
||||
id = (ID *)add_ipo( name, data_code );
|
||||
break;
|
||||
case ID_WO:
|
||||
id = (ID *)add_world( name );
|
||||
|
||||
@@ -110,6 +110,7 @@ static PyObject *Method_Number( PyObject * self, PyObject * args );
|
||||
static PyObject *Method_String( PyObject * self, PyObject * args );
|
||||
static PyObject *Method_GetStringWidth( PyObject * self, PyObject * args );
|
||||
static PyObject *Method_Text( PyObject * self, PyObject * args );
|
||||
static PyObject *Method_Label( PyObject * self, PyObject * args );
|
||||
static PyObject *Method_PupMenu( PyObject * self, PyObject * args );
|
||||
/* next Five by Campbell: */
|
||||
static PyObject *Method_PupIntInput( PyObject * self, PyObject * args );
|
||||
@@ -273,6 +274,11 @@ static char Method_Text_doc[] =
|
||||
(font) The font size: 'normal' (default), 'small' or 'tiny'.\n\n\
|
||||
This function returns the width of the drawn string.";
|
||||
|
||||
static char Method_Label_doc[] =
|
||||
"(text, x, y) - Draw a text label onscreen\n\n\
|
||||
(text) The text to draw\n\
|
||||
(x, y) The lower left coordinate of the lable";
|
||||
|
||||
static char Method_PupMenu_doc[] =
|
||||
"(string, maxrow = None) - Display a pop-up menu at the screen.\n\
|
||||
The contents of the pop-up are specified through the 'string' argument,\n\
|
||||
@@ -359,6 +365,7 @@ static struct PyMethodDef Draw_methods[] = {
|
||||
MethodDef( String ),
|
||||
MethodDef( GetStringWidth ),
|
||||
MethodDef( Text ),
|
||||
MethodDef( Label ),
|
||||
MethodDef( PupMenu ),
|
||||
MethodDef( PupIntInput ),
|
||||
MethodDef( PupFloatInput ),
|
||||
@@ -1459,6 +1466,23 @@ static PyObject *Method_Text( PyObject * self, PyObject * args )
|
||||
return PyInt_FromLong( BMF_GetStringWidth( font, text ) );
|
||||
}
|
||||
|
||||
static PyObject *Method_Label( PyObject * self, PyObject * args )
|
||||
{
|
||||
uiBlock *block;
|
||||
char *text;
|
||||
int x, y, w, h;
|
||||
|
||||
if( !PyArg_ParseTuple( args, "siiii", &text, &x, &y, &w, &h ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected a string and four ints" );
|
||||
|
||||
block = Get_uiBlock( );
|
||||
uiDefBut(block, LABEL, 0, text, x, y, w, h, 0, 0, 0, 0, 0, "");
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
static PyObject *Method_PupMenu( PyObject * self, PyObject * args )
|
||||
{
|
||||
char *text;
|
||||
|
||||
@@ -92,51 +92,51 @@ Example::
|
||||
|
||||
Window.RedrawAll()
|
||||
|
||||
@var scenes: iterator for L{scene<Scene.Scene>} data
|
||||
@type scenes: L{LibBlockSeq}
|
||||
@var objects: iterator for L{object<Object.Object>} data
|
||||
@type objects: L{LibBlockSeq}
|
||||
@var meshes: iterator for L{mesh<Mesh.Mesh>} data
|
||||
@type meshes: L{LibBlockSeq}
|
||||
@var curves: iterator for L{curve<Curve.Curve>} data
|
||||
@type curves: L{LibBlockSeq}
|
||||
@var metaballs: iterator for L{metaball<Metaball.Metaball>} data
|
||||
@type metaballs: L{LibBlockSeq}
|
||||
@var materials: iterator for L{material<Material.Material>} data
|
||||
@type materials: L{LibBlockSeq}
|
||||
@var textures: iterator for L{texture<Texture.Texture>} data
|
||||
@type textures: L{LibBlockSeq}
|
||||
@var images: iterator for L{image<Image.Image>} data
|
||||
@type images: L{LibBlockSeq}
|
||||
@var lattices: iterator for L{lattice<Lattice.Lattice>} data
|
||||
@type lattices: L{LibBlockSeq}
|
||||
@var lamps: iterator for L{lamp<Lamp.Lamp>} data
|
||||
@type lamps: L{LibBlockSeq}
|
||||
@var cameras: iterator for L{camera<Camera.Camera>} data
|
||||
@type cameras: L{LibBlockSeq}
|
||||
@var ipos: iterator for L{ipo<Ipo.Ipo>} data
|
||||
@type ipos: L{LibBlockSeq}
|
||||
@var worlds: iterator for L{world<World.World>} data
|
||||
@type worlds: L{LibBlockSeq}
|
||||
@var fonts: iterator for L{font<Font.Font>} data
|
||||
@type fonts: L{LibBlockSeq}
|
||||
@var texts: iterator for L{text<Text.Text>} data
|
||||
@type texts: L{LibBlockSeq}
|
||||
@var sounds: iterator for L{sound<Sound.Sound>} data
|
||||
@type sounds: L{LibBlockSeq}
|
||||
@var groups: iterator for L{group<Group.Group>} data
|
||||
@type groups: L{LibBlockSeq}
|
||||
@var armatures: iterator for L{armature<Armature.Armature>} data
|
||||
@type armatures: L{LibBlockSeq}
|
||||
@var actions: iterator for L{action<NLA.Action>} data
|
||||
@type actions: L{LibBlockSeq}
|
||||
@var scenes: sequence for L{scene<Scene.Scene>} data
|
||||
@type scenes: L{libBlockSeq}
|
||||
@var objects: sequence for L{object<Object.Object>} data
|
||||
@type objects: L{libBlockSeq}
|
||||
@var meshes: sequence for L{mesh<Mesh.Mesh>} data
|
||||
@type meshes: L{libBlockSeq}
|
||||
@var curves: sequence for L{curve<Curve.Curve>} data, used to store Curve, Surface and Text3d data.
|
||||
@type curves: L{libBlockSeq}
|
||||
@var metaballs: sequence for L{metaball<Metaball.Metaball>} data
|
||||
@type metaballs: L{libBlockSeq}
|
||||
@var materials: sequence for L{material<Material.Material>} data
|
||||
@type materials: L{libBlockSeq}
|
||||
@var textures: sequence for L{texture<Texture.Texture>} data
|
||||
@type textures: L{libBlockSeq}
|
||||
@var images: sequence for L{image<Image.Image>} data
|
||||
@type images: L{libBlockSeq}
|
||||
@var lattices: sequence for L{lattice<Lattice.Lattice>} data
|
||||
@type lattices: L{libBlockSeq}
|
||||
@var lamps: sequence for L{lamp<Lamp.Lamp>} data
|
||||
@type lamps: L{libBlockSeq}
|
||||
@var cameras: sequence for L{camera<Camera.Camera>} data
|
||||
@type cameras: L{libBlockSeq}
|
||||
@var ipos: sequence for L{ipo<Ipo.Ipo>} data
|
||||
@type ipos: L{libBlockSeq}
|
||||
@var worlds: sequence for L{world<World.World>} data
|
||||
@type worlds: L{libBlockSeq}
|
||||
@var fonts: sequence for L{font<Font.Font>} data
|
||||
@type fonts: L{libBlockSeq}
|
||||
@var texts: sequence for L{text<Text.Text>} data
|
||||
@type texts: L{libBlockSeq}
|
||||
@var sounds: sequence for L{sound<Sound.Sound>} data
|
||||
@type sounds: L{libBlockSeq}
|
||||
@var groups: sequence for L{group<Group.Group>} data
|
||||
@type groups: L{libBlockSeq}
|
||||
@var armatures: sequence for L{armature<Armature.Armature>} data
|
||||
@type armatures: L{libBlockSeq}
|
||||
@var actions: sequence for L{action<NLA.Action>} data
|
||||
@type actions: L{libBlockSeq}
|
||||
@var libraries: L{librarySeq<LibData>} submodule
|
||||
@type libraries: L{librarySeq<LibData>}
|
||||
|
||||
"""
|
||||
|
||||
|
||||
class LibBlockSeq:
|
||||
class libBlockSeq:
|
||||
"""
|
||||
Generic Data Access
|
||||
===================
|
||||
@@ -156,8 +156,8 @@ class LibBlockSeq:
|
||||
|
||||
B{Library distinctions}
|
||||
|
||||
Blender doesn't allow naming collisions within its own pool of data, but it's
|
||||
possible to run into naming collisions when you have data linked from an external file.
|
||||
Blender doesn't allow naming collisions within its own data, but it's
|
||||
possible to run into naming collisions when you have data linked from an external blend file.
|
||||
|
||||
You can specify where the data is from by using a (name, library) pair as the key.
|
||||
|
||||
@@ -167,11 +167,11 @@ class LibBlockSeq:
|
||||
|
||||
>>> group = bpy.groups['mygroup', None] # always returns local data
|
||||
|
||||
Iterator
|
||||
Sequence
|
||||
========
|
||||
generic_datablock's are not lists; however they can be used like lists.
|
||||
|
||||
An iterator allows you to loop through data, without wasting resources on a large list.
|
||||
An sequence allows you to loop through data, without wasting resources on a large list.
|
||||
|
||||
>>> for me in bpy.meshes:
|
||||
... print me.name
|
||||
@@ -212,24 +212,41 @@ class LibBlockSeq:
|
||||
|
||||
"""
|
||||
|
||||
def new(name="", filename=""):
|
||||
def new(name):
|
||||
"""
|
||||
This function returns a new datablock containing no data or loaded from a file.
|
||||
|
||||
Exceptions
|
||||
==========
|
||||
Most datatypes accept a name for their argument except for L{sounds}, L{fonts}, L{ipos} and L{curves} that need an additional argument.
|
||||
|
||||
Use the filename keyword string values to load data from a file, this works with L{images}, L{texts}, L{sounds}, L{fonts} only.
|
||||
Loading From File
|
||||
=================
|
||||
For L{images}, L{texts}, L{sounds}, L{fonts} types you can use the filename keyword to make a new datablock from a file.
|
||||
|
||||
New L{sounds}, L{fonts} can only be made with the a filename given.
|
||||
|
||||
The filename can a keyword or the second argument, use the keyword only for the datablocks new name to be set by the filename.
|
||||
|
||||
>>> sound = bpy.sounds.new('newsound', '~/mysound.wav') # uses the first string given for the name.
|
||||
|
||||
>>> sound = bpy.sounds.new(filename = '~/mysound.wav') # will use the filename to make the name.
|
||||
|
||||
Images
|
||||
======
|
||||
Images optionally accept extra 2 arguments for width and height, values between 4 and 5000 if no args are given they will be 256.
|
||||
|
||||
Images optionally accept 3 arguments: bpy.images.new(name, width=256, height=256)
|
||||
The width and height must br between 4 and 5000 if no args are given they will be 256.
|
||||
>>> img = bpy.images.new(name, 512, 512)
|
||||
|
||||
Ipos need 2 arguments: bpy.ipos.new(name, type) type must be a string (use in place of filename) can be...
|
||||
Curves
|
||||
======
|
||||
Curves need 2 arguments: bpy.curves.new(name, type) type must be one of the following...
|
||||
- 'Curve'
|
||||
- 'Text3d'
|
||||
|
||||
>>> text3d = bpy.curves.new('MyCurve', 'Text3d')
|
||||
|
||||
Ipos
|
||||
====
|
||||
Ipos need 2 arguments: bpy.ipos.new(name, type) type must be one of the following...
|
||||
- 'Camera'
|
||||
- 'World'
|
||||
- 'Material'
|
||||
@@ -247,7 +264,7 @@ class LibBlockSeq:
|
||||
|
||||
>>> scn = bpy.scenes.active
|
||||
... ob = scn.objects.new(bpy.meshes.new('mymesh'))
|
||||
|
||||
|
||||
@rtype: datablock
|
||||
"""
|
||||
|
||||
|
||||
@@ -741,6 +741,16 @@ def Text(string, fontsize = 'normal'):
|
||||
@note: For drawing text in the 3d view see the workaround in L{BGL.glRasterPos}
|
||||
"""
|
||||
|
||||
def Label(string, x, y, w, h):
|
||||
"""
|
||||
Draw a text lable on the screen.
|
||||
|
||||
@type string: string
|
||||
@param string: The text string to draw.
|
||||
@rtype: None
|
||||
@return: None
|
||||
"""
|
||||
|
||||
def Image(image, x, y, zoomx=1.0, zoomy=1.0, clipx=0, clipy=0, clipw=-1, cliph=-1):
|
||||
"""
|
||||
Draw an image on the screen.
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_main.h"
|
||||
#include "BKE_library.h"
|
||||
#include "BKE_curve.h"
|
||||
|
||||
/* GenericLib */
|
||||
#include "World.h"
|
||||
@@ -20,6 +21,7 @@
|
||||
#include "Armature.h"
|
||||
#include "Lamp.h"
|
||||
#include "Text.h"
|
||||
#include "Text3d.h"
|
||||
#include "Sound.h"
|
||||
#include "Scene.h"
|
||||
#include "Mesh.h"
|
||||
@@ -31,7 +33,6 @@
|
||||
#include "DNA_ipo_types.h"
|
||||
|
||||
|
||||
|
||||
/* Generic get/set attrs */
|
||||
PyObject *GenericLib_getName( void *self )
|
||||
{
|
||||
@@ -276,61 +277,47 @@ PyObject *GetPyObjectFromID( ID * id )
|
||||
switch ( MAKE_ID2( id->name[0], id->name[1] ) ) {
|
||||
case ID_SCE:
|
||||
return Scene_CreatePyObject( ( Scene *) id );
|
||||
break;
|
||||
case ID_OB:
|
||||
return Object_CreatePyObject( (Object *) id );
|
||||
break;
|
||||
case ID_ME:
|
||||
return Mesh_CreatePyObject( (Mesh *)id, NULL );
|
||||
break;
|
||||
case ID_CU: /*todo, support curnurbs?*/
|
||||
return Curve_CreatePyObject((Curve *)id);
|
||||
break;
|
||||
case ID_CU:
|
||||
switch (curve_type((Curve *)id)) {
|
||||
case OB_FONT:
|
||||
return Text3d_CreatePyObject( (Text3d *)id );
|
||||
default:
|
||||
return Curve_CreatePyObject( (Curve *)id );
|
||||
}
|
||||
case ID_MB:
|
||||
return Metaball_CreatePyObject((MetaBall *)id);
|
||||
break;
|
||||
case ID_MA:
|
||||
return Material_CreatePyObject((Material *)id);
|
||||
break;
|
||||
case ID_TE:
|
||||
return Texture_CreatePyObject((Tex *)id);
|
||||
break;
|
||||
case ID_IM:
|
||||
return Image_CreatePyObject((Image *)id);
|
||||
break;
|
||||
case ID_LT:
|
||||
return Lattice_CreatePyObject((Lattice *)id);
|
||||
break;
|
||||
case ID_LA:
|
||||
return Lamp_CreatePyObject((Lamp *)id);
|
||||
break;
|
||||
case ID_CA:
|
||||
return Camera_CreatePyObject((Camera *)id);
|
||||
break;
|
||||
case ID_IP:
|
||||
return Ipo_CreatePyObject((Ipo *)id);
|
||||
break;
|
||||
case ID_WO:
|
||||
return World_CreatePyObject((World *)id);
|
||||
break;
|
||||
case ID_VF:
|
||||
return Font_CreatePyObject((VFont *)id);
|
||||
break;
|
||||
case ID_TXT:
|
||||
return Text_CreatePyObject((Text *)id);
|
||||
break;
|
||||
case ID_SO:
|
||||
return Sound_CreatePyObject((bSound *)id);
|
||||
break;
|
||||
case ID_GR:
|
||||
return Group_CreatePyObject((Group *)id);
|
||||
break;
|
||||
case ID_AR:
|
||||
return Armature_CreatePyObject((bArmature *)id);
|
||||
break;
|
||||
case ID_AC:
|
||||
return Action_CreatePyObject((bAction *)id);
|
||||
break;
|
||||
}
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user