[Tizen] Ensuring that Registry.Unregister is called from the most derived class befor...
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / GaussianBlurView.cs
1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16
17 using Tizen.NUI.BaseComponents;
18
19 namespace Tizen.NUI
20 {
21
22     using System;
23     using System.Runtime.InteropServices;
24
25
26     internal class GaussianBlurView : View
27     {
28         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
29
30         internal GaussianBlurView(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.GaussianBlurView_SWIGUpcast(cPtr), cMemoryOwn)
31         {
32             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
33         }
34
35         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(GaussianBlurView obj)
36         {
37             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
38         }
39
40         protected override void Dispose(DisposeTypes type)
41         {
42             if (disposed)
43             {
44                 return;
45             }
46
47             if (type == DisposeTypes.Explicit)
48             {
49                 //Called by User
50                 //Release your own managed resources here.
51                 //You should release all of your own disposable objects here.
52
53             }
54
55             //Release your own unmanaged resources here.
56             //You should not access any managed member here except static instance.
57             //because the execution order of Finalizes is non-deterministic.
58
59             if (swigCPtr.Handle != global::System.IntPtr.Zero)
60             {
61                 if (swigCMemOwn)
62                 {
63                     swigCMemOwn = false;
64
65                     //Unreference this instance from Registry.
66                     Registry.Unregister(this);
67
68                     NDalicPINVOKE.delete_GaussianBlurView(swigCPtr);
69                 }
70                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
71             }
72
73             base.Dispose(type);
74         }
75
76
77
78         public class FinishedEventArgs : EventArgs
79         {
80             private GaussianBlurView _gaussianBlurView;
81
82             public GaussianBlurView GaussianBlurView
83             {
84                 get
85                 {
86                     return _gaussianBlurView;
87                 }
88                 set
89                 {
90                     _gaussianBlurView = value;
91                 }
92             }
93         }
94
95         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
96         private delegate void FinishedEventCallbackDelegate(IntPtr application);
97         private DaliEventHandler<object, FinishedEventArgs> _gaussianFinishedEventHandler;
98         private FinishedEventCallbackDelegate _gaussianFinishedEventCallbackDelegate;
99
100         public event DaliEventHandler<object, FinishedEventArgs> Finished
101         {
102             add
103             {
104                 lock (this)
105                 {
106                     // Restricted to only one listener
107                     if (_gaussianFinishedEventHandler == null)
108                     {
109                         _gaussianFinishedEventHandler += value;
110
111                         _gaussianFinishedEventCallbackDelegate = new FinishedEventCallbackDelegate(OnFinished);
112                         this.FinishedSignal().Connect(_gaussianFinishedEventCallbackDelegate);
113                     }
114                 }
115             }
116
117             remove
118             {
119                 lock (this)
120                 {
121                     if (_gaussianFinishedEventHandler != null)
122                     {
123                         this.FinishedSignal().Disconnect(_gaussianFinishedEventCallbackDelegate);
124                     }
125
126                     _gaussianFinishedEventHandler -= value;
127                 }
128             }
129         }
130
131         // Callback for GaussianBlurView FinishedSignal
132         private void OnFinished(IntPtr data)
133         {
134             FinishedEventArgs e = new FinishedEventArgs();
135
136             // Populate all members of "e" (FinishedEventArgs) with real data
137             e.GaussianBlurView = Registry.GetManagedBaseHandleFromNativePtr(data) as GaussianBlurView;
138
139             if (_gaussianFinishedEventHandler != null)
140             {
141                 //here we send all data to user event handlers
142                 _gaussianFinishedEventHandler(this, e);
143             }
144         }
145
146         public GaussianBlurView() : this(NDalicPINVOKE.GaussianBlurView_New__SWIG_0(), true)
147         {
148             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
149
150         }
151         public GaussianBlurView(uint numSamples, float blurBellCurveWidth, PixelFormat renderTargetPixelFormat, float downsampleWidthScale, float downsampleHeightScale, bool blurUserImage) : this(NDalicPINVOKE.GaussianBlurView_New__SWIG_1(numSamples, blurBellCurveWidth, (int)renderTargetPixelFormat, downsampleWidthScale, downsampleHeightScale, blurUserImage), true)
152         {
153             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
154
155         }
156         public GaussianBlurView(uint numSamples, float blurBellCurveWidth, PixelFormat renderTargetPixelFormat, float downsampleWidthScale, float downsampleHeightScale) : this(NDalicPINVOKE.GaussianBlurView_New__SWIG_2(numSamples, blurBellCurveWidth, (int)renderTargetPixelFormat, downsampleWidthScale, downsampleHeightScale), true)
157         {
158             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
159
160         }
161         public GaussianBlurView(GaussianBlurView handle) : this(NDalicPINVOKE.new_GaussianBlurView__SWIG_1(GaussianBlurView.getCPtr(handle)), true)
162         {
163             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
164         }
165
166         public GaussianBlurView Assign(GaussianBlurView ZoomView)
167         {
168             GaussianBlurView ret = new GaussianBlurView(NDalicPINVOKE.GaussianBlurView_Assign(swigCPtr, GaussianBlurView.getCPtr(ZoomView)), false);
169             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
170             return ret;
171         }
172
173         public new static GaussianBlurView DownCast(BaseHandle handle)
174         {
175             GaussianBlurView ret = new GaussianBlurView(NDalicPINVOKE.GaussianBlurView_DownCast(BaseHandle.getCPtr(handle)), true);
176             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
177             return ret;
178         }
179
180         public new void Add(View child)
181         {
182             NDalicPINVOKE.GaussianBlurView_Add(swigCPtr, View.getCPtr(child));
183             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
184         }
185
186         public new void Remove(View child)
187         {
188             NDalicPINVOKE.GaussianBlurView_Remove(swigCPtr, View.getCPtr(child));
189             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
190         }
191
192         public void Activate()
193         {
194             NDalicPINVOKE.GaussianBlurView_Activate(swigCPtr);
195             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
196         }
197
198         public void ActivateOnce()
199         {
200             NDalicPINVOKE.GaussianBlurView_ActivateOnce(swigCPtr);
201             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
202         }
203
204         public void Deactivate()
205         {
206             NDalicPINVOKE.GaussianBlurView_Deactivate(swigCPtr);
207             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
208         }
209
210         public void SetUserImageAndOutputRenderTarget(Image inputImage, FrameBufferImage outputRenderTarget)
211         {
212             NDalicPINVOKE.GaussianBlurView_SetUserImageAndOutputRenderTarget(swigCPtr, Image.getCPtr(inputImage), FrameBufferImage.getCPtr(outputRenderTarget));
213             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
214         }
215
216         public int GetBlurStrengthPropertyIndex()
217         {
218             int ret = NDalicPINVOKE.GaussianBlurView_GetBlurStrengthPropertyIndex(swigCPtr);
219             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
220             return ret;
221         }
222
223         public FrameBufferImage GetBlurredRenderTarget()
224         {
225             FrameBufferImage ret = new FrameBufferImage(NDalicPINVOKE.GaussianBlurView_GetBlurredRenderTarget(swigCPtr), true);
226             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
227             return ret;
228         }
229
230         public new void SetBackgroundColor(Vector4 color)
231         {
232             NDalicPINVOKE.GaussianBlurView_SetBackgroundColor(swigCPtr, Vector4.getCPtr(color));
233             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
234         }
235
236         public new Vector4 GetBackgroundColor()
237         {
238             Vector4 ret = new Vector4(NDalicPINVOKE.GaussianBlurView_GetBackgroundColor(swigCPtr), true);
239             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
240             return ret;
241         }
242
243         public GaussianBlurViewSignal FinishedSignal()
244         {
245             GaussianBlurViewSignal ret = new GaussianBlurViewSignal(NDalicPINVOKE.GaussianBlurView_FinishedSignal(swigCPtr), false);
246             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
247             return ret;
248         }
249
250     }
251
252 }