Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / Image.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 namespace Tizen.NUI
18 {
19
20     using System;
21     using System.Runtime.InteropServices;
22
23
24     internal class Image : BaseHandle
25     {
26         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
27
28         internal Image(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.Image_SWIGUpcast(cPtr), cMemoryOwn)
29         {
30             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
31         }
32
33         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Image obj)
34         {
35             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
36         }
37
38         protected override void Dispose(DisposeTypes type)
39         {
40             if (disposed)
41             {
42                 return;
43             }
44
45             if (type == DisposeTypes.Explicit)
46             {
47                 //Called by User
48                 //Release your own managed resources here.
49                 //You should release all of your own disposable objects here.
50
51             }
52
53             //Release your own unmanaged resources here.
54             //You should not access any managed member here except static instance.
55             //because the execution order of Finalizes is non-deterministic.
56
57             if (swigCPtr.Handle != global::System.IntPtr.Zero)
58             {
59                 if (swigCMemOwn)
60                 {
61                     swigCMemOwn = false;
62                     NDalicPINVOKE.delete_Image(swigCPtr);
63                 }
64                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
65             }
66
67             base.Dispose(type);
68         }
69
70
71
72         /**
73           * @brief Event arguments that passed via Uploaded signal
74           *
75           */
76         public class UploadedEventArgs : EventArgs
77         {
78             private Image _image;
79             /**
80               * @brief Image - is the image data that gets uploaded to GL.
81               *
82               */
83             public Image Image
84             {
85                 get
86                 {
87                     return _image;
88                 }
89                 set
90                 {
91                     _image = value;
92                 }
93             }
94         }
95
96         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
97         private delegate void UploadedEventCallbackDelegate(IntPtr image);
98         private DaliEventHandler<object, UploadedEventArgs> _imageUploadedEventHandler;
99         private UploadedEventCallbackDelegate _imageUploadedEventCallbackDelegate;
100
101         /**
102           * @brief Event for Uploaded signal which can be used to subscribe/unsubscribe the event handler
103           * (in the type of UploadedEventHandler-DaliEventHandler<object,UploadedEventArgs>)
104           * provided by the user. Uploaded signal is emitted when the image data gets uploaded to GL.
105           */
106         public event DaliEventHandler<object, UploadedEventArgs> Uploaded
107         {
108             add
109             {
110                 lock (this)
111                 {
112                     // Restricted to only one listener
113                     if (_imageUploadedEventHandler == null)
114                     {
115                         _imageUploadedEventHandler += value;
116
117                         _imageUploadedEventCallbackDelegate = new UploadedEventCallbackDelegate(OnUploaded);
118                         this.UploadedSignal().Connect(_imageUploadedEventCallbackDelegate);
119                     }
120                 }
121             }
122
123             remove
124             {
125                 lock (this)
126                 {
127                     if (_imageUploadedEventHandler != null)
128                     {
129                         this.UploadedSignal().Disconnect(_imageUploadedEventCallbackDelegate);
130                     }
131
132                     _imageUploadedEventHandler -= value;
133                 }
134             }
135         }
136
137         // Callback for Image UploadedSignal
138         private void OnUploaded(IntPtr data)
139         {
140             UploadedEventArgs e = new UploadedEventArgs();
141
142             // Populate all members of "e" (UploadedEventArgs) with real data
143             e.Image = Image.GetImageFromPtr(data);
144
145             if (_imageUploadedEventHandler != null)
146             {
147                 //here we send all data to user event handlers
148                 _imageUploadedEventHandler(this, e);
149             }
150         }
151
152
153         public static Image GetImageFromPtr(global::System.IntPtr cPtr)
154         {
155             Image ret = new Image(cPtr, false);
156             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
157             return ret;
158         }
159
160
161         public Image() : this(NDalicPINVOKE.new_Image__SWIG_0(), true)
162         {
163             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
164         }
165
166         public Image(Image handle) : this(NDalicPINVOKE.new_Image__SWIG_1(Image.getCPtr(handle)), true)
167         {
168             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
169         }
170
171         public Image Assign(Image rhs)
172         {
173             Image ret = new Image(NDalicPINVOKE.Image_Assign(swigCPtr, Image.getCPtr(rhs)), false);
174             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
175             return ret;
176         }
177
178         public static Image DownCast(BaseHandle handle)
179         {
180             Image ret =  Registry.GetManagedBaseHandleFromNativePtr(handle) as Image;
181             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
182             return ret;
183         }
184
185         public uint GetWidth()
186         {
187             uint ret = NDalicPINVOKE.Image_GetWidth(swigCPtr);
188             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
189             return ret;
190         }
191
192         public uint GetHeight()
193         {
194             uint ret = NDalicPINVOKE.Image_GetHeight(swigCPtr);
195             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
196             return ret;
197         }
198
199         public ImageSignal UploadedSignal()
200         {
201             ImageSignal ret = new ImageSignal(NDalicPINVOKE.Image_UploadedSignal(swigCPtr), false);
202             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
203             return ret;
204         }
205
206     }
207
208 }