2021-03-27 17:08:06 +01:00
|
|
|
/* Copyright (C) 2021 Wildfire Games.
|
2009-04-18 19:00:33 +02:00
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 0 A.D. 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2021-03-30 23:14:36 +02:00
|
|
|
#ifndef INCLUDED_RECT
|
|
|
|
#define INCLUDED_RECT
|
2004-05-22 01:46:16 +02:00
|
|
|
|
2021-03-27 17:08:06 +01:00
|
|
|
class CSize2D;
|
2021-03-28 23:55:13 +02:00
|
|
|
class CVector2D;
|
2004-05-29 05:53:12 +02:00
|
|
|
|
2004-05-22 01:46:16 +02:00
|
|
|
|
2004-05-29 05:53:12 +02:00
|
|
|
/**
|
2005-04-07 06:29:07 +02:00
|
|
|
* Rectangle class used for screen rectangles. It's very similar to the MS
|
2004-09-02 05:05:16 +02:00
|
|
|
* CRect, but with FLOATS because it's meant to be used with OpenGL which
|
|
|
|
* takes float values.
|
2004-05-29 05:53:12 +02:00
|
|
|
*/
|
|
|
|
class CRect
|
2004-05-22 01:46:16 +02:00
|
|
|
{
|
2004-05-29 05:53:12 +02:00
|
|
|
public:
|
|
|
|
CRect();
|
2021-03-28 23:55:13 +02:00
|
|
|
CRect(const CVector2D& pos);
|
|
|
|
CRect(const CSize2D& size);
|
|
|
|
CRect(const CVector2D& upperleft, const CVector2D& bottomright);
|
|
|
|
CRect(const CVector2D& pos, const CSize2D& size);
|
2009-12-03 21:17:22 +01:00
|
|
|
CRect(const float l, const float t, const float r, const float b);
|
2019-07-09 02:18:48 +02:00
|
|
|
CRect(const CRect&);
|
2004-05-22 01:46:16 +02:00
|
|
|
|
2019-04-22 23:53:11 +02:00
|
|
|
CRect& operator=(const CRect& a);
|
|
|
|
bool operator==(const CRect& a) const;
|
|
|
|
bool operator!=(const CRect& a) const;
|
|
|
|
CRect operator-() const;
|
|
|
|
CRect operator+() const;
|
|
|
|
|
|
|
|
CRect operator+(const CRect& a) const;
|
2021-03-28 23:55:13 +02:00
|
|
|
CRect operator+(const CVector2D& a) const;
|
2021-03-27 17:08:06 +01:00
|
|
|
CRect operator+(const CSize2D& a) const;
|
2019-04-22 23:53:11 +02:00
|
|
|
CRect operator-(const CRect& a) const;
|
2021-03-28 23:55:13 +02:00
|
|
|
CRect operator-(const CVector2D& a) const;
|
2021-03-27 17:08:06 +01:00
|
|
|
CRect operator-(const CSize2D& a) const;
|
2019-04-22 23:53:11 +02:00
|
|
|
|
|
|
|
void operator+=(const CRect& a);
|
2021-03-28 23:55:13 +02:00
|
|
|
void operator+=(const CVector2D& a);
|
2021-03-27 17:08:06 +01:00
|
|
|
void operator+=(const CSize2D& a);
|
2019-04-22 23:53:11 +02:00
|
|
|
void operator-=(const CRect& a);
|
2021-03-28 23:55:13 +02:00
|
|
|
void operator-=(const CVector2D& a);
|
2021-03-27 17:08:06 +01:00
|
|
|
void operator-=(const CSize2D& a);
|
2004-05-29 05:53:12 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Width of Rectangle
|
|
|
|
*/
|
2004-09-02 05:05:16 +02:00
|
|
|
float GetWidth() const;
|
2016-11-23 12:18:37 +01:00
|
|
|
|
2004-05-29 05:53:12 +02:00
|
|
|
/**
|
|
|
|
* @return Height of Rectangle
|
|
|
|
*/
|
2004-09-02 05:05:16 +02:00
|
|
|
float GetHeight() const;
|
2004-05-29 05:53:12 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Size
|
|
|
|
*/
|
2021-03-27 17:08:06 +01:00
|
|
|
CSize2D GetSize() const;
|
2004-05-29 05:53:12 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Position equivalent to top/left corner
|
|
|
|
*/
|
2021-03-28 23:55:13 +02:00
|
|
|
CVector2D TopLeft() const;
|
2004-05-29 05:53:12 +02:00
|
|
|
|
2011-08-20 19:17:53 +02:00
|
|
|
/**
|
|
|
|
* Get Position equivalent to top/right corner
|
|
|
|
*/
|
2021-03-28 23:55:13 +02:00
|
|
|
CVector2D TopRight() const;
|
2011-08-20 19:17:53 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Position equivalent to bottom/left corner
|
|
|
|
*/
|
2021-03-28 23:55:13 +02:00
|
|
|
CVector2D BottomLeft() const;
|
2011-08-20 19:17:53 +02:00
|
|
|
|
2004-05-29 05:53:12 +02:00
|
|
|
/**
|
|
|
|
* Get Position equivalent to bottom/right corner
|
|
|
|
*/
|
2021-03-28 23:55:13 +02:00
|
|
|
CVector2D BottomRight() const;
|
2016-11-23 12:18:37 +01:00
|
|
|
|
2004-05-29 05:53:12 +02:00
|
|
|
/**
|
|
|
|
* Get Position equivalent to the center of the rectangle
|
|
|
|
*/
|
2021-03-28 23:55:13 +02:00
|
|
|
CVector2D CenterPoint() const;
|
2004-05-29 05:53:12 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Evalutates if point is within the rectangle
|
2021-03-28 23:55:13 +02:00
|
|
|
* @param point CVector2D representing point
|
2004-05-29 05:53:12 +02:00
|
|
|
* @return true if inside.
|
|
|
|
*/
|
2021-03-28 23:55:13 +02:00
|
|
|
bool PointInside(const CVector2D &point) const;
|
2004-05-29 05:53:12 +02:00
|
|
|
|
2004-12-17 17:20:08 +01:00
|
|
|
CRect Scale(float x, float y) const;
|
|
|
|
|
2004-05-29 05:53:12 +02:00
|
|
|
/**
|
2021-03-28 23:55:13 +02:00
|
|
|
* Returning CVector2D representing each corner.
|
2004-05-29 05:53:12 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Dimensions
|
|
|
|
*/
|
2004-09-02 05:05:16 +02:00
|
|
|
float left, top, right, bottom;
|
2004-05-29 05:53:12 +02:00
|
|
|
};
|
|
|
|
|
2021-03-30 23:14:36 +02:00
|
|
|
#endif // INCLUDED_RECT
|