[dali_1.2.40] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / devel-api / scripting / scripting.h
index e688435..6149155 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_SCRIPTING_H
 
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -23,7 +23,7 @@
 #include <dali/public-api/actors/draw-mode.h>
 #include <dali/devel-api/animation/animation-data.h>
 #include <dali/public-api/images/image.h>
-#include <dali/public-api/shader-effects/shader-effect.h>
+#include <dali/public-api/object/property-array.h>
 #include <dali/public-api/object/property-map.h>
 #include <dali/public-api/object/property-value.h>
 
@@ -101,23 +101,23 @@ bool GetEnumeration( const char* value, const StringEnum* table, unsigned int ta
  * @brief Gets the enumeration value from an enumeration property.
  * An enumeration property is a property that can be set with either an INTEGER or STRING.
  *
- * @param[in]  PropertyValue The property containing the int or string value.
+ * @param[in]  propertyValue The property containing the int or string value.
  * @param[in]  table       A pointer to an array with the enumeration to string equivalents.
  * @param[in]  tableCount  Number of items in the array.
  * @param[out] result      The enum value. This is not modified if the enumeration could not be converted.
  * @return     True if the value was found successfully AND the value has changed. This is to allow the caller to do nothing if there is no change.
  */
 template< typename T >
-bool GetEnumerationProperty( const Property::Value& PropertyValue, const StringEnum* table, unsigned int tableCount, T& result )
+bool GetEnumerationProperty( const Property::Value& propertyValue, const StringEnum* table, unsigned int tableCount, T& result )
 {
   int newValue;
   bool set = false;
-  Property::Type type = PropertyValue.GetType();
+  Property::Type type = propertyValue.GetType();
 
   if( type == Property::INTEGER )
   {
     // Attempt to fetch the property as an INTEGER type.
-    if( PropertyValue.Get( newValue ) )
+    if( propertyValue.Get( newValue ) )
     {
       // Success.
       set = true;
@@ -127,7 +127,7 @@ bool GetEnumerationProperty( const Property::Value& PropertyValue, const StringE
   {
     // Attempt to fetch the property as an STRING type, and convert it from string to enumeration value.
     std::string propertyString;
-    if( table && PropertyValue.Get( propertyString ) && EnumStringToInteger( propertyString.c_str(), table, tableCount, newValue ) )
+    if( table && propertyValue.Get( propertyString ) && EnumStringToInteger( propertyString.c_str(), table, tableCount, newValue ) )
     {
       // Success.
       set = true;
@@ -146,6 +146,64 @@ bool GetEnumerationProperty( const Property::Value& PropertyValue, const StringE
 }
 
 /**
+ * @brief Gets the enumeration value from a bitmask enumeration property.
+ * An enumeration property is a property that can be set with either an INTEGER, STRING or an ARRAY of STRING.
+ *
+ * @param[in]  propertyValue The property containing the int, string or and array of string values.
+ * @param[in]  table       A pointer to an array with the enumeration to string equivalents.
+ * @param[in]  tableCount  Number of items in the array.
+ * @param[out] result      The enum value. This is not modified if the enumeration could not be converted.
+ * @return     True if the value was found successfully AND the value has changed. This is to allow the caller to do nothing if there is no change.
+ */
+template< typename T >
+bool GetBitmaskEnumerationProperty( const Property::Value& propertyValue, const Scripting::StringEnum* table, unsigned int tableCount, T& result )
+{
+  bool returnValue = true;
+
+  // Evaluate as a single INTEGER or STRING first.
+  if( !GetEnumerationProperty( propertyValue, table, tableCount, result ) )
+  {
+    // If not, then check if it's an ARRAY
+    if ( propertyValue.GetType() == Property::ARRAY )
+    {
+      int newValue = 0;
+      Property::Array array;
+      propertyValue.Get( array );
+      for( Property::Array::SizeType i = 0; i < array.Count(); ++i )
+      {
+        Property::Value currentValue = array[ i ];
+        // Use an initial value of -1 so any successful property conversion
+        // causes a change (and true to be returned).
+        T current = static_cast< T >( -1 );
+        if( GetEnumerationProperty( currentValue, table, tableCount, current ) )
+        {
+          newValue |= current;
+        }
+        else
+        {
+          // We hit an invalid type.
+          returnValue = false;
+          break;
+        }
+      }
+
+      // If we didn't hit an invalid type and the value has changed, update the result.
+      if( returnValue && ( result != static_cast<T>( newValue ) ) )
+      {
+        result = static_cast<T>( newValue );
+      }
+    }
+    else
+    {
+      // Property type was not ARRAY, and the single property evaluation also failed.
+      returnValue = false;
+    }
+  }
+
+  return returnValue;
+}
+
+/**
  * @brief Chooses the appropriate string for the provided enumeration from the given table.
  *
  * @param[in]  value       The enumeration.
@@ -187,7 +245,7 @@ const char* GetEnumerationName( T value, const StringEnum* table, unsigned int t
 template< typename T >
 const char * GetLinearEnumerationName( T value, const StringEnum* table, unsigned int tableCount )
 {
-  if ( table && ( value > 0 || value <= (int)tableCount ) )
+  if ( table && ( value > 0 || value <= static_cast<int>( tableCount ) ) )
   {
     return table[value].string;
   }
@@ -223,11 +281,8 @@ DALI_IMPORT_API Image NewImage( const Property::Value& property );
  *                 For example:
  * @code
  * {
- *   "type": "ImageActor",
- *   "image":
- *   {
- *     "filename":"my-image-path.png"
- *   },
+ *   "type": "Actor",
+ *   "position": [ 100, 100, 0 ],
  *   "actors":
  *   [
  *     {