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 "stage-api.h"
23 #include <object/property-value-wrapper.h>
24 #include <actors/actor-wrapper.h>
25 #include <actors/actor-api.h>
26 #include <render-tasks/render-task-list-wrapper.h>
36 /***************************************
39 ****************************************/
40 Dali::Stage StageApi::GetStage(v8::Isolate* isolate, const v8::FunctionCallbackInfo<v8::Value>& args)
42 // the stage object should be in args, but for now just use GetCurrent
43 return Stage::GetCurrent();
47 * Adds a child Actor to the Stage.
50 * @param {Object} Actor
52 void StageApi::Add( const v8::FunctionCallbackInfo< v8::Value >& args )
54 v8::Isolate* isolate = args.GetIsolate();
55 v8::HandleScope handleScope( isolate );
56 Stage stage = GetStage( isolate, args );
58 Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
65 DALI_SCRIPT_EXCEPTION( isolate, "missing actor parameter");
70 * Removes a child Actor to the Stage.
73 * @param {Object} Actor
75 void StageApi::Remove( const v8::FunctionCallbackInfo< v8::Value >& args )
77 v8::Isolate* isolate = args.GetIsolate();
78 v8::HandleScope handleScope( isolate );
79 Stage stage = GetStage( isolate, args );
82 Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
85 stage.Remove( actor );
89 DALI_SCRIPT_EXCEPTION( isolate, "missing actor parameter");
93 * Get the size of the stage
96 * @return {Object} size with properties { x: , y: }
98 void StageApi::GetSize( const v8::FunctionCallbackInfo< v8::Value >& args )
100 v8::Isolate* isolate = args.GetIsolate();
101 v8::HandleScope handleScope( isolate );
102 Stage stage = GetStage( isolate, args );
103 Vector2 size( stage.GetSize() );
105 v8::Local<v8::Object> sizeObject = v8::Object::New( isolate );
106 sizeObject->Set( v8::String::NewFromUtf8( isolate, "x"), v8::Number::New( isolate,size.width ));
107 sizeObject->Set( v8::String::NewFromUtf8( isolate, "y"), v8::Number::New( isolate,size.height ));
110 args.GetReturnValue().Set( sizeObject );
114 * Retrieve the list of render-tasks.
115 * @method getRenderTaskList
117 * @return {Object} render task list
119 void StageApi::GetRenderTaskList( const v8::FunctionCallbackInfo< v8::Value >& args )
121 v8::Isolate* isolate = args.GetIsolate();
122 v8::HandleScope handleScope( isolate );
123 Stage stage = GetStage( isolate, args );
125 RenderTaskList taskList = stage.GetRenderTaskList();
127 v8::Local <v8::Object> object = RenderTaskListWrapper::WrapRenderTaskList( isolate, taskList );
129 args.GetReturnValue().Set( object );
132 * Query the number of on-stage layers.
133 * Note that a default layer is always provided (count >= 1).
134 * @method getLayerCount
136 * @return {Number} number of layers
138 void StageApi::GetLayerCount( const v8::FunctionCallbackInfo<v8::Value>& args)
140 v8::Isolate* isolate = args.GetIsolate();
141 v8::HandleScope handleScope( isolate );
142 Stage stage = GetStage( isolate, args );
144 args.GetReturnValue().Set( v8::Integer::New( isolate, stage.GetLayerCount() ) );
148 * Retrieve the list of render-tasks.
151 * @param {Integer} depth
152 * @return {Object} layer
154 void StageApi::GetLayer( const v8::FunctionCallbackInfo< v8::Value >& args )
156 v8::Isolate* isolate = args.GetIsolate();
157 v8::HandleScope handleScope( isolate );
158 Stage stage = GetStage( isolate, args );
161 unsigned int depth = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 );
164 DALI_SCRIPT_EXCEPTION( isolate, "Integer parameter missing" );
167 Layer rootLayer = stage.GetLayer( depth );
169 v8::Handle < v8::Object > wrappedLayer = ActorWrapper::WrapActor( isolate, rootLayer );
170 args.GetReturnValue().Set( wrappedLayer );
173 * Returns the Stage's Root Layer.
174 * @method getRootLayer
176 * @return {Object} root layer
178 void StageApi::GetRootLayer( const v8::FunctionCallbackInfo<v8::Value>& args)
180 v8::Isolate* isolate = args.GetIsolate();
181 v8::HandleScope handleScope( isolate );
182 Stage stage = GetStage( isolate, args );
184 Layer rootLayer = stage.GetRootLayer();
186 v8::Handle < v8::Object > wrappedLayer = ActorWrapper::WrapActor( isolate, rootLayer );
187 args.GetReturnValue().Set( wrappedLayer );
191 * Set the background color of the stage
192 * @method setBackgroundColor
194 * @param {Object} Array of [Red,Green,Blue,Alpha], e.g. dali.COLOR_RED, or [1,0,0,1] (full red and alpha);
196 * dali.stage.setBackgroundColor( dali.COLOR_RED );
198 * dali.stage.setBackgroundColor( [0.5,0.5,0.5,1 ] ); // set the background to grey
200 void StageApi::SetBackgroundColor( const v8::FunctionCallbackInfo<v8::Value>& args)
202 v8::Isolate* isolate = args.GetIsolate();
203 v8::HandleScope handleScope( isolate );
204 Stage stage = GetStage( isolate, args );
207 Vector4 backgroundColor = V8Utils::GetVector4Parameter( PARAMETER_0, found, isolate, args);
210 DALI_SCRIPT_EXCEPTION( isolate, "no parameter not found" );
213 stage.SetBackgroundColor( backgroundColor );
216 * Get the background color of the stage
217 * @method getBackgroundColor
219 * @return {Object} object that contains the properties [red:,green:,blue,alpha:]
221 void StageApi::GetBackgroundColor( const v8::FunctionCallbackInfo<v8::Value>& args)
223 v8::Isolate* isolate = args.GetIsolate();
224 v8::HandleScope handleScope( isolate );
225 Stage stage = GetStage( isolate, args );
227 Vector4 color = stage.GetBackgroundColor();
229 v8::Local<v8::Object> colorObject = v8::Object::New( isolate );
231 colorObject->Set( v8::String::NewFromUtf8( isolate, "red"), v8::Number::New( isolate,color.r));
232 colorObject->Set( v8::String::NewFromUtf8( isolate, "green"), v8::Number::New( isolate,color.g));
233 colorObject->Set( v8::String::NewFromUtf8( isolate, "blue"), v8::Number::New( isolate,color.b));
234 colorObject->Set( v8::String::NewFromUtf8( isolate, "alpha"), v8::Number::New( isolate,color.a));
237 args.GetReturnValue().Set( colorObject );
242 * Retrieve the DPI of the display device to which the stage is connected.
245 * @return {Object} object that contains the properties [x:,y:]
247 void StageApi::GetDpi( const v8::FunctionCallbackInfo<v8::Value>& args)
249 v8::Isolate* isolate = args.GetIsolate();
250 v8::HandleScope handleScope( isolate );
251 Stage stage = GetStage( isolate, args );
253 Vector2 dpi( stage.GetDpi() );
255 v8::Local<v8::Object> dpiObject = v8::Object::New( isolate );
256 dpiObject->Set( v8::String::NewFromUtf8( isolate, "x"), v8::Number::New( isolate,dpi.x));
257 dpiObject->Set( v8::String::NewFromUtf8( isolate, "y"), v8::Number::New( isolate,dpi.y));
260 args.GetReturnValue().Set( dpiObject );
264 } // namespace V8Plugin