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>
35 namespace //unnamed name space
38 ImageActor GetImageActor( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
40 HandleWrapper* handleWrapper = HandleWrapper::Unwrap( isolate, args.This() );
41 return ImageActor::DownCast( handleWrapper->mHandle );
44 } //unnamed name space
52 * @param {Object} [image] Image object
53 * @param {Object} [pixelArea] Vector4
54 * @return {Object} ImageActor
56 * new DALI.imageActor( image, [10,23,35,56] );
58 Actor ImageActorApi::New( const v8::FunctionCallbackInfo<v8::Value>& args )
60 v8::Isolate* isolate = args.GetIsolate();
61 v8::HandleScope handleScope( isolate );
63 // Image actor has 3 different constructors
66 // New( image, PixelArea pixelArea);
68 if( args.Length() == 0 )
70 return ImageActor::New();
73 // args.Length> 0, must have an Image parameter
75 Image image = V8Utils::GetImageParameter( PARAMETER_0, found, isolate, args );
78 DALI_SCRIPT_EXCEPTION( isolate, "missing image from param 0" );
82 // check for PixelArea, accept a DALI Vector4 object ( which can be a JavaScript array)
83 // e.g. new DALI.imageActor( image, [10,23,35,56] );
84 // or new DALI.imageActor( image, Vector4 );
86 if( args.Length() > 1 )
88 Vector4 rect = V8Utils::GetVector4Parameter( PARAMETER_1, found, isolate, args );
91 DALI_SCRIPT_EXCEPTION( isolate, " bad parameters" );
94 Rect<int>rectangle( static_cast<int>(rect.x),
95 static_cast<int>(rect.y),
96 static_cast<int>(rect.z),
97 static_cast<int>(rect.w));
99 return ImageActor::New( image, rectangle );
103 return ImageActor::New( image );
108 * Set the image rendered by the actor.
110 * When the image is loaded the actor's size will be reset to the image size,
111 * unless a custom size was chosen, e.g. via actor.size or a pixel area
113 * Note: The old image will continue to be displayed until the given image has loaded.
116 * @param {Object} image The image to display.
119 void ImageActorApi::SetImage( const v8::FunctionCallbackInfo<v8::Value>& args )
121 v8::Isolate* isolate = args.GetIsolate();
122 v8::HandleScope handleScope( isolate );
125 Image image = V8Utils::GetImageParameter( PARAMETER_0, found, isolate, args );
128 DALI_SCRIPT_EXCEPTION( isolate, "bad parameters" );
131 ImageActor imageActor = GetImageActor( isolate, args );
132 imageActor.SetImage( image );
136 * brief Retrieve the image rendered by the actor's attachment.
139 * @return {Object} the image.
141 void ImageActorApi::GetImage( const v8::FunctionCallbackInfo<v8::Value>& args )
143 v8::Isolate* isolate = args.GetIsolate();
144 v8::HandleScope handleScope( isolate );
145 ImageActor imageActor = GetImageActor( isolate, args );
146 Image image = imageActor.GetImage();
149 v8::Local<v8::Object> localObject = ImageWrapper::WrapImage( isolate, image );
150 args.GetReturnValue().Set( localObject );
154 * Query whether a pixel area has been set.
156 * @method isPixelAreaSet
157 * @return {Boolean} True if a pixel area has been set.
159 void ImageActorApi::IsPixelAreaSet( const v8::FunctionCallbackInfo<v8::Value>& args )
161 v8::Isolate* isolate = args.GetIsolate();
162 v8::HandleScope handleScope( isolate );
163 ImageActor imageActor = GetImageActor( isolate, args );
165 args.GetReturnValue().Set( v8::Boolean::New( isolate, imageActor.IsPixelAreaSet() ) );
169 * Remove any pixel areas specified with SetPixelArea; the entire image will be displayed.
171 * The actor size will change to that of the Image unless a custom size was set, e.g. via
174 * @method clearPixelArea
176 void ImageActorApi::ClearPixelArea( const v8::FunctionCallbackInfo<v8::Value>& args )
178 v8::Isolate* isolate = args.GetIsolate();
179 v8::HandleScope handleScope( isolate );
180 ImageActor imageActor = GetImageActor( isolate, args );
182 imageActor.ClearPixelArea();
187 } // namespace V8Plugin