Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals

Ars::XRect Class Reference

A representation of a rectangle. More...

#include <xrect.h>

Inheritance diagram for Ars::XRect:

Inheritance graph
[legend]

Public Types

enum  ERelativePosition {
  RELPOS_ABOVE = 1, RELPOS_BELOW = 2, RELPOS_LEFT = 4, RELPOS_RIGHT = 8,
  RELPOS_INSIDE = 16
}

Public Member Functions

 XRect (void)
 The default constructor will initialize all 4 corners to (0, 0).

 XRect (const int ax, const int ay, const int aw, const int ah)
 XRect (const XPoint &p1, const XPoint &p2)
 XRect (const XRect &r)
virtual ~XRect (void)
 Standard Destructor.

int Width (void) const
 The width (along the X axis) of the CRect.

int Height (void) const
 The height (along the Y axis) of the CRect.

XPoint Size () const
 the size

XPoint TopLeft (void) const
 A point representing the Top Left corner of the CRect.

XPoint TopRight (void) const
 A point representing the Top Right corner of the CRect.

XPoint BottomLeft (void) const
 A point representing the Bottom Left corner of the CRect.

XPoint BottomRight (void) const
 A point representing the Bottom Right corner of the CRect.

const int Right (void) const
const int Bottom (void) const
void SetBottom (const int y2)
void SetRight (const int x2)
XPoint Center (void) const
 A point representing the center of the CRect.

 operator SDL_Rect (void)
 operator const SDL_Rect (void) const
XRectoperator= (const XRect &r)
 Assignment operator will copy the values of the other rect.

XRectoperator= (const SDL_Rect &r)
XRect operator+ (const XPoint &p) const
XRect operator- (const XPoint &p) const
XRectGrow (const int iGrowAmount)
const bool Overlaps (const XRect &r)
void ClipTo (const XRect &r)
unsigned int HitTest (const XPoint &p) const
 The HitTest will test to see where a point is in relation to the rect.


Detailed Description

A representation of a rectangle.

Definition at line 55 of file xrect.h.


Member Enumeration Documentation

enum Ars::XRect::ERelativePosition
 

Enumeration values:
RELPOS_ABOVE  The point is above the top of the CRect.
RELPOS_BELOW  The point is below the bottom of the CRect.
RELPOS_LEFT  The point is to the left of the CRect.
RELPOS_RIGHT  The point is to the right of the CRect.
RELPOS_INSIDE  The point lies within the bounds of the CRect.

Definition at line 170 of file xrect.h.

00171         {
00172                 RELPOS_ABOVE = 1, 
00173                 RELPOS_BELOW = 2, 
00174                 RELPOS_LEFT = 4, 
00175                 RELPOS_RIGHT = 8, 
00176                 RELPOS_INSIDE = 16 
00177         };


Constructor & Destructor Documentation

Ars::XRect::XRect void   )  [inline]
 

The default constructor will initialize all 4 corners to (0, 0).

Definition at line 58 of file xrect.h.

Referenced by Ars::XTextBox::Init(), Ars::XScrollBar::Init(), Ars::XListBox::Init(), Ars::XDropDown::Init(), operator+(), operator-(), Ars::XTextBox::SetWindowRect(), Ars::XScrollBar::SetWindowRect(), Ars::XListBox::SetWindowRect(), and Ars::View::wmResize().

00059         {       x = 0;  y = 0;  w = 0;  h = 0;  }  // constructor

Ars::XRect::XRect const int  ax,
const int  ay,
const int  aw,
const int  ah
[inline]
 

Parameters:
left The left edge of the rectangle
top The top edge of the rectangle
right The right edge of the rectangle
bottom The bottom edge of the rectangle

Definition at line 65 of file xrect.h.

00066         {       x = ax; y = ay; w = aw; h = ah; }  // constructor

Ars::XRect::XRect const XPoint p1,
const XPoint p2
[inline]
 

Create a CRect using a pair of CPoints that represent the Top-Left, and Bottom-Right corners

Parameters:
p1 Top left corner
p2 Bottom right corner

Definition at line 71 of file xrect.h.

References Ars::XPoint::x, and Ars::XPoint::y.

00072         {
00073                 x = min( p2.x , p1.x ); y = min( p2.y , p1.y );
00074                 w = max( p2.x , p1.x ) - x;
00075                 h = max( p2.y , p1.y ) - y;
00076         }  // constructor

Ars::XRect::XRect const XRect r  )  [inline]
 

Copy constructor

Parameters:
r A CRect that thie new CRect will be copied from

Definition at line 80 of file xrect.h.

00081         {       x = r.x;        y = r.y;        w = r.w;        h = r.h;        }  // constructor

virtual Ars::XRect::~XRect void   )  [inline, virtual]
 

Standard Destructor.

Definition at line 84 of file xrect.h.

00084 { }


Member Function Documentation

const int Ars::XRect::Bottom void   )  const [inline]
 

Definition at line 108 of file xrect.h.

References Height().

Referenced by Ars::HPaint::_TextOut(), Ars::Graf::ButtonImg(), ClipTo(), Ars::XTextBox::Draw(), Ars::XListBox::Draw(), Ars::XEditBox::Draw(), Ars::XBox::Draw(), Ars::XBox::DrawFocus(), Ars::XBox::DrawRaised(), Ars::HPaint::DrawRect(), Ars::XBox::DrawSunken(), Ars::Form::FindWindowParent(), Ars::XScrollBar::Init(), Ars::Thing::Init(), and Ars::XScrollBar::SetWindowRect().

00108 {       return y + Height();    }

XPoint Ars::XRect::BottomLeft void   )  const [inline]
 

A point representing the Bottom Left corner of the CRect.

Definition at line 102 of file xrect.h.

Referenced by Ars::XCheckBox::Draw(), Ars::XBox::DrawRaised(), Ars::XBox::DrawSunken(), and Overlaps().

00102 { return XPoint( x , y + h ); }

XPoint Ars::XRect::BottomRight void   )  const [inline]
 

A point representing the Bottom Right corner of the CRect.

Definition at line 105 of file xrect.h.

Referenced by Ars::XCheckBox::Draw(), Ars::XBox::DrawRaised(), Ars::XBox::DrawSunken(), Ars::Window::GetClientRect(), Ars::XScrollBar::Init(), Overlaps(), and Ars::XScrollBar::SetWindowRect().

00105 { return XPoint( x + w , y + h); }

XPoint Ars::XRect::Center void   )  const [inline]
 

A point representing the center of the CRect.

Definition at line 114 of file xrect.h.

References Height(), and Width().

Referenced by Ars::XEditBox::Draw(), and Ars::XButtonImage::Draw().

00114 { return XPoint( x + (Width() >> 1) , y + (Height() >> 1) );    }

void Ars::XRect::ClipTo const XRect r  )  [inline]
 

Clips the CRect to fit in another CRect

Parameters:
r The CRect to clip to

Definition at line 152 of file xrect.h.

References Bottom(), Overlaps(), Right(), SetBottom(), and SetRight().

Referenced by Ars::XTextBox::Draw(), Ars::XListBox::Draw(), Ars::XEditBox::Draw(), and Ars::Window::GetClientRect().

00153         {
00154                 if( Overlaps( r ) )
00155                 {
00156                         if( x < r.x )
00157                                 x = r.x;
00158                         if( Right() > r.Right() )
00159                                 SetRight( r.Right() );
00160         
00161                         if( y < r.y )   
00162                                 y = r.y;
00163                         if( Bottom() > r.Bottom() )
00164                                 SetBottom( r.Bottom() );
00165                 }
00166                 else
00167                         w = h = 0;
00168         }

XRect& Ars::XRect::Grow const int  iGrowAmount  )  [inline]
 

Grow will increase (or decrease) all of the dimensions by the given amount. This means that for a rect 20 wide by 10 tall, Grow(1) will increase the size to 22 wide, 12 tall. (each side is moved out by 1)

Parameters:
iGrowAmount The amount to grow the CRect's dimensions by, negative values can be used to shrink the rect
Returns:
A reference to the object

Definition at line 138 of file xrect.h.

Referenced by Ars::XTextBox::Draw(), Ars::XScrollBar::Draw(), Ars::XProgress::Draw(), Ars::XListBox::Draw(), Ars::XGroupBox::Draw(), Ars::XEditBox::Draw(), Ars::XCheckBox::Draw(), Ars::XButtonImage::Draw(), Ars::XBox::Draw(), Ars::HPaint::DrawRect(), Ars::XEditBox::evMouseButtonDown(), Ars::XEditBox::evMouseMove(), Ars::XDropDown::Init(), Ars::XTextBox::SetWindowRect(), and Ars::XListBox::SetWindowRect().

00138 {       x -= iGrowAmount;       y -= iGrowAmount;       w += 2 * iGrowAmount;   h += 2 * iGrowAmount;   return *this;   }

int Ars::XRect::Height void   )  const [inline]
 

The height (along the Y axis) of the CRect.

Definition at line 90 of file xrect.h.

Referenced by Ars::XListBox::AddItem(), Bottom(), Ars::Graf::ButtonImg(), Center(), Ars::XTextBox::Draw(), Ars::XCheckBox::Draw(), Ars::Window::DrawBG(), Ars::XListBox::evKeyDown(), Ars::XScrollBar::evMouseMove(), Ars::XTextBox::Init(), Ars::XScrollBar::Init(), Ars::XListBox::Init(), Ars::XDropDown::Init(), Ars::XListBox::RemoveItem(), Ars::Graf::SDL_StretchBlt(), Ars::XTextBox::SetWindowRect(), Ars::XScrollBar::SetWindowRect(), Ars::XListBox::SetWindowRect(), Ars::Window::SetWindowRect(), Ars::XTextBox::SetWndText(), Ars::HPaint::TextOutStr(), Ars::View::View(), and Ars::View::wmResize().

00090 { return (short int)h; }

unsigned int Ars::XRect::HitTest const XPoint p  )  const [inline]
 

The HitTest will test to see where a point is in relation to the rect.

Parameters:
p The point to test against the CRect
Returns:
The appropriate values of the ERelativePosition enum are ORed together

Definition at line 182 of file xrect.h.

References RELPOS_ABOVE, RELPOS_BELOW, RELPOS_INSIDE, RELPOS_LEFT, RELPOS_RIGHT, Ars::XPoint::x, and Ars::XPoint::y.

Referenced by Ars::HPaint::_TextOut(), Ars::XScrollBar::Draw(), Ars::XScrollBar::evMouseButtonDown(), Ars::XListBox::evMouseButtonDown(), Ars::XListBox::evMouseButtonUp(), Ars::XEditBox::evMouseMove(), Ars::Window::FindWindow(), Overlaps(), and Ars::Window::RelposInside().

00183         { 
00184                 unsigned int eRelPos = 0;
00185 
00186                 eRelPos |= (p.x < x) ? RELPOS_LEFT : 0;
00187                 eRelPos |= (p.y < y) ? RELPOS_ABOVE: 0;
00188                 eRelPos |= (p.x > (x+w)) ? RELPOS_RIGHT : 0;
00189                 eRelPos |= (p.y > (y+h)) ? RELPOS_BELOW: 0;
00190                 eRelPos |= (p.x >= x && p.x <= (x+w) && p.y >= y && p.y <= (y+h)) ? RELPOS_INSIDE : 0;
00191 
00192                 return eRelPos;
00193         }

Ars::XRect::operator const SDL_Rect void   )  const [inline]
 

Definition at line 119 of file xrect.h.

00119 {       return static_cast<const SDL_Rect>( *this );    }

Ars::XRect::operator SDL_Rect void   )  [inline]
 

Converts the CRect into a SDL style rect

Returns:
An SDL_Rect of the same size

Definition at line 118 of file xrect.h.

00118 {       return static_cast<SDL_Rect>( *this );  }

XRect Ars::XRect::operator+ const XPoint p  )  const [inline]
 

Addition operator to add a CPoint, will offset the CRect

Parameters:
p A point to offset the CRect by

Definition at line 127 of file xrect.h.

References Ars::XPoint::x, XRect(), and Ars::XPoint::y.

00127 {       return XRect( x + p.x , y + p.y , w , y );      }

XRect Ars::XRect::operator- const XPoint p  )  const [inline]
 

Subtraction operator to subtract a CPoint, will offset the CRect

Parameters:
p A point to offset the CRect by

Definition at line 131 of file xrect.h.

References Ars::XPoint::x, XRect(), and Ars::XPoint::y.

00131 {       return XRect( x - p.x , y - p.y , w , y );      }

XRect& Ars::XRect::operator= const SDL_Rect &  r  )  [inline]
 

Definition at line 123 of file xrect.h.

00123 {       x = r.x;        y = r.y;        w = r.w;        h = r.h;        return *this;   }  // assignment operator

XRect& Ars::XRect::operator= const XRect r  )  [inline]
 

Assignment operator will copy the values of the other rect.

Definition at line 122 of file xrect.h.

00122 {       x = r.x;        y = r.y;        w = r.w;        h = r.h;        return *this;   }  // assignment operator

const bool Ars::XRect::Overlaps const XRect r  )  [inline]
 

Tests to see if the two CRects overlap

Parameters:
r The other CRect to test with
Returns:
true if the CRects overlap

Definition at line 143 of file xrect.h.

References BottomLeft(), BottomRight(), HitTest(), RELPOS_INSIDE, TopLeft(), and TopRight().

Referenced by ClipTo(), Ars::XTextBox::Draw(), and Ars::XListBox::Draw().

00144         {
00145                 return (HitTest(r.TopLeft()) == RELPOS_INSIDE || HitTest(r.TopRight()) == RELPOS_INSIDE || HitTest(r.BottomRight()) == RELPOS_INSIDE
00146                          || HitTest(r.BottomLeft()) == RELPOS_INSIDE || r.HitTest(TopLeft()) == RELPOS_INSIDE || r.HitTest(TopRight()) == RELPOS_INSIDE
00147                          || r.HitTest(BottomRight()) == RELPOS_INSIDE || r.HitTest(BottomLeft()) == RELPOS_INSIDE);
00148         }

const int Ars::XRect::Right void   )  const [inline]
 

Definition at line 107 of file xrect.h.

References Width().

Referenced by Ars::HPaint::_TextOut(), Ars::Graf::ButtonImg(), ClipTo(), Ars::XEditBox::Draw(), Ars::XBox::Draw(), Ars::XBox::DrawFocus(), Ars::XBox::DrawRaised(), Ars::HPaint::DrawRect(), Ars::XBox::DrawSunken(), Ars::Form::FindWindowParent(), Ars::XTextBox::Init(), Ars::XScrollBar::Init(), Ars::XListBox::Init(), Ars::XDropDown::Init(), Ars::Thing::Init(), Ars::XTextBox::SetWindowRect(), Ars::XScrollBar::SetWindowRect(), and Ars::XListBox::SetWindowRect().

00107 {       return x + Width();     }

void Ars::XRect::SetBottom const int  y2  )  [inline]
 

Definition at line 110 of file xrect.h.

Referenced by Ars::Graf::ButtonImg(), ClipTo(), Ars::XTextBox::Draw(), Ars::XListBox::Draw(), Ars::XEditBox::Draw(), Ars::XScrollBar::SetWindowRect(), and Ars::View::wmResize().

00110 {       h = abs( y2 - y );      }

void Ars::XRect::SetRight const int  x2  )  [inline]
 

Definition at line 111 of file xrect.h.

Referenced by Ars::Graf::ButtonImg(), ClipTo(), Ars::XEditBox::Draw(), Ars::XCheckBox::Draw(), Ars::XScrollBar::SetWindowRect(), and Ars::View::wmResize().

00111 {       w = abs( x2 - x );      }

XPoint Ars::XRect::Size void   )  const [inline]
 

the size

Reimplemented in Ars::XDropDown.

Definition at line 93 of file xrect.h.

00093 {       return XPoint( w , h ); }

XPoint Ars::XRect::TopLeft void   )  const [inline]
 

A point representing the Top Left corner of the CRect.

Definition at line 96 of file xrect.h.

Referenced by Ars::XScrollBar::Draw(), Ars::XCheckBox::Draw(), Ars::XBox::DrawRaised(), Ars::XBox::DrawSunken(), Ars::Window::GetClientRect(), Ars::XScrollBar::Init(), Overlaps(), Ars::XScrollBar::SetWindowRect(), and Ars::HPaint::TextOutStr().

00096 { return XPoint( x , y ); }

XPoint Ars::XRect::TopRight void   )  const [inline]
 

A point representing the Top Right corner of the CRect.

Definition at line 99 of file xrect.h.

Referenced by Ars::XCheckBox::Draw(), Ars::XBox::DrawRaised(), Ars::XBox::DrawSunken(), and Overlaps().

00099 { return XPoint( x + w, y ); }

int Ars::XRect::Width void   )  const [inline]
 

The width (along the X axis) of the CRect.

Definition at line 87 of file xrect.h.

Referenced by Ars::HPaint::_TextOut(), Ars::Graf::ButtonImg(), Center(), Ars::XTextBox::Draw(), Ars::XListBox::Draw(), Ars::Window::DrawBG(), Ars::XScrollBar::evMouseMove(), Ars::XScrollBar::Init(), Right(), Ars::Graf::SDL_StretchBlt(), Ars::XTextBox::SetWindowRect(), Ars::XScrollBar::SetWindowRect(), Ars::XListBox::SetWindowRect(), Ars::Window::SetWindowRect(), Ars::View::View(), and Ars::View::wmResize().

00087 { return (short int)w; }


The documentation for this class was generated from the following file:
Generated on Fri Dec 5 04:07:02 2003 for Borqueror by doxygen 1.3.3