245 lines
7.6 KiB
C++
245 lines
7.6 KiB
C++
/*******************************************************************************
|
|
This file is Part of the ZEngine Library for SDL Game Development.
|
|
Copyright (C) 2002 ConceptOfZero.net
|
|
|
|
Licensed under the BSD License, see licensing.txt.
|
|
|
|
The maintainer of this library is James Turk (jturk@conceptofzero.net)
|
|
and the home of this Library is http://www.conceptofzero.net/
|
|
*******************************************************************************/
|
|
|
|
/*!
|
|
\par File Header:
|
|
File: ZE_ZRect.h <br>
|
|
Description: Header file for core ZEngine Rectangle Object. <br>
|
|
Author(s): James Turk <br>
|
|
$Id: ZE_ZRect.h,v 1.1 2002/11/21 05:41:11 cozman Exp $<br>
|
|
|
|
\file ZE_ZRect.h
|
|
\brief Definition file for ZRect.
|
|
|
|
Definition file for ZRect, the Rectangle class for ZEngine.
|
|
**/
|
|
|
|
#ifndef __ze_zrect_h__
|
|
#define __ze_zrect_h__
|
|
|
|
#include "ZE_ZObject.h" //included even though ZRect isn't derived (to obtain all other needed headers)
|
|
|
|
namespace ZE
|
|
{
|
|
|
|
/*!
|
|
\brief ZEngine class for simplified rectangle use.
|
|
|
|
ZRect Rectangle class, used to define a rectangular area or perform operations on the defined area.
|
|
**/
|
|
class ZRect
|
|
{
|
|
private:
|
|
//! X Position of top left corner of rectangle.
|
|
int mX;
|
|
//! Y Position of top left corner of rectangle.
|
|
int mY;
|
|
//! Width of Rectangle.
|
|
int mWidth;
|
|
//! Height of Rectangle.
|
|
int mHeight;
|
|
|
|
public:
|
|
|
|
/*!
|
|
\brief Default constructor for ZRect.
|
|
|
|
Default constructor, initializes all values to zero.
|
|
**/
|
|
ZRect();
|
|
|
|
/*!
|
|
\brief Constructor for ZRect that takes inital values.
|
|
|
|
Constructor for ZRect that takes inital values for all four members.
|
|
\param x Value for x position.
|
|
\param y Value for y position.
|
|
\param width Value for width.
|
|
\param height Value for height.
|
|
**/
|
|
ZRect(int x, int y, int width, int height);
|
|
|
|
/*!
|
|
\brief Copy constructor for ZRect.
|
|
|
|
Takes a ZRect and constructs a new identical rectangle.
|
|
\param rhs Rectangle to construct from.
|
|
**/
|
|
ZRect(const ZRect &rhs);
|
|
|
|
/*!
|
|
\brief Overload for = operator with ZRect.
|
|
|
|
Copies all values from one ZRect into another.
|
|
\param rhs Rectangle to copy values from.
|
|
\return New value of the ZRect.
|
|
**/
|
|
const ZRect& operator=(const ZRect &rhs);
|
|
|
|
/*!
|
|
\brief Overload for < operator with ZRect, based upon location then size.
|
|
|
|
Rectangles are sorted by y value, followed by x value, if they start at the same place,
|
|
the smaller of the two is deemed less than the other.
|
|
\param rhs Rectangle to compare.
|
|
\return True if this rectangle is smaller than the rhs rectangle, false otherwise.
|
|
**/
|
|
bool operator<(const ZRect &rhs) const;
|
|
|
|
/*!
|
|
\brief Changes the location of the rectangle.
|
|
|
|
Changes the current x,y position of the rectangle.
|
|
\param x New x position for rectangle.
|
|
\param y New y position for rectangle.
|
|
**/
|
|
void Move(int x, int y);
|
|
|
|
/*!
|
|
\brief Changes the location of the rectangle based upon the current location.
|
|
|
|
Changes the current x,y position of the rectangle relative to the current location.
|
|
\param xMove Offset for new x position from current.
|
|
\param yMove Offset for new y position from current.
|
|
**/
|
|
void MoveRel(int xMove, int yMove);
|
|
|
|
/*!
|
|
\brief Resize rectangle.
|
|
|
|
Changes the current width and height of the rectangle.
|
|
\param width New width for rectangle.
|
|
\param height New height for rectangle.
|
|
**/
|
|
void Resize(int width, int height);
|
|
|
|
/*!
|
|
\brief Grows or shrinks current rectangle.
|
|
|
|
Changes the current width and height of the rectangle based upon current values.
|
|
\param widthChange Amount to add or subtract from width.
|
|
\param heightChange Amount to add or subtract from height.
|
|
**/
|
|
void ResizeRel(int widthChange, int heightChange);
|
|
|
|
/*!
|
|
\brief Check if one ZRect intersects another.
|
|
|
|
Checks for overlap and returns boolean value based on if overlap exists.
|
|
\param rect Rectangle to check for intersection with.
|
|
\return True if intersection occured, false otherwise.
|
|
**/
|
|
bool Intersects(const ZRect &rect) const;
|
|
|
|
/*!
|
|
\brief Check if a rectangle contains a given point.
|
|
|
|
Checks point against boundaries of rectangle and returns result.
|
|
\param x X value of point to check.
|
|
\param y Y value of poitn to check.
|
|
\return Boolean variable, true if point is inside rectangle, false otherwise.
|
|
**/
|
|
bool Contains(int x, int y) const;
|
|
|
|
/*!
|
|
\brief Check if a rectangle contains a given point.
|
|
|
|
Checks point against boundaries of rectangle and returns result.
|
|
\param rect Rectangle to check for point.
|
|
\return Boolean variable, true if point is inside rectangle, false otherwise.
|
|
**/
|
|
bool Contains(const ZRect &rect) const;
|
|
|
|
/*!
|
|
\brief Finds intersection of two rectangles.
|
|
|
|
Checks for intersection, and returns rectangle where the two rectangles intersect.
|
|
\param rect Rectangle to check intersection with.
|
|
\return ZRect describing intersection area.
|
|
**/
|
|
ZRect Intersection(const ZRect &rect) const;
|
|
|
|
/*!
|
|
\brief Returns an SDL_Rect representing the rectangle.
|
|
|
|
Makes a SDL_Rect representing the rectangle, for use where functions require an SDL_Rect.
|
|
\return SDL_Rect representing the ZRect.
|
|
**/
|
|
SDL_Rect SDLrect() const;
|
|
|
|
/*!
|
|
\brief Returns X Location.
|
|
|
|
Access private X location member.
|
|
\return Value of mX.
|
|
**/
|
|
int X() const;
|
|
|
|
/*!
|
|
\brief Returns Y Location.
|
|
|
|
Access private Y location member.
|
|
\return Value of mY.
|
|
**/
|
|
int Y() const;
|
|
|
|
/*!
|
|
\brief Return position of left side.
|
|
|
|
Find X position of left side of rectangle.
|
|
\return X position of left side.
|
|
**/
|
|
int Left() const;
|
|
|
|
/*!
|
|
\brief Return position of right side.
|
|
|
|
Find X position of right side of rectangle.
|
|
\return X position of right side.
|
|
**/
|
|
int Right() const;
|
|
|
|
/*!
|
|
\brief Return position of top side.
|
|
|
|
Find Y position of top side of rectangle.
|
|
\return Y position of top side.
|
|
**/
|
|
int Top() const;
|
|
|
|
/*!
|
|
\brief Return position of bottom side.
|
|
|
|
Find Y position of left side of rectangle.
|
|
\return Y position of bottom side.
|
|
**/
|
|
int Bottom() const;
|
|
|
|
/*!
|
|
\brief Returns Width.
|
|
|
|
Access private width member.
|
|
\return Value of mWidth.
|
|
**/
|
|
int Width() const;
|
|
|
|
/*!
|
|
\brief Returns Height.
|
|
|
|
Access private height member.
|
|
\return Value of mHeight.
|
|
**/
|
|
int Height() const;
|
|
};
|
|
|
|
} //namspace ZE
|
|
|
|
#endif //__ze_zrect_h__
|