2f4760dfc25d5680b879688800b432e471e9a0f1
[platform/core/uifw/dali-adaptor.git] / adaptors / emscripten / wrappers / dali-wrapper.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18
19 // EXTERNAL INCLUDES
20 #include <sstream>
21
22 #include <dali/devel-api/scripting/scripting.h>
23 #include <dali/devel-api/events/hit-test-algorithm.h>
24 #include <dali/devel-api/rendering/geometry.h>
25 #include <dali/devel-api/rendering/shader.h>
26 #include <dali/devel-api/rendering/sampler.h>
27 #include <dali/devel-api/rendering/material.h>
28 #include <dali/devel-api/rendering/renderer.h>
29 #include "emscripten/emscripten.h"
30 #include "emscripten/bind.h"
31 #include "emscripten/val.h"
32
33 // INTERNAL INCLUDES
34 #include "platform-abstractions/emscripten/emscripten-callbacks.h"
35 #include "platform-abstractions/emscripten/emscripten-platform-abstraction.h"
36 #include "sdl-application.h"
37 #include "actor-wrapper.h"
38 #include "animation-wrapper.h"
39 #include "emscripten-utils.h"
40 #include "handle-wrapper.h"
41 #include "image-wrapper.h"
42 #include "property-buffer-wrapper.h"
43 #include "property-value-wrapper.h"
44 #include "render-task-wrapper.h"
45 #include "shader-effect-wrapper.h"
46 #include "signal-holder.h"
47 #include "type-info-wrapper.h"
48
49 ////////////////////////////////////////////////////////////////////////////////
50 //
51 // The browser javascript wrapper consists of this cpp file and a counterpart
52 // javascript file.
53 //
54 // They work in tandem to help make the interface natural and convenient
55 // for a Javascript programmer.
56 //
57 // Unfortunately there is no finalize/destruction in javascript so any cpp
58 // objects created must be explicitly deleted. Sometimes this wrapper can
59 // hide the details and simple types can be immediately marshalled to and
60 // from javascript values. More often objects created must have
61 // object.delete() called at the correct time.
62 //
63 ////////////////////////////////////////////////////////////////////////////////
64
65 extern void EmscriptenMouseEvent(double x, double y, int mouseIsDown);
66 extern void EmscriptenUpdateOnce();
67 extern void EmscriptenRenderOnce();
68
69 namespace Dali
70 {
71 namespace Internal
72 {
73 namespace Emscripten
74 {
75
76 // Javascript callbacks. These are set in the Javascript wrapper source and called
77 // from the c++ wrapper source
78 extern emscripten::val JSGetGlyphImage;
79 extern emscripten::val JSGetImage;
80 extern emscripten::val JSGetImageMetaData;
81 extern emscripten::val JSRenderFinished;
82
83 using namespace emscripten;
84
85 /**
86  * Dali Vector access for Emscripten wrapping of Dali::Vector
87  */
88 template<typename DaliVectorType>
89 struct DaliVectorAccess
90 {
91   static emscripten::val Get( const DaliVectorType& v, typename DaliVectorType::SizeType index )
92   {
93     if (index < v.Size())
94     {
95       return emscripten::val(v[index]);
96     }
97     else
98     {
99       return emscripten::val::undefined();
100     }
101   }
102
103   static bool Set( DaliVectorType& v, typename DaliVectorType::SizeType index, const typename DaliVectorType::ItemType& value)
104   {
105     v[index] = value;
106     return true;
107   }
108
109   static size_t Size( DaliVectorType& v)
110   {
111     return v.Size();
112   }
113 };
114
115 /**
116  * Registering a Dali Vector with Emscripten to wrap for JavaScript
117  */
118 template<typename T>
119 class_<Dali::Vector<T>> register_dali_vector(const char* name)
120 {
121   typedef Dali::Vector<T> DaliVecType;
122
123   void (DaliVecType::*PushBack)(const T&) = &DaliVecType::PushBack;
124   void (DaliVecType::*Resize)(const size_t, const T&) = &DaliVecType::Resize;
125   return class_<DaliVecType>(name)
126     .template constructor<>()
127     .function("push_back", PushBack)
128     .function("resize", Resize)
129     .function("size", &DaliVectorAccess<DaliVecType>::Size)
130     .function("get", &DaliVectorAccess<DaliVecType>::Get)
131     .function("set", &DaliVectorAccess<DaliVecType>::Set)
132 ;
133 };
134
135
136 namespace
137 {
138
139 std::string VersionString()
140 {
141   std::stringstream versionString;
142   versionString <<  "DALi Core:      " << Dali::CORE_MAJOR_VERSION << "." << Dali::CORE_MINOR_VERSION << "." << Dali::CORE_MICRO_VERSION << " (" << Dali::CORE_BUILD_DATE << ")" << std::endl;
143   return versionString.str();
144 }
145
146
147 /**
148  * String conversions for C++ types. For PropertyValueToString() conversions.
149  */
150 template <typename T>
151 std::string ToString(const T& value)
152 {
153   std::stringstream ss;
154   ss << value;
155   return ss.str();
156 }
157
158 /**
159  * Dali Rect to string template specialization
160  */
161 template <>
162 std::string ToString(const Dali::Rect<int>& value)
163 {
164   std::stringstream ss;
165   ss << value.x << "," << value.y << "," << value.width << "," << value.height;
166   return ss.str();
167 }
168
169 /**
170  * Converts Dali Property Value to string
171  */
172 std::string PropertyValueToString( const Dali::Property::Value& value )
173 {
174   std::string ret;
175
176   switch( value.GetType() )
177   {
178     case Dali::Property::NONE:
179     {
180       ret = "NONE";
181       break;
182     }            ///< No type
183     case Dali::Property::BOOLEAN:
184     {
185       ret = value.Get<bool>() ? "True" : "False";
186       break;
187     }
188     case Dali::Property::FLOAT:
189     {
190       ret = ToString( value.Get<float>() );
191       break;
192     }
193     case Dali::Property::INTEGER:
194     {
195       ret = ToString( value.Get<int>() );
196       break;
197     }
198     case Dali::Property::VECTOR2:
199     {
200       ret = ToString( value.Get<Dali::Vector2>() );
201       break;
202     }
203     case Dali::Property::VECTOR3:
204     {
205       ret = ToString( value.Get<Dali::Vector3>() );
206       break;
207     }
208     case Dali::Property::VECTOR4:
209     {
210       ret = ToString( value.Get<Dali::Vector4>() );
211       break;
212     }
213     case Dali::Property::MATRIX3:
214     {
215       ret = ToString( value.Get<Dali::Matrix3>() );
216       break;
217     }
218     case Dali::Property::MATRIX:
219     {
220       ret = ToString( value.Get<Dali::Matrix>() );
221       break;
222     }
223     case Dali::Property::RECTANGLE:
224     {
225       ret = ToString( value.Get< Dali::Rect<int> >() );
226       break;
227     }
228     case Dali::Property::ROTATION:
229     {
230       break;
231     }
232     case Dali::Property::STRING:
233     {
234       ret = value.Get<std::string>();
235       break;
236     }
237     case Dali::Property::ARRAY:
238     {
239       Dali::Property::Array *array = value.GetArray();
240       DALI_ASSERT_ALWAYS(array);
241       ret = std::string("Array Size=") + ToString( array->Count() );
242       break;
243     }
244     case Dali::Property::MAP:
245     {
246       Dali::Property::Map *map = value.GetMap();
247       DALI_ASSERT_ALWAYS(map);
248       ret = std::string("Map Size=") + ToString( map->Count() );
249       break;
250     }
251   }
252
253   return ret;
254 }
255
256 /**
257  * Creates an Actor previously registered with the TypeRegistry by name
258  * Actors are currently differentiated in the dali-wrapper.js and have accessor functions
259  * to support 'property.name=' access in the Javascript side object
260  */
261 Dali::Actor CreateActor(const std::string& name)
262 {
263   Dali::Actor ret;
264
265   Dali::TypeRegistry registry = Dali::TypeRegistry::Get();
266
267   Dali::TypeInfo typeInfo = registry.GetTypeInfo( name );
268
269   if(!typeInfo)
270   {
271     EM_ASM( throw "Invalid type name" );
272   }
273   else
274   {
275     Dali::BaseHandle handle = typeInfo.CreateInstance();
276
277     if(!handle)
278     {
279       EM_ASM( throw "Invalid handle. Cannot downcast (not an actor)" );
280     }
281
282     if( Dali::Actor actor = Dali::Actor::DownCast(handle) )
283     {
284       ret = actor;
285     }
286   }
287
288   return ret;
289 }
290
291 /**
292  * Creates any Handle from the TypeRegistry by name
293  */
294 Dali::Handle CreateHandle(const std::string& name)
295 {
296   Dali::Handle ret;
297
298   Dali::TypeRegistry registry = Dali::TypeRegistry::Get();
299
300   Dali::TypeInfo typeInfo = registry.GetTypeInfo( name );
301
302   if(!typeInfo)
303   {
304     EM_ASM( throw "Invalid type name" );
305   }
306   else
307   {
308     Dali::BaseHandle base = typeInfo.CreateInstance();
309     if(!base)
310     {
311       EM_ASM( throw "Cannot create instance (not a handle)" );
312     }
313     Dali::Handle handle = Dali::Handle::DownCast(base);
314
315     if(!handle)
316     {
317       EM_ASM( throw "Invalid handle. Cannot downcast" );
318     }
319
320     ret = handle;
321   }
322
323   return ret;
324 }
325
326 /**
327  * The functor to be used in the hit-test algorithm to check whether the actor is hittable.
328  */
329 bool IsActorHittableFunction(Dali::Actor actor, Dali::HitTestAlgorithm::TraverseType type)
330 {
331   const std::string& name = actor.GetName();
332   // by convention if not visible, or with a * starting the name or if the root layer
333   return actor.IsVisible() && (name.size() ? name[0] != '*' : true);
334 };
335
336 /*
337  * Hit Test wrapper
338  *
339  */
340 Dali::Actor HitTest(float x, float y)
341 {
342   Dali::HitTestAlgorithm::Results results;
343   Dali::HitTestAlgorithm::HitTest( Dali::Stage::GetCurrent(), Dali::Vector2(x,y), results, IsActorHittableFunction );
344   return results.actor;
345 }
346
347 /**
348  * Creates a solid colour actor
349  */
350 Dali::Actor CreateSolidColorActor( const Dali::Vector4& color, bool border, const Dali::Vector4& borderColor, const unsigned int borderSize )
351 {
352   static const unsigned int MAX_BORDER_SIZE( 9 );
353
354   Dali::ImageActor image;
355   if( borderSize > MAX_BORDER_SIZE )
356   {
357     return image;
358   }
359
360   const unsigned int bitmapWidth = borderSize * 2 + 2;
361
362   // Using a (2 + border) x (2 + border) image gives a better blend with the GL implementation
363   // than a (1 + border) x (1 + border) image
364   const unsigned int bitmapSize = bitmapWidth * bitmapWidth;
365   const unsigned int topLeft = bitmapWidth * borderSize + borderSize;
366   const unsigned int topRight = topLeft + 1;
367   const unsigned int bottomLeft = bitmapWidth * (borderSize + 1) + borderSize;
368   const unsigned int bottomRight = bottomLeft + 1;
369
370   Dali::BufferImage imageData;
371   if(color.a != 1.0 || borderColor.a != 1.0)
372   {
373     imageData = Dali::BufferImage::New( bitmapWidth, bitmapWidth, Dali::Pixel::RGBA8888 );
374
375     // Create the image
376     Dali::PixelBuffer* pixbuf = imageData.GetBuffer();
377     Dali::Vector4 outerColor = color;
378     if ( border )
379     {
380       outerColor = borderColor;
381     }
382
383     for( size_t i = 0; i < bitmapSize; ++i )
384     {
385       if( i == topLeft ||
386           i == topRight ||
387           i == bottomLeft ||
388           i == bottomRight )
389       {
390         pixbuf[i*4+0] = 0xFF * color.r;
391         pixbuf[i*4+1] = 0xFF * color.g;
392         pixbuf[i*4+2] = 0xFF * color.b;
393         pixbuf[i*4+3] = 0xFF * color.a;
394       }
395       else
396       {
397         pixbuf[i*4+0] = 0xFF * outerColor.r;
398         pixbuf[i*4+1] = 0xFF * outerColor.g;
399         pixbuf[i*4+2] = 0xFF * outerColor.b;
400         pixbuf[i*4+3] = 0xFF * outerColor.a;
401       }
402     }
403   }
404   else
405   {
406     imageData = Dali::BufferImage::New( bitmapWidth, bitmapWidth, Dali::Pixel::RGB888 );
407
408     // Create the image
409     Dali::PixelBuffer* pixbuf = imageData.GetBuffer();
410     Dali::Vector4 outerColor = color;
411     if ( border )
412     {
413       outerColor = borderColor;
414     }
415
416     for( size_t i = 0; i < bitmapSize; ++i )
417     {
418       if( i == topLeft ||
419           i == topRight ||
420           i == bottomLeft ||
421           i == bottomRight )
422       {
423         pixbuf[i*3+0] = 0xFF * color.r;
424         pixbuf[i*3+1] = 0xFF * color.g;
425         pixbuf[i*3+2] = 0xFF * color.b;
426       }
427       else
428       {
429         pixbuf[i*3+0] = 0xFF * outerColor.r;
430         pixbuf[i*3+1] = 0xFF * outerColor.g;
431         pixbuf[i*3+2] = 0xFF * outerColor.b;
432       }
433     }
434   }
435
436   imageData.Update();
437   image = Dali::ImageActor::New( imageData );
438   image.SetAnchorPoint( Dali::AnchorPoint::CENTER );
439   image.SetParentOrigin( Dali::ParentOrigin::CENTER );
440
441   // if( border )
442   // {
443   //   image.SetStyle( Dali::ImageActor::STYLE_NINE_PATCH );
444   //   image.SetNinePatchBorder( Dali::Vector4::ONE * (float)borderSize * 2.0f );
445   // }
446
447   return image;
448 }
449
450 } // anon namespace
451
452 /**
453  * Sets the callback to getting a glyph (from dali-wrapper.js/browser)
454  */
455 void SetCallbackGetGlyphImage(const emscripten::val& callback)
456 {
457   JSGetGlyphImage = callback;
458 }
459
460 /**
461  * Sets the callback to get an image (from dali-wrapper.js/browser)
462  */
463 void SetCallbackGetImage(const emscripten::val& callback)
464 {
465   JSGetImage = callback;
466 }
467
468 /**
469  * Sets the callback to get image meta data (from dali-wrapper.js/browser)
470  */
471 void SetCallbackGetImageMetadata(const emscripten::val& callback)
472 {
473   JSGetImageMetaData = callback;
474 }
475
476 /**
477  * Sets the callback to signal render finished to dali-wrapper.js/browser
478  */
479 void SetCallbackRenderFinished(const emscripten::val& callback)
480 {
481   JSRenderFinished = callback;
482 }
483
484 /**
485  * Generates control points for a Path
486  */
487 void GenerateControlPoints(Dali::Handle& handle, float curvature)
488 {
489   if( handle )
490   {
491     Dali::Path path = Dali::Path::DownCast(handle);
492     if(path)
493     {
494       path.GenerateControlPoints(curvature);
495     }
496     else
497     {
498       EM_ASM( throw "Handle is not a path object" );
499     }
500   }
501   else
502   {
503     EM_ASM( throw "Handle is empty" );
504   }
505
506 }
507
508 /**
509  * Creating property Value Objects
510  *   javascript can't select on type so we have renamed constructors
511  *
512  * Emscripten can convert some basic types and ones we've declared as value_array(s)
513  * (These are given member access offsets/functions and are for simple structs etc)
514  *
515  * The composite types need converting.
516  */
517 Dali::Property::Value PropertyValueBoolean(bool v)
518 {
519   return Dali::Property::Value(v);
520 }
521
522 Dali::Property::Value PropertyValueFloat(float v)
523 {
524   return Dali::Property::Value(v);
525 }
526
527 Dali::Property::Value PropertyValueInteger(int v)
528 {
529   return Dali::Property::Value(v);
530 }
531
532 Dali::Property::Value PropertyValueVector2( const Dali::Vector2& v )
533 {
534   return Dali::Property::Value(v);
535 }
536
537 Dali::Property::Value PropertyValueVector3( const Dali::Vector3& v )
538 {
539   return Dali::Property::Value(v);
540 }
541
542 Dali::Property::Value PropertyValueVector4( const Dali::Vector4& v )
543 {
544   return Dali::Property::Value(v);
545 }
546
547 Dali::Property::Value PropertyValueIntRect( int a, int b, int c, int d )
548 {
549   return Dali::Property::Value(Dali::Rect<int>( a, b, c, d));
550 }
551
552 Dali::Property::Value PropertyValueMatrix( const Dali::Matrix& v )
553 {
554   return Dali::Property::Value(v);
555 }
556
557 Dali::Property::Value PropertyValueMatrix3( const Dali::Matrix3& v )
558 {
559   return Dali::Property::Value(v);
560 }
561
562 Dali::Property::Value PropertyValueEuler( const Dali::Vector3& v )
563 {
564   return Dali::Property::Value( Dali::Quaternion(
565                                   Dali::Radian(Dali::Degree(v.x)),
566                                   Dali::Radian(Dali::Degree(v.y)),
567                                   Dali::Radian(Dali::Degree(v.z)) ) );
568 }
569
570 Dali::Property::Value PropertyValueAxisAngle( const Dali::Vector4& v )
571 {
572   return Dali::Quaternion( Dali::Radian(Dali::Degree(v[3])), Dali::Vector3(v) );
573 }
574
575 Dali::Property::Value PropertyValueString( const std::string& v )
576 {
577   return Dali::Property::Value(v);
578 }
579
580 Dali::Property::Value PropertyValueContainer( const emscripten::val& v )
581 {
582   Dali::Property::Value ret;
583   RecursiveSetProperty( ret, v );
584   return ret;
585 }
586
587 /**
588  * Property value accessors from Dali Property Value
589  */
590 bool PropertyGetBoolean(const Dali::Property::Value& v)
591 {
592   return v.Get<bool>();
593 }
594
595 float PropertyGetFloat(const Dali::Property::Value& v)
596 {
597   return v.Get<float>();
598 }
599
600 int PropertyGetInteger(const Dali::Property::Value& v)
601 {
602   return v.Get<int>();
603 }
604
605 Dali::Vector2 PropertyGetVector2(const Dali::Property::Value& v)
606 {
607   return v.Get<Dali::Vector2>();
608 }
609
610 Dali::Vector3 PropertyGetVector3(const Dali::Property::Value& v)
611 {
612   return v.Get<Dali::Vector3>();
613 }
614
615 Dali::Vector4 PropertyGetVector4(const Dali::Property::Value& v)
616 {
617   return v.Get<Dali::Vector4>();
618 }
619
620 emscripten::val PropertyGetIntRect(const Dali::Property::Value& v)
621 {
622   return JavascriptValue(v);
623 }
624
625 std::string PropertyGetString(const Dali::Property::Value& v)
626 {
627   return v.Get<std::string>();
628 }
629
630 emscripten::val PropertyGetMap(const Dali::Property::Value& v)
631 {
632   return JavascriptValue(v);
633 }
634
635 emscripten::val PropertyGetArray(const Dali::Property::Value& v)
636 {
637   return JavascriptValue(v);
638 }
639
640 emscripten::val PropertyGetMatrix(const Dali::Property::Value& v)
641 {
642   return JavascriptValue(v);
643 }
644
645 emscripten::val PropertyGetMatrix3(const Dali::Property::Value& v)
646 {
647   return JavascriptValue(v);
648 }
649
650 emscripten::val PropertyGetEuler(const Dali::Property::Value& v)
651 {
652   return JavascriptValue(v);
653 }
654
655 emscripten::val PropertyGetRotation(const Dali::Property::Value& v)
656 {
657   return JavascriptValue(v);
658 }
659
660 int PropertyGetType(Dali::Property::Value& v)
661 {
662   return (int)v.GetType();
663 }
664
665 std::string PropertyGetTypeName(Dali::Property::Value& v)
666 {
667   return Dali::PropertyTypes::GetName(v.GetType());
668 }
669
670 template <typename T>
671 float MatrixGetter(T &v, int n)
672 {
673   return *(v.AsFloat() + n);
674 }
675
676 template <typename T>
677 void MatrixSetter(T &v, float f, int n)
678 {
679   *(v.AsFloat() + n) = f;
680 }
681
682 float MatrixGetter0(const Dali::Matrix &v)        { return MatrixGetter(v, 0); }
683 float MatrixGetter1(const Dali::Matrix &v)        { return MatrixGetter(v, 1); }
684 float MatrixGetter2(const Dali::Matrix &v)        { return MatrixGetter(v, 2); }
685 float MatrixGetter3(const Dali::Matrix &v)        { return MatrixGetter(v, 3); }
686 float MatrixGetter4(const Dali::Matrix &v)        { return MatrixGetter(v, 4); }
687 float MatrixGetter5(const Dali::Matrix &v)        { return MatrixGetter(v, 5); }
688 float MatrixGetter6(const Dali::Matrix &v)        { return MatrixGetter(v, 6); }
689 float MatrixGetter7(const Dali::Matrix &v)        { return MatrixGetter(v, 7); }
690 float MatrixGetter8(const Dali::Matrix &v)        { return MatrixGetter(v, 8); }
691 float MatrixGetter9(const Dali::Matrix &v)        { return MatrixGetter(v, 9); }
692 float MatrixGetter10(const Dali::Matrix &v)        { return MatrixGetter(v,10); }
693 float MatrixGetter11(const Dali::Matrix &v)        { return MatrixGetter(v,11); }
694 float MatrixGetter12(const Dali::Matrix &v)        { return MatrixGetter(v,12); }
695 float MatrixGetter13(const Dali::Matrix &v)        { return MatrixGetter(v,13); }
696 float MatrixGetter14(const Dali::Matrix &v)        { return MatrixGetter(v,14); }
697 float MatrixGetter15(const Dali::Matrix &v)        { return MatrixGetter(v,15); }
698 float MatrixGetter16(const Dali::Matrix &v)        { return MatrixGetter(v,16); }
699
700 void MatrixSetter0(Dali::Matrix &v, float f)      { MatrixSetter(v, f, 0); }
701 void MatrixSetter1(Dali::Matrix &v, float f)      { MatrixSetter(v, f, 1); }
702 void MatrixSetter2(Dali::Matrix &v, float f)      { MatrixSetter(v, f, 2); }
703 void MatrixSetter3(Dali::Matrix &v, float f)      { MatrixSetter(v, f, 3); }
704 void MatrixSetter4(Dali::Matrix &v, float f)      { MatrixSetter(v, f, 4); }
705 void MatrixSetter5(Dali::Matrix &v, float f)      { MatrixSetter(v, f, 5); }
706 void MatrixSetter6(Dali::Matrix &v, float f)      { MatrixSetter(v, f, 6); }
707 void MatrixSetter7(Dali::Matrix &v, float f)      { MatrixSetter(v, f, 7); }
708 void MatrixSetter8(Dali::Matrix &v, float f)      { MatrixSetter(v, f, 8); }
709 void MatrixSetter9(Dali::Matrix &v, float f)      { MatrixSetter(v, f, 9); }
710 void MatrixSetter10(Dali::Matrix &v, float f)      { MatrixSetter(v, f,10); }
711 void MatrixSetter11(Dali::Matrix &v, float f)      { MatrixSetter(v, f,11); }
712 void MatrixSetter12(Dali::Matrix &v, float f)      { MatrixSetter(v, f,12); }
713 void MatrixSetter13(Dali::Matrix &v, float f)      { MatrixSetter(v, f,13); }
714 void MatrixSetter14(Dali::Matrix &v, float f)      { MatrixSetter(v, f,14); }
715 void MatrixSetter15(Dali::Matrix &v, float f)      { MatrixSetter(v, f,15); }
716 void MatrixSetter16(Dali::Matrix &v, float f)      { MatrixSetter(v, f,16); }
717
718 float Matrix3Getter0(const Dali::Matrix3 &v)        { return MatrixGetter(v, 0); }
719 float Matrix3Getter1(const Dali::Matrix3 &v)        { return MatrixGetter(v, 1); }
720 float Matrix3Getter2(const Dali::Matrix3 &v)        { return MatrixGetter(v, 2); }
721 float Matrix3Getter3(const Dali::Matrix3 &v)        { return MatrixGetter(v, 3); }
722 float Matrix3Getter4(const Dali::Matrix3 &v)        { return MatrixGetter(v, 4); }
723 float Matrix3Getter5(const Dali::Matrix3 &v)        { return MatrixGetter(v, 5); }
724 float Matrix3Getter6(const Dali::Matrix3 &v)        { return MatrixGetter(v, 6); }
725 float Matrix3Getter7(const Dali::Matrix3 &v)        { return MatrixGetter(v, 7); }
726 float Matrix3Getter8(const Dali::Matrix3 &v)        { return MatrixGetter(v, 8); }
727
728 void Matrix3Setter0(Dali::Matrix3 &v, float f)      { MatrixSetter(v, f, 0); }
729 void Matrix3Setter1(Dali::Matrix3 &v, float f)      { MatrixSetter(v, f, 1); }
730 void Matrix3Setter2(Dali::Matrix3 &v, float f)      { MatrixSetter(v, f, 2); }
731 void Matrix3Setter3(Dali::Matrix3 &v, float f)      { MatrixSetter(v, f, 3); }
732 void Matrix3Setter4(Dali::Matrix3 &v, float f)      { MatrixSetter(v, f, 4); }
733 void Matrix3Setter5(Dali::Matrix3 &v, float f)      { MatrixSetter(v, f, 5); }
734 void Matrix3Setter6(Dali::Matrix3 &v, float f)      { MatrixSetter(v, f, 6); }
735 void Matrix3Setter7(Dali::Matrix3 &v, float f)      { MatrixSetter(v, f, 7); }
736 void Matrix3Setter8(Dali::Matrix3 &v, float f)      { MatrixSetter(v, f, 8); }
737
738 val JavascriptUpdateCallback( val::undefined() );
739 bool JavascriptUpdateCallbackSet = false;
740
741 void JavascriptUpdate(int dt)
742 {
743   if( JavascriptUpdateCallbackSet )
744   {
745     JavascriptUpdateCallback( val(dt) );
746   }
747 }
748
749 void SetUpdateFunction( const emscripten::val& function )
750 {
751   JavascriptUpdateCallback = function;
752   JavascriptUpdateCallbackSet = true;
753 }
754
755 const emscripten::val& GetUpdateFunction()
756 {
757   return JavascriptUpdateCallback;
758 }
759
760 /**
761  * Emscripten Bindings
762  *
763  * This uses Emscripten 'bind' (similar in design to Boost's python wrapper library).
764  * It provides a simplified way to wrap C++ classes and wraps Emscriptens type
765  * registration API.
766  *
767  * A convention below is that where there is a function or method name prepended
768  * with '__' there is a corresponding Javascript helper function to help with
769  * marshalling parameters and return values.
770  *
771  */
772 EMSCRIPTEN_BINDINGS(dali_wrapper)
773 {
774   // With a little help embind knows about vectors so we tell it which ones to instantiate
775   register_dali_vector<int>("DaliVectorInt");
776   register_vector<std::string>("VectorString");
777   register_vector<int>("VectorInt");
778   register_vector<float>("VectorFloat");
779   register_vector<Dali::Actor>("VectorActor");
780
781   //
782   // Creation functions.
783   //
784   emscripten::function("VersionString", &VersionString);
785   emscripten::function("__createActor", &CreateActor);
786   emscripten::function("__createHandle", &CreateHandle);
787   emscripten::function("__createSolidColorActor", &CreateSolidColorActor);
788
789   //
790   // Helper functions
791   //
792   emscripten::function("javascriptValue", &JavascriptValue);
793   emscripten::function("__hitTest", &HitTest);
794   emscripten::function("sendMouseEvent", &EmscriptenMouseEvent);
795   emscripten::function("__updateOnce", &EmscriptenUpdateOnce);
796   emscripten::function("__renderOnce", &EmscriptenRenderOnce);
797   emscripten::function("generateControlPoints", &GenerateControlPoints);
798
799   //
800   // Global callback functions
801   //
802   emscripten::function("setCallbackGetGlyphImage", &SetCallbackGetGlyphImage);
803   emscripten::function("setCallbackGetImage", &SetCallbackGetImage);
804   emscripten::function("setCallbackGetImageMetadata", &SetCallbackGetImageMetadata);
805   emscripten::function("setCallbackRenderFinished", &SetCallbackRenderFinished);
806   emscripten::function("setUpdateFunction", &SetUpdateFunction);
807   emscripten::function("getUpdateFunction", &GetUpdateFunction);
808
809   //
810   // Property value creation (Javascript can't select on type)
811   //
812   emscripten::function("PropertyValueBoolean", &PropertyValueBoolean);
813   emscripten::function("PropertyValueFloat", &PropertyValueFloat);
814   emscripten::function("PropertyValueInteger", &PropertyValueInteger);
815   emscripten::function("PropertyValueString", &PropertyValueString);
816   emscripten::function("PropertyValueVector2", &PropertyValueVector2);
817   emscripten::function("PropertyValueVector3", &PropertyValueVector3);
818   emscripten::function("PropertyValueVector4", &PropertyValueVector4);
819   emscripten::function("PropertyValueMatrix", &PropertyValueMatrix);
820   emscripten::function("PropertyValueMatrix3", &PropertyValueMatrix3);
821   emscripten::function("PropertyValueMap", &PropertyValueContainer);
822   emscripten::function("PropertyValueArray", &PropertyValueContainer);
823   emscripten::function("PropertyValueEuler", &PropertyValueEuler);
824   emscripten::function("PropertyValueAxisAngle", &PropertyValueAxisAngle);
825   emscripten::function("PropertyValueString", &PropertyValueString);
826   emscripten::function("PropertyValueIntRect", &PropertyValueIntRect);
827
828   //
829   // One unfortunate aspect of wrapping for the browser is that we get no notification
830   // of object deletion so all JS wrapper objects must be wrapper.delete() correctly.
831   //
832   // Embind has a mechanism around this for simple c style structs decared as value_arrays.
833   // These are immediately transformed to Javascript arrays and don't need explicit
834   // destruction, however the API needs a member offset.
835   //
836   value_array<Dali::Internal::Emscripten::Statistics>("Statistics")
837     .element(&Dali::Internal::Emscripten::Statistics::on)
838     .element(&Dali::Internal::Emscripten::Statistics::frameCount)
839     .element(&Dali::Internal::Emscripten::Statistics::lastFrameDeltaSeconds)
840     .element(&Dali::Internal::Emscripten::Statistics::lastSyncTimeMilliseconds)
841     .element(&Dali::Internal::Emscripten::Statistics::nextSyncTimeMilliseconds)
842     .element(&Dali::Internal::Emscripten::Statistics::keepUpdating)
843     .element(&Dali::Internal::Emscripten::Statistics::needsNotification)
844     .element(&Dali::Internal::Emscripten::Statistics::secondsFromLastFrame)
845 ;
846
847   value_array<Dali::Vector2>("Vector2")
848     .element(&Dali::Vector2::x)
849     .element(&Dali::Vector2::y)
850 ;
851
852   value_array<Dali::Vector3>("Vector3")
853     .element(&Dali::Vector3::x)
854     .element(&Dali::Vector3::y)
855     .element(&Dali::Vector3::z)
856 ;
857
858   value_array<Dali::Vector4>("Vector4")
859     .element(&Dali::Vector4::x)
860     .element(&Dali::Vector4::y)
861     .element(&Dali::Vector4::z)
862     .element(&Dali::Vector4::w)
863 ;
864
865   value_array<Dali::Matrix>("Matrix")
866     .element(&MatrixGetter0, &MatrixSetter0)
867     .element(&MatrixGetter1, &MatrixSetter1)
868     .element(&MatrixGetter2, &MatrixSetter2)
869     .element(&MatrixGetter3, &MatrixSetter3)
870     .element(&MatrixGetter4, &MatrixSetter4)
871     .element(&MatrixGetter5, &MatrixSetter5)
872     .element(&MatrixGetter6, &MatrixSetter6)
873     .element(&MatrixGetter7, &MatrixSetter7)
874     .element(&MatrixGetter8, &MatrixSetter8)
875     .element(&MatrixGetter9, &MatrixSetter9)
876     .element(&MatrixGetter10, &MatrixSetter10)
877     .element(&MatrixGetter11, &MatrixSetter11)
878     .element(&MatrixGetter12, &MatrixSetter12)
879     .element(&MatrixGetter13, &MatrixSetter13)
880     .element(&MatrixGetter14, &MatrixSetter14)
881     .element(&MatrixGetter15, &MatrixSetter15)
882 ;
883
884   value_array<Dali::Matrix3>("Matrix3")
885     .element(&Matrix3Getter0, &Matrix3Setter0)
886     .element(&Matrix3Getter1, &Matrix3Setter1)
887     .element(&Matrix3Getter2, &Matrix3Setter2)
888     .element(&Matrix3Getter3, &Matrix3Setter3)
889     .element(&Matrix3Getter4, &Matrix3Setter4)
890     .element(&Matrix3Getter5, &Matrix3Setter5)
891     .element(&Matrix3Getter6, &Matrix3Setter6)
892     .element(&Matrix3Getter7, &Matrix3Setter7)
893     .element(&Matrix3Getter8, &Matrix3Setter8)
894 ;
895
896   //
897   // enums
898   //
899   enum_<Dali::Property::Type>("PropertyType")
900     .value("NONE", Dali::Property::NONE)
901     .value("BOOLEAN", Dali::Property::BOOLEAN)
902     .value("FLOAT", Dali::Property::FLOAT)
903     .value("INTEGER", Dali::Property::INTEGER)
904     .value("VECTOR2", Dali::Property::VECTOR2)
905     .value("VECTOR3", Dali::Property::VECTOR3)
906     .value("VECTOR4", Dali::Property::VECTOR4)
907     .value("MATRIX3", Dali::Property::MATRIX3)
908     .value("MATRIX", Dali::Property::MATRIX)
909     .value("RECTANGLE", Dali::Property::RECTANGLE)
910     .value("ROTATION", Dali::Property::ROTATION)
911     .value("STRING", Dali::Property::STRING)
912     .value("ARRAY", Dali::Property::ARRAY)
913     .value("MAP", Dali::Property::MAP)
914 ;
915
916   enum_<Dali::ShaderEffect::GeometryHints>("GeometryHints")
917     .value("HINT_NONE", Dali::ShaderEffect::HINT_NONE)
918     .value("HINT_GRID_X", Dali::ShaderEffect::HINT_GRID_X)
919     .value("HINT_GRID_Y", Dali::ShaderEffect::HINT_GRID_Y)
920     .value("HINT_GRID", Dali::ShaderEffect::HINT_GRID)
921     .value("HINT_DEPTH_BUFFER", Dali::ShaderEffect::HINT_DEPTH_BUFFER)
922     .value("HINT_BLENDING", Dali::ShaderEffect::HINT_BLENDING)
923     .value("HINT_DOESNT_MODIFY_GEOMETRY", Dali::ShaderEffect::HINT_DOESNT_MODIFY_GEOMETRY)
924 ;
925
926   enum_<Dali::Shader::ShaderHints>("ShaderHints")
927     .value("HINT_NONE",                      Dali::Shader::HINT_NONE)
928     .value("HINT_REQUIRES_SELF_DEPTH_TEST",  Dali::Shader::HINT_REQUIRES_SELF_DEPTH_TEST)
929     .value("HINT_OUTPUT_IS_TRANSPARENT",     Dali::Shader::HINT_OUTPUT_IS_TRANSPARENT)
930     .value("HINT_OUTPUT_IS_OPAQUE",          Dali::Shader::HINT_OUTPUT_IS_OPAQUE)
931     .value("HINT_MODIFIES_GEOMETRY",         Dali::Shader::HINT_MODIFIES_GEOMETRY)
932 ;
933
934   enum_<Dali::Animation::EndAction>("EndAction")
935     .value("Bake",        Dali::Animation::Bake)
936     .value("Discard",     Dali::Animation::Discard)
937     .value("BakeFinal",   Dali::Animation::BakeFinal)
938 ;
939
940   enum_<Dali::Animation::Interpolation>("Interpolation")
941     .value("Linear", Dali::Animation::Interpolation::Linear)
942     .value("Cubic", Dali::Animation::Interpolation::Cubic)
943 ;
944
945   enum_<Dali::Geometry::GeometryType>("GeometryType")
946     .value("POINTS",          Dali::Geometry::POINTS)
947     .value("LINES",           Dali::Geometry::LINES)
948     .value("LINE_LOOP",       Dali::Geometry::LINE_LOOP)
949     .value("LINE_STRIP",      Dali::Geometry::LINE_STRIP)
950     .value("TRIANGLES",       Dali::Geometry::TRIANGLES)
951     .value("TRIANGLE_FAN",    Dali::Geometry::TRIANGLE_FAN)
952     .value("TRIANGLE_STRIP",  Dali::Geometry::TRIANGLE_STRIP)
953 ;
954
955   enum_<Dali::Image::ReleasePolicy>("ReleasePolicy")
956     .value("UNUSED",          Dali::Image::UNUSED)
957     .value("NEVER",           Dali::Image::NEVER)
958 ;
959
960   enum_<Dali::Pixel::Format>("PixelFormat")
961     .value("A8", Dali::Pixel::Format::A8)
962     .value("L8", Dali::Pixel::Format::L8)
963     .value("LA88", Dali::Pixel::Format::LA88)
964     .value("RGB565", Dali::Pixel::Format::RGB565)
965     .value("BGR565", Dali::Pixel::Format::BGR565)
966     .value("RGBA4444", Dali::Pixel::Format::RGBA4444)
967     .value("BGRA4444", Dali::Pixel::Format::BGRA4444)
968     .value("RGBA5551", Dali::Pixel::Format::RGBA5551)
969     .value("BGRA5551", Dali::Pixel::Format::BGRA5551)
970     .value("RGB888", Dali::Pixel::Format::RGB888)
971     .value("RGB8888", Dali::Pixel::Format::RGB8888)
972     .value("BGR8888", Dali::Pixel::Format::BGR8888)
973     .value("RGBA8888", Dali::Pixel::Format::RGBA8888)
974     .value("BGRA8888", Dali::Pixel::Format::BGRA8888)
975     // GLES 3 Standard compressed formats:
976     .value("COMPRESSED_R11_EAC", Dali::Pixel::Format::COMPRESSED_R11_EAC)
977     .value("COMPRESSED_SIGNED_R11_EAC", Dali::Pixel::Format::COMPRESSED_SIGNED_R11_EAC)
978     .value("COMPRESSED_RG11_EAC", Dali::Pixel::Format::COMPRESSED_RG11_EAC)
979     .value("COMPRESSED_SIGNED_RG11_EAC", Dali::Pixel::Format::COMPRESSED_SIGNED_RG11_EAC)
980     .value("COMPRESSED_RGB8_ETC2", Dali::Pixel::Format::COMPRESSED_RGB8_ETC2)
981     .value("COMPRESSED_SRGB8_ETC2", Dali::Pixel::Format::COMPRESSED_SRGB8_ETC2)
982     .value("COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2", Dali::Pixel::Format::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2)
983     .value("COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2", Dali::Pixel::Format::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2)
984     .value("COMPRESSED_RGBA8_ETC2_EAC", Dali::Pixel::Format::COMPRESSED_RGBA8_ETC2_EAC)
985     .value("COMPRESSED_SRGB8_ALPHA8_ETC2_EAC", Dali::Pixel::Format::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC)
986     // GLES 2 extension compressed formats:
987     .value("COMPRESSED_RGB8_ETC1", Dali::Pixel::Format::COMPRESSED_RGB8_ETC1)
988     .value("COMPRESSED_RGB_PVRTC_4BPPV1", Dali::Pixel::Format::COMPRESSED_RGB_PVRTC_4BPPV1)
989 ;
990
991   enum_<Dali::Renderer::FaceCullingMode>("FaceCullingMode")
992     .value("NONE", Dali::Renderer::NONE)
993     .value("CULL_BACK", Dali::Renderer::CULL_BACK)
994     .value("CULL_FRONT", Dali::Renderer::CULL_FRONT)
995     .value("CULL_BACK_AND_FRONT", Dali::Renderer::CULL_BACK_AND_FRONT)
996 ;
997
998   enum_<Dali::BlendingMode::Type>("BlendingMode")
999     .value("OFF", Dali::BlendingMode::OFF)
1000     .value("AUTO", Dali::BlendingMode::AUTO)
1001     .value("ON", Dali::BlendingMode::ON)
1002 ;
1003
1004   enum_<Dali::AlphaFunction::BuiltinFunction>("AlphaFunction")
1005     .value("DEFAULT", Dali::AlphaFunction::BuiltinFunction::DEFAULT)
1006     .value("LINEAR", Dali::AlphaFunction::BuiltinFunction::LINEAR)
1007     .value("REVERSE", Dali::AlphaFunction::BuiltinFunction::REVERSE)
1008     .value("EASE_IN_SQUARE", Dali::AlphaFunction::BuiltinFunction::EASE_IN_SQUARE)
1009     .value("EASE_OUT_SQUARE", Dali::AlphaFunction::BuiltinFunction::EASE_OUT_SQUARE)
1010     .value("EASE_IN", Dali::AlphaFunction::BuiltinFunction::EASE_IN)
1011     .value("EASE_OUT", Dali::AlphaFunction::BuiltinFunction::EASE_OUT)
1012     .value("EASE_IN_OUT", Dali::AlphaFunction::BuiltinFunction::EASE_IN_OUT)
1013     .value("EASE_IN_SINE", Dali::AlphaFunction::BuiltinFunction::EASE_IN_SINE)
1014     .value("EASE_OUT_SINE", Dali::AlphaFunction::BuiltinFunction::EASE_OUT_SINE)
1015     .value("EASE_IN_OUT_SINE", Dali::AlphaFunction::BuiltinFunction::EASE_IN_OUT_SINE)
1016     .value("BOUNCE", Dali::AlphaFunction::BuiltinFunction::BOUNCE)
1017     .value("SIN", Dali::AlphaFunction::BuiltinFunction::SIN)
1018     .value("EASE_OUT_BACK", Dali::AlphaFunction::BuiltinFunction::EASE_OUT_BACK)
1019 ;
1020
1021   //
1022   // classes
1023   //
1024
1025   // we need property map as an object rather than straight conversion to javascript 'object'
1026   // because its ordered. And PropertyBuffer needs an order.
1027   class_<Dali::Property::Map>("PropertyMap")
1028     .constructor<>()
1029     .function("count", &Dali::Property::Map::Count)
1030     .function("empty", &Dali::Property::Map::Empty)
1031     .function("__insert", select_overload< void(const std::string&, const Dali::Property::Value&) > (&Dali::Property::Map::Insert))
1032     .function("__get", &PropertyMapGet)
1033     .function("__getValue", &Dali::Property::Map::GetValue)
1034     .function("getKey", &Dali::Property::Map::GetKey)
1035     .function("clear", &Dali::Property::Map::Clear)
1036     .function("merge", &Dali::Property::Map::Merge)
1037 ;
1038
1039   class_<Dali::Property::Value>("PropertyValue")
1040     .constructor<>()
1041     .function("getType", &PropertyGetType)
1042     .function("getTypeName", &PropertyGetTypeName)
1043     .function("getBoolean", &PropertyGetBoolean)
1044     .function("getFloat", &PropertyGetFloat)
1045     .function("getInteger", &PropertyGetInteger)
1046     .function("getVector2", &PropertyGetVector2)
1047     .function("getVector3", &PropertyGetVector3)
1048     .function("getVector4", &PropertyGetVector4)
1049     .function("getString", &PropertyGetString)
1050     .function("getMap", &PropertyGetMap)
1051     .function("getArray", &PropertyGetArray)
1052     .function("getMatrix", &PropertyGetMatrix)
1053     .function("getMatrix3", &PropertyGetMatrix3)
1054     .function("getEuler", &PropertyGetEuler)
1055     .function("getRotation", &PropertyGetRotation)
1056     .function("getIntRect", &PropertyGetIntRect)
1057 ;
1058
1059   class_<Dali::BaseHandle>("BaseHandle")
1060     .function("ok", &BaseHandleOk)
1061     .function("getTypeName", &BaseHandle::GetTypeName)
1062 ;
1063
1064   class_<Dali::TypeInfo, base<Dali::BaseHandle>>("TypeInfo")
1065     .function("getName", &Dali::TypeInfo::GetName)
1066     .function("getBaseName", &Dali::TypeInfo::GetBaseName)
1067     .function("getProperties", &GetAllProperties)
1068     .function("getActions", &GetActions)
1069     .function("getSignals", &GetSignals)
1070     .function("getPropertyIndices", &Dali::TypeInfo::GetPropertyIndices)
1071 ;
1072
1073   class_<Dali::TypeRegistry>("TypeRegistry")
1074     .constructor<>(&Dali::TypeRegistry::Get)
1075     .function("getTypeNameCount", &Dali::TypeRegistry::GetTypeNameCount)
1076     .function("getTypeName", &Dali::TypeRegistry::GetTypeName)
1077     .function("getTypeInfo", select_overload< Dali::TypeInfo(const std::string&) > (&Dali::TypeRegistry::GetTypeInfo))
1078 ;
1079
1080   class_<SignalHolder>("SignalHolder")
1081     .constructor<>()
1082 ;
1083
1084   class_<Dali::Handle, base<Dali::BaseHandle>>("Handle")
1085     .function("__registerProperty", &RegisterProperty)
1086     .function("__registerAnimatedProperty", &RegisterAnimatedProperty)
1087     .function("setSelf", &SetSelf)
1088     .function("setProperty", &SetProperty)
1089     .function("getProperty", &GetProperty)
1090     .function("getPropertyIndex", &GetPropertyIndex)
1091     .function("getProperties", &GetProperties)
1092     .function("getPropertyIndices", &Handle::GetPropertyIndices)
1093     .function("getPropertyTypeFromName", &GetPropertyTypeFromName)
1094     .function("getPropertyTypeName", &GetPropertyTypeName)
1095     .function("registerProperty", &RegisterProperty)
1096     .function("registerAnimatedProperty", &RegisterAnimatedProperty)
1097     .function("getTypeInfo", &GetTypeInfo)
1098     .function("isPropertyWritable", &Handle::IsPropertyWritable)
1099     .function("isPropertyAnimatable", &Handle::IsPropertyAnimatable)
1100     .function("isPropertyAConstraintInput", &Handle::IsPropertyAConstraintInput)
1101 ;
1102
1103   class_<Dali::Path, base<Dali::Handle>>("Path")
1104     .constructor<>(&Dali::Path::New)
1105     .function("addPoint", &Dali::Path::AddPoint)
1106     .function("addControlPoint", &Dali::Path::AddControlPoint)
1107     .function("generateControlPoints", &Dali::Path::GenerateControlPoints)
1108     .function("sample", &Dali::Path::Sample)
1109     .function("getPoint", &Dali::Path::GetPoint)
1110     .function("getControlPoint", &Dali::Path::GetControlPoint)
1111     .function("getPointCount", &Dali::Path::GetPointCount)
1112 ;
1113
1114   class_<Dali::KeyFrames>("KeyFrames")
1115     .constructor<>(&Dali::KeyFrames::New)
1116     .function("add", select_overload<void (float progress, Property::Value value)>(&Dali::KeyFrames::Add))
1117     .function("addWithAlpha", &KeyFramesAddWithAlpha)
1118 ;
1119
1120   class_<Dali::Animation>("Animation")
1121     .constructor<float>(&Dali::Animation::New)
1122     .function("__animateTo", &AnimateTo)
1123     .function("__animateBy", &AnimateBy)
1124     .function("__animateBetween", &AnimateBetween)
1125     .function("__animatePath", &AnimatePath)
1126     .function("setDuration", &Dali::Animation::SetDuration)
1127     .function("getDuration", &Dali::Animation::GetDuration)
1128     .function("setLooping", &Dali::Animation::SetLooping)
1129     .function("isLooping", &Dali::Animation::IsLooping)
1130     .function("setEndAction", &Dali::Animation::SetEndAction)
1131     .function("getEndAction", &Dali::Animation::GetEndAction)
1132     .function("setDisconnectAction", &Dali::Animation::SetDisconnectAction)
1133     .function("getDisconnectAction", &Dali::Animation::GetDisconnectAction)
1134     .function("setCurrentProgress", &Dali::Animation::SetCurrentProgress)
1135     .function("getCurrentProgress", &Dali::Animation::GetCurrentProgress)
1136     .function("setSpeedFactor", &Dali::Animation::SetSpeedFactor)
1137     .function("getSpeedFactor", &Dali::Animation::GetSpeedFactor)
1138     .function("setPlayRange", &Dali::Animation::SetPlayRange)
1139     .function("getPlayRange", &Dali::Animation::GetPlayRange)
1140     .function("play", &Dali::Animation::Play)
1141     .function("playFrom", &Dali::Animation::PlayFrom)
1142     .function("pause", &Dali::Animation::Pause)
1143     .function("stop", &Dali::Animation::Stop)
1144     .function("clear", &Dali::Animation::Clear)
1145 ;
1146
1147   class_<Dali::PropertyBuffer>("PropertyBuffer")
1148     .constructor<Dali::Property::Map&>(Dali::PropertyBuffer::New)
1149     .function("setData", &SetPropertyBufferDataRaw)
1150 ;
1151
1152   class_<Dali::Geometry>("Geometry")
1153     .constructor<>(&Dali::Geometry::New)
1154     .function("addVertexBuffer", &Dali::Geometry::AddVertexBuffer)
1155     .function("getNumberOfVertexBuffers", &Dali::Geometry::GetNumberOfVertexBuffers)
1156     .function("setIndexBuffer", &Dali::Geometry::SetIndexBuffer)
1157     .function("setGeometryType", &Dali::Geometry::SetGeometryType)
1158     .function("getGeometryType", &Dali::Geometry::GetGeometryType)
1159     .function("setRequiresDepthTesting", &Dali::Geometry::SetRequiresDepthTesting)
1160     .function("getRequiresDepthTesting", &Dali::Geometry::GetRequiresDepthTesting)
1161 ;
1162
1163   class_<Dali::Image>("Image")
1164 ;
1165
1166   class_<Dali::BufferImage, base<Dali::Image> >("BufferImage")
1167     .constructor<const std::string&, unsigned int, unsigned int, Dali::Pixel::Format>(&BufferImageNew)
1168 ;
1169
1170   class_<Dali::EncodedBufferImage, base<Dali::Image> >("EncodedBufferImage")
1171     .constructor<const std::string&>(&EncodedBufferImageNew)
1172 ;
1173
1174   class_<Dali::Sampler>("Sampler")
1175     .constructor<>(&Dali::Sampler::New)
1176 ;
1177
1178   class_<Dali::Shader, base<Dali::Handle>>("Shader")
1179     .constructor<>(&Dali::Shader::New)
1180 ;
1181
1182   class_<Dali::Material, base<Dali::Handle>>("Material")
1183     .constructor<>(&Dali::Material::New)
1184     .function("setShader", &Dali::Material::SetShader)
1185     .function("getShader", &Dali::Material::GetShader)
1186     .function("addTexture", &Dali::Material::AddTexture)
1187     .function("getNumberOfTextures", &Dali::Material::GetNumberOfTextures)
1188     .function("removeTexture", &Dali::Material::RemoveTexture)
1189 ;
1190
1191   class_<Dali::Renderer, base<Dali::Handle>>("Renderer")
1192     .constructor<>(&Dali::Renderer::New)
1193     .function("setGeometry", &Dali::Renderer::SetGeometry)
1194     .function("getGeometry", &Dali::Renderer::GetGeometry)
1195     .function("setMaterial", &Dali::Renderer::SetMaterial)
1196     .function("getMaterial", &Dali::Renderer::GetMaterial)
1197 ;
1198
1199   class_<Dali::ShaderEffect, base<Dali::Handle>>("ShaderEffect")
1200     .constructor<const std::string&, const std::string&,
1201                  const std::string&, const std::string&,
1202                  int >(&CreateShaderEffect)
1203     .function("setEffectImage", &Dali::ShaderEffect::SetEffectImage)
1204     .function("__setUniform", &SetUniform)
1205 ;
1206
1207   class_<Dali::Actor, base<Dali::Handle>>("Actor")
1208     .constructor<>(&Dali::Actor::New)
1209     .function("add", &Dali::Actor::Add)
1210     .function("remove", &Dali::Actor::Remove)
1211     .function("getId", &Dali::Actor::GetId)
1212     .function("__getParent", &Dali::Actor::GetParent)
1213     .function("__findChildById", &Dali::Actor::FindChildById)
1214     .function("__findChildByName", &Dali::Actor::FindChildByName)
1215     .function("__getChildAt", &Dali::Actor::GetChildAt)
1216     .function("getChildCount", &Dali::Actor::GetChildCount)
1217     .function("__screenToLocal",
1218               select_overload<std::vector<float> (Dali::Actor, float, float)>(&ScreenToLocal))
1219     .function("addressOf", &AddressOf)
1220     .function("__connect", &ConnectSignal)
1221     .function("__setPropertyNotification", &SetPropertyNotification)
1222     .function("addRenderer", &Dali::Actor::AddRenderer)
1223     .function("getRendererCount", &Dali::Actor::GetRendererCount)
1224     .function("removeRenderer",
1225               select_overload<void(unsigned int)>(&Dali::Actor::RemoveRenderer))
1226     .function("__getRendererAt", &Dali::Actor::GetRendererAt)
1227 ;
1228
1229   class_<Dali::CameraActor, base<Dali::Actor>>("CameraActor")
1230     .constructor<>( select_overload<Dali::CameraActor()>(&Dali::CameraActor::New))
1231 ;
1232
1233   class_<Dali::Layer, base<Dali::Actor>>("Layer")
1234     .constructor<>(&Dali::Layer::New)
1235     .function("raise", &Dali::Layer::Raise)
1236     .function("lower", &Dali::Layer::Lower)
1237 ;
1238
1239   class_<Dali::Stage>("Stage")
1240     .constructor<>(&Dali::Stage::GetCurrent)
1241     .function("add", &Dali::Stage::Add)
1242     .function("remove", &Dali::Stage::Remove)
1243     .function("__getRootLayer", &Dali::Stage::GetRootLayer)
1244     .function("getLayer", &Dali::Stage::GetLayer)
1245     .function("getRenderTaskList", &Dali::Stage::GetRenderTaskList)
1246     .function("setBackgroundColor", &Dali::Stage::SetBackgroundColor)
1247 ;
1248
1249   class_<Dali::RenderTaskList>("RenderTaskList")
1250     .function("createTask", &Dali::RenderTaskList::CreateTask)
1251     .function("removeTask", &Dali::RenderTaskList::RemoveTask)
1252     .function("getTaskCount", &Dali::RenderTaskList::GetTaskCount)
1253     .function("getTask", &Dali::RenderTaskList::GetTask)
1254 ;
1255
1256   class_<Dali::RenderTask>("RenderTask")
1257     .function("__getCameraActor", &Dali::RenderTask::GetCameraActor)
1258     .function("setCameraActor", &Dali::RenderTask::SetCameraActor)
1259     .function("setSourceActor", &Dali::RenderTask::SetSourceActor)
1260     .function("setExclusive", &Dali::RenderTask::SetExclusive)
1261     .function("setInputEnabled", &Dali::RenderTask::SetInputEnabled)
1262     .function("setViewportPosition", &Dali::RenderTask::SetViewportPosition)
1263     .function("setViewportSize", &Dali::RenderTask::SetViewportSize)
1264     .function("getCurrentViewportPosition", &Dali::RenderTask::GetCurrentViewportPosition)
1265     .function("getCurrentViewportSize", &Dali::RenderTask::GetCurrentViewportSize)
1266     .function("setClearColor", &Dali::RenderTask::SetClearColor)
1267     .function("getClearColor", &Dali::RenderTask::GetClearColor)
1268     .function("setClearEnabled", &Dali::RenderTask::SetClearEnabled)
1269     .function("getClearEnabled", &Dali::RenderTask::GetClearEnabled)
1270     .function("screenToLocal",
1271               select_overload<Dali::Vector2(Dali::RenderTask, Dali::Actor, float, float)>(&ScreenToLocal))
1272     .function("worldToScreen", &WorldToScreen)
1273 ;
1274
1275 }
1276
1277 }; // namespace Emscripten
1278 }; // namespace Internal
1279 }; // namespace Dali