]>
Commit | Line | Data |
---|---|---|
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$ | |
8 | // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org> | |
9 | // Licence: wxWindows licence | |
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 | ||
21 | class WXDLLIMPEXP_CORE wxMirrorDCImpl : public wxDCImpl | |
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 | |
29 | wxMirrorDCImpl(wxDC *owner, wxDCImpl& dc, bool mirror) | |
30 | : wxDCImpl(owner), | |
31 | m_dc(dc) | |
32 | { | |
33 | m_mirror = mirror; | |
34 | } | |
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(); } | |
55 | virtual bool IsOk() const { return m_dc.IsOk(); } | |
56 | virtual void SetMapMode(wxMappingMode mode) { m_dc.SetMapMode(mode); } | |
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)); } | |
66 | virtual void SetLogicalFunction(wxRasterOperationMode function) | |
67 | { m_dc.SetLogicalFunction(function); } | |
68 | ||
69 | virtual void* GetHandle() const | |
70 | { return m_dc.GetHandle(); } | |
71 | ||
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 | ||
85 | // exchange x and y unconditionally | |
86 | static void Swap(wxCoord& x, wxCoord& y) | |
87 | { | |
88 | wxCoord t = x; | |
89 | x = y; | |
90 | y = t; | |
91 | } | |
92 | ||
93 | // exchange x and y components of all points in the array if necessary | |
94 | void Mirror(int n, wxPoint points[]) const | |
95 | { | |
96 | if ( m_mirror ) | |
97 | { | |
98 | for ( int i = 0; i < n; i++ ) | |
99 | { | |
100 | Swap(points[i].x, points[i].y); | |
101 | } | |
102 | } | |
103 | } | |
104 | ||
105 | ||
106 | // wxDCBase functions | |
107 | virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, | |
108 | wxFloodFillStyle style = wxFLOOD_SURFACE) | |
109 | { | |
110 | return m_dc.DoFloodFill(GetX(x, y), GetY(x, y), col, style); | |
111 | } | |
112 | ||
113 | virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const | |
114 | { | |
115 | return m_dc.DoGetPixel(GetX(x, y), GetY(x, y), col); | |
116 | } | |
117 | ||
118 | ||
119 | virtual void DoDrawPoint(wxCoord x, wxCoord y) | |
120 | { | |
121 | m_dc.DoDrawPoint(GetX(x, y), GetY(x, y)); | |
122 | } | |
123 | ||
124 | virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) | |
125 | { | |
126 | m_dc.DoDrawLine(GetX(x1, y1), GetY(x1, y1), GetX(x2, y2), GetY(x2, y2)); | |
127 | } | |
128 | ||
129 | virtual void DoDrawArc(wxCoord x1, wxCoord y1, | |
130 | wxCoord x2, wxCoord y2, | |
131 | wxCoord xc, wxCoord yc) | |
132 | { | |
133 | wxFAIL_MSG( wxT("this is probably wrong") ); | |
134 | ||
135 | m_dc.DoDrawArc(GetX(x1, y1), GetY(x1, y1), | |
136 | GetX(x2, y2), GetY(x2, y2), | |
137 | xc, yc); | |
138 | } | |
139 | ||
140 | virtual void DoDrawCheckMark(wxCoord x, wxCoord y, | |
141 | wxCoord w, wxCoord h) | |
142 | { | |
143 | m_dc.DoDrawCheckMark(GetX(x, y), GetY(x, y), | |
144 | GetX(w, h), GetY(w, h)); | |
145 | } | |
146 | ||
147 | virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, | |
148 | double sa, double ea) | |
149 | { | |
150 | wxFAIL_MSG( wxT("this is probably wrong") ); | |
151 | ||
152 | m_dc.DoDrawEllipticArc(GetX(x, y), GetY(x, y), | |
153 | GetX(w, h), GetY(w, h), | |
154 | sa, ea); | |
155 | } | |
156 | ||
157 | virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord w, wxCoord h) | |
158 | { | |
159 | m_dc.DoDrawRectangle(GetX(x, y), GetY(x, y), GetX(w, h), GetY(w, h)); | |
160 | } | |
161 | ||
162 | virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y, | |
163 | wxCoord w, wxCoord h, | |
164 | double radius) | |
165 | { | |
166 | m_dc.DoDrawRoundedRectangle(GetX(x, y), GetY(x, y), | |
167 | GetX(w, h), GetY(w, h), | |
168 | radius); | |
169 | } | |
170 | ||
171 | virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord w, wxCoord h) | |
172 | { | |
173 | m_dc.DoDrawEllipse(GetX(x, y), GetY(x, y), GetX(w, h), GetY(w, h)); | |
174 | } | |
175 | ||
176 | virtual void DoCrossHair(wxCoord x, wxCoord y) | |
177 | { | |
178 | m_dc.DoCrossHair(GetX(x, y), GetY(x, y)); | |
179 | } | |
180 | ||
181 | virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) | |
182 | { | |
183 | m_dc.DoDrawIcon(icon, GetX(x, y), GetY(x, y)); | |
184 | } | |
185 | ||
186 | virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, | |
187 | bool useMask = false) | |
188 | { | |
189 | m_dc.DoDrawBitmap(bmp, GetX(x, y), GetY(x, y), useMask); | |
190 | } | |
191 | ||
192 | virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y) | |
193 | { | |
194 | // this is never mirrored | |
195 | m_dc.DoDrawText(text, x, y); | |
196 | } | |
197 | ||
198 | virtual void DoDrawRotatedText(const wxString& text, | |
199 | wxCoord x, wxCoord y, double angle) | |
200 | { | |
201 | // this is never mirrored | |
202 | m_dc.DoDrawRotatedText(text, x, y, angle); | |
203 | } | |
204 | ||
205 | virtual bool DoBlit(wxCoord xdest, wxCoord ydest, | |
206 | wxCoord w, wxCoord h, | |
207 | wxDC *source, wxCoord xsrc, wxCoord ysrc, | |
208 | wxRasterOperationMode rop = wxCOPY, | |
209 | bool useMask = false, | |
210 | wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord) | |
211 | { | |
212 | return m_dc.DoBlit(GetX(xdest, ydest), GetY(xdest, ydest), | |
213 | GetX(w, h), GetY(w, h), | |
214 | source, GetX(xsrc, ysrc), GetY(xsrc, ysrc), | |
215 | rop, useMask, | |
216 | GetX(xsrcMask, ysrcMask), GetX(xsrcMask, ysrcMask)); | |
217 | } | |
218 | ||
219 | virtual void DoGetSize(int *w, int *h) const | |
220 | { | |
221 | m_dc.DoGetSize(GetX(w, h), GetY(w, h)); | |
222 | } | |
223 | ||
224 | virtual void DoGetSizeMM(int *w, int *h) const | |
225 | { | |
226 | m_dc.DoGetSizeMM(GetX(w, h), GetY(w, h)); | |
227 | } | |
228 | ||
229 | virtual void DoDrawLines(int n, wxPoint points[], | |
230 | wxCoord xoffset, wxCoord yoffset) | |
231 | { | |
232 | Mirror(n, points); | |
233 | ||
234 | m_dc.DoDrawLines(n, points, | |
235 | GetX(xoffset, yoffset), GetY(xoffset, yoffset)); | |
236 | ||
237 | Mirror(n, points); | |
238 | } | |
239 | ||
240 | virtual void DoDrawPolygon(int n, wxPoint points[], | |
241 | wxCoord xoffset, wxCoord yoffset, | |
242 | wxPolygonFillMode fillStyle = wxODDEVEN_RULE) | |
243 | { | |
244 | Mirror(n, points); | |
245 | ||
246 | m_dc.DoDrawPolygon(n, points, | |
247 | GetX(xoffset, yoffset), GetY(xoffset, yoffset), | |
248 | fillStyle); | |
249 | ||
250 | Mirror(n, points); | |
251 | } | |
252 | ||
253 | virtual void DoSetDeviceClippingRegion(const wxRegion& WXUNUSED(region)) | |
254 | { | |
255 | wxFAIL_MSG( wxT("not implemented") ); | |
256 | } | |
257 | ||
258 | virtual void DoSetClippingRegion(wxCoord x, wxCoord y, | |
259 | wxCoord w, wxCoord h) | |
260 | { | |
261 | m_dc.DoSetClippingRegion(GetX(x, y), GetY(x, y), GetX(w, h), GetY(w, h)); | |
262 | } | |
263 | ||
264 | virtual void DoGetTextExtent(const wxString& string, | |
265 | wxCoord *x, wxCoord *y, | |
266 | wxCoord *descent = NULL, | |
267 | wxCoord *externalLeading = NULL, | |
268 | const wxFont *theFont = NULL) const | |
269 | { | |
270 | // never mirrored | |
271 | m_dc.DoGetTextExtent(string, x, y, descent, externalLeading, theFont); | |
272 | } | |
273 | ||
274 | private: | |
275 | wxDCImpl& m_dc; | |
276 | ||
277 | bool m_mirror; | |
278 | ||
279 | wxDECLARE_NO_COPY_CLASS(wxMirrorDCImpl); | |
280 | }; | |
281 | ||
282 | class WXDLLIMPEXP_CORE wxMirrorDC : public wxDC | |
283 | { | |
284 | public: | |
285 | wxMirrorDC(wxDC& dc, bool mirror) | |
286 | : wxDC(new wxMirrorDCImpl(this, *dc.GetImpl(), mirror)) | |
287 | { | |
288 | m_mirror = mirror; | |
289 | } | |
290 | ||
291 | // helper functions which may be useful for the users of this class | |
292 | wxSize Reflect(const wxSize& sizeOrig) | |
293 | { | |
294 | return m_mirror ? wxSize(sizeOrig.y, sizeOrig.x) : sizeOrig; | |
295 | } | |
296 | ||
297 | private: | |
298 | bool m_mirror; | |
299 | ||
300 | wxDECLARE_NO_COPY_CLASS(wxMirrorDC); | |
301 | }; | |
302 | ||
303 | #endif // _WX_DCMIRROR_H_ | |
304 |