]>
Commit | Line | Data |
---|---|---|
006162a9 | 1 | ///////////////////////////////////////////////////////////////////////////// |
4660e6ac | 2 | // Name: wx/dc.h |
006162a9 VZ |
3 | // Purpose: wxDC class |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 05/25/99 | |
7 | // RCS-ID: $Id$ | |
77ffb593 | 8 | // Copyright: (c) wxWidgets team |
65571936 | 9 | // Licence: wxWindows licence |
006162a9 VZ |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
34138703 JS |
12 | #ifndef _WX_DC_H_BASE_ |
13 | #define _WX_DC_H_BASE_ | |
c801d85f | 14 | |
a23fd0e1 VZ |
15 | // ---------------------------------------------------------------------------- |
16 | // headers which we must include here | |
17 | // ---------------------------------------------------------------------------- | |
18 | ||
19 | #include "wx/object.h" // the base class | |
20 | ||
21 | #include "wx/cursor.h" // we have member variables of these classes | |
22 | #include "wx/font.h" // so we can't do without them | |
23 | #include "wx/colour.h" | |
b494e2b0 | 24 | #include "wx/bitmap.h" // for wxNullBitmap |
a23fd0e1 VZ |
25 | #include "wx/brush.h" |
26 | #include "wx/pen.h" | |
27 | #include "wx/palette.h" | |
a23fd0e1 | 28 | #include "wx/list.h" // we use wxList in inline functions |
0919e93e | 29 | #include "wx/dynarray.h" |
19edb09c | 30 | #include "wx/math.h" |
a23fd0e1 | 31 | |
f4515f98 | 32 | class WXDLLEXPORT wxDC; |
aec43716 KH |
33 | class WXDLLEXPORT wxDCBase; |
34 | ||
35 | class WXDLLEXPORT wxDrawObject | |
36 | { | |
37 | public: | |
38 | ||
39 | wxDrawObject() | |
68379eaf | 40 | : m_isBBoxValid(false) |
ba161d7e GD |
41 | , m_minX(0), m_minY(0), m_maxX(0), m_maxY(0) |
42 | { } | |
aec43716 KH |
43 | |
44 | virtual ~wxDrawObject() { } | |
45 | ||
33ac7e6f | 46 | virtual void Draw(wxDCBase&) const { } |
aec43716 KH |
47 | |
48 | virtual void CalcBoundingBox(wxCoord x, wxCoord y) | |
49 | { | |
50 | if ( m_isBBoxValid ) | |
51 | { | |
52 | if ( x < m_minX ) m_minX = x; | |
53 | if ( y < m_minY ) m_minY = y; | |
54 | if ( x > m_maxX ) m_maxX = x; | |
55 | if ( y > m_maxY ) m_maxY = y; | |
56 | } | |
57 | else | |
58 | { | |
68379eaf | 59 | m_isBBoxValid = true; |
aec43716 KH |
60 | |
61 | m_minX = x; | |
62 | m_minY = y; | |
63 | m_maxX = x; | |
64 | m_maxY = y; | |
65 | } | |
66 | } | |
67 | ||
68 | void ResetBoundingBox() | |
69 | { | |
68379eaf | 70 | m_isBBoxValid = false; |
aec43716 KH |
71 | |
72 | m_minX = m_maxX = m_minY = m_maxY = 0; | |
73 | } | |
74 | ||
75 | // Get the final bounding box of the PostScript or Metafile picture. | |
76 | ||
77 | wxCoord MinX() const { return m_minX; } | |
78 | wxCoord MaxX() const { return m_maxX; } | |
79 | wxCoord MinY() const { return m_minY; } | |
80 | wxCoord MaxY() const { return m_maxY; } | |
81 | ||
82 | //to define the type of object for derived objects | |
83 | virtual int GetType()=0; | |
84 | ||
85 | protected: | |
86 | //for boundingbox calculation | |
87 | bool m_isBBoxValid:1; | |
88 | //for boundingbox calculation | |
89 | wxCoord m_minX, m_minY, m_maxX, m_maxY; | |
90 | }; | |
91 | ||
a23fd0e1 VZ |
92 | // --------------------------------------------------------------------------- |
93 | // global variables | |
94 | // --------------------------------------------------------------------------- | |
95 | ||
a23fd0e1 VZ |
96 | // --------------------------------------------------------------------------- |
97 | // wxDC is the device context - object on which any drawing is done | |
98 | // --------------------------------------------------------------------------- | |
99 | ||
100 | class WXDLLEXPORT wxDCBase : public wxObject | |
101 | { | |
a23fd0e1 VZ |
102 | public: |
103 | wxDCBase() | |
ba161d7e | 104 | : m_colour(wxColourDisplay()) |
68379eaf WS |
105 | , m_ok(true) |
106 | , m_clipping(false) | |
ba161d7e | 107 | , m_isInteractive(0) |
68379eaf | 108 | , m_isBBoxValid(false) |
ba161d7e GD |
109 | , m_logicalOriginX(0), m_logicalOriginY(0) |
110 | , m_deviceOriginX(0), m_deviceOriginY(0) | |
111 | , m_logicalScaleX(1.0), m_logicalScaleY(1.0) | |
112 | , m_userScaleX(1.0), m_userScaleY(1.0) | |
113 | , m_scaleX(1.0), m_scaleY(1.0) | |
114 | , m_signX(1), m_signY(1) | |
115 | , m_minX(0), m_minY(0), m_maxX(0), m_maxY(0) | |
116 | , m_clipX1(0), m_clipY1(0), m_clipX2(0), m_clipY2(0) | |
117 | , m_logicalFunction(wxCOPY) | |
118 | , m_backgroundMode(wxTRANSPARENT) | |
119 | , m_mappingMode(wxMM_TEXT) | |
120 | , m_pen() | |
121 | , m_brush() | |
122 | , m_backgroundBrush(*wxTRANSPARENT_BRUSH) | |
123 | , m_textForegroundColour(*wxBLACK) | |
124 | , m_textBackgroundColour(*wxWHITE) | |
125 | , m_font() | |
126 | #if wxUSE_PALETTE | |
127 | , m_palette() | |
68379eaf | 128 | , m_hasCustomPalette(false) |
ba161d7e | 129 | #endif // wxUSE_PALETTE |
a23fd0e1 | 130 | { |
f6bcfd97 | 131 | ResetBoundingBox(); |
d16b634f | 132 | ResetClipping(); |
a23fd0e1 VZ |
133 | } |
134 | ||
d3c7fc99 | 135 | virtual ~wxDCBase() { } |
a23fd0e1 | 136 | |
68df211f JG |
137 | #if WXWIN_COMPATIBILITY_2_6 |
138 | wxDEPRECATED( virtual void BeginDrawing() ); | |
139 | wxDEPRECATED( virtual void EndDrawing() ); | |
140 | #endif // WXWIN_COMPATIBILITY_2_6 | |
a23fd0e1 VZ |
141 | |
142 | // graphic primitives | |
143 | // ------------------ | |
144 | ||
aec43716 KH |
145 | virtual void DrawObject(wxDrawObject* drawobject) |
146 | { | |
147 | drawobject->Draw(*this); | |
148 | CalcBoundingBox(drawobject->MinX(),drawobject->MinY()); | |
149 | CalcBoundingBox(drawobject->MaxX(),drawobject->MaxY()); | |
150 | } | |
151 | ||
387ebd3e | 152 | bool FloodFill(wxCoord x, wxCoord y, const wxColour& col, |
72cdf4c9 | 153 | int style = wxFLOOD_SURFACE) |
387ebd3e JS |
154 | { return DoFloodFill(x, y, col, style); } |
155 | bool FloodFill(const wxPoint& pt, const wxColour& col, | |
72cdf4c9 | 156 | int style = wxFLOOD_SURFACE) |
387ebd3e | 157 | { return DoFloodFill(pt.x, pt.y, col, style); } |
a23fd0e1 | 158 | |
213ad8e7 VZ |
159 | // fill the area specified by rect with a radial gradient, starting from |
160 | // initialColour in the centre of the cercle and fading to destColour. | |
161 | void GradientFillConcentric(const wxRect& rect, | |
4660e6ac | 162 | const wxColour& initialColour, |
213ad8e7 VZ |
163 | const wxColour& destColour) |
164 | { GradientFillConcentric(rect, initialColour, destColour, | |
165 | wxPoint(rect.GetWidth() / 2, | |
166 | rect.GetHeight() / 2)); } | |
167 | ||
168 | void GradientFillConcentric(const wxRect& rect, | |
4660e6ac | 169 | const wxColour& initialColour, |
213ad8e7 | 170 | const wxColour& destColour, |
fb63a242 SC |
171 | const wxPoint& circleCenter) |
172 | { DoGradientFillConcentric(rect, initialColour, destColour, circleCenter); } | |
213ad8e7 VZ |
173 | |
174 | // fill the area specified by rect with a linear gradient | |
175 | void GradientFillLinear(const wxRect& rect, | |
4660e6ac | 176 | const wxColour& initialColour, |
213ad8e7 VZ |
177 | const wxColour& destColour, |
178 | wxDirection nDirection = wxEAST) | |
179 | { DoGradientFillLinear(rect, initialColour, destColour, nDirection); } | |
180 | ||
72cdf4c9 | 181 | bool GetPixel(wxCoord x, wxCoord y, wxColour *col) const |
a23fd0e1 VZ |
182 | { return DoGetPixel(x, y, col); } |
183 | bool GetPixel(const wxPoint& pt, wxColour *col) const | |
184 | { return DoGetPixel(pt.x, pt.y, col); } | |
185 | ||
72cdf4c9 | 186 | void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) |
a23fd0e1 VZ |
187 | { DoDrawLine(x1, y1, x2, y2); } |
188 | void DrawLine(const wxPoint& pt1, const wxPoint& pt2) | |
189 | { DoDrawLine(pt1.x, pt1.y, pt2.x, pt2.y); } | |
190 | ||
72cdf4c9 | 191 | void CrossHair(wxCoord x, wxCoord y) |
a23fd0e1 VZ |
192 | { DoCrossHair(x, y); } |
193 | void CrossHair(const wxPoint& pt) | |
194 | { DoCrossHair(pt.x, pt.y); } | |
195 | ||
72cdf4c9 VZ |
196 | void DrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, |
197 | wxCoord xc, wxCoord yc) | |
a23fd0e1 VZ |
198 | { DoDrawArc(x1, y1, x2, y2, xc, yc); } |
199 | void DrawArc(const wxPoint& pt1, const wxPoint& pt2, const wxPoint& centre) | |
200 | { DoDrawArc(pt1.x, pt1.y, pt2.x, pt2.y, centre.x, centre.y); } | |
201 | ||
cd9da200 VZ |
202 | void DrawCheckMark(wxCoord x, wxCoord y, |
203 | wxCoord width, wxCoord height) | |
204 | { DoDrawCheckMark(x, y, width, height); } | |
205 | void DrawCheckMark(const wxRect& rect) | |
206 | { DoDrawCheckMark(rect.x, rect.y, rect.width, rect.height); } | |
207 | ||
72cdf4c9 VZ |
208 | void DrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, |
209 | double sa, double ea) | |
7b90a8f2 | 210 | { DoDrawEllipticArc(x, y, w, h, sa, ea); } |
a23fd0e1 VZ |
211 | void DrawEllipticArc(const wxPoint& pt, const wxSize& sz, |
212 | double sa, double ea) | |
213 | { DoDrawEllipticArc(pt.x, pt.y, sz.x, sz.y, sa, ea); } | |
214 | ||
72cdf4c9 | 215 | void DrawPoint(wxCoord x, wxCoord y) |
a23fd0e1 VZ |
216 | { DoDrawPoint(x, y); } |
217 | void DrawPoint(const wxPoint& pt) | |
218 | { DoDrawPoint(pt.x, pt.y); } | |
219 | ||
72cdf4c9 VZ |
220 | void DrawLines(int n, wxPoint points[], |
221 | wxCoord xoffset = 0, wxCoord yoffset = 0) | |
a23fd0e1 | 222 | { DoDrawLines(n, points, xoffset, yoffset); } |
72cdf4c9 VZ |
223 | void DrawLines(const wxList *list, |
224 | wxCoord xoffset = 0, wxCoord yoffset = 0); | |
a23fd0e1 VZ |
225 | |
226 | void DrawPolygon(int n, wxPoint points[], | |
72cdf4c9 | 227 | wxCoord xoffset = 0, wxCoord yoffset = 0, |
a23fd0e1 VZ |
228 | int fillStyle = wxODDEVEN_RULE) |
229 | { DoDrawPolygon(n, points, xoffset, yoffset, fillStyle); } | |
230 | ||
231 | void DrawPolygon(const wxList *list, | |
72cdf4c9 | 232 | wxCoord xoffset = 0, wxCoord yoffset = 0, |
bd5dd957 | 233 | int fillStyle = wxODDEVEN_RULE); |
a23fd0e1 | 234 | |
793db755 | 235 | void DrawPolyPolygon(int n, int count[], wxPoint points[], |
6e76b35d VZ |
236 | wxCoord xoffset = 0, wxCoord yoffset = 0, |
237 | int fillStyle = wxODDEVEN_RULE) | |
793db755 | 238 | { DoDrawPolyPolygon(n, count, points, xoffset, yoffset, fillStyle); } |
6e76b35d | 239 | |
72cdf4c9 | 240 | void DrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) |
a23fd0e1 VZ |
241 | { DoDrawRectangle(x, y, width, height); } |
242 | void DrawRectangle(const wxPoint& pt, const wxSize& sz) | |
243 | { DoDrawRectangle(pt.x, pt.y, sz.x, sz.y); } | |
244 | void DrawRectangle(const wxRect& rect) | |
245 | { DoDrawRectangle(rect.x, rect.y, rect.width, rect.height); } | |
246 | ||
72cdf4c9 | 247 | void DrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, |
a23fd0e1 VZ |
248 | double radius) |
249 | { DoDrawRoundedRectangle(x, y, width, height, radius); } | |
250 | void DrawRoundedRectangle(const wxPoint& pt, const wxSize& sz, | |
251 | double radius) | |
252 | { DoDrawRoundedRectangle(pt.x, pt.y, sz.x, sz.y, radius); } | |
253 | void DrawRoundedRectangle(const wxRect& r, double radius) | |
254 | { DoDrawRoundedRectangle(r.x, r.y, r.width, r.height, radius); } | |
255 | ||
72cdf4c9 | 256 | void DrawCircle(wxCoord x, wxCoord y, wxCoord radius) |
220af862 | 257 | { DoDrawEllipse(x - radius, y - radius, 2*radius, 2*radius); } |
0371e9a8 | 258 | void DrawCircle(const wxPoint& pt, wxCoord radius) |
b95edd47 | 259 | { DrawCircle(pt.x, pt.y, radius); } |
0371e9a8 | 260 | |
72cdf4c9 | 261 | void DrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) |
a23fd0e1 VZ |
262 | { DoDrawEllipse(x, y, width, height); } |
263 | void DrawEllipse(const wxPoint& pt, const wxSize& sz) | |
264 | { DoDrawEllipse(pt.x, pt.y, sz.x, sz.y); } | |
265 | void DrawEllipse(const wxRect& rect) | |
266 | { DoDrawEllipse(rect.x, rect.y, rect.width, rect.height); } | |
267 | ||
72cdf4c9 | 268 | void DrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) |
a23fd0e1 VZ |
269 | { DoDrawIcon(icon, x, y); } |
270 | void DrawIcon(const wxIcon& icon, const wxPoint& pt) | |
271 | { DoDrawIcon(icon, pt.x, pt.y); } | |
272 | ||
72cdf4c9 | 273 | void DrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, |
68379eaf | 274 | bool useMask = false) |
a23fd0e1 VZ |
275 | { DoDrawBitmap(bmp, x, y, useMask); } |
276 | void DrawBitmap(const wxBitmap &bmp, const wxPoint& pt, | |
68379eaf | 277 | bool useMask = false) |
a23fd0e1 VZ |
278 | { DoDrawBitmap(bmp, pt.x, pt.y, useMask); } |
279 | ||
72cdf4c9 | 280 | void DrawText(const wxString& text, wxCoord x, wxCoord y) |
a23fd0e1 VZ |
281 | { DoDrawText(text, x, y); } |
282 | void DrawText(const wxString& text, const wxPoint& pt) | |
283 | { DoDrawText(text, pt.x, pt.y); } | |
284 | ||
95724b1a VZ |
285 | void DrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle) |
286 | { DoDrawRotatedText(text, x, y, angle); } | |
287 | void DrawRotatedText(const wxString& text, const wxPoint& pt, double angle) | |
288 | { DoDrawRotatedText(text, pt.x, pt.y, angle); } | |
289 | ||
1e6feb95 VZ |
290 | // this version puts both optional bitmap and the text into the given |
291 | // rectangle and aligns is as specified by alignment parameter; it also | |
292 | // will emphasize the character with the given index if it is != -1 and | |
293 | // return the bounding rectangle if required | |
294 | virtual void DrawLabel(const wxString& text, | |
295 | const wxBitmap& image, | |
296 | const wxRect& rect, | |
297 | int alignment = wxALIGN_LEFT | wxALIGN_TOP, | |
298 | int indexAccel = -1, | |
299 | wxRect *rectBounding = NULL); | |
300 | ||
301 | void DrawLabel(const wxString& text, const wxRect& rect, | |
302 | int alignment = wxALIGN_LEFT | wxALIGN_TOP, | |
303 | int indexAccel = -1) | |
304 | { DrawLabel(text, wxNullBitmap, rect, alignment, indexAccel); } | |
305 | ||
72cdf4c9 VZ |
306 | bool Blit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, |
307 | wxDC *source, wxCoord xsrc, wxCoord ysrc, | |
68379eaf | 308 | int rop = wxCOPY, bool useMask = false, wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord) |
a23fd0e1 VZ |
309 | { |
310 | return DoBlit(xdest, ydest, width, height, | |
0cbff120 | 311 | source, xsrc, ysrc, rop, useMask, xsrcMask, ysrcMask); |
a23fd0e1 VZ |
312 | } |
313 | bool Blit(const wxPoint& destPt, const wxSize& sz, | |
314 | wxDC *source, const wxPoint& srcPt, | |
68379eaf | 315 | int rop = wxCOPY, bool useMask = false, const wxPoint& srcPtMask = wxDefaultPosition) |
a23fd0e1 VZ |
316 | { |
317 | return DoBlit(destPt.x, destPt.y, sz.x, sz.y, | |
0cbff120 | 318 | source, srcPt.x, srcPt.y, rop, useMask, srcPtMask.x, srcPtMask.y); |
a23fd0e1 VZ |
319 | } |
320 | ||
321 | #if wxUSE_SPLINES | |
72cdf4c9 VZ |
322 | // TODO: this API needs fixing (wxPointList, why (!const) "wxList *"?) |
323 | void DrawSpline(wxCoord x1, wxCoord y1, | |
324 | wxCoord x2, wxCoord y2, | |
325 | wxCoord x3, wxCoord y3); | |
bd5dd957 | 326 | void DrawSpline(int n, wxPoint points[]); |
a23fd0e1 VZ |
327 | |
328 | void DrawSpline(wxList *points) { DoDrawSpline(points); } | |
329 | #endif // wxUSE_SPLINES | |
330 | ||
12bdd77c JS |
331 | // Eventually we will have wxUSE_GENERIC_DRAWELLIPSE |
332 | #ifdef __WXWINCE__ | |
333 | //! Generic method to draw ellipses, circles and arcs with current pen and brush. | |
334 | /*! \param x Upper left corner of bounding box. | |
335 | * \param y Upper left corner of bounding box. | |
336 | * \param w Width of bounding box. | |
337 | * \param h Height of bounding box. | |
d16b634f | 338 | * \param sa Starting angle of arc |
12bdd77c JS |
339 | * (counterclockwise, start at 3 o'clock, 360 is full circle). |
340 | * \param ea Ending angle of arc. | |
d16b634f | 341 | * \param angle Rotation angle, the Arc will be rotated after |
12bdd77c JS |
342 | * calculating begin and end. |
343 | */ | |
d16b634f VZ |
344 | void DrawEllipticArcRot( wxCoord x, wxCoord y, |
345 | wxCoord width, wxCoord height, | |
12bdd77c JS |
346 | double sa = 0, double ea = 0, double angle = 0 ) |
347 | { DoDrawEllipticArcRot( x, y, width, height, sa, ea, angle ); } | |
d16b634f VZ |
348 | |
349 | void DrawEllipticArcRot( const wxPoint& pt, | |
12bdd77c JS |
350 | const wxSize& sz, |
351 | double sa = 0, double ea = 0, double angle = 0 ) | |
352 | { DoDrawEllipticArcRot( pt.x, pt.y, sz.x, sz.y, sa, ea, angle ); } | |
353 | ||
354 | void DrawEllipticArcRot( const wxRect& rect, | |
355 | double sa = 0, double ea = 0, double angle = 0 ) | |
356 | { DoDrawEllipticArcRot( rect.x, rect.y, rect.width, rect.height, sa, ea, angle ); } | |
357 | ||
d16b634f VZ |
358 | virtual void DoDrawEllipticArcRot( wxCoord x, wxCoord y, |
359 | wxCoord w, wxCoord h, | |
12bdd77c | 360 | double sa = 0, double ea = 0, double angle = 0 ); |
d16b634f | 361 | |
12bdd77c JS |
362 | //! Rotates points around center. |
363 | /*! This is a quite straight method, it calculates in pixels | |
364 | * and so it produces rounding errors. | |
365 | * \param points The points inside will be rotated. | |
366 | * \param angle Rotating angle (counterclockwise, start at 3 o'clock, 360 is full circle). | |
367 | * \param center Center of rotation. | |
d16b634f | 368 | */ |
c47addef | 369 | void Rotate( wxList* points, double angle, wxPoint center = wxPoint(0,0) ); |
12bdd77c JS |
370 | |
371 | // used by DrawEllipticArcRot | |
372 | // Careful: wxList gets filled with points you have to delete later. | |
d16b634f VZ |
373 | void CalculateEllipticPoints( wxList* points, |
374 | wxCoord xStart, wxCoord yStart, | |
375 | wxCoord w, wxCoord h, | |
12bdd77c JS |
376 | double sa, double ea ); |
377 | #endif | |
d16b634f | 378 | |
a23fd0e1 VZ |
379 | // global DC operations |
380 | // -------------------- | |
381 | ||
382 | virtual void Clear() = 0; | |
383 | ||
68379eaf | 384 | virtual bool StartDoc(const wxString& WXUNUSED(message)) { return true; } |
af0bb3b1 | 385 | virtual void EndDoc() { } |
a23fd0e1 | 386 | |
af0bb3b1 VZ |
387 | virtual void StartPage() { } |
388 | virtual void EndPage() { } | |
a23fd0e1 VZ |
389 | |
390 | // set objects to use for drawing | |
391 | // ------------------------------ | |
392 | ||
393 | virtual void SetFont(const wxFont& font) = 0; | |
394 | virtual void SetPen(const wxPen& pen) = 0; | |
395 | virtual void SetBrush(const wxBrush& brush) = 0; | |
396 | virtual void SetBackground(const wxBrush& brush) = 0; | |
397 | virtual void SetBackgroundMode(int mode) = 0; | |
d275c7eb | 398 | #if wxUSE_PALETTE |
a23fd0e1 | 399 | virtual void SetPalette(const wxPalette& palette) = 0; |
d275c7eb | 400 | #endif // wxUSE_PALETTE |
a23fd0e1 VZ |
401 | |
402 | // clipping region | |
403 | // --------------- | |
404 | ||
72cdf4c9 | 405 | void SetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height) |
a23fd0e1 VZ |
406 | { DoSetClippingRegion(x, y, width, height); } |
407 | void SetClippingRegion(const wxPoint& pt, const wxSize& sz) | |
408 | { DoSetClippingRegion(pt.x, pt.y, sz.x, sz.y); } | |
409 | void SetClippingRegion(const wxRect& rect) | |
410 | { DoSetClippingRegion(rect.x, rect.y, rect.width, rect.height); } | |
411 | void SetClippingRegion(const wxRegion& region) | |
412 | { DoSetClippingRegionAsRegion(region); } | |
413 | ||
d16b634f | 414 | virtual void DestroyClippingRegion() { ResetClipping(); } |
a23fd0e1 | 415 | |
72cdf4c9 | 416 | void GetClippingBox(wxCoord *x, wxCoord *y, wxCoord *w, wxCoord *h) const |
a23fd0e1 VZ |
417 | { DoGetClippingBox(x, y, w, h); } |
418 | void GetClippingBox(wxRect& rect) const | |
8fb3a512 | 419 | { |
ae500232 | 420 | DoGetClippingBox(&rect.x, &rect.y, &rect.width, &rect.height); |
8fb3a512 | 421 | } |
a23fd0e1 VZ |
422 | |
423 | // text extent | |
424 | // ----------- | |
425 | ||
72cdf4c9 VZ |
426 | virtual wxCoord GetCharHeight() const = 0; |
427 | virtual wxCoord GetCharWidth() const = 0; | |
cd9da200 | 428 | |
1e6feb95 | 429 | // only works for single line strings |
72cdf4c9 VZ |
430 | void GetTextExtent(const wxString& string, |
431 | wxCoord *x, wxCoord *y, | |
432 | wxCoord *descent = NULL, | |
433 | wxCoord *externalLeading = NULL, | |
434 | wxFont *theFont = NULL) const | |
435 | { DoGetTextExtent(string, x, y, descent, externalLeading, theFont); } | |
a23fd0e1 | 436 | |
1e6feb95 VZ |
437 | // works for single as well as multi-line strings |
438 | virtual void GetMultiLineTextExtent(const wxString& text, | |
439 | wxCoord *width, | |
440 | wxCoord *height, | |
441 | wxCoord *heightLine = NULL, | |
442 | wxFont *font = NULL); | |
443 | ||
0919e93e RD |
444 | // Measure cumulative width of text after each character |
445 | bool GetPartialTextExtents(const wxString& text, wxArrayInt& widths) const | |
446 | { return DoGetPartialTextExtents(text, widths); } | |
447 | ||
d16b634f | 448 | |
a23fd0e1 VZ |
449 | // size and resolution |
450 | // ------------------- | |
451 | ||
452 | // in device units | |
453 | void GetSize(int *width, int *height) const | |
454 | { DoGetSize(width, height); } | |
455 | wxSize GetSize() const | |
456 | { | |
457 | int w, h; | |
458 | DoGetSize(&w, &h); | |
459 | ||
460 | return wxSize(w, h); | |
461 | } | |
462 | ||
463 | // in mm | |
464 | void GetSizeMM(int* width, int* height) const | |
465 | { DoGetSizeMM(width, height); } | |
466 | wxSize GetSizeMM() const | |
467 | { | |
468 | int w, h; | |
469 | DoGetSizeMM(&w, &h); | |
470 | ||
471 | return wxSize(w, h); | |
472 | } | |
473 | ||
474 | // coordinates conversions | |
475 | // ----------------------- | |
476 | ||
477 | // This group of functions does actual conversion of the input, as you'd | |
478 | // expect. | |
72cdf4c9 VZ |
479 | wxCoord DeviceToLogicalX(wxCoord x) const; |
480 | wxCoord DeviceToLogicalY(wxCoord y) const; | |
481 | wxCoord DeviceToLogicalXRel(wxCoord x) const; | |
482 | wxCoord DeviceToLogicalYRel(wxCoord y) const; | |
483 | wxCoord LogicalToDeviceX(wxCoord x) const; | |
484 | wxCoord LogicalToDeviceY(wxCoord y) const; | |
485 | wxCoord LogicalToDeviceXRel(wxCoord x) const; | |
486 | wxCoord LogicalToDeviceYRel(wxCoord y) const; | |
a23fd0e1 VZ |
487 | |
488 | // query DC capabilities | |
489 | // --------------------- | |
490 | ||
491 | virtual bool CanDrawBitmap() const = 0; | |
492 | virtual bool CanGetTextExtent() const = 0; | |
493 | ||
494 | // colour depth | |
495 | virtual int GetDepth() const = 0; | |
496 | ||
497 | // Resolution in Pixels per inch | |
498 | virtual wxSize GetPPI() const = 0; | |
499 | ||
500 | virtual bool Ok() const { return m_ok; } | |
501 | ||
2439f37a VZ |
502 | // accessors and setters |
503 | // --------------------- | |
a23fd0e1 | 504 | |
f6bcfd97 | 505 | int GetBackgroundMode() const { return m_backgroundMode; } |
a23fd0e1 VZ |
506 | const wxBrush& GetBackground() const { return m_backgroundBrush; } |
507 | const wxBrush& GetBrush() const { return m_brush; } | |
508 | const wxFont& GetFont() const { return m_font; } | |
509 | const wxPen& GetPen() const { return m_pen; } | |
a23fd0e1 | 510 | |
2439f37a VZ |
511 | const wxColour& GetTextForeground() const { return m_textForegroundColour; } |
512 | const wxColour& GetTextBackground() const { return m_textBackgroundColour; } | |
a23fd0e1 VZ |
513 | virtual void SetTextForeground(const wxColour& colour) |
514 | { m_textForegroundColour = colour; } | |
515 | virtual void SetTextBackground(const wxColour& colour) | |
516 | { m_textBackgroundColour = colour; } | |
517 | ||
518 | int GetMapMode() const { return m_mappingMode; } | |
519 | virtual void SetMapMode(int mode) = 0; | |
520 | ||
521 | virtual void GetUserScale(double *x, double *y) const | |
522 | { | |
523 | if ( x ) *x = m_userScaleX; | |
524 | if ( y ) *y = m_userScaleY; | |
525 | } | |
526 | virtual void SetUserScale(double x, double y) = 0; | |
527 | ||
a23fd0e1 VZ |
528 | virtual void GetLogicalScale(double *x, double *y) |
529 | { | |
530 | if ( x ) *x = m_logicalScaleX; | |
531 | if ( y ) *y = m_logicalScaleY; | |
532 | } | |
533 | virtual void SetLogicalScale(double x, double y) | |
534 | { | |
535 | m_logicalScaleX = x; | |
536 | m_logicalScaleY = y; | |
537 | } | |
538 | ||
72cdf4c9 | 539 | void GetLogicalOrigin(wxCoord *x, wxCoord *y) const |
a23fd0e1 VZ |
540 | { DoGetLogicalOrigin(x, y); } |
541 | wxPoint GetLogicalOrigin() const | |
72cdf4c9 VZ |
542 | { wxCoord x, y; DoGetLogicalOrigin(&x, &y); return wxPoint(x, y); } |
543 | virtual void SetLogicalOrigin(wxCoord x, wxCoord y) = 0; | |
a23fd0e1 | 544 | |
72cdf4c9 | 545 | void GetDeviceOrigin(wxCoord *x, wxCoord *y) const |
a23fd0e1 VZ |
546 | { DoGetDeviceOrigin(x, y); } |
547 | wxPoint GetDeviceOrigin() const | |
72cdf4c9 VZ |
548 | { wxCoord x, y; DoGetDeviceOrigin(&x, &y); return wxPoint(x, y); } |
549 | virtual void SetDeviceOrigin(wxCoord x, wxCoord y) = 0; | |
a23fd0e1 | 550 | |
b1263dcf WS |
551 | virtual void ComputeScaleAndOrigin() {} |
552 | ||
a23fd0e1 VZ |
553 | virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp) = 0; |
554 | ||
555 | int GetLogicalFunction() const { return m_logicalFunction; } | |
556 | virtual void SetLogicalFunction(int function) = 0; | |
557 | ||
ea76a6a5 | 558 | #if WXWIN_COMPATIBILITY_2_4 |
a23fd0e1 | 559 | virtual void SetOptimization(bool WXUNUSED(opt)) { } |
68379eaf | 560 | virtual bool GetOptimization() { return false; } |
ea76a6a5 | 561 | #endif |
a23fd0e1 VZ |
562 | |
563 | // bounding box | |
564 | // ------------ | |
565 | ||
72cdf4c9 | 566 | virtual void CalcBoundingBox(wxCoord x, wxCoord y) |
a23fd0e1 | 567 | { |
f6bcfd97 BP |
568 | if ( m_isBBoxValid ) |
569 | { | |
570 | if ( x < m_minX ) m_minX = x; | |
571 | if ( y < m_minY ) m_minY = y; | |
572 | if ( x > m_maxX ) m_maxX = x; | |
573 | if ( y > m_maxY ) m_maxY = y; | |
574 | } | |
575 | else | |
576 | { | |
68379eaf | 577 | m_isBBoxValid = true; |
f6bcfd97 BP |
578 | |
579 | m_minX = x; | |
580 | m_minY = y; | |
581 | m_maxX = x; | |
582 | m_maxY = y; | |
583 | } | |
584 | } | |
585 | ||
586 | void ResetBoundingBox() | |
587 | { | |
68379eaf | 588 | m_isBBoxValid = false; |
f6bcfd97 BP |
589 | |
590 | m_minX = m_maxX = m_minY = m_maxY = 0; | |
a23fd0e1 VZ |
591 | } |
592 | ||
593 | // Get the final bounding box of the PostScript or Metafile picture. | |
72cdf4c9 VZ |
594 | wxCoord MinX() const { return m_minX; } |
595 | wxCoord MaxX() const { return m_maxX; } | |
596 | wxCoord MinY() const { return m_minY; } | |
597 | wxCoord MaxY() const { return m_maxY; } | |
a23fd0e1 VZ |
598 | |
599 | // misc old functions | |
600 | // ------------------ | |
601 | ||
72cdf4c9 | 602 | // for compatibility with the old code when wxCoord was long everywhere |
72cdf4c9 VZ |
603 | void GetTextExtent(const wxString& string, |
604 | long *x, long *y, | |
605 | long *descent = NULL, | |
606 | long *externalLeading = NULL, | |
607 | wxFont *theFont = NULL) const | |
608 | { | |
609 | wxCoord x2, y2, descent2, externalLeading2; | |
610 | DoGetTextExtent(string, &x2, &y2, | |
611 | &descent2, &externalLeading2, | |
612 | theFont); | |
613 | if ( x ) | |
614 | *x = x2; | |
615 | if ( y ) | |
616 | *y = y2; | |
617 | if ( descent ) | |
618 | *descent = descent2; | |
619 | if ( externalLeading ) | |
620 | *externalLeading = externalLeading2; | |
621 | } | |
622 | ||
623 | void GetLogicalOrigin(long *x, long *y) const | |
624 | { | |
625 | wxCoord x2, y2; | |
626 | DoGetLogicalOrigin(&x2, &y2); | |
627 | if ( x ) | |
628 | *x = x2; | |
629 | if ( y ) | |
630 | *y = y2; | |
631 | } | |
632 | ||
633 | void GetDeviceOrigin(long *x, long *y) const | |
634 | { | |
635 | wxCoord x2, y2; | |
636 | DoGetDeviceOrigin(&x2, &y2); | |
637 | if ( x ) | |
638 | *x = x2; | |
639 | if ( y ) | |
640 | *y = y2; | |
641 | } | |
1dd989e1 | 642 | void GetClippingBox(long *x, long *y, long *w, long *h) const |
cd9da200 VZ |
643 | { |
644 | wxCoord xx,yy,ww,hh; | |
645 | DoGetClippingBox(&xx, &yy, &ww, &hh); | |
646 | if (x) *x = xx; | |
647 | if (y) *y = yy; | |
648 | if (w) *w = ww; | |
649 | if (h) *h = hh; | |
1dd989e1 | 650 | } |
72cdf4c9 | 651 | |
a23fd0e1 VZ |
652 | protected: |
653 | // the pure virtual functions which should be implemented by wxDC | |
387ebd3e | 654 | virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, |
a23fd0e1 VZ |
655 | int style = wxFLOOD_SURFACE) = 0; |
656 | ||
213ad8e7 VZ |
657 | virtual void DoGradientFillLinear(const wxRect& rect, |
658 | const wxColour& initialColour, | |
659 | const wxColour& destColour, | |
660 | wxDirection nDirection = wxEAST); | |
4660e6ac | 661 | |
fb63a242 SC |
662 | virtual void DoGradientFillConcentric(const wxRect& rect, |
663 | const wxColour& initialColour, | |
664 | const wxColour& destColour, | |
665 | const wxPoint& circleCenter); | |
666 | ||
72cdf4c9 | 667 | virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const = 0; |
a23fd0e1 | 668 | |
72cdf4c9 VZ |
669 | virtual void DoDrawPoint(wxCoord x, wxCoord y) = 0; |
670 | virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) = 0; | |
a23fd0e1 | 671 | |
72cdf4c9 VZ |
672 | virtual void DoDrawArc(wxCoord x1, wxCoord y1, |
673 | wxCoord x2, wxCoord y2, | |
674 | wxCoord xc, wxCoord yc) = 0; | |
cd9da200 VZ |
675 | virtual void DoDrawCheckMark(wxCoord x, wxCoord y, |
676 | wxCoord width, wxCoord height); | |
72cdf4c9 | 677 | virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, |
a23fd0e1 VZ |
678 | double sa, double ea) = 0; |
679 | ||
72cdf4c9 VZ |
680 | virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) = 0; |
681 | virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y, | |
682 | wxCoord width, wxCoord height, | |
a23fd0e1 | 683 | double radius) = 0; |
72cdf4c9 VZ |
684 | virtual void DoDrawEllipse(wxCoord x, wxCoord y, |
685 | wxCoord width, wxCoord height) = 0; | |
a23fd0e1 | 686 | |
72cdf4c9 | 687 | virtual void DoCrossHair(wxCoord x, wxCoord y) = 0; |
a23fd0e1 | 688 | |
72cdf4c9 VZ |
689 | virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) = 0; |
690 | virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, | |
68379eaf | 691 | bool useMask = false) = 0; |
a23fd0e1 | 692 | |
72cdf4c9 | 693 | virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y) = 0; |
95724b1a VZ |
694 | virtual void DoDrawRotatedText(const wxString& text, |
695 | wxCoord x, wxCoord y, double angle) = 0; | |
a23fd0e1 | 696 | |
72cdf4c9 VZ |
697 | virtual bool DoBlit(wxCoord xdest, wxCoord ydest, |
698 | wxCoord width, wxCoord height, | |
699 | wxDC *source, wxCoord xsrc, wxCoord ysrc, | |
68379eaf | 700 | int rop = wxCOPY, bool useMask = false, wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord) = 0; |
a23fd0e1 VZ |
701 | |
702 | virtual void DoGetSize(int *width, int *height) const = 0; | |
703 | virtual void DoGetSizeMM(int* width, int* height) const = 0; | |
704 | ||
705 | virtual void DoDrawLines(int n, wxPoint points[], | |
72cdf4c9 | 706 | wxCoord xoffset, wxCoord yoffset) = 0; |
a23fd0e1 | 707 | virtual void DoDrawPolygon(int n, wxPoint points[], |
72cdf4c9 | 708 | wxCoord xoffset, wxCoord yoffset, |
a23fd0e1 | 709 | int fillStyle = wxODDEVEN_RULE) = 0; |
793db755 | 710 | virtual void DoDrawPolyPolygon(int n, int count[], wxPoint points[], |
6e76b35d VZ |
711 | wxCoord xoffset, wxCoord yoffset, |
712 | int fillStyle); | |
a23fd0e1 VZ |
713 | |
714 | virtual void DoSetClippingRegionAsRegion(const wxRegion& region) = 0; | |
72cdf4c9 VZ |
715 | virtual void DoSetClippingRegion(wxCoord x, wxCoord y, |
716 | wxCoord width, wxCoord height) = 0; | |
b0e0d661 | 717 | |
c5789d15 WS |
718 | #if WXWIN_COMPATIBILITY_2_4 |
719 | // this was only for confusing people, use DoGetClippingBox only | |
72cdf4c9 VZ |
720 | virtual void DoGetClippingRegion(wxCoord *x, wxCoord *y, |
721 | wxCoord *w, wxCoord *h) | |
b0e0d661 | 722 | { DoGetClippingBox(x, y, w, h); } |
c5789d15 WS |
723 | #endif |
724 | ||
72cdf4c9 VZ |
725 | virtual void DoGetClippingBox(wxCoord *x, wxCoord *y, |
726 | wxCoord *w, wxCoord *h) const | |
a23fd0e1 | 727 | { |
d16b634f VZ |
728 | if ( x ) |
729 | *x = m_clipX1; | |
730 | if ( y ) | |
731 | *y = m_clipY1; | |
732 | if ( w ) | |
733 | *w = m_clipX2 - m_clipX1; | |
734 | if ( h ) | |
735 | *h = m_clipY2 - m_clipY1; | |
a23fd0e1 VZ |
736 | } |
737 | ||
72cdf4c9 | 738 | virtual void DoGetLogicalOrigin(wxCoord *x, wxCoord *y) const |
a23fd0e1 VZ |
739 | { |
740 | if ( x ) *x = m_logicalOriginX; | |
741 | if ( y ) *y = m_logicalOriginY; | |
742 | } | |
743 | ||
72cdf4c9 | 744 | virtual void DoGetDeviceOrigin(wxCoord *x, wxCoord *y) const |
a23fd0e1 VZ |
745 | { |
746 | if ( x ) *x = m_deviceOriginX; | |
747 | if ( y ) *y = m_deviceOriginY; | |
748 | } | |
749 | ||
72cdf4c9 VZ |
750 | virtual void DoGetTextExtent(const wxString& string, |
751 | wxCoord *x, wxCoord *y, | |
752 | wxCoord *descent = NULL, | |
753 | wxCoord *externalLeading = NULL, | |
754 | wxFont *theFont = NULL) const = 0; | |
d16b634f | 755 | |
0919e93e | 756 | virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const; |
d16b634f | 757 | |
64698f9a | 758 | #if wxUSE_SPLINES |
fe2e4366 | 759 | virtual void DoDrawSpline(wxList *points); |
64698f9a | 760 | #endif |
a23fd0e1 VZ |
761 | |
762 | protected: | |
d16b634f VZ |
763 | // unset clipping variables (after clipping region was destroyed) |
764 | void ResetClipping() | |
765 | { | |
766 | m_clipping = false; | |
767 | ||
768 | m_clipX1 = m_clipX2 = m_clipY1 = m_clipY2 = 0; | |
769 | } | |
770 | ||
a23fd0e1 VZ |
771 | // flags |
772 | bool m_colour:1; | |
773 | bool m_ok:1; | |
774 | bool m_clipping:1; | |
775 | bool m_isInteractive:1; | |
f6bcfd97 | 776 | bool m_isBBoxValid:1; |
a23fd0e1 VZ |
777 | |
778 | // coordinate system variables | |
779 | ||
780 | // TODO short descriptions of what exactly they are would be nice... | |
781 | ||
72cdf4c9 VZ |
782 | wxCoord m_logicalOriginX, m_logicalOriginY; |
783 | wxCoord m_deviceOriginX, m_deviceOriginY; | |
a23fd0e1 VZ |
784 | |
785 | double m_logicalScaleX, m_logicalScaleY; | |
786 | double m_userScaleX, m_userScaleY; | |
787 | double m_scaleX, m_scaleY; | |
788 | ||
789 | // Used by SetAxisOrientation() to invert the axes | |
790 | int m_signX, m_signY; | |
791 | ||
792 | // bounding and clipping boxes | |
72cdf4c9 VZ |
793 | wxCoord m_minX, m_minY, m_maxX, m_maxY; |
794 | wxCoord m_clipX1, m_clipY1, m_clipX2, m_clipY2; | |
a23fd0e1 VZ |
795 | |
796 | int m_logicalFunction; | |
797 | int m_backgroundMode; | |
798 | int m_mappingMode; | |
799 | ||
800 | // GDI objects | |
801 | wxPen m_pen; | |
802 | wxBrush m_brush; | |
803 | wxBrush m_backgroundBrush; | |
804 | wxColour m_textForegroundColour; | |
805 | wxColour m_textBackgroundColour; | |
806 | wxFont m_font; | |
d275c7eb VZ |
807 | |
808 | #if wxUSE_PALETTE | |
a23fd0e1 | 809 | wxPalette m_palette; |
b95edd47 | 810 | bool m_hasCustomPalette; |
d275c7eb | 811 | #endif // wxUSE_PALETTE |
a23fd0e1 VZ |
812 | |
813 | private: | |
ac84e37d | 814 | DECLARE_NO_COPY_CLASS(wxDCBase) |
cd9da200 | 815 | DECLARE_ABSTRACT_CLASS(wxDCBase) |
a23fd0e1 VZ |
816 | }; |
817 | ||
818 | // ---------------------------------------------------------------------------- | |
819 | // now include the declaration of wxDC class | |
820 | // ---------------------------------------------------------------------------- | |
821 | ||
4055ed82 | 822 | #if defined(__WXPALMOS__) |
ffecfa5a JS |
823 | #include "wx/palmos/dc.h" |
824 | #elif defined(__WXMSW__) | |
a23fd0e1 | 825 | #include "wx/msw/dc.h" |
2049ba38 | 826 | #elif defined(__WXMOTIF__) |
a23fd0e1 | 827 | #include "wx/motif/dc.h" |
1be7a35c | 828 | #elif defined(__WXGTK20__) |
a23fd0e1 | 829 | #include "wx/gtk/dc.h" |
1be7a35c MR |
830 | #elif defined(__WXGTK__) |
831 | #include "wx/gtk1/dc.h" | |
83df96d6 JS |
832 | #elif defined(__WXX11__) |
833 | #include "wx/x11/dc.h" | |
1e6feb95 VZ |
834 | #elif defined(__WXMGL__) |
835 | #include "wx/mgl/dc.h" | |
b3c86150 VS |
836 | #elif defined(__WXDFB__) |
837 | #include "wx/dfb/dc.h" | |
34138703 | 838 | #elif defined(__WXMAC__) |
a23fd0e1 | 839 | #include "wx/mac/dc.h" |
f4515f98 DE |
840 | #elif defined(__WXCOCOA__) |
841 | #include "wx/cocoa/dc.h" | |
1777b9bb DW |
842 | #elif defined(__WXPM__) |
843 | #include "wx/os2/dc.h" | |
c801d85f KB |
844 | #endif |
845 | ||
1e6feb95 VZ |
846 | // ---------------------------------------------------------------------------- |
847 | // helper class: you can use it to temporarily change the DC text colour and | |
848 | // restore it automatically when the object goes out of scope | |
849 | // ---------------------------------------------------------------------------- | |
850 | ||
851 | class WXDLLEXPORT wxDCTextColourChanger | |
852 | { | |
853 | public: | |
ba161d7e | 854 | wxDCTextColourChanger(wxDC& dc) : m_dc(dc), m_colFgOld() { } |
1e6feb95 VZ |
855 | |
856 | ~wxDCTextColourChanger() | |
857 | { | |
858 | if ( m_colFgOld.Ok() ) | |
859 | m_dc.SetTextForeground(m_colFgOld); | |
860 | } | |
861 | ||
862 | void Set(const wxColour& col) | |
863 | { | |
864 | if ( !m_colFgOld.Ok() ) | |
865 | m_colFgOld = m_dc.GetTextForeground(); | |
866 | m_dc.SetTextForeground(col); | |
867 | } | |
868 | ||
869 | private: | |
870 | wxDC& m_dc; | |
871 | ||
872 | wxColour m_colFgOld; | |
fc7a2a60 VZ |
873 | |
874 | DECLARE_NO_COPY_CLASS(wxDCTextColourChanger) | |
1e6feb95 VZ |
875 | }; |
876 | ||
4660e6ac WS |
877 | // ---------------------------------------------------------------------------- |
878 | // helper class: you can use it to temporarily change the DC pen and | |
879 | // restore it automatically when the object goes out of scope | |
880 | // ---------------------------------------------------------------------------- | |
881 | ||
882 | class WXDLLEXPORT wxDCPenChanger | |
883 | { | |
884 | public: | |
0164f8eb WS |
885 | wxDCPenChanger(wxDC& dc, const wxPen& pen) : m_dc(dc), m_penOld(dc.GetPen()) |
886 | { | |
887 | m_dc.SetPen(pen); | |
888 | } | |
4660e6ac WS |
889 | |
890 | ~wxDCPenChanger() | |
891 | { | |
892 | if ( m_penOld.Ok() ) | |
893 | m_dc.SetPen(m_penOld); | |
894 | } | |
895 | ||
4660e6ac WS |
896 | private: |
897 | wxDC& m_dc; | |
898 | ||
899 | wxPen m_penOld; | |
900 | ||
901 | DECLARE_NO_COPY_CLASS(wxDCPenChanger) | |
902 | }; | |
903 | ||
904 | // ---------------------------------------------------------------------------- | |
905 | // helper class: you can use it to temporarily change the DC brush and | |
906 | // restore it automatically when the object goes out of scope | |
907 | // ---------------------------------------------------------------------------- | |
908 | ||
909 | class WXDLLEXPORT wxDCBrushChanger | |
910 | { | |
911 | public: | |
0164f8eb WS |
912 | wxDCBrushChanger(wxDC& dc, const wxBrush& brush) : m_dc(dc), m_brushOld(dc.GetBrush()) |
913 | { | |
914 | m_dc.SetBrush(brush); | |
915 | } | |
4660e6ac WS |
916 | |
917 | ~wxDCBrushChanger() | |
918 | { | |
919 | if ( m_brushOld.Ok() ) | |
920 | m_dc.SetBrush(m_brushOld); | |
921 | } | |
922 | ||
4660e6ac WS |
923 | private: |
924 | wxDC& m_dc; | |
925 | ||
926 | wxBrush m_brushOld; | |
927 | ||
928 | DECLARE_NO_COPY_CLASS(wxDCBrushChanger) | |
929 | }; | |
930 | ||
e26be42b VZ |
931 | // ---------------------------------------------------------------------------- |
932 | // another small helper class: sets the clipping region in its ctor and | |
933 | // destroys it in the dtor | |
934 | // ---------------------------------------------------------------------------- | |
935 | ||
936 | class WXDLLEXPORT wxDCClipper | |
937 | { | |
938 | public: | |
fc298ea7 VZ |
939 | wxDCClipper(wxDC& dc, const wxRegion& r) : m_dc(dc) |
940 | { dc.SetClippingRegion(r); } | |
e26be42b VZ |
941 | wxDCClipper(wxDC& dc, const wxRect& r) : m_dc(dc) |
942 | { dc.SetClippingRegion(r.x, r.y, r.width, r.height); } | |
943 | wxDCClipper(wxDC& dc, wxCoord x, wxCoord y, wxCoord w, wxCoord h) : m_dc(dc) | |
944 | { dc.SetClippingRegion(x, y, w, h); } | |
945 | ||
946 | ~wxDCClipper() { m_dc.DestroyClippingRegion(); } | |
947 | ||
948 | private: | |
949 | wxDC& m_dc; | |
fc7a2a60 VZ |
950 | |
951 | DECLARE_NO_COPY_CLASS(wxDCClipper) | |
e26be42b VZ |
952 | }; |
953 | ||
c801d85f | 954 | #endif |
34138703 | 955 | // _WX_DC_H_BASE_ |