]> git.saurik.com Git - wxWidgets.git/blame - include/wx/dcmirror.h
Fix assorted typos in comments and other non-code.
[wxWidgets.git] / include / wx / dcmirror.h
CommitLineData
8f20ea03
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: wx/dcmirror.h
3// Purpose: wxMirrorDC class
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 21.07.2003
77ffb593 7// Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org>
65571936 8// Licence: wxWindows licence
8f20ea03
VZ
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
53a2db12 20class WXDLLIMPEXP_CORE wxMirrorDCImpl : public wxDCImpl
8f20ea03
VZ
21{
22public:
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
f0875501
VZ
28 wxMirrorDCImpl(wxDC *owner, wxDCImpl& dc, bool mirror)
29 : wxDCImpl(owner),
30 m_dc(dc)
31 {
32 m_mirror = mirror;
33 }
8f20ea03
VZ
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(); }
f0875501 54 virtual bool IsOk() const { return m_dc.IsOk(); }
89efaf2b 55 virtual void SetMapMode(wxMappingMode mode) { m_dc.SetMapMode(mode); }
8f20ea03
VZ
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)); }
89efaf2b 65 virtual void SetLogicalFunction(wxRasterOperationMode function)
8f20ea03
VZ
66 { m_dc.SetLogicalFunction(function); }
67
9eefb5c1
RD
68 virtual void* GetHandle() const
69 { return m_dc.GetHandle(); }
70
8f20ea03
VZ
71protected:
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
8f20ea03 84 // exchange x and y components of all points in the array if necessary
4787c92d 85 wxPoint* Mirror(int n, const wxPoint*& points) const
8f20ea03 86 {
4787c92d 87 wxPoint* points_alloc = NULL;
8f20ea03
VZ
88 if ( m_mirror )
89 {
4787c92d 90 points_alloc = new wxPoint[n];
8f20ea03
VZ
91 for ( int i = 0; i < n; i++ )
92 {
4787c92d
PC
93 points_alloc[i].x = points[i].y;
94 points_alloc[i].y = points[i].x;
8f20ea03 95 }
4787c92d 96 points = points_alloc;
8f20ea03 97 }
4787c92d 98 return points_alloc;
8f20ea03
VZ
99 }
100
8f20ea03
VZ
101 // wxDCBase functions
102 virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,
89efaf2b 103 wxFloodFillStyle style = wxFLOOD_SURFACE)
8f20ea03
VZ
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 {
9a83f860 128 wxFAIL_MSG( wxT("this is probably wrong") );
8f20ea03
VZ
129
130 m_dc.DoDrawArc(GetX(x1, y1), GetY(x1, y1),
68379eaf 131 GetX(x2, y2), GetY(x2, y2),
8f20ea03
VZ
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 {
9a83f860 145 wxFAIL_MSG( wxT("this is probably wrong") );
8f20ea03
VZ
146
147 m_dc.DoDrawEllipticArc(GetX(x, y), GetY(x, y),
68379eaf 148 GetX(w, h), GetY(w, h),
8f20ea03
VZ
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,
68379eaf 182 bool useMask = false)
8f20ea03
VZ
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,
03647350 203 wxRasterOperationMode rop = wxCOPY,
89efaf2b 204 bool useMask = false,
68379eaf 205 wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord)
8f20ea03
VZ
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
4787c92d 224 virtual void DoDrawLines(int n, const wxPoint points[],
8f20ea03
VZ
225 wxCoord xoffset, wxCoord yoffset)
226 {
4787c92d 227 wxPoint* points_alloc = Mirror(n, points);
8f20ea03
VZ
228
229 m_dc.DoDrawLines(n, points,
230 GetX(xoffset, yoffset), GetY(xoffset, yoffset));
231
4787c92d 232 delete[] points_alloc;
8f20ea03
VZ
233 }
234
4787c92d 235 virtual void DoDrawPolygon(int n, const wxPoint points[],
8f20ea03 236 wxCoord xoffset, wxCoord yoffset,
89efaf2b 237 wxPolygonFillMode fillStyle = wxODDEVEN_RULE)
8f20ea03 238 {
4787c92d 239 wxPoint* points_alloc = Mirror(n, points);
8f20ea03
VZ
240
241 m_dc.DoDrawPolygon(n, points,
242 GetX(xoffset, yoffset), GetY(xoffset, yoffset),
243 fillStyle);
244
4787c92d 245 delete[] points_alloc;
8f20ea03
VZ
246 }
247
fdaad94e 248 virtual void DoSetDeviceClippingRegion(const wxRegion& WXUNUSED(region))
8f20ea03 249 {
9a83f860 250 wxFAIL_MSG( wxT("not implemented") );
8f20ea03
VZ
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,
c94f845b 263 const wxFont *theFont = NULL) const
8f20ea03
VZ
264 {
265 // never mirrored
266 m_dc.DoGetTextExtent(string, x, y, descent, externalLeading, theFont);
267 }
268
269private:
f0875501
VZ
270 wxDCImpl& m_dc;
271
272 bool m_mirror;
273
c0c133e1 274 wxDECLARE_NO_COPY_CLASS(wxMirrorDCImpl);
f0875501 275};
8f20ea03 276
53a2db12 277class WXDLLIMPEXP_CORE wxMirrorDC : public wxDC
f0875501
VZ
278{
279public:
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
292private:
8f20ea03 293 bool m_mirror;
fc7a2a60 294
c0c133e1 295 wxDECLARE_NO_COPY_CLASS(wxMirrorDC);
8f20ea03
VZ
296};
297
298#endif // _WX_DCMIRROR_H_
299