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/CurveEditorCosine.cpp

164 lines
3.1 KiB
C++

#include "StdAfx.h"
#include "CurveEditorCosine.h"
#include "SigmaDoc.h"
namespace NItem
{
void CurveEditorCosine::OnDrawDragPreview()
{
if (NewPointList.IsEmpty()) return;
CXyDC* pDC = GetDC();
CPen pen(PS_SOLID, 0, DRAG_LINE_COLOR);
CPen* op = m_pScreenDC->SelectObject(&pen);
int od = m_pScreenDC->SetROP2(R2_NOTXORPEN);
dfPoint dp1, dp2;
POSITION pos;
dp1 = NewPointList.GetHead();
pos = NewPointList.GetHeadPosition();
if (pos) NewPointList.GetNext(pos);
while (pos)
{
dp2 = NewPointList.GetNext(pos);
CPoint ptS1 = pDC->GetScreen(dp1);
m_pScreenDC->MoveTo(ptS1);
CPoint ptS2 = pDC->GetScreen(dp2);
m_pScreenDC->LineTo(ptS2);
dp1 = dp2;
}
m_pScreenDC->SetROP2(od);
m_pScreenDC->SelectObject(op);
}
void CurveEditorCosine::OnCalculateDragEffect(CPointList* pList)
{
BOOL bRedraw = TRUE;
BOOL bAttachProcess = TRUE;
CCurveEx* pValue = (CCurveEx*)GetDoc()->GetDraw()->GetAtValue(GetPos());
if (pList)
{
CCurveEx* pc = new CCurveEx;
*pc = *pValue;
pValue = pc;
bRedraw = FALSE;
bAttachProcess = FALSE;
}
CPointList oldPoints;
CPointList newPoints;
dfPoint pt;
// ?????????????????§ß??
int begin, end;
GetDragPoint(c_last, NewPointList, begin, end);
// ???????????????????
POSITION pos = NewPointList.GetHeadPosition();
for (int i = begin; i <= end && pos; i++)
{
dfPoint dp = NewPointList.GetNext(pos);
// ?????????
if (bAttachProcess)
{
pValue->GetPoint(i, pt);
oldPoints.AddTail(pt);
}
// ????????
pValue->x[i] = dp.x0;
pValue->y[i] = dp.y0;
// ?????????
if (bAttachProcess)
{
pValue->GetPoint(i, pt);
newPoints.AddTail(pt);
}
}
if (pValue->bAutoLocation) pValue->GetLocation();
// ??????
if (bAttachProcess)
{
if (oldPoints.GetCount() > 0)
AttachProcess(oldPoints, newPoints);
}
if (pList)
{
pValue->GetPoint(*pList);
delete pValue;
}
}
double CurveEditorCosine::GetPointOffset(double offset)
{
// ????????????????????§³??????????????
offset = 1.0 + cos(PI * offset);
offset *= offset * 0.25;
return offset;
}
void CurveEditorCosine::GetDragPoint(CPoint2D& dp, CPointList& NewPointList, int& begin, int& end)
{
int i = GetHandleIndex();
if (i < 0) return;
NewPointList.RemoveAll();
CCurveEx* pValue = (CCurveEx*)GetDoc()->GetDraw()->GetAtValue(GetPos());
dfPoint cp, t;
double distance, x0, y0, d;
int j;
begin = i;
end = i;
distance = 9; // ??????9????¦Ë
GetXY(pValue, i, cp);
// ????????????????????
for (j = i; j >= 0; j--)
{
GetXY(pValue, j, t);
d = fabs(t.l - cp.l);
begin = j;
if (d >= distance)
{
NewPointList.AddHead(t);
break;
}
// ??????????
x0 = GetPointOffset(d / distance);
y0 = (x0) * (dp.y0 - cp.y0);
x0 = (x0) * (dp.x0 - cp.x0);
t.Offset(x0, y0);
NewPointList.AddHead(t);
}
// ????????????????????????????
for (j = i + 1; j < pValue->num; j++)
{
GetXY(pValue, j, t);
d = fabs(t.l - cp.l);
end = j;
if (d >= distance)
{
NewPointList.AddTail(t);
break;
}
// ??????????
x0 = GetPointOffset(d / distance);
y0 = (x0) * (dp.y0 - cp.y0);
x0 = (x0) * (dp.x0 - cp.x0);
t.Offset(x0, y0);
NewPointList.AddTail(t);
}
}
}; // namespace