2010-10-14 08:27:31 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-07-11 09:51:50 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
2007-04-11 19:12:02 +00:00
|
|
|
*
|
2012-07-11 09:51:50 +01:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2007-04-11 19:12:02 +00:00
|
|
|
*
|
2012-07-11 09:51:50 +01:00
|
|
|
* This file incorporates work covered by the following license notice:
|
2007-04-11 19:12:02 +00:00
|
|
|
*
|
2012-07-11 09:51:50 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2013-10-23 19:15:52 +02:00
|
|
|
#ifndef INCLUDED_TOOLS_GEN_HXX
|
|
|
|
#define INCLUDED_TOOLS_GEN_HXX
|
2007-04-11 19:12:02 +00:00
|
|
|
|
2013-11-09 15:37:43 -06:00
|
|
|
#include <tools/toolsdllapi.h>
|
2007-04-11 19:12:02 +00:00
|
|
|
|
2007-04-25 14:21:13 +00:00
|
|
|
#include <limits.h>
|
2014-07-08 01:05:33 +03:00
|
|
|
#include <algorithm>
|
2012-11-21 18:24:28 +01:00
|
|
|
#include <ostream>
|
2013-04-20 16:27:19 +02:00
|
|
|
#include <cstdlib>
|
2007-04-25 14:21:13 +00:00
|
|
|
|
2007-04-11 19:12:02 +00:00
|
|
|
class SvStream;
|
|
|
|
|
2014-02-24 12:25:02 +01:00
|
|
|
enum TriState { TRISTATE_FALSE, TRISTATE_TRUE, TRISTATE_INDET };
|
|
|
|
|
2012-08-13 22:51:30 +02:00
|
|
|
// Pair
|
2007-04-11 19:12:02 +00:00
|
|
|
|
2012-10-11 15:14:35 +01:00
|
|
|
class SAL_WARN_UNUSED Pair
|
2007-04-11 19:12:02 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
Pair();
|
|
|
|
Pair( long nA, long nB );
|
|
|
|
|
|
|
|
long A() const { return nA; }
|
|
|
|
long B() const { return nB; }
|
|
|
|
|
|
|
|
long& A() { return nA; }
|
|
|
|
long& B() { return nB; }
|
|
|
|
|
2013-06-29 23:57:38 -05:00
|
|
|
bool operator == ( const Pair& rPair ) const;
|
|
|
|
bool operator != ( const Pair& rPair ) const;
|
2007-04-11 19:12:02 +00:00
|
|
|
|
2014-01-30 13:46:42 +02:00
|
|
|
TOOLS_DLLPUBLIC friend SvStream& ReadPair( SvStream& rIStream, Pair& rPair );
|
2014-01-14 13:52:54 +02:00
|
|
|
TOOLS_DLLPUBLIC friend SvStream& WritePair( SvStream& rOStream, const Pair& rPair );
|
2012-10-28 23:23:53 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
long nA;
|
|
|
|
long nB;
|
2007-04-11 19:12:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
inline Pair::Pair()
|
|
|
|
{
|
|
|
|
nA = nB = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Pair::Pair( long _nA, long _nB )
|
|
|
|
{
|
|
|
|
Pair::nA = _nA;
|
|
|
|
Pair::nB = _nB;
|
|
|
|
}
|
|
|
|
|
2013-06-29 23:57:38 -05:00
|
|
|
inline bool Pair::operator == ( const Pair& rPair ) const
|
2007-04-11 19:12:02 +00:00
|
|
|
{
|
|
|
|
return ((nA == rPair.nA) && (nB == rPair.nB));
|
|
|
|
}
|
|
|
|
|
2013-06-29 23:57:38 -05:00
|
|
|
inline bool Pair::operator != ( const Pair& rPair ) const
|
2007-04-11 19:12:02 +00:00
|
|
|
{
|
|
|
|
return ((nA != rPair.nA) || (nB != rPair.nB));
|
|
|
|
}
|
|
|
|
|
2012-08-13 22:51:30 +02:00
|
|
|
// Point
|
2007-04-11 19:12:02 +00:00
|
|
|
|
2014-11-01 21:33:09 +11:00
|
|
|
class SAL_DLLPUBLIC_EXPORT SAL_WARN_UNUSED Point : public Pair
|
2007-04-11 19:12:02 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
Point();
|
|
|
|
Point( long nX, long nY );
|
|
|
|
|
|
|
|
long X() const { return nA; }
|
|
|
|
long Y() const { return nB; }
|
|
|
|
|
|
|
|
long& X() { return nA; }
|
|
|
|
long& Y() { return nB; }
|
|
|
|
|
|
|
|
void Move( long nHorzMove, long nVertMove );
|
2013-06-29 23:57:38 -05:00
|
|
|
bool IsAbove( const Point& rPoint ) const;
|
|
|
|
bool IsBelow( const Point& rPoint ) const;
|
|
|
|
bool IsLeft( const Point& rPoint ) const;
|
|
|
|
bool IsRight( const Point& rPoint ) const;
|
2007-04-11 19:12:02 +00:00
|
|
|
|
2014-11-01 21:33:09 +11:00
|
|
|
void RotateAround( long& rX, long& rY, short nOrientation ) const;
|
|
|
|
|
|
|
|
|
2007-04-11 19:12:02 +00:00
|
|
|
Point& operator += ( const Point& rPoint );
|
|
|
|
Point& operator -= ( const Point& rPoint );
|
|
|
|
Point& operator *= ( const long nVal );
|
|
|
|
Point& operator /= ( const long nVal );
|
|
|
|
|
|
|
|
friend inline Point operator+( const Point &rVal1, const Point &rVal2 );
|
|
|
|
friend inline Point operator-( const Point &rVal1, const Point &rVal2 );
|
|
|
|
friend inline Point operator*( const Point &rVal1, const long nVal2 );
|
|
|
|
friend inline Point operator/( const Point &rVal1, const long nVal2 );
|
|
|
|
|
|
|
|
long getX() const { return X(); }
|
|
|
|
long getY() const { return Y(); }
|
|
|
|
void setX(long nX) { X() = nX; }
|
|
|
|
void setY(long nY) { Y() = nY; }
|
|
|
|
};
|
|
|
|
|
|
|
|
inline Point::Point()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Point::Point( long nX, long nY ) : Pair( nX, nY )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void Point::Move( long nHorzMove, long nVertMove )
|
|
|
|
{
|
|
|
|
nA += nHorzMove;
|
|
|
|
nB += nVertMove;
|
|
|
|
}
|
|
|
|
|
2013-06-29 23:57:38 -05:00
|
|
|
inline bool Point::IsAbove( const Point& rPoint ) const
|
2007-04-11 19:12:02 +00:00
|
|
|
{
|
|
|
|
return (nB > rPoint.nB);
|
|
|
|
}
|
|
|
|
|
2013-06-29 23:57:38 -05:00
|
|
|
inline bool Point::IsBelow( const Point& rPoint ) const
|
2007-04-11 19:12:02 +00:00
|
|
|
{
|
|
|
|
return (nB < rPoint.nB);
|
|
|
|
}
|
|
|
|
|
2013-06-29 23:57:38 -05:00
|
|
|
inline bool Point::IsLeft( const Point& rPoint ) const
|
2007-04-11 19:12:02 +00:00
|
|
|
{
|
|
|
|
return (nA < rPoint.nA);
|
|
|
|
}
|
|
|
|
|
2013-06-29 23:57:38 -05:00
|
|
|
inline bool Point::IsRight( const Point& rPoint ) const
|
2007-04-11 19:12:02 +00:00
|
|
|
{
|
|
|
|
return (nA > rPoint.nA);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Point& Point::operator += ( const Point& rPoint )
|
|
|
|
{
|
|
|
|
nA += rPoint.nA;
|
|
|
|
nB += rPoint.nB;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Point& Point::operator -= ( const Point& rPoint )
|
|
|
|
{
|
|
|
|
nA -= rPoint.nA;
|
|
|
|
nB -= rPoint.nB;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Point& Point::operator *= ( const long nVal )
|
|
|
|
{
|
|
|
|
nA *= nVal;
|
|
|
|
nB *= nVal;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Point& Point::operator /= ( const long nVal )
|
|
|
|
{
|
|
|
|
nA /= nVal;
|
|
|
|
nB /= nVal;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Point operator+( const Point &rVal1, const Point &rVal2 )
|
|
|
|
{
|
|
|
|
return Point( rVal1.nA+rVal2.nA, rVal1.nB+rVal2.nB );
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Point operator-( const Point &rVal1, const Point &rVal2 )
|
|
|
|
{
|
|
|
|
return Point( rVal1.nA-rVal2.nA, rVal1.nB-rVal2.nB );
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Point operator*( const Point &rVal1, const long nVal2 )
|
|
|
|
{
|
|
|
|
return Point( rVal1.nA*nVal2, rVal1.nB*nVal2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Point operator/( const Point &rVal1, const long nVal2 )
|
|
|
|
{
|
|
|
|
return Point( rVal1.nA/nVal2, rVal1.nB/nVal2 );
|
|
|
|
}
|
|
|
|
|
2012-11-21 17:52:00 +01:00
|
|
|
template< typename charT, typename traits >
|
|
|
|
inline std::basic_ostream<charT, traits> & operator <<(
|
|
|
|
std::basic_ostream<charT, traits> & stream, const Point& point )
|
|
|
|
{
|
|
|
|
return stream << point.X() << ',' << point.Y();
|
|
|
|
}
|
|
|
|
|
2012-08-13 22:51:30 +02:00
|
|
|
// Size
|
2007-04-11 19:12:02 +00:00
|
|
|
|
2012-10-11 15:14:35 +01:00
|
|
|
class SAL_WARN_UNUSED Size : public Pair
|
2007-04-11 19:12:02 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
Size();
|
|
|
|
Size( long nWidth, long nHeight );
|
|
|
|
|
|
|
|
long Width() const { return nA; }
|
|
|
|
long Height() const { return nB; }
|
|
|
|
|
|
|
|
long& Width() { return nA; }
|
|
|
|
long& Height() { return nB; }
|
|
|
|
|
2012-12-13 13:39:18 +02:00
|
|
|
long getWidth() const { return Width(); }
|
|
|
|
long getHeight() const { return Height(); }
|
|
|
|
void setWidth(long nWidth) { Width() = nWidth; }
|
|
|
|
void setHeight(long nHeight) { Height() = nHeight; }
|
2007-04-11 19:12:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
inline Size::Size()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Size::Size( long nWidth, long nHeight ) :
|
|
|
|
Pair( nWidth, nHeight )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-11-21 17:52:00 +01:00
|
|
|
template< typename charT, typename traits >
|
|
|
|
inline std::basic_ostream<charT, traits> & operator <<(
|
|
|
|
std::basic_ostream<charT, traits> & stream, const Size& size )
|
|
|
|
{
|
|
|
|
return stream << size.Width() << 'x' << size.Height();
|
|
|
|
}
|
|
|
|
|
2012-08-13 22:51:30 +02:00
|
|
|
// Range
|
2007-04-11 19:12:02 +00:00
|
|
|
|
2007-04-25 14:21:13 +00:00
|
|
|
#define RANGE_MAX LONG_MAX
|
2007-04-11 19:12:02 +00:00
|
|
|
|
2012-10-11 15:14:35 +01:00
|
|
|
class SAL_WARN_UNUSED Range : public Pair
|
2007-04-11 19:12:02 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
Range();
|
|
|
|
Range( long nMin, long nMax );
|
|
|
|
|
|
|
|
long Min() const { return nA; }
|
|
|
|
long Max() const { return nB; }
|
|
|
|
long Len() const { return nB - nA + 1; }
|
|
|
|
|
|
|
|
long& Min() { return nA; }
|
|
|
|
long& Max() { return nB; }
|
|
|
|
|
2013-06-29 23:57:38 -05:00
|
|
|
bool IsInside( long nIs ) const;
|
2007-04-11 19:12:02 +00:00
|
|
|
|
|
|
|
void Justify();
|
|
|
|
};
|
|
|
|
|
|
|
|
inline Range::Range()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Range::Range( long nMin, long nMax ) : Pair( nMin, nMax )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-06-29 23:57:38 -05:00
|
|
|
inline bool Range::IsInside( long nIs ) const
|
2007-04-11 19:12:02 +00:00
|
|
|
{
|
|
|
|
return ((nA <= nIs) && (nIs <= nB ));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void Range::Justify()
|
|
|
|
{
|
|
|
|
if ( nA > nB )
|
|
|
|
{
|
|
|
|
long nHelp = nA;
|
|
|
|
nA = nB;
|
|
|
|
nB = nHelp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-21 17:52:00 +01:00
|
|
|
template< typename charT, typename traits >
|
|
|
|
inline std::basic_ostream<charT, traits> & operator <<(
|
|
|
|
std::basic_ostream<charT, traits> & stream, const Range& range )
|
|
|
|
{
|
|
|
|
return stream << range.Min() << '-' << range.Max();
|
|
|
|
}
|
|
|
|
|
2012-08-13 22:51:30 +02:00
|
|
|
// Selection
|
2007-04-11 19:12:02 +00:00
|
|
|
|
2007-04-25 14:21:13 +00:00
|
|
|
#define SELECTION_MIN LONG_MIN
|
|
|
|
#define SELECTION_MAX LONG_MAX
|
2007-04-11 19:12:02 +00:00
|
|
|
|
2012-10-11 15:14:35 +01:00
|
|
|
class SAL_WARN_UNUSED Selection : public Pair
|
2007-04-11 19:12:02 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
Selection();
|
|
|
|
Selection( long nPos );
|
|
|
|
Selection( long nMin, long nMax );
|
|
|
|
|
|
|
|
long Min() const { return nA; }
|
|
|
|
long Max() const { return nB; }
|
|
|
|
long Len() const { return nB - nA; }
|
|
|
|
|
|
|
|
long& Min() { return nA; }
|
|
|
|
long& Max() { return nB; }
|
|
|
|
|
2013-06-29 23:57:38 -05:00
|
|
|
bool IsInside( long nIs ) const;
|
2007-04-11 19:12:02 +00:00
|
|
|
|
|
|
|
void Justify();
|
|
|
|
|
2013-06-29 23:57:38 -05:00
|
|
|
bool operator !() const { return !Len(); }
|
2007-04-11 19:12:02 +00:00
|
|
|
|
2012-12-13 13:39:18 +02:00
|
|
|
long getMin() const { return Min(); }
|
|
|
|
long getMax() const { return Max(); }
|
|
|
|
void setMin(long nMin) { Min() = nMin; }
|
|
|
|
void setMax(long nMax) { Max() = nMax; }
|
2007-04-11 19:12:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
inline Selection::Selection()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Selection::Selection( long nPos ) : Pair( nPos, nPos )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Selection::Selection( long nMin, long nMax ) :
|
|
|
|
Pair( nMin, nMax )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-06-29 23:57:38 -05:00
|
|
|
inline bool Selection::IsInside( long nIs ) const
|
2007-04-11 19:12:02 +00:00
|
|
|
{
|
|
|
|
return ((nA <= nIs) && (nIs < nB ));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void Selection::Justify()
|
|
|
|
{
|
|
|
|
if ( nA > nB )
|
|
|
|
{
|
|
|
|
long nHelp = nA;
|
|
|
|
nA = nB;
|
|
|
|
nB = nHelp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-21 17:52:00 +01:00
|
|
|
template< typename charT, typename traits >
|
|
|
|
inline std::basic_ostream<charT, traits> & operator <<(
|
|
|
|
std::basic_ostream<charT, traits> & stream, const Selection& selection )
|
|
|
|
{
|
|
|
|
return stream << selection.Min() << '-' << selection.Max();
|
|
|
|
}
|
2012-08-13 22:51:30 +02:00
|
|
|
// Rectangle
|
2007-04-11 19:12:02 +00:00
|
|
|
|
|
|
|
#define RECT_EMPTY ((short)-32767)
|
2014-04-18 20:57:27 +02:00
|
|
|
#define RECT_MAX LONG_MAX
|
|
|
|
#define RECT_MIN LONG_MIN
|
2007-04-11 19:12:02 +00:00
|
|
|
|
2012-10-11 15:14:35 +01:00
|
|
|
class TOOLS_DLLPUBLIC SAL_WARN_UNUSED Rectangle
|
2007-04-11 19:12:02 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
Rectangle();
|
|
|
|
Rectangle( const Point& rLT, const Point& rRB );
|
|
|
|
Rectangle( long nLeft, long nTop,
|
|
|
|
long nRight, long nBottom );
|
|
|
|
Rectangle( const Point& rLT, const Size& rSize );
|
|
|
|
|
|
|
|
long Left() const { return nLeft; }
|
|
|
|
long Right() const { return nRight; }
|
|
|
|
long Top() const { return nTop; }
|
|
|
|
long Bottom() const { return nBottom; }
|
|
|
|
|
|
|
|
long& Left() { return nLeft; }
|
|
|
|
long& Right() { return nRight; }
|
|
|
|
long& Top() { return nTop; }
|
|
|
|
long& Bottom() { return nBottom; }
|
|
|
|
|
2012-12-13 13:36:57 +02:00
|
|
|
inline Point TopLeft() const;
|
|
|
|
inline Point TopRight() const;
|
|
|
|
inline Point TopCenter() const;
|
|
|
|
inline Point BottomLeft() const;
|
|
|
|
inline Point BottomRight() const;
|
|
|
|
inline Point BottomCenter() const;
|
|
|
|
inline Point LeftCenter() const;
|
|
|
|
inline Point RightCenter() const;
|
|
|
|
inline Point Center() const;
|
|
|
|
|
|
|
|
inline void Move( long nHorzMove, long nVertMove );
|
2010-03-03 14:16:02 +01:00
|
|
|
inline void Transpose();
|
2007-04-11 19:12:02 +00:00
|
|
|
inline void SetPos( const Point& rPoint );
|
|
|
|
void SetSize( const Size& rSize );
|
|
|
|
inline Size GetSize() const;
|
|
|
|
|
2012-12-13 13:36:57 +02:00
|
|
|
inline long GetWidth() const;
|
|
|
|
inline long GetHeight() const;
|
2007-04-11 19:12:02 +00:00
|
|
|
|
|
|
|
Rectangle& Union( const Rectangle& rRect );
|
|
|
|
Rectangle& Intersection( const Rectangle& rRect );
|
2012-12-13 13:36:57 +02:00
|
|
|
inline Rectangle GetUnion( const Rectangle& rRect ) const;
|
|
|
|
inline Rectangle GetIntersection( const Rectangle& rRect ) const;
|
2007-04-11 19:12:02 +00:00
|
|
|
|
|
|
|
void Justify();
|
|
|
|
|
2013-06-29 23:57:38 -05:00
|
|
|
bool IsInside( const Point& rPOINT ) const;
|
|
|
|
bool IsInside( const Rectangle& rRect ) const;
|
|
|
|
bool IsOver( const Rectangle& rRect ) const;
|
2007-04-11 19:12:02 +00:00
|
|
|
|
|
|
|
void SetEmpty() { nRight = nBottom = RECT_EMPTY; }
|
2013-06-29 23:57:38 -05:00
|
|
|
inline bool IsEmpty() const;
|
2007-04-11 19:12:02 +00:00
|
|
|
|
2013-06-29 23:57:38 -05:00
|
|
|
inline bool operator == ( const Rectangle& rRect ) const;
|
|
|
|
inline bool operator != ( const Rectangle& rRect ) const;
|
2007-04-11 19:12:02 +00:00
|
|
|
|
2012-12-13 13:36:57 +02:00
|
|
|
inline Rectangle& operator += ( const Point& rPt );
|
|
|
|
inline Rectangle& operator -= ( const Point& rPt );
|
2007-04-11 19:12:02 +00:00
|
|
|
|
|
|
|
friend inline Rectangle operator + ( const Rectangle& rRect, const Point& rPt );
|
|
|
|
friend inline Rectangle operator - ( const Rectangle& rRect, const Point& rPt );
|
|
|
|
|
2014-01-30 13:46:42 +02:00
|
|
|
TOOLS_DLLPUBLIC friend SvStream& ReadRectangle( SvStream& rIStream, Rectangle& rRect );
|
2014-01-14 13:52:54 +02:00
|
|
|
TOOLS_DLLPUBLIC friend SvStream& WriteRectangle( SvStream& rOStream, const Rectangle& rRect );
|
2007-04-11 19:12:02 +00:00
|
|
|
|
|
|
|
// ONE
|
|
|
|
long getX() const { return nLeft; }
|
|
|
|
long getY() const { return nTop; }
|
|
|
|
long getWidth() const { return nRight - nLeft; }
|
|
|
|
long getHeight() const { return nBottom - nTop; }
|
|
|
|
void setX( long n ) { nRight += n-nLeft; nLeft = n; }
|
|
|
|
void setY( long n ) { nBottom += n-nTop; nTop = n; }
|
|
|
|
void setWidth( long n ) { nRight = nLeft + n; }
|
|
|
|
void setHeight( long n ) { nBottom = nTop + n; }
|
2012-10-28 23:23:53 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
long nLeft;
|
|
|
|
long nTop;
|
|
|
|
long nRight;
|
|
|
|
long nBottom;
|
2007-04-11 19:12:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
inline Rectangle::Rectangle()
|
|
|
|
{
|
|
|
|
nLeft = nTop = 0;
|
|
|
|
nRight = nBottom = RECT_EMPTY;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Rectangle::Rectangle( const Point& rLT, const Point& rRB )
|
|
|
|
{
|
|
|
|
nLeft = rLT.X();
|
|
|
|
nTop = rLT.Y();
|
|
|
|
nRight = rRB.X();
|
|
|
|
nBottom = rRB.Y();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Rectangle::Rectangle( long _nLeft, long _nTop,
|
|
|
|
long _nRight, long _nBottom )
|
|
|
|
{
|
|
|
|
nLeft = _nLeft;
|
|
|
|
nTop = _nTop;
|
|
|
|
nRight = _nRight;
|
|
|
|
nBottom = _nBottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Rectangle::Rectangle( const Point& rLT, const Size& rSize )
|
|
|
|
{
|
|
|
|
nLeft = rLT.X();
|
|
|
|
nTop = rLT.Y();
|
|
|
|
nRight = rSize.Width() ? nLeft+rSize.Width()-1 : RECT_EMPTY;
|
|
|
|
nBottom = rSize.Height() ? nTop+rSize.Height()-1 : RECT_EMPTY;
|
|
|
|
}
|
|
|
|
|
2013-06-29 23:57:38 -05:00
|
|
|
inline bool Rectangle::IsEmpty() const
|
2007-04-11 19:12:02 +00:00
|
|
|
{
|
|
|
|
return ((nRight == RECT_EMPTY) || (nBottom == RECT_EMPTY));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Point Rectangle::TopLeft() const
|
|
|
|
{
|
|
|
|
return Point( nLeft, nTop );
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Point Rectangle::TopRight() const
|
|
|
|
{
|
|
|
|
return Point( (nRight == RECT_EMPTY) ? nLeft : nRight, nTop );
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Point Rectangle::BottomLeft() const
|
|
|
|
{
|
|
|
|
return Point( nLeft, (nBottom == RECT_EMPTY) ? nTop : nBottom );
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Point Rectangle::BottomRight() const
|
|
|
|
{
|
|
|
|
return Point( (nRight == RECT_EMPTY) ? nLeft : nRight,
|
|
|
|
(nBottom == RECT_EMPTY) ? nTop : nBottom );
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Point Rectangle::TopCenter() const
|
|
|
|
{
|
|
|
|
if ( IsEmpty() )
|
|
|
|
return Point( nLeft, nTop );
|
|
|
|
else
|
2013-04-11 00:21:40 -03:00
|
|
|
return Point( std::min( nLeft, nRight ) + std::abs( (nRight - nLeft)/2 ),
|
|
|
|
std::min( nTop, nBottom) );
|
2007-04-11 19:12:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline Point Rectangle::BottomCenter() const
|
|
|
|
{
|
|
|
|
if ( IsEmpty() )
|
|
|
|
return Point( nLeft, nTop );
|
|
|
|
else
|
2013-04-11 00:21:40 -03:00
|
|
|
return Point( std::min( nLeft, nRight ) + std::abs( (nRight - nLeft)/2 ),
|
|
|
|
std::max( nTop, nBottom) );
|
2007-04-11 19:12:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline Point Rectangle::LeftCenter() const
|
|
|
|
{
|
|
|
|
if ( IsEmpty() )
|
|
|
|
return Point( nLeft, nTop );
|
|
|
|
else
|
2013-04-11 00:21:40 -03:00
|
|
|
return Point( std::min( nLeft, nRight ), nTop + (nBottom - nTop)/2 );
|
2007-04-11 19:12:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline Point Rectangle::RightCenter() const
|
|
|
|
{
|
|
|
|
if ( IsEmpty() )
|
|
|
|
return Point( nLeft, nTop );
|
|
|
|
else
|
2013-04-11 00:21:40 -03:00
|
|
|
return Point( std::max( nLeft, nRight ), nTop + (nBottom - nTop)/2 );
|
2007-04-11 19:12:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline Point Rectangle::Center() const
|
|
|
|
{
|
|
|
|
if ( IsEmpty() )
|
|
|
|
return Point( nLeft, nTop );
|
|
|
|
else
|
|
|
|
return Point( nLeft+(nRight-nLeft)/2 , nTop+(nBottom-nTop)/2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void Rectangle::Move( long nHorzMove, long nVertMove )
|
|
|
|
{
|
|
|
|
nLeft += nHorzMove;
|
|
|
|
nTop += nVertMove;
|
|
|
|
if ( nRight != RECT_EMPTY )
|
|
|
|
nRight += nHorzMove;
|
|
|
|
if ( nBottom != RECT_EMPTY )
|
|
|
|
nBottom += nVertMove;
|
|
|
|
}
|
|
|
|
|
2010-03-03 14:16:02 +01:00
|
|
|
void Rectangle::Transpose()
|
|
|
|
{
|
|
|
|
if ( !IsEmpty() )
|
|
|
|
{
|
|
|
|
long swap( nLeft );
|
|
|
|
nLeft = nTop;
|
|
|
|
nTop = swap;
|
|
|
|
|
|
|
|
swap = nRight;
|
|
|
|
nRight = nBottom;
|
|
|
|
nBottom = swap;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-11 19:12:02 +00:00
|
|
|
inline void Rectangle::SetPos( const Point& rPoint )
|
|
|
|
{
|
|
|
|
if ( nRight != RECT_EMPTY )
|
|
|
|
nRight += rPoint.X() - nLeft;
|
|
|
|
if ( nBottom != RECT_EMPTY )
|
|
|
|
nBottom += rPoint.Y() - nTop;
|
|
|
|
nLeft = rPoint.X();
|
|
|
|
nTop = rPoint.Y();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline long Rectangle::GetWidth() const
|
|
|
|
{
|
|
|
|
long n;
|
|
|
|
if ( nRight == RECT_EMPTY )
|
|
|
|
n = 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
n = nRight - nLeft;
|
|
|
|
if( n < 0 )
|
|
|
|
n--;
|
|
|
|
else
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline long Rectangle::GetHeight() const
|
|
|
|
{
|
|
|
|
long n;
|
|
|
|
if ( nBottom == RECT_EMPTY )
|
|
|
|
n = 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
n = nBottom - nTop;
|
|
|
|
if ( n < 0 )
|
|
|
|
n--;
|
|
|
|
else
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Size Rectangle::GetSize() const
|
|
|
|
{
|
|
|
|
return Size( GetWidth(), GetHeight() );
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Rectangle Rectangle::GetUnion( const Rectangle& rRect ) const
|
|
|
|
{
|
|
|
|
Rectangle aTmpRect( *this );
|
|
|
|
return aTmpRect.Union( rRect );
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Rectangle Rectangle::GetIntersection( const Rectangle& rRect ) const
|
|
|
|
{
|
|
|
|
Rectangle aTmpRect( *this );
|
|
|
|
return aTmpRect.Intersection( rRect );
|
|
|
|
}
|
|
|
|
|
2013-06-29 23:57:38 -05:00
|
|
|
inline bool Rectangle::operator == ( const Rectangle& rRect ) const
|
2007-04-11 19:12:02 +00:00
|
|
|
{
|
|
|
|
return ((nLeft == rRect.nLeft ) &&
|
|
|
|
(nTop == rRect.nTop ) &&
|
|
|
|
(nRight == rRect.nRight ) &&
|
|
|
|
(nBottom == rRect.nBottom ));
|
|
|
|
}
|
|
|
|
|
2013-06-29 23:57:38 -05:00
|
|
|
inline bool Rectangle::operator != ( const Rectangle& rRect ) const
|
2007-04-11 19:12:02 +00:00
|
|
|
{
|
|
|
|
return ((nLeft != rRect.nLeft ) ||
|
|
|
|
(nTop != rRect.nTop ) ||
|
|
|
|
(nRight != rRect.nRight ) ||
|
|
|
|
(nBottom != rRect.nBottom ));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Rectangle& Rectangle::operator +=( const Point& rPt )
|
|
|
|
{
|
|
|
|
nLeft += rPt.X();
|
|
|
|
nTop += rPt.Y();
|
|
|
|
if ( nRight != RECT_EMPTY )
|
|
|
|
nRight += rPt.X();
|
|
|
|
if ( nBottom != RECT_EMPTY )
|
|
|
|
nBottom += rPt.Y();
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Rectangle& Rectangle::operator -= ( const Point& rPt )
|
|
|
|
{
|
|
|
|
nLeft -= rPt.X();
|
|
|
|
nTop -= rPt.Y();
|
|
|
|
if ( nRight != RECT_EMPTY )
|
|
|
|
nRight -= rPt.X();
|
|
|
|
if ( nBottom != RECT_EMPTY )
|
|
|
|
nBottom -= rPt.Y();
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Rectangle operator + ( const Rectangle& rRect, const Point& rPt )
|
|
|
|
{
|
|
|
|
Rectangle aRect( rRect.nLeft + rPt.X(), rRect.nTop + rPt.Y(),
|
|
|
|
(rRect.nRight == RECT_EMPTY) ? RECT_EMPTY : rRect.nRight + rPt.X(),
|
|
|
|
(rRect.nBottom == RECT_EMPTY) ? RECT_EMPTY : rRect.nBottom + rPt.Y() );
|
|
|
|
return aRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Rectangle operator - ( const Rectangle& rRect, const Point& rPt )
|
|
|
|
{
|
|
|
|
Rectangle aRect( rRect.nLeft - rPt.X(),
|
|
|
|
rRect.nTop - rPt.Y(),
|
|
|
|
(rRect.nRight == RECT_EMPTY) ? RECT_EMPTY : rRect.nRight - rPt.X(),
|
|
|
|
(rRect.nBottom == RECT_EMPTY) ? RECT_EMPTY : rRect.nBottom - rPt.Y() );
|
|
|
|
return aRect;
|
|
|
|
}
|
|
|
|
|
2012-11-21 17:52:00 +01:00
|
|
|
template< typename charT, typename traits >
|
|
|
|
inline std::basic_ostream<charT, traits> & operator <<(
|
|
|
|
std::basic_ostream<charT, traits> & stream, const Rectangle& rectangle )
|
|
|
|
{
|
2013-03-25 12:38:24 +02:00
|
|
|
if (rectangle.IsEmpty())
|
|
|
|
return stream << "EMPTY";
|
|
|
|
else
|
|
|
|
return stream << rectangle.getWidth() << 'x' << rectangle.getHeight()
|
|
|
|
<< "@(" << rectangle.getX() << ',' << rectangle.getY() << ")";
|
2012-11-21 17:52:00 +01:00
|
|
|
}
|
|
|
|
|
2012-08-13 23:14:08 +02:00
|
|
|
#endif
|
2010-10-14 08:27:31 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|