NAP
sequencecurvetrackview.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
7 #include <utility>
8 
9 #include "sequencetrackview.h"
10 #include "sequencetracksegmentcurve.h"
11 #include "sequencecontrollercurve.h"
12 #include "sequenceguiservice.h"
13 
14 namespace nap
15 {
17 
21  class NAPAPI SequenceCurveTrackView final : public SequenceTrackView
22  {
23  RTTI_ENABLE(SequenceTrackView)
24  public:
32 
33  // make this class explicitly non-copyable
35  SequenceCurveTrackView& operator=(const SequenceCurveTrackView&) = delete;
36 
40  void handleActions() override;
41 
42  protected:
55  template<typename T>
56  void drawSegmentContent(const SequenceTrack& track, const SequenceTrackSegment& segment, const ImVec2& trackTopLeft, float previousSegmentX, float segmentWidth, float segmentX, ImDrawList* drawList, bool drawStartValue);
57 
69  template<typename T>
70  void drawSegmentValue(const SequenceTrack& track, const SequenceTrackSegment& segment, const ImVec2& trackTopLeft, float segmentX, float segmentWidth, sequencecurveenums::ESegmentValueTypes segmentType, ImDrawList* drawList);
71 
81  void drawSegmentHandler(const SequenceTrack& track, const SequenceTrackSegment& segment, const ImVec2& trackTopLeft, float segmentX, float segmentWidth, ImDrawList* drawList);
82 
92  template<typename T>
93  void drawControlPoints(const SequenceTrack& track, const SequenceTrackSegment& segment, const ImVec2& trackTopLeft, float segmentX, float segmentWidth, ImDrawList* drawList);
94 
106  template<typename T>
107  void drawCurves(const SequenceTrack& track, const SequenceTrackSegment& segment, const ImVec2& trackTopLeft, float previousSegmentX, float segmentWidth, float segmentX, ImDrawList* drawList);
108 
123  template<typename T>
124  void drawTanHandler(const SequenceTrack& track,
125  const SequenceTrackSegment& segment,
126  std::ostringstream& stringStream,
127  float segmentWidth,
128  const math::FCurvePoint<float, float>& curvePoint,
129  const ImVec2& circlePoint, int controlPointIndex,
130  int curveIndex,
132  ImDrawList* drawList);
133 
137  void handleInsertSegmentPopup();
138 
142  void handleEditSegmentPopup();
143 
147  void handleInsertCurvePointPopup();
148 
152  template<typename T>
153  void handleCurvePointActionPopup();
154 
158  template<typename T>
159  void handleSegmentValueActionPopup();
160 
164  template<typename T>
165  void handleChangeMinMaxCurve();
166 
170  void handleDragTanPoint();
171 
175  void handleAssignOutputIDToTrack();
176 
180  void handleDragSegmentHandler();
181 
185  void handleCurveTypePopup();
186 
190  void handleTanPointActionPopup();
191 
195  void handleDraggingSegmentValue();
196 
200  void handleDraggingControlPoints();
201 
205  void handleLoadPresetPopup();
206 
212  template<typename T>
213  void drawInspectorRange(const SequenceTrack& track);
214 
223  template<typename T>
224  void showValue(const SequenceTrack& track, const SequenceTrackSegmentCurve<T>& segment, float x, double time, int curveIndex);
225 
232  template<typename T>
233  bool inputFloat(T&, int precision);
234 
239  void showInspectorContent(const SequenceTrack& track) override;
240 
246  void showTrackContent(const SequenceTrack& track, const ImVec2& trackTopLeft) override;
247 
255  template<typename T>
256  bool pasteClipboardSegments(const std::string& trackId, double time, utility::ErrorState& errorState);
257 
263  template<typename T>
264  void pasteClipboardSegmentInto(const std::string& trackID, const std::string& segmentID);
265 
271  void updateSegmentInClipboard(const std::string& trackID, const std::string& segmentID);
272 
277  void updateSegmentsInClipboard(const std::string& trackID);
278 
279  // curve cache holds evaluated curves, needs to be cleared when view changes and curves need to be redrawn
280  std::unordered_map<std::string, std::vector<std::vector<ImVec2>>> mCurveCache;
281 
282  // short curt to member function drawSegmentContent
283  using DrawSegmentMemFunPtr = void (SequenceCurveTrackView::*)(const SequenceTrack &track, const SequenceTrackSegment &segment, const ImVec2 &trackTopLeft, float previousSegmentX, float segmentWidth, float segmentX, ImDrawList *drawList, bool drawStartValue);
284 
285  // static map of member function pointers
286  static std::unordered_map<rttr::type, DrawSegmentMemFunPtr> &getDrawCurveSegmentsMap();
287  };
288 
290  // Curve Clipboards
292 
293  namespace sequenceguiclipboard
294  {
298  class NAPAPI CurveSegmentClipboard final : public Clipboard
299  {
300  RTTI_ENABLE(Clipboard)
301  public:
308  CurveSegmentClipboard(const rttr::type &segmentType, std::string trackID, std::string sequenceName)
309  : Clipboard(segmentType), mTrackID(std::move(trackID)), mSequenceName(std::move(sequenceName))
310  {}
311 
312 
317  void changeTrackID(const std::string &newTrackID);
318 
319 
324  const std::string& getTrackID() const{ return mTrackID; }
325 
326 
331  const std::string& getSequenceName() const { return mSequenceName; }
332 
333 
334  private:
335  std::string mTrackID;
336  std::string mSequenceName;
337  };
338  }
339 
340 
342  // Forward declarations
344 
345  template<>
346  void SequenceCurveTrackView::handleCurvePointActionPopup<float>();
347 
348  template<>
349  void SequenceCurveTrackView::handleSegmentValueActionPopup<float>();
350 
351  template<>
352  void SequenceCurveTrackView::showValue<float>(const SequenceTrack& track,
353  const SequenceTrackSegmentCurve<float>& segment, float x, double time,
354  int curveIndex);
355 
356  template<>
357  void SequenceCurveTrackView::showValue<glm::vec2>(const SequenceTrack& track, const SequenceTrackSegmentCurve<glm::vec2>& segment, float x, double time, int curveIndex);
358 
359  template<>
360  void SequenceCurveTrackView::showValue<glm::vec3>(const SequenceTrack& track, const SequenceTrackSegmentCurve<glm::vec3>& segment, float x, double time, int curveIndex);
361 
362  template<>
363  void SequenceCurveTrackView::showValue<glm::vec4>(const SequenceTrack& track, const SequenceTrackSegmentCurve<glm::vec4>& segment, float x, double time, int curveIndex);
364 
365  template<>
366  bool SequenceCurveTrackView::inputFloat<float>(float& v, int precision);
367 
368  template<>
369  bool SequenceCurveTrackView::inputFloat<glm::vec2>(glm::vec2& v, int precision);
370 
371  template<>
372  bool SequenceCurveTrackView::inputFloat<glm::vec3>(glm::vec3& v, int precision);
373 
374  template<>
375  bool SequenceCurveTrackView::inputFloat<glm::vec4>(glm::vec4& v, int precision);
376 }
377 
378 // Include all template definitions
379 #include "sequencecurvetrackview_template.h"
380 
381 
nap::sequencecurveenums::ETanPointTypes
ETanPointTypes
Definition: sequencecurveenums.h:13
nap::SequenceEditorGUIState
Definition: sequenceeditorguistate.h:23
nap::sequenceguiclipboard::CurveSegmentClipboard::getSequenceName
const std::string & getSequenceName() const
Definition: sequencecurvetrackview.h:331
nap::SequenceTrackSegmentCurve
Definition: sequencetracksegmentcurve.h:19
nap::sequencecurveenums::ESegmentValueTypes
ESegmentValueTypes
Definition: sequencecurveenums.h:18
nap::utility::ErrorState
Definition: errorstate.h:19
nap::SequenceTrackSegment
Definition: sequencetracksegment.h:19
nap::SequenceCurveTrackView
Definition: sequencecurvetrackview.h:21
nap::SequenceCurveTrackView::mCurveCache
std::unordered_map< std::string, std::vector< std::vector< ImVec2 > > > mCurveCache
Definition: sequencecurvetrackview.h:280
nap::SequenceCurveTrackView::DrawSegmentMemFunPtr
void(SequenceCurveTrackView::*)(const SequenceTrack &track, const SequenceTrackSegment &segment, const ImVec2 &trackTopLeft, float previousSegmentX, float segmentWidth, float segmentX, ImDrawList *drawList, bool drawStartValue) DrawSegmentMemFunPtr
Definition: sequencecurvetrackview.h:283
nap::SequenceGUIService
Definition: sequenceguiservice.h:59
nap::SequenceTrack
Definition: sequencetrack.h:22
nap::sequenceguiclipboard::Clipboard
Definition: sequenceeditorguiclipboard.h:28
nap::SequenceTrackView
Definition: sequencetrackview.h:30
nap::SequenceEditorGUIView
Definition: sequenceeditorgui.h:82
nap::sequenceguiclipboard::CurveSegmentClipboard
Definition: sequencecurvetrackview.h:298
nap
Definition: templateapp.h:17
nap::sequenceguiclipboard::CurveSegmentClipboard::CurveSegmentClipboard
CurveSegmentClipboard(const rttr::type &segmentType, std::string trackID, std::string sequenceName)
Definition: sequencecurvetrackview.h:308
nap::sequenceguiclipboard::CurveSegmentClipboard::getTrackID
const std::string & getTrackID() const
Definition: sequencecurvetrackview.h:324
nap::math::FCurvePoint
Definition: fcurve.h:75