1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
15 #include "wx/region.h"
17 //-----------------------------------------------------------------------------
19 //-----------------------------------------------------------------------------
21 class WXDLLEXPORT wxDC
;
23 //-----------------------------------------------------------------------------
25 //-----------------------------------------------------------------------------
29 #define MM_ISOTROPIC 1
30 #define MM_ANISOTROPIC 2
38 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
43 // MGL fwd declarations:
48 class WXDLLEXPORT wxDC
: public wxDCBase
50 DECLARE_DYNAMIC_CLASS(wxDC
)
56 // implement base class pure virtuals
57 // ----------------------------------
61 virtual bool StartDoc(const wxString
& message
);
62 virtual void EndDoc();
64 virtual void StartPage();
65 virtual void EndPage();
67 virtual void SetFont(const wxFont
& font
);
68 virtual void SetPen(const wxPen
& pen
);
69 virtual void SetBrush(const wxBrush
& brush
);
70 virtual void SetBackground(const wxBrush
& brush
);
71 virtual void SetBackgroundMode(int mode
);
72 virtual void SetPalette(const wxPalette
& palette
);
74 virtual void DestroyClippingRegion();
76 virtual wxCoord
GetCharHeight() const;
77 virtual wxCoord
GetCharWidth() const;
78 virtual void DoGetTextExtent(const wxString
& string
,
79 wxCoord
*x
, wxCoord
*y
,
80 wxCoord
*descent
= NULL
,
81 wxCoord
*externalLeading
= NULL
,
82 wxFont
*theFont
= NULL
) const;
84 virtual bool CanDrawBitmap() const;
85 virtual bool CanGetTextExtent() const;
86 virtual int GetDepth() const;
87 virtual wxSize
GetPPI() const;
89 virtual void SetMapMode(int mode
);
90 virtual void SetUserScale(double x
, double y
);
91 virtual void SetLogicalScale(double x
, double y
);
92 virtual void SetLogicalOrigin(wxCoord x
, wxCoord y
);
93 virtual void SetDeviceOrigin(wxCoord x
, wxCoord y
);
94 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
);
95 virtual void SetLogicalFunction(int function
);
97 // implementation from now on
98 // --------------------------
100 virtual void ComputeScaleAndOrigin();
102 wxCoord
XDEV2LOG(wxCoord x
) const
104 wxCoord new_x
= x
- m_deviceOriginX
;
106 return (wxCoord
)((double)(new_x
) / m_scaleX
+ 0.5) * m_signX
+ m_logicalOriginX
;
108 return (wxCoord
)((double)(new_x
) / m_scaleX
- 0.5) * m_signX
+ m_logicalOriginX
;
110 wxCoord
XDEV2LOGREL(wxCoord x
) const
113 return (wxCoord
)((double)(x
) / m_scaleX
+ 0.5);
115 return (wxCoord
)((double)(x
) / m_scaleX
- 0.5);
117 wxCoord
YDEV2LOG(wxCoord y
) const
119 wxCoord new_y
= y
- m_deviceOriginY
;
121 return (wxCoord
)((double)(new_y
) / m_scaleY
+ 0.5) * m_signY
+ m_logicalOriginY
;
123 return (wxCoord
)((double)(new_y
) / m_scaleY
- 0.5) * m_signY
+ m_logicalOriginY
;
125 wxCoord
YDEV2LOGREL(wxCoord y
) const
128 return (wxCoord
)((double)(y
) / m_scaleY
+ 0.5);
130 return (wxCoord
)((double)(y
) / m_scaleY
- 0.5);
132 wxCoord
XLOG2DEV(wxCoord x
) const
134 wxCoord new_x
= x
- m_logicalOriginX
;
136 return (wxCoord
)((double)(new_x
) * m_scaleX
+ 0.5) * m_signX
+ m_deviceOriginX
;
138 return (wxCoord
)((double)(new_x
) * m_scaleX
- 0.5) * m_signX
+ m_deviceOriginX
;
140 wxCoord
XLOG2DEVREL(wxCoord x
) const
143 return (wxCoord
)((double)(x
) * m_scaleX
+ 0.5);
145 return (wxCoord
)((double)(x
) * m_scaleX
- 0.5);
147 wxCoord
YLOG2DEV(wxCoord y
) const
149 wxCoord new_y
= y
- m_logicalOriginY
;
151 return (wxCoord
)((double)(new_y
) * m_scaleY
+ 0.5) * m_signY
+ m_deviceOriginY
;
153 return (wxCoord
)((double)(new_y
) * m_scaleY
- 0.5) * m_signY
+ m_deviceOriginY
;
155 wxCoord
YLOG2DEVREL(wxCoord y
) const
158 return (wxCoord
)((double)(y
) * m_scaleY
+ 0.5);
160 return (wxCoord
)((double)(y
) * m_scaleY
- 0.5);
163 MGLDevCtx
*GetMGLDC() const { return m_MGLDC
; }
164 void SetMGLDC(MGLDevCtx
*mgldc
, bool OwnsMGLDC
= false);
167 virtual bool DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
168 int style
= wxFLOOD_SURFACE
);
170 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const;
172 virtual void DoDrawPoint(wxCoord x
, wxCoord y
);
173 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
175 virtual void DoDrawArc(wxCoord x1
, wxCoord y1
,
176 wxCoord x2
, wxCoord y2
,
177 wxCoord xc
, wxCoord yc
);
178 virtual void DoDrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
179 double sa
, double ea
);
181 virtual void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
182 virtual void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
183 wxCoord width
, wxCoord height
,
185 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
187 virtual void DoCrossHair(wxCoord x
, wxCoord y
);
189 virtual void DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
);
190 virtual void DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
191 bool useMask
= false);
193 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
194 virtual void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
197 virtual bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
198 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
199 int rop
= wxCOPY
, bool useMask
= false, wxCoord xsrcMask
= -1, wxCoord ysrcMask
= -1);
201 // this is gnarly - we can't even call this function DoSetClippingRegion()
202 // because of virtual function hiding
203 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
);
204 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
205 wxCoord width
, wxCoord height
);
207 virtual void DoGetSize(int *width
, int *height
) const;
208 virtual void DoGetSizeMM(int* width
, int* height
) const;
210 virtual void DoDrawLines(int n
, wxPoint points
[],
211 wxCoord xoffset
, wxCoord yoffset
);
212 virtual void DoDrawPolygon(int n
, wxPoint points
[],
213 wxCoord xoffset
, wxCoord yoffset
,
214 int fillStyle
= wxODDEVEN_RULE
);
216 // implementation from now on:
219 // setup newly attached MGLDevCtx for wxDC's use
220 // (does things like setting RGB blending mode for antialiased texts):
221 void InitializeMGLDC();
223 // common part of DoDrawText() and DoDrawRotatedText()
224 void DrawAnyText(const wxString
& text
, wxCoord x
, wxCoord y
);
226 // MGL uses pens as both wxPens and wxBrushes, so we have to
227 // switch them as needed:
230 void SelectMGLStipplePen(int style
);
231 void SelectMGLFatPen(int style
, int flag
);
233 // Select m_font into m_MGLDC:
234 bool SelectMGLFont();
236 // Convert wxWin logical function to MGL rop:
237 int LogicalFunctionToMGLRop(int logFunc
) const;
239 // Unified implementation of DrawIcon, DrawBitmap and Blit:
240 void DoDrawSubBitmap(const wxBitmap
&bmp
,
241 wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
242 wxCoord destx
, wxCoord desty
, int rop
, bool useMask
);
244 // MGL DC class we use:
248 // helper variables for SelectXXXX():
250 bool m_brushSelected
;
251 bool m_downloadedPatterns
[2];
253 // MGL does not render lines with width>1 with endings centered
254 // at given coords but with top left corner of the pen at them,
255 // these offsets are used to correct it. They are computed by
257 int m_penOfsX
, m_penOfsY
;
259 double m_mm_to_pix_x
, m_mm_to_pix_y
;
261 wxPalette m_oldPalette
;
263 wxRegion m_currentClippingRegion
;
264 wxRegion m_globalClippingRegion
;
266 // wxDC::Blit handles memoryDCs as special cases :(