UiAnimViewSplineCtrl.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <LyShine/Animation/IUiAnimation.h>
  10. #include "Controls/UiSplineCtrlEx.h"
  11. #include <functional>
  12. class CUiAnimViewTrack;
  13. /** A customized spline control for CUiAnimViewGraph.
  14. */
  15. class CUiAnimViewSplineCtrl
  16. : public SplineWidget
  17. {
  18. friend class CUndoUiAnimViewSplineCtrl;
  19. public:
  20. CUiAnimViewSplineCtrl(QWidget* parent);
  21. virtual ~CUiAnimViewSplineCtrl();
  22. void ClearSelection() override;
  23. void AddSpline(ISplineInterpolator* pSpline, CUiAnimViewTrack* pTrack, const QColor& color);
  24. void AddSpline(ISplineInterpolator * pSpline, CUiAnimViewTrack * pTrack, QColor anColorArray[4]);
  25. const std::vector<CUiAnimViewTrack*>& GetTracks() const { return m_tracks; }
  26. void RemoveAllSplines();
  27. void OnUserCommand(UINT cmd);
  28. bool IsUnifiedKeyCurrentlySelected() const;
  29. bool IsKeysFrozen() const { return m_bKeysFreeze; }
  30. bool IsTangentsFrozen() const { return m_bTangentsFreeze; }
  31. void SetPlayCallback(const std::function<void()>& callback);
  32. protected:
  33. void mouseMoveEvent(QMouseEvent* event) override;
  34. void mousePressEvent(QMouseEvent* event) override;
  35. void mouseReleaseEvent(QMouseEvent* event) override;
  36. void mouseDoubleClickEvent(QMouseEvent* event) override;
  37. void keyPressEvent(QKeyEvent* event) override;
  38. void wheelEvent(QWheelEvent* event) override;
  39. private:
  40. virtual void SelectKey(ISplineInterpolator* pSpline, int nKey, int nDimension, bool bSelect) override;
  41. virtual void SelectRectangle(const QRect& rc, bool bSelect) override;
  42. std::vector<CUiAnimViewTrack*> m_tracks;
  43. virtual bool GetTangentHandlePts(QPoint& inTangentPt, QPoint& pt, QPoint& outTangentPt,
  44. int nSpline, int nKey, int nDimension) override;
  45. void ComputeIncomingTangentAndEaseTo(float& ds, float& easeTo, QPoint inTangentPt,
  46. int nSpline, int nKey, int nDimension);
  47. void ComputeOutgoingTangentAndEaseFrom(float& dd, float& easeFrom, QPoint outTangentPt,
  48. int nSpline, int nKey, int nDimension);
  49. void AdjustTCB(float d_tension, float d_continuity, float d_bias);
  50. void MoveSelectedTangentHandleTo(const QPoint& point);
  51. ISplineCtrlUndo* CreateSplineCtrlUndoObject(std::vector<ISplineInterpolator*>& splineContainer) override;
  52. bool m_bKeysFreeze;
  53. bool m_bTangentsFreeze;
  54. std::function<void()> m_playCallback;
  55. };