#pragma once #include "CurveEditorBase.h" #include "HandleDrawer.h" #include "SegmentSnappingEngine.h" #include #include /* * ????????????? * * ????? * 1. ????????????????? * 2. ?????????????????? * 3. ?????????? */ class CurveEditorDefault : public CurveEditorBase { public: CurveEditorDefault(CSigmaDoc* pDoc) : CurveEditorBase(pDoc) , m_bLButtonDownWhenMouseMove(false) , m_handleDrawer(std::make_unique(pDoc)) , m_nHandleDrawMode(TRACKER_CIRCLE) , m_nModeX(-1) , m_nModeY(-1) , m_nDragSegmentIndex(-1) {} virtual ~CurveEditorDefault(void) {} // Mouse event handlers void OnDraw(CXyDC* pDC) override; void OnLButtonDblClk(UINT nFlags, CPoint point) override; void OnLButtonDown(CDC* pDC, UINT nFlags, CPoint point, int vk) override; int OnMouseMove(CDC* pDC, UINT nFlags, CPoint point) override; void OnLButtonUp(CDC* pDC, UINT nFlags, CPoint point, int vk) override; BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) override; BOOL OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) override; BOOL OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) override; int GetSubMenu() override; void SetPos(POSITION pos) override; void Clear(void) override; void Draw(CDC* pDC) override; void DrawAssistant(CDC* pDC, int mouseX, int mouseY) override; int GetNumberOfNode() override; void EreaseHandles(CDC* pDC) override; void EndEdit(void) override; void CancelAll(void) override; BOOL IsCanCancelAll(void) override; // Control point operations int HitTestHandle(CPoint point) override; void DeleteHandle(int nIndex) override; int AddHandle(CPoint point) override; BOOL IsCanAddHandle(CPoint point, double* pl0 = nullptr) override; CCurveEx* GetControlCurve(void) override; void GetXY(CCurveEx* pValue, int nIndex, dfPoint& point) override; void AttachProcess(CPointList& oldPoints, CPointList& newPoints) override; void DrawMoveLine(void) override; void GetMarkCurve(void) override; CPoint2D GetCDown() const override; CPoint2D GetCLast() const override; protected: void OnDrawDragPreview(); void OnCalculateDragEffect(CPointList* pList); void OnModeInitialize(); void OnDragMove(int nIndex, CPoint2D pt); int GetOffsetMode(void); int AddHandle(double l0); int AddHandle(CCurveEx* pValue, dfPoint add); // CPoint2D c_down, c_last; // ?????????? bool m_bLButtonDownWhenMouseMove; // ???? std::unique_ptr m_pBakOne; // ???????????? std::unique_ptr m_handleDrawer; // ?????? CPoint m_nLButtonDownPoint; // ??????????? CPointList NewPointList; // ?????????? CPointList PointList; // ????? DWORD m_nHandleDrawMode; // ??????? int m_nModeX, m_nModeY; // ???? // 线段拖动相关成员变量 int m_nDragSegmentIndex; // 当前拖动的线段索引 (-1表示未拖动) Geometry::SnapResult m_lastSnapResult; // 最后一次吸附结果 private: void DrawHandle(CXyDC* pDC, CCurveEx* pCurve); void DrawHandlesByCDC(CDC* pDC, CCurveEx* pCurve); void DrawSelectHandle(int nHandle); CRect GetRangeWidthIndex(int nIndex); CRect GetFirstNodeHandleRectFocus(CPoint point); void SetDrawMode(int nModeX, int nModeY); int HitTestHandle(CCurveEx* pValue, CPoint point); bool IsDragging(int nFlags) const; int HandleMouseDrag(CXyDC* pDC, CPoint point); int HandleMouseHover(CDC* dc, CPoint point); // 线段拖动相关辅助函数 int HitTestSegment(CPoint point); void DrawMoveSegment(CDC* pDC); NBase::CPoint2D CalculateSnappedMousePos(NBase::CPoint2D rawMouse, int segmentIndex); NBase::CPoint2D CalculateNormalOffset(dfPoint p1, dfPoint p2, double dx, double dy); double DistancePointToLine(double px, double py, double x1, double y1, double x2, double y2); CRect8 GetLineSegmentAABB(const dfPoint& point1, const dfPoint& point2, double width) const; };