diff --git a/include/wx/gdicmn.h b/include/wx/gdicmn.h index 555ee6985a..50d5043416 100644 --- a/include/wx/gdicmn.h +++ b/include/wx/gdicmn.h @@ -295,6 +295,102 @@ public: wxSize& operator/=(double i) { x = wxRound(x/i); y = wxRound(y/i); return *this; } wxSize& operator*=(double i) { x = wxRound(x*i); y = wxRound(y*i); return *this; } + friend bool operator==(const wxSize& s1, const wxSize& s2) + { + return s1.x == s2.x && s1.y == s2.y; + } + + friend bool operator!=(const wxSize& s1, const wxSize& s2) + { + return s1.x != s2.x || s1.y != s2.y; + } + + friend wxSize operator+(const wxSize& s1, const wxSize& s2) + { + return wxSize(s1.x + s2.x, s1.y + s2.y); + } + + friend wxSize operator-(const wxSize& s1, const wxSize& s2) + { + return wxSize(s1.x - s2.x, s1.y - s2.y); + } + + friend wxSize operator/(const wxSize& s, int i) + { + return wxSize(s.x / i, s.y / i); + } + + friend wxSize operator*(const wxSize& s, int i) + { + return wxSize(s.x * i, s.y * i); + } + + friend wxSize operator*(int i, const wxSize& s) + { + return wxSize(s.x * i, s.y * i); + } + + friend wxSize operator/(const wxSize& s, unsigned int i) + { + return wxSize(s.x / i, s.y / i); + } + + friend wxSize operator*(const wxSize& s, unsigned int i) + { + return wxSize(s.x * i, s.y * i); + } + + friend wxSize operator*(unsigned int i, const wxSize& s) + { + return wxSize(s.x * i, s.y * i); + } + + friend wxSize operator/(const wxSize& s, long i) + { + return wxSize(s.x / i, s.y / i); + } + + friend wxSize operator*(const wxSize& s, long i) + { + return wxSize(int(s.x * i), int(s.y * i)); + } + + friend wxSize operator*(long i, const wxSize& s) + { + return wxSize(int(s.x * i), int(s.y * i)); + } + + friend wxSize operator/(const wxSize& s, unsigned long i) + { + return wxSize(int(s.x / i), int(s.y / i)); + } + + friend wxSize operator*(const wxSize& s, unsigned long i) + { + return wxSize(int(s.x * i), int(s.y * i)); + } + + friend wxSize operator*(unsigned long i, const wxSize& s) + { + return wxSize(int(s.x * i), int(s.y * i)); + } + + friend wxSize operator/(const wxSize& s, double i) + { + return wxSize(wxRound(s.x / i), wxRound(s.y / i)); + } + + friend wxSize operator*(const wxSize& s, double i) + { + return wxSize(wxRound(s.x * i), wxRound(s.y * i)); + } + + friend wxSize operator*(double i, const wxSize& s) + { + return wxSize(wxRound(s.x * i), wxRound(s.y * i)); + } + + void IncTo(const wxSize& sz) { if ( sz.x > x ) x = sz.x; if ( sz.y > y ) y = sz.y; } void DecTo(const wxSize& sz) @@ -350,103 +446,6 @@ public: int GetY() const { return y; } }; -inline bool operator==(const wxSize& s1, const wxSize& s2) -{ - return s1.x == s2.x && s1.y == s2.y; -} - -inline bool operator!=(const wxSize& s1, const wxSize& s2) -{ - return s1.x != s2.x || s1.y != s2.y; -} - -inline wxSize operator+(const wxSize& s1, const wxSize& s2) -{ - return wxSize(s1.x + s2.x, s1.y + s2.y); -} - -inline wxSize operator-(const wxSize& s1, const wxSize& s2) -{ - return wxSize(s1.x - s2.x, s1.y - s2.y); -} - -inline wxSize operator/(const wxSize& s, int i) -{ - return wxSize(s.x / i, s.y / i); -} - -inline wxSize operator*(const wxSize& s, int i) -{ - return wxSize(s.x * i, s.y * i); -} - -inline wxSize operator*(int i, const wxSize& s) -{ - return wxSize(s.x * i, s.y * i); -} - -inline wxSize operator/(const wxSize& s, unsigned int i) -{ - return wxSize(s.x / i, s.y / i); -} - -inline wxSize operator*(const wxSize& s, unsigned int i) -{ - return wxSize(s.x * i, s.y * i); -} - -inline wxSize operator*(unsigned int i, const wxSize& s) -{ - return wxSize(s.x * i, s.y * i); -} - -inline wxSize operator/(const wxSize& s, long i) -{ - return wxSize(s.x / i, s.y / i); -} - -inline wxSize operator*(const wxSize& s, long i) -{ - return wxSize(int(s.x * i), int(s.y * i)); -} - -inline wxSize operator*(long i, const wxSize& s) -{ - return wxSize(int(s.x * i), int(s.y * i)); -} - -inline wxSize operator/(const wxSize& s, unsigned long i) -{ - return wxSize(int(s.x / i), int(s.y / i)); -} - -inline wxSize operator*(const wxSize& s, unsigned long i) -{ - return wxSize(int(s.x * i), int(s.y * i)); -} - -inline wxSize operator*(unsigned long i, const wxSize& s) -{ - return wxSize(int(s.x * i), int(s.y * i)); -} - -inline wxSize operator/(const wxSize& s, double i) -{ - return wxSize(wxRound(s.x / i), wxRound(s.y / i)); -} - -inline wxSize operator*(const wxSize& s, double i) -{ - return wxSize(wxRound(s.x * i), wxRound(s.y * i)); -} - -inline wxSize operator*(double i, const wxSize& s) -{ - return wxSize(wxRound(s.x * i), wxRound(s.y * i)); -} - - - // --------------------------------------------------------------------------- // Point classes: with real or integer coordinates // --------------------------------------------------------------------------- @@ -474,130 +473,129 @@ public: wxRealPoint& operator*=(int i) { x /= i; y /= i; return *this; } wxRealPoint& operator/=(double f) { x /= f; y /= f; return *this; } wxRealPoint& operator*=(double f) { x *= f; y *= f; return *this; } + + friend bool operator==(const wxRealPoint& p1, const wxRealPoint& p2) + { + return wxIsSameDouble(p1.x, p2.x) && wxIsSameDouble(p1.y, p2.y); + } + + friend bool operator!=(const wxRealPoint& p1, const wxRealPoint& p2) + { + return !(p1 == p2); + } + + friend wxRealPoint operator+(const wxRealPoint& p1, const wxRealPoint& p2) + { + return wxRealPoint(p1.x + p2.x, p1.y + p2.y); + } + + friend wxRealPoint operator-(const wxRealPoint& p1, const wxRealPoint& p2) + { + return wxRealPoint(p1.x - p2.x, p1.y - p2.y); + } + + friend wxRealPoint operator+(const wxRealPoint& pt, const wxSize& sz) + { + return wxRealPoint(pt.x + sz.GetWidth(), pt.y + sz.GetHeight()); + } + + friend wxRealPoint operator-(const wxRealPoint& pt, const wxSize& sz) + { + return wxRealPoint(pt.x - sz.GetWidth(), pt.y - sz.GetHeight()); + } + + friend wxRealPoint operator+(const wxSize& sz, const wxRealPoint& pt) + { + return wxRealPoint(sz.GetWidth() + pt.x, sz.GetHeight() + pt.y); + } + + friend wxRealPoint operator-(const wxSize& sz, const wxRealPoint& pt) + { + return wxRealPoint(sz.GetWidth() - pt.x, sz.GetHeight() - pt.y); + } + + friend wxRealPoint operator-(const wxRealPoint& pt) + { + return wxRealPoint(-pt.x, -pt.y); + } + + friend wxRealPoint operator/(const wxRealPoint& p, int i) + { + return wxRealPoint(p.x / i, p.y / i); + } + + friend wxRealPoint operator*(const wxRealPoint& p, int i) + { + return wxRealPoint(p.x * i, p.y * i); + } + + friend wxRealPoint operator*(int i, const wxRealPoint& p) + { + return wxRealPoint(p.x * i, p.y * i); + } + + friend wxRealPoint operator/(const wxRealPoint& p, unsigned int i) + { + return wxRealPoint(p.x / i, p.y / i); + } + + friend wxRealPoint operator*(const wxRealPoint& p, unsigned int i) + { + return wxRealPoint(p.x * i, p.y * i); + } + + friend wxRealPoint operator*(unsigned int i, const wxRealPoint& p) + { + return wxRealPoint(p.x * i, p.y * i); + } + + friend wxRealPoint operator/(const wxRealPoint& p, long i) + { + return wxRealPoint(p.x / i, p.y / i); + } + + friend wxRealPoint operator*(const wxRealPoint& p, long i) + { + return wxRealPoint(p.x * i, p.y * i); + } + + friend wxRealPoint operator*(long i, const wxRealPoint& p) + { + return wxRealPoint(p.x * i, p.y * i); + } + + friend wxRealPoint operator/(const wxRealPoint& p, unsigned long i) + { + return wxRealPoint(p.x / i, p.y / i); + } + + friend wxRealPoint operator*(const wxRealPoint& p, unsigned long i) + { + return wxRealPoint(p.x * i, p.y * i); + } + + friend wxRealPoint operator*(unsigned long i, const wxRealPoint& p) + { + return wxRealPoint(p.x * i, p.y * i); + } + + friend wxRealPoint operator/(const wxRealPoint& p, double f) + { + return wxRealPoint(p.x / f, p.y / f); + } + + friend wxRealPoint operator*(const wxRealPoint& p, double f) + { + return wxRealPoint(p.x * f, p.y * f); + } + + friend wxRealPoint operator*(double f, const wxRealPoint& p) + { + return wxRealPoint(p.x * f, p.y * f); + } }; -inline bool operator==(const wxRealPoint& p1, const wxRealPoint& p2) -{ - return wxIsSameDouble(p1.x, p2.x) && wxIsSameDouble(p1.y, p2.y); -} - -inline bool operator!=(const wxRealPoint& p1, const wxRealPoint& p2) -{ - return !(p1 == p2); -} - -inline wxRealPoint operator+(const wxRealPoint& p1, const wxRealPoint& p2) -{ - return wxRealPoint(p1.x + p2.x, p1.y + p2.y); -} - -inline wxRealPoint operator-(const wxRealPoint& p1, const wxRealPoint& p2) -{ - return wxRealPoint(p1.x - p2.x, p1.y - p2.y); -} - -inline wxRealPoint operator+(const wxRealPoint& pt, const wxSize& sz) -{ - return wxRealPoint(pt.x + sz.GetWidth(), pt.y + sz.GetHeight()); -} - -inline wxRealPoint operator-(const wxRealPoint& pt, const wxSize& sz) -{ - return wxRealPoint(pt.x - sz.GetWidth(), pt.y - sz.GetHeight()); -} - -inline wxRealPoint operator+(const wxSize& sz, const wxRealPoint& pt) -{ - return wxRealPoint(sz.GetWidth() + pt.x, sz.GetHeight() + pt.y); -} - -inline wxRealPoint operator-(const wxSize& sz, const wxRealPoint& pt) -{ - return wxRealPoint(sz.GetWidth() - pt.x, sz.GetHeight() - pt.y); -} - -inline wxRealPoint operator-(const wxRealPoint& pt) -{ - return wxRealPoint(-pt.x, -pt.y); -} - -inline wxRealPoint operator/(const wxRealPoint& p, int i) -{ - return wxRealPoint(p.x / i, p.y / i); -} - -inline wxRealPoint operator*(const wxRealPoint& p, int i) -{ - return wxRealPoint(p.x * i, p.y * i); -} - -inline wxRealPoint operator*(int i, const wxRealPoint& p) -{ - return wxRealPoint(p.x * i, p.y * i); -} - -inline wxRealPoint operator/(const wxRealPoint& p, unsigned int i) -{ - return wxRealPoint(p.x / i, p.y / i); -} - -inline wxRealPoint operator*(const wxRealPoint& p, unsigned int i) -{ - return wxRealPoint(p.x * i, p.y * i); -} - -inline wxRealPoint operator*(unsigned int i, const wxRealPoint& p) -{ - return wxRealPoint(p.x * i, p.y * i); -} - -inline wxRealPoint operator/(const wxRealPoint& p, long i) -{ - return wxRealPoint(p.x / i, p.y / i); -} - -inline wxRealPoint operator*(const wxRealPoint& p, long i) -{ - return wxRealPoint(p.x * i, p.y * i); -} - -inline wxRealPoint operator*(long i, const wxRealPoint& p) -{ - return wxRealPoint(p.x * i, p.y * i); -} - -inline wxRealPoint operator/(const wxRealPoint& p, unsigned long i) -{ - return wxRealPoint(p.x / i, p.y / i); -} - -inline wxRealPoint operator*(const wxRealPoint& p, unsigned long i) -{ - return wxRealPoint(p.x * i, p.y * i); -} - -inline wxRealPoint operator*(unsigned long i, const wxRealPoint& p) -{ - return wxRealPoint(p.x * i, p.y * i); -} - -inline wxRealPoint operator/(const wxRealPoint& p, double f) -{ - return wxRealPoint(p.x / f, p.y / f); -} - -inline wxRealPoint operator*(const wxRealPoint& p, double f) -{ - return wxRealPoint(p.x * f, p.y * f); -} - -inline wxRealPoint operator*(double f, const wxRealPoint& p) -{ - return wxRealPoint(p.x * f, p.y * f); -} - - // ---------------------------------------------------------------------------- // wxPoint: 2D point with integer coordinates // ---------------------------------------------------------------------------- @@ -625,6 +623,129 @@ public: wxPoint& operator/=(double f) { x = wxRound(x/f); y = wxRound(y/f); return *this; } wxPoint& operator*=(double f) { x = wxRound(x*f); y = wxRound(y*f); return *this; } + // comparison + friend bool operator==(const wxPoint& p1, const wxPoint& p2) + { + return p1.x == p2.x && p1.y == p2.y; + } + + friend bool operator!=(const wxPoint& p1, const wxPoint& p2) + { + return !(p1 == p2); + } + + + // arithmetic operations (component wise) + friend wxPoint operator+(const wxPoint& p1, const wxPoint& p2) + { + return wxPoint(p1.x + p2.x, p1.y + p2.y); + } + + friend wxPoint operator-(const wxPoint& p1, const wxPoint& p2) + { + return wxPoint(p1.x - p2.x, p1.y - p2.y); + } + + friend wxPoint operator+(const wxPoint& p, const wxSize& s) + { + return wxPoint(p.x + s.x, p.y + s.y); + } + + friend wxPoint operator-(const wxPoint& p, const wxSize& s) + { + return wxPoint(p.x - s.x, p.y - s.y); + } + + friend wxPoint operator+(const wxSize& s, const wxPoint& p) + { + return wxPoint(p.x + s.x, p.y + s.y); + } + + friend wxPoint operator-(const wxSize& s, const wxPoint& p) + { + return wxPoint(s.x - p.x, s.y - p.y); + } + + friend wxPoint operator-(const wxPoint& p) + { + return wxPoint(-p.x, -p.y); + } + + friend wxPoint operator/(const wxPoint& p, int i) + { + return wxPoint(p.x / i, p.y / i); + } + + friend wxPoint operator*(const wxPoint& p, int i) + { + return wxPoint(p.x * i, p.y * i); + } + + friend wxPoint operator*(int i, const wxPoint& p) + { + return wxPoint(p.x * i, p.y * i); + } + + friend wxPoint operator/(const wxPoint& p, unsigned int i) + { + return wxPoint(p.x / i, p.y / i); + } + + friend wxPoint operator*(const wxPoint& p, unsigned int i) + { + return wxPoint(p.x * i, p.y * i); + } + + friend wxPoint operator*(unsigned int i, const wxPoint& p) + { + return wxPoint(p.x * i, p.y * i); + } + + friend wxPoint operator/(const wxPoint& p, long i) + { + return wxPoint(p.x / i, p.y / i); + } + + friend wxPoint operator*(const wxPoint& p, long i) + { + return wxPoint(int(p.x * i), int(p.y * i)); + } + + friend wxPoint operator*(long i, const wxPoint& p) + { + return wxPoint(int(p.x * i), int(p.y * i)); + } + + friend wxPoint operator/(const wxPoint& p, unsigned long i) + { + return wxPoint(p.x / i, p.y / i); + } + + friend wxPoint operator*(const wxPoint& p, unsigned long i) + { + return wxPoint(int(p.x * i), int(p.y * i)); + } + + friend wxPoint operator*(unsigned long i, const wxPoint& p) + { + return wxPoint(int(p.x * i), int(p.y * i)); + } + + friend wxPoint operator/(const wxPoint& p, double f) + { + return wxPoint(wxRound(p.x / f), wxRound(p.y / f)); + } + + friend wxPoint operator*(const wxPoint& p, double f) + { + return wxPoint(int(p.x * f), int(p.y * f)); + } + + friend wxPoint operator*(double f, const wxPoint& p) + { + return wxPoint(int(p.x * f), int(p.y * f)); + } + // check if both components are set/initialized bool IsFullySpecified() const { return x != wxDefaultCoord && y != wxDefaultCoord; } @@ -639,129 +760,6 @@ public: }; -// comparison -inline bool operator==(const wxPoint& p1, const wxPoint& p2) -{ - return p1.x == p2.x && p1.y == p2.y; -} - -inline bool operator!=(const wxPoint& p1, const wxPoint& p2) -{ - return !(p1 == p2); -} - - -// arithmetic operations (component wise) -inline wxPoint operator+(const wxPoint& p1, const wxPoint& p2) -{ - return wxPoint(p1.x + p2.x, p1.y + p2.y); -} - -inline wxPoint operator-(const wxPoint& p1, const wxPoint& p2) -{ - return wxPoint(p1.x - p2.x, p1.y - p2.y); -} - -inline wxPoint operator+(const wxPoint& p, const wxSize& s) -{ - return wxPoint(p.x + s.x, p.y + s.y); -} - -inline wxPoint operator-(const wxPoint& p, const wxSize& s) -{ - return wxPoint(p.x - s.x, p.y - s.y); -} - -inline wxPoint operator+(const wxSize& s, const wxPoint& p) -{ - return wxPoint(p.x + s.x, p.y + s.y); -} - -inline wxPoint operator-(const wxSize& s, const wxPoint& p) -{ - return wxPoint(s.x - p.x, s.y - p.y); -} - -inline wxPoint operator-(const wxPoint& p) -{ - return wxPoint(-p.x, -p.y); -} - -inline wxPoint operator/(const wxPoint& p, int i) -{ - return wxPoint(p.x / i, p.y / i); -} - -inline wxPoint operator*(const wxPoint& p, int i) -{ - return wxPoint(p.x * i, p.y * i); -} - -inline wxPoint operator*(int i, const wxPoint& p) -{ - return wxPoint(p.x * i, p.y * i); -} - -inline wxPoint operator/(const wxPoint& p, unsigned int i) -{ - return wxPoint(p.x / i, p.y / i); -} - -inline wxPoint operator*(const wxPoint& p, unsigned int i) -{ - return wxPoint(p.x * i, p.y * i); -} - -inline wxPoint operator*(unsigned int i, const wxPoint& p) -{ - return wxPoint(p.x * i, p.y * i); -} - -inline wxPoint operator/(const wxPoint& p, long i) -{ - return wxPoint(p.x / i, p.y / i); -} - -inline wxPoint operator*(const wxPoint& p, long i) -{ - return wxPoint(int(p.x * i), int(p.y * i)); -} - -inline wxPoint operator*(long i, const wxPoint& p) -{ - return wxPoint(int(p.x * i), int(p.y * i)); -} - -inline wxPoint operator/(const wxPoint& p, unsigned long i) -{ - return wxPoint(p.x / i, p.y / i); -} - -inline wxPoint operator*(const wxPoint& p, unsigned long i) -{ - return wxPoint(int(p.x * i), int(p.y * i)); -} - -inline wxPoint operator*(unsigned long i, const wxPoint& p) -{ - return wxPoint(int(p.x * i), int(p.y * i)); -} - -inline wxPoint operator/(const wxPoint& p, double f) -{ - return wxPoint(wxRound(p.x / f), wxRound(p.y / f)); -} - -inline wxPoint operator*(const wxPoint& p, double f) -{ - return wxPoint(int(p.x * f), int(p.y * f)); -} - -inline wxPoint operator*(double f, const wxPoint& p) -{ - return wxPoint(int(p.x * f), int(p.y * f)); -} - WX_DECLARE_LIST_WITH_DECL(wxPoint, wxPointList, class WXDLLIMPEXP_CORE); // --------------------------------------------------------------------------- @@ -888,9 +886,24 @@ public: // like Union() but don't ignore empty rectangles wxRect& operator+=(const wxRect& rect); + friend WXDLLIMPEXP_CORE wxRect operator+(const wxRect& r1, const wxRect& r2); // intersections of two rectangles not testing for empty rectangles wxRect& operator*=(const wxRect& rect); + friend WXDLLIMPEXP_CORE wxRect operator*(const wxRect& r1, const wxRect& r2); + + // compare rectangles + friend bool operator==(const wxRect& r1, const wxRect& r2) + { + return (r1.x == r2.x) && (r1.y == r2.y) && + (r1.width == r2.width) && (r1.height == r2.height); + } + + friend bool operator!=(const wxRect& r1, const wxRect& r2) + { + return !(r1 == r2); + } + // centre this rectangle in the given (usually, but not necessarily, // larger) one @@ -920,24 +933,6 @@ public: }; -// compare rectangles -inline bool operator==(const wxRect& r1, const wxRect& r2) -{ - return (r1.x == r2.x) && (r1.y == r2.y) && - (r1.width == r2.width) && (r1.height == r2.height); -} - -inline bool operator!=(const wxRect& r1, const wxRect& r2) -{ - return !(r1 == r2); -} - -// like Union() but don't treat empty rectangles specially -WXDLLIMPEXP_CORE wxRect operator+(const wxRect& r1, const wxRect& r2); - -// intersections of two rectangles -WXDLLIMPEXP_CORE wxRect operator*(const wxRect& r1, const wxRect& r2); - // define functions which couldn't be defined above because of declarations // order inline void wxSize::IncBy(const wxPoint& pt) { IncBy(pt.x, pt.y); } diff --git a/interface/wx/gdicmn.h b/interface/wx/gdicmn.h index 12105288c2..bef77ab9d4 100644 --- a/interface/wx/gdicmn.h +++ b/interface/wx/gdicmn.h @@ -200,44 +200,41 @@ public: /** @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. + Note that binary operators are defined as friend functions inside this + class, making them accessible via argument-dependent lookup, but hidden + otherwise. */ ///@{ wxRealPoint& operator=(const wxRealPoint& pt); - bool operator ==(const wxRealPoint& p1, const wxRealPoint& p2); - bool operator !=(const wxRealPoint& p1, const wxRealPoint& p2); + friend bool operator ==(const wxRealPoint& p1, const wxRealPoint& p2); + friend bool operator !=(const wxRealPoint& p1, const wxRealPoint& p2); - wxRealPoint operator +(const wxRealPoint& p1, const wxRealPoint& p2); - wxRealPoint operator -(const wxRealPoint& p1, const wxRealPoint& p2); + friend wxRealPoint operator +(const wxRealPoint& p1, const wxRealPoint& p2); + friend 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); + friend wxRealPoint operator +(const wxRealPoint& pt, const wxSize& sz); + friend wxRealPoint operator -(const wxRealPoint& pt, const wxSize& sz); + friend wxRealPoint operator +(const wxSize& sz, const wxRealPoint& pt); + friend wxRealPoint operator -(const wxSize& sz, const wxRealPoint& pt); wxRealPoint& operator +=(const wxSize& sz); wxRealPoint& operator -=(const wxSize& sz); - wxRealPoint operator -(const wxRealPoint& pt); + friend wxRealPoint operator -(const wxRealPoint& pt); - wxRealPoint operator /(const wxRealPoint& sz, int divisor); - wxRealPoint operator *(const wxRealPoint& sz, int factor); - wxRealPoint operator *(int factor, const wxRealPoint& pt); + friend wxRealPoint operator /(const wxRealPoint& sz, int divisor); + friend wxRealPoint operator *(const wxRealPoint& sz, int factor); + friend wxRealPoint operator *(int factor, const wxRealPoint& pt); wxRealPoint& operator /=(int divisor); wxRealPoint& operator *=(int factor); - wxRealPoint operator /(const wxRealPoint& pt, double divisor); - wxRealPoint operator *(const wxRealPoint& pt, double factor); - wxRealPoint operator *(double factor, const wxRealPoint& pt); + friend wxRealPoint operator /(const wxRealPoint& pt, double divisor); + friend wxRealPoint operator *(const wxRealPoint& pt, double factor); + friend wxRealPoint operator *(double factor, const wxRealPoint& pt); wxRealPoint& operator /=(double divisor); wxRealPoint& operator *=(double factor); ///@} @@ -608,13 +605,13 @@ public: /** Inequality operator. */ - bool operator !=(const wxRect& r1, const wxRect& r2); + friend bool operator !=(const wxRect& r1, const wxRect& r2); ///@{ /** Like Union(), but doesn't treat empty rectangles specially. */ - wxRect operator +(const wxRect& r1, const wxRect& r2); + friend wxRect operator +(const wxRect& r1, const wxRect& r2); wxRect& operator +=(const wxRect& r); ///@} @@ -622,7 +619,7 @@ public: /** Returns the intersection of two rectangles (which may be empty). */ - wxRect operator *(const wxRect& r1, const wxRect& r2); + friend wxRect operator *(const wxRect& r1, const wxRect& r2); wxRect& operator *=(const wxRect& r); ///@} @@ -634,7 +631,7 @@ public: /** Equality operator. */ - bool operator ==(const wxRect& r1, const wxRect& r2); + friend bool operator ==(const wxRect& r1, const wxRect& r2); /** Height member. @@ -712,44 +709,41 @@ public: /** @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. + Note that binary operators are defined as friend functions inside this + class, making them accessible via argument-dependent lookup, but hidden + otherwise. */ ///@{ wxPoint& operator=(const wxPoint& pt); - bool operator ==(const wxPoint& p1, const wxPoint& p2); - bool operator !=(const wxPoint& p1, const wxPoint& p2); + friend bool operator ==(const wxPoint& p1, const wxPoint& p2); + friend bool operator !=(const wxPoint& p1, const wxPoint& p2); - wxPoint operator +(const wxPoint& p1, const wxPoint& p2); - wxPoint operator -(const wxPoint& p1, const wxPoint& p2); + friend wxPoint operator +(const wxPoint& p1, const wxPoint& p2); + friend wxPoint operator -(const wxPoint& p1, const wxPoint& p2); wxPoint& operator +=(const wxPoint& pt); wxPoint& operator -=(const wxPoint& pt); - wxPoint operator +(const wxPoint& pt, const wxSize& sz); - wxPoint operator -(const wxPoint& pt, const wxSize& sz); - wxPoint operator +(const wxSize& sz, const wxPoint& pt); - wxPoint operator -(const wxSize& sz, const wxPoint& pt); + friend wxPoint operator +(const wxPoint& pt, const wxSize& sz); + friend wxPoint operator -(const wxPoint& pt, const wxSize& sz); + friend wxPoint operator +(const wxSize& sz, const wxPoint& pt); + friend wxPoint operator -(const wxSize& sz, const wxPoint& pt); wxPoint& operator +=(const wxSize& sz); wxPoint& operator -=(const wxSize& sz); wxPoint operator -(const wxPoint& pt); - wxPoint operator /(const wxPoint& sz, int divisor); - wxPoint operator *(const wxPoint& sz, int factor); - wxPoint operator *(int factor, const wxPoint& sz); + friend wxPoint operator /(const wxPoint& sz, int divisor); + friend wxPoint operator *(const wxPoint& sz, int factor); + friend wxPoint operator *(int factor, const wxPoint& sz); wxPoint& operator /=(int divisor); wxPoint& operator *=(int factor); - wxPoint operator /(const wxPoint& pt, double divisor); - wxPoint operator *(const wxPoint& pt, double factor); - wxPoint operator *(double factor, const wxPoint& pt); + friend wxPoint operator /(const wxPoint& pt, double divisor); + friend wxPoint operator *(const wxPoint& pt, double factor); + friend wxPoint operator *(double factor, const wxPoint& pt); wxPoint& operator /=(double divisor); wxPoint& operator *=(double factor); ///@} @@ -1117,12 +1111,9 @@ public: Sizes can be added to or subtracted from each other or divided or multiplied by a number. - 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 wxSize they - operate on as an explicit argument. + Note that binary operators are defined as friend functions inside this + class, making them accessible via argument-dependent lookup, but hidden + otherwise. Also note that using @c double factor may result in rounding errors, as wxSize always stores @c int coordinates and the result is always @@ -1131,20 +1122,20 @@ public: ///@{ wxSize& operator=(const wxSize& sz); - bool operator ==(const wxSize& s1, const wxSize& s2); - bool operator !=(const wxSize& s1, const wxSize& s2); + friend bool operator ==(const wxSize& s1, const wxSize& s2); + friend bool operator !=(const wxSize& s1, const wxSize& s2); - wxSize operator +(const wxSize& s1, const wxSize& s2); - wxSize operator -(const wxSize& s1, const wxSize& s2); + friend wxSize operator +(const wxSize& s1, const wxSize& s2); + friend wxSize operator -(const wxSize& s1, const wxSize& s2); wxSize& operator +=(const wxSize& sz); wxSize& operator -=(const wxSize& sz); - wxSize operator /(const wxSize& sz, int factor); - wxSize operator /(const wxSize& sz, double factor); - wxSize operator *(const wxSize& sz, int factor); - wxSize operator *(const wxSize& sz, double factor); - wxSize operator *(int factor, const wxSize& sz); - wxSize operator *(double factor, const wxSize& sz); + friend wxSize operator /(const wxSize& sz, int factor); + friend wxSize operator /(const wxSize& sz, double factor); + friend wxSize operator *(const wxSize& sz, int factor); + friend wxSize operator *(const wxSize& sz, double factor); + friend wxSize operator *(int factor, const wxSize& sz); + friend wxSize operator *(double factor, const wxSize& sz); wxSize& operator /=(int factor); wxSize& operator /=(double factor); wxSize& operator *=(int factor);