1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
15 #pragma interface "dc.h"
20 #include "wx/region.h"
22 //-----------------------------------------------------------------------------
24 //-----------------------------------------------------------------------------
26 class WXDLLEXPORT wxDC
;
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
33 #define MM_ISOTROPIC 1
34 #define MM_ANISOTROPIC 2
41 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
46 // MGL fwd declarations:
51 class WXDLLEXPORT wxDC
: public wxDCBase
53 DECLARE_DYNAMIC_CLASS(wxDC
)
59 // implement base class pure virtuals
60 // ----------------------------------
64 virtual bool StartDoc(const wxString
& message
);
65 virtual void EndDoc();
67 virtual void StartPage();
68 virtual void EndPage();
70 virtual void SetFont(const wxFont
& font
);
71 virtual void SetPen(const wxPen
& pen
);
72 virtual void SetBrush(const wxBrush
& brush
);
73 virtual void SetBackground(const wxBrush
& brush
);
74 virtual void SetBackgroundMode(int mode
);
75 virtual void SetPalette(const wxPalette
& palette
);
77 virtual void DestroyClippingRegion();
79 virtual wxCoord
GetCharHeight() const;
80 virtual wxCoord
GetCharWidth() const;
81 virtual void DoGetTextExtent(const wxString
& string
,
82 wxCoord
*x
, wxCoord
*y
,
83 wxCoord
*descent
= NULL
,
84 wxCoord
*externalLeading
= NULL
,
85 wxFont
*theFont
= NULL
) const;
87 virtual bool CanDrawBitmap() const;
88 virtual bool CanGetTextExtent() const;
89 virtual int GetDepth() const;
90 virtual wxSize
GetPPI() const;
92 virtual void SetMapMode(int mode
);
93 virtual void SetUserScale(double x
, double y
);
94 virtual void SetLogicalScale(double x
, double y
);
95 virtual void SetLogicalOrigin(wxCoord x
, wxCoord y
);
96 virtual void SetDeviceOrigin(wxCoord x
, wxCoord y
);
97 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
);
98 virtual void SetLogicalFunction(int function
);
100 // implementation from now on
101 // --------------------------
103 virtual void ComputeScaleAndOrigin();
105 wxCoord
XDEV2LOG(wxCoord x
) const
107 wxCoord new_x
= x
- m_deviceOriginX
;
109 return (wxCoord
)((double)(new_x
) / m_scaleX
+ 0.5) * m_signX
+ m_logicalOriginX
;
111 return (wxCoord
)((double)(new_x
) / m_scaleX
- 0.5) * m_signX
+ m_logicalOriginX
;
113 wxCoord
XDEV2LOGREL(wxCoord x
) const
116 return (wxCoord
)((double)(x
) / m_scaleX
+ 0.5);
118 return (wxCoord
)((double)(x
) / m_scaleX
- 0.5);
120 wxCoord
YDEV2LOG(wxCoord y
) const
122 wxCoord new_y
= y
- m_deviceOriginY
;
124 return (wxCoord
)((double)(new_y
) / m_scaleY
+ 0.5) * m_signY
+ m_logicalOriginY
;
126 return (wxCoord
)((double)(new_y
) / m_scaleY
- 0.5) * m_signY
+ m_logicalOriginY
;
128 wxCoord
YDEV2LOGREL(wxCoord y
) const
131 return (wxCoord
)((double)(y
) / m_scaleY
+ 0.5);
133 return (wxCoord
)((double)(y
) / m_scaleY
- 0.5);
135 wxCoord
XLOG2DEV(wxCoord x
) const
137 wxCoord new_x
= x
- m_logicalOriginX
;
139 return (wxCoord
)((double)(new_x
) * m_scaleX
+ 0.5) * m_signX
+ m_deviceOriginX
;
141 return (wxCoord
)((double)(new_x
) * m_scaleX
- 0.5) * m_signX
+ m_deviceOriginX
;
143 wxCoord
XLOG2DEVREL(wxCoord x
) const
146 return (wxCoord
)((double)(x
) * m_scaleX
+ 0.5);
148 return (wxCoord
)((double)(x
) * m_scaleX
- 0.5);
150 wxCoord
YLOG2DEV(wxCoord y
) const
152 wxCoord new_y
= y
- m_logicalOriginY
;
154 return (wxCoord
)((double)(new_y
) * m_scaleY
+ 0.5) * m_signY
+ m_deviceOriginY
;
156 return (wxCoord
)((double)(new_y
) * m_scaleY
- 0.5) * m_signY
+ m_deviceOriginY
;
158 wxCoord
YLOG2DEVREL(wxCoord y
) const
161 return (wxCoord
)((double)(y
) * m_scaleY
+ 0.5);
163 return (wxCoord
)((double)(y
) * m_scaleY
- 0.5);
166 MGLDevCtx
*GetMGLDC() const { return m_MGLDC
; }
167 void SetMGLDC(MGLDevCtx
*mgldc
, bool OwnsMGLDC
= FALSE
);
170 virtual void DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
171 int style
= wxFLOOD_SURFACE
);
173 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const;
175 virtual void DoDrawPoint(wxCoord x
, wxCoord y
);
176 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
178 virtual void DoDrawArc(wxCoord x1
, wxCoord y1
,
179 wxCoord x2
, wxCoord y2
,
180 wxCoord xc
, wxCoord yc
);
181 virtual void DoDrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
182 double sa
, double ea
);
184 virtual void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
185 virtual void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
186 wxCoord width
, wxCoord height
,
188 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
190 virtual void DoCrossHair(wxCoord x
, wxCoord y
);
192 virtual void DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
);
193 virtual void DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
194 bool useMask
= FALSE
);
196 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
197 virtual void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
200 virtual bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
201 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
202 int rop
= wxCOPY
, bool useMask
= FALSE
, wxCoord xsrcMask
= -1, wxCoord ysrcMask
= -1);
204 // this is gnarly - we can't even call this function DoSetClippingRegion()
205 // because of virtual function hiding
206 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
);
207 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
208 wxCoord width
, wxCoord height
);
209 virtual void DoGetClippingRegion(wxCoord
*x
, wxCoord
*y
,
210 wxCoord
*width
, wxCoord
*height
)
212 GetClippingBox(x
, y
, width
, height
);
215 virtual void DoGetSize(int *width
, int *height
) const;
216 virtual void DoGetSizeMM(int* width
, int* height
) const;
218 virtual void DoDrawLines(int n
, wxPoint points
[],
219 wxCoord xoffset
, wxCoord yoffset
);
220 virtual void DoDrawPolygon(int n
, wxPoint points
[],
221 wxCoord xoffset
, wxCoord yoffset
,
222 int fillStyle
= wxODDEVEN_RULE
);
224 // implementation from now on:
227 // setup newly attached MGLDevCtx for wxDC's use
228 // (does things like setting RGB blending mode for antialiased texts):
229 void InitializeMGLDC();
231 // common part of DoDrawText() and DoDrawRotatedText()
232 void DrawAnyText(const wxString
& text
, wxCoord x
, wxCoord y
);
234 // MGL uses pens as both wxPens and wxBrushes, so we have to
235 // switch them as needed:
238 void SelectMGLStipplePen(int style
);
239 void SelectMGLFatPen(int style
, int flag
);
241 // Select m_font into m_MGLDC:
242 bool SelectMGLFont();
244 // Convert wxWin logical function to MGL rop:
245 int LogicalFunctionToMGLRop(int logFunc
) const;
247 // Unified implementation of DrawIcon, DrawBitmap and Blit:
248 void DoDrawSubBitmap(const wxBitmap
&bmp
,
249 wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
250 wxCoord destx
, wxCoord desty
, int rop
, bool useMask
);
252 // MGL DC class we use:
256 // helper variables for SelectXXXX():
258 bool m_brushSelected
;
259 bool m_downloadedPatterns
[2];
261 // MGL does not render lines with width>1 with endings centered
262 // at given coords but with top left corner of the pen at them,
263 // these offsets are used to correct it. They are computed by
265 int m_penOfsX
, m_penOfsY
;
267 double m_mm_to_pix_x
, m_mm_to_pix_y
;
269 wxPalette m_oldPalette
;
271 wxRegion m_currentClippingRegion
;
272 // clipping region m_MGLDC had when it was attached:
273 MGLRegion
*m_globalClippingRegion
;
275 // wxDC::Blit handles memoryDCs as special cases :(