2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "layer-api.h"
22 #include <object/handle-wrapper.h>
31 namespace //unnamed name space
34 Layer GetLayer( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
36 HandleWrapper* handleWrapper = HandleWrapper::Unwrap( isolate, args.This() );
37 return Layer::DownCast( handleWrapper->mHandle );
40 } //unnamed name space
42 /***************************************
45 ****************************************/
52 * @return {Object} Layer
54 Actor LayerApi::New( const v8::FunctionCallbackInfo<v8::Value>& args )
60 * Query the depth of the layer
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.
67 void LayerApi::GetDepth( const v8::FunctionCallbackInfo<v8::Value>& args )
69 v8::Isolate* isolate = args.GetIsolate();
70 v8::HandleScope handleScope( isolate );
71 Layer layer = GetLayer( isolate, args );
73 args.GetReturnValue().Set( v8::Integer::New( isolate, layer.GetDepth() ) );
78 * Increment the depth of the layer.
79 * Condition: layer is on the stage
84 void LayerApi::Raise( const v8::FunctionCallbackInfo<v8::Value>& args )
86 v8::Isolate* isolate = args.GetIsolate();
87 v8::HandleScope handleScope( isolate );
88 Layer layer = GetLayer( isolate, args );
93 * Decrement the depth of the layer.
94 * Condition: layer is on the stage
98 void LayerApi::Lower( const v8::FunctionCallbackInfo<v8::Value>& args )
100 v8::Isolate* isolate = args.GetIsolate();
101 v8::HandleScope handleScope( isolate );
102 Layer layer = GetLayer( isolate, args );
107 * Ensures the layers depth is greater than the target layer.
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
116 * @param target layer to get above of
118 void LayerApi::RaiseAbove( const v8::FunctionCallbackInfo<v8::Value>& args )
120 v8::Isolate* isolate = args.GetIsolate();
121 v8::HandleScope handleScope( isolate );
122 Layer layer = GetLayer( isolate, args );
125 Layer target = V8Utils::GetLayerParameter( PARAMETER_0, found, isolate, args );
128 layer.RaiseAbove( target );
132 DALI_SCRIPT_EXCEPTION( isolate, "layer param not found");
137 * Ensures the layers depth is less than the target layer.
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
147 void LayerApi::LowerBelow( const v8::FunctionCallbackInfo<v8::Value>& args )
149 v8::Isolate* isolate = args.GetIsolate();
150 v8::HandleScope handleScope( isolate );
151 Layer layer = GetLayer( isolate, args );
154 Layer target = V8Utils::GetLayerParameter( PARAMETER_0, found, isolate, args );
158 layer.LowerBelow( target );
162 DALI_SCRIPT_EXCEPTION( isolate, "layer param not found");
168 * Raises the layer to the top.
169 * Conditions: layer is on the stage
173 void LayerApi::RaiseToTop( const v8::FunctionCallbackInfo<v8::Value>& args )
175 v8::Isolate* isolate = args.GetIsolate();
176 v8::HandleScope handleScope( isolate );
177 Layer layer = GetLayer( isolate, args );
182 * Lowers the layer to the bottom.
183 * Conditions: layer is on the stage
185 * @method lowerToBottom
187 void LayerApi::ToBottom( const v8::FunctionCallbackInfo<v8::Value>& args )
189 v8::Isolate* isolate = args.GetIsolate();
190 v8::HandleScope handleScope( isolate );
191 Layer layer = GetLayer( isolate, args );
192 layer.LowerToBottom();
196 * Moves the layer directly above the given layer.
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
205 void LayerApi::MoveAbove( const v8::FunctionCallbackInfo<v8::Value>& args )
207 v8::Isolate* isolate = args.GetIsolate();
208 v8::HandleScope handleScope( isolate );
209 Layer layer = GetLayer( isolate, args );
212 Layer target = V8Utils::GetLayerParameter( PARAMETER_0, found, isolate, args );
215 layer.MoveAbove( target );
219 DALI_SCRIPT_EXCEPTION( isolate, "layer param not found");
224 * Moves the layer directly below the given layer.
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
234 void LayerApi::MoveBelow( const v8::FunctionCallbackInfo<v8::Value>& args )
236 v8::Isolate* isolate = args.GetIsolate();
237 v8::HandleScope handleScope( isolate );
238 Layer layer = GetLayer( isolate, args );
241 Layer target = V8Utils::GetLayerParameter( PARAMETER_0, found, isolate, args );
245 layer.MoveBelow( target );
249 DALI_SCRIPT_EXCEPTION( isolate, "layer param not found");
253 // should really be a property
255 * Whether to disable the depth test.
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.
260 * @param {Boolean} disable true disables depth test. false sets the default behaviour.
262 * @method setDepthTestDisabled
264 void LayerApi::SetDepthTestDisabled( const v8::FunctionCallbackInfo<v8::Value>& args )
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 )
273 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
276 layer.SetDepthTestDisabled( depthTest );
281 * Retrieves whether depth test is disabled.
283 * @return { Boolean} true if depth test is disabled.
285 * @method isDepthTestDisabled
287 void LayerApi::IsDepthTestDisabled( const v8::FunctionCallbackInfo<v8::Value>& args )
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() ) );
297 } // namespace V8Plugin