]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/src/drawlist.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Helper functions for optimized list drawing on a wxDC
5 // Author: Robin Dunn, Chris Barker
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
16 #include "wx/wxPython/wxPython.h"
17 #include "wx/wxPython/pydrawxxx.h"
20 //---------------------------------------------------------------------------
23 // Called from _gdiinit so we can do the API import while the GIL is held
24 void wxPyDrawList_SetAPIPtr()
30 PyObject
* wxPyDrawXXXList(wxDC
& dc
, wxPyDrawListOp_t doDraw
,
31 PyObject
* pyCoords
, PyObject
* pyPens
, PyObject
* pyBrushes
)
33 wxPyBeginBlockThreads();
35 bool isFastSeq
= PyList_Check(pyCoords
) || PyTuple_Check(pyCoords
);
36 bool isFastPens
= PyList_Check(pyPens
) || PyTuple_Check(pyPens
);
37 bool isFastBrushes
= PyList_Check(pyBrushes
) || PyTuple_Check(pyBrushes
);
48 if (!PySequence_Check(pyCoords
)) {
51 if (!PySequence_Check(pyPens
)) {
54 if (!PySequence_Check(pyBrushes
)) {
57 numObjs
= PySequence_Length(pyCoords
);
58 numPens
= PySequence_Length(pyPens
);
59 numBrushes
= PySequence_Length(pyBrushes
);
60 for (i
= 0; i
< numObjs
; i
++) {
64 obj
= PySequence_Fast_GET_ITEM(pyPens
, i
);
67 obj
= PySequence_GetItem(pyPens
, i
);
69 if (! wxPyConvertSwigPtr(obj
, (void **) &pen
, wxT("wxPen"))) {
82 obj
= PySequence_Fast_GET_ITEM(pyBrushes
, i
);
85 obj
= PySequence_GetItem(pyBrushes
, i
);
87 if (!wxPyConvertSwigPtr(obj
, (void **) &brush
, wxT("wxBrush"))) {
98 // Get the Coordinates
100 coords
= PySequence_Fast_GET_ITEM(pyCoords
, i
);
103 coords
= PySequence_GetItem(pyCoords
, i
);
108 bool success
= doDraw(dc
, coords
);
117 } // end of main for loop
125 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of coordinates");
130 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of wxPens");
135 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of wxBrushes");
141 wxPyEndBlockThreads();
147 bool wxPyDrawXXXPoint(wxDC
& dc
, PyObject
* coords
)
151 if (! wxPy2int_seq_helper(coords
, &x
, &y
)) {
152 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of (x,y) sequences.");
159 bool wxPyDrawXXXLine(wxDC
& dc
, PyObject
* coords
)
163 if (! wxPy4int_seq_helper(coords
, &x1
, &y1
, &x2
, &y2
)) {
164 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of (x1,y1, x1,y2) sequences.");
167 dc
.DrawLine(x1
,y1
, x2
,y2
);
171 bool wxPyDrawXXXRectangle(wxDC
& dc
, PyObject
* coords
)
175 if (! wxPy4int_seq_helper(coords
, &x
, &y
, &w
, &h
)) {
176 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of (x,y, w,h) sequences.");
179 dc
.DrawRectangle(x
, y
, w
, h
);
183 bool wxPyDrawXXXEllipse(wxDC
& dc
, PyObject
* coords
)
187 if (! wxPy4int_seq_helper(coords
, &x
, &y
, &w
, &h
)) {
188 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of (x,y, w,h) sequences.");
191 dc
.DrawEllipse(x
, y
, w
, h
);
196 bool wxPyDrawXXXPolygon(wxDC
& dc
, PyObject
* coords
)
201 points
= wxPoint_LIST_helper(coords
, &numPoints
);
203 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of sequences of (x,y) sequences.");
206 dc
.DrawPolygon(numPoints
, points
);
211 //---------------------------------------------------------------------------
215 PyObject
* wxPyDrawTextList(wxDC
& dc
, PyObject
* textList
, PyObject
* pyPoints
, PyObject
* foregroundList
, PyObject
* backgroundList
)
217 wxPyBeginBlockThreads();
219 bool isFastSeq
= PyList_Check(pyPoints
) || PyTuple_Check(pyPoints
);
220 bool isFastText
= PyList_Check(textList
) || PyTuple_Check(textList
);
221 bool isFastForeground
= PyList_Check(foregroundList
) || PyTuple_Check(foregroundList
);
222 bool isFastBackground
= PyList_Check(backgroundList
) || PyTuple_Check(backgroundList
);
225 int numForeground
= 0;
226 int numBackground
= 0;
234 if (!PySequence_Check(pyPoints
)) {
237 if (!PySequence_Check(textList
)) {
240 if (!PySequence_Check(foregroundList
)) {
243 if (!PySequence_Check(backgroundList
)) {
246 numPoints
= PySequence_Length(pyPoints
);
247 numText
= PySequence_Length(textList
);
248 numForeground
= PySequence_Length(foregroundList
);
249 numBackground
= PySequence_Length(backgroundList
);
251 for (i
= 0; i
< numPoints
; i
++) {
252 // Use a new string ?
255 obj
= PySequence_Fast_GET_ITEM(textList
, i
);
258 obj
= PySequence_GetItem(textList
, i
);
260 if (! PyString_Check(obj
) ) {
264 string
= Py2wxString(obj
);
269 if (i
< numForeground
) {
270 // Use a new foreground ?
271 if ( isFastForeground
) {
272 obj
= PySequence_Fast_GET_ITEM(foregroundList
, i
);
275 obj
= PySequence_GetItem(foregroundList
, i
);
277 if (! wxPyConvertSwigPtr(obj
, (void **) &color
, wxT("wxColour"))) {
278 if (!isFastForeground
)
282 dc
.SetTextForeground(*color
);
283 if ( !isFastForeground
)
287 if (i
< numBackground
) {
288 // Use a new background ?
289 if ( isFastBackground
) {
290 obj
= PySequence_Fast_GET_ITEM(backgroundList
, i
);
293 obj
= PySequence_GetItem(backgroundList
, i
);
295 if (! wxPyConvertSwigPtr(obj
, (void **) &color
, wxT("wxColour"))) {
296 if (!isFastBackground
)
300 dc
.SetTextBackground(*color
);
301 if ( !isFastBackground
)
305 // Get the point coordinates
307 obj
= PySequence_Fast_GET_ITEM(pyPoints
, i
);
310 obj
= PySequence_GetItem(pyPoints
, i
);
312 if (! wxPy2int_seq_helper(obj
, &x1
, &y1
)) {
317 if (PyErr_Occurred()) {
326 dc
.DrawText(string
, x1
, y1
);
337 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of (x,y) sequences.");
341 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of strings");
346 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of wxColours for foregrounds");
351 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of wxColours for backgrounds");
356 wxPyEndBlockThreads();
362 //---------------------------------------------------------------------------