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 * Sets the blending mode.
197 * If blending is disabled (BLENDING_OFF) fade in and fade out animations do not work.
200 * // blend mode is one of the following
201 * dali.BLENDING_OFF // Blending is disabled.
202 * dali.BLENDING_AUTO // Blending is enabled if there is alpha channel.
203 * dali.BLENDING_ON // Blending is enabled.
204 * actor.SetBlendMode( dali.BLENDING_AUTO );
207 * @method setBlendMode
208 * @param { Number } blendMode
210 void ImageActorApi::SetBlendMode( const v8::FunctionCallbackInfo<v8::Value>& args )
212 v8::Isolate* isolate = args.GetIsolate();
213 v8::HandleScope handleScope( isolate );
214 ImageActor imageActor = GetImageActor( isolate, args );
217 int mode = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 );
220 DALI_SCRIPT_EXCEPTION( isolate, "invalid BlendMode parameter" );
223 imageActor.SetBlendMode( static_cast<Dali::BlendingMode::Type>( mode ) );
229 * @method getBlendMode
230 * @return { Number } blendMode
231 * @example returns one of the following:
233 * dali.BLENDING_OFF // Blending is disabled.
234 * dali.BLENDING_AUTO // Blending is enabled if there is alpha channel.
235 * dali.BLENDING_ON // Blending is enabled.
238 void ImageActorApi::GetBlendMode( const v8::FunctionCallbackInfo<v8::Value>& args )
240 v8::Isolate* isolate = args.GetIsolate();
241 v8::HandleScope handleScope( isolate );
242 ImageActor imageActor = GetImageActor( isolate, args );
244 args.GetReturnValue().Set( v8::Integer::New( isolate, imageActor.GetBlendMode() ) );
250 * @method setBlendFunc
251 * @param {Number} SourceBlending RGB
252 * @param {Number} DestinationBlending RGB
253 * @param {Number} SourceBlending Alpha
254 * @param {Number} DestinatinoBlending Alpha
256 * //blending constants
257 dali.BLEND_FACTOR_ZERO
258 dali.BLEND_FACTOR_ONE
259 dali.BLEND_FACTOR_SRC_COLOR
260 dali.BLEND_FACTOR_ONE_MINUS_SRC_COLOR
261 dali.BLEND_FACTOR_SRC_ALPHA
262 dali.BLEND_FACTOR_ONE_MINUS_SRC_ALPHA
263 dali.BLEND_FACTOR_DST_ALPHA
264 dali.BLEND_FACTOR_ONE_MINUS_DST_ALPHA
265 dali.BLEND_FACTOR_DST_COLOR
266 dali.BLEND_FACTOR_ONE_MINUS_DST_COLOR
267 dali.BLEND_FACTOR_SRC_ALPHA_SATURATE
268 dali.BLEND_FACTOR_CONSTANT_COLOR
269 dali.BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR
270 dali.BLEND_FACTOR_CONSTANT_ALPHA
271 dali.BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA
273 actor.setBlendFunc( dali.BLEND_FACTOR_CONSTANT_COLOR, BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR,
274 dali.BLEND_FACTOR_CONSTANT_ALPHA, BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA);
278 void ImageActorApi::SetBlendFunc( const v8::FunctionCallbackInfo< v8::Value >& args )
280 v8::Isolate* isolate = args.GetIsolate();
281 v8::HandleScope handleScope( isolate );
282 ImageActor imageActor = GetImageActor( isolate, args );
285 bool foundAllParams(false);
286 V8Utils::ReadIntegerArguments( foundAllParams, ¶ms[0], 4, args,0 );
289 imageActor.SetBlendFunc( static_cast< Dali::BlendingFactor::Type>(params[0]),
290 static_cast< Dali::BlendingFactor::Type>(params[1]),
291 static_cast< Dali::BlendingFactor::Type>(params[2]),
292 static_cast< Dali::BlendingFactor::Type>(params[3]));
296 DALI_SCRIPT_EXCEPTION( isolate, "invalid BlendMode parameter");
303 * @method GetBlendFunc
304 * @return {Object} BlendProperties
305 * @example Blend properties object has 4 fields
307 * blendProperties.sourceRgb // source rgb enum
308 * blendProperties.destinationRgb // destination rgb enum
309 * blendProperties.sourceAlpha source // alpha enum
310 * blendProperties.destinationAlpha // destination alpha enum
312 void ImageActorApi::GetBlendFunc( const v8::FunctionCallbackInfo< v8::Value >& args )
314 // @todo pass by reference doesn't work in Javascript so need to decide what to return
315 // for now just return a vector 4...
317 BlendingFactor::Type srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha;
318 v8::Isolate* isolate = args.GetIsolate();
319 v8::HandleScope handleScope( isolate );
320 ImageActor imageActor = GetImageActor( isolate, args );
322 imageActor.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
324 v8::Local<v8::Object> blendInfo = v8::Object::New( isolate );
326 blendInfo->Set( v8::String::NewFromUtf8( isolate, "sourceRgb" ), v8::Integer::New( isolate, srcFactorRgb) );
327 blendInfo->Set( v8::String::NewFromUtf8( isolate, "destinationRgb" ), v8::Integer::New( isolate, destFactorRgb ) );
328 blendInfo->Set( v8::String::NewFromUtf8( isolate, "sourceAlpha" ), v8::Integer::New( isolate, srcFactorAlpha ) );
329 blendInfo->Set( v8::String::NewFromUtf8( isolate, "destinationAlpha" ), v8::Integer::New( isolate, destFactorAlpha ) );
331 args.GetReturnValue().Set( blendInfo );
337 * @method getShaderEffect
338 * @return {Object} ShaderEffect object
340 * Retrieve the shader effect for the Actor.
343 * var shaderEffect = actor.getShaderEffect();
346 void ImageActorApi::GetShaderEffect( const v8::FunctionCallbackInfo<v8::Value>& args )
348 v8::Isolate* isolate = args.GetIsolate();
349 v8::HandleScope handleScope( isolate );
350 ImageActor imageActor = GetImageActor( isolate, args );
352 v8::Local < v8::Object > object = ShaderEffectWrapper::WrapShaderEffect( isolate, imageActor.GetShaderEffect() );
353 args.GetReturnValue().Set( object );
359 * @method setShaderEffect
360 * @param {Object} shaderEffect The shader effect.
362 * Sets the shader effect for the Actor.
364 * Shader effects provide special effects like rippling and bending.
365 * Setting a shader effect removes any shader effect previously set by SetShaderEffect.
367 * // first create the shaderOptions, then the shaderEffect
368 * var shader = new dali.ShaderEffect( shaderOptions );
369 * actor.setShaderEffect( shader );
372 void ImageActorApi::SetShaderEffect( const v8::FunctionCallbackInfo<v8::Value>& args )
374 v8::Isolate* isolate = args.GetIsolate();
375 v8::HandleScope handleScope( isolate );
376 ImageActor imageActor = GetImageActor( isolate, args );
379 ShaderEffect effect = ShaderEffectApi::GetShaderEffectFromParams( 0, found, isolate, args );
382 imageActor.SetShaderEffect( effect );
386 DALI_SCRIPT_EXCEPTION( isolate, "shader effect parameter missing" );
392 * Removes the current shader effect
395 * actor.removeShaderEffect();
398 * @method removeShaderEffect
400 void ImageActorApi::RemoveShaderEffect( const v8::FunctionCallbackInfo<v8::Value>& args )
402 v8::Isolate* isolate = args.GetIsolate();
403 v8::HandleScope handleScope( isolate );
404 ImageActor imageActor = GetImageActor( isolate, args );
405 imageActor.RemoveShaderEffect();
408 } // namespace V8Plugin