HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UN_StickyNote.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: UN_StickyNote.h ( UN Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __UN_StickyNote_h__
13 #define __UN_StickyNote_h__
14 
15 #include "UN_API.h"
16 #include "UN_Handle.h"
17 #include "UN_Port.h"
18 #include "UN_StickyNoteUtils.h"
19 
20 class UN_ConstGraph;
21 class UN_Graph;
22 
23 
24 // ============================================================================
25 /// Base class template for the UN sticky note handle.
26 /// Its main purpose is to factor common code for const and non-const handles.
27 template <typename BASE_CLASS, // class to derive from
28  typename GRAPH_DATA> // UN_GraphData or const UN_GraphData
29 class UN_StickyNoteBase : public BASE_CLASS
30 {
31 protected:
32  /// Constructs a handle for an invalid sticky note.
33  UN_StickyNoteBase() = default;
34 
35  /// Constructs a handle that references the given sticky note in the given graph.
36  UN_StickyNoteBase( GRAPH_DATA *graph_data, UN_StickyNoteID note_id )
37  : BASE_CLASS( graph_data, note_id )
38  {}
39 
40 public:
41  /// @{ Returns the owner of the underlying graph data structures.
42  GRAPH_DATA * graphData() const
43  { return BASE_CLASS::graphData(); }
45  { return BASE_CLASS::constGraphData(); }
46  /// @}
47 
48  /// Returns the unique ID of the sticky note this handle refers to.
49  UN_StickyNoteID stickyNoteID() const
50  { return UN_StickyNoteID( BASE_CLASS::dataID() ); }
51 
52  /// @{ Returns true if this note is valid within the graph; false otherwise.
53  bool isValid() const
54  { return UN_StickyNoteUtils::isValid(
55  graphData(), stickyNoteID());
56  }
57 
58  explicit operator bool() const
59  { return isValid(); }
60  /// @}
61 
62  /// Returns the sticky note name that differentiates it among its siblings.
63  const UT_StringHolder & name() const
64  {
65  return UN_StickyNoteUtils::name( graphData(), stickyNoteID() );
66  }
67 
68  /// Returns the sticky note's contents.
69  const UT_StringHolder & text() const
70  {
71  return UN_StickyNoteUtils::text( graphData(), stickyNoteID() );
72  }
73 
74  /// Returns the sticky note's position in the graph editor.
75  const UT_Vector2D & position() const
76  {
77  return UN_StickyNoteUtils::position( graphData(), stickyNoteID() );
78  }
79 
80  /// Returns the sticky note's dimensions (width & height).
81  const UT_Vector2D & dimensions() const
82  {
83  return UN_StickyNoteUtils::dimensions( graphData(), stickyNoteID() );
84  }
85 
86  /// Returns the sticky note's (background) color.
87  const UT_Color & color() const
88  {
89  return UN_StickyNoteUtils::color( graphData(), stickyNoteID() );
90  }
91 
92  /// Returns the sticky note's text (foreground) color.
93  const UT_Color & textColor() const
94  {
95  return UN_StickyNoteUtils::textColor( graphData(), stickyNoteID() );
96  }
97 
98  /// Returns the sticky note's text size.
99  float textSize() const
100  {
101  return UN_StickyNoteUtils::textSize( graphData(), stickyNoteID() );
102  }
103 
104  /// Returns true if the sticky note is collapsed (minimized).
105  bool isCollapsed() const
106  {
107  return UN_StickyNoteUtils::isCollapsed( graphData(), stickyNoteID() );
108  }
109 
110  /// Returns true if the background of the sticky note is not drawn,
111  /// effectively making it transparent.
112  bool isBackgroundHidden() const
113  {
114  return UN_StickyNoteUtils::isBackgroundHidden( graphData(),
115  stickyNoteID() );
116  }
117 };
118 
119 // ============================================================================
120 /// A handle that references a mutable sitkcy note in a graph.
121 /// It abstracts the APIs that operate on this sitkcy note's data stored inside
122 /// graph's data containers.
123 /// It is a non-const (read-write) handle, so allows both queries
124 /// and mutations of the sitkcy note's data.
125 class UN_API UN_StickyNote : public UN_StickyNoteBase< UN_Handle, UN_GraphData >
126 {
127 public:
128  /// Constructs a handle for an invalid sitkcy note.
129  UN_StickyNote() = default;
130 
131  /// Constructs a handle referencing the given note in the given graph.
132  UN_StickyNote( UN_GraphData *graph_data, UN_StickyNoteID note_id )
133  : UN_StickyNoteBase( graph_data, note_id )
134  {}
135 
136  /// @{ Comparison operators.
137  // Allows comparing sticky note handles, but guards against
138  // comparing sticky note to ports, for example.
139  bool operator==( const UN_StickyNote &other ) const
140  { return UN_ConstHandle::operator==( other ); }
141  bool operator!=( const UN_StickyNote &other ) const
142  { return UN_ConstHandle::operator!=( other ); }
143  /// @}
144 
145  /// Returns the graph whithin which this sticky note exists.
146  UN_Graph graph() const;
147 
148  /// Sets the sticky note name that differentiates it among its siblings.
149  void setName( const UT_StringRef &name ) const
150  {
151  UN_StickyNoteUtils::setName( graphData(), stickyNoteID(), name );
152  }
153 
154  /// Sets the sticky note's type that determines its functional behavour.
155  void setText( const UT_StringRef &type_name ) const
156  {
157  UN_StickyNoteUtils::setText( graphData(), stickyNoteID(), type_name );
158  }
159 
160  /// Sets the sticky note's location in the graph editor.
161  void setPosition( const UT_Vector2R &position ) const
162  {
163  UN_StickyNoteUtils::setPosition( graphData(), stickyNoteID(),
164  position );
165  }
166 
167  /// Sets the sticky note's width and height.
168  void setDimensions( const UT_Vector2R &dimensions ) const
169  {
170  UN_StickyNoteUtils::setDimensions( graphData(), stickyNoteID(),
171  dimensions );
172  }
173 
174  /// Sets the sticky note's (background) color.
175  void setColor( const UT_Color &color ) const
176  {
177  UN_StickyNoteUtils::setColor( graphData(), stickyNoteID(), color );
178  }
179 
180  /// Sets the sticky note's text (foreground) color.
181  void setTextColor( const UT_Color &color ) const
182  {
183  UN_StickyNoteUtils::setTextColor( graphData(), stickyNoteID(), color );
184  }
185 
186  /// Sets the sticky note's text size.
187  void setTextSize( float text_size ) const
188  {
189  UN_StickyNoteUtils::setTextSize( graphData(), stickyNoteID(),
190  text_size );
191  }
192 
193  /// Sets the sticky note's collapsed (minimized) state.
194  void setCollapsed( bool is_collapsed ) const
195  {
196  UN_StickyNoteUtils::setCollapsed( graphData(), stickyNoteID(),
197  is_collapsed );
198  }
199 
200  /// Sets the flag on the sticky note to avoid drawing its background,
201  /// effectively making it transparent.
202  void setBackgroundHidden( bool is_hidden ) const
203  {
204  UN_StickyNoteUtils::setBackgroundHidden( graphData(), stickyNoteID(),
205  is_hidden );
206  }
207 };
208 
209 
210 // ============================================================================
211 /// A handle that references a const sticky note in a graph.
212 /// It abstracts the APIs that operate on this sticky note's data stored inside
213 /// graph's data containers.
214 /// It is a constant handle, so allows only queries of the sticky note's data,
215 /// and does not allow setting any new values for.
216 class UN_API UN_ConstStickyNote : public UN_StickyNoteBase< UN_ConstHandle,
217  const UN_GraphData >
218 {
219 public:
220  /// Constructs a handle for an invalid sticky note.
221  UN_ConstStickyNote() = default;
222 
223  /// Constructs a handle referencing the given sticky note in the given graph.
224  UN_ConstStickyNote( const UN_GraphData *graph_data, UN_StickyNoteID note_id )
225  : UN_StickyNoteBase( graph_data, note_id )
226  {}
227 
228  /// Constructs a const handle from a mutable sticky note handle.
230  : UN_ConstStickyNote( note.constGraphData(), note.stickyNoteID() )
231  {}
232 
233  /// @{ Comparison operators.
234  // Allows comparing sticky note handles, but guards against
235  // comparing notes to notes, for example.
236  bool operator==( const UN_ConstStickyNote &other ) const
237  { return UN_ConstHandle::operator==( other ); }
238  bool operator!=( const UN_ConstStickyNote &other ) const
239  { return UN_ConstHandle::operator!=( other ); }
240  /// @}
241 
242 
243  /// Returns the graph whithin which this sticky note exists.
244  UN_ConstGraph graph() const;
245 };
246 
247 // ============================================================================
248 // Free functions to compare a non-const sticky note handle to a const sticky
249 // note handle.
250 // Note, the const to non-const comparison is covered by implicit conversion
251 // of non-const handle to const handle, and using const to const handle comp.
252 static inline bool
254 {
255  return b == UN_ConstStickyNote(a);
256 }
257 
258 static inline bool
260 {
261  return !(b == a);
262 }
263 
264 // ============================================================================
265 #endif
266 
const UT_StringHolder & text() const
Returns the sticky note's contents.
Definition: UN_StickyNote.h:69
void setText(const UT_StringRef &type_name) const
Sets the sticky note's type that determines its functional behavour.
UN_ConstStickyNote(const UN_GraphData *graph_data, UN_StickyNoteID note_id)
Constructs a handle referencing the given sticky note in the given graph.
GRAPH_DATA * graphData() const
Returns the owner of the underlying graph data structures.
Definition: UN_StickyNote.h:42
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
void setBackgroundHidden(bool is_hidden) const
#define UN_API
Definition: UN_API.h:11
UN_StickyNoteBase(GRAPH_DATA *graph_data, UN_StickyNoteID note_id)
Constructs a handle that references the given sticky note in the given graph.
Definition: UN_StickyNote.h:36
const UT_Color & textColor() const
Returns the sticky note's text (foreground) color.
Definition: UN_StickyNote.h:93
OutGridT const XformOp bool bool
void setCollapsed(bool is_collapsed) const
Sets the sticky note's collapsed (minimized) state.
UN_ConstStickyNote(const UN_StickyNote &note)
Constructs a const handle from a mutable sticky note handle.
const UT_Vector2D & dimensions() const
Returns the sticky note's dimensions (width & height).
Definition: UN_StickyNote.h:81
void setTextSize(float text_size) const
Sets the sticky note's text size.
void setName(const UT_StringRef &name) const
Sets the sticky note name that differentiates it among its siblings.
ROI OIIO_API text_size(string_view text, int fontsize=16, string_view fontname="")
constexpr std::enable_if< I< type_count_base< T >::value, int >::type tuple_type_size(){return subtype_count< typename std::tuple_element< I, T >::type >::value+tuple_type_size< T, I+1 >);}template< typename T > struct type_count< T, typename std::enable_if< is_tuple_like< T >::value >::type >{static constexpr int value{tuple_type_size< T, 0 >)};};template< typename T > struct subtype_count{static constexpr int value{is_mutable_container< T >::value?expected_max_vector_size:type_count< T >::value};};template< typename T, typename Enable=void > struct type_count_min{static const int value{0};};template< typename T >struct type_count_min< T, typename std::enable_if<!is_mutable_container< T >::value &&!is_tuple_like< T >::value &&!is_wrapper< T >::value &&!is_complex< T >::value &&!std::is_void< T >::value >::type >{static constexpr int value{type_count< T >::value};};template< typename T > struct type_count_min< T, typename std::enable_if< is_complex< T >::value >::type >{static constexpr int value{1};};template< typename T >struct type_count_min< T, typename std::enable_if< is_wrapper< T >::value &&!is_complex< T >::value &&!is_tuple_like< T >::value >::type >{static constexpr int value{subtype_count_min< typename T::value_type >::value};};template< typename T, std::size_t I >constexpr typename std::enable_if< I==type_count_base< T >::value, int >::type tuple_type_size_min(){return 0;}template< typename T, std::size_t I > constexpr typename std::enable_if< I< type_count_base< T >::value, int >::type tuple_type_size_min(){return subtype_count_min< typename std::tuple_element< I, T >::type >::value+tuple_type_size_min< T, I+1 >);}template< typename T > struct type_count_min< T, typename std::enable_if< is_tuple_like< T >::value >::type >{static constexpr int value{tuple_type_size_min< T, 0 >)};};template< typename T > struct subtype_count_min{static constexpr int value{is_mutable_container< T >::value?((type_count< T >::value< expected_max_vector_size)?type_count< T >::value:0):type_count_min< T >::value};};template< typename T, typename Enable=void > struct expected_count{static const int value{0};};template< typename T >struct expected_count< T, typename std::enable_if<!is_mutable_container< T >::value &&!is_wrapper< T >::value &&!std::is_void< T >::value >::type >{static constexpr int value{1};};template< typename T > struct expected_count< T, typename std::enable_if< is_mutable_container< T >::value >::type >{static constexpr int value{expected_max_vector_size};};template< typename T >struct expected_count< T, typename std::enable_if<!is_mutable_container< T >::value &&is_wrapper< T >::value >::type >{static constexpr int value{expected_count< typename T::value_type >::value};};enum class object_category:int{char_value=1, integral_value=2, unsigned_integral=4, enumeration=6, boolean_value=8, floating_point=10, number_constructible=12, double_constructible=14, integer_constructible=16, string_assignable=23, string_constructible=24, other=45, wrapper_value=50, complex_number=60, tuple_value=70, container_value=80,};template< typename T, typename Enable=void > struct classify_object{static constexpr object_category value{object_category::other};};template< typename T >struct classify_object< T, typename std::enable_if< std::is_integral< T >::value &&!std::is_same< T, char >::value &&std::is_signed< T >::value &&!is_bool< T >::value &&!std::is_enum< T >::value >::type >{static constexpr object_category value{object_category::integral_value};};template< typename T >struct classify_object< T, typename std::enable_if< std::is_integral< T >::value &&std::is_unsigned< T >::value &&!std::is_same< T, char >::value &&!is_bool< T >::value >::type >{static constexpr object_category value{object_category::unsigned_integral};};template< typename T >struct classify_object< T, typename std::enable_if< std::is_same< T, char >::value &&!std::is_enum< T >::value >::type >{static constexpr object_category value{object_category::char_value};};template< typename T > struct classify_object< T, typename std::enable_if< is_bool< T >::value >::type >{static constexpr object_category value{object_category::boolean_value};};template< typename T > struct classify_object< T, typename std::enable_if< std::is_floating_point< T >::value >::type >{static constexpr object_category value{object_category::floating_point};};template< typename T >struct classify_object< T, typename std::enable_if<!std::is_floating_point< T >::value &&!std::is_integral< T >::value &&std::is_assignable< T &, std::string >::value >::type >{static constexpr object_category value{object_category::string_assignable};};template< typename T >struct classify_object< T, typename std::enable_if<!std::is_floating_point< T >::value &&!std::is_integral< T >::value &&!std::is_assignable< T &, std::string >::value &&(type_count< T >::value==1)&&std::is_constructible< T, std::string >::value >::type >{static constexpr object_category value{object_category::string_constructible};};template< typename T > struct classify_object< T, typename std::enable_if< std::is_enum< T >::value >::type >{static constexpr object_category value{object_category::enumeration};};template< typename T > struct classify_object< T, typename std::enable_if< is_complex< T >::value >::type >{static constexpr object_category value{object_category::complex_number};};template< typename T > struct uncommon_type{using type=typename std::conditional<!std::is_floating_point< T >::value &&!std::is_integral< T >::value &&!std::is_assignable< T &, std::string >::value &&!std::is_constructible< T, std::string >::value &&!is_complex< T >::value &&!is_mutable_container< T >::value &&!std::is_enum< T >::value, std::true_type, std::false_type >::type;static constexpr bool value=type::value;};template< typename T >struct classify_object< T, typename std::enable_if<(!is_mutable_container< T >::value &&is_wrapper< T >::value &&!is_tuple_like< T >::value &&uncommon_type< T >::value)>::type >{static constexpr object_category value{object_category::wrapper_value};};template< typename T >struct classify_object< T, typename std::enable_if< uncommon_type< T >::value &&type_count< T >::value==1 &&!is_wrapper< T >::value &&is_direct_constructible< T, double >::value &&is_direct_constructible< T, int >::value >::type >{static constexpr object_category value{object_category::number_constructible};};template< typename T >struct classify_object< T, typename std::enable_if< uncommon_type< T >::value &&type_count< T >::value==1 &&!is_wrapper< T >::value &&!is_direct_constructible< T, double >::value &&is_direct_constructible< T, int >::value >::type >{static constexpr object_category value{object_category::integer_constructible};};template< typename T >struct classify_object< T, typename std::enable_if< uncommon_type< T >::value &&type_count< T >::value==1 &&!is_wrapper< T >::value &&is_direct_constructible< T, double >::value &&!is_direct_constructible< T, int >::value >::type >{static constexpr object_category value{object_category::double_constructible};};template< typename T >struct classify_object< T, typename std::enable_if< is_tuple_like< T >::value &&((type_count< T >::value >=2 &&!is_wrapper< T >::value)||(uncommon_type< T >::value &&!is_direct_constructible< T, double >::value &&!is_direct_constructible< T, int >::value)||(uncommon_type< T >::value &&type_count< T >::value >=2))>::type >{static constexpr object_category value{object_category::tuple_value};};template< typename T > struct classify_object< T, typename std::enable_if< is_mutable_container< T >::value >::type >{static constexpr object_category value{object_category::container_value};};template< typename T, enable_if_t< classify_object< T >::value==object_category::char_value, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"CHAR";}template< typename T, enable_if_t< classify_object< T >::value==object_category::integral_value||classify_object< T >::value==object_category::integer_constructible, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"INT";}template< typename T, enable_if_t< classify_object< T >::value==object_category::unsigned_integral, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"UINT";}template< typename T, enable_if_t< classify_object< T >::value==object_category::floating_point||classify_object< T >::value==object_category::number_constructible||classify_object< T >::value==object_category::double_constructible, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"FLOAT";}template< typename T, enable_if_t< classify_object< T >::value==object_category::enumeration, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"ENUM";}template< typename T, enable_if_t< classify_object< T >::value==object_category::boolean_value, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"BOOLEAN";}template< typename T, enable_if_t< classify_object< T >::value==object_category::complex_number, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"COMPLEX";}template< typename T, enable_if_t< classify_object< T >::value >=object_category::string_assignable &&classify_object< T >::value<=object_category::other, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"TEXT";}template< typename T, enable_if_t< classify_object< T >::value==object_category::tuple_value &&type_count_base< T >::value >=2, detail::enabler >=detail::dummy >std::string type_name();template< typename T, enable_if_t< classify_object< T >::value==object_category::container_value||classify_object< T >::value==object_category::wrapper_value, detail::enabler >=detail::dummy >std::string type_name();template< typename T, enable_if_t< classify_object< T >::value==object_category::tuple_value &&type_count_base< T >::value==1, detail::enabler >=detail::dummy >inline std::string type_name(){return type_name< typename std::decay< typename std::tuple_element< 0, T >::type >::type >);}template< typename T, std::size_t I >inline typename std::enable_if< I==type_count_base< T >::value, std::string >::type tuple_name(){return std::string{};}template< typename T, std::size_t I >inline typename std::enable_if<(I< type_count_base< T >::value), std::string >::type tuple_name(){auto str=std::string{type_name< typename std::decay< typename std::tuple_element< I, T >::type >::type >)}+ ','+tuple_name< T, I+1 >);if(str.back()== ',') str.pop_back();return str;}template< typename T, enable_if_t< classify_object< T >::value==object_category::tuple_value &&type_count_base< T >::value >=2, detail::enabler > > std::string type_name()
Recursively generate the tuple type name.
Definition: CLI11.h:1729
bool operator!=(const UN_StickyNote &other) const
Comparison operators.
bool operator!=(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Inequality operator, does exact floating point comparisons.
Definition: Mat3.h:556
void setDimensions(const UT_Vector2R &dimensions) const
Sets the sticky note's width and height.
bool isCollapsed() const
Returns true if the sticky note is collapsed (minimized).
void setTextColor(const UT_Color &color) const
Sets the sticky note's text (foreground) color.
GLuint const GLchar * name
Definition: glcorearb.h:786
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
bool operator!=(const UN_ConstStickyNote &other) const
Comparison operators.
bool isBackgroundHidden() const
GLuint color
Definition: glcorearb.h:1261
const UN_GraphData * constGraphData() const
Returns the owner of the underlying graph data structures.
Definition: UN_StickyNote.h:44
const UT_StringHolder & name() const
Returns the sticky note name that differentiates it among its siblings.
Definition: UN_StickyNote.h:63
bool operator!=(const UN_ConstHandle &other) const
Definition: UN_Handle.h:68
bool operator==(const UN_ConstHandle &other) const
Definition: UN_Handle.h:59
SIM_API const UT_StringHolder position
UN_StickyNote(UN_GraphData *graph_data, UN_StickyNoteID note_id)
Constructs a handle referencing the given note in the given graph.
bool isValid() const
Returns true if this note is valid within the graph; false otherwise.
Definition: UN_StickyNote.h:53
const UT_Vector2D & position() const
Returns the sticky note's position in the graph editor.
Definition: UN_StickyNote.h:75
bool operator==(const UN_ConstStickyNote &other) const
Comparison operators.
UN_StickyNoteID stickyNoteID() const
Returns the unique ID of the sticky note this handle refers to.
Definition: UN_StickyNote.h:49
void setPosition(const UT_Vector2R &position) const
Sets the sticky note's location in the graph editor.
void setColor(const UT_Color &color) const
Sets the sticky note's (background) color.
const UT_Color & color() const
Returns the sticky note's (background) color.
Definition: UN_StickyNote.h:87
bool operator==(const UN_StickyNote &other) const
Comparison operators.
bool operator==(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Equality operator, does exact floating point comparisons.
Definition: Mat3.h:542
float textSize() const
Returns the sticky note's text size.
Definition: UN_StickyNote.h:99
UN_StickyNoteBase()=default
Constructs a handle for an invalid sticky note.