📄 geditorview.cpp
字号:
m_hCrossCursor = AfxGetApp()->LoadStandardCursor(IDC_ARROW);
::SetCursor(m_hCrossCursor);
MouseDown=FALSE;
pDoc->SetModifiedFlag();
Invalidate();
break;
case TOOL_LINE:
if(m_wLButtonState == LBUTTONDOWN)
{
ASSERT_VALID(m_pCurLine);
//Set the end point of the line to point
m_pCurLine->SetEndPt(point);
//Add the line to m_lineList.
NoMove=FALSE;
pDoc->objitems+="L";
pDoc->m_shapeList.AddTail(m_pCurLine);
pDoc->SetModifiedFlag();
CurObj=m_pCurLine;
//After having inserted a line, let "m_ptCurLine" to be "NULL".
m_pCurLine = NULL;
}//end of if
Invalidate();
break;
case TOOL_RECTANGLE:
if(m_wLButtonState == LBUTTONDOWN)
{
ASSERT_VALID(m_pCurRect);
m_pCurRect->SetRect(m_tAnchorPt,point);
pDoc->objitems+="R";
pDoc->m_shapeList.AddTail(m_pCurRect);
pDoc->SetModifiedFlag();
CurObj=m_pCurRect;
m_pCurRect = NULL;
};
Invalidate();
break;
case TOOL_POLYGON:
if((m_wLButtonState == LBUTTONDOWN)&&(polypt!=point))
{
ASSERT_VALID(m_pCurPgn);
m_pCurPgn->AddPoint(point);
polypt=point;
}
break;
case TOOL_ELLIPSE:
if(m_wLButtonState == LBUTTONDOWN)
{
ASSERT_VALID(m_pCurEllipse);
m_pCurEllipse->BeSeled=1;
m_pCurEllipse->SetBox(m_tAnchorPt,point);
pDoc->objitems+="E";
pDoc->m_shapeList.AddTail(m_pCurEllipse);
pDoc->SetModifiedFlag();
CurObj=m_pCurEllipse;
m_pCurEllipse = NULL;
};
Invalidate();
break;
case TOOL_BEZIER_CURVE:
if(m_wLButtonState == LBUTTONDOWN)
{
ASSERT_VALID(m_pCurBezier);
m_pCurBezier->Draw(pClientDC);
m_pCurBezier->SetCtlPt(point,m_wBezierIndex);
switch(m_wBezierIndex)
{
case 1:
m_wBezierIndex = 2;
m_pCurBezier->Draw(pClientDC);
break;
case 2: //The end of bezier curve inserting.
m_pCurBezier->Draw(pClientDC);
m_wBezierIndex = 0;
m_pCurBezier->Curptnum=0;
Invalidate();
m_pCurBezier = NULL;
break;
case 3:
m_wBezierIndex = 1;
m_pCurBezier->SetCtlPt(point,2);
m_pCurBezier->Curptnum=2;
m_pCurBezier->Draw(pClientDC);
break;
default:
MessageBox("Bad value of m_wBezierIndex!");
};//end of switch
}
break;
case TOOL_AREA_FILLING:
break;
case TOOL_CLIPPING:
MessageBox("The function is not available!");
break;
case TOOL_BRUSH:
CurObj->invalid(this);
// MessageBox("The function is not available!");
break;
case TOOL_PEN:
MessageBox("The function is not available!");
break;
case TOOL_TEXT:
if(myFont.DoModal()==IDOK)
{
logs=myFont.log;
color=myFont.color;
m_text=new CText(logs,point,myFont.color,myFont.m_text);
m_text->SetColor(pDoc->m_curColor);
pDoc->NumText++;
sprintf(nanum,"%2d",pDoc->NumText);
m_text->name="Text#";
m_text->name+=nanum;
// p->m_name.AddString(m_text->name);
pDoc->CurObjNum=(pDoc->m_shapeList).GetCount();
// p->m_name.SetCurSel(pDoc->CurObjNum);
pDoc->m_shapeList.AddTail(m_text);
pDoc->objitems+="T";
pDoc->SetModifiedFlag();
m_text->InitProp();
m_text->Draw(pClientDC);
CurObj=m_text;
m_text = NULL;
};
break;
case TOOL_RECT_SEL:
MessageBox("The function is not available!");
break;
case TOOL_IRRE_SEL:
MessageBox("The function is not available!");
break;
case TOOL_COPY:
MessageBox("The function is not available!");
break;
case TOOL_PASTE:
MessageBox("The function is not available!");
break;
case TOOL_CYCLE:
MouseDown=FALSE;
break;
case TOOL_MIRROR:
if (CurObj!=NULL)
{
CurObj->dragmode=10;
//mirror duichenzhou 0:x;1:y;2:O
CurObj->Mirror(pDoc->m_wToolles,GetDC(),point,this);
};
break;
case TOOL_MOVE:
MessageBox("The function is not available!");
break;
default:
break;
}//end of switch
DeleteObject(curPen);
DeleteObject(curBrush);
pClientDC->SelectObject(oldPen);
pClientDC->SelectObject(oldBrush);
pClientDC->SetROP2(oldROP2);
//Release the "pClientDC".
ReleaseDC(pClientDC);
//Set the m_wLButtonState to LBUTTONDOWN
m_wLButtonState = LBUTTONUP;
//Call default
CScrollView::OnLButtonUp(nFlags, point);
}
void CGeditorView::OnLButtonDown(UINT nFlags, CPoint point)
{
//pp.UpdateData(FALSE);
// TODO: Add your message handler code here and/or call default
int oldROP2;
CDC* pClientDC = GetDC();
ASSERT_VALID(pClientDC);
pClientDC->DPtoLP(&point);
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);
oldROP2 = pClientDC->SetROP2(R2_NOTXORPEN);
//Keep the cursor within the client area.
SetCapture();
RECT rect;
GetClientRect(&rect);
ClientToScreen(&rect);
::ClipCursor(&rect);
//Set cursor to Cross shape
::SetCursor(m_hCrossCursor);
// Cprop *p=(Cprop*)AfxGetApp()->
// m_pMainWnd->GetDescendantWindow(IDD_PRPTBAR);
killFocus();//使原来的图元失去焦点
switch(pDoc->m_wToolType)
{
case TOOL_PICK:
CurObj=NextObj;
if (CurObj!=NULL)
{
setFocus();
::SetCursor(AfxGetApp()->LoadCursor(IDC_CURTAKE));
CurObj->movept=point;
MouseDown=TRUE;
CurObj->dragobj(pDoc->m_wToolles,GetDC(),point,this);
//SetCurSel start from 0
};
//GetA
break;
case TOOL_LINE:
//Create a new line object
m_pCurLine = new CLine;
//Set both of the line verteces to point
//1.Add Number of Line,for line name.
pDoc->NumLine++;
sprintf(nanum,"%2d",pDoc->NumLine);
m_pCurLine->name="Line#";
m_pCurLine->name+=nanum;
//2.show Start point.
//3.Show name
// p->m_name.AddString(m_pCurLine->name);
pDoc->CurObjNum=(pDoc->m_shapeList).GetCount();
// p->m_name.SetCurSel(pDoc->CurObjNum);
NoMove=TRUE;
//师:面向对象风格,全部由内部函数实现-》
m_pCurLine->SetStartPt(point);
m_pCurLine->SetEndPt(point);
m_pCurLine->SetColor(pDoc->m_curColor);
m_pCurLine->InitProp();
//Use R2_XORPEN mode to draw the line
m_pCurLine->Draw(pClientDC);
//Recover the old drawing mode
break;
case TOOL_RECTANGLE:
m_tAnchorPt = point;
m_tPrevPt = point;
m_pCurRect = new CMyRect(point,point);
m_pCurRect->SetColor(pDoc->m_curColor);
pDoc->NumRec++;
sprintf(nanum,"%2d",pDoc->NumRec);
m_pCurRect->name="Rect#";
m_pCurRect->name+=nanum;
// p->m_name.AddString(m_pCurRect->name);
pDoc->CurObjNum=(pDoc->m_shapeList).GetCount();
// p->m_name.SetCurSel(pDoc->CurObjNum);
//Draw the current rectangle
m_pCurRect->InitProp();
m_pCurRect->Draw(pClientDC);
break;
case TOOL_POLYGON:
if(m_pCurPgn == NULL) //Begin to insert a polygon.
{
//construct a new polygon
m_pCurPgn = new CPolygon;
//add the point into polygon vertex array.
m_pCurPgn->AddPoint(point);
m_pCurPgn->SetColor(pDoc->m_curColor);
pDoc->NumPgn++;
sprintf(nanum,"%2d",pDoc->NumPgn);
m_pCurPgn->name="Pgn#";
m_pCurPgn->name+=nanum;
m_pCurPgn->InitProp();
// p->m_name.AddString(m_pCurPgn->name);
pDoc->CurObjNum=(pDoc->m_shapeList).GetCount();
// p->m_name.SetCurSel(pDoc->CurObjNum);
};
m_tPrevPt = point;
pClientDC->MoveTo(m_pCurPgn->GetTail());
pClientDC->LineTo(point);
break;
case TOOL_ELLIPSE:
m_tAnchorPt = point;
m_tPrevPt = point;
m_pCurEllipse = new CEllipse(m_tAnchorPt,m_tPrevPt);
m_pCurEllipse->SetColor(pDoc->m_curColor);
pDoc->NumEls++;
sprintf(nanum,"%2d",pDoc->NumEls);
m_pCurEllipse->name="Ellipse#";
m_pCurEllipse->name+=nanum;
m_pCurEllipse->InitProp();
// p->m_name.AddString(m_pCurEllipse->name);
pDoc->CurObjNum=(pDoc->m_shapeList).GetCount();
// p->m_name.SetCurSel(pDoc->CurObjNum);
m_pCurEllipse->Draw(pClientDC);
break;
case TOOL_BEZIER_CURVE:
if(m_pCurBezier == NULL) //Begin to insert a Bezier curve.
{
m_pCurBezier = new CBezier;
ASSERT_VALID(m_pCurBezier);
m_pCurBezier->SetColor(pDoc->m_curColor);
//Set the first control point.
m_pCurBezier->SetCtlPt(point,0);
m_pCurBezier->SetCtlPt(point,1);
m_pCurBezier->SetCtlPt(point,2);
m_pCurBezier->SetCtlPt(point,3);
m_pCurBezier->Curptnum=1;
m_wBezierIndex = 3;
pDoc->NumBez++;
sprintf(nanum,"%2d",pDoc->NumBez);
m_pCurBezier->name="Bezier#";
m_pCurBezier->name+=nanum;
// p->m_name.AddString(m_pCurBezier->name);
pDoc->CurObjNum=(pDoc->m_shapeList).GetCount();
// p->m_name.SetCurSel(pDoc->CurObjNum);
m_pCurBezier->InitProp();
pDoc->objitems+="B";
pDoc->m_shapeList.AddTail(m_pCurBezier);
pDoc->SetModifiedFlag();
CurObj=m_pCurBezier;
m_pCurBezier->Draw(pClientDC);
}
else
{
ASSERT_VALID(m_pCurBezier);
//Erase the previous bezier curve.
m_pCurBezier->Draw(pClientDC);
ASSERT((m_wBezierIndex == 1) || (m_wBezierIndex == 2));
if (m_wBezierIndex==1)
{
m_pCurBezier->Curptnum=3;
m_pCurBezier->SetCtlPt(point,m_wBezierIndex);
m_pCurBezier->Draw(pClientDC);
}
else
{
m_pCurBezier->Curptnum=4;
m_pCurBezier->dragmode=10;
m_pCurBezier->SetCtlPt(point,m_wBezierIndex);
m_pCurBezier->Draw(pClientDC);
};
}
//draw the update bezier curve.
//Recover the old drawing mode.
break;
case TOOL_AREA_FILLING:
m_fill=new FillPat(point,pDoc->m_curColor);
m_fill->name="Fill";
pDoc->objitems+="F";
pDoc->m_shapeList.AddTail(m_fill);
pDoc->SetModifiedFlag();
m_fill->Draw(pClientDC);
CurObj=m_fill;
m_fill=NULL;
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:
CurObj=NextObj;
if (CurObj!=NULL)
{
CurObj->dragmode=DragMode;
MouseDown=TRUE;
// p->m_name.SetCurSel(pDoc->CurObjNum);
// p->OtherShow(CurObj->m_color,CurObj->width,CurObj->linesty);
if((rotatebaseptflag==0)&&((DragMode>0)&&(DragMode<10)))
{
CurObj->CalForRot(point);
rotatebaseptflag=1;
};
};
break;
case TOOL_MIRROR:
break;
case TOOL_MOVE:
break;
default:
;
}//end of switch
//创建图元时,可以公用w=...
objnumber=pDoc->CurObjNum;
pClientDC->SelectObject(oldPen);
pClientDC->SelectObject(oldBrush);
pClientDC->SetROP2(oldROP2);
DeleteObject(curPen);
DeleteObject(curBrush);
ReleaseDC(pClientDC);
//Set the m_wLButtonState to LBUTTONDOWN
m_wLButtonState = LBUTTONDOWN;
// p=NULL;
//Call default
CScrollView::OnLButtonDown(nFlags, point);
}
void CGeditorView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -