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.
kev/Drawer/Module/GeoSigmaDraw/HTrackerHandleCalculator.cpp

93 lines
2.1 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include "stdafx.h"
#include "HTrackerHandleCalculator.h"
HTrackerHandleCalculator::HTrackerHandleCalculator()
:m_HandleSize(12)
{
memset(m_Points, 0, sizeof(m_Points));
}
//创建Tracker矩形的四个角点和中心点
void HTrackerHandleCalculator::Calculate(const CRect & boundRect)
{
//CRect rc(boundRect);
//rc.InflateRect(m_OuterMargin, m_OuterMargin);
m_Points[0].x = m_Points[3].x = boundRect.left;
m_Points[1].x = m_Points[2].x = boundRect.right;
m_Points[0].y = m_Points[1].y = boundRect.top;
m_Points[2].y = m_Points[3].y = boundRect.bottom;
m_Points[4] = boundRect.CenterPoint();
}
CRect HTrackerHandleCalculator::GetHandleRect(int iHandle)
{
//if (iHandle == HandleBody)
//return m_StartRect;
CRect rc;
rc.SetRectEmpty();
rc.OffsetRect(GetHandlePoint(m_Points, iHandle));
int d = m_HandleSize / 2;
rc.InflateRect(d, d);
return rc;
}
CPoint HTrackerHandleCalculator::GetHandlePoint(int iHandle)
{
return GetHandlePoint(m_Points, iHandle);
}
POINT HTrackerHandleCalculator::GetCenterPoint()
{
return m_Points[4];
}
void HTrackerHandleCalculator::Reset()
{
memset(m_Points, 0, sizeof(m_Points));
}
POINT HTrackerHandleCalculator::Test(int i)
{
return m_Points[i];
}
//pPoints为m_PointSrc
CPoint HTrackerHandleCalculator::GetHandlePoint(LPPOINT pPoints, int iHandle)
{
// Handles are numbered clockwise, like this:
//
// HandleTopLeft HandleTop HandleTopRight
// 0 1 2
// *-----------*-----------*
// | |
// | |
// HandleLeft 7 * * 8 * 3 HandleRight
// | HandleCenter |
// | |
// *-----------*-----------*
// 6 5 4
// HandleBottomLeft HandleBottom HandleBottomRight
//
// The center point is handle 8, the HandleBody is handle 9.
if (iHandle >= 8)
return pPoints[4]; // center
//如果为偶数点,则为角点。
//m_PointSrc前四个点为角点。iHandle点隔一点就是角点。
//所以除以2就获得了iHandle对应的角点的索引。
int i = iHandle / 2;
if ((iHandle & 1) == 0)
return pPoints[i]; // corner
int j = i + 1;
if (j > 3) j = 0;
//求出边线的中点
CPoint pnt;
pnt.x = (pPoints[i].x + pPoints[j].x) / 2;
pnt.y = (pPoints[i].y + pPoints[j].y) / 2;
return pnt; // edge
}