TimelineCtrl.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. #ifndef CRYINCLUDE_EDITOR_CONTROLS_TIMELINECTRL_H
  9. #define CRYINCLUDE_EDITOR_CONTROLS_TIMELINECTRL_H
  10. #pragma once
  11. #if !defined(Q_MOC_RUN)
  12. #include "Range.h"
  13. #include "SplineCtrlEx.h"
  14. #include "Controls/WndGridHelper.h"
  15. #include "Util/fastlib.h"
  16. #endif
  17. // Custom styles for this control.
  18. #define TL_STYLE_AUTO_DELETE 0x0001
  19. #define TL_STYLE_NO_TICKS 0x0002
  20. #define TL_STYLE_NO_TIME_MARKER 0x0004
  21. #define TL_STYLE_NO_TEXT 0x0008
  22. // Notify event sent when current time is change on the timeline control.
  23. #define TLN_START_CHANGE (0x0001)
  24. #define TLN_END_CHANGE (0x0002)
  25. #define TLN_CHANGE (0x0003)
  26. #define TLN_DELETE (0x0004)
  27. class AbstractTimelineWidget
  28. {
  29. public:
  30. virtual void setZoom(float zoom, float origin) = 0;
  31. virtual void update(const QRect& r = QRect()) = 0;
  32. virtual void setGeometry(const QRect& r) = 0;
  33. virtual void SetTimeMarker(float marker) = 0;
  34. };
  35. //////////////////////////////////////////////////////////////////////////
  36. // Timeline control.
  37. //////////////////////////////////////////////////////////////////////////
  38. class TimelineWidget
  39. : public QWidget
  40. , public AbstractTimelineWidget
  41. {
  42. Q_OBJECT
  43. public:
  44. TimelineWidget(QWidget* parent = nullptr);
  45. ~TimelineWidget();
  46. void setZoom(float zoom, float origin) override { SetZoom(zoom); SetOrigin(origin); update(); }
  47. void update(const QRect& r = QRect()) override { QWidget::update(r); }
  48. void setGeometry(const QRect& r) override { QWidget::setGeometry(r); }
  49. void SetTimeRange(const Range& r) { m_timeRange = r; }
  50. void SetTimeMarker(float fTime) override;
  51. float GetTimeMarker() const { return m_fTimeMarker; }
  52. void SetZoom(float fZoom);
  53. void SetOrigin(float fOffset);
  54. void SetKeyTimeSet(IKeyTimeSet* pKeyTimeSet);
  55. void SetTicksTextScale(float fScale) { m_fTicksTextScale = fScale; }
  56. float GetTicksTextScale() const { return m_fTicksTextScale; }
  57. void SetTrackingSnapToFrames(bool bEnable) { m_bTrackingSnapToFrames = bEnable; }
  58. enum MarkerStyle
  59. {
  60. MARKER_STYLE_SECONDS,
  61. MARKER_STYLE_FRAMES
  62. };
  63. void SetMarkerStyle(MarkerStyle markerStyle);
  64. void SetFPS(float fps); // Only referred to if MarkerStyle == MARKER_STYLE_FRAMES.
  65. float GetFPS() const
  66. {
  67. return m_fps;
  68. }
  69. void SetPlayCallback(const std::function<void()>& callback);
  70. Q_SIGNALS:
  71. void deleteRequested();
  72. void clicked();
  73. void startChange();
  74. void change();
  75. void endChange();
  76. protected:
  77. enum TrackingMode
  78. {
  79. TRACKING_MODE_NONE,
  80. TRACKING_MODE_SET_TIME,
  81. TRACKING_MODE_MOVE_KEYS,
  82. TRACKING_MODE_SELECTION_RANGE
  83. };
  84. int HitKeyTimes(const QPoint& point);
  85. void MoveSelectedKeyTimes(float scale, float offset);
  86. void SelectKeysInRange(float start, float end, bool select);
  87. void paintEvent(QPaintEvent* event) override;
  88. void resizeEvent(QResizeEvent* event) override;
  89. void mousePressEvent(QMouseEvent* event) override;
  90. void mouseReleaseEvent(QMouseEvent* event) override;
  91. void mouseMoveEvent(QMouseEvent* event) override;
  92. void OnLButtonDown(const QPoint& point, Qt::KeyboardModifiers modifiers);
  93. void OnLButtonUp(const QPoint& point, Qt::KeyboardModifiers modifiers);
  94. void OnRButtonDown(const QPoint& point, Qt::KeyboardModifiers modifiers);
  95. void OnRButtonUp(const QPoint& point, Qt::KeyboardModifiers modifiers);
  96. void keyPressEvent(QKeyEvent* event) override;
  97. // Drawing functions
  98. float ClientToTime(int x);
  99. int TimeToClient(float fTime);
  100. void DrawTicks(QPainter* painter);
  101. Range GetVisibleRange() const;
  102. void StartTracking(TrackingMode trackingMode);
  103. void StopTracking();
  104. QString TimeToString(float time);
  105. // Convert time in seconds into the milliseconds.
  106. int ToMillis(float time) { return RoundFloatToInt(time * 1000.0f); };
  107. float MillisToTime(int nMillis) { return nMillis / 1000.0f; }
  108. float SnapTime(float time);
  109. void DrawSecondTicks(QPainter* dc);
  110. void DrawFrameTicks(QPainter* dc);
  111. private:
  112. QRect m_rcClient;
  113. QRect m_rcTimeline;
  114. float m_fTimeMarker;
  115. float m_fTicksTextScale;
  116. TrackingMode m_trackingMode;
  117. QPoint m_lastPoint;
  118. Range m_timeRange;
  119. float m_timeScale;
  120. int m_scrollOffset;
  121. int m_leftOffset;
  122. // Tick every Nth millisecond.
  123. int m_nTicksStep;
  124. double m_ticksStep;
  125. CWndGridHelper m_grid;
  126. bool m_bIgnoreSetTime;
  127. IKeyTimeSet* m_pKeyTimeSet;
  128. bool m_bChangedKeyTimeSet;
  129. MarkerStyle m_markerStyle;
  130. float m_fps;
  131. bool m_copyKeyTimes;
  132. bool m_bTrackingSnapToFrames;
  133. std::function<void()> m_playCallback;
  134. };
  135. #endif // CRYINCLUDE_EDITOR_CONTROLS_TIMELINECTRL_H