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.
117 lines
3.5 KiB
C++
117 lines
3.5 KiB
C++
|
1 month ago
|
#include "StdAfx.h"
|
||
|
|
#include "SplineEditorRenderer.h"
|
||
|
|
#include "SigmaDoc.h"
|
||
|
|
|
||
|
|
SplineEditorRenderer::SplineEditorRenderer(CSigmaDoc* pDoc, HandleDrawer* pHandleDrawer)
|
||
|
|
: m_pDoc(pDoc)
|
||
|
|
, m_pHandleDrawer(pHandleDrawer)
|
||
|
|
{
|
||
|
|
}
|
||
|
|
|
||
|
|
void SplineEditorRenderer::DrawHandlesByCDC(CDC* pDC, CCurveEx* pCurve) const
|
||
|
|
{
|
||
|
|
if (pCurve == nullptr || m_pHandleDrawer == nullptr)
|
||
|
|
return;
|
||
|
|
m_pHandleDrawer->ClearAll(pDC);
|
||
|
|
m_pHandleDrawer->Init(pCurve);
|
||
|
|
m_pHandleDrawer->DrawAll(pDC);
|
||
|
|
}
|
||
|
|
|
||
|
|
void SplineEditorRenderer::DrawHandle(CXyDC* pDC, CDC* pScreenDC, CCurveEx* pCurve, int currentHandleIndex) const
|
||
|
|
{
|
||
|
|
if (pCurve == nullptr || m_pDoc == nullptr || pScreenDC == nullptr)
|
||
|
|
return;
|
||
|
|
CPoint ptPrev;
|
||
|
|
CRect rt;
|
||
|
|
dfPoint pt;
|
||
|
|
CPoint point;
|
||
|
|
for (int i = 0; i < pCurve->num; i++)
|
||
|
|
{
|
||
|
|
pCurve->GetPoint(i, pt);
|
||
|
|
point.x = pDC->GetSX(pt.x0);
|
||
|
|
point.y = pDC->GetSY(pt.y0);
|
||
|
|
if (i > 0)
|
||
|
|
{
|
||
|
|
if (point.x == ptPrev.x && point.y == ptPrev.y && i != currentHandleIndex)
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
if (i == currentHandleIndex)
|
||
|
|
{
|
||
|
|
if (i == 0)
|
||
|
|
rt = GetFirstNodeHandleRectFocus(point);
|
||
|
|
else
|
||
|
|
rt = m_pDoc->m_itemTracker.GetHandleRectFocus(point);
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
if (i == 0)
|
||
|
|
rt = m_pDoc->m_itemTracker.GetHandleRectFocus(point);
|
||
|
|
else
|
||
|
|
rt = m_pDoc->m_itemTracker.GetHandleRect(point);
|
||
|
|
}
|
||
|
|
m_pDoc->m_itemTracker.DrawHandle(pScreenDC, rt, TRACKER_CIRCLE);
|
||
|
|
ptPrev = point;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
void SplineEditorRenderer::DrawSelectHandle(CDC* pScreenDC, CXyDC* pXyDC, CCurveEx* pCurve, int nHandle, DWORD handleDrawMode) const
|
||
|
|
{
|
||
|
|
if (pCurve == nullptr || m_pDoc == nullptr || pScreenDC == nullptr || pXyDC == nullptr)
|
||
|
|
return;
|
||
|
|
if (nHandle < 0 || nHandle >= pCurve->num)
|
||
|
|
return;
|
||
|
|
CPoint point;
|
||
|
|
point.x = pXyDC->GetSX(pCurve->x[nHandle]);
|
||
|
|
point.y = pXyDC->GetSY(pCurve->y[nHandle]);
|
||
|
|
CRect rt = (nHandle == 0) ? GetFirstNodeHandleRectFocus(point) : m_pDoc->m_itemTracker.GetHandleRectFocus(point);
|
||
|
|
m_pDoc->m_itemTracker.DrawHandle(pScreenDC, rt, handleDrawMode);
|
||
|
|
}
|
||
|
|
|
||
|
|
void SplineEditorRenderer::DrawDragPreview(CDC* pScreenDC, CXyDC* pXyDC, const CPointList& newPointList) const
|
||
|
|
{
|
||
|
|
if (newPointList.IsEmpty() || pScreenDC == nullptr || pXyDC == nullptr)
|
||
|
|
return;
|
||
|
|
CPen pen(PS_SOLID, 0, DRAG_LINE_COLOR);
|
||
|
|
CPen* pOldPen = pScreenDC->SelectObject(&pen);
|
||
|
|
int oldRop2 = pScreenDC->SetROP2(R2_NOTXORPEN);
|
||
|
|
dfPoint dp1 = newPointList.GetHead();
|
||
|
|
dfPoint dp2;
|
||
|
|
POSITION pos = newPointList.GetHeadPosition();
|
||
|
|
if (pos)
|
||
|
|
newPointList.GetNext(pos);
|
||
|
|
while (pos)
|
||
|
|
{
|
||
|
|
dp2 = newPointList.GetNext(pos);
|
||
|
|
CPoint ptS1 = pXyDC->GetScreen(dp1);
|
||
|
|
pScreenDC->MoveTo(ptS1);
|
||
|
|
CPoint ptS2 = pXyDC->GetScreen(dp2);
|
||
|
|
pScreenDC->LineTo(ptS2);
|
||
|
|
dp1 = dp2;
|
||
|
|
}
|
||
|
|
pScreenDC->SetROP2(oldRop2);
|
||
|
|
pScreenDC->SelectObject(pOldPen);
|
||
|
|
}
|
||
|
|
|
||
|
|
CRect SplineEditorRenderer::GetRangeWidthIndex(CCurveEx* pCurve, int nIndex, CXyDC* pDC, CSize handleSize) const
|
||
|
|
{
|
||
|
|
if (pCurve == nullptr || pDC == nullptr || nIndex < 0 || nIndex >= pCurve->num)
|
||
|
|
return CRect(0, 0, 0, 0);
|
||
|
|
CRect8 rt(pCurve->x[nIndex], pCurve->y[nIndex], pCurve->x[nIndex], pCurve->y[nIndex]);
|
||
|
|
if (nIndex > 0)
|
||
|
|
rt.CombinRect(pCurve->x[nIndex - 1], pCurve->y[nIndex - 1], pCurve->x[nIndex - 1], pCurve->y[nIndex - 1]);
|
||
|
|
if (nIndex < pCurve->num - 1)
|
||
|
|
rt.CombinRect(pCurve->x[nIndex + 1], pCurve->y[nIndex + 1], pCurve->x[nIndex + 1], pCurve->y[nIndex + 1]);
|
||
|
|
CRect rect = pDC->GetScreen(rt);
|
||
|
|
rect.InflateRect(handleSize);
|
||
|
|
return rect;
|
||
|
|
}
|
||
|
|
|
||
|
|
CRect SplineEditorRenderer::GetFirstNodeHandleRectFocus(CPoint point) const
|
||
|
|
{
|
||
|
|
if (m_pDoc == nullptr)
|
||
|
|
return CRect(0, 0, 0, 0);
|
||
|
|
CRect rt = m_pDoc->m_itemTracker.GetHandleRectFocus(point);
|
||
|
|
rt.InflateRect(1, 1);
|
||
|
|
return rt;
|
||
|
|
}
|