]>
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 | ||
4a8cd018 | 21 | class WXDLLEXPORT wxMirrorDC : public wxDC |
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 | |
29 | // | |
30 | // the cast to wxMirrorDC is a dirty hack done to allow us to call the | |
31 | // protected methods of wxDCBase directly in our code below, without it it | |
32 | // would be impossible (this is correct from C++ point of view but doesn't | |
33 | // make any sense in this particular situation) | |
34 | wxMirrorDC(wxDC& dc, bool mirror) : m_dc((wxMirrorDC&)dc) | |
35 | { m_mirror = mirror; } | |
36 | ||
37 | // wxDCBase operations | |
38 | virtual void Clear() { m_dc.Clear(); } | |
39 | virtual void SetFont(const wxFont& font) { m_dc.SetFont(font); } | |
40 | virtual void SetPen(const wxPen& pen) { m_dc.SetPen(pen); } | |
41 | virtual void SetBrush(const wxBrush& brush) { m_dc.SetBrush(brush); } | |
42 | virtual void SetBackground(const wxBrush& brush) | |
43 | { m_dc.SetBackground(brush); } | |
44 | virtual void SetBackgroundMode(int mode) { m_dc.SetBackgroundMode(mode); } | |
45 | #if wxUSE_PALETTE | |
46 | virtual void SetPalette(const wxPalette& palette) | |
47 | { m_dc.SetPalette(palette); } | |
48 | #endif // wxUSE_PALETTE | |
49 | virtual void DestroyClippingRegion() { m_dc.DestroyClippingRegion(); } | |
50 | virtual wxCoord GetCharHeight() const { return m_dc.GetCharHeight(); } | |
51 | virtual wxCoord GetCharWidth() const { return m_dc.GetCharWidth(); } | |
52 | virtual bool CanDrawBitmap() const { return m_dc.CanDrawBitmap(); } | |
53 | virtual bool CanGetTextExtent() const { return m_dc.CanGetTextExtent(); } | |
54 | virtual int GetDepth() const { return m_dc.GetDepth(); } | |
55 | virtual wxSize GetPPI() const { return m_dc.GetPPI(); } | |
b7cacb43 VZ |
56 | virtual bool Ok() const { return IsOk(); } |
57 | virtual bool IsOk() const { return m_dc.Ok(); } | |
8f20ea03 VZ |
58 | virtual void SetMapMode(int mode) { m_dc.SetMapMode(mode); } |
59 | virtual void SetUserScale(double x, double y) | |
60 | { m_dc.SetUserScale(GetX(x, y), GetY(x, y)); } | |
61 | virtual void SetLogicalOrigin(wxCoord x, wxCoord y) | |
62 | { m_dc.SetLogicalOrigin(GetX(x, y), GetY(x, y)); } | |
63 | virtual void SetDeviceOrigin(wxCoord x, wxCoord y) | |
64 | { m_dc.SetDeviceOrigin(GetX(x, y), GetY(x, y)); } | |
65 | virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp) | |
66 | { m_dc.SetAxisOrientation(GetX(xLeftRight, yBottomUp), | |
67 | GetY(xLeftRight, yBottomUp)); } | |
68 | virtual void SetLogicalFunction(int function) | |
69 | { m_dc.SetLogicalFunction(function); } | |
70 | ||
4a8cd018 VZ |
71 | // helper functions which may be useful for the users of this class |
72 | wxSize Reflect(const wxSize& sizeOrig) | |
73 | { | |
74 | return m_mirror ? wxSize(sizeOrig.y, sizeOrig.x) : sizeOrig; | |
75 | } | |
76 | ||
8f20ea03 VZ |
77 | protected: |
78 | // returns x and y if not mirroring or y and x if mirroring | |
79 | wxCoord GetX(wxCoord x, wxCoord y) const { return m_mirror ? y : x; } | |
80 | wxCoord GetY(wxCoord x, wxCoord y) const { return m_mirror ? x : y; } | |
81 | double GetX(double x, double y) const { return m_mirror ? y : x; } | |
82 | double GetY(double x, double y) const { return m_mirror ? x : y; } | |
83 | bool GetX(bool x, bool y) const { return m_mirror ? y : x; } | |
84 | bool GetY(bool x, bool y) const { return m_mirror ? x : y; } | |
85 | ||
86 | // same thing but for pointers | |
87 | wxCoord *GetX(wxCoord *x, wxCoord *y) const { return m_mirror ? y : x; } | |
88 | wxCoord *GetY(wxCoord *x, wxCoord *y) const { return m_mirror ? x : y; } | |
89 | ||
90 | // exchange x and y unconditionally | |
91 | static void Swap(wxCoord& x, wxCoord& y) | |
92 | { | |
93 | wxCoord t = x; | |
94 | x = y; | |
95 | y = t; | |
96 | } | |
97 | ||
98 | // exchange x and y components of all points in the array if necessary | |
99 | void Mirror(int n, wxPoint points[]) const | |
100 | { | |
101 | if ( m_mirror ) | |
102 | { | |
103 | for ( int i = 0; i < n; i++ ) | |
104 | { | |
105 | Swap(points[i].x, points[i].y); | |
106 | } | |
107 | } | |
108 | } | |
109 | ||
110 | ||
111 | // wxDCBase functions | |
112 | virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, | |
113 | int style = wxFLOOD_SURFACE) | |
114 | { | |
115 | return m_dc.DoFloodFill(GetX(x, y), GetY(x, y), col, style); | |
116 | } | |
117 | ||
118 | virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const | |
119 | { | |
120 | return m_dc.DoGetPixel(GetX(x, y), GetY(x, y), col); | |
121 | } | |
122 | ||
123 | ||
124 | virtual void DoDrawPoint(wxCoord x, wxCoord y) | |
125 | { | |
126 | m_dc.DoDrawPoint(GetX(x, y), GetY(x, y)); | |
127 | } | |
128 | ||
129 | virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) | |
130 | { | |
131 | m_dc.DoDrawLine(GetX(x1, y1), GetY(x1, y1), GetX(x2, y2), GetY(x2, y2)); | |
132 | } | |
133 | ||
134 | virtual void DoDrawArc(wxCoord x1, wxCoord y1, | |
135 | wxCoord x2, wxCoord y2, | |
136 | wxCoord xc, wxCoord yc) | |
137 | { | |
138 | wxFAIL_MSG( _T("this is probably wrong") ); | |
139 | ||
140 | m_dc.DoDrawArc(GetX(x1, y1), GetY(x1, y1), | |
68379eaf | 141 | GetX(x2, y2), GetY(x2, y2), |
8f20ea03 VZ |
142 | xc, yc); |
143 | } | |
144 | ||
145 | virtual void DoDrawCheckMark(wxCoord x, wxCoord y, | |
146 | wxCoord w, wxCoord h) | |
147 | { | |
148 | m_dc.DoDrawCheckMark(GetX(x, y), GetY(x, y), | |
149 | GetX(w, h), GetY(w, h)); | |
150 | } | |
151 | ||
152 | virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, | |
153 | double sa, double ea) | |
154 | { | |
155 | wxFAIL_MSG( _T("this is probably wrong") ); | |
156 | ||
157 | m_dc.DoDrawEllipticArc(GetX(x, y), GetY(x, y), | |
68379eaf | 158 | GetX(w, h), GetY(w, h), |
8f20ea03 VZ |
159 | sa, ea); |
160 | } | |
161 | ||
162 | virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord w, wxCoord h) | |
163 | { | |
164 | m_dc.DoDrawRectangle(GetX(x, y), GetY(x, y), GetX(w, h), GetY(w, h)); | |
165 | } | |
166 | ||
167 | virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y, | |
168 | wxCoord w, wxCoord h, | |
169 | double radius) | |
170 | { | |
171 | m_dc.DoDrawRoundedRectangle(GetX(x, y), GetY(x, y), | |
172 | GetX(w, h), GetY(w, h), | |
173 | radius); | |
174 | } | |
175 | ||
176 | virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord w, wxCoord h) | |
177 | { | |
178 | m_dc.DoDrawEllipse(GetX(x, y), GetY(x, y), GetX(w, h), GetY(w, h)); | |
179 | } | |
180 | ||
181 | virtual void DoCrossHair(wxCoord x, wxCoord y) | |
182 | { | |
183 | m_dc.DoCrossHair(GetX(x, y), GetY(x, y)); | |
184 | } | |
185 | ||
186 | virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) | |
187 | { | |
188 | m_dc.DoDrawIcon(icon, GetX(x, y), GetY(x, y)); | |
189 | } | |
190 | ||
191 | virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, | |
68379eaf | 192 | bool useMask = false) |
8f20ea03 VZ |
193 | { |
194 | m_dc.DoDrawBitmap(bmp, GetX(x, y), GetY(x, y), useMask); | |
195 | } | |
196 | ||
197 | virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y) | |
198 | { | |
199 | // this is never mirrored | |
200 | m_dc.DoDrawText(text, x, y); | |
201 | } | |
202 | ||
203 | virtual void DoDrawRotatedText(const wxString& text, | |
204 | wxCoord x, wxCoord y, double angle) | |
205 | { | |
206 | // this is never mirrored | |
207 | m_dc.DoDrawRotatedText(text, x, y, angle); | |
208 | } | |
209 | ||
210 | virtual bool DoBlit(wxCoord xdest, wxCoord ydest, | |
211 | wxCoord w, wxCoord h, | |
212 | wxDC *source, wxCoord xsrc, wxCoord ysrc, | |
68379eaf WS |
213 | int rop = wxCOPY, bool useMask = false, |
214 | wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord) | |
8f20ea03 VZ |
215 | { |
216 | return m_dc.DoBlit(GetX(xdest, ydest), GetY(xdest, ydest), | |
217 | GetX(w, h), GetY(w, h), | |
218 | source, GetX(xsrc, ysrc), GetY(xsrc, ysrc), | |
219 | rop, useMask, | |
220 | GetX(xsrcMask, ysrcMask), GetX(xsrcMask, ysrcMask)); | |
221 | } | |
222 | ||
223 | virtual void DoGetSize(int *w, int *h) const | |
224 | { | |
225 | m_dc.DoGetSize(GetX(w, h), GetY(w, h)); | |
226 | } | |
227 | ||
228 | virtual void DoGetSizeMM(int *w, int *h) const | |
229 | { | |
230 | m_dc.DoGetSizeMM(GetX(w, h), GetY(w, h)); | |
231 | } | |
232 | ||
233 | virtual void DoDrawLines(int n, wxPoint points[], | |
234 | wxCoord xoffset, wxCoord yoffset) | |
235 | { | |
236 | Mirror(n, points); | |
237 | ||
238 | m_dc.DoDrawLines(n, points, | |
239 | GetX(xoffset, yoffset), GetY(xoffset, yoffset)); | |
240 | ||
241 | Mirror(n, points); | |
242 | } | |
243 | ||
244 | virtual void DoDrawPolygon(int n, wxPoint points[], | |
245 | wxCoord xoffset, wxCoord yoffset, | |
246 | int fillStyle = wxODDEVEN_RULE) | |
247 | { | |
248 | Mirror(n, points); | |
249 | ||
250 | m_dc.DoDrawPolygon(n, points, | |
251 | GetX(xoffset, yoffset), GetY(xoffset, yoffset), | |
252 | fillStyle); | |
253 | ||
254 | Mirror(n, points); | |
255 | } | |
256 | ||
257 | virtual void DoSetClippingRegionAsRegion(const wxRegion& WXUNUSED(region)) | |
258 | { | |
259 | wxFAIL_MSG( _T("not implemented") ); | |
260 | } | |
261 | ||
262 | virtual void DoSetClippingRegion(wxCoord x, wxCoord y, | |
263 | wxCoord w, wxCoord h) | |
264 | { | |
265 | m_dc.DoSetClippingRegion(GetX(x, y), GetY(x, y), GetX(w, h), GetY(w, h)); | |
266 | } | |
267 | ||
268 | virtual void DoGetTextExtent(const wxString& string, | |
269 | wxCoord *x, wxCoord *y, | |
270 | wxCoord *descent = NULL, | |
271 | wxCoord *externalLeading = NULL, | |
272 | wxFont *theFont = NULL) const | |
273 | { | |
274 | // never mirrored | |
275 | m_dc.DoGetTextExtent(string, x, y, descent, externalLeading, theFont); | |
276 | } | |
277 | ||
278 | private: | |
279 | wxMirrorDC& m_dc; | |
280 | ||
281 | bool m_mirror; | |
fc7a2a60 VZ |
282 | |
283 | DECLARE_NO_COPY_CLASS(wxMirrorDC) | |
8f20ea03 VZ |
284 | }; |
285 | ||
286 | #endif // _WX_DCMIRROR_H_ | |
287 |