]>
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 /////////////////////////////////////////////////////////////////////////////
19 //----------------------------------------------------------------------
23 PyObject
* wxPyDrawXXXList(wxDC
& dc
, wxPyDrawListOp_t doDraw
,
24 PyObject
* pyCoords
, PyObject
* pyPens
, PyObject
* pyBrushes
) {
26 wxPyBeginBlockThreads(); // _DrawXXXList
28 bool isFastSeq
= PyList_Check(pyCoords
) || PyTuple_Check(pyCoords
);
29 bool isFastPens
= PyList_Check(pyPens
) || PyTuple_Check(pyPens
);
30 bool isFastBrushes
= PyList_Check(pyBrushes
) || PyTuple_Check(pyBrushes
);
41 if (!PySequence_Check(pyCoords
)) {
44 if (!PySequence_Check(pyPens
)) {
47 if (!PySequence_Check(pyBrushes
)) {
50 numObjs
= PySequence_Length(pyCoords
);
51 numPens
= PySequence_Length(pyPens
);
52 numBrushes
= PySequence_Length(pyBrushes
);
53 for (i
= 0; i
< numObjs
; i
++) {
57 obj
= PySequence_Fast_GET_ITEM(pyPens
, i
);
60 obj
= PySequence_GetItem(pyPens
, i
);
62 if (SWIG_GetPtrObj(obj
, (void **) &pen
, "_wxPen_p")) {
75 obj
= PySequence_Fast_GET_ITEM(pyBrushes
, i
);
78 obj
= PySequence_GetItem(pyBrushes
, i
);
80 if (SWIG_GetPtrObj(obj
, (void **) &brush
, "_wxBrush_p")) {
91 // Get the Coordinates
93 coords
= PySequence_Fast_GET_ITEM(pyCoords
, i
);
96 coords
= PySequence_GetItem(pyCoords
, i
);
101 bool success
= doDraw(dc
, coords
);
110 } // end of main for loop
118 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of coordinates");
123 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of wxPens");
128 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of wxBrushes");
134 wxPyEndBlockThreads();
140 bool wxPyDrawXXXPoint(wxDC
& dc
, PyObject
* coords
) {
143 if (! wxPy2int_seq_helper(coords
, &x
, &y
)) {
144 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of (x,y) sequences.");
151 bool wxPyDrawXXXLine(wxDC
& dc
, PyObject
* coords
) {
154 if (! wxPy4int_seq_helper(coords
, &x1
, &y1
, &x2
, &y2
)) {
155 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of (x1,y1, x1,y2) sequences.");
158 dc
.DrawLine(x1
,y1
, x2
,y2
);
162 bool wxPyDrawXXXRectangle(wxDC
& dc
, PyObject
* coords
) {
165 if (! wxPy4int_seq_helper(coords
, &x
, &y
, &w
, &h
)) {
166 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of (x,y, w,h) sequences.");
169 dc
.DrawRectangle(x
, y
, w
, h
);
173 bool wxPyDrawXXXEllipse(wxDC
& dc
, PyObject
* coords
) {
176 if (! wxPy4int_seq_helper(coords
, &x
, &y
, &w
, &h
)) {
177 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of (x,y, w,h) sequences.");
180 dc
.DrawEllipse(x
, y
, w
, h
);
185 bool wxPyDrawXXXPolygon(wxDC
& dc
, PyObject
* coords
) {
189 points
= wxPoint_LIST_helper(coords
, &numPoints
);
191 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of sequences of (x,y) sequences.");
194 dc
.DrawPolygon(numPoints
, points
);
199 //----------------------------------------------------------------------
203 PyObject
* wxPyDrawTextList(wxDC
& dc
, PyObject
* textList
, PyObject
* pyPoints
, PyObject
* foregroundList
, PyObject
* backgroundList
) {
204 wxPyBeginBlockThreads();
206 bool isFastSeq
= PyList_Check(pyPoints
) || PyTuple_Check(pyPoints
);
207 bool isFastText
= PyList_Check(textList
) || PyTuple_Check(textList
);
208 bool isFastForeground
= PyList_Check(foregroundList
) || PyTuple_Check(foregroundList
);
209 bool isFastBackground
= PyList_Check(backgroundList
) || PyTuple_Check(backgroundList
);
212 int numForeground
= 0;
213 int numBackground
= 0;
221 if (!PySequence_Check(pyPoints
)) {
224 if (!PySequence_Check(textList
)) {
227 if (!PySequence_Check(foregroundList
)) {
230 if (!PySequence_Check(backgroundList
)) {
233 numPoints
= PySequence_Length(pyPoints
);
234 numText
= PySequence_Length(textList
);
235 numForeground
= PySequence_Length(foregroundList
);
236 numBackground
= PySequence_Length(backgroundList
);
238 for (i
= 0; i
< numPoints
; i
++) {
239 // Use a new string ?
242 obj
= PySequence_Fast_GET_ITEM(textList
, i
);
245 obj
= PySequence_GetItem(textList
, i
);
247 if (! PyString_Check(obj
) ) {
251 string
= Py2wxString(obj
);
256 if (i
< numForeground
) {
257 // Use a new foreground ?
258 if ( isFastForeground
) {
259 obj
= PySequence_Fast_GET_ITEM(foregroundList
, i
);
262 obj
= PySequence_GetItem(foregroundList
, i
);
264 if (SWIG_GetPtrObj(obj
, (void **) &color
, "_wxColour_p")) {
265 if (!isFastForeground
)
269 dc
.SetTextForeground(*color
);
270 if ( !isFastForeground
)
274 if (i
< numBackground
) {
275 // Use a new background ?
276 if ( isFastBackground
) {
277 obj
= PySequence_Fast_GET_ITEM(backgroundList
, i
);
280 obj
= PySequence_GetItem(backgroundList
, i
);
282 if (SWIG_GetPtrObj(obj
, (void **) &color
, "_wxColour_p")) {
283 if (!isFastBackground
)
287 dc
.SetTextBackground(*color
);
288 if ( !isFastBackground
)
292 // Get the point coordinates
294 obj
= PySequence_Fast_GET_ITEM(pyPoints
, i
);
297 obj
= PySequence_GetItem(pyPoints
, i
);
299 if (! wxPy2int_seq_helper(obj
, &x1
, &y1
)) {
304 if (PyErr_Occurred()) {
313 dc
.DrawText(string
, x1
, y1
);
324 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of (x,y) sequences.");
328 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of strings");
333 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of wxColours for foregrounds");
338 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of wxColours for backgrounds");
343 wxPyEndBlockThreads();
349 //----------------------------------------------------------------------