1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Vadim Zeitlin
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_DC_H_BASE_
13 #define _WX_DC_H_BASE_
15 // ----------------------------------------------------------------------------
16 // headers which we must include here
17 // ----------------------------------------------------------------------------
19 #include "wx/object.h" // the base class
21 #include "wx/intl.h" // for wxLayoutDirection
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"
25 #include "wx/bitmap.h" // for wxNullBitmap
28 #include "wx/palette.h"
29 #include "wx/list.h" // we use wxList in inline functions
30 #include "wx/dynarray.h"
33 class WXDLLEXPORT wxDC
;
34 class WXDLLEXPORT wxDCBase
;
36 class WXDLLEXPORT wxDrawObject
41 : m_isBBoxValid(false)
42 , m_minX(0), m_minY(0), m_maxX(0), m_maxY(0)
45 virtual ~wxDrawObject() { }
47 virtual void Draw(wxDCBase
&) const { }
49 virtual void CalcBoundingBox(wxCoord x
, wxCoord y
)
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
;
69 void ResetBoundingBox()
71 m_isBBoxValid
= false;
73 m_minX
= m_maxX
= m_minY
= m_maxY
= 0;
76 // Get the final bounding box of the PostScript or Metafile picture.
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
; }
83 //to define the type of object for derived objects
84 virtual int GetType()=0;
87 //for boundingbox calculation
89 //for boundingbox calculation
90 wxCoord m_minX
, m_minY
, m_maxX
, m_maxY
;
93 // ---------------------------------------------------------------------------
95 // ---------------------------------------------------------------------------
97 // ---------------------------------------------------------------------------
98 // wxDC is the device context - object on which any drawing is done
99 // ---------------------------------------------------------------------------
101 class WXDLLEXPORT wxDCBase
: public wxObject
105 : m_colour(wxColourDisplay())
109 , m_isBBoxValid(false)
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
)
123 , m_backgroundBrush(*wxTRANSPARENT_BRUSH
)
124 , m_textForegroundColour(*wxBLACK
)
125 , m_textBackgroundColour(*wxWHITE
)
129 , m_hasCustomPalette(false)
130 #endif // wxUSE_PALETTE
136 virtual ~wxDCBase() { }
138 // graphic primitives
139 // ------------------
141 virtual void DrawObject(wxDrawObject
* drawobject
)
143 drawobject
->Draw(*this);
144 CalcBoundingBox(drawobject
->MinX(),drawobject
->MinY());
145 CalcBoundingBox(drawobject
->MaxX(),drawobject
->MaxY());
148 bool FloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
149 int style
= wxFLOOD_SURFACE
)
150 { return DoFloodFill(x
, y
, col
, style
); }
151 bool FloodFill(const wxPoint
& pt
, const wxColour
& col
,
152 int style
= wxFLOOD_SURFACE
)
153 { return DoFloodFill(pt
.x
, pt
.y
, col
, style
); }
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
,
158 const wxColour
& initialColour
,
159 const wxColour
& destColour
)
160 { GradientFillConcentric(rect
, initialColour
, destColour
,
161 wxPoint(rect
.GetWidth() / 2,
162 rect
.GetHeight() / 2)); }
164 void GradientFillConcentric(const wxRect
& rect
,
165 const wxColour
& initialColour
,
166 const wxColour
& destColour
,
167 const wxPoint
& circleCenter
)
168 { DoGradientFillConcentric(rect
, initialColour
, destColour
, circleCenter
); }
170 // fill the area specified by rect with a linear gradient
171 void GradientFillLinear(const wxRect
& rect
,
172 const wxColour
& initialColour
,
173 const wxColour
& destColour
,
174 wxDirection nDirection
= wxEAST
)
175 { DoGradientFillLinear(rect
, initialColour
, destColour
, nDirection
); }
177 bool GetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const
178 { return DoGetPixel(x
, y
, col
); }
179 bool GetPixel(const wxPoint
& pt
, wxColour
*col
) const
180 { return DoGetPixel(pt
.x
, pt
.y
, col
); }
182 void DrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
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
); }
187 void CrossHair(wxCoord x
, wxCoord y
)
188 { DoCrossHair(x
, y
); }
189 void CrossHair(const wxPoint
& pt
)
190 { DoCrossHair(pt
.x
, pt
.y
); }
192 void DrawArc(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
,
193 wxCoord xc
, wxCoord yc
)
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
); }
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
); }
204 void DrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
205 double sa
, double ea
)
206 { DoDrawEllipticArc(x
, y
, w
, h
, sa
, ea
); }
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
); }
211 void DrawPoint(wxCoord x
, wxCoord y
)
212 { DoDrawPoint(x
, y
); }
213 void DrawPoint(const wxPoint
& pt
)
214 { DoDrawPoint(pt
.x
, pt
.y
); }
216 void DrawLines(int n
, wxPoint points
[],
217 wxCoord xoffset
= 0, wxCoord yoffset
= 0)
218 { DoDrawLines(n
, points
, xoffset
, yoffset
); }
219 void DrawLines(const wxList
*list
,
220 wxCoord xoffset
= 0, wxCoord yoffset
= 0);
222 void DrawPolygon(int n
, wxPoint points
[],
223 wxCoord xoffset
= 0, wxCoord yoffset
= 0,
224 int fillStyle
= wxODDEVEN_RULE
)
225 { DoDrawPolygon(n
, points
, xoffset
, yoffset
, fillStyle
); }
227 void DrawPolygon(const wxList
*list
,
228 wxCoord xoffset
= 0, wxCoord yoffset
= 0,
229 int fillStyle
= wxODDEVEN_RULE
);
231 void DrawPolyPolygon(int n
, int count
[], wxPoint points
[],
232 wxCoord xoffset
= 0, wxCoord yoffset
= 0,
233 int fillStyle
= wxODDEVEN_RULE
)
234 { DoDrawPolyPolygon(n
, count
, points
, xoffset
, yoffset
, fillStyle
); }
236 void DrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
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
); }
243 void DrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
,
245 { DoDrawRoundedRectangle(x
, y
, width
, height
, radius
); }
246 void DrawRoundedRectangle(const wxPoint
& pt
, const wxSize
& sz
,
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
); }
252 void DrawCircle(wxCoord x
, wxCoord y
, wxCoord radius
)
253 { DoDrawEllipse(x
- radius
, y
- radius
, 2*radius
, 2*radius
); }
254 void DrawCircle(const wxPoint
& pt
, wxCoord radius
)
255 { DrawCircle(pt
.x
, pt
.y
, radius
); }
257 void DrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
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
); }
264 void DrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
)
265 { DoDrawIcon(icon
, x
, y
); }
266 void DrawIcon(const wxIcon
& icon
, const wxPoint
& pt
)
267 { DoDrawIcon(icon
, pt
.x
, pt
.y
); }
269 void DrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
270 bool useMask
= false)
271 { DoDrawBitmap(bmp
, x
, y
, useMask
); }
272 void DrawBitmap(const wxBitmap
&bmp
, const wxPoint
& pt
,
273 bool useMask
= false)
274 { DoDrawBitmap(bmp
, pt
.x
, pt
.y
, useMask
); }
276 void DrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
277 { DoDrawText(text
, x
, y
); }
278 void DrawText(const wxString
& text
, const wxPoint
& pt
)
279 { DoDrawText(text
, pt
.x
, pt
.y
); }
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
); }
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
,
293 int alignment
= wxALIGN_LEFT
| wxALIGN_TOP
,
295 wxRect
*rectBounding
= NULL
);
297 void DrawLabel(const wxString
& text
, const wxRect
& rect
,
298 int alignment
= wxALIGN_LEFT
| wxALIGN_TOP
,
300 { DrawLabel(text
, wxNullBitmap
, rect
, alignment
, indexAccel
); }
302 bool Blit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
303 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
304 int rop
= wxCOPY
, bool useMask
= false, wxCoord xsrcMask
= wxDefaultCoord
, wxCoord ysrcMask
= wxDefaultCoord
)
306 return DoBlit(xdest
, ydest
, width
, height
,
307 source
, xsrc
, ysrc
, rop
, useMask
, xsrcMask
, ysrcMask
);
309 bool Blit(const wxPoint
& destPt
, const wxSize
& sz
,
310 wxDC
*source
, const wxPoint
& srcPt
,
311 int rop
= wxCOPY
, bool useMask
= false, const wxPoint
& srcPtMask
= wxDefaultPosition
)
313 return DoBlit(destPt
.x
, destPt
.y
, sz
.x
, sz
.y
,
314 source
, srcPt
.x
, srcPt
.y
, rop
, useMask
, srcPtMask
.x
, srcPtMask
.y
);
317 wxBitmap
GetAsBitmap(const wxRect
*subrect
= (const wxRect
*) NULL
) const
319 return DoGetAsBitmap(subrect
);
323 // TODO: this API needs fixing (wxPointList, why (!const) "wxList *"?)
324 void DrawSpline(wxCoord x1
, wxCoord y1
,
325 wxCoord x2
, wxCoord y2
,
326 wxCoord x3
, wxCoord y3
);
327 void DrawSpline(int n
, wxPoint points
[]);
329 void DrawSpline(wxList
*points
) { DoDrawSpline(points
); }
330 #endif // wxUSE_SPLINES
332 // Eventually we will have wxUSE_GENERIC_DRAWELLIPSE
334 //! Generic method to draw ellipses, circles and arcs with current pen and brush.
335 /*! \param x Upper left corner of bounding box.
336 * \param y Upper left corner of bounding box.
337 * \param w Width of bounding box.
338 * \param h Height of bounding box.
339 * \param sa Starting angle of arc
340 * (counterclockwise, start at 3 o'clock, 360 is full circle).
341 * \param ea Ending angle of arc.
342 * \param angle Rotation angle, the Arc will be rotated after
343 * calculating begin and end.
345 void DrawEllipticArcRot( wxCoord x
, wxCoord y
,
346 wxCoord width
, wxCoord height
,
347 double sa
= 0, double ea
= 0, double angle
= 0 )
348 { DoDrawEllipticArcRot( x
, y
, width
, height
, sa
, ea
, angle
); }
350 void DrawEllipticArcRot( const wxPoint
& pt
,
352 double sa
= 0, double ea
= 0, double angle
= 0 )
353 { DoDrawEllipticArcRot( pt
.x
, pt
.y
, sz
.x
, sz
.y
, sa
, ea
, angle
); }
355 void DrawEllipticArcRot( const wxRect
& rect
,
356 double sa
= 0, double ea
= 0, double angle
= 0 )
357 { DoDrawEllipticArcRot( rect
.x
, rect
.y
, rect
.width
, rect
.height
, sa
, ea
, angle
); }
359 virtual void DoDrawEllipticArcRot( wxCoord x
, wxCoord y
,
360 wxCoord w
, wxCoord h
,
361 double sa
= 0, double ea
= 0, double angle
= 0 );
363 //! Rotates points around center.
364 /*! This is a quite straight method, it calculates in pixels
365 * and so it produces rounding errors.
366 * \param points The points inside will be rotated.
367 * \param angle Rotating angle (counterclockwise, start at 3 o'clock, 360 is full circle).
368 * \param center Center of rotation.
370 void Rotate( wxList
* points
, double angle
, wxPoint center
= wxPoint(0,0) );
372 // used by DrawEllipticArcRot
373 // Careful: wxList gets filled with points you have to delete later.
374 void CalculateEllipticPoints( wxList
* points
,
375 wxCoord xStart
, wxCoord yStart
,
376 wxCoord w
, wxCoord h
,
377 double sa
, double ea
);
380 // global DC operations
381 // --------------------
383 virtual void Clear() = 0;
385 virtual bool StartDoc(const wxString
& WXUNUSED(message
)) { return true; }
386 virtual void EndDoc() { }
388 virtual void StartPage() { }
389 virtual void EndPage() { }
391 #if WXWIN_COMPATIBILITY_2_6
392 wxDEPRECATED( void BeginDrawing() );
393 wxDEPRECATED( void EndDrawing() );
394 #endif // WXWIN_COMPATIBILITY_2_6
397 // set objects to use for drawing
398 // ------------------------------
400 virtual void SetFont(const wxFont
& font
) = 0;
401 virtual void SetPen(const wxPen
& pen
) = 0;
402 virtual void SetBrush(const wxBrush
& brush
) = 0;
403 virtual void SetBackground(const wxBrush
& brush
) = 0;
404 virtual void SetBackgroundMode(int mode
) = 0;
406 virtual void SetPalette(const wxPalette
& palette
) = 0;
407 #endif // wxUSE_PALETTE
412 void SetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
413 { DoSetClippingRegion(x
, y
, width
, height
); }
414 void SetClippingRegion(const wxPoint
& pt
, const wxSize
& sz
)
415 { DoSetClippingRegion(pt
.x
, pt
.y
, sz
.x
, sz
.y
); }
416 void SetClippingRegion(const wxRect
& rect
)
417 { DoSetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
418 void SetClippingRegion(const wxRegion
& region
)
419 { DoSetClippingRegionAsRegion(region
); }
421 virtual void DestroyClippingRegion() { ResetClipping(); }
423 void GetClippingBox(wxCoord
*x
, wxCoord
*y
, wxCoord
*w
, wxCoord
*h
) const
424 { DoGetClippingBox(x
, y
, w
, h
); }
425 void GetClippingBox(wxRect
& rect
) const
427 DoGetClippingBox(&rect
.x
, &rect
.y
, &rect
.width
, &rect
.height
);
433 virtual wxCoord
GetCharHeight() const = 0;
434 virtual wxCoord
GetCharWidth() const = 0;
436 // only works for single line strings
437 void GetTextExtent(const wxString
& string
,
438 wxCoord
*x
, wxCoord
*y
,
439 wxCoord
*descent
= NULL
,
440 wxCoord
*externalLeading
= NULL
,
441 wxFont
*theFont
= NULL
) const
442 { DoGetTextExtent(string
, x
, y
, descent
, externalLeading
, theFont
); }
444 wxSize
GetTextExtent(const wxString
& string
) const
447 DoGetTextExtent(string
, &w
, &h
);
451 // works for single as well as multi-line strings
452 virtual void GetMultiLineTextExtent(const wxString
& string
,
455 wxCoord
*heightLine
= NULL
,
456 wxFont
*font
= NULL
) const;
458 wxSize
GetMultiLineTextExtent(const wxString
& string
) const
461 GetMultiLineTextExtent(string
, &w
, &h
);
465 // Measure cumulative width of text after each character
466 bool GetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
467 { return DoGetPartialTextExtents(text
, widths
); }
470 // size and resolution
471 // -------------------
474 void GetSize(int *width
, int *height
) const
475 { DoGetSize(width
, height
); }
476 wxSize
GetSize() const
485 void GetSizeMM(int* width
, int* height
) const
486 { DoGetSizeMM(width
, height
); }
487 wxSize
GetSizeMM() const
495 // coordinates conversions
496 // -----------------------
498 // This group of functions does actual conversion of the input, as you'd
500 wxCoord
DeviceToLogicalX(wxCoord x
) const;
501 wxCoord
DeviceToLogicalY(wxCoord y
) const;
502 wxCoord
DeviceToLogicalXRel(wxCoord x
) const;
503 wxCoord
DeviceToLogicalYRel(wxCoord y
) const;
504 wxCoord
LogicalToDeviceX(wxCoord x
) const;
505 wxCoord
LogicalToDeviceY(wxCoord y
) const;
506 wxCoord
LogicalToDeviceXRel(wxCoord x
) const;
507 wxCoord
LogicalToDeviceYRel(wxCoord y
) const;
509 // query DC capabilities
510 // ---------------------
512 virtual bool CanDrawBitmap() const = 0;
513 virtual bool CanGetTextExtent() const = 0;
516 virtual int GetDepth() const = 0;
518 // Resolution in Pixels per inch
519 virtual wxSize
GetPPI() const = 0;
521 virtual bool Ok() const { return IsOk(); }
522 virtual bool IsOk() const { return m_ok
; }
524 // accessors and setters
525 // ---------------------
527 virtual int GetBackgroundMode() const { return m_backgroundMode
; }
528 virtual const wxBrush
& GetBackground() const { return m_backgroundBrush
; }
529 virtual const wxBrush
& GetBrush() const { return m_brush
; }
530 virtual const wxFont
& GetFont() const { return m_font
; }
531 virtual const wxPen
& GetPen() const { return m_pen
; }
533 virtual const wxColour
& GetTextForeground() const { return m_textForegroundColour
; }
534 virtual const wxColour
& GetTextBackground() const { return m_textBackgroundColour
; }
535 virtual void SetTextForeground(const wxColour
& colour
)
536 { m_textForegroundColour
= colour
; }
537 virtual void SetTextBackground(const wxColour
& colour
)
538 { m_textBackgroundColour
= colour
; }
540 virtual int GetMapMode() const { return m_mappingMode
; }
541 virtual void SetMapMode(int mode
) = 0;
543 virtual void GetUserScale(double *x
, double *y
) const
545 if ( x
) *x
= m_userScaleX
;
546 if ( y
) *y
= m_userScaleY
;
548 virtual void SetUserScale(double x
, double y
) = 0;
550 virtual void GetLogicalScale(double *x
, double *y
)
552 if ( x
) *x
= m_logicalScaleX
;
553 if ( y
) *y
= m_logicalScaleY
;
555 virtual void SetLogicalScale(double x
, double y
)
561 void GetLogicalOrigin(wxCoord
*x
, wxCoord
*y
) const
562 { DoGetLogicalOrigin(x
, y
); }
563 wxPoint
GetLogicalOrigin() const
564 { wxCoord x
, y
; DoGetLogicalOrigin(&x
, &y
); return wxPoint(x
, y
); }
565 virtual void SetLogicalOrigin(wxCoord x
, wxCoord y
) = 0;
567 void GetDeviceOrigin(wxCoord
*x
, wxCoord
*y
) const
568 { DoGetDeviceOrigin(x
, y
); }
569 wxPoint
GetDeviceOrigin() const
570 { wxCoord x
, y
; DoGetDeviceOrigin(&x
, &y
); return wxPoint(x
, y
); }
571 virtual void SetDeviceOrigin(wxCoord x
, wxCoord y
) = 0;
573 virtual void ComputeScaleAndOrigin() {}
575 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
) = 0;
577 virtual int GetLogicalFunction() const { return m_logicalFunction
; }
578 virtual void SetLogicalFunction(int function
) = 0;
583 virtual void CalcBoundingBox(wxCoord x
, wxCoord y
)
587 if ( x
< m_minX
) m_minX
= x
;
588 if ( y
< m_minY
) m_minY
= y
;
589 if ( x
> m_maxX
) m_maxX
= x
;
590 if ( y
> m_maxY
) m_maxY
= y
;
594 m_isBBoxValid
= true;
603 void ResetBoundingBox()
605 m_isBBoxValid
= false;
607 m_minX
= m_maxX
= m_minY
= m_maxY
= 0;
610 // Get the final bounding box of the PostScript or Metafile picture.
611 wxCoord
MinX() const { return m_minX
; }
612 wxCoord
MaxX() const { return m_maxX
; }
613 wxCoord
MinY() const { return m_minY
; }
614 wxCoord
MaxY() const { return m_maxY
; }
616 // misc old functions
617 // ------------------
619 // for compatibility with the old code when wxCoord was long everywhere
620 void GetTextExtent(const wxString
& string
,
622 long *descent
= NULL
,
623 long *externalLeading
= NULL
,
624 wxFont
*theFont
= NULL
) const
626 wxCoord x2
, y2
, descent2
, externalLeading2
;
627 DoGetTextExtent(string
, &x2
, &y2
,
628 &descent2
, &externalLeading2
,
636 if ( externalLeading
)
637 *externalLeading
= externalLeading2
;
640 void GetLogicalOrigin(long *x
, long *y
) const
643 DoGetLogicalOrigin(&x2
, &y2
);
650 void GetDeviceOrigin(long *x
, long *y
) const
653 DoGetDeviceOrigin(&x2
, &y2
);
659 void GetClippingBox(long *x
, long *y
, long *w
, long *h
) const
662 DoGetClippingBox(&xx
, &yy
, &ww
, &hh
);
669 // RTL related functions
670 // ---------------------
672 // get or change the layout direction (LTR or RTL) for this dc,
673 // wxLayout_Default is returned if layout direction is not supported
674 virtual wxLayoutDirection
GetLayoutDirection() const
675 { return wxLayout_Default
; }
676 virtual void SetLayoutDirection(wxLayoutDirection
WXUNUSED(dir
))
680 // the pure virtual functions which should be implemented by wxDC
681 virtual bool DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
682 int style
= wxFLOOD_SURFACE
) = 0;
684 virtual void DoGradientFillLinear(const wxRect
& rect
,
685 const wxColour
& initialColour
,
686 const wxColour
& destColour
,
687 wxDirection nDirection
= wxEAST
);
689 virtual void DoGradientFillConcentric(const wxRect
& rect
,
690 const wxColour
& initialColour
,
691 const wxColour
& destColour
,
692 const wxPoint
& circleCenter
);
694 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const = 0;
696 virtual void DoDrawPoint(wxCoord x
, wxCoord y
) = 0;
697 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
) = 0;
699 virtual void DoDrawArc(wxCoord x1
, wxCoord y1
,
700 wxCoord x2
, wxCoord y2
,
701 wxCoord xc
, wxCoord yc
) = 0;
702 virtual void DoDrawCheckMark(wxCoord x
, wxCoord y
,
703 wxCoord width
, wxCoord height
);
704 virtual void DoDrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
705 double sa
, double ea
) = 0;
707 virtual void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
) = 0;
708 virtual void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
709 wxCoord width
, wxCoord height
,
711 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
,
712 wxCoord width
, wxCoord height
) = 0;
714 virtual void DoCrossHair(wxCoord x
, wxCoord y
) = 0;
716 virtual void DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
) = 0;
717 virtual void DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
718 bool useMask
= false) = 0;
720 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
) = 0;
721 virtual void DoDrawRotatedText(const wxString
& text
,
722 wxCoord x
, wxCoord y
, double angle
) = 0;
724 virtual bool DoBlit(wxCoord xdest
, wxCoord ydest
,
725 wxCoord width
, wxCoord height
,
726 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
727 int rop
= wxCOPY
, bool useMask
= false, wxCoord xsrcMask
= wxDefaultCoord
, wxCoord ysrcMask
= wxDefaultCoord
) = 0;
729 virtual wxBitmap
DoGetAsBitmap(const wxRect
*WXUNUSED(subrect
)) const { return wxNullBitmap
; }
731 virtual void DoGetSize(int *width
, int *height
) const = 0;
732 virtual void DoGetSizeMM(int* width
, int* height
) const = 0;
734 virtual void DoDrawLines(int n
, wxPoint points
[],
735 wxCoord xoffset
, wxCoord yoffset
) = 0;
736 virtual void DoDrawPolygon(int n
, wxPoint points
[],
737 wxCoord xoffset
, wxCoord yoffset
,
738 int fillStyle
= wxODDEVEN_RULE
) = 0;
739 virtual void DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[],
740 wxCoord xoffset
, wxCoord yoffset
,
743 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
) = 0;
744 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
745 wxCoord width
, wxCoord height
) = 0;
747 virtual void DoGetClippingBox(wxCoord
*x
, wxCoord
*y
,
748 wxCoord
*w
, wxCoord
*h
) const
755 *w
= m_clipX2
- m_clipX1
;
757 *h
= m_clipY2
- m_clipY1
;
760 virtual void DoGetLogicalOrigin(wxCoord
*x
, wxCoord
*y
) const
762 if ( x
) *x
= m_logicalOriginX
;
763 if ( y
) *y
= m_logicalOriginY
;
766 virtual void DoGetDeviceOrigin(wxCoord
*x
, wxCoord
*y
) const
768 if ( x
) *x
= m_deviceOriginX
;
769 if ( y
) *y
= m_deviceOriginY
;
772 virtual void DoGetTextExtent(const wxString
& string
,
773 wxCoord
*x
, wxCoord
*y
,
774 wxCoord
*descent
= NULL
,
775 wxCoord
*externalLeading
= NULL
,
776 wxFont
*theFont
= NULL
) const = 0;
778 virtual bool DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const;
781 virtual void DoDrawSpline(wxList
*points
);
785 // unset clipping variables (after clipping region was destroyed)
790 m_clipX1
= m_clipX2
= m_clipY1
= m_clipY2
= 0;
797 bool m_isInteractive
:1;
798 bool m_isBBoxValid
:1;
800 // coordinate system variables
802 // TODO short descriptions of what exactly they are would be nice...
804 wxCoord m_logicalOriginX
, m_logicalOriginY
;
805 wxCoord m_deviceOriginX
, m_deviceOriginY
;
807 double m_logicalScaleX
, m_logicalScaleY
;
808 double m_userScaleX
, m_userScaleY
;
809 double m_scaleX
, m_scaleY
;
811 // Used by SetAxisOrientation() to invert the axes
812 int m_signX
, m_signY
;
814 // bounding and clipping boxes
815 wxCoord m_minX
, m_minY
, m_maxX
, m_maxY
;
816 wxCoord m_clipX1
, m_clipY1
, m_clipX2
, m_clipY2
;
818 int m_logicalFunction
;
819 int m_backgroundMode
;
825 wxBrush m_backgroundBrush
;
826 wxColour m_textForegroundColour
;
827 wxColour m_textBackgroundColour
;
832 bool m_hasCustomPalette
;
833 #endif // wxUSE_PALETTE
836 DECLARE_NO_COPY_CLASS(wxDCBase
)
837 DECLARE_ABSTRACT_CLASS(wxDCBase
)
840 // ----------------------------------------------------------------------------
841 // now include the declaration of wxDC class
842 // ----------------------------------------------------------------------------
844 #if defined(__WXPALMOS__)
845 #include "wx/palmos/dc.h"
846 #elif defined(__WXMSW__)
847 #include "wx/msw/dc.h"
848 #elif defined(__WXMOTIF__)
849 #include "wx/motif/dc.h"
850 #elif defined(__WXGTK20__)
851 #include "wx/gtk/dc.h"
852 #elif defined(__WXGTK__)
853 #include "wx/gtk1/dc.h"
854 #elif defined(__WXX11__)
855 #include "wx/x11/dc.h"
856 #elif defined(__WXMGL__)
857 #include "wx/mgl/dc.h"
858 #elif defined(__WXDFB__)
859 #include "wx/dfb/dc.h"
860 #elif defined(__WXMAC__)
861 #include "wx/mac/dc.h"
862 #elif defined(__WXCOCOA__)
863 #include "wx/cocoa/dc.h"
864 #elif defined(__WXPM__)
865 #include "wx/os2/dc.h"
868 #if wxUSE_GRAPHICS_CONTEXT
869 #include "wx/dcgraph.h"
872 // ----------------------------------------------------------------------------
873 // helper class: you can use it to temporarily change the DC text colour and
874 // restore it automatically when the object goes out of scope
875 // ----------------------------------------------------------------------------
877 class WXDLLEXPORT wxDCTextColourChanger
880 wxDCTextColourChanger(wxDC
& dc
) : m_dc(dc
), m_colFgOld() { }
882 wxDCTextColourChanger(wxDC
& dc
, const wxColour
& col
) : m_dc(dc
)
887 ~wxDCTextColourChanger()
889 if ( m_colFgOld
.Ok() )
890 m_dc
.SetTextForeground(m_colFgOld
);
893 void Set(const wxColour
& col
)
895 if ( !m_colFgOld
.Ok() )
896 m_colFgOld
= m_dc
.GetTextForeground();
897 m_dc
.SetTextForeground(col
);
905 DECLARE_NO_COPY_CLASS(wxDCTextColourChanger
)
908 // ----------------------------------------------------------------------------
909 // helper class: you can use it to temporarily change the DC pen and
910 // restore it automatically when the object goes out of scope
911 // ----------------------------------------------------------------------------
913 class WXDLLEXPORT wxDCPenChanger
916 wxDCPenChanger(wxDC
& dc
, const wxPen
& pen
) : m_dc(dc
), m_penOld(dc
.GetPen())
924 m_dc
.SetPen(m_penOld
);
932 DECLARE_NO_COPY_CLASS(wxDCPenChanger
)
935 // ----------------------------------------------------------------------------
936 // helper class: you can use it to temporarily change the DC brush and
937 // restore it automatically when the object goes out of scope
938 // ----------------------------------------------------------------------------
940 class WXDLLEXPORT wxDCBrushChanger
943 wxDCBrushChanger(wxDC
& dc
, const wxBrush
& brush
) : m_dc(dc
), m_brushOld(dc
.GetBrush())
945 m_dc
.SetBrush(brush
);
950 if ( m_brushOld
.Ok() )
951 m_dc
.SetBrush(m_brushOld
);
959 DECLARE_NO_COPY_CLASS(wxDCBrushChanger
)
962 // ----------------------------------------------------------------------------
963 // another small helper class: sets the clipping region in its ctor and
964 // destroys it in the dtor
965 // ----------------------------------------------------------------------------
967 class WXDLLEXPORT wxDCClipper
970 wxDCClipper(wxDC
& dc
, const wxRegion
& r
) : m_dc(dc
)
971 { dc
.SetClippingRegion(r
); }
972 wxDCClipper(wxDC
& dc
, const wxRect
& r
) : m_dc(dc
)
973 { dc
.SetClippingRegion(r
.x
, r
.y
, r
.width
, r
.height
); }
974 wxDCClipper(wxDC
& dc
, wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
) : m_dc(dc
)
975 { dc
.SetClippingRegion(x
, y
, w
, h
); }
977 ~wxDCClipper() { m_dc
.DestroyClippingRegion(); }
982 DECLARE_NO_COPY_CLASS(wxDCClipper
)
985 #endif // _WX_DC_H_BASE_