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

📄 geditorview.cpp

📁 一个复杂的画图系统
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	
	//Get the client DC associated with the view.
	CDC* pClientDC = GetDC();
	ASSERT_VALID(pClientDC);

	//Convert "point" from devive coordinate to logical coordinate.
	pClientDC->DPtoLP(&point);

	//Get the document associated with the view.
	CGeditorDoc *pDoc = (CGeditorDoc*)GetDocument();
	ASSERT_VALID(pDoc);
	
	CPen curPen(PS_SOLID,1,(COLORREF)pDoc->m_curColor);
	CPen* oldPen = pClientDC->SelectObject(&curPen);
	CBrush curBrush((COLORREF)pDoc->m_curColor);
	CBrush* oldBrush = pClientDC->SelectObject(&curBrush);
	int oldROP2 = pClientDC->SetROP2(R2_NOTXORPEN);

	switch(pDoc->m_wToolType)
	{
	case TOOL_POLYGON:
		if(m_pCurPgn != NULL)
		{
			if(m_pCurPgn->GetVtxCount() > 2) 
				//A valid polygon have 3 verteces at least
			{
				pClientDC->MoveTo(m_pCurPgn->GetHead());
				pClientDC->LineTo(m_pCurPgn->GetTail());
				m_pCurPgn->dragmode=10;
				m_pCurPgn->Draw(pClientDC);
				pDoc->objitems+="P";
				pDoc->m_shapeList.AddTail(m_pCurPgn);
				pDoc->SetModifiedFlag();
				CurObj=m_pCurPgn;
				polypt.x=polypt.y=-1;
			}
			else //Remove the invalid polygon
			{
				delete m_pCurPgn;
			}
			//Reset the "m_ptCurPgn" to NULL.
			m_pCurPgn = NULL;
		
		};//end of if
		Invalidate();
		break;
	default:	
		break;
	}//end of switch

	pClientDC->SelectObject(oldPen);
	pClientDC->SelectObject(oldBrush);
	pClientDC->SetROP2(oldROP2);
	DeleteObject(curPen);
	DeleteObject(curBrush);
	//Release the DC
	ReleaseDC(pClientDC);
	//Call default handler
	CScrollView::OnLButtonDblClk(nFlags, point);
}

/*******************************************************************
Function Name:	CGeditorView::OntoolType()
Processing:		Based on the visual object on which you click, the 
				function record the drawing tool type in 
				"pDoc->mwToolType".
Parameters:		
			nID--the ID of the visual object you clicked
Return value:
			None
********************************************************************/
void CGeditorView::OnToolType(UINT nID)
//nID指明响应的BUTTON的ID,在ON_COMMAND_MAP中可见
{
    CGeditorDoc * pDoc=GetDocument();
	ASSERT_VALID(pDoc);
	pDoc->m_wToolType = (WORD)(nID-ID_TOOL_BASE);//从UINT型转为WORD型
//响应函数处理:将pDoc->m_wToolType赋为与BUTTON对应的值(nID-ID_TOOL_BASE) 
	
}

void CGeditorView::OnUpdateToolType(CCmdUI* pCmdUI)//同上
{
    CGeditorDoc * pDoc=GetDocument();
	ASSERT_VALID(pDoc);
	UINT nIndex = pDoc->m_wToolType;//从WORD型转为UINT型
	pCmdUI->SetCheck((UINT)(ID_TOOL_BASE+nIndex) == pCmdUI->m_nID);
    //m_nID为当前用户敲击的BUTTON的ID
}

void CGeditorView::SetPropChange(int styles)
{
	switch(styles)
	{
	case TOOL_PICK:
		break;
	case TOOL_LINE:

		break;
	case TOOL_RECTANGLE:
		break;

	case TOOL_POLYGON:
		break;

	case TOOL_ELLIPSE:
		break;

	case TOOL_BEZIER_CURVE:
		break;

	case TOOL_AREA_FILLING:
		break;

	case TOOL_CLIPPING:
		break;
    case TOOL_BRUSH:
		break;
    case TOOL_PEN:
		break;
    case TOOL_TEXT:
		break;
    case TOOL_RECT_SEL:
		break;
    case TOOL_IRRE_SEL:
		break;
    case TOOL_COPY:
		break;
    case TOOL_PASTE:
		break;
    case TOOL_CYCLE:
		break;
    case TOOL_MIRROR:
		break;
    case TOOL_MOVE:
		break;
	default:
		;
	} 

}

void CGeditorView::OnEditCut() 
{//直接指向旧图元,不必复制,do not do like next lines:
	TempObj=new CShape;//must new,else can't add to tail of list
	objtype='S';
	TempObj=NULL;
	CGeditorDoc *pDoc = (CGeditorDoc*)GetDocument();
	ASSERT_VALID(pDoc);
	if (CurObj!=NULL) 
	{
		TempObj=CurObj->copys(objtype);
		//want delete
		DeleteObj(objnumber);
	};
}

void CGeditorView::OnEditCopy() 
{
	TempObj=new CShape;
	objtype='S';
	TempObj=NULL;
	if (CurObj!=NULL) TempObj=CurObj->copys(objtype);
}

void CGeditorView::OnEditPaste() 
{
	CGeditorDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (TempObj!=NULL)
	{
//		Cprop *p=(Cprop*)AfxGetApp()->
//			   m_pMainWnd->GetDescendantWindow(IDD_PRPTBAR);
		//todo: change x and y point ...
		TempObj->SetColor(RGB(0,0,0));
		pDoc->objitems+=objtype;
		CPoint point;
		switch (objtype)
		{
		case 'L':
			pDoc->NumLine++;
			sprintf(nanum,"%2d",pDoc->NumLine);
			TempObj->name="Line#";
			TempObj->name+=nanum;
			break;
		case 'R':
			pDoc->NumRec++;
			sprintf(nanum,"%2d",pDoc->NumRec);
			TempObj->name="Rect#";
			TempObj->name+=nanum;
			break;
		case 'E':
			pDoc->NumEls++;
			sprintf(nanum,"%2d",pDoc->NumEls);
			TempObj->name="Ellipse#";
			TempObj->name+=nanum;
			break;
		case 'P':
			pDoc->NumPgn++;
			sprintf(nanum,"%2d",pDoc->NumPgn);
			TempObj->name="Poly#";
			TempObj->name+=nanum;
			break;
		case 'B':
			pDoc->NumBez++;
			sprintf(nanum,"%2d",pDoc->NumBez);
			TempObj->name="Bezier#";
			TempObj->name+=nanum;
			break;
		case 'T':
			pDoc->NumText++;
			sprintf(nanum,"%2d",pDoc->NumText);
			TempObj->name="Text#";
			TempObj->name+=nanum;
			break;
		default:
			break;
		}; //改进:用ChangeFocus(CurObj)更新焦点
		CPoint pt;
		pt.x=pt.y=0;
		if(CurObj!=NULL)
		{
			CurObj->dragmode=0;
			CurObj->dragobj(0,GetDC(),pt,this);
		};
//		p->m_name.AddString(TempObj->name);
		TempObj->InitProp();
		pDoc->CurObjNum=(pDoc->m_shapeList).GetCount();
//		p->m_name.SetCurSel(pDoc->CurObjNum);
		pDoc->m_shapeList.AddTail(TempObj);
		pDoc->SetModifiedFlag();
		CDC *pDC=GetDC();
		TempObj->Draw(pDC);
		CurObj=TempObj;
		TempObj=CurObj->copys(objtype);
//		p=NULL;
	}else CurObj=TempObj;
}

void CGeditorView::OnToolLes(UINT nID)
{
	CGeditorDoc * pDoc=GetDocument();
	ASSERT_VALID(pDoc);
	pDoc->m_wToolles = (WORD)(nID-ID_TOOL_LESBS);
}

void CGeditorView::OnUpdateToolles(CCmdUI *pCmdUI)
{
	CGeditorDoc * pDoc=GetDocument();
	ASSERT_VALID(pDoc);
	UINT nIndex = pDoc->m_wToolles;//从WORD型转为UINT型
	pCmdUI->SetCheck((UINT)(ID_TOOL_LESBS+nIndex) == pCmdUI->m_nID);

}

void CGeditorView::OnColor() 
{
//	Cprop *p=(Cprop*)AfxGetApp()->
//		m_pMainWnd->GetDescendantWindow(IDD_PRPTBAR);
	unsigned int m_curColor;
	CColorDialog ColorDlg(CurObj->m_color,0,NULL);
	CRect rect;
	rect.left=rect.top=2;
	rect.right=rect.bottom=17;
	    if (ColorDlg.DoModal()==IDOK) 
		{
			m_curColor=ColorDlg.GetColor();
			CBrush brush(m_curColor);
//			(p->m_colr).GetDC()->FillRect(&rect,&brush);
			if (CurObj!=NULL)
			{
				CurObj->SetColor(m_curColor);
				CurObj->Draw(GetDC());
			};
			brush.DeleteObject();
		}
		else 
		{
			CBrush brusha(CurObj->m_color);
//			(p->m_colr).GetDC()->FillRect(&rect,&brusha);
			DeleteObject(brusha);
		};
//	p=NULL;
}

void CGeditorView::OnUse() 
{
	if(CurObj!=NULL)
	{
	};
}

void CGeditorView::OnRadsolid() 
{
	if(CurObj!=NULL)
	{
		
		CurObj->invalid(this);
		CurObj->linesty=PS_SOLID;
		CurObj->dragmode=1;
		CurObj->Draw(GetDC());
	};
	
}

void CGeditorView::OnRaddot() 
{
	if(CurObj!=NULL)
	{
		CDC *pDC=GetDC();
		//CurObj->dragobj(0,pDC,RotPt,this);
		CurObj->invalid(this);
		CurObj->linesty=PS_DOT;
		CurObj->width=1;
		CurObj->dragmode=1;
		CurObj->Draw(pDC);
	};
}

void CGeditorView::OnRaddashdotdot() 
{
	if(CurObj!=NULL)
	{
		CurObj->invalid(this);
		CurObj->linesty=PS_DASHDOTDOT;
		CurObj->width=1;
		CurObj->dragmode=1;
		CurObj->Draw(GetDC());
	};
}

void CGeditorView::OnRaddashdot() 
{
	if(CurObj!=NULL)
	{
		CurObj->invalid(this);
		CurObj->linesty=PS_DASHDOT;
		CurObj->width=1;
		CurObj->dragmode=1;
		CurObj->Draw(GetDC());
	};
}

void CGeditorView::OnRaddash() 
{
	if(CurObj!=NULL)
	{
		CurObj->invalid(this);
		CurObj->linesty=PS_DASH;
		CurObj->width=1;
		CurObj->dragmode=1;
		CurObj->Draw(GetDC());
	};
}

void CGeditorView::OnSelendokObjname() 
{
	killFocus();
//	Cprop *p=(Cprop*)AfxGetApp()->
//		   m_pMainWnd->GetDescendantWindow(IDD_PRPTBAR);
	CGeditorDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
//	int index=p->m_name.GetCurSel();
//	CurObj=pDoc->m_shapeList.GetAt(pDoc->m_shapeList.FindIndex(index));
//	pDoc->CurObjNum=index;
	DragMode=1;
	setFocus();
//	p=NULL;
}

void CGeditorView::DeleteObj(int index)
{
	CGeditorDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	//int index=objnumber;
	if (index==pDoc->m_shapeList.GetCount())
		pDoc->m_shapeList.RemoveTail();
	else
		pDoc->m_shapeList.RemoveAt(pDoc->m_shapeList.FindIndex(index));
	pDoc->objitems.Delete(index);
	CurObj=NULL;
	Invalidate();
}

void CGeditorView::killFocus()//必须与getFocus成对调用 
{
	if (CurObj!=NULL)
	{
		CurObj->movept.x=0;
		CurObj->movept.y=0;
		CurObj->dragmode=0;
		CurObj->dragobj(0,GetDC(),CurObj->movept,this);
	};
}

void CGeditorView::setFocus()
{
	CGeditorDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	CurObj->dragmode=DragMode;
	CurObj->Draw(GetDC());
	objnumber=pDoc->CurObjNum;
}

void CGeditorView::OnBkcolor() 
{
	
}

void CGeditorView::OnChkfill() 
{
	if(CurObj!=NULL)
	{
		CurObj->invalid(this);
		CurObj->Draw(GetDC());
	};
}

⌨️ 快捷键说明

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