]>
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
);
42 if (!PySequence_Check(pyCoords
)) {
45 if (!PySequence_Check(pyPens
)) {
48 if (!PySequence_Check(pyBrushes
)) {
51 numObjs
= PySequence_Length(pyCoords
);
52 numPens
= PySequence_Length(pyPens
);
53 numBrushes
= PySequence_Length(pyBrushes
);
54 for (i
= 0; i
< numObjs
; i
++) {
58 obj
= PySequence_Fast_GET_ITEM(pyPens
, i
);
61 obj
= PySequence_GetItem(pyPens
, i
);
63 if (SWIG_GetPtrObj(obj
, (void **) &pen
, "_wxPen_p")) {
76 obj
= PySequence_Fast_GET_ITEM(pyBrushes
, i
);
79 obj
= PySequence_GetItem(pyBrushes
, i
);
81 if (SWIG_GetPtrObj(obj
, (void **) &brush
, "_wxBrush_p")) {
92 // Get the Coordinates
94 coords
= PySequence_Fast_GET_ITEM(pyCoords
, i
);
97 coords
= PySequence_GetItem(pyCoords
, i
);
102 bool success
= doDraw(dc
, coords
);
111 } // end of main for loop
119 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of coordinates");
124 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of wxPens");
129 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of wxBrushes");
135 wxPyEndBlockThreads();
141 bool wxPyDrawXXXPoint(wxDC
& dc
, PyObject
* coords
) {
144 if (! wxPy2int_seq_helper(coords
, &x
, &y
)) {
145 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of (x,y) sequences.");
152 bool wxPyDrawXXXLine(wxDC
& dc
, PyObject
* coords
) {
155 if (! wxPy4int_seq_helper(coords
, &x1
, &y1
, &x2
, &y2
)) {
156 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of (x1,y1, x1,y2) sequences.");
159 dc
.DrawLine(x1
,y1
, x2
,y2
);
163 bool wxPyDrawXXXRectangle(wxDC
& dc
, PyObject
* coords
) {
166 if (! wxPy4int_seq_helper(coords
, &x
, &y
, &w
, &h
)) {
167 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of (x,y, w,h) sequences.");
170 dc
.DrawRectangle(x
, y
, w
, h
);
174 bool wxPyDrawXXXEllipse(wxDC
& dc
, PyObject
* coords
) {
177 if (! wxPy4int_seq_helper(coords
, &x
, &y
, &w
, &h
)) {
178 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of (x,y, w,h) sequences.");
181 dc
.DrawEllipse(x
, y
, w
, h
);
186 bool wxPyDrawXXXPolygon(wxDC
& dc
, PyObject
* coords
) {
190 points
= wxPoint_LIST_helper(coords
, &numPoints
);
192 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of sequences of (x,y) sequences.");
195 dc
.DrawPolygon(numPoints
, points
);
200 //----------------------------------------------------------------------
204 PyObject
* wxPyDrawTextList(wxDC
& dc
, PyObject
* textList
, PyObject
* pyPoints
, PyObject
* foregroundList
, PyObject
* backgroundList
) {
205 wxPyBeginBlockThreads();
207 bool isFastSeq
= PyList_Check(pyPoints
) || PyTuple_Check(pyPoints
);
208 bool isFastText
= PyList_Check(textList
) || PyTuple_Check(textList
);
209 bool isFastForeground
= PyList_Check(foregroundList
) || PyTuple_Check(foregroundList
);
210 bool isFastBackground
= PyList_Check(backgroundList
) || PyTuple_Check(backgroundList
);
213 int numForeground
= 0;
214 int numBackground
= 0;
222 if (!PySequence_Check(pyPoints
)) {
225 if (!PySequence_Check(textList
)) {
228 if (!PySequence_Check(foregroundList
)) {
231 if (!PySequence_Check(backgroundList
)) {
234 numPoints
= PySequence_Length(pyPoints
);
235 numText
= PySequence_Length(textList
);
236 numForeground
= PySequence_Length(foregroundList
);
237 numBackground
= PySequence_Length(backgroundList
);
239 for (i
= 0; i
< numPoints
; i
++) {
240 // Use a new string ?
243 obj
= PySequence_Fast_GET_ITEM(textList
, i
);
246 obj
= PySequence_GetItem(textList
, i
);
248 if (! PyString_Check(obj
) ) {
252 string
= Py2wxString(obj
);
257 if (i
< numForeground
) {
258 // Use a new foreground ?
259 if ( isFastForeground
) {
260 obj
= PySequence_Fast_GET_ITEM(foregroundList
, i
);
263 obj
= PySequence_GetItem(foregroundList
, i
);
265 if (SWIG_GetPtrObj(obj
, (void **) &color
, "_wxColour_p")) {
266 if (!isFastForeground
)
270 dc
.SetTextForeground(*color
);
271 if ( !isFastForeground
)
275 if (i
< numBackground
) {
276 // Use a new background ?
277 if ( isFastBackground
) {
278 obj
= PySequence_Fast_GET_ITEM(backgroundList
, i
);
281 obj
= PySequence_GetItem(backgroundList
, i
);
283 if (SWIG_GetPtrObj(obj
, (void **) &color
, "_wxColour_p")) {
284 if (!isFastBackground
)
288 dc
.SetTextBackground(*color
);
289 if ( !isFastBackground
)
293 // Get the point coordinates
295 obj
= PySequence_Fast_GET_ITEM(pyPoints
, i
);
298 obj
= PySequence_GetItem(pyPoints
, i
);
300 if (! wxPy2int_seq_helper(obj
, &x1
, &y1
)) {
305 if (PyErr_Occurred()) {
314 dc
.DrawText(string
, x1
, y1
);
325 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of (x,y) sequences.");
329 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of strings");
334 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of wxColours for foregrounds");
339 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of wxColours for backgrounds");
344 wxPyEndBlockThreads();
350 //----------------------------------------------------------------------