Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
DrawSysView.cpp
Package: 计算机图形学综合大程序.rar [view]
Upload User: taoguanmin
Upload Date: 2007-05-11
Package Size: 180k
Code Size: 38k
Category:
2D Graphic
Development Platform:
Visual C++
- // DrawSysView.cpp : implementation of the CDrawSysView class
- //
- #include "stdafx.h"
- #include "DrawSys.h"
- #include "math.h"
- #include "MainFrm.h"
- #include "DrawSysDoc.h"
- #include "DrawSysView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CDrawSysView
- IMPLEMENT_DYNCREATE(CDrawSysView, CView)
- BEGIN_MESSAGE_MAP(CDrawSysView, CView)
- //{{AFX_MSG_MAP(CDrawSysView)
- ON_COMMAND(IDM_LINE, OnLine)
- ON_COMMAND(IDM_CIRCLE, OnCircle)
- ON_UPDATE_COMMAND_UI(IDM_LINE, OnUpdateLine)
- ON_UPDATE_COMMAND_UI(IDM_CIRCLE, OnUpdateCircle)
- ON_WM_LBUTTONDOWN()
- ON_WM_LBUTTONUP()
- ON_WM_MOUSEMOVE()
- ON_COMMAND(IDM_DDA, OnDda)
- ON_COMMAND(IDM_BRESENHAM, OnBresenham)
- ON_COMMAND(IDM_SET, OnSet)
- ON_COMMAND(IDM_MANYBD, OnManybd)
- ON_UPDATE_COMMAND_UI(IDM_MANYBD, OnUpdateManybd)
- ON_WM_LBUTTONDBLCLK()
- ON_COMMAND(IDM_CUT, OnCut)
- ON_UPDATE_COMMAND_UI(IDM_CUT, OnUpdateCut)
- ON_WM_RBUTTONDOWN()
- ON_WM_RBUTTONUP()
- ON_WM_RBUTTONDBLCLK()
- ON_COMMAND(IDM_BEZIER, OnBezier)
- ON_UPDATE_COMMAND_UI(IDM_BEZIER, OnUpdateBezier)
- ON_COMMAND(IDM_TEXT, OnText)
- ON_COMMAND(IDM_CLEAR, OnClear)
- ON_COMMAND(IDM_STROKE, OnStroke)
- ON_UPDATE_COMMAND_UI(IDM_STROKE, OnUpdateStroke)
- ON_UPDATE_COMMAND_UI(IDM_TEXT, OnUpdateText)
- ON_COMMAND(IDM_TEST, OnTest)
- ON_COMMAND(IDM_RANDLINE, OnRandline)
- ON_COMMAND(IDM_REFRESH, OnRefresh)
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CDrawSysView construction/destruction
- CDrawSysView::CDrawSysView()
- {
- // TODO: add construction code here
- m_dsDrawSort=DsNull;
- m_dlsDrawLSort=DlsBresenham;
- m_startPoint.x=0;
- m_startPoint.y=0;
- m_endPoint.x=0;
- m_endPoint.y=0;
- m_bIsMouseDown=0;
- m_bIsFirstDone=0;
- m_bIsDel=0;
- m_lPenColor=RGB(0,0,255);
- m_lBkColor=RGB(255,255,255);
- m_lFillColor=RGB(255,0,0);
- m_iPenWidth=1;
- m_lPenColor=RGB(0,0,255);
- m_dlsDrawLSort=DlsBresenham;
- m_hDLCursor=AfxGetApp()->LoadCursor(IDC_DRAWLINE);
- m_hDCCursor=AfxGetApp()->LoadCursor(IDC_DRAWCIRCLE);
- m_hCLCursor=AfxGetApp()->LoadCursor(IDC_CUTLINE);
- m_hDBCursor=AfxGetApp()->LoadCursor(IDC_DRAWBEZIER);
- m_hDTCursor=AfxGetApp()->LoadCursor(IDC_DRAWTEXT);
- m_hDSCursor=AfxGetApp()->LoadCursor(IDC_DRAWSTROKE);
- m_pwndStatusBar=0;
- }
- CDrawSysView::~CDrawSysView()
- {
- }
- BOOL CDrawSysView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CDrawSysView drawing
- void CDrawSysView::OnDraw(CDC* pDC)
- {
- CDrawSysDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- // TODO: add draw code for native data here
- list<LINE>::iterator pLine;
- list<CIRCLE>::iterator pCircle;
- list<BEZIER>::iterator pBezier;
- vector<TEXT>::iterator pText;
- //画直线
- for(pLine=m_listAllLine.begin();pLine!=m_listAllLine.end();pLine++)
- Line(*pLine,pDC);
- //画圆
- for(pCircle=m_listAllCircle.begin();pCircle!=m_listAllCircle.end();pCircle++)
- Circle(*pCircle,pDC);
- //画Bezier曲线
- for(pBezier=m_listBezier.begin();pBezier!=m_listBezier.end();pBezier++)
- Bezier(*pBezier,pDC);
- //画文本
- for(pText=m_vectorText.begin();pText!=m_vectorText.end();pText++)
- pDC->TextOut((*pText).p.x,(*pText).p.y,(*pText).str);
- CRect rectText;
- GetClientRect(&rectText);
- rectText.left=rectText.right-290;
- rectText.top=rectText.bottom-50;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CDrawSysView printing
- BOOL CDrawSysView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CDrawSysView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CDrawSysView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- /////////////////////////////////////////////////////////////////////////////
- // CDrawSysView diagnostics
- #ifdef _DEBUG
- void CDrawSysView::AssertValid() const
- {
- CView::AssertValid();
- }
- void CDrawSysView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CDrawSysDoc* CDrawSysView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDrawSysDoc)));
- return (CDrawSysDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CDrawSysView message handlers
- void CDrawSysView::OnLine()
- {
- // TODO: Add your command handler code here
- if(m_dsDrawSort!=DsLine)
- {
- TEXT tTemp;
- int nSize;
- CDC *pDC=GetDC();
- switch(m_dsDrawSort)
- {
- case DsManyBd:
- if(m_bIsFirstDone)
- {
- CDC *pDC=GetDC();
- LINE lTemp;
- Line(m_startPoint,m_spManyBd,pDC);
- lTemp.pStart=m_startPoint;
- lTemp.pEnd=m_spManyBd;
- m_listAllLine.push_back(lTemp);
- }
- break;
- case DsBezier:
- m_listBezier.push_back(m_vectorCurBezier);
- m_vectorCurBezier.clear();
- break;
- case DsText:
- m_edtTextIn.GetWindowText(tTemp.str);
- if(tTemp.str!="")
- {
- m_startPoint.y-=7;
- tTemp.p=m_startPoint;
- m_vectorText.push_back(tTemp);
- }
- m_edtTextIn.ShowWindow(0);
- m_edtTextIn.SetWindowText("");
- nSize=m_vectorText.size();
- if(nSize>0)
- pDC->TextOut(m_vectorText[nSize-1].p.x,m_vectorText[nSize-1].p.y,m_vectorText[nSize-1].str);
- break;
- }
- m_dsDrawSort=DsLine;
- }
- else
- m_dsDrawSort=DsNull;
- m_bIsFirstDone=0;
- m_bIsMouseDown=0;
- }
- void CDrawSysView::OnCircle()
- {
- // TODO: Add your command handler code here
- if(m_dsDrawSort!=DsCircle)
- {
- TEXT tTemp;
- int nSize;
- CDC *pDC=GetDC();
- switch(m_dsDrawSort)
- {
- case DsManyBd:
- if(m_bIsFirstDone)
- {
- CDC *pDC=GetDC();
- LINE lTemp;
- Line(m_startPoint,m_spManyBd,pDC);
- lTemp.pStart=m_startPoint;
- lTemp.pEnd=m_spManyBd;
- m_listAllLine.push_back(lTemp);
- }
- break;
- case DsBezier:
- m_listBezier.push_back(m_vectorCurBezier);
- m_vectorCurBezier.clear();
- break;
- case DsText:
- m_edtTextIn.GetWindowText(tTemp.str);
- if(tTemp.str!="")
- {
- m_startPoint.y-=7;
- tTemp.p=m_startPoint;
- m_vectorText.push_back(tTemp);
- }
- m_edtTextIn.ShowWindow(0);
- m_edtTextIn.SetWindowText("");
- nSize=m_vectorText.size();
- if(nSize>0)
- pDC->TextOut(m_vectorText[nSize-1].p.x,m_vectorText[nSize-1].p.y,m_vectorText[nSize-1].str);
- break;
- }
- m_dsDrawSort=DsCircle;
- }
- else
- m_dsDrawSort=DsNull;
- m_bIsFirstDone=0;
- m_bIsMouseDown=0;
- }
- void CDrawSysView::OnUpdateLine(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->SetCheck(m_dsDrawSort==DsLine);
- }
- void CDrawSysView::OnUpdateCircle(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->SetCheck(m_dsDrawSort==DsCircle);
- }
- void CDrawSysView::OnLButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- m_bIsMouseDown=1;
- if(m_dsDrawSort==DsNull)
- return;
- CDC *pDC=GetDC();
- LINE lTemp;
- CRect rect;
- TEXT tTemp;
- int nSize;
- DWORD dwStyle=WS_CHILD | ES_WANTRETURN | WS_TABSTOP;;
- pDC->SetROP2(R2_NOTXORPEN);
- switch(m_dsDrawSort)
- {
- case DsBezier:
- Bezier(m_vectorCurBezier,pDC);
- m_vectorCurBezier.push_back(point);
- Bezier(m_vectorCurBezier,pDC);
- break;
- case DsText:
- if(!m_edtTextIn)
- {
- if (!m_edtTextIn.CreateEx(WS_EX_CLIENTEDGE,_T("Edit"),NULL,
- dwStyle,CRect(0,0,0,0), this,IDC_EDIT_TEXTIN))
- {
- TRACE(_T("Failed to create Edit TextIn.n"));
- OnClose();
- }
- CFont *font = CFont::FromHandle((HFONT)::GetStockObject(DEFAULT_GUI_FONT));
- m_edtTextIn.SetFont(font);
- }
- rect.left=point.x;
- rect.bottom=point.y+10;
- rect.right=rect.left+90;
- rect.top=rect.bottom-20;
- m_edtTextIn.MoveWindow(&rect,1);
- m_edtTextIn.UpdateWindow();
- m_edtTextIn.ShowWindow(1);
- m_edtTextIn.GetWindowText(tTemp.str);
- if(tTemp.str!="")
- {
- m_startPoint.y-=7;
- tTemp.p=m_startPoint;
- m_vectorText.push_back(tTemp);
- }
- m_edtTextIn.SetWindowText("");
- nSize=m_vectorText.size();
- if(nSize>0)
- pDC->TextOut(m_vectorText[nSize-1].p.x,m_vectorText[nSize-1].p.y,m_vectorText[nSize-1].str);
- break;
- }
- if(m_dsDrawSort==DsManyBd && m_bIsFirstDone)
- {
- Line(m_startPoint,point,pDC);
- lTemp.pStart=m_startPoint;
- lTemp.pEnd=point;
- m_listAllLine.push_back(lTemp);
- }
- if(m_dsDrawSort!=DsManyBd || !m_bIsFirstDone)
- {
- m_endPoint.x=m_startPoint.x=point.x;
- m_endPoint.y=m_startPoint.y=point.y;
- }
- m_endPoint.x=point.x;
- m_endPoint.y=point.y;
- switch(m_dsDrawSort)
- {
- case DsLine:
- case DsManyBd:
- SetCursor(m_hDLCursor);
- break;
- case DsCircle:
- SetCursor(m_hDCCursor);
- break;
- case DsCutLine:
- SetCursor(m_hCLCursor);
- break;
- case DsBezier:
- SetCursor(m_hDBCursor);
- break;
- case DsText:
- SetCursor(m_hDTCursor);
- break;
- case DsStroke:
- SetCursor(m_hDSCursor);
- break;
- }
- CView::OnLButtonDown(nFlags, point);
- }
- void CDrawSysView::Line_DDA(POINT p1, POINT p2,CDC *pDC)
- {
- int i;
- if(p1.x==p2.x)
- {
- //为竖线
- if(p1.y<=p2.y)
- {
- for(i=p1.y;i<=p2.y;i++)
- pDC->SetPixel(p1.x,i,m_lPenColor);
- }
- else
- {
- for(i=p2.y;i<=p1.y;i++)
- pDC->SetPixel(p1.x,i,m_lPenColor);
- }
- return;
- }
- //为横线
- if(p1.y==p2.y)
- {
- if(p1.x<=p2.x)
- {
- for(i=p1.x;i<=p2.x;i++)
- pDC->SetPixel(i,p1.y,m_lPenColor);
- }
- else
- {
- for(i=p2.x;i<=p1.x;i++)
- pDC->SetPixel(i,p1.y,m_lPenColor);
- }
- return;
- }
- //为斜线
- float m=(p2.y-p1.y)*1.0/(p2.x-p1.x);
- float fTemp;
- if(abs(m)<=1)
- {
- if(p1.x<p2.x)
- {
- fTemp=p1.y-m;
- for(i=p1.x;i<=p2.x;i++)
- pDC->SetPixel(i,fTemp+=m,m_lPenColor);
- }
- else
- {
- fTemp=p2.y-m;
- for(i=p2.x;i<=p1.x;i++)
- pDC->SetPixel(i,fTemp+=m,m_lPenColor);
- }
- return;
- }
- if(p1.y<p2.y)
- {
- fTemp=p1.x-1/m;
- for(i=p1.y;i<=p2.y;i++)
- pDC->SetPixel(fTemp+=1/m,i,m_lPenColor);
- }
- else
- {
- fTemp=p2.x-1/m;
- for(i=p2.y;i<=p1.y;i++)
- pDC->SetPixel(fTemp+=1/m,i,m_lPenColor);
- }
- }
- void CDrawSysView::Line_Bresenham(POINT p1, POINT p2,CDC *pDC)
- {
- int i;
- if(p1.x==p2.x)
- {
- //为竖线
- if(p1.y<=p2.y)
- {
- for(i=p1.y;i<=p2.y;i++)
- pDC->SetPixel(p1.x,i,m_lPenColor);
- }
- else
- {
- for(i=p2.y;i<=p1.y;i++)
- pDC->SetPixel(p1.x,i,m_lPenColor);
- }
- return;
- }
- //为横线
- if(p1.y==p2.y)
- {
- if(p1.x<=p2.x)
- {
- for(i=p1.x;i<=p2.x;i++)
- pDC->SetPixel(i,p1.y,m_lPenColor);
- }
- else
- {
- for(i=p2.x;i<=p1.x;i++)
- pDC->SetPixel(i,p1.y,m_lPenColor);
- }
- return;
- }
- //为斜线
- float m=(p2.y-p1.y)*1.0/(p2.x-p1.x);
- float p;
- p=2*m-1;
- if(m>0 && m<=1)
- {
- if(p1.x<p2.x)
- {
- while(p1.x<=p2.x)
- {
- pDC->SetPixel(p1.x++,p1.y,m_lPenColor);
- if(p>=0)
- {
- p+=2*m-2;
- p1.y++;
- }
- else
- p+=2*m;
- }
- }
- else
- {
- while(p2.x<=p1.x)
- {
- pDC->SetPixel(p2.x++,p2.y,m_lPenColor);
- if(p>=0)
- {
- p+=2*m-2;
- p2.y++;
- }
- else
- p+=2*m;
- }
- }
- return;
- }
- p=-2*m-1;
- if(m<0 && m>=-1)
- {
- if(p1.x<p2.x)
- {
- while(p1.x<=p2.x)
- {
- pDC->SetPixel(p1.x++,p1.y,m_lPenColor);
- if(p>=0)
- {
- p+=-2*m-2;
- p1.y--;
- }
- else
- p+=-2*m;
- }
- }
- else
- {
- while(p2.x<=p1.x)
- {
- pDC->SetPixel(p2.x++,p2.y,m_lPenColor);
- if(p>=0)
- {
- p+=-2*m-2;
- p2.y--;
- }
- else
- p+=-2*m;
- }
- }
- return;
- }
- p=2/m-1;
- if(m>1)
- {
- if(p1.y<p2.y)
- {
- while(p1.y<=p2.y)
- {
- pDC->SetPixel(p1.x,p1.y++,m_lPenColor);
- if(p>=0)
- {
- p+=2/m-2;
- p1.x++;
- }
- else
- p+=2/m;
- }
- }
- else
- {
- while(p2.y<=p1.y)
- {
- pDC->SetPixel(p2.x,p2.y++,m_lPenColor);
- if(p>=0)
- {
- p+=2/m-2;
- p2.x++;
- }
- else
- p+=2/m;
- }
- }
- return;
- }
- p=-2/m-1;
- if(p1.y<p2.y)
- {
- while(p1.y<=p2.y)
- {
- pDC->SetPixel(p1.x,p1.y++,m_lPenColor);
- if(p>=0)
- {
- p+=-2/m-2;
- p1.x--;
- }
- else
- p+=-2/m;
- }
- }
- else
- {
- while(p2.y<=p1.y)
- {
- pDC->SetPixel(p2.x,p2.y++,m_lPenColor);
- if(p>=0)
- {
- p+=-2/m-2;
- p2.x--;
- }
- else
- p+=-2/m;
- }
- }
- }
- void CDrawSysView::OnLButtonUp(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- m_bIsMouseDown=0;
- if(m_dsDrawSort==DsNull)
- return;
- CDC *pDC=GetDC();
- CPen Pen;
- LINE lTemp;
- CIRCLE cTemp;
- int r;
- RECT rect;
- list<LINE>::iterator pLine=m_listAllLine.begin();
- list<LINE>::iterator pTemp;
- switch(m_dsDrawSort)
- {
- case DsManyBd:
- case DsLine:
- Line(m_startPoint,point,GetDC());
- lTemp.pStart=m_startPoint;
- lTemp.pEnd=point;
- m_listAllLine.push_back(lTemp);
- if(m_dsDrawSort==DsManyBd)
- m_startPoint=point;
- SetCursor(m_hDLCursor);
- break;
- case DsCircle:
- r=GetDist(m_startPoint,point);
- Circle(m_startPoint,r,pDC);
- cTemp.pMid=m_startPoint;
- cTemp.r=r;
- m_listAllCircle.push_back(cTemp);
- pDC->SetROP2(R2_NOTXORPEN);
- Line(m_startPoint,point,pDC);
- SetCursor(m_hDCCursor);
- break;
- case DsCutLine:
- rect.left=m_startPoint.x;
- rect.top=m_startPoint.y;
- rect.right=point.x;
- rect.bottom=point.y;
- while(pLine!=m_listAllLine.end())
- {
- CutLine(rect,*pLine);
- if(!(*pLine).pStart.x && !(*pLine).pStart.y && !(*pLine).pEnd.x && !(*pLine).pEnd.y)
- {
- pTemp=pLine;
- pTemp++;
- m_listAllLine.remove(*pLine);
- pLine=pTemp;
- }
- else
- pLine++;
- }
- GetClientRect(&rect);
- InvalidateRect(&rect,1);
- SetCursor(m_hCLCursor);
- break;
- case DsBezier:
- Bezier(m_vectorCurBezier,pDC);
- m_vectorCurBezier.pop_back();
- m_vectorCurBezier.push_back(point);
- Bezier(m_vectorCurBezier,pDC);
- SetCursor(m_hDBCursor);
- break;
- case DsText:
- SetCursor(m_hDTCursor);
- break;
- case DsStroke:
- SetCursor(m_hDSCursor);
- break;
- }
- CView::OnLButtonUp(nFlags, point);
- }
- void CDrawSysView::OnMouseMove(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- CString str;
- CDC *pDC=GetDC();
- str.Format("X:%d,Y:%d",point.x,point.y);
- if(!m_pwndStatusBar)
- m_pwndStatusBar=((CMainFrame*)AfxGetMainWnd())->GetStatusBar();
- m_pwndStatusBar->SetPaneText(1,str,1);
- if(m_dsDrawSort==DsNull)
- return;
- switch(m_dsDrawSort)
- {
- case DsLine:
- case DsManyBd:
- SetCursor(m_hDLCursor);
- break;
- case DsCircle:
- SetCursor(m_hDCCursor);
- break;
- case DsCutLine:
- SetCursor(m_hCLCursor);
- break;
- case DsBezier:
- SetCursor(m_hDBCursor);
- break;
- case DsText:
- SetCursor(m_hDTCursor);
- break;
- case DsStroke:
- SetCursor(m_hDSCursor);
- break;
- }
- if(!m_bIsMouseDown)
- return;
- CPen pen;
- CRect rect;
- list<LINE>::iterator p=m_listAllLine.end();
- vector<POINT>::iterator pVector=m_vectorCurBezier.end();
- pDC->SetROP2(R2_NOTXORPEN);
- switch(m_dsDrawSort)
- {
- case DsManyBd:
- p--;
- if((*p).pStart.x==m_startPoint.x && (*p).pStart.y==m_startPoint.y)
- m_listAllLine.pop_back();
- if(!m_bIsFirstDone)
- m_spManyBd=m_startPoint;
- m_bIsFirstDone=1;
- case DsLine:
- Line(m_startPoint,m_endPoint,pDC);
- Line(m_startPoint,point,pDC);
- break;
- case DsCircle:
- Line(m_startPoint,m_endPoint,pDC);
- Line(m_startPoint,point,pDC);
- Circle(m_startPoint,GetDist(m_startPoint,m_endPoint),pDC);
- Circle(m_startPoint,GetDist(m_startPoint,point),pDC);
- break;
- case DsCutLine:
- pen.CreatePen(PS_DOT,m_iPenWidth,m_lPenColor);
- pDC->SelectObject(&pen);
- pDC->Rectangle(&CRect(m_startPoint,m_endPoint));
- pDC->Rectangle(&CRect(m_startPoint,point));
- break;
- case DsBezier:
- Bezier(m_vectorCurBezier,pDC);
- m_vectorCurBezier.pop_back();
- m_vectorCurBezier.push_back(point);
- Bezier(m_vectorCurBezier,pDC);
- break;
- case DsStroke:
- pen.CreatePen(PS_SOLID,m_iPenWidth,m_lPenColor);
- pDC->SelectObject(&pen);
- pDC->MoveTo(m_endPoint);
- pDC->LineTo(point);
- break;
- }
- m_endPoint=point;
- CView::OnMouseMove(nFlags, point);
- }
- void CDrawSysView::Circle(POINT pc, int r,CDC *pDC)
- {
- int x,y;
- float p;
- pDC->SetViewportOrg(pc);
- x=0;
- y=r;
- p=1.25-r;
- while(x<=y+1)
- {
- //第1象限
- pDC->SetPixel(x,y,m_lPenColor);
- pDC->SetPixel(y,x,m_lPenColor);
- //第2象限
- pDC->SetPixel(-x,y,m_lPenColor);
- pDC->SetPixel(-y,x,m_lPenColor);
- //第3象限
- pDC->SetPixel(-y,-x,m_lPenColor);
- pDC->SetPixel(-x,-y,m_lPenColor);
- //第4象限
- pDC->SetPixel(x,-y,m_lPenColor);
- pDC->SetPixel(y,-x,m_lPenColor);
- x++;
- if(p>=0)
- {
- y--;
- p+=2*x+1-2*y;
- }
- else
- p+=2*x+1;
- }
- pDC->SetViewportOrg(0,0);
- }
- int CDrawSysView::GetDist(POINT p1, POINT p2)
- {
- return pow(pow(p1.y-p2.y,2)+pow(p1.x-p2.x,2),1.0/2);
- }
- void CDrawSysView::OnDda()
- {
- // TODO: Add your command handler code here
- m_dlsDrawLSort=DlsDDA;
- }
- void CDrawSysView::OnBresenham()
- {
- // TODO: Add your command handler code here
- m_dlsDrawLSort=DlsBresenham;
- }
- void CDrawSysView::OnSet()
- {
- // TODO: Add your command handler code here
- if(m_SetDlg.DoModal()==IDOK)
- {
- m_iPenWidth=m_SetDlg.GetPenWidth();
- m_lPenColor=m_SetDlg.GetPenColor();
- m_lBkColor=m_SetDlg.GetBkColor();
- m_lFillColor=m_SetDlg.GetFillColor();
- m_dlsDrawLSort=m_SetDlg.GetDrawLSort();
- CDC *pDC=GetDC();
- CPen Pen;
- pDC->SetBkColor(m_lBkColor);
- Pen.CreatePen(PS_SOLID,m_iPenWidth,m_lPenColor);
- pDC->SelectObject(&Pen);
- }
- }
- void CDrawSysView::OnManybd()
- {
- // TODO: Add your command handler code here
- if(m_dsDrawSort!=DsManyBd)
- {
- TEXT tTemp;
- int nSize;
- CDC *pDC=GetDC();
- switch(m_dsDrawSort)
- {
- case DsBezier:
- m_listBezier.push_back(m_vectorCurBezier);
- m_vectorCurBezier.clear();
- break;
- case DsText:
- m_edtTextIn.GetWindowText(tTemp.str);
- if(tTemp.str!="")
- {
- m_startPoint.y-=7;
- tTemp.p=m_startPoint;
- m_vectorText.push_back(tTemp);
- }
- m_edtTextIn.ShowWindow(0);
- m_edtTextIn.SetWindowText("");
- nSize=m_vectorText.size();
- if(nSize>0)
- pDC->TextOut(m_vectorText[nSize-1].p.x,m_vectorText[nSize-1].p.y,m_vectorText[nSize-1].str);
- break;
- }
- m_dsDrawSort=DsManyBd;
- }
- else
- {
- if(m_bIsFirstDone)
- {
- CDC *pDC=GetDC();
- LINE lTemp;
- Line(m_startPoint,m_spManyBd,pDC);
- lTemp.pStart=m_startPoint;
- lTemp.pEnd=m_spManyBd;
- m_listAllLine.push_back(lTemp);
- }
- m_dsDrawSort=DsNull;
- }
- m_bIsFirstDone=0;
- m_bIsMouseDown=0;
- }
- void CDrawSysView::OnUpdateManybd(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->SetCheck(m_dsDrawSort==DsManyBd);
- }
- void CDrawSysView::OnLButtonDblClk(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- if(m_dsDrawSort==DsNull)
- return;
- switch(m_dsDrawSort)
- {
- case DsLine:
- case DsManyBd:
- SetCursor(m_hDLCursor);
- break;
- case DsCircle:
- SetCursor(m_hDCCursor);
- break;
- case DsCutLine:
- SetCursor(m_hCLCursor);
- break;
- case DsBezier:
- SetCursor(m_hDBCursor);
- break;
- case DsText:
- SetCursor(m_hDTCursor);
- break;
- case DsStroke:
- SetCursor(m_hDSCursor);
- break;
- }
- CView::OnLButtonDblClk(nFlags, point);
- }
- void CDrawSysView::OnCut()
- {
- // TODO: Add your command handler code here
- if(m_dsDrawSort!=DsCutLine)
- {
- TEXT tTemp;
- int nSize;
- CDC *pDC=GetDC();
- switch(m_dsDrawSort)
- {
- case DsManyBd:
- if(m_bIsFirstDone)
- {
- CDC *pDC=GetDC();
- LINE lTemp;
- Line(m_startPoint,m_spManyBd,pDC);
- lTemp.pStart=m_startPoint;
- lTemp.pEnd=m_spManyBd;
- m_listAllLine.push_back(lTemp);
- }
- break;
- case DsBezier:
- m_listBezier.push_back(m_vectorCurBezier);
- m_vectorCurBezier.clear();
- break;
- case DsText:
- m_edtTextIn.GetWindowText(tTemp.str);
- if(tTemp.str!="")
- {
- m_startPoint.y-=7;
- tTemp.p=m_startPoint;
- m_vectorText.push_back(tTemp);
- }
- m_edtTextIn.ShowWindow(0);
- m_edtTextIn.SetWindowText("");
- nSize=m_vectorText.size();
- if(nSize>0)
- pDC->TextOut(m_vectorText[nSize-1].p.x,m_vectorText[nSize-1].p.y,m_vectorText[nSize-1].str);
- break;
- }
- m_dsDrawSort=DsCutLine;
- }
- else
- m_dsDrawSort=DsNull;
- m_bIsFirstDone=0;
- m_bIsMouseDown=0;
- }
- void CDrawSysView::OnUpdateCut(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->SetCheck(m_dsDrawSort==DsCutLine);
- }
- void CDrawSysView::CutLine(RECT rect,POINT& p1, POINT& p2)
- {
- //说明:此坐标为设备坐标
- int iRgnCode1=0;
- int iRgnCode2=0;
- int temp;
- POINT ptTemp;
- //使p1在前面
- if(p1.x>p2.x)
- {
- ptTemp=p1;
- p1=p2;
- p2=ptTemp;
- }
- //使bottom比top大,right比left大
- if(rect.bottom<rect.top)
- {
- temp=rect.bottom;
- rect.bottom=rect.top;
- rect.top=temp;
- }
- if(rect.right<rect.left)
- {
- temp=rect.right;
- rect.right=rect.left;
- rect.left=temp;
- }
- //----------求p1和p2的区域码----------
- if(p1.x<rect.left)
- iRgnCode1+=1;
- if(p1.x>rect.right)
- iRgnCode1+=1<<1;
- if(p1.y>rect.bottom)
- iRgnCode1+=1<<2;
- if(p1.y<rect.top)
- iRgnCode1+=1<<3;
- if(p2.x<rect.left)
- iRgnCode2+=1;
- if(p2.x>rect.right)
- iRgnCode2+=1<<1;
- if(p2.y>rect.bottom)
- iRgnCode2+=1<<2;
- if(p2.y<rect.top)
- iRgnCode2+=1<<3;
- //------------------------------------
- //被裁剪的线段在矩形内
- if(!iRgnCode1 && !iRgnCode2)
- return;
- //被裁剪的线段在矩形外
- if((iRgnCode1 & iRgnCode2)!=0 && (iRgnCode1 || iRgnCode2))
- {
- p1.x=p2.x=0;
- p1.y=p2.y=0;
- return;
- }
- //竖线
- if(p1.x==p2.x)
- {
- if(p1.y>p2.y)
- {
- temp=p1.y;
- p1.y=p2.y;
- p2.y=temp;
- }
- if(p1.y<rect.top)
- {
- p1.y=rect.top;
- if(p2.y>rect.bottom)
- p2.y=rect.bottom;
- return;
- }
- p2.y=rect.bottom;
- return;
- }
- //横线
- if(p1.y==p2.y)
- {
- if(p1.x<rect.left)
- {
- p1.x=rect.left;
- if(p2.x>rect.right)
- p2.x=rect.right;
- return;
- }
- p2.x=rect.right;
- return;
- }
- //斜线
- float m=(p2.y-p1.y)*1.0/(p2.x-p1.x);
- //---------------p1在矩形内,p2在矩形外---------------
- if(!iRgnCode1)
- {
- if(m<0)
- {
- p2.y=p1.y+(rect.right-p1.x)*m;
- if(p2.y>rect.top)
- {
- p2.x=rect.right;
- return;
- }
- p2.y=rect.top;
- p2.x=(p2.y-p1.y)/m+p1.x;
- return;
- }
- p2.y=p1.y+(rect.right-p1.x)*m;
- if(p2.y<rect.bottom)
- {
- p2.x=rect.right;
- return;
- }
- p2.y=rect.bottom;
- p2.x=(p2.y-p1.y)/m+p1.x;
- return;
- }
- //---------------------------------------------------
- //---------------p1在矩形外,p2在矩形内---------------
- if(!iRgnCode2)
- {
- if(m<0)
- {
- p1.y=p2.y-m*(p2.x-rect.left);
- if(p1.y<rect.bottom)
- {
- p1.x=rect.left;
- return;
- }
- p1.y=rect.bottom;
- p1.x=p2.x-(p2.y-p1.y)/m;
- return;
- }
- p1.y=p2.y-m*(p2.x-rect.left);
- if(p1.y>rect.top)
- {
- p1.x=rect.left;
- return;
- }
- p1.y=rect.top;
- p1.x=p2.x-(p2.y-p1.y)/m;
- return;
- }
- //---------------------------------------------------
- //---------------两点都在矩形外---------------
- //iRgnCode1==9 || 1 || 5
- if(p1.x<rect.left)
- {
- if(iRgnCode1==9)
- {
- if(m<0)
- {
- p1.x=p2.x=0;
- p1.y=p2.y=0;
- return;
- }
- temp=p1.x+(rect.top-p1.y)/m;
- if(temp>rect.right)
- {
- p1.x=p2.x=0;
- p1.y=p2.y=0;
- return;
- }
- if(temp>rect.left)
- {
- p1.x=temp;
- p1.y=rect.top;
- p2.x=rect.right;
- p2.y=p1.y+(p2.x-p1.x)*m;
- if(p2.y<rect.bottom)
- return;
- p2.y=rect.bottom;
- p2.x=p1.x+(p2.y-p1.y)/m;
- return;
- }
- p1.y+=(rect.left-p1.x)*m;
- if(p1.y>rect.bottom)
- {
- p1.x=p2.x=0;
- p1.y=p2.y=0;
- return;
- }
- p1.x=rect.left;
- p2.y=rect.bottom;
- p2.x=p1.x+(p2.y-p1.y)/m;
- if(p2.x<rect.right)
- return;
- p2.x=rect.right;
- p2.y=p1.y+(p2.x-p1.x)*m;
- return;
- }
- if(iRgnCode1==1)
- {
- if(m<0)
- {
- p1.y+=(rect.left-p1.x)*m;
- if(p1.y<rect.top)
- {
- p1.x=p2.x=0;
- p1.y=p2.y=0;
- return;
- }
- p1.x=rect.left;
- p2.x=p1.x+(rect.top-p1.y)/m;
- if(p2.x>rect.right)
- {
- p2.x=rect.right;
- p2.y=p1.y+(p2.x-p1.x)*m;
- return;
- }
- p2.y=rect.top;
- return;
- }
- p1.y+=(rect.left-p1.x)*m;
- if(p1.y>rect.bottom)
- {
- p1.x=p2.x=0;
- p1.y=p2.y=0;
- return;
- }
- p1.x=rect.left;
- p2.x=p1.x+(rect.bottom-p1.y)/m;
- if(p2.x>rect.right)
- {
- p2.x=rect.right;
- p2.y=p1.y+(p2.x-p1.x)*m;
- return;
- }
- p2.y=rect.bottom;
- return;
- }
- //iRgnCode1==5
- if(m>0)
- {
- p1.x=p2.x=0;
- p1.y=p2.y=0;
- return;
- }
- temp=p1.x+(rect.bottom-p1.y)/m;
- if(temp>rect.right)
- {
- p1.x=p2.x=0;
- p1.y=p2.y=0;
- return;
- }
- if(temp>rect.left)
- {
- p1.x=temp;
- p1.y=rect.bottom;
- p2.x=rect.right;
- p2.y=p1.y+(p2.x-p1.x)*m;
- if(p2.y>rect.top)
- return;
- p2.y=rect.top;
- p2.x=p1.x+(p2.y-p1.y)/m;
- return;
- }
- p1.y+=(rect.left-p1.x)*m;
- if(p1.y<rect.top)
- {
- p1.x=p2.x=0;
- p1.y=p2.y=0;
- return;
- }
- p1.x=rect.left;
- p2.y=rect.top;
- p2.x=p1.x+(p2.y-p1.y)/m;
- if(p2.x<rect.right)
- return;
- p2.x=rect.right;
- p2.y=p1.y+(p2.x-p1.x)*m;
- return;
- }
- //iRgnCode1==8 || 4
- if(m<0)
- {
- //iRgnCode1==8
- if(p1.y<rect.top)
- {
- p1.x=p2.x=0;
- p1.y=p2.y=0;
- return;
- }
- //iRgnCode1==4
- p1.x+=(rect.bottom-p1.y)/m;
- if(p1.x>rect.right)
- {
- p1.x=p2.x=0;
- p1.y=p2.y=0;
- return;
- }
- p1.y=rect.bottom;
- p2.y=p1.y+(rect.right-p1.x)*m;
- if(p2.y>rect.top)
- {
- p2.x=rect.right;
- return;
- }
- p2.y=rect.top;
- p2.x=p1.x+(p2.y-p1.y)/m;
- return;
- }
- if(p1.y>rect.bottom)
- {
- p1.x=p2.x=0;
- p1.y=p2.y=0;
- return;
- }
- p1.x+=(rect.top-p1.y)/m;
- if(p1.x>rect.right)
- {
- p1.x=p2.x=0;
- p1.y=p2.y=0;
- return;
- }
- p1.y=rect.top;
- p2.y=p1.y+(rect.right-p1.x)*m;
- if(p2.y<rect.bottom)
- {
- p2.x=rect.right;
- return;
- }
- p2.y=rect.bottom;
- p2.x=p1.x+(p2.y-p1.y)/m;
- //--------------------------------------------
- }
- void CDrawSysView::CutLine(RECT rect, LINE &l)
- {
- POINT p1,p2;
- p1=l.pStart;
- p2=l.pEnd;
- CutLine(rect,p1,p2);
- l.pStart=p1;
- l.pEnd=p2;
- }
- void CDrawSysView::Bezier(vector<POINT> vectorPoint,CDC *pDC)
- {
- int n=vectorPoint.size()-1;
- int i,r;
- float u;
- POINT *p=new POINT[n+1];
- vector<POINT> vectorBPoint;
- CPen pen;
- for(u=0;u<=1;u+=0.0005)
- {
- for(i=0;i<=n;i++)
- p[i]=vectorPoint[i];
- for(r=1;r<=n;r++)
- {
- for(i=0;i<=n-r;i++)
- {
- p[i].x=(1-u)*p[i].x+u*p[i+1].x;
- p[i].y=(1-u)*p[i].y+u*p[i+1].y;
- }
- }
- vectorBPoint.push_back(p[0]);
- }
- pen.CreatePen(PS_SOLID,m_iPenWidth,m_lPenColor);
- pDC->SelectObject(&pen);
- n=vectorBPoint.size();
- for(i=1;i<n;i++)
- {
- pDC->MoveTo(vectorBPoint[i-1]);
- pDC->LineTo(vectorBPoint[i]);
- }
- }
- void CDrawSysView::OnRButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- switch(m_dsDrawSort)
- {
- case DsLine:
- case DsManyBd:
- SetCursor(m_hDLCursor);
- break;
- case DsCircle:
- SetCursor(m_hDCCursor);
- break;
- case DsCutLine:
- SetCursor(m_hCLCursor);
- break;
- case DsBezier:
- SetCursor(m_hDBCursor);
- break;
- case DsText:
- SetCursor(m_hDTCursor);
- break;
- case DsStroke:
- SetCursor(m_hDSCursor);
- break;
- }
- CView::OnRButtonDown(nFlags, point);
- }
- void CDrawSysView::OnRButtonUp(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- CDC *pDC=GetDC();
- LINE lTemp;
- switch(m_dsDrawSort)
- {
- case DsManyBd:
- Line(m_startPoint,m_spManyBd,pDC);
- lTemp.pStart=m_startPoint;
- lTemp.pEnd=m_spManyBd;
- m_listAllLine.push_back(lTemp);
- m_bIsFirstDone=0;
- case DsLine:
- SetCursor(m_hDLCursor);
- break;
- case DsCircle:
- SetCursor(m_hDCCursor);
- break;
- case DsCutLine:
- SetCursor(m_hCLCursor);
- break;
- case DsBezier:
- m_listBezier.push_back(m_vectorCurBezier);
- m_vectorCurBezier.clear();
- SetCursor(m_hDBCursor);
- break;
- case DsText:
- SetCursor(m_hDTCursor);
- break;
- case DsStroke:
- SetCursor(m_hDSCursor);
- break;
- }
- CView::OnRButtonUp(nFlags, point);
- }
- void CDrawSysView::OnRButtonDblClk(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- switch(m_dsDrawSort)
- {
- case DsLine:
- case DsManyBd:
- SetCursor(m_hDLCursor);
- break;
- case DsCircle:
- SetCursor(m_hDCCursor);
- break;
- case DsCutLine:
- SetCursor(m_hCLCursor);
- break;
- case DsBezier:
- SetCursor(m_hDBCursor);
- break;
- case DsText:
- SetCursor(m_hDTCursor);
- break;
- case DsStroke:
- SetCursor(m_hDSCursor);
- break;
- }
- CView::OnRButtonDblClk(nFlags, point);
- }
- void CDrawSysView::OnBezier()
- {
- // TODO: Add your command handler code here
- if(m_dsDrawSort!=DsBezier)
- {
- CDC *pDC=GetDC();
- TEXT tTemp;
- int nSize;
- switch(m_dsDrawSort)
- {
- case DsManyBd:
- if(m_bIsFirstDone)
- {
- LINE lTemp;
- Line(m_startPoint,m_spManyBd,pDC);
- lTemp.pStart=m_startPoint;
- lTemp.pEnd=m_spManyBd;
- m_listAllLine.push_back(lTemp);
- }
- break;
- case DsText:
- m_edtTextIn.GetWindowText(tTemp.str);
- if(tTemp.str!="")
- {
- m_startPoint.y-=7;
- tTemp.p=m_startPoint;
- m_vectorText.push_back(tTemp);
- }
- m_edtTextIn.ShowWindow(0);
- m_edtTextIn.SetWindowText("");
- nSize=m_vectorText.size();
- if(nSize>0)
- pDC->TextOut(m_vectorText[nSize-1].p.x,m_vectorText[nSize-1].p.y,m_vectorText[nSize-1].str);
- break;
- }
- m_dsDrawSort=DsBezier;
- }
- else
- {
- m_listBezier.push_back(m_vectorCurBezier);
- m_vectorCurBezier.clear();
- m_dsDrawSort=DsNull;
- }
- m_bIsFirstDone=0;
- m_bIsMouseDown=0;
- }
- void CDrawSysView::OnUpdateBezier(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->SetCheck(m_dsDrawSort==DsBezier);
- }
- void CDrawSysView::OnText()
- {
- // TODO: Add your command handler code here
- CDC *pDC=GetDC();
- if(m_dsDrawSort!=DsText)
- {
- switch(m_dsDrawSort)
- {
- case DsManyBd:
- if(m_bIsFirstDone)
- {
- CDC *pDC=GetDC();
- LINE lTemp;
- Line(m_startPoint,m_spManyBd,pDC);
- lTemp.pStart=m_startPoint;
- lTemp.pEnd=m_spManyBd;
- m_listAllLine.push_back(lTemp);
- }
- break;
- case DsBezier:
- m_listBezier.push_back(m_vectorCurBezier);
- m_vectorCurBezier.clear();
- break;
- }
- m_dsDrawSort=DsText;
- }
- else
- {
- TEXT tTemp;
- int nSize;
- m_edtTextIn.GetWindowText(tTemp.str);
- if(tTemp.str!="")
- {
- m_startPoint.y-=7;
- tTemp.p=m_startPoint;
- m_vectorText.push_back(tTemp);
- }
- m_edtTextIn.ShowWindow(0);
- m_edtTextIn.SetWindowText("");
- nSize=m_vectorText.size();
- if(nSize>0)
- pDC->TextOut(m_vectorText[nSize-1].p.x,m_vectorText[nSize-1].p.y,m_vectorText[nSize-1].str);
- m_dsDrawSort=DsNull;
- }
- m_bIsFirstDone=0;
- m_bIsMouseDown=0;
- }
- void CDrawSysView::OnClear()
- {
- // TODO: Add your command handler code here
- CRect rect;
- m_listAllLine.clear();
- m_listAllCircle.clear();
- m_listBezier.clear();
- m_vectorText.clear();
- GetClientRect(&rect);
- InvalidateRect(&rect,1);
- }
- void CDrawSysView::OnStroke()
- {
- // TODO: Add your command handler code here
- if(m_dsDrawSort!=DsStroke)
- {
- TEXT tTemp;
- int nSize;
- CDC *pDC=GetDC();
- switch(m_dsDrawSort)
- {
- case DsManyBd:
- if(m_bIsFirstDone)
- {
- LINE lTemp;
- Line(m_startPoint,m_spManyBd,pDC);
- lTemp.pStart=m_startPoint;
- lTemp.pEnd=m_spManyBd;
- m_listAllLine.push_back(lTemp);
- }
- break;
- case DsBezier:
- m_listBezier.push_back(m_vectorCurBezier);
- m_vectorCurBezier.clear();
- break;
- case DsText:
- m_edtTextIn.GetWindowText(tTemp.str);
- if(tTemp.str!="")
- {
- m_startPoint.y-=7;
- tTemp.p=m_startPoint;
- m_vectorText.push_back(tTemp);
- }
- m_edtTextIn.ShowWindow(0);
- m_edtTextIn.SetWindowText("");
- nSize=m_vectorText.size();
- if(nSize>0)
- pDC->TextOut(m_vectorText[nSize-1].p.x,m_vectorText[nSize-1].p.y,m_vectorText[nSize-1].str);
- break;
- }
- m_dsDrawSort=DsStroke;
- }
- else
- m_dsDrawSort=DsNull;
- m_bIsFirstDone=0;
- m_bIsMouseDown=0;
- }
- void CDrawSysView::OnUpdateStroke(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->SetCheck(m_dsDrawSort==DsStroke);
- }
- void CDrawSysView::OnUpdateText(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->SetCheck(m_dsDrawSort==DsText);
- }
- void CDrawSysView::OnTest()
- {
- // TODO: Add your command handler code here
- CDC *pDC=GetDC();
- int i;
- long temp=m_lPenColor;
- CBrush brush;
- CRect rect;
- int nScreenWidth;
- int nScreenHight;
- TEXT tTemp;
- int nSize;
- switch(m_dsDrawSort)
- {
- case DsManyBd:
- if(m_bIsFirstDone)
- {
- CDC *pDC=GetDC();
- LINE lTemp;
- Line(m_startPoint,m_spManyBd,pDC);
- lTemp.pStart=m_startPoint;
- lTemp.pEnd=m_spManyBd;
- m_listAllLine.push_back(lTemp);
- }
- break;
- case DsBezier:
- m_listBezier.push_back(m_vectorCurBezier);
- m_vectorCurBezier.clear();
- break;
- case DsText:
- m_edtTextIn.GetWindowText(tTemp.str);
- if(tTemp.str!="")
- {
- m_startPoint.y-=7;
- tTemp.p=m_startPoint;
- m_vectorText.push_back(tTemp);
- }
- m_edtTextIn.ShowWindow(0);
- m_edtTextIn.SetWindowText("");
- nSize=m_vectorText.size();
- if(nSize>0)
- pDC->TextOut(m_vectorText[nSize-1].p.x,m_vectorText[nSize-1].p.y,m_vectorText[nSize-1].str);
- break;
- }
- m_dsDrawSort=DsNull;
- brush.CreateSolidBrush(RGB(255,255,255));
- GetClientRect(&rect);
- pDC->FillRect(&rect,&brush);
- brush.DeleteObject();
- nScreenWidth=rect.right;
- nScreenHight=rect.bottom;
- // for(i=5;i<=505;i++)
- // {
- // m_lPenColor=RGB(255,0,i*255/550);
- // Line(255,320,i,70,pDC);
- // }
- // for(i=5;i<=505;i++)
- // {
- // m_lPenColor=RGB(i*255/550,255,0);
- // Line(255,320,i,570,pDC);
- // }
- // for(i=70;i<570;i++)
- // {
- // m_lPenColor=RGB(0,255,i*255/650);
- // Line(255,320,5,i,pDC);
- // }
- // for(i=70;i<570;i++)
- // {
- // m_lPenColor=RGB(0,i*255/650,255);
- // Line(255,320,505,i,pDC);
- // }
- //
- // for(int r=0;r<=250;r++)
- // {
- // m_lPenColor=RGB(0,255-r,255+r);
- // Circle(760,320,r,pDC);
- // }
- for(i=5;i<=nScreenWidth/2+5;i++)
- {
- m_lPenColor=RGB(255,0,i*255/550);
- Line(nScreenWidth/4+5,nScreenHight/2,i,nScreenHight/2-nScreenWidth/4,pDC);
- }
- for(i=5;i<=nScreenWidth/2+5;i++)
- {
- m_lPenColor=RGB(i*255/550,255,0);
- Line(nScreenWidth/4+5,nScreenHight/2,i,nScreenHight/2+nScreenWidth/4,pDC);
- }
- for(i=nScreenHight/2-nScreenWidth/4;i<nScreenHight/2+nScreenWidth/4;i++)
- {
- m_lPenColor=RGB(0,255,i*255/650);
- Line(nScreenWidth/4+5,nScreenHight/2,5,i,pDC);
- }
- for(i=nScreenHight/2-nScreenWidth/4;i<nScreenHight/2+nScreenWidth/4;i++)
- {
- m_lPenColor=RGB(0,i*255/650,255);
- Line(nScreenWidth/4+5,nScreenHight/2,nScreenWidth/2+5,i,pDC);
- }
- for(int r=0;r<=nScreenWidth/4-5;r++)
- {
- m_lPenColor=RGB(0,255-r,255+r);
- Circle(nScreenWidth*0.75+5,nScreenHight/2,r,pDC);
- }
- ReleaseDC(pDC);
- }
- void CDrawSysView::Line(POINT p1, POINT p2, CDC *pDC)
- {
- if(m_dlsDrawLSort==DlsDDA)
- Line_DDA(p1,p2,pDC);
- else
- Line_Bresenham(p1,p2,pDC);
- }
- void CDrawSysView::Line(long p1x, long p1y, long p2x, long p2y, CDC *pDC)
- {
- POINT p1,p2;
- p1.x=p1x;
- p1.y=p1y;
- p2.x=p2x;
- p2.y=p2y;
- Line(p1,p2,pDC);
- }
- void CDrawSysView::Circle(long pcx, long pcy, int r, CDC *pDC)
- {
- POINT pc;
- pc.x=pcx;
- pc.y=pcy;
- Circle(pc,r,pDC);
- }
- void CDrawSysView::OnRandline()
- {
- // TODO: Add your command handler code here
- CDC *pDC=GetDC();
- CRect rect;
- int i;
- LINE lTemp;
- TEXT tTemp;
- int nSize;
- switch(m_dsDrawSort)
- {
- case DsManyBd:
- if(m_bIsFirstDone)
- {
- CDC *pDC=GetDC();
- LINE lTemp;
- Line(m_startPoint,m_spManyBd,pDC);
- lTemp.pStart=m_startPoint;
- lTemp.pEnd=m_spManyBd;
- m_listAllLine.push_back(lTemp);
- }
- break;
- case DsBezier:
- m_listBezier.push_back(m_vectorCurBezier);
- m_vectorCurBezier.clear();
- break;
- case DsText:
- m_edtTextIn.GetWindowText(tTemp.str);
- if(tTemp.str!="")
- {
- m_startPoint.y-=7;
- tTemp.p=m_startPoint;
- m_vectorText.push_back(tTemp);
- }
- m_edtTextIn.ShowWindow(0);
- m_edtTextIn.SetWindowText("");
- nSize=m_vectorText.size();
- if(nSize>0)
- pDC->TextOut(m_vectorText[nSize-1].p.x,m_vectorText[nSize-1].p.y,m_vectorText[nSize-1].str);
- break;
- }
- m_dsDrawSort=DsNull;
- srand(time(0));
- GetClientRect(&rect);
- for(i=0;i<500;i++)
- {
- lTemp.pStart.x=rect.left+(rect.right-rect.left)*rand()*1.0/RAND_MAX;
- lTemp.pStart.y=rect.top+(rect.bottom-rect.top)*rand()*1.0/RAND_MAX;
- lTemp.pEnd.x=rect.left+(rect.right-rect.left)*rand()*1.0/RAND_MAX;
- lTemp.pEnd.y=rect.top+(rect.bottom-rect.top)*rand()*1.0/RAND_MAX;
- m_listAllLine.push_back(lTemp);
- }
- InvalidateRect(rect,1);
- ReleaseDC(pDC);
- }
- void CDrawSysView::Draw3DText(CString str,CRect rectText,int nHeight,int nWidth,int nWeight,BYTE bItalic,LPCTSTR lpszFacename,CDC *pDC)
- {
- CFont fontLogo,*oldFont;
- COLORREF oldColor;
- fontLogo.CreateFont(nHeight,nWidth,0,0,nWeight,bItalic,FALSE,FALSE,
- DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
- FIXED_PITCH | FF_ROMAN,lpszFacename);
- pDC->SetBkMode(TRANSPARENT);
- oldFont=pDC->SelectObject(&fontLogo);
- oldColor=pDC->SetTextColor(RGB(0,0,0));
- pDC->DrawText(str,rectText+CPoint(1,1),DT_SINGLELINE | DT_LEFT | DT_VCENTER|DT_CENTER);
- pDC->SetTextColor(::GetSysColor(COLOR_BTNFACE));
- pDC->DrawText(str,rectText,DT_SINGLELINE | DT_LEFT | DT_VCENTER|DT_CENTER);
- pDC->SetTextColor(oldColor);
- pDC->SelectObject(oldFont);
- }
- void CDrawSysView::OnRefresh()
- {
- // TODO: Add your command handler code here
- CRect rect;
- GetClientRect(&rect);
- InvalidateRect(&rect,1);
- }
- void CDrawSysView::Circle(CIRCLE c, CDC *pDC)
- {
- POINT pc=c.pMid;
- int r=c.r;
- Circle(pc,r,pDC);
- }
- void CDrawSysView::Line(LINE l,CDC *pDC)
- {
- POINT p1=l.pStart;
- POINT p2=l.pEnd;
- Line(p1,p2,pDC);
- }