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-attributes-api.h"
23 #include <image/image-attributes-wrapper.h>
24 #include <object/property-value-wrapper.h>
25 #include <shared/base-wrapped-object.h>
33 ImageAttributes ImageAttributesApi::GetImageAttributesFromObject( v8::Isolate* isolate, v8::Local<v8::Object> object )
35 v8::HandleScope handleScope( isolate);
37 if( BaseWrappedObject::IsWrappedType ( isolate, object, BaseWrappedObject::IMAGE_ATTRIBUTES ))
39 v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField(0) );
40 void* ptr = field->Value();
41 BaseWrappedObject* wrappedObject = static_cast< BaseWrappedObject *>(ptr);
42 ImageAttributesWrapper* wrapper = static_cast< ImageAttributesWrapper*>( wrappedObject );;
43 return wrapper->GetImageAttributes();
47 DALI_SCRIPT_EXCEPTION( isolate, "bad image attributes url");
48 return ImageAttributes();
53 /***************************************
54 * IMAGE ATTRIBUTES FUNCTIONS
56 ****************************************/
57 ImageAttributes ImageAttributesApi::New( const v8::FunctionCallbackInfo< v8::Value >& args )
59 v8::Isolate* isolate = args.GetIsolate();
60 // two combinations of constructor
63 bool foundParams( false );
66 V8Utils::ReadIntegerArguments( foundParams, ¶ms[0],2,args,0);
69 if( args.Length() != 0 )
71 DALI_SCRIPT_EXCEPTION( isolate, " ImageAttributes::New invalid params");
72 return Dali::ImageAttributes();
74 return Dali::ImageAttributes::New();
78 return Dali::ImageAttributes::New( params[0], params[1] );
83 ImageAttributes& ImageAttributesApi::GetImageAttributes( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
85 v8::Local<v8::Object> object = args.This();
86 v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField(0) );
87 void* ptr = field->Value();
89 ImageAttributesWrapper* wrapper = static_cast< ImageAttributesWrapper *>(ptr);
90 return wrapper->GetImageAttributes();
93 void ImageAttributesApi::SetSize( const v8::FunctionCallbackInfo< v8::Value >& args )
95 v8::Isolate* isolate = args.GetIsolate();
96 v8::HandleScope handleScope( isolate );
97 ImageAttributes& attribs( GetImageAttributes( isolate, args ));
100 Vector2 size = V8Utils::GetVector2Parameter( PARAMETER_0, found, isolate, args );
103 DALI_SCRIPT_EXCEPTION( isolate, "invalid size parameter" );
108 attribs.SetSize( size );
112 void ImageAttributesApi::SetScalingMode( const v8::FunctionCallbackInfo< v8::Value >& args )
114 v8::Isolate* isolate = args.GetIsolate();
115 v8::HandleScope handleScope( isolate );
116 ImageAttributes& attribs( GetImageAttributes( isolate, args ));
119 int value = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0);
122 DALI_SCRIPT_EXCEPTION( isolate, "invalid scaling mode parameter");
125 if( value!= ImageAttributes::ShrinkToFit ||
126 value!= ImageAttributes::ScaleToFill ||
127 value!= ImageAttributes::FitWidth ||
128 value!= ImageAttributes::FitHeight )
130 DALI_SCRIPT_EXCEPTION( isolate, "invalid scaling mode parameter");
134 attribs.SetScalingMode(static_cast<ImageAttributes::ScalingMode >( value) );
137 void ImageAttributesApi::SetOrientationCorrection( const v8::FunctionCallbackInfo< v8::Value >& args )
139 v8::Isolate* isolate = args.GetIsolate();
140 v8::HandleScope handleScope( isolate );
141 ImageAttributes& attribs( GetImageAttributes( isolate, args ));
143 bool parameterFound(false);
144 bool value = V8Utils::GetBooleanParameter( PARAMETER_0 , parameterFound, isolate, args );
146 if( !parameterFound )
148 DALI_SCRIPT_EXCEPTION( isolate, "boolean parameter not found");
151 attribs.SetOrientationCorrection( value );
154 void ImageAttributesApi::GetWidth( const v8::FunctionCallbackInfo< v8::Value >& args )
156 v8::Isolate* isolate = args.GetIsolate();
157 v8::HandleScope handleScope( isolate );
158 ImageAttributes& attribs( GetImageAttributes( isolate, args ));
160 args.GetReturnValue().Set( v8::Integer::New( isolate, attribs.GetWidth() ) );
163 void ImageAttributesApi::GetHeight( const v8::FunctionCallbackInfo< v8::Value >& args )
165 v8::Isolate* isolate = args.GetIsolate();
166 v8::HandleScope handleScope( isolate );
167 ImageAttributes& attribs( GetImageAttributes( isolate, args ));
169 args.GetReturnValue().Set( v8::Integer::New( isolate, attribs.GetHeight() ) );
173 void ImageAttributesApi::GetSize( const v8::FunctionCallbackInfo< v8::Value >& args )
175 v8::Isolate* isolate = args.GetIsolate();
176 v8::HandleScope handleScope( isolate );
177 ImageAttributes& attribs( GetImageAttributes( isolate, args ));
179 Vector2 vec( attribs.GetSize() );
180 Dali::Property::Value value( vec );
182 v8::Local <v8::Object> object = PropertyValueWrapper::WrapDaliProperty( isolate, value);
183 args.GetReturnValue().Set( object );
186 void ImageAttributesApi::GetScalingMode( const v8::FunctionCallbackInfo< v8::Value >& args )
188 v8::Isolate* isolate = args.GetIsolate();
189 v8::HandleScope handleScope( isolate );
190 ImageAttributes& attribs( GetImageAttributes( isolate, args ));
192 args.GetReturnValue().Set( v8::Integer::New( isolate, attribs.GetScalingMode() ) );
196 void ImageAttributesApi::GetOrientationCorrection( const v8::FunctionCallbackInfo< v8::Value >& args )
198 v8::Isolate* isolate = args.GetIsolate();
199 v8::HandleScope handleScope( isolate );
200 ImageAttributes& attribs( GetImageAttributes( isolate, args ));
202 args.GetReturnValue().Set( v8::Boolean::New( isolate, attribs.GetOrientationCorrection() ) );
207 } // namespace V8Plugin