441547902193f47a66f2e62eb9ba88b2287678de
[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       * @brief Event arguments that passed via Finished signal
31       *
32       */
33     public class FinishedEventArgs : EventArgs
34     {
35       private Animation _animation;
36
37       /**
38         * @brief Animation - is the Animation which has finished with the animation.
39         *
40         */
41       public Animation Animation
42       {
43         get
44         {
45           return _animation;
46         }
47         set
48         {
49           _animation = value;
50         }
51       }
52     }
53
54     [UnmanagedFunctionPointer(CallingConvention.StdCall)]
55     public delegate void FinishedEventHandler(object source, FinishedEventArgs e);
56
57     [UnmanagedFunctionPointer(CallingConvention.StdCall)]
58     private delegate void FinishedEventCallbackDelegate(IntPtr Animation);
59     private FinishedEventHandler _animationFinishedEventHandler;
60     private FinishedEventCallbackDelegate _animationFinishedEventCallbackDelegate;
61
62     /**
63       * @brief Event for Finished signal which can be used to subscribe/unsubscribe the event handler
64       * (in the type of FinishedEventHandler) provided by the user.
65       * Finished signal is emitted when an Animation's animations have finished.
66       */
67     public event FinishedEventHandler Finished
68     {
69       add
70       {
71         lock(this)
72         {
73           // Restricted to only one listener
74           if (_animationFinishedEventHandler == null)
75           {
76             _animationFinishedEventHandler += value;
77
78             _animationFinishedEventCallbackDelegate = new FinishedEventCallbackDelegate(OnFinished);
79             this.FinishedSignal().Connect(_animationFinishedEventCallbackDelegate);
80           }
81         }
82       }
83
84       remove
85       {
86         lock(this)
87         {
88           if (_animationFinishedEventHandler != null)
89           {
90             this.FinishedSignal().Disconnect(_animationFinishedEventCallbackDelegate);
91           }
92
93           _animationFinishedEventHandler -= value;
94         }
95       }
96     }
97
98     // Callback for Animation FinishedSignal
99     private void OnFinished(IntPtr data)
100     {
101       FinishedEventArgs e = new FinishedEventArgs();
102
103       // Populate all members of "e" (FinishedEventArgs) with real data
104       e.Animation = Animation.GetAnimationFromPtr(data);
105
106       if (_animationFinishedEventHandler != null)
107       {
108         //here we send all data to user event handlers
109         _animationFinishedEventHandler(this, e);
110       }
111     }
112
113
114   public static ClassName Get ## ClassName ## FromPtr(global::System.IntPtr cPtr) {
115     ClassName ret = new ClassName(cPtr, false);
116     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
117     return ret;
118   }
119
120
121   public float Duration
122   {
123     set
124     {
125        SetDuration(value);
126     }
127     get
128     {
129        float ret = GetDuration();
130        return ret;
131     }
132   }
133
134   public AlphaFunction DefaultAlphaFunction
135   {
136     set
137     {
138        SetDefaultAlphaFunction(value);
139     }
140     get
141     {
142        AlphaFunction ret = GetDefaultAlphaFunction();
143        return ret;
144     }
145   }
146
147   public Animation.State Status
148   {
149     get
150     {
151        Animation.State ret = GetState();
152        return ret;
153     }
154   }
155
156 %}
157
158 %enddef
159
160
161 %define DALI_animation_EVENTHANDLER_PARAM( NameSpace, ClassName)
162   Animation_EVENTHANDLER_TYPEMAP_EVENTARG( NameSpace, ClassName);
163   Animation_EVENTHANDLER_TYPEMAP_HELPER( NameSpace, ClassName);
164   %enddef
165
166   namespace Dali
167 {
168   DALI_animation_EVENTHANDLER_PARAM( Dali, Animation);
169 }