2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* frect.h - Rectangle with position and size *
|
|
|
|
* *
|
|
|
|
* This file is part of the Final Cut widget toolkit *
|
|
|
|
* *
|
2018-04-16 02:24:37 +02:00
|
|
|
* Copyright 2014-2018 Markus Gans *
|
2017-11-04 07:03:53 +01:00
|
|
|
* *
|
|
|
|
* The Final Cut is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 3 of *
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* The Final Cut is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU Lesser General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public *
|
|
|
|
* License along with this program. If not, see *
|
|
|
|
* <http://www.gnu.org/licenses/>. *
|
|
|
|
***********************************************************************/
|
2017-10-02 07:32:33 +02:00
|
|
|
|
|
|
|
/* Standalone class
|
|
|
|
* ════════════════
|
|
|
|
*
|
|
|
|
* ▕▔▔▔▔▔▔▔▏1 *▕▔▔▔▔▔▔▔▔▏
|
|
|
|
* ▕ FRect ▏- - - -▕ FPoint ▏
|
|
|
|
* ▕▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▏
|
|
|
|
*/
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-04-09 20:08:53 +02:00
|
|
|
#ifndef FRECT_H
|
|
|
|
#define FRECT_H
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-10-31 00:41:59 +01:00
|
|
|
#if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
|
|
|
|
#error "Only <final/final.h> can be included directly."
|
|
|
|
#endif
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
#include <algorithm>
|
2017-09-17 21:32:46 +02:00
|
|
|
#include "final/fpoint.h"
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
namespace finalcut
|
|
|
|
{
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FRect
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma pack(push)
|
|
|
|
#pragma pack(1)
|
|
|
|
|
|
|
|
class FRect
|
|
|
|
{
|
2017-09-11 03:06:02 +02:00
|
|
|
public:
|
|
|
|
// Constructors
|
|
|
|
FRect ();
|
|
|
|
FRect (const FRect&); // copy constructor
|
2018-10-14 06:25:33 +02:00
|
|
|
FRect (int, int, std::size_t, std::size_t);
|
2017-09-11 03:06:02 +02:00
|
|
|
FRect (const FPoint&, const FPoint&);
|
|
|
|
|
|
|
|
// Destructor
|
|
|
|
virtual ~FRect();
|
|
|
|
|
|
|
|
// Overloaded operators
|
|
|
|
FRect& operator = (const FRect&);
|
|
|
|
|
|
|
|
friend FRect operator + (const FRect&, const FPoint&);
|
|
|
|
friend FRect operator - (const FRect&, const FPoint&);
|
|
|
|
friend bool operator == (const FRect&, const FRect&);
|
|
|
|
friend bool operator != (const FRect&, const FRect&);
|
2018-04-16 02:24:37 +02:00
|
|
|
friend std::ostream& operator << (std::ostream&, const FRect&);
|
|
|
|
friend std::istream& operator >> (std::istream&, FRect&);
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Accessors
|
|
|
|
virtual const char* getClassName();
|
2018-10-14 06:25:33 +02:00
|
|
|
int getX1() const;
|
|
|
|
int getY1() const;
|
|
|
|
int getX2() const;
|
|
|
|
int getY2() const;
|
|
|
|
int getX() const;
|
|
|
|
int getY() const;
|
|
|
|
FPoint getPos() const;
|
|
|
|
FPoint getUpperLeftPos() const;
|
|
|
|
FPoint getUpperRightPos() const;
|
|
|
|
FPoint getLowerLeftPos() const;
|
|
|
|
FPoint getLowerRightPos() const;
|
|
|
|
std::size_t getWidth() const;
|
|
|
|
std::size_t getHeight() const;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Mutators
|
2018-10-14 06:25:33 +02:00
|
|
|
void setX1 (int);
|
|
|
|
void setY1 (int);
|
|
|
|
void setX2 (int);
|
|
|
|
void setY2 (int);
|
|
|
|
void setX (int);
|
|
|
|
void setY (int);
|
|
|
|
void setPos (int, int);
|
|
|
|
void setPos (const FPoint&);
|
|
|
|
void setWidth (std::size_t);
|
|
|
|
void setHeight (std::size_t);
|
|
|
|
void setSize (std::size_t, std::size_t);
|
|
|
|
void setRect (const FRect&);
|
|
|
|
void setRect (int, int, std::size_t, std::size_t);
|
|
|
|
void setCoordinates (const FPoint&, const FPoint&);
|
|
|
|
void setCoordinates (int, int, int, int);
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Inquiry
|
2018-10-14 06:25:33 +02:00
|
|
|
bool isNull() const;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Coordinate references
|
2018-10-14 06:25:33 +02:00
|
|
|
short& x1_ref();
|
|
|
|
short& y1_ref();
|
|
|
|
short& x2_ref();
|
|
|
|
short& y2_ref();
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Methods
|
2018-10-14 06:25:33 +02:00
|
|
|
void move (int, int);
|
|
|
|
void move (const FPoint&);
|
|
|
|
bool contains (int, int) const;
|
|
|
|
bool contains (const FPoint&) const;
|
|
|
|
bool contains (const FRect&) const;
|
|
|
|
bool overlap (const FRect&) const;
|
|
|
|
FRect intersect (const FRect&) const;
|
|
|
|
FRect combined (const FRect&) const;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Data Members
|
|
|
|
short X1;
|
|
|
|
short Y1;
|
|
|
|
short X2;
|
|
|
|
short Y2;
|
2015-05-23 13:35:12 +02:00
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
|
|
|
|
// FRect inline functions
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FRect::FRect()
|
2015-09-20 05:44:50 +02:00
|
|
|
: X1(0)
|
|
|
|
, Y1(0)
|
|
|
|
, X2(-1)
|
|
|
|
, Y2(-1)
|
|
|
|
{ }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-08-11 10:50:39 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FRect::FRect (const FRect& r) // copy constructor
|
|
|
|
: X1(r.X1)
|
|
|
|
, Y1(r.Y1)
|
|
|
|
, X2(r.X2)
|
|
|
|
, Y2(r.Y2)
|
|
|
|
{ }
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2018-10-14 06:25:33 +02:00
|
|
|
inline FRect::FRect (int x, int y, std::size_t width, std::size_t height)
|
2015-09-20 05:44:50 +02:00
|
|
|
: X1(short(x))
|
|
|
|
, Y1(short(y))
|
2018-10-14 06:25:33 +02:00
|
|
|
, X2(short(x + short(width) - 1))
|
|
|
|
, Y2(short(y + short(height) - 1))
|
2015-09-20 05:44:50 +02:00
|
|
|
{ }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline const char* FRect::getClassName()
|
|
|
|
{ return "FRect"; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline int FRect::getX1() const
|
|
|
|
{ return X1; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline int FRect::getY1() const
|
|
|
|
{ return Y1; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline int FRect::getX2() const
|
|
|
|
{ return X2; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline int FRect::getY2() const
|
|
|
|
{ return Y2; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline int FRect::getX() const
|
|
|
|
{ return X1; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline int FRect::getY() const
|
|
|
|
{ return Y1; }
|
|
|
|
|
2015-09-27 16:00:13 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FPoint FRect::getPos() const
|
2017-09-11 03:06:02 +02:00
|
|
|
{ return FPoint(X1, Y1); }
|
2015-09-27 16:00:13 +02:00
|
|
|
|
2016-09-29 04:29:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FPoint FRect::getUpperLeftPos() const
|
2017-09-11 03:06:02 +02:00
|
|
|
{ return FPoint(X1, Y1); }
|
2016-09-29 04:29:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FPoint FRect::getUpperRightPos() const
|
2017-09-11 03:06:02 +02:00
|
|
|
{ return FPoint(X2, Y1); }
|
2016-09-29 04:29:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FPoint FRect::getLowerLeftPos() const
|
2017-09-11 03:06:02 +02:00
|
|
|
{ return FPoint(X1, Y2); }
|
2016-09-29 04:29:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FPoint FRect::getLowerRightPos() const
|
2017-09-11 03:06:02 +02:00
|
|
|
{ return FPoint(X2, Y2); }
|
2016-09-29 04:29:12 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2018-10-14 06:25:33 +02:00
|
|
|
inline std::size_t FRect::getWidth() const
|
|
|
|
{
|
|
|
|
short w = X2 - X1 + 1;
|
|
|
|
return ( w < 0 ) ? 0 : std::size_t(w);
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-10-14 06:25:33 +02:00
|
|
|
inline std::size_t FRect::getHeight() const
|
|
|
|
{
|
|
|
|
short h = Y2 - Y1 + 1;
|
|
|
|
return ( h < 0 ) ? 0 : std::size_t(h);
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-09-25 23:53:48 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline short& FRect::x1_ref()
|
|
|
|
{ return X1; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline short& FRect::y1_ref()
|
|
|
|
{ return Y1; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline short& FRect::x2_ref()
|
|
|
|
{ return X2; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline short& FRect::y2_ref()
|
|
|
|
{ return Y2; }
|
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
} // namespace finalcut
|
|
|
|
|
2017-04-09 20:08:53 +02:00
|
|
|
#endif // FRECT_H
|