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 "image-actor-api.h"
22 #include <object/handle-wrapper.h>
24 #include <object/property-value-wrapper.h>
25 #include <image/image-api.h>
26 #include <image/image-wrapper.h>
27 #include <shader-effects/shader-effect-api.h>
28 #include <shader-effects/shader-effect-wrapper.h>
36 namespace //unnamed name space
39 ImageActor GetImageActor( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
41 HandleWrapper* handleWrapper = HandleWrapper::Unwrap( isolate, args.This() );
42 return ImageActor::DownCast( handleWrapper->mHandle );
45 } //unnamed name space
53 * @param {Object} [image] Image object
54 * @param {Object} [pixelArea] Vector4
55 * @return {Object} ImageActor
57 * new DALI.imageActor( image, [10,23,35,56] );
59 Actor ImageActorApi::New( const v8::FunctionCallbackInfo<v8::Value>& args )
61 v8::Isolate* isolate = args.GetIsolate();
62 v8::HandleScope handleScope( isolate );
64 // Image actor has 3 different constructors
67 // New( image, PixelArea pixelArea);
69 if( args.Length() == 0 )
71 return ImageActor::New();
74 // args.Length> 0, must have an Image parameter
76 Image image = V8Utils::GetImageParameter( PARAMETER_0, found, isolate, args );
79 DALI_SCRIPT_EXCEPTION( isolate, "missing image from param 0" );
83 // check for PixelArea, accept a DALI Vector4 object ( which can be a JavaScript array)
84 // e.g. new DALI.imageActor( image, [10,23,35,56] );
85 // or new DALI.imageActor( image, Vector4 );
87 if( args.Length() > 1 )
89 Vector4 rect = V8Utils::GetVector4Parameter( PARAMETER_1, found, isolate, args );
92 DALI_SCRIPT_EXCEPTION( isolate, " bad parameters" );
95 Rect<int>rectangle( static_cast<int>(rect.x),
96 static_cast<int>(rect.y),
97 static_cast<int>(rect.z),
98 static_cast<int>(rect.w));
100 return ImageActor::New( image, rectangle );
104 return ImageActor::New( image );
109 * Set the image rendered by the actor.
111 * When the image is loaded the actor's size will be reset to the image size,
112 * unless a custom size was chosen, e.g. via actor.size or a pixel area
114 * Note: The old image will continue to be displayed until the given image has loaded.
117 * @param {Object} image The image to display.
120 void ImageActorApi::SetImage( const v8::FunctionCallbackInfo<v8::Value>& args )
122 v8::Isolate* isolate = args.GetIsolate();
123 v8::HandleScope handleScope( isolate );
126 Image image = V8Utils::GetImageParameter( PARAMETER_0, found, isolate, args );
129 DALI_SCRIPT_EXCEPTION( isolate, "bad parameters" );
132 ImageActor imageActor = GetImageActor( isolate, args );
133 imageActor.SetImage( image );
137 * brief Retrieve the image rendered by the actor's attachment.
140 * @return {Object} the image.
142 void ImageActorApi::GetImage( const v8::FunctionCallbackInfo<v8::Value>& args )
144 v8::Isolate* isolate = args.GetIsolate();
145 v8::HandleScope handleScope( isolate );
146 ImageActor imageActor = GetImageActor( isolate, args );
147 Image image = imageActor.GetImage();
150 v8::Local<v8::Object> localObject = ImageWrapper::WrapImage( isolate, image );
151 args.GetReturnValue().Set( localObject );
155 * Allows modification of an actors position in the depth sort algorithm.
157 * The offset can be altered for each coplanar actor hence allowing an order of painting.
158 * @param { Number } depthOffset the offset to be given to the actor. Positive values pushing it further back.
160 * @method setSortModifier
162 void ImageActorApi::SetSortModifier( const v8::FunctionCallbackInfo<v8::Value>& args )
164 v8::Isolate* isolate = args.GetIsolate();
165 v8::HandleScope handleScope( isolate );
166 ImageActor imageActor = GetImageActor( isolate, args );
169 float value = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 0.f );
172 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
175 imageActor.SetSortModifier( value );
179 * Retrieves the offset used to modify an actors position in the depth sort algorithm.
181 * @method getSortModifier .
182 * @return { Number} the offset that has been given to the actor. Positive values pushing it further back
184 void ImageActorApi::GetSortModifier( const v8::FunctionCallbackInfo<v8::Value>& args )
186 v8::Isolate* isolate = args.GetIsolate();
187 v8::HandleScope handleScope( isolate );
188 ImageActor imageActor = GetImageActor( isolate, args );
190 args.GetReturnValue().Set( v8::Number::New( isolate, imageActor.GetSortModifier() ) );
195 * Set the face-culling mode for this actor.
197 * @method setCullFace
198 * @param {Number} cullMode
200 * // cull mode should be one of the following constants
201 * dali.CULL_FACE_DISABLE // Face culling disabled
202 * dali.CULL_FRONT_FACE // Cull front facing polygons
203 * dali.CULL_BACK_FACE // Cull back facing polygons
204 * dali.CULL_FRONT_AND_BACK_FACE // Cull front and back facing polygons
205 * actor.SetCullFace( dali.CULL_FRONT_FACE );
207 void ImageActorApi::SetCullFace( const v8::FunctionCallbackInfo<v8::Value>& args )
209 v8::Isolate* isolate = args.GetIsolate();
210 v8::HandleScope handleScope( isolate );
211 ImageActor imageActor = GetImageActor( isolate, args );
214 int cullMode = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 );
217 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
221 imageActor.SetCullFace( static_cast<Dali::CullFaceMode>( cullMode ) );
226 * Retrieve the face-culling mode for this actor.
228 * @method getCullFace
229 * @return {Number} cullMode
231 * // cull mode is one of the following
232 * dali.CULL_FACE_DISABLE // Face culling disabled
233 * dali.CULL_FRONT_FACE // Cull front facing polygons
234 * dali.CULL_BACK_FACE // Cull back facing polygons
235 * dali.CULL_FRONT_AND_BACK_FACE // Cull front and back facing polygon
237 void ImageActorApi::GetCullFace( const v8::FunctionCallbackInfo<v8::Value>& args )
239 v8::Isolate* isolate = args.GetIsolate();
240 v8::HandleScope handleScope( isolate );
241 ImageActor imageActor = GetImageActor( isolate, args );
243 args.GetReturnValue().Set( v8::Integer::New( isolate, imageActor.GetCullFace() ) );
248 * Sets the blending mode.
250 * If blending is disabled (BLENDING_OFF) fade in and fade out animations do not work.
253 * // blend mode is one of the following
254 * dali.BLENDING_OFF // Blending is disabled.
255 * dali.BLENDING_AUTO // Blending is enabled if there is alpha channel.
256 * dali.BLENDING_ON // Blending is enabled.
257 * actor.SetBlendMode( dali.BLENDING_AUTO );
260 * @method setBlendMode
261 * @param { Number } blendMode
263 void ImageActorApi::SetBlendMode( const v8::FunctionCallbackInfo<v8::Value>& args )
265 v8::Isolate* isolate = args.GetIsolate();
266 v8::HandleScope handleScope( isolate );
267 ImageActor imageActor = GetImageActor( isolate, args );
270 int mode = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 );
273 DALI_SCRIPT_EXCEPTION( isolate, "invalid BlendMode parameter" );
276 imageActor.SetBlendMode( static_cast<Dali::BlendingMode::Type>( mode ) );
282 * @method getBlendMode
283 * @return { Number } blendMode
284 * @example returns one of the following:
286 * dali.BLENDING_OFF // Blending is disabled.
287 * dali.BLENDING_AUTO // Blending is enabled if there is alpha channel.
288 * dali.BLENDING_ON // Blending is enabled.
291 void ImageActorApi::GetBlendMode( const v8::FunctionCallbackInfo<v8::Value>& args )
293 v8::Isolate* isolate = args.GetIsolate();
294 v8::HandleScope handleScope( isolate );
295 ImageActor imageActor = GetImageActor( isolate, args );
297 args.GetReturnValue().Set( v8::Integer::New( isolate, imageActor.GetBlendMode() ) );
303 * @method setBlendFunc
304 * @param {Number} SourceBlending RGB
305 * @param {Number} DestinationBlending RGB
306 * @param {Number} SourceBlending Alpha
307 * @param {Number} DestinatinoBlending Alpha
309 * //blending constants
310 dali.BLEND_FACTOR_ZERO
311 dali.BLEND_FACTOR_ONE
312 dali.BLEND_FACTOR_SRC_COLOR
313 dali.BLEND_FACTOR_ONE_MINUS_SRC_COLOR
314 dali.BLEND_FACTOR_SRC_ALPHA
315 dali.BLEND_FACTOR_ONE_MINUS_SRC_ALPHA
316 dali.BLEND_FACTOR_DST_ALPHA
317 dali.BLEND_FACTOR_ONE_MINUS_DST_ALPHA
318 dali.BLEND_FACTOR_DST_COLOR
319 dali.BLEND_FACTOR_ONE_MINUS_DST_COLOR
320 dali.BLEND_FACTOR_SRC_ALPHA_SATURATE
321 dali.BLEND_FACTOR_CONSTANT_COLOR
322 dali.BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR
323 dali.BLEND_FACTOR_CONSTANT_ALPHA
324 dali.BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA
326 actor.setBlendFunc( dali.BLEND_FACTOR_CONSTANT_COLOR, BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR,
327 dali.BLEND_FACTOR_CONSTANT_ALPHA, BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA);
331 void ImageActorApi::SetBlendFunc( const v8::FunctionCallbackInfo< v8::Value >& args )
333 v8::Isolate* isolate = args.GetIsolate();
334 v8::HandleScope handleScope( isolate );
335 ImageActor imageActor = GetImageActor( isolate, args );
338 bool foundAllParams(false);
339 V8Utils::ReadIntegerArguments( foundAllParams, ¶ms[0], 4, args,0 );
342 imageActor.SetBlendFunc( static_cast< Dali::BlendingFactor::Type>(params[0]),
343 static_cast< Dali::BlendingFactor::Type>(params[1]),
344 static_cast< Dali::BlendingFactor::Type>(params[2]),
345 static_cast< Dali::BlendingFactor::Type>(params[3]));
349 DALI_SCRIPT_EXCEPTION( isolate, "invalid BlendMode parameter");
356 * @method GetBlendFunc
357 * @return {Object} BlendProperties
358 * @example Blend properties object has 4 fields
360 * blendProperties.sourceRgb // source rgb enum
361 * blendProperties.destinationRgb // destination rgb enum
362 * blendProperties.sourceAlpha source // alpha enum
363 * blendProperties.destinationAlpha // destination alpha enum
365 void ImageActorApi::GetBlendFunc( const v8::FunctionCallbackInfo< v8::Value >& args )
367 // @todo pass by reference doesn't work in Javascript so need to decide what to return
368 // for now just return a vector 4...
370 BlendingFactor::Type srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha;
371 v8::Isolate* isolate = args.GetIsolate();
372 v8::HandleScope handleScope( isolate );
373 ImageActor imageActor = GetImageActor( isolate, args );
375 imageActor.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
377 v8::Local<v8::Object> blendInfo = v8::Object::New( isolate );
379 blendInfo->Set( v8::String::NewFromUtf8( isolate, "sourceRgb" ), v8::Integer::New( isolate, srcFactorRgb) );
380 blendInfo->Set( v8::String::NewFromUtf8( isolate, "destinationRgb" ), v8::Integer::New( isolate, destFactorRgb ) );
381 blendInfo->Set( v8::String::NewFromUtf8( isolate, "sourceAlpha" ), v8::Integer::New( isolate, srcFactorAlpha ) );
382 blendInfo->Set( v8::String::NewFromUtf8( isolate, "destinationAlpha" ), v8::Integer::New( isolate, destFactorAlpha ) );
384 args.GetReturnValue().Set( blendInfo );
390 * @method getShaderEffect
391 * @return {Object} ShaderEffect object
393 * Retrieve the shader effect for the Actor.
396 * var shaderEffect = actor.getShaderEffect();
399 void ImageActorApi::GetShaderEffect( const v8::FunctionCallbackInfo<v8::Value>& args )
401 v8::Isolate* isolate = args.GetIsolate();
402 v8::HandleScope handleScope( isolate );
403 ImageActor imageActor = GetImageActor( isolate, args );
405 v8::Local < v8::Object > object = ShaderEffectWrapper::WrapShaderEffect( isolate, imageActor.GetShaderEffect() );
406 args.GetReturnValue().Set( object );
412 * @method setShaderEffect
413 * @param {Object} shaderEffect The shader effect.
415 * Sets the shader effect for the Actor.
417 * Shader effects provide special effects like rippling and bending.
418 * Setting a shader effect removes any shader effect previously set by SetShaderEffect.
420 * // first create the shaderOptions, then the shaderEffect
421 * var shader = new dali.ShaderEffect( shaderOptions );
422 * actor.setShaderEffect( shader );
425 void ImageActorApi::SetShaderEffect( const v8::FunctionCallbackInfo<v8::Value>& args )
427 v8::Isolate* isolate = args.GetIsolate();
428 v8::HandleScope handleScope( isolate );
429 ImageActor imageActor = GetImageActor( isolate, args );
432 ShaderEffect effect = ShaderEffectApi::GetShaderEffectFromParams( 0, found, isolate, args );
435 imageActor.SetShaderEffect( effect );
439 DALI_SCRIPT_EXCEPTION( isolate, "shader effect parameter missing" );
445 * Removes the current shader effect
448 * actor.removeShaderEffect();
451 * @method removeShaderEffect
453 void ImageActorApi::RemoveShaderEffect( const v8::FunctionCallbackInfo<v8::Value>& args )
455 v8::Isolate* isolate = args.GetIsolate();
456 v8::HandleScope handleScope( isolate );
457 ImageActor imageActor = GetImageActor( isolate, args );
458 imageActor.RemoveShaderEffect();
461 } // namespace V8Plugin