Fix the warning log in Control causing the wrong position
[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 Dali.Constants.Animation.State Status
113   {
114     get
115     {
116        return (Dali.Constants.Animation.State)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 Dali.Constants.Animation.EndAction EndAction
147   {
148     set
149     {
150         switch(value)
151         {
152           case Dali.Constants.Animation.EndAction.Cancel :
153             SetEndAction(Dali.Animation.DaliEndAction.Bake);
154             break;
155           case Dali.Constants.Animation.EndAction.Discard :
156             SetEndAction(Dali.Animation.DaliEndAction.Discard);
157             break;
158           case Dali.Constants.Animation.EndAction.Stop :
159             SetEndAction(Dali.Animation.DaliEndAction.BakeFinal);
160             break;
161           default :
162             SetEndAction(Dali.Animation.DaliEndAction.Bake);
163             break;
164         }
165     }
166     get
167     {
168         Dali.Animation.DaliEndAction temp = GetEndAction();
169         switch(temp)
170         {
171           case Dali.Animation.DaliEndAction.Bake :
172             return Dali.Constants.Animation.EndAction.Cancel;
173           case Dali.Animation.DaliEndAction.Discard :
174             return Dali.Constants.Animation.EndAction.Discard;
175           case Dali.Animation.DaliEndAction.BakeFinal :
176             return Dali.Constants.Animation.EndAction.Stop;
177           default :
178             return Dali.Constants.Animation.EndAction.Cancel;
179         }
180     }
181   }
182
183   public void Stop(Dali.Constants.Animation.EndAction action) {
184     switch( action )
185     {
186       case Dali.Constants.Animation.EndAction.Cancel :
187         SetEndAction(Dali.Animation.DaliEndAction.Bake);
188         break;
189       case Dali.Constants.Animation.EndAction.Discard :
190         SetEndAction(Dali.Animation.DaliEndAction.Discard);
191         break;
192       case Dali.Constants.Animation.EndAction.Stop :
193         SetEndAction(Dali.Animation.DaliEndAction.BakeFinal);
194         break;
195       default :
196         SetEndAction(Dali.Animation.DaliEndAction.Bake);
197         break;
198     }
199     NDalicPINVOKE.Animation_Stop(swigCPtr);
200     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
201   }
202
203   public int StartTime { set; get; }
204   public int EndTime { set; get; }
205   public string TargetPoperty { set; get; }
206   public object Destination { set; get; }
207   public Dali.AlphaFunction AlphaFunction { set; get; }
208
209
210   public void AnimateBy(Actor target)
211   {
212     string _str1 = TargetPoperty.Substring(0, 1);
213     string _str2 = TargetPoperty.Substring(1);
214     string _str = _str1.ToLower() + _str2;
215
216     dynamic obj = (object)Destination;
217
218     if( this.AlphaFunction != null )
219     {
220       if( this.StartTime == 0 && this.EndTime == 0 )
221       {
222         AnimateBy(new Property(target, _str), new Property.Value(obj), this.AlphaFunction );
223       }
224       else
225       {
226         Dali.TimePeriod time = new Dali.TimePeriod( MilliSecondsToSeconds( this.StartTime ), MilliSecondsToSeconds( this.EndTime ) );
227         AnimateBy(new Property(target, _str), new Property.Value(obj), this.AlphaFunction, time );
228       }
229     }
230     else
231     {
232       if( this.StartTime == 0 && this.EndTime == 0 )
233       {
234         AnimateBy(new Property(target, _str), new Property.Value(obj) );
235       }
236       else
237       {
238         Dali.TimePeriod time = new Dali.TimePeriod( MilliSecondsToSeconds( this.StartTime ), MilliSecondsToSeconds( this.EndTime ) );
239         AnimateBy(new Property(target, _str), new Property.Value(obj), time );
240       }
241     }
242   }
243
244   public void AnimateBy(Actor target, string propertyIndex)
245   {
246     string _str1 = propertyIndex.Substring(0, 1);
247     string _str2 = propertyIndex.Substring(1);
248     string _str = _str1.ToLower() + _str2;
249
250     dynamic obj = (object)Destination;
251
252     if( this.AlphaFunction != null )
253     {
254       if( this.StartTime == 0 && this.EndTime == 0 )
255       {
256         AnimateBy(new Property(target, _str), new Property.Value(obj), this.AlphaFunction );
257       }
258       else
259       {
260         Dali.TimePeriod time = new Dali.TimePeriod( MilliSecondsToSeconds( this.StartTime ), MilliSecondsToSeconds( this.EndTime ) );
261         AnimateBy(new Property(target, _str), new Property.Value(obj), this.AlphaFunction, time );
262       }
263     }
264     else
265     {
266       if( this.StartTime == 0 && this.EndTime == 0 )
267       {
268         AnimateBy(new Property(target, _str), new Property.Value(obj) );
269       }
270       else
271       {
272         Dali.TimePeriod time = new Dali.TimePeriod( MilliSecondsToSeconds( this.StartTime ), MilliSecondsToSeconds( this.EndTime ) );
273         AnimateBy(new Property(target, _str), new Property.Value(obj), time );
274       }
275     }
276   }
277
278   public void AnimateBy(Actor target, string propertyIndex, object relativeValue)
279   {
280     string _str1 = propertyIndex.Substring(0, 1);
281     string _str2 = propertyIndex.Substring(1);
282     string _str = _str1.ToLower() + _str2;
283
284     dynamic obj = (object)relativeValue;
285
286     if( this.AlphaFunction != null )
287     {
288       if( this.StartTime == 0 && this.EndTime == 0 )
289       {
290         AnimateBy(new Property(target, _str), new Property.Value(obj), this.AlphaFunction );
291       }
292       else
293       {
294         Dali.TimePeriod time = new Dali.TimePeriod( MilliSecondsToSeconds( this.StartTime ), MilliSecondsToSeconds( this.EndTime ) );
295         AnimateBy(new Property(target, _str), new Property.Value(obj), this.AlphaFunction, time );
296       }
297     }
298     else
299     {
300       if( this.StartTime == 0 && this.EndTime == 0 )
301       {
302         AnimateBy(new Property(target, _str), new Property.Value(obj) );
303       }
304       else
305       {
306         Dali.TimePeriod time = new Dali.TimePeriod( MilliSecondsToSeconds( this.StartTime ), MilliSecondsToSeconds( this.EndTime ) );
307         AnimateBy(new Property(target, _str), new Property.Value(obj), time );
308       }
309     }
310   }
311
312   public void AnimateTo(Actor target)
313   {
314     string _str1 = TargetPoperty.Substring(0, 1);
315     string _str2 = TargetPoperty.Substring(1);
316     string _str = _str1.ToLower() + _str2;
317
318     dynamic obj = (object)Destination;
319
320     if( this.AlphaFunction != null )
321     {
322       if( this.StartTime == 0 && this.EndTime == 0 )
323       {
324         AnimateTo(new Property(target, _str), new Property.Value(obj), this.AlphaFunction );
325       }
326       else
327       {
328         Dali.TimePeriod time = new Dali.TimePeriod( MilliSecondsToSeconds( this.StartTime ), MilliSecondsToSeconds( this.EndTime ) );
329         AnimateTo(new Property(target, _str), new Property.Value(obj), this.AlphaFunction, time );
330       }
331     }
332     else
333     {
334       if( this.StartTime == 0 && this.EndTime == 0 )
335       {
336         AnimateTo(new Property(target, _str), new Property.Value(obj) );
337       }
338       else
339       {
340         Dali.TimePeriod time = new Dali.TimePeriod( MilliSecondsToSeconds( this.StartTime ), MilliSecondsToSeconds( this.EndTime ) );
341         AnimateTo(new Property(target, _str), new Property.Value(obj), time );
342       }
343     }
344   }
345
346   public void AnimateTo(Actor target, string propertyIndex)
347   {
348     string _str1 = propertyIndex.Substring(0, 1);
349     string _str2 = propertyIndex.Substring(1);
350     string _str = _str1.ToLower() + _str2;
351
352     dynamic obj = (object)Destination;
353
354     if( this.AlphaFunction != null )
355     {
356       if( this.StartTime == 0 && this.EndTime == 0 )
357       {
358         AnimateTo(new Property(target, _str), new Property.Value(obj), this.AlphaFunction );
359       }
360       else
361       {
362         Dali.TimePeriod time = new Dali.TimePeriod( MilliSecondsToSeconds( this.StartTime ), MilliSecondsToSeconds( this.EndTime ) );
363         AnimateTo(new Property(target, _str), new Property.Value(obj), this.AlphaFunction, time );
364       }
365     }
366     else
367     {
368       if( this.StartTime == 0 && this.EndTime == 0 )
369       {
370         AnimateTo(new Property(target, _str), new Property.Value(obj) );
371       }
372       else
373       {
374         Dali.TimePeriod time = new Dali.TimePeriod( MilliSecondsToSeconds( this.StartTime ), MilliSecondsToSeconds( this.EndTime ) );
375         AnimateTo(new Property(target, _str), new Property.Value(obj), time );
376       }
377     }
378   }
379
380   public void AnimateTo(Actor target, string propertyIndex, object destinationValue)
381   {
382     string _str1 = propertyIndex.Substring(0, 1);
383     string _str2 = propertyIndex.Substring(1);
384     string _str = _str1.ToLower() + _str2;
385
386     dynamic obj = (object)destinationValue;
387
388     if( this.AlphaFunction != null )
389     {
390       if( this.StartTime == 0 && this.EndTime == 0 )
391       {
392         AnimateTo(new Property(target, _str), new Property.Value(obj), this.AlphaFunction );
393       }
394       else
395       {
396         Dali.TimePeriod time = new Dali.TimePeriod( MilliSecondsToSeconds( this.StartTime ), MilliSecondsToSeconds( this.EndTime ) );
397         AnimateTo(new Property(target, _str), new Property.Value(obj), this.AlphaFunction, time );
398       }
399     }
400     else
401     {
402       if( this.StartTime == 0 && this.EndTime == 0 )
403       {
404         AnimateTo(new Property(target, _str), new Property.Value(obj) );
405       }
406       else
407       {
408         Dali.TimePeriod time = new Dali.TimePeriod( MilliSecondsToSeconds( this.StartTime ), MilliSecondsToSeconds( this.EndTime ) );
409         AnimateTo(new Property(target, _str), new Property.Value(obj), time );
410       }
411     }
412   }
413
414   /**
415    * @brief Create an initialized Animation.
416    *
417    * The animation will not loop.
418    * The default end action is "Bake".
419    * The default Alpha function is linear.
420    * @since 1.0.0
421    * @param [in] durationmSeconds The duration in milli seconds (int).
422    * @return A handle to a newly allocated Dali resource.
423    * @pre DurationmSeconds must be greater than zero.
424    */
425   public Animation (int durationmSeconds) : this (NDalicPINVOKE.Animation_New((float)durationmSeconds/1000.0f), true) {
426     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
427   }
428
429   public Animation () : this (NDalicPINVOKE.Animation_New( 0.0f ), true ) {
430     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
431   }
432   
433 %}
434
435 %enddef
436
437
438 %define DALI_animation_EVENTHANDLER_PARAM( NameSpace, ClassName)
439   Animation_EVENTHANDLER_TYPEMAP_EVENTARG( NameSpace, ClassName);
440   Animation_EVENTHANDLER_TYPEMAP_HELPER( NameSpace, ClassName);
441   %enddef
442
443   namespace Dali
444 {
445   DALI_animation_EVENTHANDLER_PARAM( Dali, Animation);
446 }