2015-09-25 21:37:19 +02:00
|
|
|
// File: frect.h
|
|
|
|
// Provides: class FRect
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include "fpoint.h"
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FRect
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma pack(push)
|
|
|
|
#pragma pack(1)
|
|
|
|
|
|
|
|
class FRect
|
|
|
|
{
|
|
|
|
public:
|
2016-09-30 04:55:28 +02:00
|
|
|
// Constructors
|
|
|
|
FRect ();
|
|
|
|
FRect (int, int, int, int);
|
|
|
|
FRect (const FPoint&, const FPoint&);
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2016-09-30 04:55:28 +02:00
|
|
|
// Destructor
|
|
|
|
virtual ~FRect();
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
// Overloaded operators
|
|
|
|
FRect& operator = (const FRect&);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
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&);
|
|
|
|
|
|
|
|
// Accessors
|
|
|
|
virtual const char* getClassName();
|
2016-09-25 23:53:48 +02:00
|
|
|
int getX1() const;
|
|
|
|
int getY1() const;
|
|
|
|
int getX2() const;
|
|
|
|
int getY2() const;
|
|
|
|
int getX() const;
|
|
|
|
int getY() const;
|
|
|
|
FPoint getPos() const;
|
2016-09-29 04:29:12 +02:00
|
|
|
FPoint getUpperLeftPos() const;
|
|
|
|
FPoint getUpperRightPos() const;
|
|
|
|
FPoint getLowerLeftPos() const;
|
|
|
|
FPoint getLowerRightPos() const;
|
2016-09-25 23:53:48 +02:00
|
|
|
int getWidth() const;
|
|
|
|
int getHeight() const;
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
// Mutators
|
2016-09-25 23:53:48 +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 (int);
|
|
|
|
void setHeight (int);
|
2016-09-29 04:29:12 +02:00
|
|
|
void setSize (int, int);
|
2016-09-25 23:53:48 +02:00
|
|
|
void setRect (const FRect&);
|
|
|
|
void setRect (int, int, int, int);
|
|
|
|
void setCoordinates (const FPoint&, const FPoint&);
|
|
|
|
void setCoordinates (int, int, int, int);
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
// Inquiry
|
|
|
|
bool isNull() const;
|
|
|
|
|
|
|
|
// Coordinate references
|
|
|
|
short& x1_ref();
|
|
|
|
short& y1_ref();
|
|
|
|
short& x2_ref();
|
|
|
|
short& y2_ref();
|
|
|
|
|
|
|
|
// Methods
|
2016-09-25 23:53:48 +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;
|
2017-03-12 00:29:56 +01:00
|
|
|
FRect combined (const FRect&) const;
|
2016-09-25 23:53:48 +02:00
|
|
|
|
2016-11-02 00:37:58 +01: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
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FRect::FRect (int x, int y, int width, int height)
|
2015-09-20 05:44:50 +02:00
|
|
|
: X1(short(x))
|
|
|
|
, Y1(short(y))
|
2016-09-25 23:53:48 +02:00
|
|
|
, X2(short(x + width - 1))
|
|
|
|
, Y2(short(y + 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
|
|
|
|
{ return FPoint(X1,Y1); }
|
|
|
|
|
2016-09-29 04:29:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FPoint FRect::getUpperLeftPos() const
|
|
|
|
{ return FPoint(X1,Y1); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FPoint FRect::getUpperRightPos() const
|
|
|
|
{ return FPoint(X2,Y1); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FPoint FRect::getLowerLeftPos() const
|
|
|
|
{ return FPoint(X1,Y2); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FPoint FRect::getLowerRightPos() const
|
|
|
|
{ return FPoint(X2,Y2); }
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline int FRect::getWidth() const
|
2016-10-06 23:15:09 +02:00
|
|
|
{ return short(X2 - X1 + 1); }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline int FRect::getHeight() const
|
2016-10-06 23:15:09 +02:00
|
|
|
{ return short(Y2 - Y1 + 1); }
|
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; }
|
|
|
|
|
2017-04-09 20:08:53 +02:00
|
|
|
#endif // FRECT_H
|