Dali C#: Common Interface Define related changes
[platform/core/uifw/dali-toolkit.git] / plugins / dali-swig / SWIG / events / animation-event.i
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 %define Animation_EVENTHANDLER_TYPEMAP_EVENTARG(NameSpace, ClassName)
19 %typemap(csimports) NameSpace::ClassName %{
20 using System;
21 using System.Runtime.InteropServices;
22 %}
23
24 %enddef
25
26 %define Animation_EVENTHANDLER_TYPEMAP_HELPER(NameSpace, ClassName)
27   %typemap(cscode) NameSpace::ClassName %{
28
29
30     private EventCallbackDelegateType1<IntPtr> _animationFinishedEventCallbackDelegate;
31     private event EventHandler _animationFinishedEventHandler;
32
33     /**
34       * @brief Event for Finished signal which can be used to subscribe/unsubscribe the event handler
35       * Finished signal is emitted when an Animation's animations have finished.
36       */
37     public event EventHandler Finished
38     {
39       add
40       {
41         lock(this)
42         {
43           _animationFinishedEventHandler += value;
44           _animationFinishedEventCallbackDelegate = OnFinished;
45           this.FinishedSignal().Connect(_animationFinishedEventCallbackDelegate);
46         }
47       }
48       remove
49       {
50         lock(this)
51         {
52           if (_animationFinishedEventHandler != null)
53           {
54             this.FinishedSignal().Disconnect(_animationFinishedEventCallbackDelegate);
55           }
56           _animationFinishedEventHandler -= value;
57         }
58       }
59     }
60
61     // Callback for Animation FinishedSignal
62     private void OnFinished(IntPtr data)
63     {
64       if (_animationFinishedEventHandler != null)
65       {
66         //here we send all data to user event handlers
67         _animationFinishedEventHandler(this, null);
68       }
69     }
70
71   public static ClassName Get ## ClassName ## FromPtr(global::System.IntPtr cPtr) {
72     ClassName ret = new ClassName(cPtr, false);
73     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
74     return ret;
75   }
76
77   private float MilliSecondsToSeconds( int millisec )
78   {
79     return (float)millisec / 1000.0f;
80   }
81
82   private int SecondsToMilliSeconds( float sec )
83   {
84     return (int)( sec * 1000 );
85   }
86
87   public int Duration
88   {
89     set
90     {
91       SetDuration( MilliSecondsToSeconds( value ) );
92     }
93     get
94     {
95       return SecondsToMilliSeconds( GetDuration() );
96     }
97   }
98
99   public AlphaFunction DefaultAlphaFunction
100   {
101     set
102     {
103        SetDefaultAlphaFunction(value);
104     }
105     get
106     {
107        AlphaFunction ret = GetDefaultAlphaFunction();
108        return ret;
109     }
110   }
111
112   public Animation.State Status
113   {
114     get
115     {
116        return GetState();
117     }
118   }
119
120   public int LoopCount
121   {
122     set
123     {
124       SetLoopCount(value);
125     }
126     get
127     {
128       int ret = GetLoopCount();
129       return ret;
130     }
131   }
132
133   public bool Looping
134   {
135     set
136     {
137       SetLooping(value);
138     }
139     get
140     {
141       bool ret = IsLooping();
142       return ret;
143     }
144   }
145
146   public Animation.EndActions EndAction
147   {
148     set
149     {
150       SetEndAction(value);
151     }
152     get
153     {
154       return GetEndAction();
155     }
156   }
157
158   public void Stop(Animation.EndActions action) 
159   {
160     SetEndAction(action);
161     NDalicPINVOKE.Animation_Stop(swigCPtr);
162     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
163   }
164
165   public int StartTime { set; get; }
166   public int EndTime { set; get; }
167   public string TargetProperty { set; get; }
168   public object Destination { set; get; }
169   public Dali.AlphaFunction AlphaFunction { set; get; }
170
171
172   public void AnimateBy(Actor target)
173   {
174     string _str1 = TargetProperty.Substring(0, 1);
175     string _str2 = TargetProperty.Substring(1);
176     string _str = _str1.ToLower() + _str2;
177
178     dynamic obj = (object)Destination;
179
180     if( this.AlphaFunction != null )
181     {
182       if( this.StartTime == 0 && this.EndTime == 0 )
183       {
184         AnimateBy(new Property(target, _str), new Property.Value(obj), this.AlphaFunction );
185       }
186       else
187       {
188         Dali.TimePeriod time = new Dali.TimePeriod( MilliSecondsToSeconds( this.StartTime ), MilliSecondsToSeconds( this.EndTime - this.StartTime ) );
189         AnimateBy(new Property(target, _str), new Property.Value(obj), this.AlphaFunction, time );
190       }
191     }
192     else
193     {
194       if( this.StartTime == 0 && this.EndTime == 0 )
195       {
196         AnimateBy(new Property(target, _str), new Property.Value(obj) );
197       }
198       else
199       {
200         Dali.TimePeriod time = new Dali.TimePeriod( MilliSecondsToSeconds( this.StartTime ), MilliSecondsToSeconds( this.EndTime - this.StartTime ) );
201         AnimateBy(new Property(target, _str), new Property.Value(obj), time );
202       }
203     }
204   }
205
206   public void AnimateBy(Actor target, string propertyIndex)
207   {
208     string _str1 = propertyIndex.Substring(0, 1);
209     string _str2 = propertyIndex.Substring(1);
210     string _str = _str1.ToLower() + _str2;
211
212     dynamic obj = (object)Destination;
213
214     if( this.AlphaFunction != null )
215     {
216       if( this.StartTime == 0 && this.EndTime == 0 )
217       {
218         AnimateBy(new Property(target, _str), new Property.Value(obj), this.AlphaFunction );
219       }
220       else
221       {
222         Dali.TimePeriod time = new Dali.TimePeriod( MilliSecondsToSeconds( this.StartTime ), MilliSecondsToSeconds( this.EndTime - this.StartTime ) );
223         AnimateBy(new Property(target, _str), new Property.Value(obj), this.AlphaFunction, time );
224       }
225     }
226     else
227     {
228       if( this.StartTime == 0 && this.EndTime == 0 )
229       {
230         AnimateBy(new Property(target, _str), new Property.Value(obj) );
231       }
232       else
233       {
234         Dali.TimePeriod time = new Dali.TimePeriod( MilliSecondsToSeconds( this.StartTime ), MilliSecondsToSeconds( this.EndTime - this.StartTime ) );
235         AnimateBy(new Property(target, _str), new Property.Value(obj), time );
236       }
237     }
238   }
239
240   public void AnimateBy(Actor target, string propertyIndex, object relativeValue)
241   {
242     string _str1 = propertyIndex.Substring(0, 1);
243     string _str2 = propertyIndex.Substring(1);
244     string _str = _str1.ToLower() + _str2;
245
246     dynamic obj = (object)relativeValue;
247
248     if( this.AlphaFunction != null )
249     {
250       if( this.StartTime == 0 && this.EndTime == 0 )
251       {
252         AnimateBy(new Property(target, _str), new Property.Value(obj), this.AlphaFunction );
253       }
254       else
255       {
256         Dali.TimePeriod time = new Dali.TimePeriod( MilliSecondsToSeconds( this.StartTime ), MilliSecondsToSeconds( this.EndTime - this.StartTime ) );
257         AnimateBy(new Property(target, _str), new Property.Value(obj), this.AlphaFunction, time );
258       }
259     }
260     else
261     {
262       if( this.StartTime == 0 && this.EndTime == 0 )
263       {
264         AnimateBy(new Property(target, _str), new Property.Value(obj) );
265       }
266       else
267       {
268         Dali.TimePeriod time = new Dali.TimePeriod( MilliSecondsToSeconds( this.StartTime ), MilliSecondsToSeconds( this.EndTime - this.StartTime ) );
269         AnimateBy(new Property(target, _str), new Property.Value(obj), time );
270       }
271     }
272   }
273
274   public void AnimateTo(Actor target)
275   {
276     string _str1 = TargetProperty.Substring(0, 1);
277     string _str2 = TargetProperty.Substring(1);
278     string _str = _str1.ToLower() + _str2;
279
280     dynamic obj = (object)Destination;
281
282     if( this.AlphaFunction != null )
283     {
284       if( this.StartTime == 0 && this.EndTime == 0 )
285       {
286         AnimateTo(new Property(target, _str), new Property.Value(obj), this.AlphaFunction );
287       }
288       else
289       {
290         Dali.TimePeriod time = new Dali.TimePeriod( MilliSecondsToSeconds( this.StartTime ), MilliSecondsToSeconds( this.EndTime - this.StartTime ) );
291         AnimateTo(new Property(target, _str), new Property.Value(obj), this.AlphaFunction, time );
292       }
293     }
294     else
295     {
296       if( this.StartTime == 0 && this.EndTime == 0 )
297       {
298         AnimateTo(new Property(target, _str), new Property.Value(obj) );
299       }
300       else
301       {
302         Dali.TimePeriod time = new Dali.TimePeriod( MilliSecondsToSeconds( this.StartTime ), MilliSecondsToSeconds( this.EndTime - this.StartTime ) );
303         AnimateTo(new Property(target, _str), new Property.Value(obj), time );
304       }
305     }
306   }
307
308   public void AnimateTo(Actor target, string propertyIndex)
309   {
310     string _str1 = propertyIndex.Substring(0, 1);
311     string _str2 = propertyIndex.Substring(1);
312     string _str = _str1.ToLower() + _str2;
313
314     dynamic obj = (object)Destination;
315
316     if( this.AlphaFunction != null )
317     {
318       if( this.StartTime == 0 && this.EndTime == 0 )
319       {
320         AnimateTo(new Property(target, _str), new Property.Value(obj), this.AlphaFunction );
321       }
322       else
323       {
324         Dali.TimePeriod time = new Dali.TimePeriod( MilliSecondsToSeconds( this.StartTime ), MilliSecondsToSeconds( this.EndTime - this.StartTime ) );
325         AnimateTo(new Property(target, _str), new Property.Value(obj), this.AlphaFunction, time );
326       }
327     }
328     else
329     {
330       if( this.StartTime == 0 && this.EndTime == 0 )
331       {
332         AnimateTo(new Property(target, _str), new Property.Value(obj) );
333       }
334       else
335       {
336         Dali.TimePeriod time = new Dali.TimePeriod( MilliSecondsToSeconds( this.StartTime ), MilliSecondsToSeconds( this.EndTime - this.StartTime ) );
337         AnimateTo(new Property(target, _str), new Property.Value(obj), time );
338       }
339     }
340   }
341
342   public void AnimateTo(Actor target, string propertyIndex, object destinationValue)
343   {
344     string _str1 = propertyIndex.Substring(0, 1);
345     string _str2 = propertyIndex.Substring(1);
346     string _str = _str1.ToLower() + _str2;
347
348     dynamic obj = (object)destinationValue;
349
350     if( this.AlphaFunction != null )
351     {
352       if( this.StartTime == 0 && this.EndTime == 0 )
353       {
354         AnimateTo(new Property(target, _str), new Property.Value(obj), this.AlphaFunction );
355       }
356       else
357       {
358         Dali.TimePeriod time = new Dali.TimePeriod( MilliSecondsToSeconds( this.StartTime ), MilliSecondsToSeconds( this.EndTime - this.StartTime ) );
359         AnimateTo(new Property(target, _str), new Property.Value(obj), this.AlphaFunction, time );
360       }
361     }
362     else
363     {
364       if( this.StartTime == 0 && this.EndTime == 0 )
365       {
366         AnimateTo(new Property(target, _str), new Property.Value(obj) );
367       }
368       else
369       {
370         Dali.TimePeriod time = new Dali.TimePeriod( MilliSecondsToSeconds( this.StartTime ), MilliSecondsToSeconds( this.EndTime - this.StartTime ) );
371         AnimateTo(new Property(target, _str), new Property.Value(obj), time );
372       }
373     }
374   }
375
376   public void AnimateBetween(Actor target, KeyFrames keyFrames)
377   {
378     string _str1 = TargetProperty.Substring(0, 1);
379     string _str2 = TargetProperty.Substring(1);
380     string _str = _str1.ToLower() + _str2;
381
382
383     if( this.AlphaFunction != null )
384     {
385       if( this.StartTime == 0 && this.EndTime == 0 )
386       {
387         AnimateBetween(new Property(target, _str), keyFrames, this.AlphaFunction);
388       }
389       else
390       {
391         Dali.TimePeriod time = new Dali.TimePeriod( MilliSecondsToSeconds( this.StartTime ), MilliSecondsToSeconds( this.EndTime - this.StartTime ) );
392         AnimateBetween(new Property(target, _str), keyFrames, this.AlphaFunction, time);
393       }
394     }
395     else
396     {
397       if( this.StartTime == 0 && this.EndTime == 0 )
398       {
399         AnimateBetween(new Property(target, _str), keyFrames);
400       }
401       else
402       {
403         Dali.TimePeriod time = new Dali.TimePeriod( MilliSecondsToSeconds( this.StartTime ), MilliSecondsToSeconds( this.EndTime - this.StartTime ) );
404         AnimateBetween(new Property(target, _str), keyFrames, time);
405       }
406     }
407   }
408
409   public void AnimateBetween(Actor target, KeyFrames keyFrames, Animation.Interpolation interpolation)
410   {
411     string _str1 = TargetProperty.Substring(0, 1);
412     string _str2 = TargetProperty.Substring(1);
413     string _str = _str1.ToLower() + _str2;
414
415
416     if( this.AlphaFunction != null )
417     {
418       if( this.StartTime == 0 && this.EndTime == 0 )
419       {
420         AnimateBetween(new Property(target, _str), keyFrames, this.AlphaFunction, interpolation);
421       }
422       else
423       {
424         Dali.TimePeriod time = new Dali.TimePeriod( MilliSecondsToSeconds( this.StartTime ), MilliSecondsToSeconds( this.EndTime - this.StartTime ) );
425         AnimateBetween(new Property(target, _str), keyFrames, this.AlphaFunction, time, interpolation);
426       }
427     }
428     else
429     {
430       if( this.StartTime == 0 && this.EndTime == 0 )
431       {
432         AnimateBetween(new Property(target, _str), keyFrames, interpolation);
433       }
434       else
435       {
436         Dali.TimePeriod time = new Dali.TimePeriod( MilliSecondsToSeconds( this.StartTime ), MilliSecondsToSeconds( this.EndTime - this.StartTime ) );
437         AnimateBetween(new Property(target, _str), keyFrames, time, interpolation);
438       }
439     }
440   }
441
442
443   /**
444    * @brief Create an initialized Animation.
445    *
446    * The animation will not loop.
447    * The default end action is "Bake".
448    * The default Alpha function is linear.
449    * @since 1.0.0
450    * @param [in] durationmSeconds The duration in milli seconds (int).
451    * @return A handle to a newly allocated Dali resource.
452    * @pre DurationmSeconds must be greater than zero.
453    */
454   public Animation (int durationmSeconds) : this (NDalicPINVOKE.Animation_New((float)durationmSeconds/1000.0f), true) {
455     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
456   }
457
458   public Animation () : this (NDalicPINVOKE.Animation_New( 0.0f ), true ) {
459     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
460   }
461   
462 %}
463
464 %enddef
465
466
467 %define DALI_animation_EVENTHANDLER_PARAM( NameSpace, ClassName)
468   Animation_EVENTHANDLER_TYPEMAP_EVENTARG( NameSpace, ClassName);
469   Animation_EVENTHANDLER_TYPEMAP_HELPER( NameSpace, ClassName);
470   %enddef
471
472   namespace Dali
473 {
474   DALI_animation_EVENTHANDLER_PARAM( Dali, Animation);
475
476 %typemap(cscode) Dali::KeyFrames %{
477
478   public void Add(float progress, object value)
479   {
480     dynamic obj = value;
481     Add(progress, new Property.Value(obj));
482   }
483
484   public void Add(float progress, object value, AlphaFunction alpha)
485   {
486     dynamic obj = value;
487     Add(progress, new Property.Value(obj), alpha);
488   }
489
490 %}
491
492 }