#include "StdAfx.h" #include "itemcircle.h" #include "SigmaDoc.h" namespace NItem { CItemCircle::CItemCircle(CSigmaDoc * ppDoc) : CItemEllipse(ppDoc) { this->SetType(ITEM_CIRCLE); } CItemCircle::~CItemCircle(void) { } BOOL CItemCircle::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) { return TRUE; //GetDoc()->GetCursor().SetCursor(CursorCrosshair); //return GetDoc()->GetCursor().SetCursor(); } void CItemCircle::OnLButtonDown(CDC *pDC, UINT nFlags, CPoint point, int vk) { CPoint2D dp = GetDC()->GetReal(point); m_downPoint=dp; m_upPoint=dp; DoDrawOther(pDC, 1); //GetView()->SetCapture(); } int CItemCircle::OnMouseMove(CDC *pDC, UINT nFlags, CPoint point) { if(!IsCaptureState()) return 1; CPoint2D dp=GetDC()->GetReal(point); DoDrawOther(pDC, 2); m_upPoint=dp; DoDrawOther(pDC, 2); return 1; } void CItemCircle::OnLButtonUp(CDC *pDC, UINT nFlags, CPoint point, int vk) { if(!IsCaptureState()) return; m_upPoint=GetDC()->GetReal(point); DoDrawOther(pDC, 3); ReleaseCapture(); if(AfxGetPublicFunction()->Distance2(m_downPoint.x0,m_downPoint.y0,m_upPoint.x0,m_upPoint.y0)<1e10) return; DoLButtonUp(pDC); } BOOL CItemCircle::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) { //switch(nChar) //{ //case VK_ESCAPE: // if(IsCaptureState()) // { // CRect8 rect=GetRect(); // DoDrawOther(3); // ReleaseCapture(); // return TRUE; // } // else // { // //GetDoc()->EnableDefaultTool(); // } // break; //} return FALSE; } void CItemCircle::DoLButtonUp(CDC *pDC) { CCircle* pc=new CCircle(); pc->x0=m_downPoint.x0; pc->y0=m_downPoint.y0; pc->m_size.cx=AfxGetPublicFunction()->Distance(m_downPoint.x0,m_downPoint.y0,m_upPoint.x0,m_upPoint.y0); pc->m_size.cx=pc->m_size.cy; if(GetDoc()->GetDraw()==NULL) {delete pc;return;} POSITION pos=AddElement(pc,DOUBLEFOX_CIRCLE); //GetDoc()->Select(pos); } void CItemCircle::DoDrawOther(CDC* pDC, int nButton) { CItemFocusRect::DoDrawOther(pDC, nButton); int od=GetDC()->GetDC()->SetROP2(R2_NOTXORPEN); GetDC()->Ellipse(m_downPoint.x0,m_downPoint.y0,m_upPoint.x0,m_upPoint.y0); GetDC()->GetDC()->SetROP2(od); } /* BOOL CItemCircle::InitPropertyGrid(CXTPPropertyGrid& grid) { if(!this->IsEditState()) return FALSE; CPropertyGridItemAdd ItemAdd(NULL); CXTPPropertyGridItem* pItem=grid.AddCategory(IDS_STRING_Circle); ItemAdd.SetItem(pItem); pItem->Expand(); CString strFormat=GetFloatFormatString(); COne* pOne=(COne*)GetDoc()->GetDraw()->GetAt(GetPos()); CCircle* pCircle=(CCircle*)pOne->GetValue(); m_point.SetPoint(pCircle->x0,pCircle->y0); ItemAdd.AddItemPoint(IDS_GI_CIRCLE_COOR, m_point, &m_point); ItemAdd.AddItemDouble(IDS_GI_CIRCLE_RADIUS, pCircle->m_size.cx, strFormat, NULL); m_dCurveWidth = GetUnitMode().toPrintUnit(pCircle->m_dCurveWidth); ItemAdd.AddItemUnitDouble(IDS_STRING_CURVE_WIDTH, GetUnit(), m_dCurveWidth, strFormat, &m_dCurveWidth); m_nWidthPosition=GetWdithPosition(pCircle); ItemAdd.AddItemCombo(IDS_GI_WIDTH_POSITION, IDS_GI_CURVE_WIDTH_POSITION, m_nWidthPosition, &m_nWidthPosition); ItemAdd.AddItemColor(IDS_GI_COLOR, pOne->color, NULL); CItem::InitPropertyGrid(grid); return TRUE; } BOOL CItemCircle::OnGridItemChangeValue(CXTPPropertyGridItem* pItem) { COne* pOne=(COne*)GetDoc()->GetDraw()->GetAt(GetPos()); CCircle* pCircle=(CCircle*)pOne->GetValue(); BOOL bUpdate=FALSE; switch(pItem->GetID()) { case IDS_GI_CIRCLE_COOR: pCircle->x0=m_point.x0; pCircle->y0=m_point.y0; bUpdate=TRUE; break; case IDS_GI_CIRCLE_RADIUS: pCircle->m_size.cx = ((CXTPPropertyGridItemDouble*)pItem)->GetDouble(); pCircle->m_size.cy = pCircle->m_size.cx; bUpdate=TRUE; break; case IDS_STRING_CURVE_WIDTH: pCircle->m_dCurveWidth = GetUnitMode().toRealUnit(m_dCurveWidth); bUpdate=TRUE; break; case IDS_GI_WIDTH_POSITION: SetWidthPosition(pCircle, m_nWidthPosition); bUpdate=TRUE; break; case IDS_GI_COLOR: pOne->color = ((CXTPPropertyGridItemColor*)pItem)->GetColor(); bUpdate=TRUE; break; } return bUpdate | CItem::OnGridItemChangeValue(pItem); } */ int CItemEllipse::GetWdithPosition(CEllipse* pell) { int pos=0; switch(pell->GetWidthPosition()) { case CEllipse::posIn: pos=0; break; case CEllipse::posCenter: pos=1; break; case CEllipse::posOut: pos=2; break; } return pos; } void CItemEllipse::SetWidthPosition(CEllipse* pell, int nPos) { switch(nPos) { case 0: pell->SetWidthPosition(CEllipse::posIn); break; case 1: pell->SetWidthPosition(CEllipse::posCenter); break; case 2: pell->SetWidthPosition(CEllipse::posOut); break; } } }//namespace