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

📄 painterview.cpp

📁 很不错的简单的矢量图形开发软件
💻 CPP
📖 第 1 页 / 共 5 页
字号:
					ellipse->bDo=-6;
					cutnode->Index[index]=ellipse->Index;
					index+=1;
				}
			}
			break;
		}
	}

	if(pDoc->RecordCopy.GetSize())  //如果拷贝数组不为空
		m_bCopy=TRUE;
	if(*DrawType==CUT)
	{
		cutnode->iCompNum=index;
		pDoc->RecordList.AddTail(&cutnode->bType);
		pDoc->RecordList.AddTail(cutnode);
	}
	m_IsSelected=0;
	Invalidate();
}

//设置拷贝命令状态
void CPainterView::OnUpdateEditCopy(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::OnEditPaste() 
{
	// TODO: Add your command handler code here
	pastenode=new PASTENODE;
	DrawType=new BYTE;
	*DrawType=PASTE;
	int i,index=0;
	CPainterDoc *pDoc=GetDocument();

	CStatusBar* pStatus;//得到状态栏指针
	pStatus=(CStatusBar*)AfxGetApp()->m_pMainWnd->GetDescendantWindow(ID_VIEW_STATUS_BAR);
   	pStatus->SetPaneText(0,"拖动图元到指定位置");
	
	for(i=0;i<pDoc->RecordCopy.GetSize();)
	{
		BYTE *style;
		style=(BYTE *)pDoc->RecordCopy.GetAt(i);//从复制矩阵中取出图元类型
		i+=1;
		switch(*style)
		{
		case LINE:
			LINENODE *line;
			line=(LINENODE *)pDoc->RecordCopy.GetAt(i);//从复制矩阵中取出图元
			//将复制图元移动一定位移以与原图元分别
			line->End.x+=10;
			line->End.y+=10;
			line->bDo=2;
			OppIndex+=1;
			line->Index=OppIndex;
			pastenode->Index[index]=line->Index;
			index+=1;
			//添加复制图元到链表
			pDoc->RecordList.AddTail(style);
			pDoc->RecordList.AddTail(line);
			break;
		case TEXT:
			TEXTNODE *text;
			text=(TEXTNODE *)pDoc->RecordCopy.GetAt(i);
			text->point.x+=10;
			text->point.y+=10;
			text->bDo=2;
			OppIndex+=1;
			text->Index=OppIndex;
			pastenode->Index[index]=text->Index;
			index+=1;
			pDoc->RecordList.AddTail(style);
			pDoc->RecordList.AddTail(text);
			break;
		case RECTANGLE:
			RECTANGLENODE *rectangle;
			rectangle=(RECTANGLENODE *)pDoc->RecordCopy.GetAt(i);
			rectangle->rT.left+=10;
			rectangle->rT.right+=10;
			rectangle->rT.top-=10;
			rectangle->rT.bottom-=10;
			rectangle->bDo=2;
			OppIndex+=1;
			rectangle->Index=OppIndex;
			pastenode->Index[index]=rectangle->Index;
			index+=1;
			pDoc->RecordList.AddTail(style);
			pDoc->RecordList.AddTail(rectangle);
			break;
		case TRIANGLE:
			TRIANGLENODE *triangle;
			triangle=(TRIANGLENODE *)pDoc->RecordCopy.GetAt(i);
			triangle->rT.left+=10;
			triangle->rT.right+=10;
			triangle->rT.bottom-=10;
			triangle->rT.top-=10;
			triangle->bDo=2;
			OppIndex+=1;
			triangle->Index=OppIndex;
			pastenode->Index[index]=triangle->Index;
			index+=1;
			pDoc->RecordList.AddTail(style);
			pDoc->RecordList.AddTail(triangle);
			break;
		case ELLIPSE:
			ELLIPSENODE *ellipse;
			ellipse=(ELLIPSENODE *)pDoc->RecordCopy.GetAt(i);
			ellipse->rT.left+=10;
			ellipse->rT.right+=10;
			ellipse->bDo=2;
			OppIndex+=1;
			ellipse->Index=OppIndex;
			pastenode->Index[index]=ellipse->Index;
			index+=1;
			pDoc->RecordList.AddTail(style);
			pDoc->RecordList.AddTail(ellipse);
			break;
		}
		i+=1;
	}

	pastenode->iCompNum=index;
	pDoc->RecordList.AddTail(&pastenode->bType);
	pDoc->RecordList.AddTail(pastenode);
	Invalidate();
}

//设置粘贴命令状态
void CPainterView::OnUpdateEditPaste(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if(m_bCopy)//如果存在拷贝图元则允许执行该命令
		pCmdUI->Enable(TRUE && !m_bModify);
	else//否则禁止该命令
		pCmdUI->Enable(FALSE);	
}


void CPainterView::OnEditCut() 
{
	// TODO: Add your command handler code here
	DrawType=new BYTE;
	*DrawType=CUT;
	DrawStep=1;
	OnEditCopy();
}

void CPainterView::OnUpdateEditCut(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::OnEditRedo() 
{
	// TODO: Add your command handler code here
	CPainterDoc *pDoc=GetDocument();
	POSITION pos=pDoc->RecordList.GetHeadPosition(),TempPos;
	DrawType=new BYTE;
	*DrawType=REDO;
	int finish=0;

	while(pos!=NULL && finish<=0)
	{
		BYTE *style;
		TempPos=pos;
		style=(BYTE *)pDoc->RecordList.GetNext(pos);
		switch(*style)
		{
		case LINE:
			LINENODE *line;
			line=(LINENODE *)pDoc->RecordList.GetNext(pos);
			if(line->bDo==0)
			{
				line->bDo=1;
				finish=1;
			}
			break;
		case TEXT:
			TEXTNODE *text;
			text=(TEXTNODE *)pDoc->RecordList.GetNext(pos);
			if(text->bDo==0)
			{
				text->bDo=1;
				finish=1;
			}
			break;
		case FILL:
			FILLNODE *fill;
			fill=(FILLNODE *)pDoc->RecordList.GetNext(pos);
			if(fill->bDo==0)
			{
				fill->bDo=1;
				finish=1;
			}
			break;
		case RECTANGLE:
			RECTANGLENODE *rectangle;
			rectangle=(RECTANGLENODE *)pDoc->RecordList.GetNext(pos);
			if(rectangle->bDo==0)
			{
				rectangle->bDo=1;
				finish=1;
			}
			break;
		case TRIANGLE:
			TRIANGLENODE *triangle;
			triangle=(TRIANGLENODE *)pDoc->RecordList.GetNext(pos);
			if(triangle->bDo==0)
			{
				triangle->bDo=1;
				finish=1;
			}
			break;
		case ELLIPSE:
			ELLIPSENODE *ellipse;
			ellipse=(ELLIPSENODE *)pDoc->RecordList.GetNext(pos);
			if(ellipse->bDo<=0)
			{
				ellipse->bDo=1;
				finish=1;
			}
			break;
		case MOVE:
			MOVENODE *move;
			move=(MOVENODE *)pDoc->RecordList.GetNext(pos);
			if(move->bDo==0)
			{
				move->bDo=1;
				UndoMove(move);
				finish=1;
			}
			break;
		case PASTE:
			PASTENODE *paste;
			paste=(PASTENODE *)pDoc->RecordList.GetNext(pos);
			if(paste->bDo==0)
			{
				paste->bDo=1;
				UndoPaste(paste);
				finish=1;
			}
			break;
		case CUT:
			CUTNODE *cut;
			cut=(CUTNODE *)pDoc->RecordList.GetNext(pos);
			if(cut->bDo==0)
			{
				cut->bDo=1;
				UndoCut(cut);
				finish=1;
			}
			break;
		}
	}
	if(!finish)
		m_bRedo=0;
	*DrawType=SELECT;
	Invalidate();
}

void CPainterView::OnUpdateEditUndo(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	CPainterDoc *pDoc=GetDocument();
	POSITION pos=pDoc->RecordList.GetTailPosition();
	if(pos)
		pCmdUI->Enable(!m_bModify);
	else
	{
		pCmdUI->Enable(FALSE);
		m_bUndo=FALSE;
	}
}

void CPainterView::OnUpdateEditRedo(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if(m_bUndo)
		pCmdUI->Enable(!m_bModify);
	else
		pCmdUI->Enable(FALSE);
}

void CPainterView::OnEditUndo() 
{
	// TODO: Add your command handler code here
	m_bUndo=TRUE;
	CPainterDoc *pDoc=GetDocument();
	POSITION pos=pDoc->RecordList.GetTailPosition(),TempPos;
	DrawType=new BYTE;
	*DrawType=UNDO;
	int finish=0;

	while(pos!=NULL && finish<=0)
	{
		BYTE *style;
		TempPos=pos;
		pDoc->RecordList.GetPrev(pos);
		style=(BYTE *)pDoc->RecordList.GetPrev(pos);
		switch(*style)
		{
		case LINE:
			LINENODE *line;
			line=(LINENODE *)pDoc->RecordList.GetAt(TempPos);
			if(line->bDo==1 || line->bDo==7)
			{
				line->bDo=0;
				finish=1;
			}
			break;
		case TEXT:
			TEXTNODE *text;
			text=(TEXTNODE *)pDoc->RecordList.GetAt(TempPos);
			if(text->bDo==1 || text->bDo==7)
			{
				text->bDo=0;
				finish=1;
			}
			break;
		case FILL:
			FILLNODE *fill;
			fill=(FILLNODE *)pDoc->RecordList.GetAt(TempPos);
			if(fill->bDo==1 || fill->bDo==7)
			{
				fill->bDo=0;
				finish=1;
			}
			break;
		case RECTANGLE:
			RECTANGLENODE *rectangle;
			rectangle=(RECTANGLENODE *)pDoc->RecordList.GetAt(TempPos);
			if(rectangle->bDo==1 || rectangle->bDo==7)
			{
				rectangle->bDo=0;
				finish=1;
			}
			break;
		case TRIANGLE:
			TRIANGLENODE *triangle;
			triangle=(TRIANGLENODE *)pDoc->RecordList.GetAt(TempPos);
			if(triangle->bDo==1 || triangle->bDo==7)
			{
				triangle->bDo=0;
				finish=1;
			}
			break;
		case ELLIPSE:
			ELLIPSENODE *ellipse;
			ellipse=(ELLIPSENODE *)pDoc->RecordList.GetAt(TempPos);
			if(ellipse->bDo==1 || ellipse->bDo==7)
			{
				ellipse->bDo=0;
				finish=1;
			}
			break;
		case MOVE:
			MOVENODE *move;
			move=(MOVENODE *)pDoc->RecordList.GetAt(TempPos);
			if(move->bDo==1)
			{
			    UndoMove(move);
			    finish=1;
			    move->bDo=0;
			}
			break;
		case PASTE:
			PASTENODE *paste;
			paste=(PASTENODE *)pDoc->RecordList.GetAt(TempPos);
			if(paste->bDo==1)
			{
				UndoPaste(paste);
				finish=1;
				paste->bDo=0;
			}
			break;
		case CUT:
			CUTNODE *cut;
			cut=(CUTNODE *)pDoc->RecordList.GetAt(TempPos);
			if(cut->bDo==1)
			{
				UndoCut(cut);
				finish=1;
				cut->bDo=0;
			}
		}
	}
	if(!finish)
		m_bUndo=0;
	Invalidate();
	*DrawType=SELECT;
}

//画三角形
void CPainterView::DrawTriangle(CDC * pDC,RECT rect)
{
	pDC->MoveTo(rect.left,rect.top);
	pDC->LineTo(rect.right,(rect.top+rect.bottom)/2);
	pDC->LineTo(rect.left,rect.bottom);
	pDC->LineTo(rect.left,rect.top);
}

//绘制三角形
void CPainterView::OnDrawTriangle() 
{
	// TODO: Add your command handler code here
	DrawType=new BYTE;
	*DrawType=TRIANGLE;	
}

//检查点是否在三角形内部以决定是否此三角形被选择
BOOL CPainterView::PickTriangle(RECT rect)
{
	//另一种拾取方法
	CRgn Triangle;
	BOOL returncode;
	POINT point[3];
	point[0].x=rect.left;
	point[0].y=rect.top;
	point[1].x=rect.right;
	point[1].y=(rect.top+rect.bottom)/2;
	point[2].x=rect.left;
	point[2].y=rect.bottom;
	Triangle.CreatePolygonRgn(point,3,WINDING);
	returncode=Triangle.PtInRegion(PrePoint);
	Triangle.DeleteObject();
	return returncode;
}

//绘制文本
void CPainterView::OnText() 
{
	// TODO: Add your command handler code here
	DrawType=new BYTE;
	*DrawType=TEXT;
}

//选择文本
BOOL CPainterView::PickText(/*POINT point*/TEXTNODE *text)
{
	CClientDC dc(this);
	CSize TextSize;
	CRect TextRect;
	BOOL returncode;

	TextRect.top=text->point.x;
	TextRect.left=text->point.y;
	TextSize=dc.GetTextExtent(text->str);
	TextRect.bottom=text->point.x+TextSize.cx;
	TextRect.right=text->point.y+TextSize.cy;
	returncode=TextRect.PtInRect(PrePoint);
	
	return returncode;	
}

void CPainterView::OnDestroy() 
{
	CScrollView::OnDestroy();

	CRect rect;
	//清除对话框工具条的内容。
	CBrush  brush=(0,RGB(255,255,255));
	CMainFrame *OwnWnd;
	OwnWnd=(CMainFrame *)GetParentOwner();
	CWnd* pWnd = OwnWnd->m_wndMyDialogBar.GetDlgItem(IDC_FILL_PREVIEW);
	pWnd->GetClientRect(rect);
	CDC* dc=pWnd->GetDC();
	dc->FillRect(rect,&brush);

	CComboBox* pCBox=(CComboBox*)OwnWnd->m_wndMyDialogBar.GetDlgItem(IDC_FILL_PATTERN);
	pCBox->SetCurSel(-1);

	pCBox = (CComboBox*)OwnWnd->m_wndMyDialogBar.GetDlgItem(IDC_LINE_TYPE);
	pCBox->SetCurSel(-1);

	pCBox=(CComboBox*)OwnWnd->m_wndMyDialogBar.GetDlgItem(IDC_LINE_WIDTH);
	pCBox->SetCurSel(-1);

	pWnd = OwnWnd->m_wndMyDialogBar.GetDlgItem(IDC_LINE_PREVIEW);
	pWnd->GetClientRect(rect);
	dc=pWnd->GetDC();
	dc->Rectangle(rect);
}

void CPainterView::OnDrawGrid() 
{
	// TODO: Add your command handler code here
	if(m_bGrid)
		m_bGrid=FALSE;
	else 
		m_bGrid=TRUE;
	Invalidate();
}

//根据是否绘制辅助网点而设置按钮状态
void CPainterView::OnUpdateDrawGrid(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
		pCmdUI->SetCheck(m_bGrid);
		pCmdUI->Enable(!m_bModify);
}

//根据是否绘处于填充而设置按钮状态
void CPainterView::OnUpdateDrawFill(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if(*DrawType==FILL)
		pCmdUI->SetCheck(TRUE);

⌨️ 快捷键说明

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