]>
Commit | Line | Data |
---|---|---|
8f20ea03 VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/dcmirror.h | |
3 | // Purpose: wxMirrorDC class | |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 21.07.2003 | |
7 | // RCS-ID: $Id$ | |
77ffb593 | 8 | // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org> |
65571936 | 9 | // Licence: wxWindows licence |
8f20ea03 VZ |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _WX_DCMIRROR_H_ | |
13 | #define _WX_DCMIRROR_H_ | |
14 | ||
15 | #include "wx/dc.h" | |
16 | ||
17 | // ---------------------------------------------------------------------------- | |
18 | // wxMirrorDC allows to write the same code for horz/vertical layout | |
19 | // ---------------------------------------------------------------------------- | |
20 | ||
53a2db12 | 21 | class WXDLLIMPEXP_CORE wxMirrorDCImpl : public wxDCImpl |
8f20ea03 VZ |
22 | { |
23 | public: | |
24 | // constructs a mirror DC associated with the given real DC | |
25 | // | |
26 | // if mirror parameter is true, all vertical and horizontal coordinates are | |
27 | // exchanged, otherwise this class behaves in exactly the same way as a | |
28 | // plain DC | |
f0875501 VZ |
29 | wxMirrorDCImpl(wxDC *owner, wxDCImpl& dc, bool mirror) |
30 | : wxDCImpl(owner), | |
31 | m_dc(dc) | |
32 | { | |
33 | m_mirror = mirror; | |
34 | } | |
8f20ea03 VZ |
35 | |
36 | // wxDCBase operations | |
37 | virtual void Clear() { m_dc.Clear(); } | |
38 | virtual void SetFont(const wxFont& font) { m_dc.SetFont(font); } | |
39 | virtual void SetPen(const wxPen& pen) { m_dc.SetPen(pen); } | |
40 | virtual void SetBrush(const wxBrush& brush) { m_dc.SetBrush(brush); } | |
41 | virtual void SetBackground(const wxBrush& brush) | |
42 | { m_dc.SetBackground(brush); } | |
43 | virtual void SetBackgroundMode(int mode) { m_dc.SetBackgroundMode(mode); } | |
44 | #if wxUSE_PALETTE | |
45 | virtual void SetPalette(const wxPalette& palette) | |
46 | { m_dc.SetPalette(palette); } | |
47 | #endif // wxUSE_PALETTE | |
48 | virtual void DestroyClippingRegion() { m_dc.DestroyClippingRegion(); } | |
49 | virtual wxCoord GetCharHeight() const { return m_dc.GetCharHeight(); } | |
50 | virtual wxCoord GetCharWidth() const { return m_dc.GetCharWidth(); } | |
51 | virtual bool CanDrawBitmap() const { return m_dc.CanDrawBitmap(); } | |
52 | virtual bool CanGetTextExtent() const { return m_dc.CanGetTextExtent(); } | |
53 | virtual int GetDepth() const { return m_dc.GetDepth(); } | |
54 | virtual wxSize GetPPI() const { return m_dc.GetPPI(); } | |
f0875501 | 55 | virtual bool IsOk() const { return m_dc.IsOk(); } |
89efaf2b | 56 | virtual void SetMapMode(wxMappingMode mode) { m_dc.SetMapMode(mode); } |
8f20ea03 VZ |
57 | virtual void SetUserScale(double x, double y) |
58 | { m_dc.SetUserScale(GetX(x, y), GetY(x, y)); } | |
59 | virtual void SetLogicalOrigin(wxCoord x, wxCoord y) | |
60 | { m_dc.SetLogicalOrigin(GetX(x, y), GetY(x, y)); } | |
61 | virtual void SetDeviceOrigin(wxCoord x, wxCoord y) | |
62 | { m_dc.SetDeviceOrigin(GetX(x, y), GetY(x, y)); } | |
63 | virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp) | |
64 | { m_dc.SetAxisOrientation(GetX(xLeftRight, yBottomUp), | |
65 | GetY(xLeftRight, yBottomUp)); } | |
89efaf2b | 66 | virtual void SetLogicalFunction(wxRasterOperationMode function) |
8f20ea03 VZ |
67 | { m_dc.SetLogicalFunction(function); } |
68 | ||
9eefb5c1 RD |
69 | virtual void* GetHandle() const |
70 | { return m_dc.GetHandle(); } | |
71 | ||
8f20ea03 VZ |
72 | protected: |
73 | // returns x and y if not mirroring or y and x if mirroring | |
74 | wxCoord GetX(wxCoord x, wxCoord y) const { return m_mirror ? y : x; } | |
75 | wxCoord GetY(wxCoord x, wxCoord y) const { return m_mirror ? x : y; } | |
76 | double GetX(double x, double y) const { return m_mirror ? y : x; } | |
77 | double GetY(double x, double y) const { return m_mirror ? x : y; } | |
78 | bool GetX(bool x, bool y) const { return m_mirror ? y : x; } | |
79 | bool GetY(bool x, bool y) const { return m_mirror ? x : y; } | |
80 | ||
81 | // same thing but for pointers | |
82 | wxCoord *GetX(wxCoord *x, wxCoord *y) const { return m_mirror ? y : x; } | |
83 | wxCoord *GetY(wxCoord *x, wxCoord *y) const { return m_mirror ? x : y; } | |
84 | ||
8f20ea03 | 85 | // exchange x and y components of all points in the array if necessary |
4787c92d | 86 | wxPoint* Mirror(int n, const wxPoint*& points) const |
8f20ea03 | 87 | { |
4787c92d | 88 | wxPoint* points_alloc = NULL; |
8f20ea03 VZ |
89 | if ( m_mirror ) |
90 | { | |
4787c92d | 91 | points_alloc = new wxPoint[n]; |
8f20ea03 VZ |
92 | for ( int i = 0; i < n; i++ ) |
93 | { | |
4787c92d PC |
94 | points_alloc[i].x = points[i].y; |
95 | points_alloc[i].y = points[i].x; | |
8f20ea03 | 96 | } |
4787c92d | 97 | points = points_alloc; |
8f20ea03 | 98 | } |
4787c92d | 99 | return points_alloc; |
8f20ea03 VZ |
100 | } |
101 | ||
8f20ea03 VZ |
102 | // wxDCBase functions |
103 | virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, | |
89efaf2b | 104 | wxFloodFillStyle style = wxFLOOD_SURFACE) |
8f20ea03 VZ |
105 | { |
106 | return m_dc.DoFloodFill(GetX(x, y), GetY(x, y), col, style); | |
107 | } | |
108 | ||
109 | virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const | |
110 | { | |
111 | return m_dc.DoGetPixel(GetX(x, y), GetY(x, y), col); | |
112 | } | |
113 | ||
114 | ||
115 | virtual void DoDrawPoint(wxCoord x, wxCoord y) | |
116 | { | |
117 | m_dc.DoDrawPoint(GetX(x, y), GetY(x, y)); | |
118 | } | |
119 | ||
120 | virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) | |
121 | { | |
122 | m_dc.DoDrawLine(GetX(x1, y1), GetY(x1, y1), GetX(x2, y2), GetY(x2, y2)); | |
123 | } | |
124 | ||
125 | virtual void DoDrawArc(wxCoord x1, wxCoord y1, | |
126 | wxCoord x2, wxCoord y2, | |
127 | wxCoord xc, wxCoord yc) | |
128 | { | |
9a83f860 | 129 | wxFAIL_MSG( wxT("this is probably wrong") ); |
8f20ea03 VZ |
130 | |
131 | m_dc.DoDrawArc(GetX(x1, y1), GetY(x1, y1), | |
68379eaf | 132 | GetX(x2, y2), GetY(x2, y2), |
8f20ea03 VZ |
133 | xc, yc); |
134 | } | |
135 | ||
136 | virtual void DoDrawCheckMark(wxCoord x, wxCoord y, | |
137 | wxCoord w, wxCoord h) | |
138 | { | |
139 | m_dc.DoDrawCheckMark(GetX(x, y), GetY(x, y), | |
140 | GetX(w, h), GetY(w, h)); | |
141 | } | |
142 | ||
143 | virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, | |
144 | double sa, double ea) | |
145 | { | |
9a83f860 | 146 | wxFAIL_MSG( wxT("this is probably wrong") ); |
8f20ea03 VZ |
147 | |
148 | m_dc.DoDrawEllipticArc(GetX(x, y), GetY(x, y), | |
68379eaf | 149 | GetX(w, h), GetY(w, h), |
8f20ea03 VZ |
150 | sa, ea); |
151 | } | |
152 | ||
153 | virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord w, wxCoord h) | |
154 | { | |
155 | m_dc.DoDrawRectangle(GetX(x, y), GetY(x, y), GetX(w, h), GetY(w, h)); | |
156 | } | |
157 | ||
158 | virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y, | |
159 | wxCoord w, wxCoord h, | |
160 | double radius) | |
161 | { | |
162 | m_dc.DoDrawRoundedRectangle(GetX(x, y), GetY(x, y), | |
163 | GetX(w, h), GetY(w, h), | |
164 | radius); | |
165 | } | |
166 | ||
167 | virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord w, wxCoord h) | |
168 | { | |
169 | m_dc.DoDrawEllipse(GetX(x, y), GetY(x, y), GetX(w, h), GetY(w, h)); | |
170 | } | |
171 | ||
172 | virtual void DoCrossHair(wxCoord x, wxCoord y) | |
173 | { | |
174 | m_dc.DoCrossHair(GetX(x, y), GetY(x, y)); | |
175 | } | |
176 | ||
177 | virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) | |
178 | { | |
179 | m_dc.DoDrawIcon(icon, GetX(x, y), GetY(x, y)); | |
180 | } | |
181 | ||
182 | virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, | |
68379eaf | 183 | bool useMask = false) |
8f20ea03 VZ |
184 | { |
185 | m_dc.DoDrawBitmap(bmp, GetX(x, y), GetY(x, y), useMask); | |
186 | } | |
187 | ||
188 | virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y) | |
189 | { | |
190 | // this is never mirrored | |
191 | m_dc.DoDrawText(text, x, y); | |
192 | } | |
193 | ||
194 | virtual void DoDrawRotatedText(const wxString& text, | |
195 | wxCoord x, wxCoord y, double angle) | |
196 | { | |
197 | // this is never mirrored | |
198 | m_dc.DoDrawRotatedText(text, x, y, angle); | |
199 | } | |
200 | ||
201 | virtual bool DoBlit(wxCoord xdest, wxCoord ydest, | |
202 | wxCoord w, wxCoord h, | |
203 | wxDC *source, wxCoord xsrc, wxCoord ysrc, | |
03647350 | 204 | wxRasterOperationMode rop = wxCOPY, |
89efaf2b | 205 | bool useMask = false, |
68379eaf | 206 | wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord) |
8f20ea03 VZ |
207 | { |
208 | return m_dc.DoBlit(GetX(xdest, ydest), GetY(xdest, ydest), | |
209 | GetX(w, h), GetY(w, h), | |
210 | source, GetX(xsrc, ysrc), GetY(xsrc, ysrc), | |
211 | rop, useMask, | |
212 | GetX(xsrcMask, ysrcMask), GetX(xsrcMask, ysrcMask)); | |
213 | } | |
214 | ||
215 | virtual void DoGetSize(int *w, int *h) const | |
216 | { | |
217 | m_dc.DoGetSize(GetX(w, h), GetY(w, h)); | |
218 | } | |
219 | ||
220 | virtual void DoGetSizeMM(int *w, int *h) const | |
221 | { | |
222 | m_dc.DoGetSizeMM(GetX(w, h), GetY(w, h)); | |
223 | } | |
224 | ||
4787c92d | 225 | virtual void DoDrawLines(int n, const wxPoint points[], |
8f20ea03 VZ |
226 | wxCoord xoffset, wxCoord yoffset) |
227 | { | |
4787c92d | 228 | wxPoint* points_alloc = Mirror(n, points); |
8f20ea03 VZ |
229 | |
230 | m_dc.DoDrawLines(n, points, | |
231 | GetX(xoffset, yoffset), GetY(xoffset, yoffset)); | |
232 | ||
4787c92d | 233 | delete[] points_alloc; |
8f20ea03 VZ |
234 | } |
235 | ||
4787c92d | 236 | virtual void DoDrawPolygon(int n, const wxPoint points[], |
8f20ea03 | 237 | wxCoord xoffset, wxCoord yoffset, |
89efaf2b | 238 | wxPolygonFillMode fillStyle = wxODDEVEN_RULE) |
8f20ea03 | 239 | { |
4787c92d | 240 | wxPoint* points_alloc = Mirror(n, points); |
8f20ea03 VZ |
241 | |
242 | m_dc.DoDrawPolygon(n, points, | |
243 | GetX(xoffset, yoffset), GetY(xoffset, yoffset), | |
244 | fillStyle); | |
245 | ||
4787c92d | 246 | delete[] points_alloc; |
8f20ea03 VZ |
247 | } |
248 | ||
fdaad94e | 249 | virtual void DoSetDeviceClippingRegion(const wxRegion& WXUNUSED(region)) |
8f20ea03 | 250 | { |
9a83f860 | 251 | wxFAIL_MSG( wxT("not implemented") ); |
8f20ea03 VZ |
252 | } |
253 | ||
254 | virtual void DoSetClippingRegion(wxCoord x, wxCoord y, | |
255 | wxCoord w, wxCoord h) | |
256 | { | |
257 | m_dc.DoSetClippingRegion(GetX(x, y), GetY(x, y), GetX(w, h), GetY(w, h)); | |
258 | } | |
259 | ||
260 | virtual void DoGetTextExtent(const wxString& string, | |
261 | wxCoord *x, wxCoord *y, | |
262 | wxCoord *descent = NULL, | |
263 | wxCoord *externalLeading = NULL, | |
c94f845b | 264 | const wxFont *theFont = NULL) const |
8f20ea03 VZ |
265 | { |
266 | // never mirrored | |
267 | m_dc.DoGetTextExtent(string, x, y, descent, externalLeading, theFont); | |
268 | } | |
269 | ||
270 | private: | |
f0875501 VZ |
271 | wxDCImpl& m_dc; |
272 | ||
273 | bool m_mirror; | |
274 | ||
c0c133e1 | 275 | wxDECLARE_NO_COPY_CLASS(wxMirrorDCImpl); |
f0875501 | 276 | }; |
8f20ea03 | 277 | |
53a2db12 | 278 | class WXDLLIMPEXP_CORE wxMirrorDC : public wxDC |
f0875501 VZ |
279 | { |
280 | public: | |
281 | wxMirrorDC(wxDC& dc, bool mirror) | |
282 | : wxDC(new wxMirrorDCImpl(this, *dc.GetImpl(), mirror)) | |
283 | { | |
284 | m_mirror = mirror; | |
285 | } | |
286 | ||
287 | // helper functions which may be useful for the users of this class | |
288 | wxSize Reflect(const wxSize& sizeOrig) | |
289 | { | |
290 | return m_mirror ? wxSize(sizeOrig.y, sizeOrig.x) : sizeOrig; | |
291 | } | |
292 | ||
293 | private: | |
8f20ea03 | 294 | bool m_mirror; |
fc7a2a60 | 295 | |
c0c133e1 | 296 | wxDECLARE_NO_COPY_CLASS(wxMirrorDC); |
8f20ea03 VZ |
297 | }; |
298 | ||
299 | #endif // _WX_DCMIRROR_H_ | |
300 |