]>
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 //----------------------------------------------------------------------
24 PyObject
* wxPyDrawXXXList(wxDC
& dc
, wxPyDrawListOp_t doDraw
,
25 PyObject
* pyCoords
, PyObject
* pyPens
, PyObject
* pyBrushes
) {
27 wxPyBeginBlockThreads();
32 bool isFastSeq
= PyList_Check(pyCoords
) || PyTuple_Check(pyCoords
);
33 bool isFastPens
= PyList_Check(pyPens
) || PyTuple_Check(pyPens
);
34 bool isFastBrushes
= PyList_Check(pyBrushes
) || PyTuple_Check(pyBrushes
);
45 if (!PySequence_Check(pyCoords
)) {
48 if (!PySequence_Check(pyPens
)) {
51 if (!PySequence_Check(pyBrushes
)) {
54 numObjs
= PySequence_Length(pyCoords
);
55 numPens
= PySequence_Length(pyPens
);
56 numBrushes
= PySequence_Length(pyBrushes
);
57 for (i
= 0; i
< numObjs
; i
++) {
61 obj
= PySequence_Fast_GET_ITEM(pyPens
, i
);
64 obj
= PySequence_GetItem(pyPens
, i
);
66 if (! wxPyConvertSwigPtr(obj
, (void **) &pen
, wxT("wxPen"))) {
79 obj
= PySequence_Fast_GET_ITEM(pyBrushes
, i
);
82 obj
= PySequence_GetItem(pyBrushes
, i
);
84 if (!wxPyConvertSwigPtr(obj
, (void **) &brush
, wxT("wxBrush"))) {
95 // Get the Coordinates
97 coords
= PySequence_Fast_GET_ITEM(pyCoords
, i
);
100 coords
= PySequence_GetItem(pyCoords
, i
);
105 bool success
= doDraw(dc
, coords
);
114 } // end of main for loop
122 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of coordinates");
127 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of wxPens");
132 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of wxBrushes");
138 wxPyEndBlockThreads();
144 bool wxPyDrawXXXPoint(wxDC
& dc
, PyObject
* coords
) {
147 if (! wxPy2int_seq_helper(coords
, &x
, &y
)) {
148 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of (x,y) sequences.");
155 bool wxPyDrawXXXLine(wxDC
& dc
, PyObject
* coords
) {
158 if (! wxPy4int_seq_helper(coords
, &x1
, &y1
, &x2
, &y2
)) {
159 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of (x1,y1, x1,y2) sequences.");
162 dc
.DrawLine(x1
,y1
, x2
,y2
);
166 bool wxPyDrawXXXRectangle(wxDC
& dc
, PyObject
* coords
) {
169 if (! wxPy4int_seq_helper(coords
, &x
, &y
, &w
, &h
)) {
170 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of (x,y, w,h) sequences.");
173 dc
.DrawRectangle(x
, y
, w
, h
);
177 bool wxPyDrawXXXEllipse(wxDC
& dc
, PyObject
* coords
) {
180 if (! wxPy4int_seq_helper(coords
, &x
, &y
, &w
, &h
)) {
181 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of (x,y, w,h) sequences.");
184 dc
.DrawEllipse(x
, y
, w
, h
);
189 bool wxPyDrawXXXPolygon(wxDC
& dc
, PyObject
* coords
) {
193 points
= wxPoint_LIST_helper(coords
, &numPoints
);
195 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of sequences of (x,y) sequences.");
198 dc
.DrawPolygon(numPoints
, points
);
203 //----------------------------------------------------------------------
207 PyObject
* wxPyDrawTextList(wxDC
& dc
, PyObject
* textList
, PyObject
* pyPoints
, PyObject
* foregroundList
, PyObject
* backgroundList
) {
208 wxPyBeginBlockThreads();
210 if ( !wxPyCoreAPIPtr
)
211 wxPyCoreAPI_IMPORT();
213 bool isFastSeq
= PyList_Check(pyPoints
) || PyTuple_Check(pyPoints
);
214 bool isFastText
= PyList_Check(textList
) || PyTuple_Check(textList
);
215 bool isFastForeground
= PyList_Check(foregroundList
) || PyTuple_Check(foregroundList
);
216 bool isFastBackground
= PyList_Check(backgroundList
) || PyTuple_Check(backgroundList
);
219 int numForeground
= 0;
220 int numBackground
= 0;
228 if (!PySequence_Check(pyPoints
)) {
231 if (!PySequence_Check(textList
)) {
234 if (!PySequence_Check(foregroundList
)) {
237 if (!PySequence_Check(backgroundList
)) {
240 numPoints
= PySequence_Length(pyPoints
);
241 numText
= PySequence_Length(textList
);
242 numForeground
= PySequence_Length(foregroundList
);
243 numBackground
= PySequence_Length(backgroundList
);
245 for (i
= 0; i
< numPoints
; i
++) {
246 // Use a new string ?
249 obj
= PySequence_Fast_GET_ITEM(textList
, i
);
252 obj
= PySequence_GetItem(textList
, i
);
254 if (! PyString_Check(obj
) ) {
258 string
= Py2wxString(obj
);
263 if (i
< numForeground
) {
264 // Use a new foreground ?
265 if ( isFastForeground
) {
266 obj
= PySequence_Fast_GET_ITEM(foregroundList
, i
);
269 obj
= PySequence_GetItem(foregroundList
, i
);
271 if (! wxPyConvertSwigPtr(obj
, (void **) &color
, wxT("wxColour_p"))) {
272 if (!isFastForeground
)
276 dc
.SetTextForeground(*color
);
277 if ( !isFastForeground
)
281 if (i
< numBackground
) {
282 // Use a new background ?
283 if ( isFastBackground
) {
284 obj
= PySequence_Fast_GET_ITEM(backgroundList
, i
);
287 obj
= PySequence_GetItem(backgroundList
, i
);
289 if (! wxPyConvertSwigPtr(obj
, (void **) &color
, wxT("wxColour"))) {
290 if (!isFastBackground
)
294 dc
.SetTextBackground(*color
);
295 if ( !isFastBackground
)
299 // Get the point coordinates
301 obj
= PySequence_Fast_GET_ITEM(pyPoints
, i
);
304 obj
= PySequence_GetItem(pyPoints
, i
);
306 if (! wxPy2int_seq_helper(obj
, &x1
, &y1
)) {
311 if (PyErr_Occurred()) {
320 dc
.DrawText(string
, x1
, y1
);
331 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of (x,y) sequences.");
335 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of strings");
340 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of wxColours for foregrounds");
345 PyErr_SetString(PyExc_TypeError
, "Expected a sequence of wxColours for backgrounds");
350 wxPyEndBlockThreads();
356 //----------------------------------------------------------------------