139 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			C++
		
	
	
	
		
		
			
		
	
	
			139 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			C++
		
	
	
	
|  | #include "..\easy2d.h"
 | |||
|  | 
 | |||
|  | RectNode::RectNode() : | |||
|  | 	m_Rect(0, 0, 0, 0) | |||
|  | { | |||
|  | 
 | |||
|  | } | |||
|  | 
 | |||
|  | RectNode::~RectNode() | |||
|  | { | |||
|  | } | |||
|  | 
 | |||
|  | bool RectNode::isCollisionWith(RectNode * rectNode) const | |||
|  | { | |||
|  | 	return IntersectRect(NULL, &m_Rect, &rectNode->m_Rect); | |||
|  | } | |||
|  | 
 | |||
|  | bool RectNode::isPointIn(CPoint p) const | |||
|  | { | |||
|  | 	return m_Rect.PtInRect(p); | |||
|  | } | |||
|  | 
 | |||
|  | void RectNode::setWindowCenterX() | |||
|  | { | |||
|  | 	setX((App::getWidth() - getWidth()) / 2); | |||
|  | } | |||
|  | 
 | |||
|  | void RectNode::setWindowCenterY() | |||
|  | { | |||
|  | 	setY((App::getHeight() - getHeight()) / 2); | |||
|  | } | |||
|  | 
 | |||
|  | 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); | |||
|  | } |