⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 painterview.cpp

📁 很不错的简单的矢量图形开发软件
💻 CPP
📖 第 1 页 / 共 5 页
字号:
			{
			    IsPicked=PickLine(line);
			    if(IsPicked)
				{
					m_IsSelected=TRUE;
				    line->bDo=2;
				}
			    else if(!bShiftDown)//如果没有按下Shift键,而对其它图元进行选择
				{
					if(line->bDo==2/* || line->bDo==2*/)
						line->bDo=1;
				}
			}
			break;
		case RECTANGLE:
			RECTANGLENODE *rectangle;
			rectangle=(RECTANGLENODE *)pDoc->RecordList.GetNext(pos);
			if(rectangle->bDo>0)//如果图元显示则继续处理
			{
			    IsPicked=PickRectangle(rectangle);
			    if(IsPicked)
				{
					m_IsSelected=TRUE;
					    rectangle->bDo=2;
				}
			    else if(!bShiftDown)//如果没有按下Shift键,而对其它图元进行选择
				{
					if(rectangle->bDo==2 /*|| rectangle->bDo==2*/)
						rectangle->bDo=1;
				}
			}
			break;
		case TRIANGLE:
			TRIANGLENODE *triangle;
			triangle=(TRIANGLENODE *)pDoc->RecordList.GetNext(pos);
			if(triangle->bDo>0)//如果图元显示则继续处理
			{
				IsPicked=PickTriangle(triangle->rT);
				if(IsPicked)
				{
					m_IsSelected=TRUE;
					triangle->bDo=2;
				}
				else if(!bShiftDown)//如果没有按下Shift键,而对其它图元进行选择
				{
					if(triangle->bDo==2/* ||triangle->bDo==2*/)
						triangle->bDo=1;
				}
			}
			break;
		case TEXT:
			TEXTNODE *text;
			text=(TEXTNODE *)pDoc->RecordList.GetNext(pos);
			if(text->bDo>0)
			{
				IsPicked=PickText(text);
				if(IsPicked)
				{
					m_IsSelected=TRUE;
					text->bDo=2;
				}
				else if(!bShiftDown)//如果没有按下Shift键,而对其它图元进行选择
				{
					if(text->bDo==2 /*|| text->bDo==2*/)
						text->bDo=1;
				}
			}
			break;
		case ELLIPSE:
			ELLIPSENODE *ellipse;
			ellipse=(ELLIPSENODE *)pDoc->RecordList.GetNext(pos);
			if(ellipse->bDo>0)//如果图元显示则继续处理
			{
			    IsPicked=PickEllipse(ellipse);
			    if(IsPicked)
				{
					m_IsSelected=TRUE;
				    ellipse->bDo=2;
				}
			    else if(!bShiftDown)//如果没有按下Shift键,而对其它图元进行选择
				{
					if(ellipse->bDo==2 /*|| ellipse->bDo==3*/)
						ellipse->bDo=1;
				}
			}
			break;
		}		
	}
}

//拾取直线
BOOL CPainterView::PickLine(LINENODE *linenode)
{
	BOOL	returncode=FALSE;
	double	x=PrePoint.x-linenode->Start.x;
	double	y=PrePoint.y-linenode->Start.y;

	double	a=linenode->End.x-linenode->Start.x;
	double	b=linenode->End.y-linenode->Start.y;
	double	c=sqrt(a*a+b*b);

	double	sin=b/c;
	double  cos=a/c;

	double	chg_x=x*cos+y*sin;
	double	chg_y=-x*sin+y*cos;

	if(fabs(chg_y)<5.0 &&(chg_x>=0&&chg_x<=c))
		returncode=TRUE;

	return returncode;	
}

//拾取椭圆
BOOL CPainterView::PickEllipse(ELLIPSENODE *ellipsenode)
{
	CRgn ellipse;
	BOOL returncode;
	POINT point[4];
	
	point[0].x=ellipsenode->rT.left;
	point[0].y=ellipsenode->rT.top;
	point[1].x=ellipsenode->rT.right;
	point[1].y=ellipsenode->rT.top;
	point[2].x=ellipsenode->rT.right;
	point[2].y=ellipsenode->rT.bottom;
	point[3].x=ellipsenode->rT.left;
	point[3].y=ellipsenode->rT.bottom;
	ellipse.CreatePolygonRgn(point,4,WINDING);

	return returncode=ellipse.PtInRegion(PrePoint);
}

//拾取矩形
BOOL CPainterView::PickRectangle(RECTANGLENODE *rectanglenode)
{
	BOOL   returncode=FALSE;

	if(fabs(PrePoint.x-rectanglenode->rT.left)<5.0||
		   fabs(PrePoint.x-rectanglenode->rT.right)<5.0)
	{
		if((PrePoint.y>=rectanglenode->rT.top && PrePoint.y<=rectanglenode->rT.bottom)
			||(PrePoint.y<=rectanglenode->rT.top && PrePoint.y>=rectanglenode->rT.bottom))
		{
			returncode=TRUE;
		}
	}

	if(fabs(PrePoint.y-rectanglenode->rT.top)<5.0||fabs(PrePoint.y-rectanglenode->rT.bottom)<5.0)
	{
		if((PrePoint.x>=rectanglenode->rT.left && PrePoint.x<=rectanglenode->rT.right)
			||(PrePoint.x<=rectanglenode->rT.left && PrePoint.y>=rectanglenode->rT.right))
		{
			returncode=TRUE;
		}
	}

	return returncode;
}

//处理选择命令
void CPainterView::OnDrawSelect() 
{
	// TODO: Add your command handler code here
	DrawType=new BYTE;
	*DrawType=SELECT;	
}

//处理移动命令
void CPainterView::OnModifyMove() 
{
	// TODO: Add your command handler code here
	DrawType=new BYTE;
	*DrawType=MOVE;
}

//移动图元
void CPainterView::MoveCompent()
{
	CPainterDoc *pDoc=GetDocument();
	POSITION pos=pDoc->RecordList.GetHeadPosition();
	int x_off=TempPoint.x-PrePoint.x;
	int y_off=TempPoint.y-PrePoint.y;
	if(*DrawType==MOVE)
		movenode=new MOVENODE;
	int index=0;

	while(pos!=NULL)
	{
		BYTE *style;
		style=(BYTE *)pDoc->RecordList.GetNext(pos);

		switch(*style)
		{
		case LINE:
			LINENODE *line;
			line=(LINENODE *)pDoc->RecordList.GetNext(pos);
			if(line->bDo==2)
			{
				if(*DrawType==MOVE)
				{
					line->bDo=5;
					line->End.x+=x_off;
				    line->End.y+=y_off;
				    line->Start.x+=x_off;
				    line->Start.y+=y_off;
					movenode->Index[index]=line->Index;
					index+=1;
				}
				else
				{
					line->bDo=3;
					line->End.x+=x_off;
				    line->End.y+=y_off;
				    line->Start.x+=x_off;
				    line->Start.y+=y_off;
				}
			}
		break;
		case RECTANGLE:
			RECTANGLENODE *rectangle;
			rectangle=(RECTANGLENODE *)pDoc->RecordList.GetNext(pos);
			if(rectangle->bDo==2)
			{
				if(*DrawType==MOVE)
				{
					 rectangle->bDo=5;
			         rectangle->rT.left+=x_off;
			         rectangle->rT.right+=x_off;
			         rectangle->rT.bottom+=y_off;
			         rectangle->rT.top+=y_off;
					 movenode->Index[index]=rectangle->Index;
					 index+=1;
				}
				else
				{
					 rectangle->bDo=3;
					 rectangle->rT.left+=x_off;
			         rectangle->rT.right+=x_off;
			         rectangle->rT.bottom+=y_off;
			         rectangle->rT.top+=y_off;
				}
			}
			break;
		case TRIANGLE:
			TRIANGLENODE *triangle;
			triangle=(TRIANGLENODE *)pDoc->RecordList.GetNext(pos);
			if(triangle->bDo==2)
			{
				triangle->bDo=-2;
				if(*DrawType==MOVE)
				{
					 triangle->bDo=5;
			         triangle->rT.left+=x_off;
			         triangle->rT.right+=x_off;
			         triangle->rT.bottom+=y_off;
			         triangle->rT.top+=y_off;
					 movenode->Index[index]=triangle->Index;
					 index+=1;
				}
				else
				{
					 triangle->bDo=3;
					 triangle->rT.left+=x_off;
			         triangle->rT.right+=x_off;
			         triangle->rT.bottom+=y_off;
			         triangle->rT.top+=y_off;
				}
			}
			break;
		case TEXT:
			TEXTNODE *text;
			text=(TEXTNODE *)pDoc->RecordList.GetNext(pos);
			if(text->bDo==2)
			{
				if(*DrawType==MOVE)
				{
					 text->bDo=5;
			         text->point.x+=x_off;
			         text->point.y+=y_off;
					 movenode->Index[index]=text->Index;
					 index+=1;
				}
				else
				{
					 text->bDo=3;
					 text->point.x+=x_off;
			         text->point.y+=y_off;
				}
			}
			break;
		case ELLIPSE:
			ELLIPSENODE *ellipse;
			ellipse=(ELLIPSENODE *)pDoc->RecordList.GetNext(pos);
			if(ellipse->bDo==2)
			{
				if(*DrawType==MOVE)
				{
					ellipse->bDo=5;
				    ellipse->rT.left+=x_off;
				    ellipse->rT.right+=x_off;
				    ellipse->rT.top+=y_off;
				    ellipse->rT.bottom+=y_off;
					movenode->Index[index]=ellipse->Index;
					index+=1;
				}
				else
				{
					ellipse->bDo=3;
					ellipse->rT.left+=x_off;
				    ellipse->rT.right+=x_off;
				    ellipse->rT.top+=y_off;
				    ellipse->rT.bottom+=y_off;
				}
			}
			break;
		default:
			pDoc->RecordList.GetNext(pos);
			break;
		}
	}

	if(*DrawType==MOVE)
	{
	    movenode->x_off=x_off;
	    movenode->y_off=y_off;
	    movenode->iCompNum=index;
	    pDoc->RecordList.AddTail(&movenode->bType);
	    pDoc->RecordList.AddTail(movenode);
	}
}

//设置删除命令状态
void CPainterView::OnUpdateEditDelete(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if(m_IsSelected)
		pCmdUI->Enable(TRUE && !m_bModify);
	else
		pCmdUI->Enable(FALSE);
}

//处理删除命令
void CPainterView::OnEditDelete() 
{
	// TODO: Add your command handler code here
	CPainterDoc *pDoc=GetDocument();
	POSITION pos,TempPos,TempPos1;
	pos=pDoc->RecordList.GetHeadPosition();

	while(pos!=NULL)
	{
    	BYTE* style;
		TempPos1=pos;//记录图元文件类型的位置
		style=(BYTE*)pDoc->RecordList.GetNext(pos);
		TempPos=pos;//记录图元文件的位置
		switch(*style)
		{
		case LINE:
			LINENODE *line;
			line=(LINENODE*)pDoc->RecordList.GetNext(pos);
			if(line->bDo==2)
			{
				pDoc->RecordList.RemoveAt(TempPos1);//删除图元文件类型
				pDoc->RecordList.RemoveAt(TempPos);//删除图元文件
			}
			break;
		case TEXT:
			TEXTNODE *text;
			text=(TEXTNODE *)pDoc->RecordList.GetNext(pos);
			if(text->bDo==2)
			{
				pDoc->RecordList.RemoveAt(TempPos1);
				pDoc->RecordList.RemoveAt(TempPos);
			}
			break;
		case RECTANGLE:
			RECTANGLENODE *rectangle;
			rectangle=(RECTANGLENODE *)pDoc->RecordList.GetNext(pos);
			if(rectangle->bDo==2)
			{
				pDoc->RecordList.RemoveAt(TempPos1);//删除图元文件类型
				pDoc->RecordList.RemoveAt(TempPos);//删除图元文件
			}
			break;
		case TRIANGLE:
			TRIANGLENODE *triangle;
			triangle=(TRIANGLENODE *)pDoc->RecordList.GetNext(pos);
			if(triangle->bDo==2)
			{
				pDoc->RecordList.RemoveAt(TempPos1);
				pDoc->RecordList.RemoveAt(TempPos);
			}
			break;
		case ELLIPSE:
			ELLIPSENODE *ellipse;
			ellipse=(ELLIPSENODE*)pDoc->RecordList.GetNext(pos);
			if(ellipse->bDo==2)
			{
				pDoc->RecordList.RemoveAt(TempPos1);//删除图元文件类型
				pDoc->RecordList.RemoveAt(TempPos);//删除图元文件
			}
			break;
		}
	}
	Invalidate();
}

//处理拷贝命令
void CPainterView::OnEditCopy() 
{
	// TODO: Add your command handler code here
	CPainterDoc *pDoc=GetDocument();
	POSITION pos=pDoc->RecordList.GetHeadPosition();
	pDoc->RecordCopy.RemoveAll();
	int index=0;
	if(*DrawType==CUT)
		cutnode=new CUTNODE;

	while(pos!=NULL)
	{
		BYTE *style;
		style=(BYTE *)pDoc->RecordList.GetNext(pos);

		switch(*style)
		{
		case LINE:
			LINENODE *line;
			line=(LINENODE *)pDoc->RecordList.GetNext(pos);
			if(line->bDo==2)//如果图元处于被选择状态
			{
				line->bDo=1;
				LINENODE *newline;
				newline=new LINENODE;//初始化指针
				memcpy(newline,line,sizeof(LINENODE));
				pDoc->RecordCopy.Add(style);
				pDoc->RecordCopy.Add(newline);
				if(*DrawType==CUT)
				{
					line->bDo=-6;
					cutnode->Index[index]=line->Index;
					index+=1;
				}
			}
		break;
		case TEXT:
			TEXTNODE *text;
			text=(TEXTNODE *)pDoc->RecordList.GetNext(pos);
			if(text->bDo==2)
			{
				text->bDo=1;
				TEXTNODE *newtext;
				newtext=new TEXTNODE;
				memcpy(newtext,text,sizeof(TEXTNODE));
				pDoc->RecordCopy.Add(style);
				pDoc->RecordCopy.Add(newtext);
				if(*DrawType==CUT)
				{
					text->bDo=-6;
					cutnode->Index[index]=text->Index;
					index+=1;
				}
			}
			break;
		case RECTANGLE:
			RECTANGLENODE *rectangle;
			rectangle=(RECTANGLENODE *)pDoc->RecordList.GetNext(pos);
			if(rectangle->bDo==2)
			{
				rectangle->bDo=1;
				RECTANGLENODE *newrectangle;
				newrectangle=new RECTANGLENODE;
				memcpy(newrectangle,rectangle,sizeof(RECTANGLENODE));
				newrectangle->bDo=3;
				pDoc->RecordCopy.Add(style);
				pDoc->RecordCopy.Add(newrectangle);
				if(*DrawType==CUT)
				{
					rectangle->bDo=-6;
					cutnode->Index[index]=rectangle->Index;
					index+=1;
				}
			}
			break;
		case TRIANGLE:
			TRIANGLENODE *triangle;
			triangle=(TRIANGLENODE *)pDoc->RecordList.GetNext(pos);
			if(triangle->bDo==2)
			{
				triangle->bDo=1;
				TRIANGLENODE *newtriangle;
				newtriangle=new TRIANGLENODE;
				memcpy(newtriangle,triangle,sizeof(TRIANGLENODE));
				newtriangle->bDo=3;
				pDoc->RecordCopy.Add(style);
				pDoc->RecordCopy.Add(newtriangle);
				if(*DrawType==CUT)
				{
					triangle->bDo=-6;
					cutnode->Index[index]=triangle->Index;
					index+=1;
				}
			}
			break;
		case ELLIPSE:
			ELLIPSENODE *ellipse;
			ellipse=(ELLIPSENODE *)pDoc->RecordList.GetNext(pos);
			if(ellipse->bDo==2)
			{
				ellipse->bDo=1;
				ELLIPSENODE *newellipse;
				newellipse=new ELLIPSENODE;
				memcpy(newellipse,ellipse,sizeof(ELLIPSENODE));
				pDoc->RecordCopy.Add(style);
				pDoc->RecordCopy.Add(newellipse);
				if(*DrawType==CUT)
				{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -