From: Francesco Montorsi Date: Wed, 9 Jun 2010 18:03:27 +0000 (+0000) Subject: Increase interoperability between wxPoint and wxRealPoint introducing constructors... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/a5664fd6ef32c7e7432a9213ad8a8f9550460fbf Increase interoperability between wxPoint and wxRealPoint introducing constructors which convert between the two classes. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64539 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/gdicmn.h b/include/wx/gdicmn.h index 0eb175b799..1c3601f86c 100644 --- a/include/wx/gdicmn.h +++ b/include/wx/gdicmn.h @@ -395,6 +395,16 @@ public: wxRealPoint() : x(0.0), y(0.0) { } wxRealPoint(double xx, double yy) : x(xx), y(yy) { } + wxRealPoint(const wxPoint& pt); + + // no copy ctor or assignment operator - the defaults are ok + + //assignment operators + wxRealPoint& operator+=(const wxRealPoint& p) { x += p.x; y += p.y; return *this; } + wxRealPoint& operator-=(const wxRealPoint& p) { x -= p.x; y -= p.y; return *this; } + + wxRealPoint& operator+=(const wxSize& s) { x += s.GetWidth(); y += s.GetHeight(); return *this; } + wxRealPoint& operator-=(const wxSize& s) { x -= s.GetWidth(); y -= s.GetHeight(); return *this; } }; @@ -502,6 +512,7 @@ public: wxPoint() : x(0), y(0) { } wxPoint(int xx, int yy) : x(xx), y(yy) { } + wxPoint(const wxRealPoint& pt) : x(pt.x), y(pt.y) { } // no copy ctor or assignment operator - the defaults are ok diff --git a/interface/wx/gdicmn.h b/interface/wx/gdicmn.h index 192a6b6bd2..43a4aa596f 100644 --- a/interface/wx/gdicmn.h +++ b/interface/wx/gdicmn.h @@ -136,7 +136,49 @@ public: Initializes the point with the given coordinates. */ wxRealPoint(double x, double y); + + /** + Converts the given wxPoint (with integer coordinates) to a wxRealPoint. + */ + wxRealPoint(const wxPoint& pt); + + /** + @name Miscellaneous operators + + Note that these operators are documented as class members + (to make them easier to find) but, as their prototype shows, + they are implemented as global operators; note that this is + transparent to the user but it helps to understand why the + following functions are documented to take the wxPoint they + operate on as an explicit argument. + */ + //@{ + wxRealPoint& operator=(const wxRealPoint& pt); + + bool operator ==(const wxRealPoint& p1, const wxRealPoint& p2); + bool operator !=(const wxRealPoint& p1, const wxRealPoint& p2); + + wxRealPoint operator +(const wxRealPoint& p1, const wxRealPoint& p2); + wxRealPoint operator -(const wxRealPoint& p1, const wxRealPoint& p2); + + wxRealPoint& operator +=(const wxRealPoint& pt); + wxRealPoint& operator -=(const wxRealPoint& pt); + wxRealPoint operator +(const wxRealPoint& pt, const wxSize& sz); + wxRealPoint operator -(const wxRealPoint& pt, const wxSize& sz); + wxRealPoint operator +(const wxSize& sz, const wxRealPoint& pt); + wxRealPoint operator -(const wxSize& sz, const wxRealPoint& pt); + + wxRealPoint& operator +=(const wxSize& sz); + wxRealPoint& operator -=(const wxSize& sz); + + wxSize operator /(const wxRealPoint& sz, int factor); + wxSize operator *(const wxRealPoint& sz, int factor); + wxSize operator *(int factor, const wxSize& sz); + wxSize& operator /=(int factor); + wxSize& operator *=(int factor); + //@} + /** X coordinate of this point. */ @@ -497,6 +539,12 @@ public: Initializes the point object with the given @a x and @a y coordinates. */ wxPoint(int x, int y); + + /** + Converts the given wxRealPoint (with floating point coordinates) to a + wxPoint instance. + */ + wxPoint(const wxRealPoint& pt); /** @name Miscellaneous operators diff --git a/src/common/gdicmn.cpp b/src/common/gdicmn.cpp index 06117b98c2..f2522192b7 100644 --- a/src/common/gdicmn.cpp +++ b/src/common/gdicmn.cpp @@ -252,6 +252,11 @@ wxRect operator*(const wxRect& r1, const wxRect& r2) return wxRect(x1, y1, x2-x1, y2-y1); } +wxRealPoint::wxRealPoint(const wxPoint& pt) + : x(pt.x), y(pt.y) +{ +} + // ============================================================================ // wxColourDatabase // ============================================================================