added wxRect::CentreIn()
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@37435 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -68,6 +68,19 @@ Width member.
|
|||||||
Height member.
|
Height member.
|
||||||
|
|
||||||
|
|
||||||
|
\membersection{wxRect::CentreIn}\label{wxrectcentrein}
|
||||||
|
|
||||||
|
\constfunc{wxRect}{CentreIn}{\param{const wxRect\& }{r}, \param{int }{dir = wxBOTH}}
|
||||||
|
|
||||||
|
\constfunc{wxRect}{CenterIn}{\param{const wxRect\& }{r}, \param{int }{dir = wxBOTH}}
|
||||||
|
|
||||||
|
Returns the rectangle having the same size as this one but centered relatively
|
||||||
|
to the given rectangle \arg{r}. By default, rectangle is centred in both
|
||||||
|
directions but if \arg{dir} includes only \texttt{wxVERTICAL} or only
|
||||||
|
\texttt{wxHORIZONTAL} flag, then it is only centered in this direction while
|
||||||
|
the other component of its position remains unchanged.
|
||||||
|
|
||||||
|
|
||||||
\membersection{wxRect::Deflate}\label{wxrectdeflate}
|
\membersection{wxRect::Deflate}\label{wxrectdeflate}
|
||||||
|
|
||||||
\func{void}{Deflate}{\param{wxCoord }{dx}, \param{wxCoord }{dy}}
|
\func{void}{Deflate}{\param{wxCoord }{dx}, \param{wxCoord }{dy}}
|
||||||
|
@@ -428,6 +428,20 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// centre this rectangle in the given (usually, but not necessarily,
|
||||||
|
// larger) one
|
||||||
|
wxRect CentreIn(const wxRect& r, int dir = wxBOTH) const
|
||||||
|
{
|
||||||
|
return wxRect(dir & wxHORIZONTAL ? r.x + (r.width - width)/2 : x,
|
||||||
|
dir & wxVERTICAL ? r.y + (r.height - height)/2 : y,
|
||||||
|
width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
wxRect CenterIn(const wxRect& r, int dir = wxBOTH) const
|
||||||
|
{
|
||||||
|
return CentreIn(r, dir);
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int x, y, width, height;
|
int x, y, width, height;
|
||||||
};
|
};
|
||||||
|
@@ -21,6 +21,21 @@
|
|||||||
#include "wx/gdicmn.h"
|
#include "wx/gdicmn.h"
|
||||||
#endif // WX_PRECOMP
|
#endif // WX_PRECOMP
|
||||||
|
|
||||||
|
#include "wx/iosfwrap.h"
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// helper functions
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// this operator is needed to use CPPUNIT_ASSERT_EQUAL with wxRects
|
||||||
|
wxSTD ostream& operator<<(wxSTD ostream& os, const wxRect& r)
|
||||||
|
{
|
||||||
|
os << "{"
|
||||||
|
<< r.x << ", " << r.y << ", " << r.width << ", " << r.height
|
||||||
|
<< "}";
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// test class
|
// test class
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -32,11 +47,13 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
CPPUNIT_TEST_SUITE( RectTestCase );
|
CPPUNIT_TEST_SUITE( RectTestCase );
|
||||||
|
CPPUNIT_TEST( CentreIn );
|
||||||
CPPUNIT_TEST( InflateDeflate );
|
CPPUNIT_TEST( InflateDeflate );
|
||||||
CPPUNIT_TEST( Operators );
|
CPPUNIT_TEST( Operators );
|
||||||
CPPUNIT_TEST( Union );
|
CPPUNIT_TEST( Union );
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
|
|
||||||
|
void CentreIn();
|
||||||
void InflateDeflate();
|
void InflateDeflate();
|
||||||
void Operators();
|
void Operators();
|
||||||
void Union();
|
void Union();
|
||||||
@@ -50,6 +67,17 @@ CPPUNIT_TEST_SUITE_REGISTRATION( RectTestCase );
|
|||||||
// also include in it's own registry so that these tests can be run alone
|
// also include in it's own registry so that these tests can be run alone
|
||||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RectTestCase, "RectTestCase" );
|
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RectTestCase, "RectTestCase" );
|
||||||
|
|
||||||
|
void RectTestCase::CentreIn()
|
||||||
|
{
|
||||||
|
typedef wxRect R;
|
||||||
|
|
||||||
|
CPPUNIT_ASSERT_EQUAL( R(45, 45, 10, 10),
|
||||||
|
R(0, 0, 10, 10).CentreIn(R(0, 0, 100, 100)));
|
||||||
|
|
||||||
|
CPPUNIT_ASSERT_EQUAL( R(-5, -5, 20, 20),
|
||||||
|
R(0, 0, 20, 20).CentreIn(R(0, 0, 10, 10)));
|
||||||
|
}
|
||||||
|
|
||||||
void RectTestCase::InflateDeflate()
|
void RectTestCase::InflateDeflate()
|
||||||
{
|
{
|
||||||
// This is the rectangle from the example in the documentation of wxRect::Inflate().
|
// This is the rectangle from the example in the documentation of wxRect::Inflate().
|
||||||
|
Reference in New Issue
Block a user