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

📄 geditorview.cpp

📁 一个复杂的画图系统
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// geditorView.cpp : implementation of the CGeditorView class
//

#include "stdafx.h"
#include "geditor.h"
#include "globals.h"
#include "textInput.h"
#include "MainFrm.h"
#include "geditorDoc.h"
#include "geditorView.h"
#include <cmath>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CGeditorView

IMPLEMENT_DYNCREATE(CGeditorView, CScrollView)

BEGIN_MESSAGE_MAP(CGeditorView, CScrollView)
	//{{AFX_MSG_MAP(CGeditorView)
	ON_WM_MOUSEMOVE()
	ON_WM_LBUTTONUP()
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONDBLCLK()
	ON_COMMAND(ID_EDIT_CUT, OnEditCut)
	ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
	ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
	ON_BN_CLICKED(IDC_COLOR, OnColor)
	ON_BN_CLICKED(IDC_USE, OnUse)
	ON_BN_CLICKED(IDC_RADSOLID, OnRadsolid)
	ON_BN_CLICKED(IDC_RADDOT, OnRaddot)
	ON_BN_CLICKED(IDC_RADDASHDOTDOT, OnRaddashdotdot)
	ON_BN_CLICKED(IDC_RADDASHDOT, OnRaddashdot)
	ON_BN_CLICKED(IDC_RADDASH, OnRaddash)
	ON_CBN_SELENDOK(IDC_OBJNAME, OnSelendokObjname)
	ON_BN_CLICKED(IDC_BKCOLOR, OnBkcolor)
	ON_COMMAND(ID_TOOL_CLIPPING, OnEditCut)
	ON_COMMAND(ID_TOOLCOPY, OnEditCopy)
	ON_COMMAND(ID_TOOLPASTE, OnEditPaste)
	ON_BN_CLICKED(IDC_CHKFILL, OnChkfill)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
	ON_COMMAND_RANGE(ID_TOOL_PICK, ID_TOOLMOVE, OnToolType)
	ON_UPDATE_COMMAND_UI_RANGE(ID_TOOL_PICK, ID_TOOLMOVE, OnUpdateToolType)
	ON_COMMAND_RANGE(ID_LESX, ID_LESW, OnToolLes)
	ON_UPDATE_COMMAND_UI_RANGE(ID_LESX, ID_LESW, OnUpdateToolles)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGeditorView construction/destruction

CGeditorView::CGeditorView()
{
}

CGeditorView::~CGeditorView()
{
}

BOOL CGeditorView::PreCreateWindow(CREATESTRUCT& cs)
{
	return CScrollView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CGeditorView drawing

void CGeditorView::OnDraw(CDC* pDC)
{
	CGeditorDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	pDC->SetBkMode(TRANSPARENT);
	CShape* pObj;
	///////////////Attention////////////////////////////////
	POSITION pos = pDoc->m_shapeList.GetHeadPosition( );
	///////////////////////////////////////////////////////
	while(pos != NULL)
	{
		pObj = pDoc->m_shapeList.GetNext(pos);
		ASSERT_VALID(pObj);
		pObj->Draw(pDC);
	}//end of while

}

void CGeditorView::OnInitialUpdate()
{
	CGeditorDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	m_wLButtonState = LBUTTONUP;
	m_pCurLine = NULL;
	m_pCurPgn = NULL;
	m_pCurRect = NULL;
	m_pCurEllipse = NULL;
	m_pCurBezier = NULL;
	m_wBezierIndex = 0;
    MoveFlag=0; 
	rotatebaseptflag=0;
	NoMove=FALSE;
	MouseDown=FALSE;
    //CurObj=NULL;
	NextObj=NULL;
	TempObj=NULL;
	polypt.x=polypt.y=-1;
	m_hCrossCursor = AfxGetApp()->LoadStandardCursor(IDC_CROSS);
	CurObj=pDoc->CurObj;//文件打开后,获得存入时的激活图元
	objnumber=pDoc->CurObjNum;
	if (CurObj!=NULL) 
	{
		CurObj->InitProp();
		DragMode=1;
		setFocus();
	};
	pDoc->open=0;
	CScrollView::OnInitialUpdate();
	CSize sizeTotal;
	sizeTotal.cx = sizeTotal.cy = 100;
	SetScrollSizes(MM_TEXT, sizeTotal);
}

/////////////////////////////////////////////////////////////////////////////
// CGeditorView printing

BOOL CGeditorView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CGeditorView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CGeditorView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CGeditorView diagnostics

#ifdef _DEBUG
void CGeditorView::AssertValid() const
{
	CScrollView::AssertValid();
}

void CGeditorView::Dump(CDumpContext& dc) const
{
	CScrollView::Dump(dc);
}

CGeditorDoc* CGeditorView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGeditorDoc)));
	return (CGeditorDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CGeditorView message handlers

void CGeditorView::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	int oldROP2;
	//Get a DC for use.
	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);
	
	//Set the drawing mode to R2_XORPEN
	oldROP2 = pClientDC->SetROP2(R2_NOTXORPEN);
//	Cprop *p=(Cprop*)AfxGetApp()->
//			m_pMainWnd->GetDescendantWindow(IDD_PRPTBAR);
	switch(pDoc->m_wToolType)
	{
	case TOOL_PICK:

		if (MouseDown) //if mouse down,then obj should be moved
		{
			if (CurObj!=NULL){
			CDC *pDC=GetDC();
			CurObj->dragobj(pDoc->m_wToolles,pDC,point,this);}//at least this two para
		}
		else //test which obj is be selected during mouse move
		{
			CGeditorDoc *pDoc=GetDocument();
			POSITION pos=(pDoc->m_shapeList).GetTailPosition();
			int count=(pDoc->m_shapeList).GetCount();
			BOOL Seled=FALSE;//set it unselected
			NextObj=NULL;    //no obj is selected
			pDoc->CurObjNum=count;
			while ((pDoc->CurObjNum>0)&&(!Seled))
			{
				NextObj = pDoc->m_shapeList.GetPrev(pos);
				ASSERT_VALID(NextObj);
				DragMode=NextObj->InTest(point);
				//intest测试鼠标是否落入图元,及落入的位置,并返回模式
				Seled=(DragMode!=0);//0=don't drag
				(pDoc->CurObjNum)--;
			};
			//因为CurObjNum会随着鼠标移动而改变,在PICK被按下时不能反映实际选定物体的编号。
			//古必须在LButtonDown时确定物体序号,见ButtonDown
			if (!Seled) //none is selected,change mouse 
			{
				NextObj=NULL;//not seltect obj
				m_hCrossCursor = AfxGetApp()->LoadStandardCursor(IDC_ARROW);
				::SetCursor(m_hCrossCursor);
			};
		}
		break;
	case TOOL_LINE:
		if(m_wLButtonState == LBUTTONDOWN)
		{
			ASSERT_VALID(m_pCurLine);
			//Remove the previous line
			m_pCurLine->Draw(pClientDC);
			//Set the end point of the line to point
			m_pCurLine->SetEndPt(point);
			m_pCurLine->UpdateProp(1);
			//Draw the update line
			m_pCurLine->Draw(pClientDC);		
		}//end of if
		break;

	case TOOL_RECTANGLE:
		if(m_wLButtonState == LBUTTONDOWN)
		{
			ASSERT_VALID(m_pCurRect);
			m_pCurRect->Draw(pClientDC);
			m_tPrevPt = point;
			m_pCurRect->SetRect(m_tAnchorPt,m_tPrevPt);
			m_pCurRect->UpdateProp(1);
			//Draw the update rect
			m_pCurRect->Draw(pClientDC);
		}//end of if	
		break;

	case TOOL_POLYGON:
		if(m_wLButtonState == LBUTTONDOWN)
		{	
			ASSERT_VALID(m_pCurPgn);
			pClientDC->MoveTo(m_pCurPgn->GetTail());
			pClientDC->LineTo(m_tPrevPt);
			//Draw the update line
			pClientDC->MoveTo(m_pCurPgn->GetTail());
			pClientDC->LineTo(point);
			m_tPrevPt = point;
		}//end of if
		break;

	case TOOL_ELLIPSE:
		if(m_wLButtonState == LBUTTONDOWN)
		{
			ASSERT_VALID(m_pCurEllipse);
			m_pCurEllipse->Draw(pClientDC);
			m_tPrevPt = point;
			m_pCurEllipse->SetBox(m_tAnchorPt,m_tPrevPt);
			//Draw the update rect
			m_pCurEllipse->Draw(pClientDC);
		}//end of if	

		break;

	case TOOL_BEZIER_CURVE:
		if(m_wLButtonState == LBUTTONDOWN)
		{
			ASSERT_VALID(m_pCurBezier);
			//Erase the previous bezier curve.
			m_pCurBezier->Draw(pClientDC);
			//draw the update bezier curve.
			m_pCurBezier->SetCtlPt(point,m_wBezierIndex);
			m_pCurBezier->Draw(pClientDC);
		}//end of if

		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:
		if (MouseDown) //if mouse down,then obj should be moved
		{
			if (CurObj!=NULL)
			{
				rotatebaseptflag=0;
				CDC *pDC=GetDC();
				CurObj->rotate(pDoc->m_wToolles,pDC,point,this);
				RotPt=point;
			}//at least this two para
		}
		else //test which obj is be selected during mouse move
		{
			CGeditorDoc *pDoc=GetDocument();
			POSITION pos=(pDoc->m_shapeList).GetTailPosition();
			int count=(pDoc->m_shapeList).GetCount();
			BOOL Seled=FALSE;//set it unselected
			NextObj=NULL;    //no obj is selected
			pDoc->CurObjNum=count;
			while ((pDoc->CurObjNum>0)&&(!Seled))
			{
				NextObj = pDoc->m_shapeList.GetPrev(pos);
				ASSERT_VALID(NextObj);
				DragMode=NextObj->InTest(point);
				//intest测试鼠标是否落入图元,及落入的位置,并返回模式
				Seled=(DragMode!=0);//0=don't drag
				(pDoc->CurObjNum)--;
			};
			if (!Seled) //none is selected,change mouse 
			{
				NextObj=NULL;//not seltect obj
				m_hCrossCursor = AfxGetApp()->LoadStandardCursor(IDC_ARROW);
				::SetCursor(m_hCrossCursor);
			}
			else 
			{
				m_hCrossCursor = AfxGetApp()->LoadCursor(IDC_CURROT);
				::SetCursor(m_hCrossCursor);
			};
		}
		break;
    case TOOL_MIRROR:
		break;
    case TOOL_MOVE:
		break;
	default:
		;
	};//end of switch
	DeleteObject(curPen);
	DeleteObject(curBrush);
	pClientDC->SelectObject(oldPen);
	pClientDC->SelectObject(oldBrush);
	pClientDC->SetROP2(oldROP2);
	//Release the DC.
	ReleaseDC(pClientDC);


	//Call default
	CScrollView::OnMouseMove(nFlags, point);

	//Display current coordinates on the status bar
	char szStr[40];
	CStatusBar *pStatusBar=(CStatusBar *)AfxGetApp()->m_pMainWnd
				->GetDescendantWindow(AFX_IDW_STATUS_BAR);
	sprintf(szStr,"[%03d,%03d]",point.x,point.y);
	pStatusBar->SetPaneText(1,szStr);
//	p=NULL;
}

void CGeditorView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	double d0=0.5;
	double mx=0;
	// TODO: Add your message handler code here and/or call default
	int oldROP2;

	CDC* pClientDC = GetDC();
	ASSERT_VALID(pClientDC);

	//Convert "point" from device coordinate to logical coordinate
	pClientDC->DPtoLP(&point);
	
	//Get the document pointer
	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);

	//Release the focus capture
	::ReleaseCapture();
	::ClipCursor(NULL);

    textInput myFont;
	LOGFONT logs;
	COLORREF color;
//	Cprop *p=(Cprop*)AfxGetApp()->
//		m_pMainWnd->GetDescendantWindow(IDD_PRPTBAR);
	switch(pDoc->m_wToolType)
	{
	case TOOL_PICK:

⌨️ 快捷键说明

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