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
107 // graphic primitives
108 // ------------------
110 virtual void DrawObject(wxDrawObject
* drawobject
)
112 drawobject
->Draw(*this);
113 CalcBoundingBox(drawobject
->MinX(),drawobject
->MinY());
114 CalcBoundingBox(drawobject
->MaxX(),drawobject
->MaxY());
117 bool FloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
118 int style
= wxFLOOD_SURFACE
)
119 { return DoFloodFill(x
, y
, col
, style
); }
120 bool FloodFill(const wxPoint
& pt
, const wxColour
& col
,
121 int style
= wxFLOOD_SURFACE
)
122 { return DoFloodFill(pt
.x
, pt
.y
, col
, style
); }
124 // fill the area specified by rect with a radial gradient, starting from
125 // initialColour in the centre of the cercle and fading to destColour.
126 void GradientFillConcentric(const wxRect
& rect
,
127 const wxColour
& initialColour
,
128 const wxColour
& destColour
)
129 { GradientFillConcentric(rect
, initialColour
, destColour
,
130 wxPoint(rect
.GetWidth() / 2,
131 rect
.GetHeight() / 2)); }
133 void GradientFillConcentric(const wxRect
& rect
,
134 const wxColour
& initialColour
,
135 const wxColour
& destColour
,
136 const wxPoint
& circleCenter
)
137 { DoGradientFillConcentric(rect
, initialColour
, destColour
, circleCenter
); }
139 // fill the area specified by rect with a linear gradient
140 void GradientFillLinear(const wxRect
& rect
,
141 const wxColour
& initialColour
,
142 const wxColour
& destColour
,
143 wxDirection nDirection
= wxEAST
)
144 { DoGradientFillLinear(rect
, initialColour
, destColour
, nDirection
); }
146 bool GetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const
147 { return DoGetPixel(x
, y
, col
); }
148 bool GetPixel(const wxPoint
& pt
, wxColour
*col
) const
149 { return DoGetPixel(pt
.x
, pt
.y
, col
); }
151 void DrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
152 { DoDrawLine(x1
, y1
, x2
, y2
); }
153 void DrawLine(const wxPoint
& pt1
, const wxPoint
& pt2
)
154 { DoDrawLine(pt1
.x
, pt1
.y
, pt2
.x
, pt2
.y
); }
156 void CrossHair(wxCoord x
, wxCoord y
)
157 { DoCrossHair(x
, y
); }
158 void CrossHair(const wxPoint
& pt
)
159 { DoCrossHair(pt
.x
, pt
.y
); }
161 void DrawArc(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
,
162 wxCoord xc
, wxCoord yc
)
163 { DoDrawArc(x1
, y1
, x2
, y2
, xc
, yc
); }
164 void DrawArc(const wxPoint
& pt1
, const wxPoint
& pt2
, const wxPoint
& centre
)
165 { DoDrawArc(pt1
.x
, pt1
.y
, pt2
.x
, pt2
.y
, centre
.x
, centre
.y
); }
167 void DrawCheckMark(wxCoord x
, wxCoord y
,
168 wxCoord width
, wxCoord height
)
169 { DoDrawCheckMark(x
, y
, width
, height
); }
170 void DrawCheckMark(const wxRect
& rect
)
171 { DoDrawCheckMark(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
173 void DrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
174 double sa
, double ea
)
175 { DoDrawEllipticArc(x
, y
, w
, h
, sa
, ea
); }
176 void DrawEllipticArc(const wxPoint
& pt
, const wxSize
& sz
,
177 double sa
, double ea
)
178 { DoDrawEllipticArc(pt
.x
, pt
.y
, sz
.x
, sz
.y
, sa
, ea
); }
180 void DrawPoint(wxCoord x
, wxCoord y
)
181 { DoDrawPoint(x
, y
); }
182 void DrawPoint(const wxPoint
& pt
)
183 { DoDrawPoint(pt
.x
, pt
.y
); }
185 void DrawLines(int n
, wxPoint points
[],
186 wxCoord xoffset
= 0, wxCoord yoffset
= 0)
187 { DoDrawLines(n
, points
, xoffset
, yoffset
); }
188 void DrawLines(const wxList
*list
,
189 wxCoord xoffset
= 0, wxCoord yoffset
= 0);
191 void DrawPolygon(int n
, wxPoint points
[],
192 wxCoord xoffset
= 0, wxCoord yoffset
= 0,
193 int fillStyle
= wxODDEVEN_RULE
)
194 { DoDrawPolygon(n
, points
, xoffset
, yoffset
, fillStyle
); }
196 void DrawPolygon(const wxList
*list
,
197 wxCoord xoffset
= 0, wxCoord yoffset
= 0,
198 int fillStyle
= wxODDEVEN_RULE
);
200 void DrawPolyPolygon(int n
, int count
[], wxPoint points
[],
201 wxCoord xoffset
= 0, wxCoord yoffset
= 0,
202 int fillStyle
= wxODDEVEN_RULE
)
203 { DoDrawPolyPolygon(n
, count
, points
, xoffset
, yoffset
, fillStyle
); }
205 void DrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
206 { DoDrawRectangle(x
, y
, width
, height
); }
207 void DrawRectangle(const wxPoint
& pt
, const wxSize
& sz
)
208 { DoDrawRectangle(pt
.x
, pt
.y
, sz
.x
, sz
.y
); }
209 void DrawRectangle(const wxRect
& rect
)
210 { DoDrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
212 void DrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
,
214 { DoDrawRoundedRectangle(x
, y
, width
, height
, radius
); }
215 void DrawRoundedRectangle(const wxPoint
& pt
, const wxSize
& sz
,
217 { DoDrawRoundedRectangle(pt
.x
, pt
.y
, sz
.x
, sz
.y
, radius
); }
218 void DrawRoundedRectangle(const wxRect
& r
, double radius
)
219 { DoDrawRoundedRectangle(r
.x
, r
.y
, r
.width
, r
.height
, radius
); }
221 void DrawCircle(wxCoord x
, wxCoord y
, wxCoord radius
)
222 { DoDrawEllipse(x
- radius
, y
- radius
, 2*radius
, 2*radius
); }
223 void DrawCircle(const wxPoint
& pt
, wxCoord radius
)
224 { DrawCircle(pt
.x
, pt
.y
, radius
); }
226 void DrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
227 { DoDrawEllipse(x
, y
, width
, height
); }
228 void DrawEllipse(const wxPoint
& pt
, const wxSize
& sz
)
229 { DoDrawEllipse(pt
.x
, pt
.y
, sz
.x
, sz
.y
); }
230 void DrawEllipse(const wxRect
& rect
)
231 { DoDrawEllipse(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
233 void DrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
)
234 { DoDrawIcon(icon
, x
, y
); }
235 void DrawIcon(const wxIcon
& icon
, const wxPoint
& pt
)
236 { DoDrawIcon(icon
, pt
.x
, pt
.y
); }
238 void DrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
239 bool useMask
= false)
240 { DoDrawBitmap(bmp
, x
, y
, useMask
); }
241 void DrawBitmap(const wxBitmap
&bmp
, const wxPoint
& pt
,
242 bool useMask
= false)
243 { DoDrawBitmap(bmp
, pt
.x
, pt
.y
, useMask
); }
245 void DrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
246 { DoDrawText(text
, x
, y
); }
247 void DrawText(const wxString
& text
, const wxPoint
& pt
)
248 { DoDrawText(text
, pt
.x
, pt
.y
); }
250 void DrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
251 { DoDrawRotatedText(text
, x
, y
, angle
); }
252 void DrawRotatedText(const wxString
& text
, const wxPoint
& pt
, double angle
)
253 { DoDrawRotatedText(text
, pt
.x
, pt
.y
, angle
); }
255 // this version puts both optional bitmap and the text into the given
256 // rectangle and aligns is as specified by alignment parameter; it also
257 // will emphasize the character with the given index if it is != -1 and
258 // return the bounding rectangle if required
259 virtual void DrawLabel(const wxString
& text
,
260 const wxBitmap
& image
,
262 int alignment
= wxALIGN_LEFT
| wxALIGN_TOP
,
264 wxRect
*rectBounding
= NULL
);
266 void DrawLabel(const wxString
& text
, const wxRect
& rect
,
267 int alignment
= wxALIGN_LEFT
| wxALIGN_TOP
,
269 { DrawLabel(text
, wxNullBitmap
, rect
, alignment
, indexAccel
); }
271 bool Blit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
272 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
273 int rop
= wxCOPY
, bool useMask
= false, wxCoord xsrcMask
= wxDefaultCoord
, wxCoord ysrcMask
= wxDefaultCoord
)
275 return DoBlit(xdest
, ydest
, width
, height
,
276 source
, xsrc
, ysrc
, rop
, useMask
, xsrcMask
, ysrcMask
);
278 bool Blit(const wxPoint
& destPt
, const wxSize
& sz
,
279 wxDC
*source
, const wxPoint
& srcPt
,
280 int rop
= wxCOPY
, bool useMask
= false, const wxPoint
& srcPtMask
= wxDefaultPosition
)
282 return DoBlit(destPt
.x
, destPt
.y
, sz
.x
, sz
.y
,
283 source
, srcPt
.x
, srcPt
.y
, rop
, useMask
, srcPtMask
.x
, srcPtMask
.y
);
286 bool StretchBlit(wxCoord dstX
, wxCoord dstY
,
287 wxCoord dstWidth
, wxCoord dstHeight
,
289 wxCoord srcX
, wxCoord srcY
,
290 wxCoord srcWidth
, wxCoord srcHeight
,
291 int rop
= wxCOPY
, bool useMask
= false,
292 wxCoord srcMaskX
= wxDefaultCoord
, wxCoord srcMaskY
= wxDefaultCoord
)
294 return DoStretchBlit(dstX
, dstY
, dstWidth
, dstHeight
,
295 source
, srcX
, srcY
, srcWidth
, srcHeight
, rop
, useMask
, srcMaskX
, srcMaskY
);
297 bool StretchBlit(const wxPoint
& dstPt
, const wxSize
& dstSize
,
298 wxDC
*source
, const wxPoint
& srcPt
, const wxSize
& srcSize
,
299 int rop
= wxCOPY
, bool useMask
= false, const wxPoint
& srcMaskPt
= wxDefaultPosition
)
301 return DoStretchBlit(dstPt
.x
, dstPt
.y
, dstSize
.x
, dstSize
.y
,
302 source
, srcPt
.x
, srcPt
.y
, srcSize
.x
, srcSize
.y
, rop
, useMask
, srcMaskPt
.x
, srcMaskPt
.y
);
305 wxBitmap
GetAsBitmap(const wxRect
*subrect
= (const wxRect
*) NULL
) const
307 return DoGetAsBitmap(subrect
);
311 // TODO: this API needs fixing (wxPointList, why (!const) "wxList *"?)
312 void DrawSpline(wxCoord x1
, wxCoord y1
,
313 wxCoord x2
, wxCoord y2
,
314 wxCoord x3
, wxCoord y3
);
315 void DrawSpline(int n
, wxPoint points
[]);
317 void DrawSpline(wxList
*points
) { DoDrawSpline(points
); }
318 #endif // wxUSE_SPLINES
320 // Eventually we will have wxUSE_GENERIC_DRAWELLIPSE
322 //! Generic method to draw ellipses, circles and arcs with current pen and brush.
323 /*! \param x Upper left corner of bounding box.
324 * \param y Upper left corner of bounding box.
325 * \param w Width of bounding box.
326 * \param h Height of bounding box.
327 * \param sa Starting angle of arc
328 * (counterclockwise, start at 3 o'clock, 360 is full circle).
329 * \param ea Ending angle of arc.
330 * \param angle Rotation angle, the Arc will be rotated after
331 * calculating begin and end.
333 void DrawEllipticArcRot( wxCoord x
, wxCoord y
,
334 wxCoord width
, wxCoord height
,
335 double sa
= 0, double ea
= 0, double angle
= 0 )
336 { DoDrawEllipticArcRot( x
, y
, width
, height
, sa
, ea
, angle
); }
338 void DrawEllipticArcRot( const wxPoint
& pt
,
340 double sa
= 0, double ea
= 0, double angle
= 0 )
341 { DoDrawEllipticArcRot( pt
.x
, pt
.y
, sz
.x
, sz
.y
, sa
, ea
, angle
); }
343 void DrawEllipticArcRot( const wxRect
& rect
,
344 double sa
= 0, double ea
= 0, double angle
= 0 )
345 { DoDrawEllipticArcRot( rect
.x
, rect
.y
, rect
.width
, rect
.height
, sa
, ea
, angle
); }
347 virtual void DoDrawEllipticArcRot( wxCoord x
, wxCoord y
,
348 wxCoord w
, wxCoord h
,
349 double sa
= 0, double ea
= 0, double angle
= 0 );
351 //! Rotates points around center.
352 /*! This is a quite straight method, it calculates in pixels
353 * and so it produces rounding errors.
354 * \param points The points inside will be rotated.
355 * \param angle Rotating angle (counterclockwise, start at 3 o'clock, 360 is full circle).
356 * \param center Center of rotation.
358 void Rotate( wxList
* points
, double angle
, wxPoint center
= wxPoint(0,0) );
360 // used by DrawEllipticArcRot
361 // Careful: wxList gets filled with points you have to delete later.
362 void CalculateEllipticPoints( wxList
* points
,
363 wxCoord xStart
, wxCoord yStart
,
364 wxCoord w
, wxCoord h
,
365 double sa
, double ea
);
368 // global DC operations
369 // --------------------
371 virtual void Clear() = 0;
373 virtual bool StartDoc(const wxString
& WXUNUSED(message
)) { return true; }
374 virtual void EndDoc() { }
376 virtual void StartPage() { }
377 virtual void EndPage() { }
379 #if WXWIN_COMPATIBILITY_2_6
380 wxDEPRECATED( void BeginDrawing() );
381 wxDEPRECATED( void EndDrawing() );
382 #endif // WXWIN_COMPATIBILITY_2_6
385 // set objects to use for drawing
386 // ------------------------------
388 virtual void SetFont(const wxFont
& font
) = 0;
389 virtual void SetPen(const wxPen
& pen
) = 0;
390 virtual void SetBrush(const wxBrush
& brush
) = 0;
391 virtual void SetBackground(const wxBrush
& brush
) = 0;
392 virtual void SetBackgroundMode(int mode
) = 0;
394 virtual void SetPalette(const wxPalette
& palette
) = 0;
395 #endif // wxUSE_PALETTE
400 void SetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
401 { DoSetClippingRegion(x
, y
, width
, height
); }
402 void SetClippingRegion(const wxPoint
& pt
, const wxSize
& sz
)
403 { DoSetClippingRegion(pt
.x
, pt
.y
, sz
.x
, sz
.y
); }
404 void SetClippingRegion(const wxRect
& rect
)
405 { DoSetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
406 void SetClippingRegion(const wxRegion
& region
)
407 { DoSetClippingRegionAsRegion(region
); }
409 virtual void DestroyClippingRegion() { ResetClipping(); }
411 void GetClippingBox(wxCoord
*x
, wxCoord
*y
, wxCoord
*w
, wxCoord
*h
) const
412 { DoGetClippingBox(x
, y
, w
, h
); }
413 void GetClippingBox(wxRect
& rect
) const
415 DoGetClippingBox(&rect
.x
, &rect
.y
, &rect
.width
, &rect
.height
);
421 virtual wxCoord
GetCharHeight() const = 0;
422 virtual wxCoord
GetCharWidth() const = 0;
424 // only works for single line strings
425 void GetTextExtent(const wxString
& string
,
426 wxCoord
*x
, wxCoord
*y
,
427 wxCoord
*descent
= NULL
,
428 wxCoord
*externalLeading
= NULL
,
429 const wxFont
*theFont
= NULL
) const
430 { DoGetTextExtent(string
, x
, y
, descent
, externalLeading
, theFont
); }
432 wxSize
GetTextExtent(const wxString
& string
) const
435 DoGetTextExtent(string
, &w
, &h
);
439 // works for single as well as multi-line strings
440 virtual void GetMultiLineTextExtent(const wxString
& string
,
443 wxCoord
*heightLine
= NULL
,
444 const wxFont
*font
= NULL
) const;
446 wxSize
GetMultiLineTextExtent(const wxString
& string
) const
449 GetMultiLineTextExtent(string
, &w
, &h
);
453 // Measure cumulative width of text after each character
454 bool GetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
455 { return DoGetPartialTextExtents(text
, widths
); }
458 // size and resolution
459 // -------------------
462 void GetSize(int *width
, int *height
) const
463 { DoGetSize(width
, height
); }
464 wxSize
GetSize() const
473 void GetSizeMM(int* width
, int* height
) const
474 { DoGetSizeMM(width
, height
); }
475 wxSize
GetSizeMM() const
483 // query DC capabilities
484 // ---------------------
486 virtual bool CanDrawBitmap() const = 0;
487 virtual bool CanGetTextExtent() const = 0;
490 virtual int GetDepth() const = 0;
492 // Resolution in Pixels per inch
493 virtual wxSize
GetPPI() const = 0;
495 virtual bool Ok() const { return IsOk(); }
496 virtual bool IsOk() const { return m_ok
; }
498 // accessors and setters
499 // ---------------------
501 virtual int GetBackgroundMode() const { return m_backgroundMode
; }
502 virtual const wxBrush
& GetBackground() const { return m_backgroundBrush
; }
503 virtual const wxBrush
& GetBrush() const { return m_brush
; }
504 virtual const wxFont
& GetFont() const { return m_font
; }
505 virtual const wxPen
& GetPen() const { return m_pen
; }
507 virtual const wxColour
& GetTextForeground() const { return m_textForegroundColour
; }
508 virtual const wxColour
& GetTextBackground() const { return m_textBackgroundColour
; }
509 virtual void SetTextForeground(const wxColour
& colour
)
510 { m_textForegroundColour
= colour
; }
511 virtual void SetTextBackground(const wxColour
& colour
)
512 { m_textBackgroundColour
= colour
; }
515 // coordinates conversions and transforms
516 // --------------------------------------
518 virtual wxCoord
DeviceToLogicalX(wxCoord x
) const;
519 virtual wxCoord
DeviceToLogicalY(wxCoord y
) const;
520 virtual wxCoord
DeviceToLogicalXRel(wxCoord x
) const;
521 virtual wxCoord
DeviceToLogicalYRel(wxCoord y
) const;
522 virtual wxCoord
LogicalToDeviceX(wxCoord x
) const;
523 virtual wxCoord
LogicalToDeviceY(wxCoord y
) const;
524 virtual wxCoord
LogicalToDeviceXRel(wxCoord x
) const;
525 virtual wxCoord
LogicalToDeviceYRel(wxCoord y
) const;
527 virtual void SetMapMode(int mode
);
528 virtual int GetMapMode() const { return m_mappingMode
; }
530 virtual void SetUserScale(double x
, double y
);
531 virtual void GetUserScale(double *x
, double *y
) const
533 if ( x
) *x
= m_userScaleX
;
534 if ( y
) *y
= m_userScaleY
;
537 virtual void SetLogicalScale(double x
, double y
);
538 virtual void GetLogicalScale(double *x
, double *y
)
540 if ( x
) *x
= m_logicalScaleX
;
541 if ( y
) *y
= m_logicalScaleY
;
544 virtual void SetLogicalOrigin(wxCoord x
, wxCoord y
);
545 void GetLogicalOrigin(wxCoord
*x
, wxCoord
*y
) const
546 { DoGetLogicalOrigin(x
, y
); }
547 wxPoint
GetLogicalOrigin() const
548 { wxCoord x
, y
; DoGetLogicalOrigin(&x
, &y
); return wxPoint(x
, y
); }
550 virtual void SetDeviceOrigin(wxCoord x
, wxCoord y
);
551 void GetDeviceOrigin(wxCoord
*x
, wxCoord
*y
) const
552 { DoGetDeviceOrigin(x
, y
); }
553 wxPoint
GetDeviceOrigin() const
554 { wxCoord x
, y
; DoGetDeviceOrigin(&x
, &y
); return wxPoint(x
, y
); }
556 virtual void SetDeviceLocalOrigin( wxCoord x
, wxCoord y
);
558 virtual void ComputeScaleAndOrigin();
560 // this needs to overidden if the axis is inverted (such
561 // as when using Postscript, where 0,0 is the lower left
562 // corner, not the upper left).
563 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
);
566 // ---------------------------
568 virtual int GetLogicalFunction() const { return m_logicalFunction
; }
569 virtual void SetLogicalFunction(int function
) = 0;
574 virtual void CalcBoundingBox(wxCoord x
, wxCoord y
)
578 if ( x
< m_minX
) m_minX
= x
;
579 if ( y
< m_minY
) m_minY
= y
;
580 if ( x
> m_maxX
) m_maxX
= x
;
581 if ( y
> m_maxY
) m_maxY
= y
;
585 m_isBBoxValid
= true;
594 void ResetBoundingBox()
596 m_isBBoxValid
= false;
598 m_minX
= m_maxX
= m_minY
= m_maxY
= 0;
601 // Get the final bounding box of the PostScript or Metafile picture.
602 wxCoord
MinX() const { return m_minX
; }
603 wxCoord
MaxX() const { return m_maxX
; }
604 wxCoord
MinY() const { return m_minY
; }
605 wxCoord
MaxY() const { return m_maxY
; }
607 // misc old functions
608 // ------------------
610 // for compatibility with the old code when wxCoord was long everywhere
611 void GetTextExtent(const wxString
& string
,
613 long *descent
= NULL
,
614 long *externalLeading
= NULL
,
615 const wxFont
*theFont
= NULL
) const
617 wxCoord x2
, y2
, descent2
, externalLeading2
;
618 DoGetTextExtent(string
, &x2
, &y2
,
619 &descent2
, &externalLeading2
,
627 if ( externalLeading
)
628 *externalLeading
= externalLeading2
;
631 void GetLogicalOrigin(long *x
, long *y
) const
634 DoGetLogicalOrigin(&x2
, &y2
);
641 void GetDeviceOrigin(long *x
, long *y
) const
644 DoGetDeviceOrigin(&x2
, &y2
);
650 void GetClippingBox(long *x
, long *y
, long *w
, long *h
) const
653 DoGetClippingBox(&xx
, &yy
, &ww
, &hh
);
660 // RTL related functions
661 // ---------------------
663 // get or change the layout direction (LTR or RTL) for this dc,
664 // wxLayout_Default is returned if layout direction is not supported
665 virtual wxLayoutDirection
GetLayoutDirection() const
666 { return wxLayout_Default
; }
667 virtual void SetLayoutDirection(wxLayoutDirection
WXUNUSED(dir
))
671 // the pure virtual functions which should be implemented by wxDC
672 virtual bool DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
673 int style
= wxFLOOD_SURFACE
) = 0;
675 virtual void DoGradientFillLinear(const wxRect
& rect
,
676 const wxColour
& initialColour
,
677 const wxColour
& destColour
,
678 wxDirection nDirection
= wxEAST
);
680 virtual void DoGradientFillConcentric(const wxRect
& rect
,
681 const wxColour
& initialColour
,
682 const wxColour
& destColour
,
683 const wxPoint
& circleCenter
);
685 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const = 0;
687 virtual void DoDrawPoint(wxCoord x
, wxCoord y
) = 0;
688 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
) = 0;
690 virtual void DoDrawArc(wxCoord x1
, wxCoord y1
,
691 wxCoord x2
, wxCoord y2
,
692 wxCoord xc
, wxCoord yc
) = 0;
693 virtual void DoDrawCheckMark(wxCoord x
, wxCoord y
,
694 wxCoord width
, wxCoord height
);
695 virtual void DoDrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
696 double sa
, double ea
) = 0;
698 virtual void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
) = 0;
699 virtual void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
700 wxCoord width
, wxCoord height
,
702 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
,
703 wxCoord width
, wxCoord height
) = 0;
705 virtual void DoCrossHair(wxCoord x
, wxCoord y
) = 0;
707 virtual void DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
) = 0;
708 virtual void DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
709 bool useMask
= false) = 0;
711 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
) = 0;
712 virtual void DoDrawRotatedText(const wxString
& text
,
713 wxCoord x
, wxCoord y
, double angle
) = 0;
715 virtual bool DoBlit(wxCoord xdest
, wxCoord ydest
,
716 wxCoord width
, wxCoord height
,
718 wxCoord xsrc
, wxCoord ysrc
,
720 bool useMask
= false,
721 wxCoord xsrcMask
= wxDefaultCoord
,
722 wxCoord ysrcMask
= wxDefaultCoord
) = 0;
724 virtual bool DoStretchBlit(wxCoord xdest
, wxCoord ydest
,
725 wxCoord dstWidth
, wxCoord dstHeight
,
727 wxCoord xsrc
, wxCoord ysrc
,
728 wxCoord srcWidth
, wxCoord srcHeight
,
730 bool useMask
= false,
731 wxCoord xsrcMask
= wxDefaultCoord
,
732 wxCoord ysrcMask
= wxDefaultCoord
);
734 virtual wxBitmap
DoGetAsBitmap(const wxRect
*WXUNUSED(subrect
)) const
735 { return wxNullBitmap
; }
737 virtual void DoGetSize(int *width
, int *height
) const = 0;
738 virtual void DoGetSizeMM(int* width
, int* height
) const = 0;
740 virtual void DoDrawLines(int n
, wxPoint points
[],
741 wxCoord xoffset
, wxCoord yoffset
) = 0;
742 virtual void DoDrawPolygon(int n
, wxPoint points
[],
743 wxCoord xoffset
, wxCoord yoffset
,
744 int fillStyle
= wxODDEVEN_RULE
) = 0;
745 virtual void DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[],
746 wxCoord xoffset
, wxCoord yoffset
,
749 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
) = 0;
750 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
751 wxCoord width
, wxCoord height
) = 0;
753 virtual void DoGetClippingBox(wxCoord
*x
, wxCoord
*y
,
754 wxCoord
*w
, wxCoord
*h
) const
761 *w
= m_clipX2
- m_clipX1
;
763 *h
= m_clipY2
- m_clipY1
;
766 virtual void DoGetLogicalOrigin(wxCoord
*x
, wxCoord
*y
) const
768 if ( x
) *x
= m_logicalOriginX
;
769 if ( y
) *y
= m_logicalOriginY
;
772 virtual void DoGetDeviceOrigin(wxCoord
*x
, wxCoord
*y
) const
774 if ( x
) *x
= m_deviceOriginX
;
775 if ( y
) *y
= m_deviceOriginY
;
778 virtual void DoGetTextExtent(const wxString
& string
,
779 wxCoord
*x
, wxCoord
*y
,
780 wxCoord
*descent
= NULL
,
781 wxCoord
*externalLeading
= NULL
,
782 const wxFont
*theFont
= NULL
) const = 0;
784 virtual bool DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const;
787 virtual void DoDrawSpline(wxList
*points
);
791 // unset clipping variables (after clipping region was destroyed)
796 m_clipX1
= m_clipX2
= m_clipY1
= m_clipY2
= 0;
803 bool m_isInteractive
:1;
804 bool m_isBBoxValid
:1;
806 // coordinate system variables
808 // TODO short descriptions of what exactly they are would be nice...
810 wxCoord m_logicalOriginX
, m_logicalOriginY
;
811 wxCoord m_deviceOriginX
, m_deviceOriginY
; // Usually 0,0, can be change by user
813 wxCoord m_deviceLocalOriginX
, m_deviceLocalOriginY
; // non-zero if native top-left corner
814 // is not at 0,0. This was the case under
815 // Mac's GrafPorts (coordinate system
816 // used toplevel window's origin) and
817 // e.g. for Postscript, where the native
818 // origin in the bottom left corner.
819 double m_logicalScaleX
, m_logicalScaleY
;
820 double m_userScaleX
, m_userScaleY
;
821 double m_scaleX
, m_scaleY
; // calculated from logical scale and user scale
823 // Used by SetAxisOrientation() to invert the axes
824 int m_signX
, m_signY
;
826 // what is a mm on a screen you don't know the size of?
827 double m_mm_to_pix_x
,
830 // bounding and clipping boxes
831 wxCoord m_minX
, m_minY
, m_maxX
, m_maxY
;
832 wxCoord m_clipX1
, m_clipY1
, m_clipX2
, m_clipY2
;
834 int m_logicalFunction
;
835 int m_backgroundMode
;
841 wxBrush m_backgroundBrush
;
842 wxColour m_textForegroundColour
;
843 wxColour m_textBackgroundColour
;
848 bool m_hasCustomPalette
;
849 #endif // wxUSE_PALETTE
852 DECLARE_NO_COPY_CLASS(wxDCBase
)
853 DECLARE_ABSTRACT_CLASS(wxDCBase
)
856 // ----------------------------------------------------------------------------
857 // now include the declaration of wxDC class
858 // ----------------------------------------------------------------------------
860 #if defined(__WXPALMOS__)
861 #include "wx/palmos/dc.h"
862 #elif defined(__WXMSW__)
863 #include "wx/msw/dc.h"
864 #elif defined(__WXMOTIF__)
865 #include "wx/motif/dc.h"
866 #elif defined(__WXGTK20__)
867 #include "wx/gtk/dc.h"
868 #elif defined(__WXGTK__)
869 #include "wx/gtk1/dc.h"
870 #elif defined(__WXX11__)
871 #include "wx/x11/dc.h"
872 #elif defined(__WXMGL__)
873 #include "wx/mgl/dc.h"
874 #elif defined(__WXDFB__)
875 #include "wx/dfb/dc.h"
876 #elif defined(__WXMAC__)
877 #include "wx/mac/dc.h"
878 #elif defined(__WXCOCOA__)
879 #include "wx/cocoa/dc.h"
880 #elif defined(__WXPM__)
881 #include "wx/os2/dc.h"
884 #if wxUSE_GRAPHICS_CONTEXT
885 #include "wx/dcgraph.h"
888 // ----------------------------------------------------------------------------
889 // helper class: you can use it to temporarily change the DC text colour and
890 // restore it automatically when the object goes out of scope
891 // ----------------------------------------------------------------------------
893 class WXDLLEXPORT wxDCTextColourChanger
896 wxDCTextColourChanger(wxDC
& dc
) : m_dc(dc
), m_colFgOld() { }
898 wxDCTextColourChanger(wxDC
& dc
, const wxColour
& col
) : m_dc(dc
)
903 ~wxDCTextColourChanger()
905 if ( m_colFgOld
.Ok() )
906 m_dc
.SetTextForeground(m_colFgOld
);
909 void Set(const wxColour
& col
)
911 if ( !m_colFgOld
.Ok() )
912 m_colFgOld
= m_dc
.GetTextForeground();
913 m_dc
.SetTextForeground(col
);
921 DECLARE_NO_COPY_CLASS(wxDCTextColourChanger
)
924 // ----------------------------------------------------------------------------
925 // helper class: you can use it to temporarily change the DC pen and
926 // restore it automatically when the object goes out of scope
927 // ----------------------------------------------------------------------------
929 class WXDLLEXPORT wxDCPenChanger
932 wxDCPenChanger(wxDC
& dc
, const wxPen
& pen
) : m_dc(dc
), m_penOld(dc
.GetPen())
940 m_dc
.SetPen(m_penOld
);
948 DECLARE_NO_COPY_CLASS(wxDCPenChanger
)
951 // ----------------------------------------------------------------------------
952 // helper class: you can use it to temporarily change the DC brush and
953 // restore it automatically when the object goes out of scope
954 // ----------------------------------------------------------------------------
956 class WXDLLEXPORT wxDCBrushChanger
959 wxDCBrushChanger(wxDC
& dc
, const wxBrush
& brush
) : m_dc(dc
), m_brushOld(dc
.GetBrush())
961 m_dc
.SetBrush(brush
);
966 if ( m_brushOld
.Ok() )
967 m_dc
.SetBrush(m_brushOld
);
975 DECLARE_NO_COPY_CLASS(wxDCBrushChanger
)
978 // ----------------------------------------------------------------------------
979 // another small helper class: sets the clipping region in its ctor and
980 // destroys it in the dtor
981 // ----------------------------------------------------------------------------
983 class WXDLLEXPORT wxDCClipper
986 wxDCClipper(wxDC
& dc
, const wxRegion
& r
) : m_dc(dc
)
987 { dc
.SetClippingRegion(r
); }
988 wxDCClipper(wxDC
& dc
, const wxRect
& r
) : m_dc(dc
)
989 { dc
.SetClippingRegion(r
.x
, r
.y
, r
.width
, r
.height
); }
990 wxDCClipper(wxDC
& dc
, wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
) : m_dc(dc
)
991 { dc
.SetClippingRegion(x
, y
, w
, h
); }
993 ~wxDCClipper() { m_dc
.DestroyClippingRegion(); }
998 DECLARE_NO_COPY_CLASS(wxDCClipper
)
1001 #endif // _WX_DC_H_BASE_