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


// EllipseTool.cpp: implementation of the CEllipseTool class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "EllipseTool.h" 
#include "Shape.h" 
#include "Ellipse.h" 
 
extern CList<CShape *> m_list; 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
 
CEllipseTool::CEllipseTool(HWND hWnd):CTool(hWnd),m_IsFirstOpe(true) 
{ 
 
} 
 
CEllipseTool::~CEllipseTool() 
{ 
 
} 
 
void CEllipseTool::SaveSelf() 
{ 
	CShape *newrect = new CEllipse(m_begPT,m_endPT); 
	newrect->SetLOGPEN(penattrib->GetPenStyle(false)); 
	newrect->SetLOGBRUSH(penattrib->GetBrushStyle(false));  
 
	m_list.AddTail(newrect); 
    m_list.SetEditStatus(true); 
} 
 
void CEllipseTool::PreDraw() 
{ 
	if(m_IsFirstOpe) 
	{ 
      m_IsFirstOpe=false; 
	} 
	else 
	{ 
	  EllipseToBezier(m_hdc,m_begPT.GetPoint().x,m_begPT.GetPoint().y, 
		m_oldPT.GetPoint().x,m_oldPT.GetPoint().y); 
	} 
     
	EllipseToBezier(m_hdc,m_begPT.GetPoint().x,	m_begPT.GetPoint().y, 
		m_endPT.GetPoint().x,m_endPT.GetPoint().y); 
	m_oldPT = m_endPT; 
 
} 
 
void CEllipseTool::Draw() 
{ 
	EllipseToBezier(m_hdc,m_begPT.GetPoint().x,	m_begPT.GetPoint().y, 
		m_endPT.GetPoint().x,m_endPT.GetPoint().y); 
 
   m_IsFirstOpe=true; 
} 
 
bool CEllipseTool::EllipseToBezier(HDC hDC, int left, int top, int right, int bottom) 
{ 
const double M = 0.55228474983; 
  int dx = (int) ((right - left) * (1-M) / 2); 
  int dy = (int) ((bottom - top) * (1-M) / 2); 
 
  m_p[ 0].x = right;            //   .   .   .   .   . 
  m_p[ 0].y = (top+bottom)/2;   //       4   3   2 
  m_p[ 1].x = right;            // 
  m_p[ 1].y = top + dy;         //   5               1 
  m_p[ 2].x = right - dx;       // 
  m_p[ 2].y = top;              //   6              0,12 
  m_p[ 3].x = (left+right)/2;   // 
  m_p[ 3].y = top;              //   7               11 
                              // 
  m_p[ 4].x = left + dx;        //       8   9   10 
  m_p[ 4].y = top; 
  m_p[ 5].x = left; 
  m_p[ 5].y = top + dy; 
  m_p[ 6].x = left; 
  m_p[ 6].y = (top+bottom)/2; 
 
  m_p[ 7].x = left; 
  m_p[ 7].y = bottom - dy; 
  m_p[ 8].x = left + dx; 
  m_p[ 8].y = bottom; 
  m_p[ 9].x = (left+right)/2; 
  m_p[ 9].y = bottom; 
  m_p[10].x = right - dx; 
  m_p[10].y = bottom; 
  m_p[11].x = right; 
  m_p[11].y = bottom - dy; 
  m_p[12].x = right; 
  m_p[12].y = (top+bottom)/2; 
 
  return PolyBezier(hDC, m_p, 13); 
 
}