#include "StdAfx.h"
|
#include "Shape2D.h"
|
#include "math.h"
|
|
//-----------------------------
|
// ÐÎ×´
|
//-----------------------------
|
CShape2D::CShape2D(void)
|
{
|
m_nLineWidth = 1;
|
m_crLineColor = Color::Red;
|
}
|
|
CShape2D::~CShape2D(void)
|
{
|
}
|
void CShape2D::SetStartPoint(Point ptStart)
|
{
|
m_ptStart = ptStart;
|
}
|
void CShape2D::SetEndPoint(Point ptEnd)
|
{
|
m_ptEnd = ptEnd;
|
}
|
void CShape2D::SetLineWidth(UINT nLineWidth)
|
{
|
m_nLineWidth = nLineWidth;
|
}
|
void CShape2D::SetLineColor(Color crLineColor)
|
{
|
m_crLineColor = crLineColor;
|
}
|
|
void CShape2D::SetClipArea(Rect rcClipArea)
|
{
|
m_rcClipArea = rcClipArea;
|
}
|
|
//-----------------------------
|
// ¾ØÐÎ
|
//-----------------------------
|
CRectangle2D::CRectangle2D(){}
|
CRectangle2D::~CRectangle2D(){}
|
|
void CRectangle2D::Draw(Graphics& g)
|
{
|
if(m_ptEnd.X < m_rcClipArea.X)
|
{
|
m_ptEnd.X = m_rcClipArea.X;
|
}
|
if(m_ptEnd.X > m_rcClipArea.X + m_rcClipArea.Width)
|
{
|
m_ptEnd.X = m_rcClipArea.X + m_rcClipArea.Width;
|
}
|
|
if(m_ptEnd.Y < m_rcClipArea.Y)
|
{
|
m_ptEnd.Y = m_rcClipArea.Y;
|
}
|
if(m_ptEnd.Y > m_rcClipArea.Y + m_rcClipArea.Height)
|
{
|
m_ptEnd.Y = m_rcClipArea.Y + m_rcClipArea.Height;
|
}
|
|
Rect rc;
|
if(m_ptEnd.X < m_ptStart.X)
|
{
|
rc.X = m_ptEnd.X;
|
rc.Width = m_ptStart.X - m_ptEnd.X;
|
}else
|
{
|
rc.X = m_ptStart.X;
|
rc.Width = m_ptEnd.X - m_ptStart.X;
|
}
|
|
if(m_ptEnd.Y < m_ptStart.Y)
|
{
|
rc.Y = m_ptEnd.Y;
|
rc.Height = m_ptStart.Y - m_ptEnd.Y;
|
}else
|
{
|
rc.Y = m_ptStart.Y;
|
rc.Height = m_ptEnd.Y - m_ptStart.Y;
|
}
|
|
Pen pen(m_crLineColor,m_nLineWidth);
|
|
g.DrawRectangle(&pen,rc);
|
|
}
|
|
//--------------------------------
|
// ÍÖÔ²
|
//--------------------------------
|
CEllipse2D::CEllipse2D(){}
|
CEllipse2D::~CEllipse2D(){}
|
|
void CEllipse2D::Draw(Graphics& g)
|
{
|
if(m_ptEnd.X < m_rcClipArea.X)
|
{
|
m_ptEnd.X = m_rcClipArea.X;
|
}
|
if(m_ptEnd.X > m_rcClipArea.X + m_rcClipArea.Width)
|
{
|
m_ptEnd.X = m_rcClipArea.X + m_rcClipArea.Width;
|
}
|
|
if(m_ptEnd.Y < m_rcClipArea.Y)
|
{
|
m_ptEnd.Y = m_rcClipArea.Y;
|
}
|
if(m_ptEnd.Y > m_rcClipArea.Y + m_rcClipArea.Height)
|
{
|
m_ptEnd.Y = m_rcClipArea.Y + m_rcClipArea.Height;
|
}
|
|
Rect rc;
|
if(m_ptEnd.X < m_ptStart.X)
|
{
|
rc.X = m_ptEnd.X;
|
rc.Width = m_ptStart.X - m_ptEnd.X;
|
}else
|
{
|
rc.X = m_ptStart.X;
|
rc.Width = m_ptEnd.X - m_ptStart.X;
|
}
|
|
if(m_ptEnd.Y < m_ptStart.Y)
|
{
|
rc.Y = m_ptEnd.Y;
|
rc.Height = m_ptStart.Y - m_ptEnd.Y;
|
}else
|
{
|
rc.Y = m_ptStart.Y;
|
rc.Height = m_ptEnd.Y - m_ptStart.Y;
|
}
|
|
Pen pen(m_crLineColor,m_nLineWidth);
|
|
g.DrawEllipse(&pen,rc);
|
|
}
|
|
//------------------------------------
|
// ¼ýÍ·
|
//-------------------------------------
|
void CArrow2D::Draw(Graphics& g)
|
{
|
|
if(m_ptEnd.X < m_rcClipArea.X)
|
{
|
m_ptEnd.X = m_rcClipArea.X;
|
}
|
if(m_ptEnd.X > m_rcClipArea.X + m_rcClipArea.Width)
|
{
|
m_ptEnd.X = m_rcClipArea.X + m_rcClipArea.Width;
|
}
|
|
if(m_ptEnd.Y < m_rcClipArea.Y)
|
{
|
m_ptEnd.Y = m_rcClipArea.Y;
|
}
|
if(m_ptEnd.Y > m_rcClipArea.Y + m_rcClipArea.Height)
|
{
|
m_ptEnd.Y = m_rcClipArea.Y + m_rcClipArea.Height;
|
}
|
|
Pen pen(m_crLineColor,m_nLineWidth);
|
g.DrawLine(&pen,m_ptStart,m_ptEnd);
|
|
double slopy, cosy, siny;
|
Point ptVertex[4];
|
|
slopy = atan2( (float)( m_ptStart.Y - m_ptEnd.Y ),
|
(float)( m_ptStart.X - m_ptEnd.X ) );
|
cosy = cos( slopy );
|
siny = sin( slopy );
|
|
ptVertex[0].X = m_ptEnd.X;
|
ptVertex[0].Y = m_ptEnd.Y;
|
ptVertex[1].X = m_ptEnd.X + int(ARROWLEN * cosy - ARROWLEN / 2.0 * siny);
|
ptVertex[1].Y = m_ptEnd.Y + int(ARROWLEN * siny + ARROWLEN / 2.0 * cosy);
|
ptVertex[2].X = m_ptEnd.X + int(ARROWLEN * cosy + ARROWLEN / 2.0 * siny);
|
ptVertex[2].Y = m_ptEnd.Y - int(ARROWLEN / 2.0 * cosy - ARROWLEN * siny);
|
ptVertex[3].X = ptVertex[0].X;
|
ptVertex[3].Y = ptVertex[0].Y;
|
|
SolidBrush brushSolid( m_crLineColor );
|
g.FillPolygon( &brushSolid, ptVertex, 4 );
|
}
|
|
//-------------------------------------
|
// »Ë¢(ÏßÌõ)
|
//-------------------------------------
|
|
void CBrush2D::SetStartPoint(Point ptStart)
|
{
|
if(ptStart.X < m_rcClipArea.X)
|
{
|
ptStart.X = m_rcClipArea.X;
|
}
|
if(ptStart.X > m_rcClipArea.X + m_rcClipArea.Width)
|
{
|
ptStart.X = m_rcClipArea.X + m_rcClipArea.Width;
|
}
|
|
if(ptStart.Y < m_rcClipArea.Y)
|
{
|
ptStart.Y = m_rcClipArea.Y;
|
}
|
if(ptStart.Y > m_rcClipArea.Y + m_rcClipArea.Height)
|
{
|
ptStart.Y = m_rcClipArea.Y + m_rcClipArea.Height;
|
}
|
m_arrPoints.Add(new Point(ptStart.X,ptStart.Y));
|
}
|
|
void CBrush2D::SetEndPoint(Point ptEnd)
|
{
|
if(ptEnd.X < m_rcClipArea.X)
|
{
|
ptEnd.X = m_rcClipArea.X;
|
}
|
if(ptEnd.X > m_rcClipArea.X + m_rcClipArea.Width)
|
{
|
ptEnd.X = m_rcClipArea.X + m_rcClipArea.Width;
|
}
|
|
if(ptEnd.Y < m_rcClipArea.Y)
|
{
|
ptEnd.Y = m_rcClipArea.Y;
|
}
|
if(ptEnd.Y > m_rcClipArea.Y + m_rcClipArea.Height)
|
{
|
ptEnd.Y = m_rcClipArea.Y + m_rcClipArea.Height;
|
}
|
m_arrPoints.Add(new Point(ptEnd.X,ptEnd.Y));
|
}
|
void CBrush2D::Draw(Graphics& g)
|
{
|
Pen pen(m_crLineColor,m_nLineWidth);
|
for(int i = 1;i<m_arrPoints.GetCount();i++)
|
{
|
g.DrawLine(&pen,m_arrPoints[i-1]->X,m_arrPoints[i-1]->Y,m_arrPoints[i]->X,m_arrPoints[i]->Y);
|
}
|
}
|
|
void CText2D::SetRect(Rect rcClient)
|
{
|
m_rcClient.X = rcClient.X;
|
m_rcClient.Y = rcClient.Y;
|
m_rcClient.Width = rcClient.Width;
|
m_rcClient.Height = rcClient.Height;
|
}
|
|
void CText2D::SetResize(bool bResize)
|
{
|
m_bResize = bResize;
|
}
|
|
Rect CText2D::GetRect()
|
{
|
if(m_rcClient.Height < 14)
|
m_rcClient.Height = 14;
|
if(m_rcClient.Width < 60)
|
m_rcClient.Width = 40;
|
return m_rcClient;
|
}
|
void CText2D::Draw(Graphics& g)
|
{
|
if(m_ptEnd.X < m_rcClipArea.X)
|
{
|
m_ptEnd.X = m_rcClipArea.X;
|
}
|
if(m_ptEnd.X > m_rcClipArea.X + m_rcClipArea.Width)
|
{
|
m_ptEnd.X = m_rcClipArea.X + m_rcClipArea.Width;
|
}
|
|
if(m_ptEnd.Y < m_rcClipArea.Y)
|
{
|
m_ptEnd.Y = m_rcClipArea.Y;
|
}
|
if(m_ptEnd.Y > m_rcClipArea.Y + m_rcClipArea.Height)
|
{
|
m_ptEnd.Y = m_rcClipArea.Y + m_rcClipArea.Height;
|
}
|
|
Rect rc;
|
if(m_ptEnd.X < m_ptStart.X)
|
{
|
rc.X = m_ptEnd.X;
|
rc.Width = m_ptStart.X - m_ptEnd.X;
|
}else
|
{
|
rc.X = m_ptStart.X;
|
rc.Width = m_ptEnd.X - m_ptStart.X;
|
}
|
|
if(m_ptEnd.Y < m_ptStart.Y)
|
{
|
rc.Y = m_ptEnd.Y;
|
rc.Height = m_ptStart.Y - m_ptEnd.Y;
|
}else
|
{
|
rc.Y = m_ptStart.Y;
|
rc.Height = m_ptEnd.Y - m_ptStart.Y;
|
}
|
|
if(!m_bResize)
|
m_rcClient = rc;
|
|
Pen pen(Color::Black);
|
pen.SetDashStyle(DashStyleDash);
|
g.DrawRectangle(&pen,m_rcClient);
|
|
}
|