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