fd121852389e659526c7c41ebc81248c32994167
[platform/core/uifw/dali-toolkit.git] / plugins / dali-script-v8 / src / actors / actor-wrapper.h
1 #ifndef __DALI_V8PLUGIN_ACTOR_WRAPPER_H__
2 #define __DALI_V8PLUGIN_ACTOR_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/actors/actor.h>
24
25 // INTERNAL INCLUDES
26 #include <object/handle-wrapper.h>
27
28 namespace Dali
29 {
30
31 namespace V8Plugin
32 {
33
34
35 /**
36  * Wraps a Dali Actor.
37  */
38 class ActorWrapper : public HandleWrapper
39 {
40
41 public:
42
43   /**
44    * Actor type used an index.
45    * These enums are used to index the ActorApiLookup table in actor-wrapper.cpp.
46    * Any changes made must be reflected in the ActorApiLookup otherwise it may segfault when creating an actor
47    */
48   enum ActorType
49   {
50     UNKNOWN_ACTOR = -1,
51     ACTOR        = 0,
52     LAYER_ACTOR  = 1,
53     CAMERA_ACTOR = 2
54   };
55
56   /**
57    * Constructor
58    * @param actor DALi actor
59    * @param gc garbage collection interface
60    */
61   ActorWrapper( Actor actor,
62                 GarbageCollectorInterface& gc );
63
64   /**
65    * destructor
66    */
67   virtual ~ActorWrapper()
68   {
69   }
70
71   /**
72    * @brief Creates a new Actor wrapped inside a Javascript Object.
73    * @note: the actor type ie 'CameraActor' is expected to be the name of the callee function.
74    * @param[in] args v8 function call arguments interpreted
75    */
76   static void NewActor( const v8::FunctionCallbackInfo< v8::Value >& args);
77
78   /**
79    * @brief Creates a new Control wrapped inside a Javascript Object.
80    * @note: the control type is passed as a parameter e.g. 'TextField'
81    * @param[in] args v8 function call arguments interpreted
82    */
83   static void NewControl( const v8::FunctionCallbackInfo< v8::Value >& args);
84
85   /**
86    * @brief Wraps an actor of a given type
87    */
88   static v8::Handle<v8::Object> WrapActor(v8::Isolate* isolate, Dali::Actor actor,ActorType actorType);
89
90   /**
91    * @brief Wraps an actor, the type is looked up from the actor
92    */
93   static v8::Handle<v8::Object> WrapActor(v8::Isolate* isolate, Dali::Actor actor );
94
95   // The Actor ObjectTemplates.
96   static v8::Persistent<v8::ObjectTemplate> mActorTemplate;
97   static v8::Persistent<v8::ObjectTemplate> mCameraActorTemplate;
98   static v8::Persistent<v8::ObjectTemplate> mLayerActorTemplate;
99
100   /**
101    * @return the wrapped actor
102    */
103   Actor GetActor();
104
105   /**
106    * @return they actor type
107    */
108   static ActorWrapper::ActorType GetActorType( const std::string& name );
109
110 private:
111
112   /**
113    * Helper to make the actor template
114    *
115    */
116   static v8::Handle<v8::ObjectTemplate> MakeDaliActorTemplate( v8::Isolate* isolate, ActorType actorType );
117
118   /**
119    * Helper, get an actor template given an actor type
120    */
121   static v8::Local<v8::ObjectTemplate> GetActorTemplate( v8::Isolate* isolate, ActorType type );
122
123   Actor mActor;
124
125 };
126
127 } // namespace V8Plugin
128
129 } // namespace Dali
130
131 #endif // header