Merge remote-tracking branch 'origin/tizen' into devel/new_mesh
[platform/core/uifw/dali-toolkit.git] / docs / content / programming-guide / script-howto.h
1 /*! \page script-howto Scripting HowTo
2  *
3  * <h2 class="pg">Scripting A Custom Control</h2>
4  *
5  * These steps must be taken to provide scripting access for your control.
6  *
7  * <ul>
8  *   <li>Register your class Type.
9  *   <li>Register Signals and Actions (optional).
10  *   <li>Register properties (optional).
11  * </ul>
12  *
13 *
14  * <h3 class="pg">Registering your Type, Signals and Actions</h3>
15  *
16  * As part of your <b>my-actor.cpp</b> a <em>static</em> "Dali::TypeRegistration" object is created to register MyActor for scripting.
17  *
18  * Functions for Creation, Signal Connection and Action are registered with this object.
19  *
20  * @code
21  * namespace   // type registration
22  * {
23  *
24  * // Register MyActor with base actor CustomActor and creation function CreateCustom
25  * Dali::TypeRegistration mCustomType( typeid(MyActor), typeid(Dali::CustomActor), MyActor::Create );
26  *
27  * // Add a signal to the type registration
28  * Dali::TypeSignalConnector signal1( mCustomType, "page-changed", MyActor::DoConnectSignalCustom);
29  *
30  * // Add an action to the type registration
31  * Dali::TypeAction action1( mCustomType, "SelectPage", MyActor::DoActionCustom);
32  *
33  * }
34  * @endcode
35  *
36  * The registered handling functions are also static. For example.
37  *
38  * @code
39  * BaseHandle MyActor::Create(void)
40  * {
41  *   return MyActor::New();
42  * }
43  *
44  * Dali::Connection MyActor::DoConnectSignalCustom(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
45  * {
46  *   Dali::Connection connection ;
47  *
48  *   MyActor* actor = dynamic_cast<MyActor*>(object);
49  *
50  *   if(actor && "page-changed" == signalName)
51  *   {
52  *     connection = return actor->PageChangedSignal().Connect( tracker, functor );
53  *   }
54  *
55  *   return connection ;
56  * }
57  *
58  * bool MyActor::DoActionCustom(BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes)
59  * {
60  *   bool actioned = false ;
61  *
62  *   MyActor* actor = dynamic_cast<MyActor*>(object) ;
63  *
64  *   if(actor && "SelectPage" == actionName)
65  *   {
66  *      actor->DoSelectPage() ;
67  *      actioned = true;
68  *   }
69  *
70  *   return actioned ;
71  * }
72  * @endcode
73  *
74  * <h3 class="pg">Providing Properties for scripting</h3>
75  *
76  * Properties can be registered by name to allow script access.
77  *
78  * A RegisterProperty() call with property attributes allows the custom class to register non animatable properties.
79  *
80  * @code
81  * void MyActor::Initialize()
82  * {
83  *   // Register a non animatable and writeable property.
84  *   mPropertyAlphaIndex = Self().RegisterProperty("alpha", 0.0f, Dali::Property::WRITEABLE);
85  * }
86  * @endcode
87  *
88  * If a non animatable property is set then the class is notified via the OnPropertySet virtual function.
89  *
90  * @code
91  * void MyActor::OnPropertySet(Property::Index index, Property::Value propertyValue)
92  * {
93  *  if(index == mPropertyAlphaIndex)
94  *  {
95  *    SetAlpha(propertyValue.<float>Get());
96  *  }
97  * }
98  *
99  * @endcode
100  *
101  */