[dali_1.4.26] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / plugins / dali-script-v8 / src / events / pan-gesture-detector-api.cpp
1 /*
2  * Copyright (c) 2015 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 // CLASS HEADER
19 #include "pan-gesture-detector-api.h"
20
21 // INTERNAL INCLUDES
22 #include <events/pan-gesture-detector-wrapper.h>
23 #include <object/property-value-wrapper.h>
24 #include <v8-utils.h>
25
26 namespace Dali
27 {
28
29 namespace V8Plugin
30 {
31
32 namespace // unnamed namespace
33 {
34
35 PanGestureDetector GetPanGestureDetector( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
36 {
37   v8::HandleScope handleScope( isolate );
38
39   v8::Local<v8::Object> object = args.This();
40   v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField( 0 ) );
41   void* ptr = field->Value();
42
43   PanGestureDetectorWrapper* wrapper = static_cast<PanGestureDetectorWrapper *>( ptr );
44   return wrapper->GetPanGestureDetector();
45 }
46
47 } // unnamed namespace
48
49 /**
50  * Constructor
51  *
52  * @constructor
53  * @for PanGestureDetector
54  * @method PanGestureDetector
55  */
56 PanGestureDetector PanGestureDetectorApi::New( const v8::FunctionCallbackInfo< v8::Value >& args )
57 {
58   return PanGestureDetector::New();
59 }
60
61 /**
62  * Attaches an actor to the pan gesture.
63  *
64  * The panDetected signal will be dispatched when the pan gesture occurs on
65  * the attached actor. You can attach several actors to a pan gesture detector.
66  * @method attach
67  * @for PanGestureDetector
68  * @param {Actor} actor The actor to attach to the pan gesture detector
69  * @example
70  *        panGestureDetector.attach(actor);
71  */
72 void PanGestureDetectorApi::Attach( const v8::FunctionCallbackInfo< v8::Value >& args )
73 {
74   v8::Isolate* isolate = args.GetIsolate();
75   v8::HandleScope handleScope( isolate );
76   bool found( false );
77   //Get actor
78   Dali::Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
79   if( found )
80   {
81     PanGestureDetector panGestureDetector = GetPanGestureDetector( isolate, args );
82     panGestureDetector.Attach( actor );
83   }
84   else
85   {
86     DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
87   }
88 }
89
90
91 /**
92  * Detaches the attached actor from the pan gesture detector.
93  *
94  * The specified actor should have been attached to the pan gesture detector
95  * @method detach
96  * @for PanGestureDetector
97  * @param {Actor} actor The actor to detach from the pan gesture detector
98  * @example
99  *        panGestureDetector.detach(actor);
100  */
101 void PanGestureDetectorApi::Detach( const v8::FunctionCallbackInfo< v8::Value >& args )
102 {
103   v8::Isolate* isolate = args.GetIsolate();
104   v8::HandleScope handleScope( isolate );
105   bool found( false );
106   //Get actor
107   Dali::Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
108   if( found )
109   {
110     PanGestureDetector panGestureDetector = GetPanGestureDetector( isolate, args );
111     panGestureDetector.Detach( actor );
112   }
113   else
114   {
115     DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
116   }
117 }
118
119
120 } // namespace V8Plugin
121
122 } // namespace Dali