1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMirrorDC class
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_DCMIRROR_H_
12 #define _WX_DCMIRROR_H_
16 // ----------------------------------------------------------------------------
17 // wxMirrorDC allows to write the same code for horz/vertical layout
18 // ----------------------------------------------------------------------------
20 class WXDLLIMPEXP_CORE wxMirrorDCImpl
: public wxDCImpl
23 // constructs a mirror DC associated with the given real DC
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
28 wxMirrorDCImpl(wxDC
*owner
, wxDCImpl
& dc
, bool mirror
)
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
); }
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
); }
68 virtual void* GetHandle() const
69 { return m_dc
.GetHandle(); }
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
; }
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
; }
84 // exchange x and y components of all points in the array if necessary
85 wxPoint
* Mirror(int n
, const wxPoint
*& points
) const
87 wxPoint
* points_alloc
= NULL
;
90 points_alloc
= new wxPoint
[n
];
91 for ( int i
= 0; i
< n
; i
++ )
93 points_alloc
[i
].x
= points
[i
].y
;
94 points_alloc
[i
].y
= points
[i
].x
;
96 points
= points_alloc
;
101 // wxDCBase functions
102 virtual bool DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
103 wxFloodFillStyle style
= wxFLOOD_SURFACE
)
105 return m_dc
.DoFloodFill(GetX(x
, y
), GetY(x
, y
), col
, style
);
108 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const
110 return m_dc
.DoGetPixel(GetX(x
, y
), GetY(x
, y
), col
);
114 virtual void DoDrawPoint(wxCoord x
, wxCoord y
)
116 m_dc
.DoDrawPoint(GetX(x
, y
), GetY(x
, y
));
119 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
121 m_dc
.DoDrawLine(GetX(x1
, y1
), GetY(x1
, y1
), GetX(x2
, y2
), GetY(x2
, y2
));
124 virtual void DoDrawArc(wxCoord x1
, wxCoord y1
,
125 wxCoord x2
, wxCoord y2
,
126 wxCoord xc
, wxCoord yc
)
128 wxFAIL_MSG( wxT("this is probably wrong") );
130 m_dc
.DoDrawArc(GetX(x1
, y1
), GetY(x1
, y1
),
131 GetX(x2
, y2
), GetY(x2
, y2
),
135 virtual void DoDrawCheckMark(wxCoord x
, wxCoord y
,
136 wxCoord w
, wxCoord h
)
138 m_dc
.DoDrawCheckMark(GetX(x
, y
), GetY(x
, y
),
139 GetX(w
, h
), GetY(w
, h
));
142 virtual void DoDrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
143 double sa
, double ea
)
145 wxFAIL_MSG( wxT("this is probably wrong") );
147 m_dc
.DoDrawEllipticArc(GetX(x
, y
), GetY(x
, y
),
148 GetX(w
, h
), GetY(w
, h
),
152 virtual void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
154 m_dc
.DoDrawRectangle(GetX(x
, y
), GetY(x
, y
), GetX(w
, h
), GetY(w
, h
));
157 virtual void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
158 wxCoord w
, wxCoord h
,
161 m_dc
.DoDrawRoundedRectangle(GetX(x
, y
), GetY(x
, y
),
162 GetX(w
, h
), GetY(w
, h
),
166 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
168 m_dc
.DoDrawEllipse(GetX(x
, y
), GetY(x
, y
), GetX(w
, h
), GetY(w
, h
));
171 virtual void DoCrossHair(wxCoord x
, wxCoord y
)
173 m_dc
.DoCrossHair(GetX(x
, y
), GetY(x
, y
));
176 virtual void DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
)
178 m_dc
.DoDrawIcon(icon
, GetX(x
, y
), GetY(x
, y
));
181 virtual void DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
182 bool useMask
= false)
184 m_dc
.DoDrawBitmap(bmp
, GetX(x
, y
), GetY(x
, y
), useMask
);
187 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
189 // this is never mirrored
190 m_dc
.DoDrawText(text
, x
, y
);
193 virtual void DoDrawRotatedText(const wxString
& text
,
194 wxCoord x
, wxCoord y
, double angle
)
196 // this is never mirrored
197 m_dc
.DoDrawRotatedText(text
, x
, y
, angle
);
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
)
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
),
211 GetX(xsrcMask
, ysrcMask
), GetX(xsrcMask
, ysrcMask
));
214 virtual void DoGetSize(int *w
, int *h
) const
216 m_dc
.DoGetSize(GetX(w
, h
), GetY(w
, h
));
219 virtual void DoGetSizeMM(int *w
, int *h
) const
221 m_dc
.DoGetSizeMM(GetX(w
, h
), GetY(w
, h
));
224 virtual void DoDrawLines(int n
, const wxPoint points
[],
225 wxCoord xoffset
, wxCoord yoffset
)
227 wxPoint
* points_alloc
= Mirror(n
, points
);
229 m_dc
.DoDrawLines(n
, points
,
230 GetX(xoffset
, yoffset
), GetY(xoffset
, yoffset
));
232 delete[] points_alloc
;
235 virtual void DoDrawPolygon(int n
, const wxPoint points
[],
236 wxCoord xoffset
, wxCoord yoffset
,
237 wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
)
239 wxPoint
* points_alloc
= Mirror(n
, points
);
241 m_dc
.DoDrawPolygon(n
, points
,
242 GetX(xoffset
, yoffset
), GetY(xoffset
, yoffset
),
245 delete[] points_alloc
;
248 virtual void DoSetDeviceClippingRegion(const wxRegion
& WXUNUSED(region
))
250 wxFAIL_MSG( wxT("not implemented") );
253 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
254 wxCoord w
, wxCoord h
)
256 m_dc
.DoSetClippingRegion(GetX(x
, y
), GetY(x
, y
), GetX(w
, h
), GetY(w
, h
));
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
266 m_dc
.DoGetTextExtent(string
, x
, y
, descent
, externalLeading
, theFont
);
274 wxDECLARE_NO_COPY_CLASS(wxMirrorDCImpl
);
277 class WXDLLIMPEXP_CORE wxMirrorDC
: public wxDC
280 wxMirrorDC(wxDC
& dc
, bool mirror
)
281 : wxDC(new wxMirrorDCImpl(this, *dc
.GetImpl(), mirror
))
286 // helper functions which may be useful for the users of this class
287 wxSize
Reflect(const wxSize
& sizeOrig
)
289 return m_mirror
? wxSize(sizeOrig
.y
, sizeOrig
.x
) : sizeOrig
;
295 wxDECLARE_NO_COPY_CLASS(wxMirrorDC
);
298 #endif // _WX_DCMIRROR_H_