📄 stroke.cpp
字号:
#include "StdAfx.h"
#include ".\stroke.h"
/////////////////////////////////////////////////////////////////////////////
// CStroke
CStroke::CStroke()
{
// This empty constructor should be used by serialization only
}
CStroke::CStroke(UINT nPenWidth)
{
m_nPenWidth = nPenWidth;
m_rectBounding.SetRectEmpty();
}
BOOL CStroke::DrawStroke(CDC* pDC)
{
//CPen penStroke;
//if (!penStroke.CreatePen(PS_SOLID, m_nPenWidth, RGB(0,0,0)))
// return FALSE;
//CPen* pOldPen = pDC->SelectObject(&penStroke);
pDC->MoveTo(m_pointArray[0]);
for (int i=1; i < m_pointArray.GetSize(); i++)
{
pDC->LineTo(m_pointArray[i]);
}
//pDC->SelectObject(pOldPen);
return TRUE;
}
BOOL CStroke::DrawStroke(CDC* pDC, float fXFactor, float fYFactor)
{
//CPen penStroke;
//if (!penStroke.CreatePen(PS_SOLID, m_nPenWidth, RGB(0,0,0)))
// return FALSE;
//CPen* pOldPen = pDC->SelectObject(&penStroke);
pDC->MoveTo(
(int)((float) m_pointArray[0].x * fXFactor),
(int)((float) m_pointArray[0].y * fYFactor));
for (int i=1; i < m_pointArray.GetSize(); i++)
{
pDC->LineTo(
(int)((float) m_pointArray[i].x * fXFactor),
(int)((float) m_pointArray[i].y * fYFactor));
}
//pDC->SelectObject(pOldPen);
return TRUE;
}
void CStroke::FinishStroke()
{
// Calculate the bounding rectangle. It's needed for smart
// repainting.
if (m_pointArray.GetSize()==0)
{
m_rectBounding.SetRectEmpty();
return;
}
CPoint pt = m_pointArray[0];
m_rectBounding = CRect(pt.x, pt.y, pt.x, pt.y);
for (int i=1; i < m_pointArray.GetSize(); i++)
{
// If the point lies outside of the accumulated bounding
// rectangle, then inflate the bounding rect to include it.
pt = m_pointArray[i];
m_rectBounding.left = min(m_rectBounding.left, pt.x);
m_rectBounding.right = max(m_rectBounding.right, pt.x);
m_rectBounding.top = max(m_rectBounding.top, pt.y);
m_rectBounding.bottom = min(m_rectBounding.bottom, pt.y);
}
// Add the pen width to the bounding rectangle. This is necessary
// to account for the width of the stroke when invalidating
// the screen.
m_rectBounding.InflateRect(CSize(m_nPenWidth, -(int)m_nPenWidth));
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -