dali ver 1.2.27 devel-master branch code sync
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / devel-src / PropertyRangeManager.cs
1 using System;
2 using System.Runtime.InteropServices;
3 using System.Collections.Generic;
4
5 #if true
6 using System.Reflection;
7 #endif
8
9 namespace Tizen.NUI
10 {
11   /// <summary>
12   /// Helper class for calculating what property indexes should be assigned to C# View (view) classes.
13   /// </summary>
14   public class PropertyRangeManager
15   {
16     private Dictionary<String, PropertyRange > _propertyRange;
17
18     /// <summary>
19     /// Initializes a new instance of the <see cref="Tizen.NUI.PropertyRangeManager"/> class.
20     /// </summary>
21     public PropertyRangeManager ()
22     {
23       _propertyRange = new Dictionary<String, PropertyRange > ();
24     }
25
26     /// <summary>
27     /// Only called if a View has scriptable properties
28     /// </summary>
29     private PropertyRange RegisterView( string viewName, System.Type viewType )
30     {
31       PropertyRange range;
32
33       if ( _propertyRange.TryGetValue (viewName, out range) )
34       {
35         // already registered
36         return range;
37       }
38
39       // Find out the event and animatable start indexes for the type
40       range = new PropertyRange();
41
42       GetPropertyStartRange( viewType, ref range);
43
44       // add it to our dictionary
45       _propertyRange.Add( viewName, range );
46
47       return range;
48
49      }
50
51     /// <summary>
52     /// Gets the index of the property.
53     /// Each property has to have unique index for this view type
54     /// </summary>
55     /// <returns>The property index.</returns>
56     /// <param name="viewName">View name</param>
57     /// <param name="viewType">View type</param>
58     /// <param name="type">Type.</param>
59     public int GetPropertyIndex( string viewName, System.Type viewType, ScriptableProperty.ScriptableType type )
60     {
61
62       PropertyRange range;
63
64       if (!  _propertyRange.TryGetValue (viewName, out range) )
65       {
66          // view not found, register it now
67           range = RegisterView( viewName, viewType);
68       }
69
70       int index =  range.GetNextFreePropertyIndex ( type );
71
72       // update the dictionary
73       _propertyRange[viewName]=range;
74
75       return index;
76
77     }
78
79     ///<summary>
80     /// 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)
81     /// </summary>
82     private void GetPropertyStartRange( System.Type viewType, ref PropertyRange range )
83     {
84       const int maxCountPerDerivation = 1000; // For child and animtable properties we use a gap of 1000 between each
85       // views property range in the heirachy
86
87       // custom views start there property index, at view_PROPERTY_END_INDEX
88       // we add 1000, just incase View class (our C# custom view base) starts using scriptable properties
89       int startEventPropertyIndex = (int)View.PropertyRange.CONTROL_PROPERTY_END_INDEX+maxCountPerDerivation;
90
91       // for animatable properties current range starts at ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX,
92       // we add 1000, just incase View class starts using animatable properties
93       int startAnimatablePropertyIndex = (int)Tizen.NUI.PropertyRanges.ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX +maxCountPerDerivation;\r
94 \r
95 #if true
96             while (viewType.GetTypeInfo().BaseType.Name != "CustomView")   // custom view is our C# view base class. we don't go any deeper.\r
97             {\r
98                 // for every base class increase property start index\r
99                 startEventPropertyIndex += (int)Tizen.NUI.PropertyRanges.DEFAULT_PROPERTY_MAX_COUNT_PER_DERIVATION; // DALi uses 10,000\r
100                 startAnimatablePropertyIndex += maxCountPerDerivation;\r
101 \r
102                 Tizen.Log.Debug("NUI-APP", "getStartPropertyIndex =  " + viewType.Name + "current index " + startEventPropertyIndex);\r
103                 viewType = viewType.GetTypeInfo().BaseType;\r
104             }\r
105 #else
106       //original
107       while ( viewType.BaseType.Name != "CustomView" )   // custom view is our C# view base class. we don't go any deeper.
108       {
109         // for every base class increase property start index
110         startEventPropertyIndex += (int)Tizen.NUI.PropertyRanges.DEFAULT_PROPERTY_MAX_COUNT_PER_DERIVATION; // DALi uses 10,000
111         startAnimatablePropertyIndex += maxCountPerDerivation;
112
113         ////Console.WriteLine ("getStartPropertyIndex =  " + viewType.Name +"current index " + startEventPropertyIndex);
114         viewType = viewType.BaseType;
115       }
116 #endif
117 \r
118             range.startEventIndex = startEventPropertyIndex;
119       range.lastUsedEventIndex = startEventPropertyIndex;
120
121       range.startAnimationIndex = startAnimatablePropertyIndex;
122       range.lastUsedAnimationIndex = startAnimatablePropertyIndex;
123
124     }
125
126
127     public struct PropertyRange
128     {
129
130       public int GetNextFreePropertyIndex( ScriptableProperty.ScriptableType type)
131       {
132         if ( type == ScriptableProperty.ScriptableType.Default )
133         {
134            lastUsedEventIndex++;
135            return lastUsedEventIndex;
136         }
137         else
138         {
139           lastUsedAnimationIndex++;
140           return lastUsedAnimationIndex ;
141         }
142       }
143
144
145       public int startEventIndex;    /// start of the property range
146       public int lastUsedEventIndex;    /// last used of the property index
147
148       public int startAnimationIndex;  /// start of the property range
149       public int lastUsedAnimationIndex; /// last used of the property index
150     };
151
152
153
154 }
155 }