]> git.saurik.com Git - wxWidgets.git/blob - wxPython/contrib/ogl/ogl.i
fixes for rotated text
[wxWidgets.git] / wxPython / contrib / ogl / ogl.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: ogl.i
3 // Purpose: SWIG definitions for the wxWindows Object Graphics Library
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 30-June-1999
8 // RCS-ID: $Id$
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 %define DOCSTRING
14 "The Object Graphics Library provides for simple drawing and manipulation
15 of 2D objects."
16 %enddef
17 %module(docstring=DOCSTRING) ogl
18
19 %{
20 #include "wx/wxPython/wxPython.h"
21 #include "wx/wxPython/pyclasses.h"
22 #include "oglhelpers.h"
23
24 %}
25
26 //---------------------------------------------------------------------------
27
28 %import windows.i
29 %pythoncode { wx = _core }
30 %pythoncode { __docfilter__ = wx.__DocFilter(globals()) }
31
32
33 MAKE_CONST_WXSTRING_NOSWIG(EmptyString);
34
35 %include _ogl_rename.i
36
37 %include _ogldefs.i
38 %include _oglbasic.i
39 %include _oglshapes.i
40 %include _oglshapes2.i
41 %include _oglcanvas.i
42
43 %pythoncode {
44 %# Aliases
45 ShapeCanvas = PyShapeCanvas
46 ShapeEvtHandler = PyShapeEvtHandler
47 Shape = PyShape
48 RectangleShape = PyRectangleShape
49 BitmapShape = PyBitmapShape
50 DrawnShape = PyDrawnShape
51 CompositeShape = PyCompositeShape
52 DividedShape = PyDividedShape
53 DivisionShape = PyDivisionShape
54 EllipseShape = PyEllipseShape
55 CircleShape = PyCircleShape
56 LineShape = PyLineShape
57 PolygonShape = PyPolygonShape
58 TextShape = PyTextShape
59 ControlPoint = PyControlPoint
60 }
61
62
63 //---------------------------------------------------------------------------
64
65
66 enum {
67 KEY_SHIFT,
68 KEY_CTRL,
69 ARROW_NONE,
70 ARROW_END,
71 ARROW_BOTH,
72 ARROW_MIDDLE,
73 ARROW_START,
74 ARROW_HOLLOW_CIRCLE,
75 ARROW_FILLED_CIRCLE,
76 ARROW_ARROW,
77 ARROW_SINGLE_OBLIQUE,
78 ARROW_DOUBLE_OBLIQUE,
79 ARROW_METAFILE,
80 ARROW_POSITION_END,
81 ARROW_POSITION_START,
82 CONTROL_POINT_VERTICAL,
83 CONTROL_POINT_HORIZONTAL,
84 CONTROL_POINT_DIAGONAL,
85 CONTROL_POINT_ENDPOINT_TO,
86 CONTROL_POINT_ENDPOINT_FROM,
87 CONTROL_POINT_LINE,
88 FORMAT_NONE,
89 FORMAT_CENTRE_HORIZ,
90 FORMAT_CENTRE_VERT,
91 FORMAT_SIZE_TO_CONTENTS,
92 LINE_ALIGNMENT_HORIZ,
93 LINE_ALIGNMENT_VERT,
94 LINE_ALIGNMENT_TO_NEXT_HANDLE,
95 LINE_ALIGNMENT_NONE,
96 SHADOW_NONE,
97 SHADOW_LEFT,
98 SHADOW_RIGHT,
99 // SHAPE_BASIC,
100 // SHAPE_RECTANGLE,
101 // SHAPE_ELLIPSE,
102 // SHAPE_POLYGON,
103 // SHAPE_CIRCLE,
104 // SHAPE_LINE,
105 // SHAPE_DIVIDED_RECTANGLE,
106 // SHAPE_COMPOSITE,
107 // SHAPE_CONTROL_POINT,
108 // SHAPE_DRAWN,
109 // SHAPE_DIVISION,
110 // SHAPE_LABEL_OBJECT,
111 // SHAPE_BITMAP,
112 // SHAPE_DIVIDED_OBJECT_CONTROL_POINT,
113 // OBJECT_REGION,
114 OP_CLICK_LEFT,
115 OP_CLICK_RIGHT,
116 OP_DRAG_LEFT,
117 OP_DRAG_RIGHT,
118 OP_ALL,
119 ATTACHMENT_MODE_NONE,
120 ATTACHMENT_MODE_EDGE,
121 ATTACHMENT_MODE_BRANCHING,
122 BRANCHING_ATTACHMENT_NORMAL,
123 BRANCHING_ATTACHMENT_BLOB,
124
125 gyCONSTRAINT_CENTRED_VERTICALLY,
126 gyCONSTRAINT_CENTRED_HORIZONTALLY,
127 gyCONSTRAINT_CENTRED_BOTH,
128 gyCONSTRAINT_LEFT_OF,
129 gyCONSTRAINT_RIGHT_OF,
130 gyCONSTRAINT_ABOVE,
131 gyCONSTRAINT_BELOW,
132 gyCONSTRAINT_ALIGNED_TOP,
133 gyCONSTRAINT_ALIGNED_BOTTOM,
134 gyCONSTRAINT_ALIGNED_LEFT,
135 gyCONSTRAINT_ALIGNED_RIGHT,
136 gyCONSTRAINT_MIDALIGNED_TOP,
137 gyCONSTRAINT_MIDALIGNED_BOTTOM,
138 gyCONSTRAINT_MIDALIGNED_LEFT,
139 gyCONSTRAINT_MIDALIGNED_RIGHT,
140
141 DIVISION_SIDE_NONE,
142 DIVISION_SIDE_LEFT,
143 DIVISION_SIDE_TOP,
144 DIVISION_SIDE_RIGHT,
145 DIVISION_SIDE_BOTTOM,
146
147 };
148
149
150
151 //---------------------------------------------------------------------------
152
153 void wxOGLInitialize();
154 void wxOGLCleanUp();
155
156
157 %{
158 //---------------------------------------------------------------------------
159
160 // Convert from a Python list to a list of className objects. This one will
161 // work for any class for the VERY generic cases, but beyond that the helper
162 // needs to know more about the type.
163 wxList* wxPy_wxListHelper(PyObject* pyList, const wxChar* className) {
164 bool blocked = wxPyBeginBlockThreads();
165 if (!PyList_Check(pyList)) {
166 PyErr_SetString(PyExc_TypeError, "Expected a list object.");
167 wxPyEndBlockThreads(blocked);
168 return NULL;
169 }
170 int count = PyList_Size(pyList);
171 wxList* list = new wxList;
172 if (! list) {
173 PyErr_SetString(PyExc_MemoryError, "Unable to allocate wxList object");
174 wxPyEndBlockThreads(blocked);
175 return NULL;
176 }
177 for (int x=0; x<count; x++) {
178 PyObject* pyo = PyList_GetItem(pyList, x);
179 wxObject* wxo = NULL;
180
181 if ( !wxPyConvertSwigPtr(pyo, (void **)&wxo, className) ) {
182 wxString errmsg;
183 errmsg.Printf(wxT("Type error, expected list of %s objects"), className);
184 PyErr_SetString(PyExc_TypeError, errmsg.mb_str());
185 wxPyEndBlockThreads(blocked);
186 return NULL;
187 }
188 list->Append(wxo);
189 }
190 wxPyEndBlockThreads(blocked);
191 return list;
192 }
193
194 //---------------------------------------------------------------------------
195
196 wxList* wxPy_wxRealPoint_ListHelper(PyObject* pyList) {
197 bool blocked = wxPyBeginBlockThreads();
198 if (!PyList_Check(pyList)) {
199 PyErr_SetString(PyExc_TypeError, "Expected a list object.");
200 wxPyEndBlockThreads(blocked);
201 return NULL;
202 }
203 int count = PyList_Size(pyList);
204 wxList* list = new wxList;
205 if (! list) {
206 PyErr_SetString(PyExc_MemoryError, "Unable to allocate wxList object");
207 wxPyEndBlockThreads(blocked);
208 return NULL;
209 }
210 for (int x=0; x<count; x++) {
211 PyObject* pyo = PyList_GetItem(pyList, x);
212
213 if (PyTuple_Check(pyo)) {
214 PyObject* o1 = PyNumber_Float(PyTuple_GetItem(pyo, 0));
215 PyObject* o2 = PyNumber_Float(PyTuple_GetItem(pyo, 1));
216
217 double val1 = (o1 ? PyFloat_AsDouble(o1) : 0.0);
218 double val2 = (o2 ? PyFloat_AsDouble(o2) : 0.0);
219
220 list->Append((wxObject*) new wxRealPoint(val1, val2));
221
222 } else {
223 wxRealPoint* wxo = NULL;
224 if (wxPyConvertSwigPtr(pyo, (void **)&wxo, wxT("wxRealPoint"))) {
225 PyErr_SetString(PyExc_TypeError, "Type error, expected list of wxRealPoint objects or 2-tuples");
226 wxPyEndBlockThreads(blocked);
227 return NULL;
228 }
229 list->Append((wxObject*) new wxRealPoint(*wxo));
230 }
231 }
232 wxPyEndBlockThreads(blocked);
233 return list;
234 }
235
236 //---------------------------------------------------------------------------
237
238 PyObject* wxPyMake_wxShapeEvtHandler(wxShapeEvtHandler* source) {
239 PyObject* target = NULL;
240
241 if (source && wxIsKindOf(source, wxShapeEvtHandler)) {
242 // If it's derived from wxShapeEvtHandler then there may
243 // already be a pointer to a Python object that we can use
244 // in the OOR data.
245 wxShapeEvtHandler* seh = (wxShapeEvtHandler*)source;
246 wxPyOORClientData* data = (wxPyOORClientData*)seh->GetClientObject();
247 if (data) {
248 target = data->m_obj;
249 Py_INCREF(target);
250 }
251 }
252 if (! target) {
253 target = wxPyMake_wxObject2(source, FALSE);
254 if (target != Py_None)
255 ((wxShapeEvtHandler*)source)->SetClientObject(new wxPyOORClientData(target));
256 }
257 return target;
258 }
259
260 //---------------------------------------------------------------------------
261
262 PyObject* wxPy_ConvertRealPointList(wxListBase* listbase) {
263 wxList* list = (wxList*)listbase;
264 PyObject* pyList;
265 PyObject* pyObj;
266 wxObject* wxObj;
267 wxNode* node = list->GetFirst();
268
269 bool blocked = wxPyBeginBlockThreads();
270 pyList = PyList_New(0);
271 while (node) {
272 wxObj = node->GetData();
273 pyObj = wxPyConstructObject(wxObj, wxT("wxRealPoint"), 0);
274 PyList_Append(pyList, pyObj);
275 node = node->GetNext();
276 }
277 wxPyEndBlockThreads(blocked);
278 return pyList;
279 }
280
281 //---------------------------------------------------------------------------
282
283 PyObject* wxPy_ConvertShapeList(wxListBase* listbase) {
284 wxList* list = (wxList*)listbase;
285 PyObject* pyList;
286 PyObject* pyObj;
287 wxObject* wxObj;
288 wxNode* node = list->GetFirst();
289
290 bool blocked = wxPyBeginBlockThreads();
291 pyList = PyList_New(0);
292 while (node) {
293 wxObj = node->GetData();
294 pyObj = wxPyMake_wxShapeEvtHandler((wxShapeEvtHandler*)wxObj);
295 PyList_Append(pyList, pyObj);
296 node = node->GetNext();
297 }
298 wxPyEndBlockThreads(blocked);
299 return pyList;
300 }
301
302
303 //---------------------------------------------------------------------------
304
305 IMPLEMENT_DYNAMIC_CLASS(wxPyShapeCanvas, wxShapeCanvas);
306 IMPLEMENT_DYNAMIC_CLASS(wxPyShapeEvtHandler, wxShapeEvtHandler);
307 IMPLEMENT_ABSTRACT_CLASS(wxPyShape, wxShape);
308 IMPLEMENT_DYNAMIC_CLASS(wxPyRectangleShape, wxRectangleShape);
309 IMPLEMENT_DYNAMIC_CLASS(wxPyControlPoint, wxControlPoint);
310 IMPLEMENT_DYNAMIC_CLASS(wxPyBitmapShape, wxBitmapShape);
311 IMPLEMENT_DYNAMIC_CLASS(wxPyDrawnShape, wxDrawnShape);
312 IMPLEMENT_DYNAMIC_CLASS(wxPyCompositeShape, wxCompositeShape);
313 IMPLEMENT_DYNAMIC_CLASS(wxPyDividedShape, wxDividedShape);
314 IMPLEMENT_DYNAMIC_CLASS(wxPyDivisionShape, wxDivisionShape);
315 IMPLEMENT_DYNAMIC_CLASS(wxPyEllipseShape, wxEllipseShape);
316 IMPLEMENT_DYNAMIC_CLASS(wxPyCircleShape, wxCircleShape);
317 IMPLEMENT_DYNAMIC_CLASS(wxPyLineShape, wxLineShape);
318 IMPLEMENT_DYNAMIC_CLASS(wxPyPolygonShape, wxPolygonShape);
319 IMPLEMENT_DYNAMIC_CLASS(wxPyTextShape, wxTextShape);
320
321 //---------------------------------------------------------------------------
322
323 // extern "C" SWIGEXPORT(void) initoglbasicc();
324 // extern "C" SWIGEXPORT(void) initoglshapesc();
325 // extern "C" SWIGEXPORT(void) initoglshapes2c();
326 // extern "C" SWIGEXPORT(void) initoglcanvasc();
327 %}
328
329
330 %init %{
331
332 // initoglbasicc();
333 // initoglshapesc();
334 // initoglshapes2c();
335 // initoglcanvasc();
336
337
338 wxPyPtrTypeMap_Add("wxControlPoint", "wxPyControlPoint");
339 wxPyPtrTypeMap_Add("wxShapeCanvas", "wxPyShapeCanvas");
340 wxPyPtrTypeMap_Add("wxShapeEvtHandler", "wxPyShapeEvtHandler");
341 wxPyPtrTypeMap_Add("wxShape", "wxPyShape");
342 wxPyPtrTypeMap_Add("wxRectangleShape", "wxPyRectangleShape");
343 wxPyPtrTypeMap_Add("wxDrawnShape", "wxPyDrawnShape");
344 wxPyPtrTypeMap_Add("wxCompositeShape", "wxPyCompositeShape");
345 wxPyPtrTypeMap_Add("wxDividedShape", "wxPyDividedShape");
346 wxPyPtrTypeMap_Add("wxDivisionShape", "wxPyDivisionShape");
347 wxPyPtrTypeMap_Add("wxEllipseShape", "wxPyEllipseShape");
348 wxPyPtrTypeMap_Add("wxCircleShape", "wxPyCircleShape");
349 wxPyPtrTypeMap_Add("wxLineShape", "wxPyLineShape");
350 wxPyPtrTypeMap_Add("wxPolygonShape", "wxPyPolygonShape");
351 wxPyPtrTypeMap_Add("wxTextShape", "wxPyTextShape");
352
353 %}
354
355 //---------------------------------------------------------------------------
356 //---------------------------------------------------------------------------