// EXTERNAL INCLUDES
#include <dali/integration-api/debug.h>
+#include <dali/public-api/object/property-array.h>
// INTERNAL INCLUDES
#include <v8-utils.h>
{
T tmp = value.Get<T>();
tmp.y = v;
- value = tmp ;
+ value = tmp;
}
template <typename T, typename S>
{
T tmp = value.Get<T>();
tmp.z = v;
- value = tmp ;
+ value = tmp;
}
template <typename T, typename S>
{
T tmp = value.Get<T>();
tmp.w = v;
- value = tmp ;
+ value = tmp;
}
template <typename T, typename S>
void SetWidth( Dali::Property::Value &value, S& v)
{
T tmp = value.Get<T>();
tmp.width = v;
- value = tmp ;
+ value = tmp;
}
template <typename T, typename S>
{
T tmp = value.Get<T>();
tmp.height = v;
- value = tmp ;
+ value = tmp;
}
v8::Handle< v8::Value > GetV8ValueFrom( v8::Isolate* isolate,
if( field == "x" || field == "width" )
{
- Dali::Vector2 v2 = value.Get<Dali::Vector2>() ;
- ret = v8::Number::New( isolate, v2.x) ;
+ Dali::Vector2 v2 = value.Get<Dali::Vector2>();
+ ret = v8::Number::New( isolate, v2.x);
}
else if(field == "y" || field == "height")
{
- Dali::Vector2 v2 = value.Get<Dali::Vector2>() ;
- ret = v8::Number::New( isolate, v2.y) ;
+ Dali::Vector2 v2 = value.Get<Dali::Vector2>();
+ ret = v8::Number::New( isolate, v2.y);
}
break;
if(field == "x" || field == "width" || field == "r")
{
- Dali::Vector3 v3 = value.Get<Dali::Vector3>() ;
- ret = v8::Number::New( isolate, v3.x) ;
+ Dali::Vector3 v3 = value.Get<Dali::Vector3>();
+ ret = v8::Number::New( isolate, v3.x);
}
else if(field == "y" || field == "height" || field == "g")
{
- Dali::Vector3 v3 = value.Get<Dali::Vector3>() ;
- ret = v8::Number::New( isolate, v3.y) ;
+ Dali::Vector3 v3 = value.Get<Dali::Vector3>();
+ ret = v8::Number::New( isolate, v3.y);
}
else if(field == "z" || field == "depth" || field == "b")
{
- Dali::Vector3 v3 = value.Get<Dali::Vector3>() ;
- ret = v8::Number::New( isolate, v3.z) ;
+ Dali::Vector3 v3 = value.Get<Dali::Vector3>();
+ ret = v8::Number::New( isolate, v3.z);
}
break;
}
if(field == "x" || field == "s" || field == "r")
{
- Dali::Vector4 v4 = value.Get<Dali::Vector4>() ;
- ret = v8::Number::New( isolate, v4.x) ;
+ Dali::Vector4 v4 = value.Get<Dali::Vector4>();
+ ret = v8::Number::New( isolate, v4.x);
}
else if(field == "y" || field == "g" || field == "t")
{
- Dali::Vector4 v4 = value.Get<Dali::Vector4>() ;
- ret = v8::Number::New( isolate, v4.y) ;
+ Dali::Vector4 v4 = value.Get<Dali::Vector4>();
+ ret = v8::Number::New( isolate, v4.y);
}
else if(field == "z" || field == "r" || field == "b")
{
- Dali::Vector4 v4 = value.Get<Dali::Vector4>() ;
- ret = v8::Number::New( isolate, v4.z) ;
+ Dali::Vector4 v4 = value.Get<Dali::Vector4>();
+ ret = v8::Number::New( isolate, v4.z);
}
else if(field == "w" || field == "a" || field == "q")
{
- Dali::Vector4 v4 = value.Get<Dali::Vector4>() ;
- ret = v8::Number::New( isolate, v4.w) ;
+ Dali::Vector4 v4 = value.Get<Dali::Vector4>();
+ ret = v8::Number::New( isolate, v4.w);
}
break;
if(field == "roll")
{
Dali::Vector4 v4 = value.Get<Dali::Quaternion>().EulerAngles();
- ret = v8::Number::New( isolate, v4.z) ;
+ ret = v8::Number::New( isolate, v4.z);
}
else if(field == "pitch")
{
Dali::Vector4 v4 = value.Get<Dali::Quaternion>().EulerAngles();
- ret = v8::Number::New( isolate, v4.x) ;
+ ret = v8::Number::New( isolate, v4.x);
}
else if(field == "yaw")
{
Dali::Vector4 v4 = value.Get<Dali::Quaternion>().EulerAngles();
- ret = v8::Number::New( isolate, v4.y) ;
+ ret = v8::Number::New( isolate, v4.y);
}
else if(field == "axis")
if(field == "x")
{
- Dali::Rect<int> r = value.Get<Dali::Rect<int> >() ;
- ret = v8::Number::New( isolate, r.x) ;
+ Dali::Rect<int> r = value.Get<Dali::Rect<int> >();
+ ret = v8::Number::New( isolate, r.x);
}
else if(field == "y")
{
- Dali::Rect<int> r = value.Get<Dali::Rect<int> >() ;
- ret = v8::Number::New( isolate, r.y) ;
+ Dali::Rect<int> r = value.Get<Dali::Rect<int> >();
+ ret = v8::Number::New( isolate, r.y);
}
else if(field == "width")
{
- Dali::Rect<int> r = value.Get<Dali::Rect<int> >() ;
- ret = v8::Number::New( isolate, r.width) ;
+ Dali::Rect<int> r = value.Get<Dali::Rect<int> >();
+ ret = v8::Number::New( isolate, r.width);
}
else if(field == "height")
{
- Dali::Rect<int> r = value.Get<Dali::Rect<int> >() ;
- ret = v8::Number::New( isolate, r.height) ;
+ Dali::Rect<int> r = value.Get<Dali::Rect<int> >();
+ ret = v8::Number::New( isolate, r.height);
}
break;
}
{
if(field == "x" || field == "width")
{
- SetX<Dali::Vector2>(value, asFloat) ;
+ SetX<Dali::Vector2>(value, asFloat);
}
else if(field == "y" || field == "height")
{
- SetY<Dali::Vector2>(value, asFloat) ;
+ SetY<Dali::Vector2>(value, asFloat);
}
else
{
{
if(field == "x" || field == "width" || field == "r")
{
- SetX<Dali::Vector3>(value, asFloat) ;
+ SetX<Dali::Vector3>(value, asFloat);
}
else if(field == "y" || field == "height" || field == "g")
{
- SetY<Dali::Vector3>(value, asFloat) ;
+ SetY<Dali::Vector3>(value, asFloat);
}
else if(field == "z" || field == "depth" || field == "b")
{
- SetZ<Dali::Vector3>(value, asFloat) ;
+ SetZ<Dali::Vector3>(value, asFloat);
}
else
{
{
if(field == "x" || field == "s" || field == "r")
{
- SetX<Dali::Vector4>(value, asFloat) ;
+ SetX<Dali::Vector4>(value, asFloat);
}
else if(field == "y" || field == "g" || field == "t")
{
- SetY<Dali::Vector4>(value, asFloat) ;
+ SetY<Dali::Vector4>(value, asFloat);
}
else if(field == "z" || field == "r" || field == "b")
{
- SetZ<Dali::Vector4>(value, asFloat) ;
+ SetZ<Dali::Vector4>(value, asFloat);
}
else if(field == "w" || field == "a" || field == "q")
{
- SetW<Dali::Vector4>(value, asFloat) ;
+ SetW<Dali::Vector4>(value, asFloat);
}
else
{
{
if(field == "x")
{
- SetX<Dali::Rect<int> >(value, asInt) ;
+ SetX<Dali::Rect<int> >(value, asInt);
}
else if(field == "y")
{
- SetY<Dali::Rect<int> >(value, asInt) ;
+ SetY<Dali::Rect<int> >(value, asInt);
}
else if(field == "width")
{
- SetWidth<Dali::Rect<int> >(value, asInt) ;
+ SetWidth<Dali::Rect<int> >(value, asInt);
}
else if(field == "height")
{
{
case Dali::Property::BOOLEAN:
case Dali::Property::INTEGER:
- case Dali::Property::UNSIGNED_INTEGER:
case Dali::Property::STRING:
case Dali::Property::FLOAT:
{
{
v8::EscapableHandleScope handleScope( isolate );
- v8::Local<v8::Value> v8Value ;
+ v8::Local<v8::Value> v8Value;
switch( value.GetType() )
{
v8Value = v8::Integer::New( isolate, value.Get<int>());
break;
}
- case Dali::Property::UNSIGNED_INTEGER:
- {
- v8Value = v8::Integer::New( isolate, value.Get<unsigned int>());
- break;
- }
case Dali::Property::STRING:
{
std::string string = value.Get< std::string >();
break;
}
}
- v8::Local<v8::Object> ret = v8Value->ToObject();
- return handleScope.Escape( ret );
+ v8::Local<v8::Object> ret;
+
+ if( v8Value->IsObject() )
+ {
+ ret = v8Value->ToObject();
+ }
+
+ return handleScope.Escape( ret );
}
}
if(16 == len )
{
- ret = Dali::Matrix( out[0] );
+ ret = Dali::Matrix( out );
}
else if ( 9 == len )
{
//Cast v8::Value to v8::Array
v8::Local<v8::Array> v8Array = v8::Local<v8::Array>::Cast( v8Value );
uint32_t elementCount = v8Array->Length();
- Dali::Property::Array data( elementCount );
+ Dali::Property::Array data;
+ data.Reserve( elementCount );
bool bFound(false);
for( uint32_t i(0); i<elementCount; ++i )
{
//Get Property::Value for each element in the array
- data[i] = V8Utils::GetPropertyValueFromObject( bFound, isolate, v8Array->Get(i) );
+ data.PushBack( V8Utils::GetPropertyValueFromObject( bFound, isolate, v8Array->Get(i) ) );
}
//return the Property::Value
{
daliPropertyValue = Dali::Property::Value( v8Value->Int32Value() ) ;//static_cast<int>( V8Utils::GetNumberValue( isolate, v8Value) ));
}
- break;
- }
- case Dali::Property::UNSIGNED_INTEGER:
- {
- if( v8Value->IsUint32() )
+ else if( V8Utils::IsStringPrimitiveOrObject( v8Value) ) // Take string as value for properties that internally convert the string to an enum
{
- daliPropertyValue = Dali::Property::Value( v8Value->Uint32Value() );//static_cast<unsigned int>( V8Utils::GetNumberValue( isolate, v8Value) ));
+ daliPropertyValue = Dali::Property::Value( V8Utils::GetStringValue( isolate, v8Value) );
}
break;
}
}
break;
}
+ case Dali::Property::RECTANGLE:
+ {
+ if( array.GetType() == Dali::Property::VECTOR4)
+ {
+ Vector4 vec4( array.Get<Vector4>());
+ daliPropertyValue = Property::Value(Rect<int>( vec4.x,vec4.y, vec4.z, vec4.w ));
+ }
+ break;
+ }
case Dali::Property::ROTATION:
{
if( array.GetType() == Dali::Property::VECTOR4)
daliPropertyValue = ArrayFromV8Array( isolate, v8Value );
break;
}
+ case Dali::Property::MAP:
+ {
+ if( v8Value->IsObject() )
+ {
+ v8::Local<v8::Object> object = v8::Handle<v8::Object>::Cast(v8Value);
+ Dali::Property::Map propertyMap = V8Utils::GetPropertyMapFromObject(isolate, object);
+ daliPropertyValue = Dali::Property::Value( propertyMap );
+ }
+ else if( V8Utils::IsStringPrimitiveOrObject( v8Value) )
+ {
+ // There are special cases where a property with property map type can accept a string value,
+ // so we do the additional check here.
+ daliPropertyValue = Dali::Property::Value( V8Utils::GetStringValue( isolate, v8Value) );
+ }
+
+ break;
+ }
case Dali::Property::NONE:
- case Dali::Property::TYPE_COUNT:
default:
{
break;
}
- } // switch type
+ } // switch type
+
+ return daliPropertyValue;
+}
+
+Dali::Property::Value PropertyValueWrapper::ExtractPropertyValue( v8::Isolate* isolate, v8::Local< v8::Value> v8Value)
+{
+ v8::HandleScope handleScope( isolate);
+
+ Dali::Property::Value daliPropertyValue;
+
+ // Check if it's a javascript Array
+ Dali::Property::Value array = VectorOrMatrixFromV8Array( isolate, v8Value );
+
+ if( V8Utils::IsBooleanPrimitiveOrObject( v8Value ) )
+ {
+ daliPropertyValue = Dali::Property::Value( V8Utils::GetBooleanValue( isolate, v8Value));
+ }
+ else if( V8Utils::IsNumberPrimitiveOrObject( v8Value ) )
+ {
+ daliPropertyValue = Dali::Property::Value( V8Utils::GetNumberValue( isolate, v8Value) );
+ }
+ else if( v8Value->IsInt32() )
+ {
+ daliPropertyValue = Dali::Property::Value( v8Value->Int32Value() ) ;
+ }
+ else if( V8Utils::IsStringPrimitiveOrObject( v8Value) )
+ {
+ daliPropertyValue = Dali::Property::Value( V8Utils::GetStringValue( isolate, v8Value) );
+ }
+ else if( array.GetType() == Dali::Property::VECTOR2
+ || array.GetType() == Dali::Property::VECTOR3
+ || array.GetType() == Dali::Property::VECTOR4 )
+ {
+ daliPropertyValue = array;
+ }
+ else if( array.GetType() == Dali::Property::MATRIX )
+ {
+ Dali::Matrix mat = array.Get<Dali::Matrix>();
+ daliPropertyValue = mat;
+ }
+ else if( array.GetType() == Dali::Property::MATRIX3 )
+ {
+ Dali::Matrix3 mat = array.Get<Dali::Matrix3>();
+ daliPropertyValue = mat;
+ }
+ else if( array.GetType() == Dali::Property::ARRAY )
+ {
+ daliPropertyValue = ArrayFromV8Array( isolate, v8Value );
+ }
+ else if( v8Value->IsObject() )
+ {
+ // Assume this is a property map
+ v8::Local<v8::Object> object = v8::Handle<v8::Object>::Cast(v8Value);
+ Dali::Property::Map propertyMap = V8Utils::GetPropertyMapFromObject(isolate, object);
+ daliPropertyValue = Dali::Property::Value( propertyMap );
+ }
- return daliPropertyValue;
+ return daliPropertyValue;
}
void PropertyValueWrapper::NewRotation( const v8::FunctionCallbackInfo< v8::Value >& args)
}
v8::Local<v8::Object > object;
- float v[4] = {0.f,0.f,0.f,0.f} ;
+ float v[4] = {0.f,0.f,0.f,0.f};
bool foundAllArguments(false);
V8Utils::ReadFloatArguments( foundAllArguments, v, 4, args, 0.f );