// ============================================================================ // Draw points and curves // ============================================================================ void CBezierWnd::Draw() { // Draw control point handles and labels for ( PointSetIt i = m_Points.begin(); i != m_Points.end(); ++i ) { DrawHandle( *i ); DrawLabel( *i ); } if ( m_Points.size() < 3) return; // Draw curve PointList lPoints; for ( PointSetIt i = m_Points.begin(); i != m_Points.end(); ++i ) lPoints.push_back( *i ); CPoint2D p2DStart = *m_Points.begin(); float fStep = 1.f / ( 10.f * ( float ) lPoints.size() ); for ( float i = 0.f; i <= 1.f; i+= fStep ) { CPoint2D p2D = GetBezierPoint( lPoints, i ); DrawLine( p2DStart, p2D ); p2DStart = p2D; } DrawLine( p2DStart, lPoints.back() ); // Draw control polygon if ( m_bDrawPoly ) { PointSetIt i = m_Points.begin(), iPrev = i++; do { DrawLine( *iPrev, *i ); iPrev = i++; } while ( i != m_Points.end() ); } }
void CTrack::DrawHandles(HDC hDC, bool bOn, CPoint* pCorners) { CPoint ptRotate(0,0); CPoint ptCenter(0,0); for (int h = 0; h < NUM_HANDLES; h++) { if (!m_iHandleInUse[h]) continue; switch (h) { case H_UL: case H_UR: case H_LR: case H_LL: { int i = h - H_UL; m_hHandleRects[h].left = pCorners[i].x; m_hHandleRects[h].top = pCorners[i].y; break; } case H_TOP: { m_hHandleRects[h].left = (pCorners[0].x + pCorners[1].x)/2; m_hHandleRects[h].top = (pCorners[0].y + pCorners[1].y)/2; break; } case H_RIGHT: { m_hHandleRects[h].left = (pCorners[1].x + pCorners[2].x)/2; m_hHandleRects[h].top = (pCorners[1].y + pCorners[2].y)/2; break; } case H_BOTTOM: { m_hHandleRects[h].left = (pCorners[2].x + pCorners[3].x)/2; m_hHandleRects[h].top = (pCorners[2].y + pCorners[3].y)/2; break; } case H_LEFT: { m_hHandleRects[h].left = (pCorners[3].x + pCorners[0].x)/2; m_hHandleRects[h].top = (pCorners[3].y + pCorners[0].y)/2; break; } case H_ROTATE: { m_Matrix.Transform(m_ptRotate, m_hHandleRects[h].left, m_hHandleRects[h].top); m_ViewToDeviceMatrix.Transform((CPoint&)m_hHandleRects[h].left); ptRotate.x = m_hHandleRects[h].left; ptRotate.y = m_hHandleRects[h].top; break; } case H_CENTER: { m_Matrix.Transform(m_ptCenter, m_hHandleRects[h].left, m_hHandleRects[h].top); m_ViewToDeviceMatrix.Transform((CPoint&)m_hHandleRects[h].left); ptCenter.x = m_hHandleRects[h].left; ptCenter.y = m_hHandleRects[h].top; break; } case H_CORNER_UL: case H_CORNER_UR: case H_CORNER_LR: case H_CORNER_LL: { int i = h - H_CORNER_UL; m_Matrix.Transform(m_Distort.p[i], m_hHandleRects[h].left, m_hHandleRects[h].top); m_ViewToDeviceMatrix.Transform((CPoint&)m_hHandleRects[h].left); break; } default: break; } m_hHandleRects[h].left -= (H_SIZE/2); m_hHandleRects[h].top -= (H_SIZE/2); m_hHandleRects[h].right = m_hHandleRects[h].left + H_SIZE; m_hHandleRects[h].bottom = m_hHandleRects[h].top + H_SIZE; DrawHandle(hDC, &m_hHandleRects[h], h >= H_CENTER, bOn); } if (ptRotate.x || ptRotate.y || ptCenter.x || ptCenter.y) DrawLine(hDC, ptCenter.x, ptCenter.y, ptRotate.x, ptRotate.y, bOn); }