]>
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 bool blocked
= 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(blocked
);
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
);
212 //---------------------------------------------------------------------------
216 PyObject
* wxPyDrawTextList(wxDC
& dc
, PyObject
* textList
, PyObject
* pyPoints
, PyObject
* foregroundList
, PyObject
* backgroundList
)
218 bool blocked
= wxPyBeginBlockThreads();
220 bool isFastSeq
= PyList_Check(pyPoints
) || PyTuple_Check(pyPoints
);
221 bool isFastText
= PyList_Check(textList
) || PyTuple_Check(textList
);
222 bool isFastForeground
= PyList_Check(foregroundList
) || PyTuple_Check(foregroundList
);
223 bool isFastBackground
= PyList_Check(backgroundList
) || PyTuple_Check(backgroundList
);
226 int numForeground
= 0;
227 int numBackground
= 0;
235 if (!PySequence_Check(pyPoints
)) {
238 if (!PySequence_Check(textList
)) {
241 if (!PySequence_Check(foregroundList
)) {
244 if (!PySequence_Check(backgroundList
)) {
247 numPoints
= PySequence_Length(pyPoints
);
248 numText
= PySequence_Length(textList
);
249 numForeground
= PySequence_Length(foregroundList
);
250 numBackground
= PySequence_Length(backgroundList
);
252 for (i
= 0; i
< numPoints
; i
++) {
253 // Use a new string ?
256 obj
= PySequence_Fast_GET_ITEM(textList
, i
);
259 obj
= PySequence_GetItem(textList
, i
);
261 if (! PyString_Check(obj
) ) {
265 string
= Py2wxString(obj
);
270 if (i
< numForeground
) {
271 // Use a new foreground ?
272 if ( isFastForeground
) {
273 obj
= PySequence_Fast_GET_ITEM(foregroundList
, i
);
276 obj
= PySequence_GetItem(foregroundList
, i
);
278 if (! wxPyConvertSwigPtr(obj
, (void **) &color
, wxT("wxColour"))) {
279 if (!isFastForeground
)
283 dc
.SetTextForeground(*color
);
284 if ( !isFastForeground
)
288 if (i
< numBackground
) {
289 // Use a new background ?
290 if ( isFastBackground
) {
291 obj
= PySequence_Fast_GET_ITEM(backgroundList
, i
);
294 obj
= PySequence_GetItem(backgroundList
, i
);
296 if (! wxPyConvertSwigPtr(obj
, (void **) &color
, wxT("wxColour"))) {
297 if (!isFastBackground
)
301 dc
.SetTextBackground(*color
);
302 if ( !isFastBackground
)
306 // Get the point coordinates
308 obj
= PySequence_Fast_GET_ITEM(pyPoints
, i
);
311 obj
= PySequence_GetItem(pyPoints
, i
);
313 if (! wxPy2int_seq_helper(obj
, &x1
, &y1
)) {
318 if (PyErr_Occurred()) {
327 dc
.DrawText(string
, x1
, y1
);
338 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of (x,y) sequences.");
342 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of strings");
347 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of wxColours for foregrounds");
352 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of wxColours for backgrounds");
357 wxPyEndBlockThreads(blocked
);
363 //---------------------------------------------------------------------------