Back to index

nux  3.0.0
Public Member Functions | Public Attributes
nux::Rect Class Reference

#include <Rect.h>

List of all members.

Public Member Functions

 Rect ()
 Rect (int x_, int y_, int width_, int height_)
 ~Rect ()
 Rect (const Rect &r)
Rectoperator= (const Rect &r)
bool operator== (const Rect &p) const
bool operator!= (const Rect &p) const
bool IsNull () const
bool IsInside (const Point &p) const
Rect Intersect (const Rect &) const
void Expand (int factor_x, int factor_y)
int GetWidth () const
int GetHeight () const
Point GetCenter () const
 Returns a Point at the center of the Rectangle.
Point GetPosition ()
 Returns a Point at the center of the Rectangle.
void SetWidth (int w)
void SetHeight (int h)
void SetX (int px)
void SetY (int py)
void Set (int px, int py, int w, int h)
void SetPosition (int px, int py)
void SetSize (int px, int py)
void OffsetSize (int dw, int dh)
void OffsetPosition (int dx, int dy)
bool IsPointInside (int dx, int dy) const
Rect GetExpand (int dx, int dy) const

Public Attributes

int x
int y
int width
int height

Detailed Description

Definition at line 32 of file Rect.h.


Constructor & Destructor Documentation

Definition at line 30 of file Rect.cpp.

  {
    x = 0;
    y = 0;
    width = 0;
    height = 0;

  }

Here is the caller graph for this function:

nux::Rect::Rect ( int  x_,
int  y_,
int  width_,
int  height_ 
)

Definition at line 39 of file Rect.cpp.

  {
    x = x_;
    y = y_;
    width = Max<int> (0, int (width_) );
    height = Max<int> (0, int (height_) );
  }

Definition at line 47 of file Rect.cpp.

  {

  }
nux::Rect::Rect ( const Rect r)

Definition at line 52 of file Rect.cpp.

  {
    x = r.x;
    y = r.y;
    width = r.width;
    height = r.height;
  }

Member Function Documentation

void nux::Rect::Expand ( int  factor_x,
int  factor_y 
)

Definition at line 157 of file Rect.cpp.

  {
    if (!IsNull() )
    {
      x -= dx;
      y -= dy;
      width  += 2 * dx;
      height += 2 * dy;
    }
  }

Here is the call graph for this function:

Point nux::Rect::GetCenter ( ) const [inline]

Returns a Point at the center of the Rectangle.

Definition at line 65 of file Rect.h.

    {
      return Point (x + width / 2, y + height / 2);
    }
Rect nux::Rect::GetExpand ( int  dx,
int  dy 
) const

Definition at line 169 of file Rect.cpp.

  {
    Rect r = Rect (x - dx, y - dy, width + 2 * dx, height + 2 * dy);

    if (r.IsNull() )
    {
      return Rect (0, 0, 0, 0);
    }

    return r;
  }

Here is the call graph for this function:

int nux::Rect::GetHeight ( ) const [inline]

Definition at line 60 of file Rect.h.

    {
      return height;
    }

Returns a Point at the center of the Rectangle.

Definition at line 70 of file Rect.h.

    {
      return Point (x, y);
    }
int nux::Rect::GetWidth ( ) const [inline]

Definition at line 56 of file Rect.h.

    {
      return width;
    }
Rect nux::Rect::Intersect ( const Rect r) const

Definition at line 129 of file Rect.cpp.

  {
    // Get the corner points.

    bool intersect = ! ((r.x > x + width) ||
                      (r.x + r.width < x) ||
                      (r.y > y + height) ||
                      (r.y + r.height < y));

    if (intersect)
    {
      const Point &ul1 = Point (x, y);
      const Point &ul2 = Point (r.x, r.y);
      int xx = Max<int> (ul1.x, ul2.x);
      int yy = Max<int> (ul1.y, ul2.y);
      int ww = Min<int> (ul1.x + width,  ul2.x + r.width) - xx;
      int hh = Min<int> (ul1.y + height, ul2.y + r.height) - yy;

      return Rect (xx, yy, ww, hh);
    }
    else
    {
      // No intersection
      return Rect ();
    }
  }

Here is the call graph for this function:

Here is the caller graph for this function:

bool nux::Rect::IsInside ( const Point p) const

Definition at line 117 of file Rect.cpp.

  {
    return ( (x <= p.x) && (x + width > p.x) &&
             (y <= p.y) && (y + height > p.y) );
  }

Here is the caller graph for this function:

bool nux::Rect::IsNull ( ) const

Return true is the area of this rectangle is Null.

Definition at line 92 of file Rect.cpp.

  {
    return ((width == 0) || (height == 0));
  }

Here is the caller graph for this function:

bool nux::Rect::IsPointInside ( int  dx,
int  dy 
) const

Definition at line 123 of file Rect.cpp.

  {
    return ( (x <= x_) && (x + width > x_) &&
             (y <= y_) && (y + height > y_) );
  }

Here is the caller graph for this function:

void nux::Rect::OffsetPosition ( int  dx,
int  dy 
) [inline]

Definition at line 107 of file Rect.h.

    {
      x += dx;
      y += dy;
    }
void nux::Rect::OffsetSize ( int  dw,
int  dh 
) [inline]

Definition at line 96 of file Rect.h.

    {
      width += dw;
      height += dh;

      if (width < 0)
        width = 0;

      if (height < 0)
        height = 0;
    }

Here is the caller graph for this function:

bool nux::Rect::operator!= ( const Rect p) const

Definition at line 82 of file Rect.cpp.

  {
    if ( (x == r.x) && (y == r.y) && (width == r.width) && (height == r.height) )
    {
      return false;
    }

    return true;
  }
Rect & nux::Rect::operator= ( const Rect r)

Definition at line 60 of file Rect.cpp.

  {
    if (&r == this)
      return *this;

    x = r.x;
    y = r.y;
    width = r.width;
    height = r.height;
    return *this;
  }
bool nux::Rect::operator== ( const Rect p) const

Definition at line 72 of file Rect.cpp.

  {
    if ( (x == r.x) && (y == r.y) && (width == r.width) && (height == r.height) )
    {
      return true;
    }

    return false;
  }
void nux::Rect::Set ( int  px,
int  py,
int  w,
int  h 
)

Definition at line 97 of file Rect.cpp.

  {
    x = px;
    y = py;
    width = w;
    height = h;
  }
void nux::Rect::SetHeight ( int  h) [inline]

Definition at line 79 of file Rect.h.

    {
      height = h;
    }

Here is the caller graph for this function:

void nux::Rect::SetPosition ( int  px,
int  py 
)

Definition at line 105 of file Rect.cpp.

  {
    x = px;
    y = py;
  }
void nux::Rect::SetSize ( int  px,
int  py 
)

Definition at line 111 of file Rect.cpp.

  {
    width = w;
    height = h;
  }
void nux::Rect::SetWidth ( int  w) [inline]

Definition at line 75 of file Rect.h.

    {
      width = w;
    }

Here is the caller graph for this function:

void nux::Rect::SetX ( int  px) [inline]

Definition at line 83 of file Rect.h.

    {
      x = px;
    }

Here is the caller graph for this function:

void nux::Rect::SetY ( int  py) [inline]

Definition at line 87 of file Rect.h.

    {
      y = py;
    }

Here is the caller graph for this function:


Member Data Documentation

Definition at line 117 of file Rect.h.

Definition at line 117 of file Rect.h.

Definition at line 116 of file Rect.h.

Definition at line 116 of file Rect.h.


The documentation for this class was generated from the following files: