#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.
#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>
* @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;
{
// 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;
}
/**
+ * @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.
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;
}
* For example:
* @code
* {
- * "type": "ImageActor",
- * "image":
- * {
- * "filename":"my-image-path.png"
- * },
+ * "type": "Actor",
+ * "position": [ 100, 100, 0 ],
* "actors":
* [
* {