2 using System.Runtime.InteropServices;
3 using System.Collections.Generic;
8 /// Helper class for calculating what property indexes should be assigned to C# View (view) classes.
10 internal class PropertyRangeManager
12 private Dictionary<String, PropertyRange > _propertyRange;
15 /// Initializes a new instance of the <see cref="Dali.PropertyRangeManager"/> class.
17 public PropertyRangeManager ()
19 _propertyRange = new Dictionary<String, PropertyRange > ();
23 /// Only called if a View has scriptable properties
25 private PropertyRange RegisterView( string viewName, System.Type viewType )
29 if ( _propertyRange.TryGetValue (viewName, out range) )
35 // Find out the event and animatable start indexes for the type
36 range = new PropertyRange();
38 GetPropertyStartRange( viewType, ref range);
40 // add it to our dictionary
41 _propertyRange.Add( viewName, range );
48 /// Gets the index of the property.
49 /// Each property has to have unique index for this view type
51 /// <returns>The property index.</returns>
52 /// <param name="viewName">View name</param>
53 /// <param name="viewType">View type</param>
54 /// <param name="type">Type.</param>
55 public int GetPropertyIndex( string viewName, System.Type viewType, ScriptableProperty.ScriptableType type )
60 if (! _propertyRange.TryGetValue (viewName, out range) )
62 // view not found, register it now
63 range = RegisterView( viewName, viewType);
66 int index = range.GetNextFreePropertyIndex ( type );
68 // update the dictionary
69 _propertyRange[viewName]=range;
76 /// We calculate the start property indices, based on the type and it's class heirachy, e.g. DateView (70,000)- > Spin (60,000) -> View (50,000)
78 private void GetPropertyStartRange( System.Type viewType, ref PropertyRange range )
80 const int maxCountPerDerivation = 1000; // For child and animtable properties we use a gap of 1000 between each
81 // views property range in the heirachy
83 // custom views start there property index, at view_PROPERTY_END_INDEX
84 // we add 1000, just incase View class (our C# custom view base) starts using scriptable properties
85 int startEventPropertyIndex = (int)View.PropertyRange.CONTROL_PROPERTY_END_INDEX+maxCountPerDerivation;
87 // for animatable properties current range starts at ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX,
88 // we add 1000, just incase View class starts using animatable properties
89 int startAnimatablePropertyIndex = (int)Dali.PropertyRanges.ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX +maxCountPerDerivation;
91 while ( viewType.BaseType.Name != "CustomView" ) // custom view is our C# view base class. we don't go any deeper.
93 // for every base class increase property start index
94 startEventPropertyIndex += (int)Dali.PropertyRanges.DEFAULT_PROPERTY_MAX_COUNT_PER_DERIVATION; // DALi uses 10,000
95 startAnimatablePropertyIndex += maxCountPerDerivation;
97 //Console.WriteLine ("getStartPropertyIndex = " + viewType.Name +"current index " + startEventPropertyIndex);
98 viewType = viewType.BaseType;
101 range.startEventIndex = startEventPropertyIndex;
102 range.lastUsedEventIndex = startEventPropertyIndex;
104 range.startAnimationIndex = startAnimatablePropertyIndex;
105 range.lastUsedAnimationIndex = startAnimatablePropertyIndex;
110 public struct PropertyRange
113 public int GetNextFreePropertyIndex( ScriptableProperty.ScriptableType type)
115 if ( type == ScriptableProperty.ScriptableType.Default )
117 lastUsedEventIndex++;
118 return lastUsedEventIndex;
122 lastUsedAnimationIndex++;
123 return lastUsedAnimationIndex ;
128 public int startEventIndex; /// start of the property range
129 public int lastUsedEventIndex; /// last used of the property index
131 public int startAnimationIndex; /// start of the property range
132 public int lastUsedAnimationIndex; /// last used of the property index