1 #ifndef __DALI_SCRIPTING_H__
2 #define __DALI_SCRIPTING_H__
5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/actors/actor-enumerations.h>
23 #include <dali/public-api/actors/draw-mode.h>
24 #include <dali/devel-api/animation/animation-data.h>
25 #include <dali/public-api/images/image.h>
26 #include <dali/public-api/shader-effects/shader-effect.h>
27 #include <dali/public-api/object/property-map.h>
28 #include <dali/public-api/object/property-value.h>
36 * @brief Utilities for scripting support.
42 * @brief Structure which stores an enumeration and its string equivalent.
46 const char* string; ///< The string representation
47 const int value; ///< The enumeration value wrapped in int
51 * @brief Find the given enum index from the table
53 * @param[in] value The string equivalent (case-insensitive).
54 * @param[in] table A pointer to an array with the enumeration to string equivalents.
55 * @param[in] tableCount Number of items in the array.
56 * @return The index of the enumeration. If enumeration is not found, logs an error and returns tableCount.
58 DALI_IMPORT_API unsigned int FindEnumIndex( const char* value, const StringEnum* table, unsigned int tableCount );
61 * @brief Find the enum as an integer from the table
65 * @param[in] value The string equivalent (case-insensitive, comma separate to OR values).
66 * @param[in] table A pointer to an array with the enumeration to string equivalents.
67 * @param[in] tableCount Number of items in the array.
68 * @param[out] integerEnum The value of the enum.
69 * @return true if one or more enums in value.
71 DALI_IMPORT_API bool EnumStringToInteger( const char* const value, const StringEnum* const table, unsigned int tableCount, unsigned int& integerEnum );
74 * @brief Chooses the appropriate enumeration for the provided string from the given table.
76 * @param[in] value The string equivalent (case-insensitive, comma separate to OR values).
77 * @param[in] table A pointer to an array with the enumeration to string equivalents.
78 * @param[in] tableCount Number of items in the array.
79 * @param[out] result The enum value
81 * @return True if the value was found from the table
83 template< typename T >
84 bool GetEnumeration( const char* value, const StringEnum* table, unsigned int tableCount, T& result )
89 unsigned int integerEnum = 0;
90 // check to avoid crash, not asserting on purpose, error is logged instead
91 if( EnumStringToInteger( value, table, tableCount, integerEnum ) )
93 result = static_cast<T>( integerEnum );
101 * @brief Chooses the appropriate string for the provided enumeration from the given table.
103 * @param[in] value The enumeration.
104 * @param[in] table A pointer to an array with the enumeration to string equivalents.
105 * @param[in] tableCount Number of items in the array.
107 * @return The equivalent enumeration for the given string. Will return NULL if the value does not exist
109 * @note The caller is NOT responsible for cleaning up the returned pointer as it is statically allocated.
111 template< typename T >
112 const char* GetEnumerationName( T value, const StringEnum* table, unsigned int tableCount )
116 for ( unsigned int i = 0; i < tableCount; ++i )
118 if ( value == T(table[ i ].value) )
120 return table[ i ].string;
128 * @brief Chooses the appropriate string for the provided enumeration from the given table.
129 * This is an optimised version that handles enumerations that start at 0 and are linear only.
131 * @param[in] value The enumeration.
132 * @param[in] table A pointer to an array with the enumeration to string equivalents.
133 * @param[in] tableCount Number of items in the array.
135 * @return The equivalent enumeration for the given string. Will return NULL if the value does not exist
137 * @note The caller is NOT responsible for cleaning up the returned pointer as it is statically allocated.
139 template< typename T >
140 const char * GetLinearEnumerationName( T value, const StringEnum* table, unsigned int tableCount )
142 if ( table && ( value > 0 || value <= (int)tableCount ) )
144 return table[value].string;
150 * @brief Takes a string and returns the appropriate color mode.
152 * @param[in] value The input string
153 * @return The corresponding color-mode.
155 DALI_IMPORT_API ColorMode GetColorMode( const std::string& value );
158 * @brief Takes a color mode and returns the appropriate string equivalent.
160 * @param[in] value The color mode
161 * @return The corresponding string.
163 DALI_IMPORT_API std::string GetColorMode( ColorMode value );
166 * @brief Takes a string and returns the appropriate position inheritance mode.
168 * @param[in] value The input string
169 * @return The corresponding position-inheritance-mode.
171 DALI_IMPORT_API PositionInheritanceMode GetPositionInheritanceMode( const std::string& value );
174 * @brief Takes a position inheritance mode and returns the string equivalent.
176 * @param[in] value The position-inheritance-mode.
177 * @return The corresponding string.
179 DALI_IMPORT_API std::string GetPositionInheritanceMode( PositionInheritanceMode value );
182 * @brief Takes a string and returns the appropriate draw mode.
184 * @param[in] value The input string
185 * @return The corresponding draw-mode.
187 DALI_IMPORT_API DrawMode::Type GetDrawMode( const std::string& value );
190 * @brief Takes a draw-mode and returns the string equivalent.
192 * @param[in] value The draw-mode.
193 * @return The corresponding string.
195 DALI_IMPORT_API std::string GetDrawMode( DrawMode::Type value );
198 * @brief Takes a string and returns the appropriate anchor-point or parent-origin constant.
200 * @param[in] value The input string
201 * @return The corresponding anchor-point or parent-origin constant.
203 DALI_IMPORT_API Vector3 GetAnchorConstant( const std::string& value );
206 * @brief Creates object with data from the property value map.
208 * @param[in] property The property value map with the following valid fields:
210 * "filename": type std::string
211 * "loadPolicy" type std::string (enum)
212 * "releasePolicy" type std::string (enum)
214 * "height" type float
215 * "pixelFormat" type std::string (enum)
216 * "fittingMode" type std::string (enum)
217 * "samplingMode" type std::string (enum)
218 * "orientation" type bool
219 * "type" type std::string (FrameBufferImage|BufferImage|ResourceImage(default))
221 * Some fields are optional and some only pertain to a specific type.
223 * @return A pointer to a newly created object.
225 DALI_IMPORT_API Image NewImage( const Property::Value& property );
228 * @brief Creates object with data from the property value map.
230 * @param[in] property The property value map with the following valid fields:
232 * // a program can be specified as string or a filename.
233 * // some fields may be ignored depending on the geometry-type
234 * "program": type Map
236 * "vertex": type std::string
237 * "fragment": type std::string
238 * "vertexPrefix": type std::string
239 * "fragmentPrefix": type std::string
240 * "textVertex": type std::string
241 * "textFragment": type std::string
242 * "vertexFilename": type std::string
243 * "fragmentFilename": type std::string
244 * "vertexPrefixFilename": type std::string
245 * "fragmentPrefixFilename": type std::string
246 * "textVertexFilename": type std::string
247 * "textFragmentFilename": type std::string
248 * "geometryType": type std::string (enum)
249 * "geometryHints": type std::string (enum)
251 * // uniforms must be specified to be registered
252 * "uUniform1": type float,
253 * "uUniform2": type float, etc
256 * @return A pointer to a newly created object.
258 DALI_IMPORT_API ShaderEffect NewShaderEffect( const Property::Value& property );
261 * @brief Creates an actor with the date from the property value map.
263 * @param[in] map The property value map with the properties (and hierarchy) of the actor required
267 * "type": "ImageActor",
270 * "filename":"my-image-path.png"
282 * @return A handle to the newly created actor.
284 DALI_IMPORT_API Actor NewActor( const Property::Map& map );
287 * @brief Creates a Property::Map from the actor provided.
289 * @param[in] actor The base-actor from which a Property::Map should be created
290 * @param[out] map This map is cleared and a property map of actor and its children is filled in
292 DALI_IMPORT_API void CreatePropertyMap( Actor actor, Property::Map& map );
295 * @brief Creates a Property::Map from the image provided.
297 * @param[in] image The image from which a Property::Map should be created
298 * @param[out] map This map is cleared and a property map of the image is filled in
300 DALI_IMPORT_API void CreatePropertyMap( Image image, Property::Map& map );
303 * @brief Creates description data required to create an Animation object from a property map.
305 * @param[in] map The property value map containing the animation description
306 * @param[out] outputAnimationData Resultant data retrieved from the property map is written here
308 DALI_IMPORT_API void NewAnimation( const Property::Map& map, Dali::AnimationData& outputAnimationData );
310 } // namespace Scripting
314 #endif // __DALI_SCRIPTING_H__