MyDrawView.docx
- 文档编号:6824223
- 上传时间:2023-01-10
- 格式:DOCX
- 页数:29
- 大小:20.20KB
MyDrawView.docx
《MyDrawView.docx》由会员分享,可在线阅读,更多相关《MyDrawView.docx(29页珍藏版)》请在冰豆网上搜索。
MyDrawView
MyDrawView.cpp
//MyDrawView.cpp:
implementationoftheCMyDrawViewclass
//
#include"stdafx.h"
#include"MyDraw.h"
#include"MyDrawDoc.h"
#include"MyDrawView.h"
#include"Ellipse.h"
#include"Line.h"
#include"LineProperties.h"
#include"EllipseProperties.h"
#include"Rectangle.h"
#include"Text.h"
#include"TextProperties.h"
#ifdef_DEBUG
#definenewDEBUG_NEW
#undefTHIS_FILE
staticcharTHIS_FILE[]=__FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
//CMyDrawView
IMPLEMENT_DYNCREATE(CMyDrawView,CView)
BEGIN_MESSAGE_MAP(CMyDrawView,CView)
//{{AFX_MSG_MAP(CMyDrawView)
ON_WM_LBUTTONDOWN()
ON_WM_SETCURSOR()
ON_WM_LBUTTONDBLCLK()
ON_COMMAND(ID_BUTTON_LINE,OnButtonLine)
ON_COMMAND(ID_BUTTON_ELLIPSE,OnButtonEllipse)
ON_COMMAND(ID_BUTTON_RECTANGLE,OnButtonRectangle)
ON_COMMAND(ID_BUTTON_ARC,OnButtonArc)
ON_WM_KEYUP()
ON_COMMAND(ID_BUTTON_TEXT,OnButtonText)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
//CMyDrawViewconstruction/destruction
CMyDrawView:
:
CMyDrawView()
{
//TODO:
addconstructioncodehere
m_tracker.m_nStyle=CRectTracker:
:
resizeInside|
CRectTracker:
:
dottedLine;
m_tracker.m_rect.SetRect(0,0,0,0);
m_tracker.m_nHandleSize=8;
}
CMyDrawView:
:
~CMyDrawView()
{
}
BOOLCMyDrawView:
:
PreCreateWindow(CREATESTRUCT&cs)
{
//TODO:
ModifytheWindowclassorstylesherebymodifying
//theCREATESTRUCTcs
returnCView:
:
PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
//CMyDrawViewdrawing
voidCMyDrawView:
:
OnDraw(CDC*pDC)
{
CMyDrawDoc*pDoc=GetDocument();
ASSERT_VALID(pDoc);
//TODO:
adddrawcodefornativedatahere
POSITIONpos=m_ObjectList.GetHeadPosition();
CEllipse*pEllipse=NULL;
CLine*pLine=NULL;
CRectangle*pRectangle=NULL;
CArc*pArc=NULL;
CText*pText=NULL;
CObject*pObject=NULL;
while(pos!
=NULL)
{
pObject=(CObject*)m_ObjectList.GetNext(pos);
if(pObject->IsKindOf(RUNTIME_CLASS(CEllipse)))
{
pEllipse=(CEllipse*)pObject;
if(pEllipse!
=NULL)
{
if(pEllipse->bIsSelected)
{
pEllipse->startX=m_tracker.m_rect.left;
pEllipse->startY=m_tracker.m_rect.top;
pEllipse->endX=m_tracker.m_rect.right;
pEllipse->endY=m_tracker.m_rect.bottom;
}
DrawEllipse(pDC,pEllipse);
if(pEllipse->bIsSelected)
{
m_tracker.Draw(pDC);
}
}
}
elseif(pObject->IsKindOf(RUNTIME_CLASS(CLine)))
{
pLine=(CLine*)pObject;
if(pLine!
=NULL)
{
if(pLine->bIsSelected)
{
pLine->startX=m_tracker.m_rect.left;
pLine->startY=m_tracker.m_rect.top;
pLine->endX=m_tracker.m_rect.right;
pLine->endY=m_tracker.m_rect.bottom;
}
DrawLine(pDC,pLine);
if(pLine->bIsSelected)
{
m_tracker.Draw(pDC);
}
}
}
elseif(pObject->IsKindOf(RUNTIME_CLASS(CArc)))
{
pArc=(CArc*)pObject;
if(pArc!
=NULL)
{
if(pArc->bIsSelected)
{
pArc->startX=m_tracker.m_rect.left;
pArc->startY=m_tracker.m_rect.top;
pArc->endX=m_tracker.m_rect.right;
pArc->endY=m_tracker.m_rect.bottom;
}
DrawArc(pDC,pArc);
if(pArc->bIsSelected)
{
m_tracker.Draw(pDC);
}
}
}
elseif(pObject->IsKindOf(RUNTIME_CLASS(CText)))
{
pText=(CText*)pObject;
if(pText!
=NULL)
{
if(pText->bIsSelected)
{
pText->startX=m_tracker.m_rect.left;
pText->startY=m_tracker.m_rect.top;
pText->endX=m_tracker.m_rect.right;
pText->endY=m_tracker.m_rect.bottom;
}
DrawMyText(pDC,pText);
if(pText->bIsSelected)
{
m_tracker.Draw(pDC);
}
}
}
elseif(pObject->IsKindOf(RUNTIME_CLASS(CRectangle)))
{
pRectangle=(CRectangle*)pObject;
if(pRectangle!
=NULL)
{
if(pRectangle->bIsSelected)
{
pRectangle->startX=m_tracker.m_rect.left;
pRectangle->startY=m_tracker.m_rect.top;
pRectangle->endX=m_tracker.m_rect.right;
pRectangle->endY=m_tracker.m_rect.bottom;
}
DrawRectangle(pDC,pRectangle);
if(pRectangle->bIsSelected)
{
m_tracker.Draw(pDC);
}
}
}
}
}
/////////////////////////////////////////////////////////////////////////////
//CMyDrawViewdiagnostics
#ifdef_DEBUG
voidCMyDrawView:
:
AssertValid()const
{
CView:
:
AssertValid();
}
voidCMyDrawView:
:
Dump(CDumpContext&dc)const
{
CView:
:
Dump(dc);
}
CMyDrawDoc*CMyDrawView:
:
GetDocument()//non-debugversionisinline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDrawDoc)));
return(CMyDrawDoc*)m_pDocument;
}
#endif//_DEBUG
/////////////////////////////////////////////////////////////////////////////
//CMyDrawViewmessagehandlers
voidCMyDrawView:
:
OnLButtonDown(UINTnFlags,CPointpoint)
{
//TODO:
Addyourmessagehandlercodehereand/orcalldefault
CEllipse*pEllipse=NULL;
CLine*pLine=NULL;
CRectangle*pRectangle=NULL;
CArc*pArc=NULL;
CText*pText=NULL;
POSITIONpos=m_ObjectList.GetHeadPosition();
CObject*pHitItem;
while(pos!
=NULL)
{
pHitItem=(CObject*)m_ObjectList.GetNext(pos);
if(pHitItem->IsKindOf(RUNTIME_CLASS(CEllipse)))
{
pEllipse=(CEllipse*)pHitItem;
if(pEllipse!
=NULL)
{
CRectrc;
rc.left=pEllipse->startX;
rc.top=pEllipse->startY;
rc.right=pEllipse->endX;
rc.bottom=pEllipse->endY;
if(rc.PtInRect(point))
{
ClearSelection();
pEllipse->bIsSelected=true;
m_tracker.m_rect.SetRect(pEllipse->startX,pEllipse->startY,
pEllipse->endX,pEllipse->endY);
}
else
{
pEllipse->bIsSelected=false;
}
}
}
elseif(pHitItem->IsKindOf(RUNTIME_CLASS(CLine)))
{
pLine=(CLine*)pHitItem;
if(pLine!
=NULL)
{
CRectrc(pLine->startX,pLine->startY,pLine->endX,pLine->endY);
if(rc.PtInRect(point))
{
ClearSelection();
pLine->bIsSelected=true;
m_tracker.m_rect.SetRect(pLine->startX,pLine->startY,
pLine->endX,pLine->endY);
}
else
{
pLine->bIsSelected=false;
}
}
}
elseif(pHitItem->IsKindOf(RUNTIME_CLASS(CArc)))
{
pArc=(CArc*)pHitItem;
if(pArc!
=NULL)
{
CRectrc(pArc->startX,pArc->startY,pArc->endX,pArc->endY);
if(rc.PtInRect(point))
{
ClearSelection();
pArc->bIsSelected=true;
m_tracker.m_rect.SetRect(pArc->startX,pArc->startY,
pArc->endX,pArc->endY);
}
else
{
pArc->bIsSelected=false;
}
}
}
elseif(pHitItem->IsKindOf(RUNTIME_CLASS(CText)))
{
pText=(CText*)pHitItem;
if(pText!
=NULL)
{
CRectrc(pText->startX,pText->startY,pText->endX,pText->endY);
if(rc.PtInRect(point))
{
ClearSelection();
pText->bIsSelected=true;
m_tracker.m_rect.SetRect(pText->startX,pText->startY,
pText->endX,pText->endY);
}
else
{
pText->bIsSelected=false;
}
}
}
elseif(pHitItem->IsKindOf(RUNTIME_CLASS(CRectangle)))
{
pRectangle=(CRectangle*)pHitItem;
if(pRectangle!
=NULL)
{
CRectrc;
rc.left=pRectangle->startX;
rc.top=pRectangle->startY;
rc.right=pRectangle->endX;
rc.bottom=pRectangle->endY;
if(rc.PtInRect(point))
{
ClearSelection();
pRectangle->bIsSelected=true;
m_tracker.m_rect.SetRect(pRectangle->startX,
pRectangle->startY,pRectangle->endX,pRectangle->endY);
}
else
{
pRectangle->bIsSelected=false;
}
}
}
}
m_tracker.Track(this,point);//显示调节框
Invalidate();
}
BOOLCMyDrawView:
:
OnSetCursor(CWnd*pWnd,UINTnHitTest,UINTmessage)
{
//TODO:
Addyourmessagehandlercodehereand/orcalldefault
//鼠标移动到调节框范围内时,改变鼠标指针形状,指示可以拖动或改变绘图元素
if(m_tracker.SetCursor(pWnd,nHitTest))
returntrue;
returnCView:
:
OnSetCursor(pWnd,nHitTest,message);
}
voidCMyDrawView:
:
ClearSelection()
{
CObject*pHitItem=NULL;
POSITIONpos=m_ObjectList.GetHeadPosition();
CEllipse*pEllipse=NULL;
CLine*pLine=NULL;
CRectangle*pRectangle=NULL;
CArc*pArc=NULL;
CText*pText=NULL;
while(pos!
=NULL)
{
pHitItem=(CObject*)m_ObjectList.GetNext(pos);
if(pHitItem->IsKindOf(RUNTIME_CLASS(CEllipse)))
{
pEllipse=(CEllipse*)pHitItem;
if(pEllipse!
=NULL)
{
pEllipse->bIsSelected=false;
}
}
elseif(pHitItem->IsKindOf(RUNTIME_CLASS(CLine)))
{
pLine=(CLine*)pHitItem;
if(pLine!
=NULL)
{
pLine->bIsSelected=false;
}
}
elseif(pHitItem->IsKindOf(RUNTIME_CLASS(CRectangle)))
{
pRectangle=(CRectangle*)pHitItem;
if(pRectangle!
=NULL)
{
pRectangle->bIsSelected=false;
}
}
elseif(pHitItem->IsKindOf(RUNTIME_CLASS(CArc)))
{
pArc=(CArc*)pHitItem;
if(pArc!
=NULL)
{
pArc->bIsSelected=false;
}
}
elseif(pHitItem->IsKindOf(RUNTIME_CLASS(CText)))
{
pText=(CText*)pHitItem;
if(pText!
=NULL)
{
pText->bIsSelected=false;
}
}
}
return;
}
voidCMyDrawView:
:
DrawLine(CDC*pDC,CLine*pLine)
{
CPencMyPen;
CPen*pOldPen;
cMyPen.CreatePenIndirect(&pLine->LinePen);
pOldPen=pDC->SelectObject(&cMyPen);
pDC->MoveTo(pLine->startX,pLine->startY);
pDC->LineTo(pLine->endX,pLine->endY);
pDC->SelectObject(pOldPen);
}
voidCMyDrawView:
:
DrawArc(CDC*pDC,CArc*pArc)
{
CPencMyPen;
CPen*pOldPen;
cMyPen.CreatePenIndirect(&pArc->LinePen);
pOldPen=pDC->SelectObject(&cMyPen);
if(pArc->Direction)
{
pDC->Arc(pArc->startX,pArc->startY,pArc->endX,pArc->endY,
pArc->startX,pArc->startY,pArc->endX,pArc->endY);
}
else
{
pDC->Arc(pArc->endX,pArc->endY,pArc->startX,pArc->startY,
pArc->endX,pArc->en
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- MyDrawView
![提示](https://static.bdocx.com/images/bang_tan.gif)