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 wxMirrorDCImpl(wxDC * owner,wxDCImpl & dc,bool mirror)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 Clear()36 virtual void Clear() wxOVERRIDE { m_dc.Clear(); } SetFont(const wxFont & font)37 virtual void SetFont(const wxFont& font) wxOVERRIDE { m_dc.SetFont(font); } SetPen(const wxPen & pen)38 virtual void SetPen(const wxPen& pen) wxOVERRIDE { m_dc.SetPen(pen); } SetBrush(const wxBrush & brush)39 virtual void SetBrush(const wxBrush& brush) wxOVERRIDE { m_dc.SetBrush(brush); } SetBackground(const wxBrush & brush)40 virtual void SetBackground(const wxBrush& brush) wxOVERRIDE 41 { m_dc.SetBackground(brush); } SetBackgroundMode(int mode)42 virtual void SetBackgroundMode(int mode) wxOVERRIDE { m_dc.SetBackgroundMode(mode); } 43 #if wxUSE_PALETTE SetPalette(const wxPalette & palette)44 virtual void SetPalette(const wxPalette& palette) wxOVERRIDE 45 { m_dc.SetPalette(palette); } 46 #endif // wxUSE_PALETTE DestroyClippingRegion()47 virtual void DestroyClippingRegion() wxOVERRIDE { m_dc.DestroyClippingRegion(); } GetCharHeight()48 virtual wxCoord GetCharHeight() const wxOVERRIDE { return m_dc.GetCharHeight(); } GetCharWidth()49 virtual wxCoord GetCharWidth() const wxOVERRIDE { return m_dc.GetCharWidth(); } CanDrawBitmap()50 virtual bool CanDrawBitmap() const wxOVERRIDE { return m_dc.CanDrawBitmap(); } CanGetTextExtent()51 virtual bool CanGetTextExtent() const wxOVERRIDE { return m_dc.CanGetTextExtent(); } GetDepth()52 virtual int GetDepth() const wxOVERRIDE { return m_dc.GetDepth(); } GetPPI()53 virtual wxSize GetPPI() const wxOVERRIDE { return m_dc.GetPPI(); } IsOk()54 virtual bool IsOk() const wxOVERRIDE { return m_dc.IsOk(); } SetMapMode(wxMappingMode mode)55 virtual void SetMapMode(wxMappingMode mode) wxOVERRIDE { m_dc.SetMapMode(mode); } SetUserScale(double x,double y)56 virtual void SetUserScale(double x, double y) wxOVERRIDE 57 { m_dc.SetUserScale(GetX(x, y), GetY(x, y)); } SetLogicalOrigin(wxCoord x,wxCoord y)58 virtual void SetLogicalOrigin(wxCoord x, wxCoord y) wxOVERRIDE 59 { m_dc.SetLogicalOrigin(GetX(x, y), GetY(x, y)); } SetDeviceOrigin(wxCoord x,wxCoord y)60 virtual void SetDeviceOrigin(wxCoord x, wxCoord y) wxOVERRIDE 61 { m_dc.SetDeviceOrigin(GetX(x, y), GetY(x, y)); } SetAxisOrientation(bool xLeftRight,bool yBottomUp)62 virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp) wxOVERRIDE 63 { m_dc.SetAxisOrientation(GetX(xLeftRight, yBottomUp), 64 GetY(xLeftRight, yBottomUp)); } SetLogicalFunction(wxRasterOperationMode function)65 virtual void SetLogicalFunction(wxRasterOperationMode function) wxOVERRIDE 66 { m_dc.SetLogicalFunction(function); } 67 GetHandle()68 virtual void* GetHandle() const wxOVERRIDE 69 { return m_dc.GetHandle(); } 70 71 protected: 72 // returns x and y if not mirroring or y and x if mirroring GetX(wxCoord x,wxCoord y)73 wxCoord GetX(wxCoord x, wxCoord y) const { return m_mirror ? y : x; } GetY(wxCoord x,wxCoord y)74 wxCoord GetY(wxCoord x, wxCoord y) const { return m_mirror ? x : y; } GetX(double x,double y)75 double GetX(double x, double y) const { return m_mirror ? y : x; } GetY(double x,double y)76 double GetY(double x, double y) const { return m_mirror ? x : y; } GetX(bool x,bool y)77 bool GetX(bool x, bool y) const { return m_mirror ? y : x; } GetY(bool x,bool y)78 bool GetY(bool x, bool y) const { return m_mirror ? x : y; } 79 80 // same thing but for pointers GetX(wxCoord * x,wxCoord * y)81 wxCoord *GetX(wxCoord *x, wxCoord *y) const { return m_mirror ? y : x; } GetY(wxCoord * x,wxCoord * y)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 Mirror(int n,const wxPoint * & points)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) wxOVERRIDE 104 { 105 return m_dc.DoFloodFill(GetX(x, y), GetY(x, y), col, style); 106 } 107 DoGetPixel(wxCoord x,wxCoord y,wxColour * col)108 virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const wxOVERRIDE 109 { 110 return m_dc.DoGetPixel(GetX(x, y), GetY(x, y), col); 111 } 112 113 DoDrawPoint(wxCoord x,wxCoord y)114 virtual void DoDrawPoint(wxCoord x, wxCoord y) wxOVERRIDE 115 { 116 m_dc.DoDrawPoint(GetX(x, y), GetY(x, y)); 117 } 118 DoDrawLine(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2)119 virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) wxOVERRIDE 120 { 121 m_dc.DoDrawLine(GetX(x1, y1), GetY(x1, y1), GetX(x2, y2), GetY(x2, y2)); 122 } 123 DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2,wxCoord xc,wxCoord yc)124 virtual void DoDrawArc(wxCoord x1, wxCoord y1, 125 wxCoord x2, wxCoord y2, 126 wxCoord xc, wxCoord yc) wxOVERRIDE 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 DoDrawCheckMark(wxCoord x,wxCoord y,wxCoord w,wxCoord h)135 virtual void DoDrawCheckMark(wxCoord x, wxCoord y, 136 wxCoord w, wxCoord h) wxOVERRIDE 137 { 138 m_dc.DoDrawCheckMark(GetX(x, y), GetY(x, y), 139 GetX(w, h), GetY(w, h)); 140 } 141 DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea)142 virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, 143 double sa, double ea) wxOVERRIDE 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 DoDrawRectangle(wxCoord x,wxCoord y,wxCoord w,wxCoord h)152 virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord w, wxCoord h) wxOVERRIDE 153 { 154 m_dc.DoDrawRectangle(GetX(x, y), GetY(x, y), GetX(w, h), GetY(w, h)); 155 } 156 DoDrawRoundedRectangle(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double radius)157 virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y, 158 wxCoord w, wxCoord h, 159 double radius) wxOVERRIDE 160 { 161 m_dc.DoDrawRoundedRectangle(GetX(x, y), GetY(x, y), 162 GetX(w, h), GetY(w, h), 163 radius); 164 } 165 DoDrawEllipse(wxCoord x,wxCoord y,wxCoord w,wxCoord h)166 virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord w, wxCoord h) wxOVERRIDE 167 { 168 m_dc.DoDrawEllipse(GetX(x, y), GetY(x, y), GetX(w, h), GetY(w, h)); 169 } 170 DoCrossHair(wxCoord x,wxCoord y)171 virtual void DoCrossHair(wxCoord x, wxCoord y) wxOVERRIDE 172 { 173 m_dc.DoCrossHair(GetX(x, y), GetY(x, y)); 174 } 175 DoDrawIcon(const wxIcon & icon,wxCoord x,wxCoord y)176 virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) wxOVERRIDE 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) wxOVERRIDE 183 { 184 m_dc.DoDrawBitmap(bmp, GetX(x, y), GetY(x, y), useMask); 185 } 186 DoDrawText(const wxString & text,wxCoord x,wxCoord y)187 virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y) wxOVERRIDE 188 { 189 // this is never mirrored 190 m_dc.DoDrawText(text, x, y); 191 } 192 DoDrawRotatedText(const wxString & text,wxCoord x,wxCoord y,double angle)193 virtual void DoDrawRotatedText(const wxString& text, 194 wxCoord x, wxCoord y, double angle) wxOVERRIDE 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) wxOVERRIDE 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 DoGetSize(int * w,int * h)214 virtual void DoGetSize(int *w, int *h) const wxOVERRIDE 215 { 216 m_dc.DoGetSize(GetX(w, h), GetY(w, h)); 217 } 218 DoGetSizeMM(int * w,int * h)219 virtual void DoGetSizeMM(int *w, int *h) const wxOVERRIDE 220 { 221 m_dc.DoGetSizeMM(GetX(w, h), GetY(w, h)); 222 } 223 DoDrawLines(int n,const wxPoint points[],wxCoord xoffset,wxCoord yoffset)224 virtual void DoDrawLines(int n, const wxPoint points[], 225 wxCoord xoffset, wxCoord yoffset) wxOVERRIDE 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) wxOVERRIDE 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 DoSetDeviceClippingRegion(const wxRegion & WXUNUSED (region))248 virtual void DoSetDeviceClippingRegion(const wxRegion& WXUNUSED(region)) wxOVERRIDE 249 { 250 wxFAIL_MSG( wxT("not implemented") ); 251 } 252 DoSetClippingRegion(wxCoord x,wxCoord y,wxCoord w,wxCoord h)253 virtual void DoSetClippingRegion(wxCoord x, wxCoord y, 254 wxCoord w, wxCoord h) wxOVERRIDE 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 wxOVERRIDE 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: wxMirrorDC(wxDC & dc,bool mirror)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 Reflect(const wxSize & sizeOrig)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 300