📄 crect.cpp
字号:
////////////////////////////////////////////////////////////////////////
//
// 作者:
// 创建日期:
// 最后修改日期:
//
////////////////////////////////////////////////////////////////////////
#include "crect.h"
//##ModelId=3FC70480008B
CRect::CRect ()
{
left = 0;
right = 0;
top = 0;
bottom = 0;
}
//##ModelId=3FC70480008C
CRect::CRect (int Left, int Top, int Right, int Bottom)
{
left = Left;
right = Right;
top = Top;
bottom = Bottom;
}
//##ModelId=3FC704800091
CRect::CRect(CPoint point,CSize size)
{
left = point.x;
right = point.x + size.cx;
top = point.y;
bottom = point.y + size.cy;
}
//##ModelId=3FC704800096
CRect::CRect(CPoint leftTop,CPoint rightBottom)
{
left = leftTop.x;
right = rightBottom.x ;
top = leftTop.y;
bottom = rightBottom.y ;
}
//##ModelId=3FC704800099
const CRect & CRect::operator=(const CRect &rect)
{
left = rect.Left();
right = rect.Right();
top = rect.Top();
bottom = rect.Bottom();
return *this ;
}
//##ModelId=3FC70480009B
CRect CRect::operator=(CRect rect)
{
left = rect.Left();
right = rect.Right();
top = rect.Top();
bottom = rect.Bottom();
return *this ;
}
//##ModelId=3FC7048000A0
int CRect::operator==(const CRect &rect) const
{
if(left == rect.Left() && right == rect.Right() && top == rect.Top() && bottom == rect.Bottom())
//if equal than 0
return 1;
else
//if not equal than 1
return 0;
}
//##ModelId=3FC7048000A3
int CRect::operator!=(const CRect &rect) const
{
if(left != rect.Left() || right != rect.Right() || top != rect.Top() || bottom != rect.Bottom())
//if equal than 0
return 1;
else
//if not equal than 1
return 0;
}
//##ModelId=3FC7048000A9
int CRect::Width()
{
return (right - left);
}
//##ModelId=3FC7048000AA
int CRect::Height()
{
return (bottom - top);
}
//##ModelId=3FC7048000AB
int CRect::Left() const
{
return left;
}
//##ModelId=3FC7048000AD
int CRect::Right() const
{
return right;
}
//##ModelId=3FC7048000AF
int CRect::Top() const
{
return top;
}
//##ModelId=3FC7048000B1
int CRect::Bottom() const
{
return bottom;
}
//A point is within CRect if it lies on the left or top side or is within all four sides.
//A point on the right or bottom side is outside CRect.
//##ModelId=3FC7048000B4
bool CRect::PtInRect (int x, int y)
{
NormalizeRect();
if(x >= left && x < right && y < bottom && y >= top)
return true;
else
return false;
}
//##ModelId=3FC7048000B7
bool CRect::PtInRect(POINT point)
{
return PtInRect(point.x,point.y);
}
//##ModelId=3FC7048000B9
bool CRect::PtInRect(CPoint point)
{
return PtInRect(point.x,point.y);
}
// 将矩形进行规格化处理,即保证处理后的数值中,left < right, top < bottom。
//##ModelId=3FC7048000BE
void CRect::NormalizeRect()
{
if(Width() < 0){
int tmp = right;
right = left;
left = tmp;
}
if(Height() < 0){
int tmp = bottom;
bottom = top;
top = tmp;
}
}
//##ModelId=3FC7048000BF
const CPoint CRect::TopLeft( ) const
{
CPoint tmp(left,top);
return tmp;
}
//##ModelId=3FC7048000C1
const CPoint CRect::BottomRight( ) const
{
return CPoint(right,bottom);
}
//##ModelId=3FC7048000C3
CPoint CRect::CenterPoint( ) const
{
return CPoint((right + left) / 2 , (bottom + top) /2);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -