]>
Commit | Line | Data |
---|---|---|
e91a9dfc RD |
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 | ||
c8fac2b6 RD |
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 | |
e91a9dfc RD |
18 | |
19 | %{ | |
d14a1e28 RD |
20 | #include "wx/wxPython/wxPython.h" |
21 | #include "wx/wxPython/pyclasses.h" | |
e91a9dfc | 22 | #include "oglhelpers.h" |
d14a1e28 | 23 | |
e91a9dfc RD |
24 | %} |
25 | ||
26 | //--------------------------------------------------------------------------- | |
27 | ||
e91a9dfc | 28 | %import windows.i |
54f9ee45 | 29 | %pythoncode { wx = _core } |
99109c0f | 30 | %pythoncode { __docfilter__ = wx.__DocFilter(globals()) } |
e91a9dfc | 31 | |
b2dc1044 RD |
32 | |
33 | MAKE_CONST_WXSTRING_NOSWIG(EmptyString); | |
34 | ||
d14a1e28 | 35 | %include _ogl_rename.i |
e91a9dfc | 36 | |
d14a1e28 RD |
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 | } | |
e91a9dfc | 61 | |
e91a9dfc RD |
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 | ||
1e7ecb7b | 157 | %{ |
e91a9dfc | 158 | //--------------------------------------------------------------------------- |
1e7ecb7b | 159 | |
d14a1e28 RD |
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) { | |
da32eb53 | 164 | bool blocked = wxPyBeginBlockThreads(); |
1e7ecb7b RD |
165 | if (!PyList_Check(pyList)) { |
166 | PyErr_SetString(PyExc_TypeError, "Expected a list object."); | |
da32eb53 | 167 | wxPyEndBlockThreads(blocked); |
1e7ecb7b RD |
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"); | |
da32eb53 | 174 | wxPyEndBlockThreads(blocked); |
1e7ecb7b RD |
175 | return NULL; |
176 | } | |
177 | for (int x=0; x<count; x++) { | |
178 | PyObject* pyo = PyList_GetItem(pyList, x); | |
179 | wxObject* wxo = NULL; | |
180 | ||
d14a1e28 RD |
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()); | |
da32eb53 | 185 | wxPyEndBlockThreads(blocked); |
1e7ecb7b RD |
186 | return NULL; |
187 | } | |
188 | list->Append(wxo); | |
189 | } | |
da32eb53 | 190 | wxPyEndBlockThreads(blocked); |
1e7ecb7b RD |
191 | return list; |
192 | } | |
193 | ||
e91a9dfc | 194 | //--------------------------------------------------------------------------- |
1e7ecb7b RD |
195 | |
196 | wxList* wxPy_wxRealPoint_ListHelper(PyObject* pyList) { | |
da32eb53 | 197 | bool blocked = wxPyBeginBlockThreads(); |
1e7ecb7b RD |
198 | if (!PyList_Check(pyList)) { |
199 | PyErr_SetString(PyExc_TypeError, "Expected a list object."); | |
da32eb53 | 200 | wxPyEndBlockThreads(blocked); |
1e7ecb7b RD |
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"); | |
da32eb53 | 207 | wxPyEndBlockThreads(blocked); |
1e7ecb7b RD |
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; | |
d14a1e28 | 224 | if (wxPyConvertSwigPtr(pyo, (void **)&wxo, wxT("wxRealPoint"))) { |
1e7ecb7b | 225 | PyErr_SetString(PyExc_TypeError, "Type error, expected list of wxRealPoint objects or 2-tuples"); |
da32eb53 | 226 | wxPyEndBlockThreads(blocked); |
1e7ecb7b RD |
227 | return NULL; |
228 | } | |
229 | list->Append((wxObject*) new wxRealPoint(*wxo)); | |
230 | } | |
231 | } | |
da32eb53 | 232 | wxPyEndBlockThreads(blocked); |
1e7ecb7b RD |
233 | return list; |
234 | } | |
235 | ||
2f4e9287 RD |
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; | |
4acff284 | 246 | wxPyOORClientData* data = (wxPyOORClientData*)seh->GetClientObject(); |
2f4e9287 RD |
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) | |
4acff284 | 255 | ((wxShapeEvtHandler*)source)->SetClientObject(new wxPyOORClientData(target)); |
2f4e9287 RD |
256 | } |
257 | return target; | |
258 | } | |
259 | ||
c893f25d RD |
260 | //--------------------------------------------------------------------------- |
261 | ||
d68a6b6d RD |
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; | |
1ce56f78 RD |
279 | } |
280 | ||
281 | //--------------------------------------------------------------------------- | |
282 | ||
d14a1e28 | 283 | PyObject* wxPy_ConvertShapeList(wxListBase* listbase) { |
26b8693b | 284 | wxList* list = (wxList*)listbase; |
c893f25d RD |
285 | PyObject* pyList; |
286 | PyObject* pyObj; | |
287 | wxObject* wxObj; | |
26b8693b | 288 | wxNode* node = list->GetFirst(); |
c893f25d | 289 | |
da32eb53 | 290 | bool blocked = wxPyBeginBlockThreads(); |
c893f25d RD |
291 | pyList = PyList_New(0); |
292 | while (node) { | |
26b8693b | 293 | wxObj = node->GetData(); |
c893f25d RD |
294 | pyObj = wxPyMake_wxShapeEvtHandler((wxShapeEvtHandler*)wxObj); |
295 | PyList_Append(pyList, pyObj); | |
26b8693b | 296 | node = node->GetNext(); |
c893f25d | 297 | } |
da32eb53 | 298 | wxPyEndBlockThreads(blocked); |
c893f25d RD |
299 | return pyList; |
300 | } | |
2f4e9287 | 301 | |
1e7ecb7b | 302 | |
e91a9dfc | 303 | //--------------------------------------------------------------------------- |
1e7ecb7b | 304 | |
9416aa89 RD |
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 | //--------------------------------------------------------------------------- | |
1e7ecb7b | 322 | |
d14a1e28 RD |
323 | // extern "C" SWIGEXPORT(void) initoglbasicc(); |
324 | // extern "C" SWIGEXPORT(void) initoglshapesc(); | |
325 | // extern "C" SWIGEXPORT(void) initoglshapes2c(); | |
326 | // extern "C" SWIGEXPORT(void) initoglcanvasc(); | |
e91a9dfc RD |
327 | %} |
328 | ||
389c5527 | 329 | |
e91a9dfc RD |
330 | %init %{ |
331 | ||
d14a1e28 RD |
332 | // initoglbasicc(); |
333 | // initoglshapesc(); | |
334 | // initoglshapes2c(); | |
335 | // initoglcanvasc(); | |
e91a9dfc RD |
336 | |
337 | ||
856e03b7 RD |
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 | ||
e91a9dfc RD |
353 | %} |
354 | ||
e91a9dfc RD |
355 | //--------------------------------------------------------------------------- |
356 | //--------------------------------------------------------------------------- |