added and documented wxRect::Union(); also moved some methods inline

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30932 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2004-12-11 23:29:55 +00:00
parent c28cb884de
commit df83b840bb
3 changed files with 83 additions and 23 deletions

View File

@ -16,6 +16,7 @@ None
\latexignore{\rtfignore{\wxheading{Members}}}
\membersection{wxRect::wxRect}\label{wxrectctor}
\func{}{wxRect}{\void}
@ -38,30 +39,35 @@ Creates a wxRect object from position and size values.
Creates a wxRect object from size values at the origin.
\membersection{wxRect::x}\label{wxrectx}
\member{int}{x}
x coordinate of the top-level corner of the rectangle.
\membersection{wxRect::y}\label{wxrecty}
\member{int}{y}
y coordinate of the top-level corner of the rectangle.
\membersection{wxRect::width}\label{wxrectwidth}
\member{int}{width}
Width member.
\membersection{wxRect::height}\label{wxrectheight}
\member{int}{height}
Height member.
\membersection{wxRect::Deflate}\label{wxrectdeflate}
\func{void}{Deflate}{\param{wxCoord }{dx}, \param{wxCoord }{dy}}
@ -83,78 +89,91 @@ new rectangle leaving this one unchanged.
\helpref{Inflate}{wxrectinflate}
\membersection{wxRect::GetBottom}\label{wxrectgetbottom}
\constfunc{int}{GetBottom}{\void}
Gets the bottom point of the rectangle.
\membersection{wxRect::GetHeight}\label{wxrectgetheight}
\constfunc{int}{GetHeight}{\void}
Gets the height member.
\membersection{wxRect::GetLeft}\label{wxrectgetleft}
\constfunc{int}{GetLeft}{\void}
Gets the left point of the rectangle (the same as \helpref{wxRect::GetX}{wxrectgetx}).
\membersection{wxRect::GetPosition}\label{wxrectgetposition}
\constfunc{wxPoint}{GetPosition}{\void}
Gets the position.
\membersection{wxRect::GetTopLeft}\label{wxrectgettopleft}
\constfunc{wxPoint}{GetTopLeft}{\void}
Gets the topleft position of the rectangle. (Same as GetPosition).
\membersection{wxRect::GetBottomRight}\label{wxrectgetbottomright}
\constfunc{wxPoint}{GetBottomRight}{\void}
Gets the the bottom right position. Returns the bottom right point inside the rectangle.
\membersection{wxRect::GetRight}\label{wxrectgetright}
\constfunc{int}{GetRight}{\void}
Gets the right point of the rectangle.
\membersection{wxRect::GetSize}\label{wxrectgetsize}
\constfunc{wxSize}{GetSize}{\void}
Gets the size.
\membersection{wxRect::GetTop}\label{wxrectgettop}
\constfunc{int}{GetTop}{\void}
Gets the top point of the rectangle (the same as \helpref{wxRect::GetY}{wxrectgety}).
\membersection{wxRect::GetWidth}\label{wxrectgetwidth}
\constfunc{int}{GetWidth}{\void}
Gets the width member.
\membersection{wxRect::GetX}\label{wxrectgetx}
\constfunc{int}{GetX}{\void}
Gets the x member.
\membersection{wxRect::GetY}\label{wxrectgety}
\constfunc{int}{GetY}{\void}
Gets the y member.
\membersection{wxRect::Inflate}\label{wxrectinflate}
\func{void}{Inflate}{\param{wxCoord }{dx}, \param{wxCoord }{dy}}
@ -176,6 +195,7 @@ new rectangle leaving this one unchanged.
\helpref{Deflate}{wxrectdeflate}
\membersection{wxRect::Inside}\label{wxrectinside}
\constfunc{bool}{Inside}{\param{int }{x}, \param{int }{y}}
@ -185,6 +205,7 @@ new rectangle leaving this one unchanged.
Returns {\tt true} if the given point is inside the rectangle (or on its
boundary) and {\tt false} otherwise.
\membersection{wxRect::Intersects}\label{wxrectintersects}
\constfunc{bool}{Intersects}{\param{const wxRect\& }{rect}}
@ -192,6 +213,7 @@ boundary) and {\tt false} otherwise.
Returns {\tt true} if this rectangle has a non empty intersection with the
rectangle {\it rect} and {\tt false} otherwise.
\membersection{wxRect::Offset}\label{wxrectoffset}
\func{void}{Offset}{\param{wxCoord }{dx}, \param{wxCoord }{dy}}
@ -202,42 +224,60 @@ Moves the rectangle by the specified offset. If {\it dx} is positive, the
rectangle is moved to the right, if {\it dy} is positive, it is moved to the
bottom, otherwise it is moved to the left or top respectively.
\membersection{wxRect::SetHeight}\label{wxrectsetheight}
\func{void}{SetHeight}{\param{int}{ height}}
Sets the height.
\membersection{wxRect::SetWidth}\label{wxrectsetwidth}
\func{void}{SetWidth}{\param{int}{ width}}
Sets the width.
\membersection{wxRect::SetX}\label{wxrectsetx}
\func{void}{SetX}{\param{int}{ x}}
Sets the x position.
\membersection{wxRect::SetY}\label{wxrectsety}
\func{void}{SetY}{\param{int}{ y}}
Sets the y position.
\membersection{wxRect::Union}\label{wxrectunion}
\constfunc{wxRect}{Union}{\param{const wxRect\&}{ rect}}
\func{wxRect\&}{Union}{\param{const wxRect\&}{ rect}}
Modifies the rectangle to contain the bounding box of this rectangle and the
one passed in as parameter. The const version returns the new rectangle, the
other one modifies this rectangle in place.
\membersection{wxRect::operator $=$}\label{wxrectassign}
\func{void}{operator $=$}{\param{const wxRect\& }{rect}}
Assignment operator.
\membersection{wxRect::operator $==$}\label{wxrectequal}
\func{bool}{operator $==$}{\param{const wxRect\& }{rect}}
Equality operator.
\membersection{wxRect::operator $!=$}\label{wxrectnotequal}
\func{bool}{operator $!=$}{\param{const wxRect\& }{rect}}

View File

@ -319,8 +319,12 @@ public:
: x(xx), y(yy), width(ww), height(hh)
{ }
wxRect(const wxPoint& topLeft, const wxPoint& bottomRight);
wxRect(const wxPoint& pos, const wxSize& size);
wxRect(const wxSize& size);
wxRect(const wxPoint& pt, const wxSize& size)
: x(pt.x), y(pt.y), width(size.x), height(size.y)
{ }
wxRect(const wxSize& size)
: x(0), y(0), width(size.x), height(size.y)
{ }
// default copy ctor and assignment operators ok
@ -392,8 +396,13 @@ public:
return r;
}
wxRect operator+(const wxRect& rect) const;
wxRect& operator+=(const wxRect& rect);
wxRect& Union(const wxRect& rect);
wxRect Union(const wxRect& rect) const
{
wxRect r = *this;
r.Union(rect);
return r;
}
// compare rectangles
bool operator==(const wxRect& rect) const;
@ -406,6 +415,16 @@ public:
// return true if the rectangles have a non empty intersection
bool Intersects(const wxRect& rect) const;
// these are like Union() but don't ignore empty rectangles
wxRect operator+(const wxRect& rect) const;
wxRect& wxRect::operator+=(const wxRect& rect)
{
*this = *this + rect;
return *this;
}
public:
int x, y, width, height;
};

View File

@ -119,18 +119,6 @@ wxRect::wxRect(const wxPoint& point1, const wxPoint& point2)
height++;
}
wxRect::wxRect(const wxPoint& point, const wxSize& size)
{
x = point.x; y = point.y;
width = size.x; height = size.y;
}
wxRect::wxRect(const wxSize& size)
{
x = 0; y = 0;
width = size.x; height = size.y;
}
bool wxRect::operator==(const wxRect& rect) const
{
return ((x == rect.x) &&
@ -139,13 +127,7 @@ bool wxRect::operator==(const wxRect& rect) const
(height == rect.height));
}
wxRect& wxRect::operator += (const wxRect& rect)
{
*this = (*this + rect);
return ( *this ) ;
}
wxRect wxRect::operator + (const wxRect& rect) const
wxRect wxRect::operator+(const wxRect& rect) const
{
int x1 = wxMin(this->x, rect.x);
int y1 = wxMin(this->y, rect.y);
@ -154,6 +136,25 @@ wxRect wxRect::operator + (const wxRect& rect) const
return wxRect(x1, y1, x2-x1, y2-y1);
}
wxRect& wxRect::Union(const wxRect& rect)
{
// ignore empty rectangles
if ( rect.width && rect.height )
{
int x1 = wxMin(x, rect.x);
int y1 = wxMin(y, rect.y);
int y2 = wxMax(y + height, rect.height + rect.y);
int x2 = wxMax(x + width, rect.width + rect.x);
x = x1;
y = y1;
width = x2 - x1;
height = y2 - y1;
}
return *this;
}
wxRect& wxRect::Inflate(wxCoord dx, wxCoord dy)
{
x -= dx;