1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
19 #include "wx/object.h"
20 #include "wx/gdicmn.h"
25 #include "wx/gdicmn.h"
27 //-----------------------------------------------------------------------------
29 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
38 #define MM_ISOTROPIC 1
39 #define MM_ANISOTROPIC 2
46 //-----------------------------------------------------------------------------
48 //-----------------------------------------------------------------------------
50 extern int wxPageNumber
;
52 //-----------------------------------------------------------------------------
54 //-----------------------------------------------------------------------------
56 class wxDC
: public wxObject
58 DECLARE_ABSTRACT_CLASS(wxDC
)
65 virtual void BeginDrawing() {}
66 virtual void EndDrawing() {}
68 virtual bool Ok() const;
70 virtual void FloodFill( long x
, long y
, const wxColour
& col
, int style
=wxFLOOD_SURFACE
) = 0;
71 inline void FloodFill(const wxPoint
& pt
, const wxColour
& col
, int style
=wxFLOOD_SURFACE
)
73 FloodFill(pt
.x
, pt
.y
, col
, style
);
75 virtual bool GetPixel( long x
, long y
, wxColour
*col
) const = 0;
76 inline bool GetPixel(const wxPoint
& pt
, wxColour
*col
) const
78 return GetPixel(pt
.x
, pt
.y
, col
);
81 virtual void DrawLine( long x1
, long y1
, long x2
, long y2
) = 0;
82 inline void DrawLine(const wxPoint
& pt1
, const wxPoint
& pt2
)
84 DrawLine(pt1
.x
, pt1
.y
, pt2
.x
, pt2
.y
);
86 virtual void CrossHair( long x
, long y
) = 0;
87 inline void CrossHair(const wxPoint
& pt
)
89 CrossHair(pt
.x
, pt
.y
);
91 virtual void DrawArc( long x1
, long y1
, long x2
, long y2
, double xc
, double yc
);
92 inline void DrawArc(const wxPoint
& pt1
, const wxPoint
& pt2
, const wxPoint
& centre
)
94 DrawArc(pt1
.x
, pt1
.y
, pt2
.x
, pt2
.y
, centre
.x
, centre
.y
);
96 virtual void DrawEllipticArc( long x
, long y
, long width
, long height
, double sa
, double ea
) = 0;
97 virtual void DrawEllipticArc (const wxPoint
& pt
, const wxSize
& sz
, double sa
, double ea
)
99 DrawEllipticArc(pt
.x
, pt
.y
, sz
.x
, sz
.y
, sa
, ea
);
101 virtual void DrawPoint( long x
, long y
) = 0;
102 inline void DrawPoint(const wxPoint
& pt
)
104 DrawPoint(pt
.x
, pt
.y
);
106 virtual void DrawPoint( wxPoint
& point
);
108 virtual void DrawLines( int n
, wxPoint points
[], long xoffset
= 0, long yoffset
= 0 ) = 0;
109 virtual void DrawLines( wxList
*points
, long xoffset
= 0, long yoffset
= 0 );
110 virtual void DrawPolygon( int n
, wxPoint points
[], long xoffset
= 0, long yoffset
= 0,
111 int fillStyle
=wxODDEVEN_RULE
) = 0;
112 virtual void DrawPolygon( wxList
*lines
, long xoffset
= 0, long yoffset
= 0,
113 int fillStyle
=wxODDEVEN_RULE
);
115 virtual void DrawRectangle( long x
, long y
, long width
, long height
) = 0;
116 inline void DrawRectangle(const wxPoint
& pt
, const wxSize
& sz
)
118 DrawRectangle(pt
.x
, pt
.y
, sz
.x
, sz
.y
);
120 inline void DrawRectangle(const wxRect
& rect
)
122 DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
124 virtual void DrawRoundedRectangle( long x
, long y
, long width
, long height
, double radius
= 20.0 ) = 0;
125 inline void DrawRoundedRectangle(const wxPoint
& pt
, const wxSize
& sz
, double radius
= 20.0)
127 DrawRoundedRectangle(pt
.x
, pt
.y
, sz
.x
, sz
.y
, radius
);
129 inline void DrawRoundedRectangle(const wxRect
& rect
, double radius
= 20.0)
131 DrawRoundedRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
, radius
);
133 virtual void DrawEllipse( long x
, long y
, long width
, long height
) = 0;
134 inline void DrawEllipse(const wxPoint
& pt
, const wxSize
& sz
)
136 DrawEllipse(pt
.x
, pt
.y
, sz
.x
, sz
.y
);
138 inline void DrawEllipse(const wxRect
& rect
)
140 DrawEllipse(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
143 virtual void DrawSpline( long x1
, long y1
, long x2
, long y2
, long x3
, long y3
);
144 virtual void DrawSpline( wxList
*points
) = 0;
145 virtual void DrawSpline( int n
, wxPoint points
[] );
147 virtual bool CanDrawBitmap(void) const = 0;
148 virtual void DrawIcon( const wxIcon
&icon
, long x
, long y
) = 0;
149 inline void DrawIcon( const wxIcon
& icon
, const wxPoint
& pt
)
151 DrawIcon(icon
, pt
.x
, pt
.y
);
153 virtual void DrawBitmap( const wxBitmap
&bmp
, long x
, long y
, bool useMask
=FALSE
) = 0;
154 inline void DrawBitmap( const wxBitmap
& bitmap
, const wxPoint
& pt
, bool useMask
=FALSE
)
156 DrawBitmap(bitmap
, pt
.x
, pt
.y
, useMask
);
158 virtual bool Blit( long xdest
, long ydest
,
159 long width
, long height
,
161 long xsrc
, long ysrc
,
162 int logical_func
=wxCOPY
,
163 bool useMask
=FALSE
) = 0;
164 inline bool Blit( const wxPoint
& destPt
,
167 const wxPoint
& srcPt
,
171 return Blit(destPt
.x
, destPt
.y
, sz
.x
, sz
.y
, source
, srcPt
.x
, srcPt
.y
, rop
, useMask
);
174 virtual void DrawText( const wxString
&text
, long x
, long y
, bool use16
= FALSE
) = 0;
175 inline void DrawText(const wxString
& text
, const wxPoint
& pt
, bool use16bit
= FALSE
)
177 DrawText(text
, pt
.x
, pt
.y
, use16bit
);
179 virtual bool CanGetTextExtent(void) const = 0;
180 virtual void GetTextExtent( const wxString
&string
,
181 long *width
, long *height
,
182 long *descent
= (long *) NULL
,
183 long *externalLeading
= (long *) NULL
,
184 wxFont
*theFont
= (wxFont
*) NULL
,
185 bool use16
= FALSE
) = 0;
186 virtual long GetCharWidth(void) = 0;
187 virtual long GetCharHeight(void) = 0;
189 virtual void Clear() = 0;
191 virtual void SetFont( const wxFont
&font
) = 0;
192 virtual wxFont
& GetFont() const { return (wxFont
&)m_font
; };
194 virtual void SetPen( const wxPen
&pen
) = 0;
195 virtual wxPen
& GetPen() const { return (wxPen
&)m_pen
; };
197 virtual void SetBrush( const wxBrush
&brush
) = 0;
198 virtual wxBrush
& GetBrush() const { return (wxBrush
&)m_brush
; };
200 virtual void SetBackground( const wxBrush
&brush
) = 0;
201 virtual wxBrush
& GetBackground() const { return (wxBrush
&)m_backgroundBrush
; };
203 virtual void SetLogicalFunction( int function
) = 0;
204 virtual int GetLogicalFunction() { return m_logicalFunction
; };
206 virtual void SetTextForeground( const wxColour
&col
);
207 virtual void SetTextBackground( const wxColour
&col
);
208 virtual wxColour
& GetTextBackground() const { return (wxColour
&)m_textBackgroundColour
; };
209 virtual wxColour
& GetTextForeground() const { return (wxColour
&)m_textForegroundColour
; };
211 virtual void SetBackgroundMode( int mode
) = 0;
212 virtual int GetBackgroundMode() { return m_backgroundMode
; };
214 virtual void SetPalette( const wxPalette
& palette
) = 0;
215 void SetColourMap( const wxPalette
& palette
) { SetPalette(palette
); };
217 // the first two must be overridden and called
218 virtual void DestroyClippingRegion(void);
219 virtual void SetClippingRegion( long x
, long y
, long width
, long height
);
220 virtual void GetClippingBox( long *x
, long *y
, long *width
, long *height
) const;
221 virtual void SetClippingRegion( const wxRegion
®ion
) = 0;
223 virtual long MinX() const { return m_minX
; }
224 virtual long MaxX() const { return m_maxX
; }
225 virtual long MinY() const { return m_minY
; }
226 virtual long MaxY() const { return m_maxY
; }
228 // Size in device units
229 virtual void GetSize( int* width
, int* height
) const;
230 inline wxSize
GetSize(void) const { int w
, h
; GetSize(&w
, &h
); return wxSize(w
, h
); }
232 // Size in millimetres
233 virtual void GetSizeMM( int* width
, int* height
) const;
234 inline wxSize
GetSizeMM(void) const { int w
, h
; GetSizeMM(&w
, &h
); return wxSize(w
, h
); }
236 // Resolution in pixels per logical inch
237 virtual wxSize
GetPPI(void) const;
239 virtual bool StartDoc( const wxString
& WXUNUSED(message
) ) { return TRUE
; }
240 virtual void EndDoc() {}
241 virtual void StartPage() {}
242 virtual void EndPage() {}
244 virtual void SetMapMode( int mode
);
245 virtual int GetMapMode(void) const { return m_mappingMode
; };
247 virtual void SetUserScale( double x
, double y
);
248 virtual void GetUserScale( double *x
, double *y
);
249 virtual void SetLogicalScale( double x
, double y
);
250 virtual void GetLogicalScale( double *x
, double *y
);
252 virtual void SetLogicalOrigin( long x
, long y
);
253 virtual void GetLogicalOrigin( long *x
, long *y
);
254 virtual void SetDeviceOrigin( long x
, long y
);
255 virtual void GetDeviceOrigin( long *x
, long *y
);
257 virtual void SetAxisOrientation( bool xLeftRight
, bool yBottomUp
);
259 virtual void SetOptimization( bool WXUNUSED(optimize
) ) {}
260 virtual bool GetOptimization() { return m_optimize
; }
262 virtual long DeviceToLogicalX(long x
) const;
263 virtual long DeviceToLogicalY(long y
) const;
264 virtual long DeviceToLogicalXRel(long x
) const;
265 virtual long DeviceToLogicalYRel(long y
) const;
266 virtual long LogicalToDeviceX(long x
) const;
267 virtual long LogicalToDeviceY(long y
) const;
268 virtual long LogicalToDeviceXRel(long x
) const;
269 virtual long LogicalToDeviceYRel(long y
) const;
273 void CalcBoundingBox( long x
, long y
);
274 void ComputeScaleAndOrigin();
276 long XDEV2LOG(long x
) const
278 long new_x
= x
- m_deviceOriginX
;
280 return (long)((double)(new_x
) / m_scaleX
+ 0.5) * m_signX
+ m_logicalOriginX
;
282 return (long)((double)(new_x
) / m_scaleX
- 0.5) * m_signX
+ m_logicalOriginX
;
284 long XDEV2LOGREL(long x
) const
287 return (long)((double)(x
) / m_scaleX
+ 0.5);
289 return (long)((double)(x
) / m_scaleX
- 0.5);
291 long YDEV2LOG(long y
) const
293 long new_y
= y
- m_deviceOriginY
;
295 return (long)((double)(new_y
) / m_scaleY
+ 0.5) * m_signY
+ m_logicalOriginY
;
297 return (long)((double)(new_y
) / m_scaleY
- 0.5) * m_signY
+ m_logicalOriginY
;
299 long YDEV2LOGREL(long y
) const
302 return (long)((double)(y
) / m_scaleY
+ 0.5);
304 return (long)((double)(y
) / m_scaleY
- 0.5);
306 long XLOG2DEV(long x
) const
308 long new_x
= x
- m_logicalOriginX
;
310 return (long)((double)(new_x
) * m_scaleX
+ 0.5) * m_signX
+ m_deviceOriginX
;
312 return (long)((double)(new_x
) * m_scaleX
- 0.5) * m_signX
+ m_deviceOriginX
;
314 long XLOG2DEVREL(long x
) const
317 return (long)((double)(x
) * m_scaleX
+ 0.5);
319 return (long)((double)(x
) * m_scaleX
- 0.5);
321 long YLOG2DEV(long y
) const
323 long new_y
= y
- m_logicalOriginY
;
325 return (long)((double)(new_y
) * m_scaleY
+ 0.5) * m_signY
+ m_deviceOriginY
;
327 return (long)((double)(new_y
) * m_scaleY
- 0.5) * m_signY
+ m_deviceOriginY
;
329 long YLOG2DEVREL(long y
) const
332 return (long)((double)(y
) * m_scaleY
+ 0.5);
334 return (long)((double)(y
) * m_scaleY
- 0.5);
343 // not sure, what these mean
344 bool m_clipping
; // Is clipping on right now ?
345 bool m_isInteractive
; // Is GetPixel possible ?
346 bool m_autoSetting
; // wxMSW only ?
347 bool m_dontDelete
; // wxMSW only ?
348 bool m_optimize
; // wxMSW only ?
352 wxBrush m_backgroundBrush
;
353 wxColour m_textForegroundColour
;
354 wxColour m_textBackgroundColour
;
357 int m_logicalFunction
;
358 int m_backgroundMode
;
359 int m_textAlignment
; // gone in wxWin 2.0 ?
363 // not sure what for, but what is a mm on a screen you don't know the size of?
364 double m_mm_to_pix_x
,m_mm_to_pix_y
;
366 long m_deviceOriginX
,m_deviceOriginY
;
368 long m_logicalOriginX
,m_logicalOriginY
; // User defined.
370 double m_scaleX
,m_scaleY
;
371 double m_logicalScaleX
,m_logicalScaleY
;
372 double m_userScaleX
,m_userScaleY
;
373 long m_signX
,m_signY
;
375 bool m_needComputeScaleX
,m_needComputeScaleY
; // not yet used
377 float m_scaleFactor
; // wxPSDC wants to have this. Will disappear.
379 long m_clipX1
,m_clipY1
,m_clipX2
,m_clipY2
;
380 long m_minX
,m_maxX
,m_minY
,m_maxY
;