]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mgl/dc.h
made wxTLW::SetIcon() non-virtual, it was already implemented in terms of
[wxWidgets.git] / include / wx / mgl / dc.h
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 #include "wx/defs.h"
15 #include "wx/region.h"
16
17 //-----------------------------------------------------------------------------
18 // classes
19 //-----------------------------------------------------------------------------
20
21 class WXDLLEXPORT wxDC;
22
23 //-----------------------------------------------------------------------------
24 // constants
25 //-----------------------------------------------------------------------------
26
27 #ifndef MM_TEXT
28 #define MM_TEXT 0
29 #define MM_ISOTROPIC 1
30 #define MM_ANISOTROPIC 2
31 #define MM_LOMETRIC 3
32 #define MM_HIMETRIC 4
33 #define MM_TWIPS 5
34 #define MM_POINTS 6
35 #define MM_METRIC 7
36 #endif
37
38 //-----------------------------------------------------------------------------
39 // wxDC
40 //-----------------------------------------------------------------------------
41
42
43 // MGL fwd declarations:
44 class MGLDevCtx;
45 class MGLRegion;
46 struct font_t;
47
48 class WXDLLEXPORT wxDC : public wxDCBase
49 {
50 DECLARE_DYNAMIC_CLASS(wxDC)
51
52 public:
53 wxDC();
54 virtual ~wxDC();
55
56 // implement base class pure virtuals
57 // ----------------------------------
58
59 virtual void Clear();
60
61 virtual bool StartDoc(const wxString& message);
62 virtual void EndDoc();
63
64 virtual void StartPage();
65 virtual void EndPage();
66
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);
73
74 virtual void DestroyClippingRegion();
75
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;
83
84 virtual bool CanDrawBitmap() const;
85 virtual bool CanGetTextExtent() const;
86 virtual int GetDepth() const;
87 virtual wxSize GetPPI() const;
88
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);
96
97 // implementation from now on
98 // --------------------------
99
100 virtual void ComputeScaleAndOrigin();
101
102 wxCoord XDEV2LOG(wxCoord x) const
103 {
104 return wxRound((double)(x - m_deviceOriginX) / m_scaleX) * m_signX + m_logicalOriginX;
105 }
106 wxCoord XDEV2LOGREL(wxCoord x) const
107 {
108 return wxRound((double)(x) / m_scaleX);
109 }
110 wxCoord YDEV2LOG(wxCoord y) const
111 {
112 return wxRound((double)(y - m_deviceOriginY) / m_scaleY) * m_signY + m_logicalOriginY;
113 }
114 wxCoord YDEV2LOGREL(wxCoord y) const
115 {
116 return wxRound((double)(y) / m_scaleY);
117 }
118 wxCoord XLOG2DEV(wxCoord x) const
119 {
120 return wxRound((double)(x - m_logicalOriginX) * m_scaleX) * m_signX + m_deviceOriginX;
121 }
122 wxCoord XLOG2DEVREL(wxCoord x) const
123 {
124 return wxRound((double)(x) * m_scaleX);
125 }
126 wxCoord YLOG2DEV(wxCoord y) const
127 {
128 return wxRound((double)(y - m_logicalOriginY) * m_scaleY) * m_signY + m_deviceOriginY;
129 }
130 wxCoord YLOG2DEVREL(wxCoord y) const
131 {
132 return wxRound((double)(y) * m_scaleY);
133 }
134
135 MGLDevCtx *GetMGLDC() const { return m_MGLDC; }
136 void SetMGLDC(MGLDevCtx *mgldc, bool OwnsMGLDC = false);
137
138 protected:
139 virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,
140 int style = wxFLOOD_SURFACE);
141
142 virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const;
143
144 virtual void DoDrawPoint(wxCoord x, wxCoord y);
145 virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
146
147 virtual void DoDrawArc(wxCoord x1, wxCoord y1,
148 wxCoord x2, wxCoord y2,
149 wxCoord xc, wxCoord yc);
150 virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
151 double sa, double ea);
152
153 virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
154 virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y,
155 wxCoord width, wxCoord height,
156 double radius);
157 virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
158
159 virtual void DoCrossHair(wxCoord x, wxCoord y);
160
161 virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y);
162 virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
163 bool useMask = false);
164
165 virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y);
166 virtual void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y,
167 double angle);
168
169 virtual bool DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
170 wxDC *source, wxCoord xsrc, wxCoord ysrc,
171 int rop = wxCOPY, bool useMask = false, wxCoord xsrcMask = -1, wxCoord ysrcMask = -1);
172
173 // this is gnarly - we can't even call this function DoSetClippingRegion()
174 // because of virtual function hiding
175 virtual void DoSetClippingRegionAsRegion(const wxRegion& region);
176 virtual void DoSetClippingRegion(wxCoord x, wxCoord y,
177 wxCoord width, wxCoord height);
178
179 virtual void DoGetSize(int *width, int *height) const;
180 virtual void DoGetSizeMM(int* width, int* height) const;
181
182 virtual void DoDrawLines(int n, wxPoint points[],
183 wxCoord xoffset, wxCoord yoffset);
184 virtual void DoDrawPolygon(int n, wxPoint points[],
185 wxCoord xoffset, wxCoord yoffset,
186 int fillStyle = wxODDEVEN_RULE);
187
188 // implementation from now on:
189
190 protected:
191 // setup newly attached MGLDevCtx for wxDC's use
192 // (does things like setting RGB blending mode for antialiased texts):
193 void InitializeMGLDC();
194
195 // common part of DoDrawText() and DoDrawRotatedText()
196 void DrawAnyText(const wxString& text, wxCoord x, wxCoord y);
197
198 // MGL uses pens as both wxPens and wxBrushes, so we have to
199 // switch them as needed:
200 void SelectPen();
201 void SelectBrush();
202 void SelectMGLStipplePen(int style);
203 void SelectMGLFatPen(int style, int flag);
204
205 // Select m_font into m_MGLDC:
206 bool SelectMGLFont();
207
208 // Convert wxWin logical function to MGL rop:
209 int LogicalFunctionToMGLRop(int logFunc) const;
210
211 // Unified implementation of DrawIcon, DrawBitmap and Blit:
212 void DoDrawSubBitmap(const wxBitmap &bmp,
213 wxCoord x, wxCoord y, wxCoord w, wxCoord h,
214 wxCoord destx, wxCoord desty, int rop, bool useMask);
215
216 // MGL DC class we use:
217 MGLDevCtx *m_MGLDC;
218 bool m_OwnsMGLDC:1;
219
220 // helper variables for SelectXXXX():
221 bool m_penSelected;
222 bool m_brushSelected;
223 bool m_downloadedPatterns[2];
224
225 // MGL does not render lines with width>1 with endings centered
226 // at given coords but with top left corner of the pen at them,
227 // these offsets are used to correct it. They are computed by
228 // SelectPen.
229 int m_penOfsX, m_penOfsY;
230
231 double m_mm_to_pix_x, m_mm_to_pix_y;
232
233 wxPalette m_oldPalette;
234
235 wxRegion m_currentClippingRegion;
236 wxRegion m_globalClippingRegion;
237
238 // wxDC::Blit handles memoryDCs as special cases :(
239 bool m_isMemDC;
240
241 font_t *m_mglFont;
242 };
243
244 #endif
245 // _WX_DC_H_