UiAnimViewDopeSheetBase.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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/ReflectedPropertyControl/ReflectedPropertyCtrl.h>
  11. #include "UiAnimViewNode.h"
  12. #include "UiAnimViewSequence.h"
  13. #include "AnimationContext.h"
  14. class CUiAVTrackPropsDialog;
  15. class CUiAnimViewNodesCtrl;
  16. class CUiAnimViewKeyPropertiesDlg;
  17. class CUiAnimViewNode;
  18. class CUiAnimViewTrack;
  19. class CUiAnimViewAnimNode;
  20. class QRubberBand;
  21. class QScrollBar;
  22. enum EUiAVActionMode
  23. {
  24. eUiAVActionMode_MoveKey = 1,
  25. eUiAVActionMode_AddKeys,
  26. eUiAVActionMode_SlideKey,
  27. eUiAVActionMode_ScaleKey,
  28. };
  29. enum ESnappingMode
  30. {
  31. eSnappingMode_SnapNone = 0,
  32. eSnappingMode_SnapTick,
  33. eSnappingMode_SnapMagnet,
  34. eSnappingMode_SnapFrame,
  35. };
  36. enum EUiAVTickMode
  37. {
  38. eUiAVTickMode_InSeconds = 0,
  39. eUiAVTickMode_InFrames,
  40. };
  41. /** UiAnimView DopeSheet interface
  42. */
  43. class CUiAnimViewDopeSheetBase
  44. : public QWidget
  45. , public IUiAnimationContextListener
  46. , public IUiAnimViewSequenceListener
  47. {
  48. public:
  49. CUiAnimViewDopeSheetBase(QWidget* parent = 0);
  50. virtual ~CUiAnimViewDopeSheetBase();
  51. void SetNodesCtrl(CUiAnimViewNodesCtrl* pNodesCtrl) { m_pNodesCtrl = pNodesCtrl; }
  52. void SetTimeScale(float timeScale, float fAnchorTime);
  53. float GetTimeScale() { return m_timeScale; }
  54. void SetScrollOffset(int hpos);
  55. int GetScrollOffset();
  56. int GetScrollPos() const;
  57. void SetTimeRange(float start, float end);
  58. void SetStartMarker(float fTime);
  59. void SetEndMarker(float fTime);
  60. void SetMouseActionMode(EUiAVActionMode mode);
  61. void SetKeyPropertiesDlg(CUiAnimViewKeyPropertiesDlg* dlg) { m_keyPropertiesDlg = dlg; }
  62. void SetSnappingMode(ESnappingMode mode) { m_snappingMode = mode; }
  63. ESnappingMode GetSnappingMode() const { return m_snappingMode; }
  64. void SetSnapFPS(UINT fps);
  65. EUiAVTickMode GetTickDisplayMode() const { return m_tickDisplayMode; }
  66. void SetTickDisplayMode(EUiAVTickMode mode);
  67. void SetEditLock(bool bLock) { m_bEditLock = bLock; }
  68. // IUiAnimationContextListener
  69. void OnTimeChanged(float newTime) override;
  70. float TickSnap(float time) const;
  71. protected:
  72. void showEvent(QShowEvent* event) override;
  73. void resizeEvent(QResizeEvent* event) override;
  74. void wheelEvent(QWheelEvent* event) override;
  75. void mousePressEvent(QMouseEvent* event) override;
  76. void mouseReleaseEvent(QMouseEvent* event) override;
  77. void mouseDoubleClickEvent(QMouseEvent* event) override;
  78. private:
  79. void OnHScroll();
  80. void OnLButtonDown(Qt::KeyboardModifiers modifiers, const QPoint& point);
  81. void OnLButtonDblClk(Qt::KeyboardModifiers modifiers, const QPoint& point);
  82. void OnRButtonDown(Qt::KeyboardModifiers modifiers, const QPoint& point);
  83. void OnLButtonUp(Qt::KeyboardModifiers modifiers, const QPoint& point);
  84. void OnMButtonDown(Qt::KeyboardModifiers modifiers, const QPoint& point);
  85. void OnMButtonUp(Qt::KeyboardModifiers modifiers, const QPoint& point);
  86. void mouseMoveEvent(QMouseEvent* event) override;
  87. void paintEvent(QPaintEvent* event) override;
  88. void keyPressEvent(QKeyEvent* event) override;
  89. void OnRButtonUp(Qt::KeyboardModifiers modifiers, const QPoint& point);
  90. void OnCaptureChanged();
  91. private:
  92. void AddKeys(const QPoint& point, const bool bTryAddKeysInGroup);
  93. XmlNodeRef GetKeysInClickboard();
  94. void StartPasteKeys();
  95. CUiAnimViewKeyHandle FirstKeyFromPoint(const QPoint& point);
  96. CUiAnimViewKeyHandle DurationKeyFromPoint(const QPoint& point);
  97. CUiAnimViewKeyHandle CheckCursorOnStartEndTimeAdjustBar(const QPoint& point, bool& bStart);
  98. void SelectKeys(const QRect& rc, const bool bMultiSelection);
  99. int NumKeysFromPoint(const QPoint& point);
  100. //! Select all keys within time frame defined by this client rectangle.
  101. void SelectAllKeysWithinTimeFrame(const QRect& rc, const bool bMultiSelection);
  102. //! Return time snapped to time step,
  103. double GetTickTime() const;
  104. float MagnetSnap(float time, const CUiAnimViewAnimNode* pNode) const;
  105. float FrameSnap(float time) const;
  106. //! Return move time offset snapped with current snap settings
  107. float ComputeSnappedMoveOffset();
  108. //! Returns visible time range.
  109. Range GetVisibleRange() const;
  110. Range GetTimeRange(const QRect& rc) const;
  111. void SetHorizontalExtent(int min, int max);
  112. void SetCurrTime(float time);
  113. //! Return client position for given time.
  114. int TimeToClient(float time) const;
  115. float TimeFromPoint(const QPoint& point) const;
  116. float TimeFromPointUnsnapped(const QPoint& point) const;
  117. void SetLeftOffset(int ofs) { m_leftOffset = ofs; };
  118. void SetMouseCursor(const QCursor& cursor);
  119. void ShowKeyTooltip(const CUiAnimViewKeyHandle& keyHandle, const QPoint& point);
  120. bool IsOkToAddKeyHere(const CUiAnimViewTrack* pTrack, float time) const;
  121. void MouseMoveSelect(const QPoint& point);
  122. void MouseMoveMove(const QPoint& point, Qt::KeyboardModifiers modifiers);
  123. void MouseMoveDragTime(const QPoint& point, Qt::KeyboardModifiers modifiers);
  124. void MouseMoveOver(const QPoint& point);
  125. void MouseMoveDragEndMarker(const QPoint& point, Qt::KeyboardModifiers modifiers);
  126. float SnapTime(Qt::KeyboardModifiers modifiers, const QPoint& p);
  127. void MouseMoveDragStartMarker(const QPoint& point, Qt::KeyboardModifiers modifiers);
  128. void MouseMoveStartEndTimeAdjust(const QPoint& point, bool bStart);
  129. CUiAnimViewNode* GetNodeFromPointRec(CUiAnimViewNode* pCurrentNode, const QPoint& point);
  130. CUiAnimViewNode* GetNodeFromPoint(const QPoint& point);
  131. CUiAnimViewAnimNode* GetAnimNodeFromPoint(const QPoint& point);
  132. CUiAnimViewTrack* GetTrackFromPoint(const QPoint& point);
  133. void LButtonDownOnTimeAdjustBar(const QPoint& point, CUiAnimViewKeyHandle& keyHandle, bool bStart);
  134. void LButtonDownOnKey(const QPoint& point, CUiAnimViewKeyHandle& keyHandle, Qt::KeyboardModifiers modifiers);
  135. bool CreateColorKey(CUiAnimViewTrack* pTrack, float keyTime);
  136. void RecordTrackUndo(CUiAnimViewTrack* pTrack);
  137. void AcceptUndo();
  138. // Returns the snapping mode modified active keys
  139. ESnappingMode GetKeyModifiedSnappingMode();
  140. QRect GetNodeRect(const CUiAnimViewNode* pNode) const;
  141. void StoreMementoForTracksWithSelectedKeys();
  142. // Drawing methods.
  143. void DrawControl(QPainter* pDC, const QRect& rcUpdate);
  144. void DrawNodesRecursive(CUiAnimViewNode* pNode, QPainter* pDC, const QRect& rcUpdate);
  145. void DrawTimeline(QPainter* pDC, const QRect& rcUpdate);
  146. void DrawSummary(QPainter* pDC, const QRect& rcUpdate);
  147. void DrawSelectedKeyIndicators(QPainter* pDC);
  148. void DrawTicks(QPainter* pDC, const QRect& rc, Range& timeRange);
  149. void DrawNodeTrack(CUiAnimViewAnimNode* pAnimNode, QPainter* pDC, const QRect& trackRect);
  150. void DrawTrack(CUiAnimViewTrack* pTrack, QPainter* pDC, const QRect& trackRect);
  151. void DrawKeys(CUiAnimViewTrack* pTrack, QPainter* pDC, QRect& rc, Range& timeRange);
  152. void DrawBoolTrack(const Range& timeRange, QPainter* pDC, CUiAnimViewTrack* pTrack, const QRect& rc);
  153. void DrawSelectTrack(const Range& timeRange, QPainter* pDC, CUiAnimViewTrack* pTrack, const QRect& rc);
  154. void DrawKeyDuration(CUiAnimViewTrack* pTrack, QPainter* pDC, const QRect& rc, int keyIndex);
  155. void DrawGoToTrackArrow(CUiAnimViewTrack* pTrack, QPainter* pDC, const QRect& rc);
  156. void DrawColorGradient(QPainter* pDC, const QRect& rc, const CUiAnimViewTrack* pTrack);
  157. void DrawClipboardKeys(QPainter* pDC, const QRect& rc);
  158. void DrawTrackClipboardKeys(QPainter* pDC, CUiAnimViewTrack* pTrack, XmlNodeRef trackNode, const float timeOffset);
  159. CUiAnimViewNodesCtrl* m_pNodesCtrl;
  160. void ComputeFrameSteps(const Range& VisRange);
  161. void DrawTimeLineInFrames(QPainter* dc, const QRect& rc, const QColor& lineCol, const QColor& textCol, double step);
  162. void DrawTimeLineInSeconds(QPainter* dc, const QRect& rc, const QColor& lineCol, const QColor& textCol, double step);
  163. QBrush m_bkgrBrush;
  164. QBrush m_bkgrBrushEmpty;
  165. QBrush m_selectedBrush;
  166. QBrush m_timeBkgBrush;
  167. QBrush m_timeHighlightBrush;
  168. QBrush m_visibilityBrush;
  169. QBrush m_selectTrackBrush;
  170. QCursor m_currCursor;
  171. QCursor m_crsLeftRight;
  172. QCursor m_crsAddKey;
  173. QCursor m_crsCross;
  174. QCursor m_crsAdjustLR;
  175. QRect m_rcClient;
  176. QPoint m_scrollOffset;
  177. QRect m_rcSelect;
  178. QRect m_rcTimeline;
  179. QRect m_rcSummary;
  180. QPoint m_lastTooltipPos;
  181. QPoint m_mouseDownPos;
  182. QPoint m_mouseOverPos;
  183. QPixmap m_offscreenBitmap;
  184. QRubberBand* m_rubberBand;
  185. QScrollBar* m_scrollBar;
  186. // Time
  187. float m_timeScale;
  188. float m_currentTime;
  189. float m_storedTime;
  190. Range m_timeRange;
  191. Range m_timeMarked;
  192. // This is how often to place ticks.
  193. // value of 10 means place ticks every 10 second.
  194. double m_ticksStep;
  195. CUiAnimViewKeyPropertiesDlg* m_keyPropertiesDlg;
  196. #if UI_ANIMATION_REMOVED // UI_ANIMATION_REVISIT - not sure what PropsOnSpot is for
  197. ReflectedPropertyControl m_wndPropsOnSpot;
  198. #endif
  199. const CUiAnimViewTrack* m_pLastTrackSelectedOnSpot;
  200. QFont m_descriptionFont;
  201. // Mouse interaction state
  202. int m_mouseMode;
  203. int m_mouseActionMode;
  204. bool m_bZoomDrag;
  205. bool m_bMoveDrag;
  206. bool m_bCursorWasInKey;
  207. bool m_bJustSelected;
  208. bool m_bMouseMovedAfterRButtonDown;
  209. bool m_bKeysMoved;
  210. // Offset for keys while moving/pasting
  211. float m_keyTimeOffset;
  212. // If control is locked for editing
  213. bool m_bEditLock;
  214. // Fast redraw: Only redraw time slider. Everything else is buffered.
  215. bool m_bFastRedraw;
  216. // Scrolling
  217. int m_leftOffset;
  218. int m_scrollMin;
  219. int m_scrollMax;
  220. // Snapping
  221. ESnappingMode m_snappingMode;
  222. float m_snapFrameTime;
  223. // Ticks in frames or seconds
  224. EUiAVTickMode m_tickDisplayMode;
  225. double m_fFrameTickStep;
  226. double m_fFrameLabelStep;
  227. // Key for time adjust
  228. CUiAnimViewKeyHandle m_keyForTimeAdjust;
  229. // Cached clipboard XML for eUiAVMouseMode_Paste
  230. XmlNodeRef m_clipboardKeys;
  231. // Mementos of unchanged tracks for Move/Scale/Slide etc.
  232. struct TrackMemento
  233. {
  234. CUiAnimViewTrackMemento m_memento;
  235. // Also need to store key selection states,
  236. // because RestoreMemento will destroy them
  237. std::vector<bool> m_keySelectionStates;
  238. };
  239. std::unordered_map<CUiAnimViewTrack*, TrackMemento> m_trackMementos;
  240. #ifdef DEBUG
  241. unsigned int m_redrawCount;
  242. #endif
  243. };