Fixed typo of JavaScript API name for layer.lowerBelow
[platform/core/uifw/dali-toolkit.git] / plugins / dali-script-v8 / src / actors / layer-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 "layer-api.h"
20
21 // INTERNAL INCLUDES
22 #include <object/handle-wrapper.h>
23 #include <v8-utils.h>
24
25 namespace Dali
26 {
27
28 namespace V8Plugin
29 {
30
31 namespace //unnamed name space
32 {
33
34 Layer GetLayer( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
35 {
36   HandleWrapper* handleWrapper = HandleWrapper::Unwrap( isolate, args.This() );
37   return Layer::DownCast( handleWrapper->mHandle );
38 }
39
40 } //unnamed name space
41
42 /***************************************
43  * LAYER FUNCTIONS
44  *
45  ****************************************/
46 /**
47  * Constructor
48  *
49  * @constructor
50  * @method Layer
51  * @for Layer
52  * @return {Object} Layer
53  */
54 Actor LayerApi::New( const v8::FunctionCallbackInfo<v8::Value>& args )
55 {
56   return Layer::New();
57 }
58
59 /**
60  *  Query the depth of the layer
61  *
62  * 0 is bottom most layer, higher number is on top
63  * Condition: layer is on the stage
64  * If layer is not added to the stage, returns 0.
65  * @return  {Number}  the current depth of the layer.
66  */
67 void LayerApi::GetDepth( const v8::FunctionCallbackInfo<v8::Value>& args )
68 {
69   v8::Isolate* isolate = args.GetIsolate();
70   v8::HandleScope handleScope( isolate );
71   Layer layer = GetLayer( isolate, args );
72
73   args.GetReturnValue().Set( v8::Integer::New( isolate, layer.GetDepth() ) );
74
75 }
76
77 /**
78  * Increment the depth of the layer.
79  * Condition: layer is on the stage
80  * @method Raise
81  * @for Layer
82  *
83  */
84 void LayerApi::Raise( const v8::FunctionCallbackInfo<v8::Value>& args )
85 {
86   v8::Isolate* isolate = args.GetIsolate();
87   v8::HandleScope handleScope( isolate );
88   Layer layer = GetLayer( isolate, args );
89   layer.Raise();
90 }
91
92 /**
93  * Decrement the depth of the layer.
94  * Condition: layer is on the stage
95  * @for Layer
96  * @method lower
97  */
98 void LayerApi::Lower( const v8::FunctionCallbackInfo<v8::Value>& args )
99 {
100   v8::Isolate* isolate = args.GetIsolate();
101   v8::HandleScope handleScope( isolate );
102   Layer layer = GetLayer( isolate, args );
103   layer.Lower();
104 }
105
106 /**
107  *  Ensures the layers depth is greater than the target layer.
108  *
109  * If the layer already is above target layer its depth is not changed
110  * If the layer was below target, its new depth will be immediately above target
111  * Note! All layers between this layer and target get new depth values
112  * Condition: layer is on the stage
113  * Condition: target layer is on the stage
114  * @for Layer
115  * @method raiseAbove
116  * @param target layer to get above of
117  */
118 void LayerApi::RaiseAbove( const v8::FunctionCallbackInfo<v8::Value>& args )
119 {
120   v8::Isolate* isolate = args.GetIsolate();
121   v8::HandleScope handleScope( isolate );
122   Layer layer = GetLayer( isolate, args );
123   bool found(false);
124
125   Layer target = V8Utils::GetLayerParameter( PARAMETER_0, found, isolate, args );
126   if( found )
127   {
128     layer.RaiseAbove( target );
129   }
130   else
131   {
132     DALI_SCRIPT_EXCEPTION( isolate, "layer param not found");
133   }
134 }
135
136 /**
137  *  Ensures the layers depth is less than the target layer.
138  *
139  * If the layer already is below the layer its depth is not changed
140  * If the layer was above target, its new depth will be immediately below target
141  * Note! All layers between this layer and target get new depth values
142  * Conditions: layer is on the stage, target layer is on the stage
143  * @param target layer to get below of
144  * @for Layer
145  * @method lowerBelow
146  */
147 void LayerApi::LowerBelow( const v8::FunctionCallbackInfo<v8::Value>& args )
148 {
149   v8::Isolate* isolate = args.GetIsolate();
150   v8::HandleScope handleScope( isolate );
151   Layer layer = GetLayer( isolate, args );
152   bool found( false );
153
154   Layer target = V8Utils::GetLayerParameter( PARAMETER_0, found, isolate, args );
155
156   if( found )
157   {
158     layer.LowerBelow( target );
159   }
160   else
161   {
162     DALI_SCRIPT_EXCEPTION( isolate, "layer param not found");
163   }
164
165 }
166
167 /**
168  * Raises the layer to the top.
169  * Conditions:  layer is on the stage
170  * @for Layer
171  * @method raiseToTop
172  */
173 void LayerApi::RaiseToTop( const v8::FunctionCallbackInfo<v8::Value>& args )
174 {
175   v8::Isolate* isolate = args.GetIsolate();
176   v8::HandleScope handleScope( isolate );
177   Layer layer = GetLayer( isolate, args );
178   layer.RaiseToTop();
179 }
180
181 /**
182  * Lowers the layer to the bottom.
183  * Conditions:  layer is on the stage
184  * @for Layer
185  * @method lowerToBottom
186  */
187 void LayerApi::LowerToBottom( const v8::FunctionCallbackInfo<v8::Value>& args )
188 {
189   v8::Isolate* isolate = args.GetIsolate();
190   v8::HandleScope handleScope( isolate );
191   Layer layer = GetLayer( isolate, args );
192   layer.LowerToBottom();
193 }
194
195 /**
196  *  Moves the layer directly above the given layer.
197  *
198  * After the call this layers depth will be immediately above target
199  * Note! All layers between this layer and target get new depth values
200  * Conditions: layer is on the stage, target layer is on the stage
201  * @param target layer to get on top of
202  * @for Layer
203  * @method moveAbove
204  */
205 void LayerApi::MoveAbove( const v8::FunctionCallbackInfo<v8::Value>& args )
206 {
207   v8::Isolate* isolate = args.GetIsolate();
208   v8::HandleScope handleScope( isolate );
209   Layer layer = GetLayer( isolate, args );
210   bool found( false );
211
212   Layer target = V8Utils::GetLayerParameter( PARAMETER_0, found, isolate, args );
213   if( found )
214   {
215     layer.MoveAbove( target );
216   }
217   else
218   {
219     DALI_SCRIPT_EXCEPTION( isolate, "layer param not found");
220   }
221 }
222
223 /**
224  *  Moves the layer directly below the given layer.
225  *
226  * After the call this layers depth will be immediately below target
227  * Note! All layers between this layer and target get new depth values
228  * Condition: layer is on the stage
229  * Condition: target layer is on the stage
230  * @param target layer to get below of
231  * @for Layer
232  * @method moveBelow
233  */
234 void LayerApi::MoveBelow( const v8::FunctionCallbackInfo<v8::Value>& args )
235 {
236   v8::Isolate* isolate = args.GetIsolate();
237   v8::HandleScope handleScope( isolate );
238   Layer layer = GetLayer( isolate, args );
239   bool found( false );
240
241   Layer target = V8Utils::GetLayerParameter( PARAMETER_0, found, isolate, args );
242
243   if( found )
244   {
245     layer.MoveBelow( target );
246   }
247   else
248   {
249     DALI_SCRIPT_EXCEPTION( isolate, "layer param not found");
250   }
251 }
252
253 // should really be a property
254 /**
255  *  Whether to disable the depth test.
256  *
257  * By default a layer enables depth test if there is more than one opaque actor or if there is one opaque actor and one, or more, transparent actors.
258  * However, it's possible to disable the depth test by calling this method.
259  *
260  * @param {Boolean}  disable true disables depth test. false sets the default behaviour.
261  * @for Layer
262  * @method setDepthTestDisabled
263  */
264 void LayerApi::SetDepthTestDisabled( const v8::FunctionCallbackInfo<v8::Value>& args )
265 {
266   v8::Isolate* isolate = args.GetIsolate();
267   v8::HandleScope handleScope( isolate );
268   Layer layer = GetLayer( isolate, args );
269   bool parameterFound( false );
270   bool depthTest = V8Utils::GetBooleanParameter( PARAMETER_0, parameterFound, isolate, args );
271   if( !parameterFound )
272   {
273     DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
274     return;
275   }
276   layer.SetDepthTestDisabled( depthTest );
277
278 }
279
280 /**
281  *  Retrieves whether depth test is disabled.
282  *
283  * @return { Boolean}  true if depth test is disabled.
284  * @for Layer
285  * @method isDepthTestDisabled
286  */
287 void LayerApi::IsDepthTestDisabled( const v8::FunctionCallbackInfo<v8::Value>& args )
288 {
289   v8::Isolate* isolate = args.GetIsolate();
290   v8::HandleScope handleScope( isolate );
291   Layer layer = GetLayer( isolate, args );
292   args.GetReturnValue().Set( v8::Boolean::New( isolate, layer.IsDepthTestDisabled() ) );
293 }
294
295
296
297 } // namespace V8Plugin
298
299 } // namespace Dali