You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

139 lines
3.1 KiB
C++

#include "StdAfx.h"
#include "MouseTool.h"
#include "GlobalDrawMgr.h"
#include "GlobalFunction.h"
#include "CommandCreat.h"
#include "CommandMgr.h"
#include "GlobalDrawMgr.h"
CMouseTool::CMouseTool(void)
{
m_Status = _STATUS_1;//初始为第一步
ClearFirstPoint();
m_bFirstMove = true;//用于标记第一次移动
}
CMouseTool::~CMouseTool(void)
{
}
void CMouseTool::AddObject(CObjBase *p)
{
Sptr<CObjBase> sPtr(p);
m_TmpObjContainer.AddObject(sPtr);
gLayer.AddTmpObject(sPtr);
}
void CMouseTool::SaveDownPoint(CPoint point)
{
SaveDownPoint(gDraw->CPoint2Dbxy(point));
}
void CMouseTool::SaveDownPoint(Dbxy point)
{
m_DownPoint = point;
}
bool CMouseTool::HasPreMovePt()
{
if(m_PreMovePt.x == 0 && m_PreMovePt.y == 0)
return false;
else
return true;
}
void CMouseTool::ClearFirstPoint()
{
m_DownPoint.x = 0;
m_DownPoint.y = 0;
m_PreMovePt.x = 0;
m_PreMovePt.y = 0;
}
void CMouseTool::OnLButtonDown(UINT nFlags, CPoint point,CClientDC &dc)
{
//非编辑模式禁用鼠标相关操作
if(!gDraw->IsbObjEditMode())
return;
SaveDownPoint(point);
}
void CMouseTool::OnRButtonDown(UINT nFlags, CPoint point,CClientDC &dc)
{
GetCurViewPtr()->OnEscape();
}
void CMouseTool::OperateOver()
{
ClearFirstPoint();
m_bFirstMove = true;
//删除layer 的临时对象-----------------------------------
gLayer.ClearTmpObj();
}
void CMouseTool::OnLButtonUp(UINT nFlags, CPoint point,CClientDC &dc)
{
OperateOver();
}
void CMouseTool::AddCreatCommand()
{
if(!m_TmpObjContainer.Empty())
{
//创建撤销指令-------start
CCommandCreat *p = new CCommandCreat;
gCommandMgr.AddUndoCommand(p,m_TmpObjContainer.GetObjVec());
p->Excute();
//创建撤销指令-------end
}
//清空临时容器
m_TmpObjContainer.Clear();
}
void CMouseTool::OnEscapeKey()
{
m_TmpObjContainer.Clear();
OperateOver();
}
//变成下一个状态
void CMouseTool::ToNextStatus()
{
switch(m_Status)
{
case _STATUS_1:
m_Status = _STATUS_2;
break;
case _STATUS_2:
m_Status = _STATUS_3;
break;
case _STATUS_3:
m_Status = _STATUS_4;
break;
case _STATUS_4:
m_Status = _STATUS_5;
break;
case _STATUS_5:
m_Status = _STATUS_6;
break;
default:
break;
}
}
bool CMouseTool::IsEndStatus()
{
return (m_Status ==_STATUS_END);
}
bool CMouseTool::IsStartStatus()
{
return (m_Status ==_STATUS_1);
}
//创建模拟操作的对象
void CMouseTool::CreatOpSimulateObj()
{
//先取得选择obj 的矩形
DbRect rect = gLayer.GetSelObjRect();
m_OpSimulateObjBak.CreatRect(rect);
}
//重绘模拟对象
void CMouseTool::XorRedrawOpSimulateObj(CDC* pDC)
{
int old_rop = pDC->SetROP2(R2_XORPEN);
m_OpSimulateObj.Draw(pDC,gDraw->GetSelObjectPen());
pDC->SetROP2(old_rop);
}
//操作模拟对象
void CMouseTool::OpSimulateObj(SObjOperatePar &par)
{
//每次都从备份对象取值来操作
m_OpSimulateObj.DelAllPt();
m_OpSimulateObj.CopyPt(m_OpSimulateObjBak);
m_OpSimulateObj.Operate(par);
}