JavaScript support for DALi
[platform/core/uifw/dali-toolkit.git] / plugins / dali-script-v8 / src / image / image-wrapper.h
1 #ifndef __DALI_V8PLUGIN_IMAGE_WRAPPER_H__
2 #define __DALI_V8PLUGIN_IMAGE_WRAPPER_H__
3
4 /*
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <v8.h>
23 #include <dali/public-api/images/image.h>
24
25 // INTERNAL INCLUDES
26 #include <shared/base-wrapped-object.h>
27 #include <signals/signal-manager.h>
28
29
30 namespace Dali
31 {
32
33 namespace V8Plugin
34 {
35
36
37 /**
38  * An Image  wrapper.
39  * Provides access to Image specific functionality and V8 memory handling.
40  */
41 class ImageWrapper : public BaseWrappedObject
42 {
43
44 public:
45
46   /**
47    * Image type used an index,
48    * please update the table in ImageApiLookup if this list changes ( the enum is used as an index)
49    */
50   enum ImageType
51   {
52     UNKNOWN_IMAGE_TYPE = -1,
53     IMAGE               = 0,
54     RESOURCE_IMAGE      = 1,
55     NINE_PATCH_IMAGE    = 2,
56     BITMAP_IMAGE        = 3,
57     FRAME_BUFFER_IMAGE  = 4,
58     NATIVE_IMAGE        = 5
59    };
60
61   /**
62    * Constructor
63    */
64   ImageWrapper( const Image& image,
65                 GarbageCollectorInterface& gc );
66
67   /**
68    * Destructor
69    */
70   virtual ~ImageWrapper()
71   {
72   };
73
74   /**
75    * @brief Creates a new Image wrapped inside a Javascript Object.
76    * @note: the actor type ie 'ImageImage' is expected to be the name of the callee function.
77    * @param[in] args v8 function call arguments interpreted
78    */
79   static void NewImage( const v8::FunctionCallbackInfo< v8::Value >& args);
80
81   /**
82    * Wraps an image of a given type
83    */
84   static v8::Handle<v8::Object> WrapImage(v8::Isolate* isolate, const Dali::Image& image, ImageType imageType );
85
86   /**
87    * Wraps an image, the type is looked up from the image
88    */
89   static v8::Handle<v8::Object> WrapImage(v8::Isolate* isolate, const Dali::Image& image );
90
91   /**
92    * @return Image
93    */
94   Image GetImage();
95
96   /**
97    * @return signal manager pointer
98    */
99   virtual SignalManager* GetSignalManager() { return &mSignalManager;}
100
101   // The Image ObjectTemplate, we cache templates so we don't have
102   // keep generating them everytime we want to create an Image
103   static v8::Persistent<v8::ObjectTemplate> mImageTemplate;
104   static v8::Persistent<v8::ObjectTemplate> mResourceImageTemplate;
105   static v8::Persistent<v8::ObjectTemplate> mNinePatchImageTemplate;
106   static v8::Persistent<v8::ObjectTemplate> mBufferImageTemplate;
107   static v8::Persistent<v8::ObjectTemplate> mFrameBufferImageTemplate;
108   static v8::Persistent<v8::ObjectTemplate> mNativeImageTemplate;
109
110 private:
111
112   /**
113    * Helper
114    */
115   static ImageType GetImageType( const std::string& name );
116
117   static v8::Handle<v8::ObjectTemplate> MakeImageTemplate( v8::Isolate* isolate, ImageType imageType );
118   static v8::Local<v8::ObjectTemplate> GetImageTemplate( v8::Isolate* isolate , ImageType imageType );
119
120
121   Image mImage;                     ///< Image handle
122   SignalManager mSignalManager;     ///< Signal Manager
123
124 };
125
126 } // namespace V8Plugin
127
128 } // namespace Dali
129
130 #endif // __DALI_V8PLUGIN_IMAGE_WRAPPER_H__