]> git.saurik.com Git - wxWidgets.git/blob - include/wx/dcmirror.h
added default parameters to wxBrush/wxPen ctors
[wxWidgets.git] / include / wx / dcmirror.h
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@wxwindows.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 WXDLLEXPORT wxMirrorDC : public wxDCBase
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(); }
56 virtual bool Ok() const { return m_dc.Ok(); }
57 virtual void SetMapMode(int mode) { m_dc.SetMapMode(mode); }
58 virtual void SetUserScale(double x, double y)
59 { m_dc.SetUserScale(GetX(x, y), GetY(x, y)); }
60 virtual void SetLogicalOrigin(wxCoord x, wxCoord y)
61 { m_dc.SetLogicalOrigin(GetX(x, y), GetY(x, y)); }
62 virtual void SetDeviceOrigin(wxCoord x, wxCoord y)
63 { m_dc.SetDeviceOrigin(GetX(x, y), GetY(x, y)); }
64 virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp)
65 { m_dc.SetAxisOrientation(GetX(xLeftRight, yBottomUp),
66 GetY(xLeftRight, yBottomUp)); }
67 virtual void SetLogicalFunction(int function)
68 { m_dc.SetLogicalFunction(function); }
69
70 protected:
71 // returns x and y if not mirroring or y and x if mirroring
72 wxCoord GetX(wxCoord x, wxCoord y) const { return m_mirror ? y : x; }
73 wxCoord GetY(wxCoord x, wxCoord y) const { return m_mirror ? x : y; }
74 double GetX(double x, double y) const { return m_mirror ? y : x; }
75 double GetY(double x, double y) const { return m_mirror ? x : y; }
76 bool GetX(bool x, bool y) const { return m_mirror ? y : x; }
77 bool GetY(bool x, bool y) const { return m_mirror ? x : y; }
78
79 // same thing but for pointers
80 wxCoord *GetX(wxCoord *x, wxCoord *y) const { return m_mirror ? y : x; }
81 wxCoord *GetY(wxCoord *x, wxCoord *y) const { return m_mirror ? x : y; }
82
83 // exchange x and y unconditionally
84 static void Swap(wxCoord& x, wxCoord& y)
85 {
86 wxCoord t = x;
87 x = y;
88 y = t;
89 }
90
91 // exchange x and y components of all points in the array if necessary
92 void Mirror(int n, wxPoint points[]) const
93 {
94 if ( m_mirror )
95 {
96 for ( int i = 0; i < n; i++ )
97 {
98 Swap(points[i].x, points[i].y);
99 }
100 }
101 }
102
103
104 // wxDCBase functions
105 virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,
106 int style = wxFLOOD_SURFACE)
107 {
108 return m_dc.DoFloodFill(GetX(x, y), GetY(x, y), col, style);
109 }
110
111 virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const
112 {
113 return m_dc.DoGetPixel(GetX(x, y), GetY(x, y), col);
114 }
115
116
117 virtual void DoDrawPoint(wxCoord x, wxCoord y)
118 {
119 m_dc.DoDrawPoint(GetX(x, y), GetY(x, y));
120 }
121
122 virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
123 {
124 m_dc.DoDrawLine(GetX(x1, y1), GetY(x1, y1), GetX(x2, y2), GetY(x2, y2));
125 }
126
127 virtual void DoDrawArc(wxCoord x1, wxCoord y1,
128 wxCoord x2, wxCoord y2,
129 wxCoord xc, wxCoord yc)
130 {
131 wxFAIL_MSG( _T("this is probably wrong") );
132
133 m_dc.DoDrawArc(GetX(x1, y1), GetY(x1, y1),
134 GetX(x2, y2), GetY(x2, y2),
135 xc, yc);
136 }
137
138 virtual void DoDrawCheckMark(wxCoord x, wxCoord y,
139 wxCoord w, wxCoord h)
140 {
141 m_dc.DoDrawCheckMark(GetX(x, y), GetY(x, y),
142 GetX(w, h), GetY(w, h));
143 }
144
145 virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
146 double sa, double ea)
147 {
148 wxFAIL_MSG( _T("this is probably wrong") );
149
150 m_dc.DoDrawEllipticArc(GetX(x, y), GetY(x, y),
151 GetX(w, h), GetY(w, h),
152 sa, ea);
153 }
154
155 virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord w, wxCoord h)
156 {
157 m_dc.DoDrawRectangle(GetX(x, y), GetY(x, y), GetX(w, h), GetY(w, h));
158 }
159
160 virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y,
161 wxCoord w, wxCoord h,
162 double radius)
163 {
164 m_dc.DoDrawRoundedRectangle(GetX(x, y), GetY(x, y),
165 GetX(w, h), GetY(w, h),
166 radius);
167 }
168
169 virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord w, wxCoord h)
170 {
171 m_dc.DoDrawEllipse(GetX(x, y), GetY(x, y), GetX(w, h), GetY(w, h));
172 }
173
174 virtual void DoCrossHair(wxCoord x, wxCoord y)
175 {
176 m_dc.DoCrossHair(GetX(x, y), GetY(x, y));
177 }
178
179 virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y)
180 {
181 m_dc.DoDrawIcon(icon, GetX(x, y), GetY(x, y));
182 }
183
184 virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
185 bool useMask = FALSE)
186 {
187 m_dc.DoDrawBitmap(bmp, GetX(x, y), GetY(x, y), useMask);
188 }
189
190 virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y)
191 {
192 // this is never mirrored
193 m_dc.DoDrawText(text, x, y);
194 }
195
196 virtual void DoDrawRotatedText(const wxString& text,
197 wxCoord x, wxCoord y, double angle)
198 {
199 // this is never mirrored
200 m_dc.DoDrawRotatedText(text, x, y, angle);
201 }
202
203 virtual bool DoBlit(wxCoord xdest, wxCoord ydest,
204 wxCoord w, wxCoord h,
205 wxDC *source, wxCoord xsrc, wxCoord ysrc,
206 int rop = wxCOPY, bool useMask = FALSE,
207 wxCoord xsrcMask = -1, wxCoord ysrcMask = -1)
208 {
209 return m_dc.DoBlit(GetX(xdest, ydest), GetY(xdest, ydest),
210 GetX(w, h), GetY(w, h),
211 source, GetX(xsrc, ysrc), GetY(xsrc, ysrc),
212 rop, useMask,
213 GetX(xsrcMask, ysrcMask), GetX(xsrcMask, ysrcMask));
214 }
215
216 virtual void DoGetSize(int *w, int *h) const
217 {
218 m_dc.DoGetSize(GetX(w, h), GetY(w, h));
219 }
220
221 virtual void DoGetSizeMM(int *w, int *h) const
222 {
223 m_dc.DoGetSizeMM(GetX(w, h), GetY(w, h));
224 }
225
226 virtual void DoDrawLines(int n, wxPoint points[],
227 wxCoord xoffset, wxCoord yoffset)
228 {
229 Mirror(n, points);
230
231 m_dc.DoDrawLines(n, points,
232 GetX(xoffset, yoffset), GetY(xoffset, yoffset));
233
234 Mirror(n, points);
235 }
236
237 virtual void DoDrawPolygon(int n, wxPoint points[],
238 wxCoord xoffset, wxCoord yoffset,
239 int fillStyle = wxODDEVEN_RULE)
240 {
241 Mirror(n, points);
242
243 m_dc.DoDrawPolygon(n, points,
244 GetX(xoffset, yoffset), GetY(xoffset, yoffset),
245 fillStyle);
246
247 Mirror(n, points);
248 }
249
250 virtual void DoSetClippingRegionAsRegion(const wxRegion& WXUNUSED(region))
251 {
252 wxFAIL_MSG( _T("not implemented") );
253 }
254
255 virtual void DoSetClippingRegion(wxCoord x, wxCoord y,
256 wxCoord w, wxCoord h)
257 {
258 m_dc.DoSetClippingRegion(GetX(x, y), GetY(x, y), GetX(w, h), GetY(w, h));
259 }
260
261 virtual void DoGetTextExtent(const wxString& string,
262 wxCoord *x, wxCoord *y,
263 wxCoord *descent = NULL,
264 wxCoord *externalLeading = NULL,
265 wxFont *theFont = NULL) const
266 {
267 // never mirrored
268 m_dc.DoGetTextExtent(string, x, y, descent, externalLeading, theFont);
269 }
270
271 private:
272 wxMirrorDC& m_dc;
273
274 bool m_mirror;
275 };
276
277 #endif // _WX_DCMIRROR_H_
278