HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CH_Tweener.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: CH_Tweener.h (C++)
7  *
8  * COMMENTS: Tool for tweening channels in various ways.
9  *
10  */
11 
12 #ifndef __CH_Tweener__
13 #define __CH_Tweener__
14 
15 #include "CH_API.h"
16 
17 #include "CH_Types.h"
18 
19 #include <UT/UT_Function.h>
20 #include <UT/UT_NonCopyable.h>
21 #include <UT/UT_StringHolder.h>
22 #include <UT/UT_SuperInterval.h>
23 #include <UT/UT_UniquePtr.h>
24 
25 class CH_Channel;
26 class CH_TweenTool;
27 
29 {
31  : myChannel(nullptr)
32  {}
33 
35  CH_Channel *channel,
37  : myChannel(channel), myRanges(ranges)
38  {
39  }
40 
43 
44  /// Can be set by the component providing current channel selections
45  /// to update its UI during the tween.
46  /// Parameters:
47  /// const UT_Array<UT_SuperIntervalR>& intervals -- selected intervals
48  /// bool first -- true if the tween is starting. The first UI update
49  /// bool last -- true if the tween is ending. This is the last UI update
52 };
53 
54 // Informs UT_Array that CH_ChannelSelections is not safe for trivial relocation
55 // due to the UT_Function
57 
59 {
60 public:
61  CH_Tweener();
62 
63  ~CH_Tweener();
64 
66 
67  // Add channel and selection ranges for that channel
68  // Used for the methods that tween sequences of existing keys
69  void setChannels(UT_Array<CH_ChannelSelections> &&channels);
70 
71  // Set channels only, used for the methods that blend a pose at the current
72  // time.
73  void setChannels(const CH_ChannelList &channels);
74 
75  // Clears the channel list, setting it to all scoped channels
76  void setChannelsFromScopedChannels();
77 
78  // Clear all channels and ranges
79  void clear();
80 
81  /// Perform a tween on all channels currently added to the Tweener
82  /// @param first Starts a new tween, creating a new undo block and caching
83  /// any relevant data for the given tween mode. For instance,
84  /// blending tween modes need to cache the current values of
85  /// the keys.
86  /// @param last Finishes a tween, closing undo blocks. This MUST be called
87  /// when finishing a tween
88  void tween(
90  fpreal val,
91  bool first = false,
92  bool last = false);
93 
94  int getNumModes() { return static_cast<int>(CH_TweenMode::Count); }
95 
96  /// Set the eval times used by the blend to frame mode.
97  void setLeftBlendTime(fpreal t) { myLeftBlendTime = t; };
98  void setRightBlendTime(fpreal t) { myRightBlendTime = t; };
100  {
101  setLeftBlendTime(left);
102  setRightBlendTime(right);
103  };
104 
106  {
107  left = myLeftBlendTime;
108  right = myRightBlendTime;
109  }
110 
111  /// Returns the name of the tween mode in a format suitable to display.
112  /// eg CH_TweenMode::BlendToNeighbor -> "Blend To Neighbor"
113  UT_StringHolder getModeName(CH_TweenMode mode) const;
114  UT_StringHolder getModeAbbreviation(CH_TweenMode mode) const;
115  /// Returns a simple, all lowercase token unique to each tween mode
116  /// Used by the playbar to generate unique UI_Value names for each tween
117  /// Mode.
118  UT_StringHolder getModeToken(CH_TweenMode mode) const;
119  /// Given the mode token, return the CH_TweenMode enum value.
120  /// If there is no such mode, returns CH_TweenMode::Count
121  CH_TweenMode getMode(const UT_StringHolder &token) const;
122 
123  bool getOvershootSupported(CH_TweenMode mode) const;
124  // Returns whether we need to save the entire channel for undo or
125  // if we just need to save the keys that already exist.
126  bool getRequiresFullChannelUndo(CH_TweenMode mode) const;
127  CH_TweenToolType getToolType(CH_TweenMode mode) const;
128 
129 private:
130  void startTween(CH_TweenMode mode);
131  void endTween();
132 
134 
135  // Eval Times to use when using the blend to frame mode
136  fpreal myLeftBlendTime;
137  fpreal myRightBlendTime;
138 
139  int myUndo;
140 
141  // The tween being currently evaluated. Set when starting a new tween
142  // based on the mode.
143  UT_UniquePtr<CH_TweenTool> myCurrentTween;
144 
145  int myUndoEventHandlerLevel;
146 };
147 
148 #endif
void getBlendTimes(fpreal &left, fpreal &right) const
Definition: CH_Tweener.h:105
GLint first
Definition: glcorearb.h:405
GLint left
Definition: glcorearb.h:2005
GLdouble right
Definition: glad.h:2817
void setRightBlendTime(fpreal t)
Definition: CH_Tweener.h:98
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
CH_Channel * myChannel
Definition: CH_Tweener.h:41
UT_Function< void(const UT_Array< UT_SuperIntervalR > &, bool, bool)> myUpdateUICallback
Definition: CH_Tweener.h:51
void setLeftBlendTime(fpreal t)
Set the eval times used by the blend to frame mode.
Definition: CH_Tweener.h:97
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
CH_ChannelSelections(CH_Channel *channel, UT_Array< UT_SuperIntervalR > &&ranges)
Definition: CH_Tweener.h:34
SYS_DECLARE_IS_NOT_TR(CH_ChannelSelections)
std::function< T > UT_Function
Definition: UT_Function.h:37
GLdouble t
Definition: glad.h:2397
GLenum mode
Definition: glcorearb.h:99
UT_Array< UT_SuperIntervalR > myRanges
Definition: CH_Tweener.h:42
__hostdev__ uint64_t last(uint32_t i) const
Definition: NanoVDB.h:5976
CH_TweenMode
Definition: CH_Types.h:152
void setBlendTimes(fpreal left, fpreal right)
Definition: CH_Tweener.h:99
fpreal64 fpreal
Definition: SYS_Types.h:277
#define CH_API
Definition: CH_API.h:10
GLuint GLfloat * val
Definition: glcorearb.h:1608
int getNumModes()
Definition: CH_Tweener.h:94
CH_TweenToolType
Definition: CH_Types.h:174
ImageBuf OIIO_API channels(const ImageBuf &src, int nchannels, cspan< int > channelorder, cspan< float > channelvalues={}, cspan< std::string > newchannelnames={}, bool shuffle_channel_names=false, int nthreads=0)