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 //-----------------------------------------------------------------------------
33 #define MM_ISOTROPIC 1
34 #define MM_ANISOTROPIC 2
42 //-----------------------------------------------------------------------------
44 //-----------------------------------------------------------------------------
47 // MGL fwd declarations:
52 class WXDLLEXPORT wxDC
: public wxDCBase
54 DECLARE_DYNAMIC_CLASS(wxDC
)
60 // implement base class pure virtuals
61 // ----------------------------------
65 virtual bool StartDoc(const wxString
& message
);
66 virtual void EndDoc();
68 virtual void StartPage();
69 virtual void EndPage();
71 virtual void SetFont(const wxFont
& font
);
72 virtual void SetPen(const wxPen
& pen
);
73 virtual void SetBrush(const wxBrush
& brush
);
74 virtual void SetBackground(const wxBrush
& brush
);
75 virtual void SetBackgroundMode(int mode
);
76 virtual void SetPalette(const wxPalette
& palette
);
78 virtual void DestroyClippingRegion();
80 virtual wxCoord
GetCharHeight() const;
81 virtual wxCoord
GetCharWidth() const;
82 virtual void DoGetTextExtent(const wxString
& string
,
83 wxCoord
*x
, wxCoord
*y
,
84 wxCoord
*descent
= NULL
,
85 wxCoord
*externalLeading
= NULL
,
86 wxFont
*theFont
= NULL
) const;
88 virtual bool CanDrawBitmap() const;
89 virtual bool CanGetTextExtent() const;
90 virtual int GetDepth() const;
91 virtual wxSize
GetPPI() const;
93 virtual void SetMapMode(int mode
);
94 virtual void SetUserScale(double x
, double y
);
95 virtual void SetLogicalScale(double x
, double y
);
96 virtual void SetLogicalOrigin(wxCoord x
, wxCoord y
);
97 virtual void SetDeviceOrigin(wxCoord x
, wxCoord y
);
98 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
);
99 virtual void SetLogicalFunction(int function
);
101 // implementation from now on
102 // --------------------------
104 virtual void ComputeScaleAndOrigin();
106 wxCoord
XDEV2LOG(wxCoord x
) const
108 wxCoord new_x
= x
- m_deviceOriginX
;
110 return (wxCoord
)((double)(new_x
) / m_scaleX
+ 0.5) * m_signX
+ m_logicalOriginX
;
112 return (wxCoord
)((double)(new_x
) / m_scaleX
- 0.5) * m_signX
+ m_logicalOriginX
;
114 wxCoord
XDEV2LOGREL(wxCoord x
) const
117 return (wxCoord
)((double)(x
) / m_scaleX
+ 0.5);
119 return (wxCoord
)((double)(x
) / m_scaleX
- 0.5);
121 wxCoord
YDEV2LOG(wxCoord y
) const
123 wxCoord new_y
= y
- m_deviceOriginY
;
125 return (wxCoord
)((double)(new_y
) / m_scaleY
+ 0.5) * m_signY
+ m_logicalOriginY
;
127 return (wxCoord
)((double)(new_y
) / m_scaleY
- 0.5) * m_signY
+ m_logicalOriginY
;
129 wxCoord
YDEV2LOGREL(wxCoord y
) const
132 return (wxCoord
)((double)(y
) / m_scaleY
+ 0.5);
134 return (wxCoord
)((double)(y
) / m_scaleY
- 0.5);
136 wxCoord
XLOG2DEV(wxCoord x
) const
138 wxCoord new_x
= x
- m_logicalOriginX
;
140 return (wxCoord
)((double)(new_x
) * m_scaleX
+ 0.5) * m_signX
+ m_deviceOriginX
;
142 return (wxCoord
)((double)(new_x
) * m_scaleX
- 0.5) * m_signX
+ m_deviceOriginX
;
144 wxCoord
XLOG2DEVREL(wxCoord x
) const
147 return (wxCoord
)((double)(x
) * m_scaleX
+ 0.5);
149 return (wxCoord
)((double)(x
) * m_scaleX
- 0.5);
151 wxCoord
YLOG2DEV(wxCoord y
) const
153 wxCoord new_y
= y
- m_logicalOriginY
;
155 return (wxCoord
)((double)(new_y
) * m_scaleY
+ 0.5) * m_signY
+ m_deviceOriginY
;
157 return (wxCoord
)((double)(new_y
) * m_scaleY
- 0.5) * m_signY
+ m_deviceOriginY
;
159 wxCoord
YLOG2DEVREL(wxCoord y
) const
162 return (wxCoord
)((double)(y
) * m_scaleY
+ 0.5);
164 return (wxCoord
)((double)(y
) * m_scaleY
- 0.5);
167 MGLDevCtx
*GetMGLDC() const { return m_MGLDC
; }
168 void SetMGLDC(MGLDevCtx
*mgldc
, bool OwnsMGLDC
= FALSE
);
171 virtual bool DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
172 int style
= wxFLOOD_SURFACE
);
174 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const;
176 virtual void DoDrawPoint(wxCoord x
, wxCoord y
);
177 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
179 virtual void DoDrawArc(wxCoord x1
, wxCoord y1
,
180 wxCoord x2
, wxCoord y2
,
181 wxCoord xc
, wxCoord yc
);
182 virtual void DoDrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
183 double sa
, double ea
);
185 virtual void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
186 virtual void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
187 wxCoord width
, wxCoord height
,
189 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
191 virtual void DoCrossHair(wxCoord x
, wxCoord y
);
193 virtual void DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
);
194 virtual void DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
195 bool useMask
= FALSE
);
197 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
198 virtual void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
201 virtual bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
202 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
203 int rop
= wxCOPY
, bool useMask
= FALSE
, wxCoord xsrcMask
= -1, wxCoord ysrcMask
= -1);
205 // this is gnarly - we can't even call this function DoSetClippingRegion()
206 // because of virtual function hiding
207 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
);
208 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
209 wxCoord width
, wxCoord height
);
211 virtual void DoGetSize(int *width
, int *height
) const;
212 virtual void DoGetSizeMM(int* width
, int* height
) const;
214 virtual void DoDrawLines(int n
, wxPoint points
[],
215 wxCoord xoffset
, wxCoord yoffset
);
216 virtual void DoDrawPolygon(int n
, wxPoint points
[],
217 wxCoord xoffset
, wxCoord yoffset
,
218 int fillStyle
= wxODDEVEN_RULE
);
220 // implementation from now on:
223 // setup newly attached MGLDevCtx for wxDC's use
224 // (does things like setting RGB blending mode for antialiased texts):
225 void InitializeMGLDC();
227 // common part of DoDrawText() and DoDrawRotatedText()
228 void DrawAnyText(const wxString
& text
, wxCoord x
, wxCoord y
);
230 // MGL uses pens as both wxPens and wxBrushes, so we have to
231 // switch them as needed:
234 void SelectMGLStipplePen(int style
);
235 void SelectMGLFatPen(int style
, int flag
);
237 // Select m_font into m_MGLDC:
238 bool SelectMGLFont();
240 // Convert wxWin logical function to MGL rop:
241 int LogicalFunctionToMGLRop(int logFunc
) const;
243 // Unified implementation of DrawIcon, DrawBitmap and Blit:
244 void DoDrawSubBitmap(const wxBitmap
&bmp
,
245 wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
246 wxCoord destx
, wxCoord desty
, int rop
, bool useMask
);
248 // MGL DC class we use:
252 // helper variables for SelectXXXX():
254 bool m_brushSelected
;
255 bool m_downloadedPatterns
[2];
257 // MGL does not render lines with width>1 with endings centered
258 // at given coords but with top left corner of the pen at them,
259 // these offsets are used to correct it. They are computed by
261 int m_penOfsX
, m_penOfsY
;
263 double m_mm_to_pix_x
, m_mm_to_pix_y
;
265 wxPalette m_oldPalette
;
267 wxRegion m_currentClippingRegion
;
268 wxRegion m_globalClippingRegion
;
270 // wxDC::Blit handles memoryDCs as special cases :(