]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: dc.h | |
3 | // Purpose: wxDC class | |
4 | // Author: Vaclav Slavik | |
5 | // Created: 2001/03/09 | |
6 | // RCS-ID: $Id$ | |
7 | // Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com) | |
8 | // Licence: wxWindows licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | #ifndef _WX_DC_H_ | |
12 | #define _WX_DC_H_ | |
13 | ||
14 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) | |
15 | #pragma interface "dc.h" | |
16 | #endif | |
17 | ||
18 | #include "wx/defs.h" | |
19 | #include "wx/region.h" | |
20 | ||
21 | //----------------------------------------------------------------------------- | |
22 | // classes | |
23 | //----------------------------------------------------------------------------- | |
24 | ||
25 | class WXDLLEXPORT wxDC; | |
26 | ||
27 | //----------------------------------------------------------------------------- | |
28 | // constants | |
29 | //----------------------------------------------------------------------------- | |
30 | ||
31 | #ifndef MM_TEXT | |
32 | #define MM_TEXT 0 | |
33 | #define MM_ISOTROPIC 1 | |
34 | #define MM_ANISOTROPIC 2 | |
35 | #define MM_LOMETRIC 3 | |
36 | #define MM_HIMETRIC 4 | |
37 | #define MM_TWIPS 5 | |
38 | #define MM_POINTS 6 | |
39 | #define MM_METRIC 7 | |
40 | #endif | |
41 | ||
42 | //----------------------------------------------------------------------------- | |
43 | // wxDC | |
44 | //----------------------------------------------------------------------------- | |
45 | ||
46 | ||
47 | // MGL fwd declarations: | |
48 | class MGLDevCtx; | |
49 | class MGLRegion; | |
50 | struct font_t; | |
51 | ||
52 | class WXDLLEXPORT wxDC : public wxDCBase | |
53 | { | |
54 | DECLARE_DYNAMIC_CLASS(wxDC) | |
55 | ||
56 | public: | |
57 | wxDC(); | |
58 | ~wxDC(); | |
59 | ||
60 | // implement base class pure virtuals | |
61 | // ---------------------------------- | |
62 | ||
63 | virtual void Clear(); | |
64 | ||
65 | virtual bool StartDoc(const wxString& message); | |
66 | virtual void EndDoc(); | |
67 | ||
68 | virtual void StartPage(); | |
69 | virtual void EndPage(); | |
70 | ||
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); | |
77 | ||
78 | virtual void DestroyClippingRegion(); | |
79 | ||
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; | |
87 | ||
88 | virtual bool CanDrawBitmap() const; | |
89 | virtual bool CanGetTextExtent() const; | |
90 | virtual int GetDepth() const; | |
91 | virtual wxSize GetPPI() const; | |
92 | ||
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); | |
100 | ||
101 | // implementation from now on | |
102 | // -------------------------- | |
103 | ||
104 | virtual void ComputeScaleAndOrigin(); | |
105 | ||
106 | wxCoord XDEV2LOG(wxCoord x) const | |
107 | { | |
108 | wxCoord new_x = x - m_deviceOriginX; | |
109 | if (new_x > 0) | |
110 | return (wxCoord)((double)(new_x) / m_scaleX + 0.5) * m_signX + m_logicalOriginX; | |
111 | else | |
112 | return (wxCoord)((double)(new_x) / m_scaleX - 0.5) * m_signX + m_logicalOriginX; | |
113 | } | |
114 | wxCoord XDEV2LOGREL(wxCoord x) const | |
115 | { | |
116 | if (x > 0) | |
117 | return (wxCoord)((double)(x) / m_scaleX + 0.5); | |
118 | else | |
119 | return (wxCoord)((double)(x) / m_scaleX - 0.5); | |
120 | } | |
121 | wxCoord YDEV2LOG(wxCoord y) const | |
122 | { | |
123 | wxCoord new_y = y - m_deviceOriginY; | |
124 | if (new_y > 0) | |
125 | return (wxCoord)((double)(new_y) / m_scaleY + 0.5) * m_signY + m_logicalOriginY; | |
126 | else | |
127 | return (wxCoord)((double)(new_y) / m_scaleY - 0.5) * m_signY + m_logicalOriginY; | |
128 | } | |
129 | wxCoord YDEV2LOGREL(wxCoord y) const | |
130 | { | |
131 | if (y > 0) | |
132 | return (wxCoord)((double)(y) / m_scaleY + 0.5); | |
133 | else | |
134 | return (wxCoord)((double)(y) / m_scaleY - 0.5); | |
135 | } | |
136 | wxCoord XLOG2DEV(wxCoord x) const | |
137 | { | |
138 | wxCoord new_x = x - m_logicalOriginX; | |
139 | if (new_x > 0) | |
140 | return (wxCoord)((double)(new_x) * m_scaleX + 0.5) * m_signX + m_deviceOriginX; | |
141 | else | |
142 | return (wxCoord)((double)(new_x) * m_scaleX - 0.5) * m_signX + m_deviceOriginX; | |
143 | } | |
144 | wxCoord XLOG2DEVREL(wxCoord x) const | |
145 | { | |
146 | if (x > 0) | |
147 | return (wxCoord)((double)(x) * m_scaleX + 0.5); | |
148 | else | |
149 | return (wxCoord)((double)(x) * m_scaleX - 0.5); | |
150 | } | |
151 | wxCoord YLOG2DEV(wxCoord y) const | |
152 | { | |
153 | wxCoord new_y = y - m_logicalOriginY; | |
154 | if (new_y > 0) | |
155 | return (wxCoord)((double)(new_y) * m_scaleY + 0.5) * m_signY + m_deviceOriginY; | |
156 | else | |
157 | return (wxCoord)((double)(new_y) * m_scaleY - 0.5) * m_signY + m_deviceOriginY; | |
158 | } | |
159 | wxCoord YLOG2DEVREL(wxCoord y) const | |
160 | { | |
161 | if (y > 0) | |
162 | return (wxCoord)((double)(y) * m_scaleY + 0.5); | |
163 | else | |
164 | return (wxCoord)((double)(y) * m_scaleY - 0.5); | |
165 | } | |
166 | ||
167 | MGLDevCtx *GetMGLDC() const { return m_MGLDC; } | |
168 | void SetMGLDC(MGLDevCtx *mgldc, bool OwnsMGLDC = FALSE); | |
169 | ||
170 | protected: | |
171 | virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, | |
172 | int style = wxFLOOD_SURFACE); | |
173 | ||
174 | virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const; | |
175 | ||
176 | virtual void DoDrawPoint(wxCoord x, wxCoord y); | |
177 | virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2); | |
178 | ||
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); | |
184 | ||
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, | |
188 | double radius); | |
189 | virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height); | |
190 | ||
191 | virtual void DoCrossHair(wxCoord x, wxCoord y); | |
192 | ||
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); | |
196 | ||
197 | virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y); | |
198 | virtual void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, | |
199 | double angle); | |
200 | ||
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); | |
204 | ||
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); | |
210 | virtual void DoGetClippingRegion(wxCoord *x, wxCoord *y, | |
211 | wxCoord *width, wxCoord *height) | |
212 | { | |
213 | GetClippingBox(x, y, width, height); | |
214 | } | |
215 | ||
216 | virtual void DoGetSize(int *width, int *height) const; | |
217 | virtual void DoGetSizeMM(int* width, int* height) const; | |
218 | ||
219 | virtual void DoDrawLines(int n, wxPoint points[], | |
220 | wxCoord xoffset, wxCoord yoffset); | |
221 | virtual void DoDrawPolygon(int n, wxPoint points[], | |
222 | wxCoord xoffset, wxCoord yoffset, | |
223 | int fillStyle = wxODDEVEN_RULE); | |
224 | ||
225 | // implementation from now on: | |
226 | ||
227 | protected: | |
228 | // setup newly attached MGLDevCtx for wxDC's use | |
229 | // (does things like setting RGB blending mode for antialiased texts): | |
230 | void InitializeMGLDC(); | |
231 | ||
232 | // common part of DoDrawText() and DoDrawRotatedText() | |
233 | void DrawAnyText(const wxString& text, wxCoord x, wxCoord y); | |
234 | ||
235 | // MGL uses pens as both wxPens and wxBrushes, so we have to | |
236 | // switch them as needed: | |
237 | void SelectPen(); | |
238 | void SelectBrush(); | |
239 | void SelectMGLStipplePen(int style); | |
240 | void SelectMGLFatPen(int style, int flag); | |
241 | ||
242 | // Select m_font into m_MGLDC: | |
243 | bool SelectMGLFont(); | |
244 | ||
245 | // Convert wxWin logical function to MGL rop: | |
246 | int LogicalFunctionToMGLRop(int logFunc) const; | |
247 | ||
248 | // Unified implementation of DrawIcon, DrawBitmap and Blit: | |
249 | void DoDrawSubBitmap(const wxBitmap &bmp, | |
250 | wxCoord x, wxCoord y, wxCoord w, wxCoord h, | |
251 | wxCoord destx, wxCoord desty, int rop, bool useMask); | |
252 | ||
253 | // MGL DC class we use: | |
254 | MGLDevCtx *m_MGLDC; | |
255 | bool m_OwnsMGLDC:1; | |
256 | ||
257 | // helper variables for SelectXXXX(): | |
258 | bool m_penSelected; | |
259 | bool m_brushSelected; | |
260 | bool m_downloadedPatterns[2]; | |
261 | ||
262 | // MGL does not render lines with width>1 with endings centered | |
263 | // at given coords but with top left corner of the pen at them, | |
264 | // these offsets are used to correct it. They are computed by | |
265 | // SelectPen. | |
266 | int m_penOfsX, m_penOfsY; | |
267 | ||
268 | double m_mm_to_pix_x, m_mm_to_pix_y; | |
269 | ||
270 | wxPalette m_oldPalette; | |
271 | ||
272 | wxRegion m_currentClippingRegion; | |
273 | wxRegion m_globalClippingRegion; | |
274 | ||
275 | // wxDC::Blit handles memoryDCs as special cases :( | |
276 | bool m_isMemDC; | |
277 | ||
278 | font_t *m_mglFont; | |
279 | }; | |
280 | ||
281 | #endif | |
282 | // _WX_DC_H_ |