]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/src/pseudodc.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: common/pseudodc.cpp
3 // Purpose: Implementation of the wxPseudoDC Class
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
15 #include "wx/wxPython/pseudodc.h"
18 // wxList based class definitions
19 #include <wx/listimpl.cpp>
20 WX_DEFINE_LIST(pdcOpList
);
21 WX_DEFINE_LIST(pdcObjectList
);
23 // ============================================================================
24 // various pdcOp class implementation methods
25 // ============================================================================
27 // ----------------------------------------------------------------------------
28 // pdcDrawPolyPolygonOp constructor
29 // ----------------------------------------------------------------------------
30 pdcDrawPolyPolygonOp::pdcDrawPolyPolygonOp(int n
, int count
[], wxPoint points
[],
31 wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
33 m_n
=n
; m_xoffset
=xoffset
; m_yoffset
=yoffset
; m_fillStyle
=fillStyle
;
38 for(int i
=0; i
<n
; i
++)
45 m_points
= new wxPoint
[total_n
];
46 for(int j
=0; j
<total_n
; j
++)
47 m_points
[j
] = points
[j
];
59 // ----------------------------------------------------------------------------
60 // pdcDrawPolyPolygonOp destructor
61 // ----------------------------------------------------------------------------
62 pdcDrawPolyPolygonOp::~pdcDrawPolyPolygonOp()
64 if (m_points
) delete m_points
;
65 if (m_count
) delete m_count
;
70 // ----------------------------------------------------------------------------
71 // pdcDrawLinesOp constructor
72 // ----------------------------------------------------------------------------
73 pdcDrawLinesOp::pdcDrawLinesOp(int n
, wxPoint points
[],
74 wxCoord xoffset
, wxCoord yoffset
)
76 m_n
=n
; m_xoffset
=xoffset
; m_yoffset
=yoffset
;
79 m_points
= new wxPoint
[n
];
80 for (int i
=0; i
<n
; i
++)
81 m_points
[i
] = points
[i
];
86 // ----------------------------------------------------------------------------
87 // pdcDrawLinesOp destructor
88 // ----------------------------------------------------------------------------
89 pdcDrawLinesOp::~pdcDrawLinesOp()
91 if (m_points
) delete m_points
;
95 // ----------------------------------------------------------------------------
96 // pdcDrawPolygonOp constructor
97 // ----------------------------------------------------------------------------
98 pdcDrawPolygonOp::pdcDrawPolygonOp(int n
, wxPoint points
[],
99 wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
101 m_n
=n
; m_xoffset
=xoffset
; m_yoffset
=yoffset
; m_fillStyle
=fillStyle
;
104 m_points
= new wxPoint
[n
];
105 for (int i
=0; i
<n
; i
++)
106 m_points
[i
] = points
[i
];
111 // ----------------------------------------------------------------------------
112 // pdcDrawPolygonOp destructor
113 // ----------------------------------------------------------------------------
114 pdcDrawPolygonOp::~pdcDrawPolygonOp()
116 if (m_points
) delete m_points
;
121 // ----------------------------------------------------------------------------
122 // pdcDrawSplineOp constructor
123 // ----------------------------------------------------------------------------
124 pdcDrawSplineOp::pdcDrawSplineOp(int n
, wxPoint points
[])
129 m_points
= new wxPoint
[n
];
130 for(int i
=0; i
<n
; i
++)
131 m_points
[i
] = points
[i
];
136 // ----------------------------------------------------------------------------
137 // pdcDrawSplineOp destructor
138 // ----------------------------------------------------------------------------
139 pdcDrawSplineOp::~pdcDrawSplineOp()
141 if (m_points
) delete m_points
;
144 #endif // wxUSE_SPLINES
146 // ============================================================================
147 // pdcObject implementation
148 // ============================================================================
149 // ----------------------------------------------------------------------------
150 // DrawToDC - play back the op list to the DC
151 // ----------------------------------------------------------------------------
152 void pdcObject::DrawToDC(wxDC
*dc
)
154 pdcOpList::Node
*node
= m_oplist
.GetFirst();
157 node
->GetData()->DrawToDC(dc
);
158 node
= node
->GetNext();
162 // ----------------------------------------------------------------------------
163 // Translate - translate all the operations by some dx,dy
164 // ----------------------------------------------------------------------------
165 void pdcObject::Translate(wxCoord dx
, wxCoord dy
)
167 pdcOpList::Node
*node
= m_oplist
.GetFirst();
170 node
->GetData()->Translate(dx
,dy
);
171 node
= node
->GetNext();
180 // ============================================================================
181 // wxPseudoDC implementation
182 // ============================================================================
184 // ----------------------------------------------------------------------------
186 // ----------------------------------------------------------------------------
187 wxPseudoDC::~wxPseudoDC()
189 // delete all the nodes in the list
194 // ----------------------------------------------------------------------------
195 // ClearAll - remove all nodes from list
196 // ----------------------------------------------------------------------------
197 void wxPseudoDC::RemoveAll(void)
199 m_objectlist
.Clear();
201 m_lastObjNode
= NULL
;
204 // ----------------------------------------------------------------------------
205 // GetLen - return the number of operations in the current op list
206 // ----------------------------------------------------------------------------
207 int wxPseudoDC::GetLen(void)
209 pdcObjectList::Node
*pt
= m_objectlist
.GetFirst();
213 len
+= pt
->GetData()->GetLen();
219 // ----------------------------------------------------------------------------
220 // FindObjNode - find and return an object node by id. If node doesn't exist
221 // and create is true then create one and return it. Otherwise
223 // ----------------------------------------------------------------------------
224 pdcObjectList::Node
*wxPseudoDC::FindObjNode(int id
, bool create
)
226 // see if last operation was for same id
227 if (m_lastObjNode
&& m_lastObjNode
->GetData()->GetId() == id
)
228 return m_lastObjNode
;
229 // if not then search for it
230 pdcObjectList::Node
*pt
= m_objectlist
.GetFirst();
233 if (pt
->GetData()->GetId() == id
)
236 // cache this node for future operations
242 // if create then create and return a new node
245 // cache this node for future operations
246 m_lastObjNode
= m_objectlist
.Append(new pdcObject(id
));
247 return m_lastObjNode
;
249 // otherwise just return NULL
253 // ----------------------------------------------------------------------------
254 // AddToList - Add a node to the list at the end (preserve draw order)
255 // ----------------------------------------------------------------------------
256 void wxPseudoDC::AddToList(pdcOp
*newOp
)
258 pdcObjectList::Node
*pt
= FindObjNode(m_currId
, true);
259 pt
->GetData()->AddOp(newOp
);
262 // ----------------------------------------------------------------------------
263 // ClearID - remove all the operations associated with a single ID
264 // ----------------------------------------------------------------------------
265 void wxPseudoDC::ClearId(int id
)
267 pdcObjectList::Node
*pt
= FindObjNode(id
);
268 if (pt
) pt
->GetData()->Clear();
271 // ----------------------------------------------------------------------------
272 // RemoveID - Remove the object node (and all operations) associated with an id
273 // ----------------------------------------------------------------------------
274 void wxPseudoDC::RemoveId(int id
)
276 pdcObjectList::Node
*pt
= FindObjNode(id
);
279 if (m_lastObjNode
== pt
)
280 m_lastObjNode
= NULL
;
281 m_objectlist
.DeleteNode(pt
);
285 // ----------------------------------------------------------------------------
286 // SetIdBounds - Set the bounding rect for a given id
287 // ----------------------------------------------------------------------------
288 void wxPseudoDC::SetIdBounds(int id
, wxRect
& rect
)
290 pdcObjectList::Node
*pt
= FindObjNode(id
, true);
291 pt
->GetData()->SetBounds(rect
);
294 // ----------------------------------------------------------------------------
295 // GetIdBounds - Get the bounding rect for a given id
296 // ----------------------------------------------------------------------------
297 void wxPseudoDC::GetIdBounds(int id
, wxRect
& rect
)
299 pdcObjectList::Node
*pt
= FindObjNode(id
);
300 if (pt
&& pt
->GetData()->IsBounded())
301 rect
= pt
->GetData()->GetBounds();
303 rect
.x
= rect
.y
= rect
.width
= rect
.height
= 0;
306 // ----------------------------------------------------------------------------
307 // TranslateId - Translate all the operations of a single id
308 // ----------------------------------------------------------------------------
309 void wxPseudoDC::TranslateId(int id
, wxCoord dx
, wxCoord dy
)
311 pdcObjectList::Node
*pt
= FindObjNode(id
);
312 if (pt
) pt
->GetData()->Translate(dx
,dy
);
315 // ----------------------------------------------------------------------------
316 // DrawIdToDC - Draw a specific id to the dc passed in
317 // ----------------------------------------------------------------------------
318 void wxPseudoDC::DrawIdToDC(int id
, wxDC
*dc
)
320 pdcObjectList::Node
*pt
= FindObjNode(id
);
321 if (pt
) pt
->GetData()->DrawToDC(dc
);
324 // ----------------------------------------------------------------------------
325 // DrawToDCClipped - play back the op list to the DC but clip any objects
326 // known to be not in rect. This is a coarse level of
327 // clipping to speed things up when lots of objects are off
328 // screen and doesn't affect the dc level clipping
329 // ----------------------------------------------------------------------------
330 void wxPseudoDC::DrawToDCClipped(wxDC
*dc
, const wxRect
& rect
)
332 pdcObjectList::Node
*pt
= m_objectlist
.GetFirst();
337 if (!obj
->IsBounded() || rect
.Intersects(obj
->GetBounds()))
342 void wxPseudoDC::DrawToDCClippedRgn(wxDC
*dc
, const wxRegion
& region
)
344 pdcObjectList::Node
*pt
= m_objectlist
.GetFirst();
349 if (!obj
->IsBounded() ||
350 (region
.Contains(obj
->GetBounds()) != wxOutRegion
))
356 // ----------------------------------------------------------------------------
357 // DrawToDC - play back the op list to the DC
358 // ----------------------------------------------------------------------------
359 void wxPseudoDC::DrawToDC(wxDC
*dc
)
361 pdcObjectList::Node
*pt
= m_objectlist
.GetFirst();
364 pt
->GetData()->DrawToDC(dc
);