1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
14 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
15 #pragma interface "dc.h"
19 #include "wx/region.h"
21 //-----------------------------------------------------------------------------
23 //-----------------------------------------------------------------------------
25 class WXDLLEXPORT wxDC
;
27 //-----------------------------------------------------------------------------
29 //-----------------------------------------------------------------------------
32 #define MM_ISOTROPIC 1
33 #define MM_ANISOTROPIC 2
40 //-----------------------------------------------------------------------------
42 //-----------------------------------------------------------------------------
45 // MGL fwd declarations:
50 class WXDLLEXPORT wxDC
: public wxDCBase
52 DECLARE_DYNAMIC_CLASS(wxDC
)
58 // implement base class pure virtuals
59 // ----------------------------------
63 virtual bool StartDoc(const wxString
& message
);
64 virtual void EndDoc();
66 virtual void StartPage();
67 virtual void EndPage();
69 virtual void SetFont(const wxFont
& font
);
70 virtual void SetPen(const wxPen
& pen
);
71 virtual void SetBrush(const wxBrush
& brush
);
72 virtual void SetBackground(const wxBrush
& brush
);
73 virtual void SetBackgroundMode(int mode
);
74 virtual void SetPalette(const wxPalette
& palette
);
76 virtual void DestroyClippingRegion();
78 virtual wxCoord
GetCharHeight() const;
79 virtual wxCoord
GetCharWidth() const;
80 virtual void DoGetTextExtent(const wxString
& string
,
81 wxCoord
*x
, wxCoord
*y
,
82 wxCoord
*descent
= NULL
,
83 wxCoord
*externalLeading
= NULL
,
84 wxFont
*theFont
= NULL
) const;
86 virtual bool CanDrawBitmap() const;
87 virtual bool CanGetTextExtent() const;
88 virtual int GetDepth() const;
89 virtual wxSize
GetPPI() const;
91 virtual void SetMapMode(int mode
);
92 virtual void SetUserScale(double x
, double y
);
93 virtual void SetLogicalScale(double x
, double y
);
94 virtual void SetLogicalOrigin(wxCoord x
, wxCoord y
);
95 virtual void SetDeviceOrigin(wxCoord x
, wxCoord y
);
96 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
);
97 virtual void SetLogicalFunction(int function
);
99 // implementation from now on
100 // --------------------------
102 virtual void ComputeScaleAndOrigin();
104 wxCoord
XDEV2LOG(wxCoord x
) const
106 wxCoord new_x
= x
- m_deviceOriginX
;
108 return (wxCoord
)((double)(new_x
) / m_scaleX
+ 0.5) * m_signX
+ m_logicalOriginX
;
110 return (wxCoord
)((double)(new_x
) / m_scaleX
- 0.5) * m_signX
+ m_logicalOriginX
;
112 wxCoord
XDEV2LOGREL(wxCoord x
) const
115 return (wxCoord
)((double)(x
) / m_scaleX
+ 0.5);
117 return (wxCoord
)((double)(x
) / m_scaleX
- 0.5);
119 wxCoord
YDEV2LOG(wxCoord y
) const
121 wxCoord new_y
= y
- m_deviceOriginY
;
123 return (wxCoord
)((double)(new_y
) / m_scaleY
+ 0.5) * m_signY
+ m_logicalOriginY
;
125 return (wxCoord
)((double)(new_y
) / m_scaleY
- 0.5) * m_signY
+ m_logicalOriginY
;
127 wxCoord
YDEV2LOGREL(wxCoord y
) const
130 return (wxCoord
)((double)(y
) / m_scaleY
+ 0.5);
132 return (wxCoord
)((double)(y
) / m_scaleY
- 0.5);
134 wxCoord
XLOG2DEV(wxCoord x
) const
136 wxCoord new_x
= x
- m_logicalOriginX
;
138 return (wxCoord
)((double)(new_x
) * m_scaleX
+ 0.5) * m_signX
+ m_deviceOriginX
;
140 return (wxCoord
)((double)(new_x
) * m_scaleX
- 0.5) * m_signX
+ m_deviceOriginX
;
142 wxCoord
XLOG2DEVREL(wxCoord x
) const
145 return (wxCoord
)((double)(x
) * m_scaleX
+ 0.5);
147 return (wxCoord
)((double)(x
) * m_scaleX
- 0.5);
149 wxCoord
YLOG2DEV(wxCoord y
) const
151 wxCoord new_y
= y
- m_logicalOriginY
;
153 return (wxCoord
)((double)(new_y
) * m_scaleY
+ 0.5) * m_signY
+ m_deviceOriginY
;
155 return (wxCoord
)((double)(new_y
) * m_scaleY
- 0.5) * m_signY
+ m_deviceOriginY
;
157 wxCoord
YLOG2DEVREL(wxCoord y
) const
160 return (wxCoord
)((double)(y
) * m_scaleY
+ 0.5);
162 return (wxCoord
)((double)(y
) * m_scaleY
- 0.5);
165 MGLDevCtx
*GetMGLDC() const { return m_MGLDC
; }
166 void SetMGLDC(MGLDevCtx
*mgldc
, bool OwnsMGLDC
= FALSE
);
169 virtual bool DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
170 int style
= wxFLOOD_SURFACE
);
172 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const;
174 virtual void DoDrawPoint(wxCoord x
, wxCoord y
);
175 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
177 virtual void DoDrawArc(wxCoord x1
, wxCoord y1
,
178 wxCoord x2
, wxCoord y2
,
179 wxCoord xc
, wxCoord yc
);
180 virtual void DoDrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
181 double sa
, double ea
);
183 virtual void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
184 virtual void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
185 wxCoord width
, wxCoord height
,
187 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
189 virtual void DoCrossHair(wxCoord x
, wxCoord y
);
191 virtual void DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
);
192 virtual void DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
193 bool useMask
= FALSE
);
195 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
196 virtual void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
199 virtual bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
200 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
201 int rop
= wxCOPY
, bool useMask
= FALSE
, wxCoord xsrcMask
= -1, wxCoord ysrcMask
= -1);
203 // this is gnarly - we can't even call this function DoSetClippingRegion()
204 // because of virtual function hiding
205 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
);
206 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
207 wxCoord width
, wxCoord height
);
208 virtual void DoGetClippingRegion(wxCoord
*x
, wxCoord
*y
,
209 wxCoord
*width
, wxCoord
*height
)
211 GetClippingBox(x
, y
, width
, height
);
214 virtual void DoGetSize(int *width
, int *height
) const;
215 virtual void DoGetSizeMM(int* width
, int* height
) const;
217 virtual void DoDrawLines(int n
, wxPoint points
[],
218 wxCoord xoffset
, wxCoord yoffset
);
219 virtual void DoDrawPolygon(int n
, wxPoint points
[],
220 wxCoord xoffset
, wxCoord yoffset
,
221 int fillStyle
= wxODDEVEN_RULE
);
223 // implementation from now on:
226 // setup newly attached MGLDevCtx for wxDC's use
227 // (does things like setting RGB blending mode for antialiased texts):
228 void InitializeMGLDC();
230 // common part of DoDrawText() and DoDrawRotatedText()
231 void DrawAnyText(const wxString
& text
, wxCoord x
, wxCoord y
);
233 // MGL uses pens as both wxPens and wxBrushes, so we have to
234 // switch them as needed:
237 void SelectMGLStipplePen(int style
);
238 void SelectMGLFatPen(int style
, int flag
);
240 // Select m_font into m_MGLDC:
241 bool SelectMGLFont();
243 // Convert wxWin logical function to MGL rop:
244 int LogicalFunctionToMGLRop(int logFunc
) const;
246 // Unified implementation of DrawIcon, DrawBitmap and Blit:
247 void DoDrawSubBitmap(const wxBitmap
&bmp
,
248 wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
249 wxCoord destx
, wxCoord desty
, int rop
, bool useMask
);
251 // MGL DC class we use:
255 // helper variables for SelectXXXX():
257 bool m_brushSelected
;
258 bool m_downloadedPatterns
[2];
260 // MGL does not render lines with width>1 with endings centered
261 // at given coords but with top left corner of the pen at them,
262 // these offsets are used to correct it. They are computed by
264 int m_penOfsX
, m_penOfsY
;
266 double m_mm_to_pix_x
, m_mm_to_pix_y
;
268 wxPalette m_oldPalette
;
270 wxRegion m_currentClippingRegion
;
271 wxRegion m_globalClippingRegion
;
273 // wxDC::Blit handles memoryDCs as special cases :(