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