Magic_Game/Easy2D/Object/RectNode.cpp

140 lines
1.9 KiB
C++
Raw Normal View History

2017-09-27 17:56:28 +08:00
#include "..\easy2d.h"
RectNode::RectNode() :
m_Rect(0, 0, 0, 0)
{
}
RectNode::~RectNode()
{
}
bool RectNode::isCollisionWith(RectNode * rectNode) const
{
2017-10-09 10:19:04 +08:00
static CRect rt;
return IntersectRect(&rt, &m_Rect, &rectNode->m_Rect);
2017-09-27 17:56:28 +08:00
}
bool RectNode::isPointIn(CPoint p) const
{
return m_Rect.PtInRect(p);
}
void RectNode::setWindowCenterX()
{
2017-10-12 02:44:44 +08:00
setX((EApp::getWidth() - getWidth()) / 2);
2017-09-27 17:56:28 +08:00
}
void RectNode::setWindowCenterY()
{
2017-10-12 02:44:44 +08:00
setY((EApp::getHeight() - getHeight()) / 2);
2017-09-27 17:56:28 +08:00
}
void RectNode::setWindowCenter()
{
setWindowCenterX();
setWindowCenterY();
}
int RectNode::getX() const
{
return m_Rect.left;
}
int RectNode::getY() const
{
return m_Rect.top;
}
CPoint RectNode::getPos() const
{
return m_Rect.TopLeft();
}
int RectNode::getWidth() const
{
return m_Rect.Width(); // <20><><EFBFBD>ο<EFBFBD><CEBF><EFBFBD>
}
int RectNode::getHeight() const
{
return m_Rect.Height(); // <20><><EFBFBD>θ߶<CEB8>
}
CSize RectNode::getSize() const
{
return m_Rect.Size();
}
CRect RectNode::getRect() const
{
return m_Rect;
}
void RectNode::setX(int x)
{
m_Rect.MoveToX(x);
}
void RectNode::setY(int y)
{
m_Rect.MoveToY(y);
}
void RectNode::setPos(int x, int y)
{
m_Rect.MoveToXY(x, y); // <20>޸ľ<DEB8><C4BE><EFBFBD>λ<EFBFBD><CEBB>
}
void RectNode::setPos(CPoint p)
{
m_Rect.MoveToXY(p); // <20>޸ľ<DEB8><C4BE><EFBFBD>λ<EFBFBD><CEBB>
}
void RectNode::move(int x, int y)
{
m_Rect.OffsetRect(x, y); // <20>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD>
}
void RectNode::move(CVector v)
{
m_Rect.OffsetRect(v); // <20>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD>
}
void RectNode::setWidth(int width)
{
m_Rect.right = max(m_Rect.left + width, 0);
}
void RectNode::setHeight(int height)
{
m_Rect.bottom = max(m_Rect.top + height, 0);
}
void RectNode::setSize(int width, int height)
{
setWidth(width);
setHeight(height);
}
void RectNode::setSize(CSize size)
{
setSize(size.cx, size.cy);
}
void RectNode::setRect(int x1, int y1, int x2, int y2)
{
m_Rect.SetRect(x1, y1, x2, y2);
}
void RectNode::setRect(CPoint leftTop, CPoint rightBottom)
{
m_Rect.SetRect(leftTop, rightBottom);
}
void RectNode::setRect(CRect rect)
{
m_Rect.CopyRect(&rect);
}