/*--------------------------------------------------------------------------
  Project:  Manual 2D Library - m2d
  File:     Rect.h

  Copyright (C)2007-2009 Nintendo  All Rights Reserved.

  These coded instructions, statements, and computer programs contain
  proprietary information of Nintendo of America Inc. and/or Nintendo
  Company Ltd., and are protected by Federal copyright law. They may
  not be disclosed to third parties or copied or duplicated in any form,
  in whole or in part, without the prior written consent of Nintendo.

  $Revision: 1.6 $
 *-------------------------------------------------------------------------*/

#ifndef NTMV_M2D_RECT_H_
#define NTMV_M2D_RECT_H_

#include <nitro/types.h>
#include <ntmv/m2d/types.h>

namespace ntmv
{
namespace m2d
{

struct Rect
{
public:
    /* ------------------------------------------------------------------------
            Variables
       ------------------------------------------------------------------------ */
    s16 left;
    s16 top;
    s16 right;
    s16 bottom;


    /* ------------------------------------------------------------------------
            Functions
       ------------------------------------------------------------------------ */
    //---- Constructor/destructor
            Rect()
    : left(0),
      top(0),
      right(0),
      bottom(0)
    {
    }

            Rect(s16 l, s16 t, s16 r, s16 b)
    : left(l),
      top(t),
      right(r),
      bottom(b)
    {
    }

                        Rect(
                            Point   point,
                            Size    size
                        )
                        :   left(point.x),
                            top(point.y),
                            right(static_cast<s16>(point.x + size.width)),
                            bottom(static_cast<s16>(point.y + size.height))
    {}

            ~Rect()
    {
    }

    s16     GetWidth() const
    {
        return static_cast<s16>(right - left);
    }

    s16     GetHeight() const
    {
        return static_cast<s16>(bottom - top);
    }

    void    SetWidth(s16 width)
    {
        right = static_cast<s16>(left + width);
    }

    void    SetHeight(s16 height)
    {
        bottom = static_cast<s16>(top + height);
    }

    void    MoveTo(s16 x, s16 y)
    {
        right  = static_cast<s16>(x + GetWidth());
        left   = x;
        bottom = static_cast<s16>(y + GetHeight());
        top    = y;
    }
    
    void    Move(s16 dx, s16 dy)
    {
        left    += dx;
        right   += dx;
        top     += dy;
        bottom  += dy;
    }

    bool
    Contains(Point point) const
    {
        return left <= point.x && point.x <= right && top <= point.y && point.y <= bottom;
    }

};



}   // namespace m2d
}   // namespace ntmv

#endif //  NTMV_M2D_RECT_H_
