www.pudn.com > my2cadtest07261930.rar > ParaTool.cpp, change:2006-07-25,size:4293b


 
 
#include "stdafx.h" 
#include "ParaTool.h" 
#include "list.h" 
#include "shape.h" 
#include "rectangle.h" 
 
 
extern CList<CShape*> m_list; 
 
CParaTool::CParaTool(HWND hWnd,bool whatShape): 
CTool(hWnd),m_line1(hWnd,true),m_whatShape(whatShape),m_isFirstDraw(true) 
{ 
 
} 
 
CParaTool::~CParaTool() 
{ 
 
} 
 
void CParaTool::OnLButtonDown(WPARAM wParam,LPARAM lParam) 
{ 
   POINT curPoint; 
   curPoint.x=LOWORD(lParam); 
   curPoint.y=HIWORD(lParam); 
 
  switch(m_status) 
  { 
    case NoClick: 
		{          
         m_line1.OnLButtonDown(wParam,lParam); 
         m_status=FirstClick; 
 
         m_fourthPT=m_begPT=curPoint;		 
		} 
     break; 
	case FirstClick: 
		{ 
          m_line1.OnLButtonDown(wParam,lParam);         
          m_status=SecClick;		   
		   
		  m_thirdPT=m_endPT=curPoint; 
 
          m_hdc=GetDC(m_hWnd);    //打开HDC 开始划其它三条边了 
          penattrib->GetPen(m_hdc,true);  //选异或笔 
		} 
		break; 
    case SecClick: 
		{ 
		 penattrib->ReleasePen(true);	 
         penattrib->GetPen(m_hdc,false,false); 
		  
         this->Draw(); 
         m_status=NoClick; 
         m_isFirstDraw=true; 
         this->SaveSelf(); 
		  
		 penattrib->ReleasePen(false,false); 
         ReleaseDC(m_hWnd,m_hdc);  //图形绘制完毕 释放HDC 
		} 
		break; 
     break; 
	default: 
		break; 
 
  } 
 
} 
 
void CParaTool::OnMouseMove(WPARAM wParam,LPARAM lParam) 
{ 
   POINT curPoint; 
   curPoint.x=LOWORD(lParam); 
   curPoint.y=HIWORD(lParam); 
	 
	 
	if(m_status==FirstClick) 
   { 
         m_line1.OnMouseMove(wParam,lParam);       
   } 
   else if(m_status==SecClick) 
   { 
      
 
	 if(m_isFirstDraw) 
	 {   
		 m_isFirstDraw=false; 
	 } 
	 else 
	 { 
       this->PreDraw();   //擦掉老线 
     } 
	 m_thirdPT=curPoint; 
	 double dx=m_thirdPT.GetPoint().x-m_endPT.GetPoint().x; 
	 double dy=m_thirdPT.GetPoint().y-m_endPT.GetPoint().y; 
     m_fourthPT=m_begPT;                //第四点复位 
	 m_fourthPT.Move(dx,dy);            //从新计算偏移量 
	 this->PreDraw();   //划新线 
      
   } 
 
} 
 
void CParaTool::PreDraw() 
{ 
	 
	if(m_whatShape)  //划平行线时两侧的线不连 
    { 
     
	::MoveToEx(m_hdc,m_endPT.GetPoint().x,m_endPT.GetPoint().y,NULL);		 
	::LineTo(m_hdc,m_thirdPT.GetPoint().x,m_thirdPT.GetPoint().y); 
 
    ::MoveToEx(m_hdc,m_fourthPT.GetPoint().x,m_fourthPT.GetPoint().y,NULL);		 
	::LineTo(m_hdc,m_begPT.GetPoint().x,m_begPT.GetPoint().y); 
     
	} 
 
    ::MoveToEx(m_hdc,m_thirdPT.GetPoint().x,m_thirdPT.GetPoint().y,NULL);		 
	::LineTo(m_hdc,m_fourthPT.GetPoint().x,m_fourthPT.GetPoint().y); 
 
 
} 
 
void CParaTool::Draw() 
{ 
     
 
	if(m_whatShape)  //划平行线时两侧的线不连 
	{	 
		::MoveToEx(m_hdc,m_endPT.GetPoint().x,m_endPT.GetPoint().y,NULL);		 
		::LineTo(m_hdc,m_thirdPT.GetPoint().x,m_thirdPT.GetPoint().y); 
 
		::MoveToEx(m_hdc,m_fourthPT.GetPoint().x,m_fourthPT.GetPoint().y,NULL);		 
		::LineTo(m_hdc,m_begPT.GetPoint().x,m_begPT.GetPoint().y); 
    } 
 
    ::MoveToEx(m_hdc,m_thirdPT.GetPoint().x,m_thirdPT.GetPoint().y,NULL);		 
	::LineTo(m_hdc,m_fourthPT.GetPoint().x,m_fourthPT.GetPoint().y); 
		 
} 
 
void CParaTool::SaveSelf() 
{ 
   
    if(m_whatShape) //平行四边形 
	{	 
		CShape* pPara=new CRectangle(m_begPT,m_endPT,m_thirdPT,m_fourthPT,true); 
		pPara->SetLOGPEN(penattrib->GetPenStyle(false)); 
	    pPara->SetLOGBRUSH(penattrib->GetBrushStyle(false)); 
        m_list.AddTail(pPara); 
        m_list.SetEditStatus(true); 
	} 
	else 
	{ 
        CShape* pPara=new CRectangle(m_begPT,m_endPT,m_thirdPT,m_fourthPT,false); 
	    pPara->SetLOGPEN(penattrib->GetPenStyle(false)); 
	    pPara->SetLOGBRUSH(penattrib->GetBrushStyle(false)); 
	    m_list.AddTail(pPara); 
        m_list.SetEditStatus(true); 
	} 
    
} 
 
 
void CParaTool::OnRButtonDown(WPARAM wParam,LPARAM lParam) 
{ 
 
  m_hdc=GetDC(m_hWnd);  
  if(m_status==FirstClick) 
  { 
//	  penattrib->GetPen(m_hdc,true);	   
      m_line1.OnLButtonDown(wParam,lParam); 
	  ::InvalidateRect(m_hWnd,NULL,true); 
       
  } 
  else if(m_status==SecClick) 
  { 
    penattrib->GetPen(m_hdc,true); 
    this->Draw(); 
	penattrib->ReleasePen(true); 
    ::InvalidateRect(m_hWnd,NULL,true); 
      
  } 
 
  m_status=NoClick; 
  m_isFirstDraw=true; 
 
  ReleaseDC(m_hWnd,m_hdc); 
 
} 
 
void CParaTool::RollBackOper(HDC &hdc) 
{ 
	 
   
}