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

📄 stmbseventhandle.cpp

📁 一个简单的vc++开发的城市公交地图编辑器源代码及生成的地图样例
💻 CPP
字号:
// STMBSEventHandle.cpp: implementation of the CSTMBSEventHandle class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "stmeditor.h"
#include "STMBSEventHandle.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
#include "BSNameInputDlg.h"

CSTMBSEventHandle::CSTMBSEventHandle()
{
	m_pDoc=NULL;
	m_pMapView=NULL;
}

CSTMBSEventHandle::~CSTMBSEventHandle()
{
}

void CSTMBSEventHandle::OnLButtonUp(UINT nFlags, CPoint point)
{
	POINT	originpoint;
	originpoint=m_pMapView->GetScrollPosition();
	point.Offset(originpoint);
	if(m_pDoc->m_focusEI.eleType==ET_PATH)	//destinate type
	{
		if(m_pDoc->m_focusEI.index!=-1)
		{
			if(m_pDoc->m_activeType==ACT_BS_PICK)//add a bus station
			{
				BSINFO	bsi;
				bsi.path_id=m_pDoc->m_focusEI.index;
				bsi.pos=point;
				CBSNameInputDlg inputdlg;
				if(inputdlg.DoModal()==IDOK)
				{
					strcpy(bsi.name,inputdlg.m_BSName);
					int index=m_pDoc->AddBS(bsi);
					DrawBS(index);
				}
			}
		}
	}else if(m_pDoc->m_focusEI.eleType==ET_BS)//self type
	{
		if(m_pDoc->m_focusEI.index!=-1)
		{
	
			if(m_pDoc->m_activeType==ACT_BROWSE)//browse select the bus station
			{
				CString msg;
				BSINFO	bsi=m_pDoc->m_arrBS.GetAt(m_pDoc->m_focusEI.index);
				msg.Format("you clicked a bus station! name=%s,pos:x=%d;y=%d",bsi.name,bsi.pos.x,bsi.pos.y);
//				m_pMapView->MessageBox(msg,"info");
			}
		}
	}
	if(m_pDoc->m_activeType==ACT_BS_MOVE)//move finish
	{
		//wait to fill
		m_pDoc->m_activeType=ACT_BS_PICK;
	}
}

void CSTMBSEventHandle::OnRButtonUp(UINT nFlags, CPoint point)
{
	POINT	originpoint;
	originpoint=m_pMapView->GetScrollPosition();
	point.Offset(originpoint);
	if(m_pDoc->m_focusEI.eleType==ET_BS && 
		m_pDoc->m_focusEI.index !=-1)
	{
		if(m_pDoc->m_activeType!=ACT_BS_MOVE) //delete bs
		{
			CRgn effectrgn;
			m_pDoc->RemoveBS(effectrgn,m_pDoc->m_focusEI.index);
			effectrgn.OffsetRgn(-originpoint.x,-originpoint.y);
			m_pDoc->m_focusEI.index=-1;
			m_pMapView->InvalidateRgn(&effectrgn,FALSE);
		}
	}
}
void CSTMBSEventHandle::OnMouseMove(UINT nFlags, CPoint point)
{
	POINT	originpoint;
	originpoint=m_pMapView->GetScrollPosition();
	point.Offset(originpoint);
	if(!(nFlags&MK_LBUTTON))//	gerenal operator
	{
		if(m_pDoc->m_bFocusChanged)
		{
			if(m_pDoc->m_preFocusEI.eleType==ET_BS &&
				m_pDoc->m_preFocusEI.index!=-1)// restore old focus cross
			{
				DrawBS(m_pDoc->m_preFocusEI.index);
			}
			if(m_pDoc->m_focusEI.eleType==ET_BS &&
				m_pDoc->m_focusEI.index!=-1)	//hilight the focus cross
			{
				DrawBS(m_pDoc->m_focusEI.index);
			}
		}
	}else	//drag
	{
		if(CanBSMove())//move bus station
		{
			if(m_pDoc->m_activeType==ACT_BS_PICK)
				m_pDoc->m_activeType=ACT_BS_MOVE;
			if(m_pDoc->m_activeType==ACT_BS_MOVE)
			{
				ELEINFO ei=m_pDoc->m_arrSel.GetAt(0);
				CRgn bsrgn;
				m_pDoc->CalcBSRgn(bsrgn,ei.index);
				bsrgn.OffsetRgn(-originpoint.x,-originpoint.y);
				m_pDoc->MoveBS(ei.index,point);
				m_pMapView->InvalidateRgn(&bsrgn,FALSE);
				DrawBS(ei.index);
			}	
		}
	}

}
void CSTMBSEventHandle::DrawBS(int index)
{
	BSINFO bsi=m_pDoc->m_arrBS.GetAt(index);
	ELEINFO	ei;
	ei.eleType=ET_BS;
	ei.index=index;
	ELESTATE state=m_pDoc->GetElementState(ei);//get element state
	COLORREF color;
	switch(state)
	{
	case ES_NORMAL:color=RGB(0,255,0);break;
	case ES_FOCUS:color=RGB(255,255,0);break;
	case ES_SELECTED:color=RGB(255,0,0);break;
	}

	POINT	originpoint;
	POINT	pt=bsi.pos;

	originpoint=m_pMapView->GetScrollPosition();
	pt.x-=originpoint.x;
	pt.y-=originpoint.y;
	RECT    rc=m_pDoc->CalcBSRect(pt);
	CDC *pDC=m_pMapView->GetDC();
	CPen pen,*oldpen;
	pen.CreatePen(PS_SOLID,1,color);
	CBrush	brush,*oldbrush;
	oldpen=pDC->SelectObject(&pen);
	brush.CreateSolidBrush(color);
	oldbrush=pDC->SelectObject(&brush);
	pDC->Ellipse(&rc);
	int oldmode=pDC->SetBkMode(TRANSPARENT);
	COLORREF oldcolor=pDC->SetTextColor(color);
	pDC->TextOut(rc.right,rc.top,bsi.name,strlen(bsi.name));
	pDC->SetTextColor(oldcolor);
	pDC->SetBkMode(oldmode);	
	pDC->SelectObject(oldbrush);
	pDC->SelectObject(oldpen);
	m_pMapView->ReleaseDC(pDC);
}

void CSTMBSEventHandle::DrawAllBSes()
{
	for(int i=0;i<m_pDoc->m_arrBS.GetSize();i++)
	{
		DrawBS(i);
	}
}

void CSTMBSEventHandle::OnLButtonDown(UINT nFlags, CPoint point)
{
	//draw new selected bus station
	if(m_pDoc->m_focusEI.eleType==ET_BS &&
		m_pDoc->m_focusEI.index!=-1)
	{
		ELEINFO selEI=m_pDoc->m_focusEI;
		m_pDoc->SelectElements(&selEI,1);
		DrawBS(selEI.index);
	}
}

void CSTMBSEventHandle::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	switch(nChar)
	{
	case VK_UP:
		break;
	case VK_DOWN:
		break;
	case VK_LEFT:
		break;
	case VK_RIGHT:
		break;
	}
}

BOOL CSTMBSEventHandle::CanBSMove()
{
	BOOL ret=TRUE;
	if(m_pDoc->m_arrSel.GetSize()!=1)
		ret=FALSE;
	else 
	{
		ELEINFO ei=m_pDoc->m_arrSel.GetAt(0);
		if(ei.eleType!=ET_BS||ei.index==-1)
			ret=FALSE;
	}
	return ret;
}

⌨️ 快捷键说明

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