2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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/texture-set.h>
28 #include <dali/devel-api/rendering/renderer.h>
29 #include "emscripten/emscripten.h"
30 #include "emscripten/bind.h"
31 #include "emscripten/val.h"
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"
49 ////////////////////////////////////////////////////////////////////////////////
51 // The browser javascript wrapper consists of this cpp file and a counterpart
54 // They work in tandem to help make the interface natural and convenient
55 // for a Javascript programmer.
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.
63 ////////////////////////////////////////////////////////////////////////////////
65 extern void EmscriptenMouseEvent(double x, double y, int mouseIsDown);
66 extern void EmscriptenUpdateOnce();
67 extern void EmscriptenRenderOnce();
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;
83 using namespace emscripten;
86 * Dali Vector access for Emscripten wrapping of Dali::Vector
88 template<typename DaliVectorType>
89 struct DaliVectorAccess
91 static emscripten::val Get( const DaliVectorType& v, typename DaliVectorType::SizeType index )
95 return emscripten::val(v[index]);
99 return emscripten::val::undefined();
103 static bool Set( DaliVectorType& v, typename DaliVectorType::SizeType index, const typename DaliVectorType::ItemType& value)
109 static size_t Size( DaliVectorType& v)
116 * Registering a Dali Vector with Emscripten to wrap for JavaScript
119 class_<Dali::Vector<T>> register_dali_vector(const char* name)
121 typedef Dali::Vector<T> DaliVecType;
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)
139 std::string VersionString()
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();
147 * Creates an Actor previously registered with the TypeRegistry by name
148 * Actors are currently differentiated in the dali-wrapper.js and have accessor functions
149 * to support 'property.name=' access in the Javascript side object
151 Dali::Actor CreateActor(const std::string& name)
155 Dali::TypeRegistry registry = Dali::TypeRegistry::Get();
157 Dali::TypeInfo typeInfo = registry.GetTypeInfo( name );
161 EM_ASM( throw "Invalid type name" );
165 Dali::BaseHandle handle = typeInfo.CreateInstance();
169 EM_ASM( throw "Invalid handle. Cannot downcast (not an actor)" );
172 if( Dali::Actor actor = Dali::Actor::DownCast(handle) )
182 * Creates any Handle from the TypeRegistry by name
184 Dali::Handle CreateHandle(const std::string& name)
188 Dali::TypeRegistry registry = Dali::TypeRegistry::Get();
190 Dali::TypeInfo typeInfo = registry.GetTypeInfo( name );
194 EM_ASM( throw "Invalid type name" );
198 Dali::BaseHandle base = typeInfo.CreateInstance();
201 EM_ASM( throw "Cannot create instance (not a handle)" );
203 Dali::Handle handle = Dali::Handle::DownCast(base);
207 EM_ASM( throw "Invalid handle. Cannot downcast" );
217 * The functor to be used in the hit-test algorithm to check whether the actor is hittable.
219 bool IsActorHittableFunction(Dali::Actor actor, Dali::HitTestAlgorithm::TraverseType type)
221 const std::string& name = actor.GetName();
222 // by convention if not visible, or with a * starting the name or if the root layer
223 return actor.IsVisible() && (name.size() ? name[0] != '*' : true);
230 Dali::Actor HitTest(float x, float y)
232 Dali::HitTestAlgorithm::Results results;
233 Dali::HitTestAlgorithm::HitTest( Dali::Stage::GetCurrent(), Dali::Vector2(x,y), results, IsActorHittableFunction );
234 return results.actor;
238 * Creates a solid colour actor
240 Dali::Actor CreateSolidColorActor( const Dali::Vector4& color, bool border, const Dali::Vector4& borderColor, const unsigned int borderSize )
242 static const unsigned int MAX_BORDER_SIZE( 9 );
244 Dali::ImageActor image;
245 if( borderSize > MAX_BORDER_SIZE )
250 const unsigned int bitmapWidth = borderSize * 2 + 2;
252 // Using a (2 + border) x (2 + border) image gives a better blend with the GL implementation
253 // than a (1 + border) x (1 + border) image
254 const unsigned int bitmapSize = bitmapWidth * bitmapWidth;
255 const unsigned int topLeft = bitmapWidth * borderSize + borderSize;
256 const unsigned int topRight = topLeft + 1;
257 const unsigned int bottomLeft = bitmapWidth * (borderSize + 1) + borderSize;
258 const unsigned int bottomRight = bottomLeft + 1;
260 Dali::BufferImage imageData;
261 if(color.a != 1.0 || borderColor.a != 1.0)
263 imageData = Dali::BufferImage::New( bitmapWidth, bitmapWidth, Dali::Pixel::RGBA8888 );
266 Dali::PixelBuffer* pixbuf = imageData.GetBuffer();
267 Dali::Vector4 outerColor = color;
270 outerColor = borderColor;
273 for( size_t i = 0; i < bitmapSize; ++i )
280 pixbuf[i*4+0] = 0xFF * color.r;
281 pixbuf[i*4+1] = 0xFF * color.g;
282 pixbuf[i*4+2] = 0xFF * color.b;
283 pixbuf[i*4+3] = 0xFF * color.a;
287 pixbuf[i*4+0] = 0xFF * outerColor.r;
288 pixbuf[i*4+1] = 0xFF * outerColor.g;
289 pixbuf[i*4+2] = 0xFF * outerColor.b;
290 pixbuf[i*4+3] = 0xFF * outerColor.a;
296 imageData = Dali::BufferImage::New( bitmapWidth, bitmapWidth, Dali::Pixel::RGB888 );
299 Dali::PixelBuffer* pixbuf = imageData.GetBuffer();
300 Dali::Vector4 outerColor = color;
303 outerColor = borderColor;
306 for( size_t i = 0; i < bitmapSize; ++i )
313 pixbuf[i*3+0] = 0xFF * color.r;
314 pixbuf[i*3+1] = 0xFF * color.g;
315 pixbuf[i*3+2] = 0xFF * color.b;
319 pixbuf[i*3+0] = 0xFF * outerColor.r;
320 pixbuf[i*3+1] = 0xFF * outerColor.g;
321 pixbuf[i*3+2] = 0xFF * outerColor.b;
327 image = Dali::ImageActor::New( imageData );
328 image.SetAnchorPoint( Dali::AnchorPoint::CENTER );
329 image.SetParentOrigin( Dali::ParentOrigin::CENTER );
333 // image.SetStyle( Dali::ImageActor::STYLE_NINE_PATCH );
334 // image.SetNinePatchBorder( Dali::Vector4::ONE * (float)borderSize * 2.0f );
343 * Sets the callback to getting a glyph (from dali-wrapper.js/browser)
345 void SetCallbackGetGlyphImage(const emscripten::val& callback)
347 JSGetGlyphImage = callback;
351 * Sets the callback to get an image (from dali-wrapper.js/browser)
353 void SetCallbackGetImage(const emscripten::val& callback)
355 JSGetImage = callback;
359 * Sets the callback to get image meta data (from dali-wrapper.js/browser)
361 void SetCallbackGetImageMetadata(const emscripten::val& callback)
363 JSGetImageMetaData = callback;
367 * Sets the callback to signal render finished to dali-wrapper.js/browser
369 void SetCallbackRenderFinished(const emscripten::val& callback)
371 JSRenderFinished = callback;
375 * Generates control points for a Path
377 void GenerateControlPoints(Dali::Handle& handle, float curvature)
381 Dali::Path path = Dali::Path::DownCast(handle);
384 path.GenerateControlPoints(curvature);
388 EM_ASM( throw "Handle is not a path object" );
393 EM_ASM( throw "Handle is empty" );
399 * Creating property Value Objects
400 * javascript can't select on type so we have renamed constructors
402 * Emscripten can convert some basic types and ones we've declared as value_array(s)
403 * (These are given member access offsets/functions and are for simple structs etc)
405 * The composite types need converting.
407 Dali::Property::Value PropertyValueBoolean(bool v)
409 return Dali::Property::Value(v);
412 Dali::Property::Value PropertyValueFloat(float v)
414 return Dali::Property::Value(v);
417 Dali::Property::Value PropertyValueInteger(int v)
419 return Dali::Property::Value(v);
422 Dali::Property::Value PropertyValueVector2( const Dali::Vector2& v )
424 return Dali::Property::Value(v);
427 Dali::Property::Value PropertyValueVector3( const Dali::Vector3& v )
429 return Dali::Property::Value(v);
432 Dali::Property::Value PropertyValueVector4( const Dali::Vector4& v )
434 return Dali::Property::Value(v);
437 Dali::Property::Value PropertyValueIntRect( int a, int b, int c, int d )
439 return Dali::Property::Value(Dali::Rect<int>( a, b, c, d));
442 Dali::Property::Value PropertyValueMatrix( const Dali::Matrix& v )
444 return Dali::Property::Value(v);
447 Dali::Property::Value PropertyValueMatrix3( const Dali::Matrix3& v )
449 return Dali::Property::Value(v);
452 Dali::Property::Value PropertyValueEuler( const Dali::Vector3& v )
454 return Dali::Property::Value( Dali::Quaternion(
455 Dali::Radian(Dali::Degree(v.x)),
456 Dali::Radian(Dali::Degree(v.y)),
457 Dali::Radian(Dali::Degree(v.z)) ) );
460 Dali::Property::Value PropertyValueAxisAngle( const Dali::Vector4& v )
462 return Dali::Quaternion( Dali::Radian(Dali::Degree(v[3])), Dali::Vector3(v) );
465 Dali::Property::Value PropertyValueString( const std::string& v )
467 return Dali::Property::Value(v);
470 Dali::Property::Value PropertyValueContainer( const emscripten::val& v )
472 Dali::Property::Value ret;
473 RecursiveSetProperty( ret, v );
478 * Property value accessors from Dali Property Value
480 bool PropertyGetBoolean(const Dali::Property::Value& v)
482 return v.Get<bool>();
485 float PropertyGetFloat(const Dali::Property::Value& v)
487 return v.Get<float>();
490 int PropertyGetInteger(const Dali::Property::Value& v)
495 Dali::Vector2 PropertyGetVector2(const Dali::Property::Value& v)
497 return v.Get<Dali::Vector2>();
500 Dali::Vector3 PropertyGetVector3(const Dali::Property::Value& v)
502 return v.Get<Dali::Vector3>();
505 Dali::Vector4 PropertyGetVector4(const Dali::Property::Value& v)
507 return v.Get<Dali::Vector4>();
510 emscripten::val PropertyGetIntRect(const Dali::Property::Value& v)
512 return JavascriptValue(v);
515 std::string PropertyGetString(const Dali::Property::Value& v)
517 return v.Get<std::string>();
520 emscripten::val PropertyGetMap(const Dali::Property::Value& v)
522 return JavascriptValue(v);
525 emscripten::val PropertyGetArray(const Dali::Property::Value& v)
527 return JavascriptValue(v);
530 emscripten::val PropertyGetMatrix(const Dali::Property::Value& v)
532 return JavascriptValue(v);
535 emscripten::val PropertyGetMatrix3(const Dali::Property::Value& v)
537 return JavascriptValue(v);
540 emscripten::val PropertyGetEuler(const Dali::Property::Value& v)
542 return JavascriptValue(v);
545 emscripten::val PropertyGetRotation(const Dali::Property::Value& v)
547 return JavascriptValue(v);
550 int PropertyGetType(Dali::Property::Value& v)
552 return (int)v.GetType();
555 std::string PropertyGetTypeName(Dali::Property::Value& v)
557 return Dali::PropertyTypes::GetName(v.GetType());
560 template <typename T>
561 float MatrixGetter(T &v, int n)
563 return *(v.AsFloat() + n);
566 template <typename T>
567 void MatrixSetter(T &v, float f, int n)
569 *(v.AsFloat() + n) = f;
572 float MatrixGetter0(const Dali::Matrix &v) { return MatrixGetter(v, 0); }
573 float MatrixGetter1(const Dali::Matrix &v) { return MatrixGetter(v, 1); }
574 float MatrixGetter2(const Dali::Matrix &v) { return MatrixGetter(v, 2); }
575 float MatrixGetter3(const Dali::Matrix &v) { return MatrixGetter(v, 3); }
576 float MatrixGetter4(const Dali::Matrix &v) { return MatrixGetter(v, 4); }
577 float MatrixGetter5(const Dali::Matrix &v) { return MatrixGetter(v, 5); }
578 float MatrixGetter6(const Dali::Matrix &v) { return MatrixGetter(v, 6); }
579 float MatrixGetter7(const Dali::Matrix &v) { return MatrixGetter(v, 7); }
580 float MatrixGetter8(const Dali::Matrix &v) { return MatrixGetter(v, 8); }
581 float MatrixGetter9(const Dali::Matrix &v) { return MatrixGetter(v, 9); }
582 float MatrixGetter10(const Dali::Matrix &v) { return MatrixGetter(v,10); }
583 float MatrixGetter11(const Dali::Matrix &v) { return MatrixGetter(v,11); }
584 float MatrixGetter12(const Dali::Matrix &v) { return MatrixGetter(v,12); }
585 float MatrixGetter13(const Dali::Matrix &v) { return MatrixGetter(v,13); }
586 float MatrixGetter14(const Dali::Matrix &v) { return MatrixGetter(v,14); }
587 float MatrixGetter15(const Dali::Matrix &v) { return MatrixGetter(v,15); }
588 float MatrixGetter16(const Dali::Matrix &v) { return MatrixGetter(v,16); }
590 void MatrixSetter0(Dali::Matrix &v, float f) { MatrixSetter(v, f, 0); }
591 void MatrixSetter1(Dali::Matrix &v, float f) { MatrixSetter(v, f, 1); }
592 void MatrixSetter2(Dali::Matrix &v, float f) { MatrixSetter(v, f, 2); }
593 void MatrixSetter3(Dali::Matrix &v, float f) { MatrixSetter(v, f, 3); }
594 void MatrixSetter4(Dali::Matrix &v, float f) { MatrixSetter(v, f, 4); }
595 void MatrixSetter5(Dali::Matrix &v, float f) { MatrixSetter(v, f, 5); }
596 void MatrixSetter6(Dali::Matrix &v, float f) { MatrixSetter(v, f, 6); }
597 void MatrixSetter7(Dali::Matrix &v, float f) { MatrixSetter(v, f, 7); }
598 void MatrixSetter8(Dali::Matrix &v, float f) { MatrixSetter(v, f, 8); }
599 void MatrixSetter9(Dali::Matrix &v, float f) { MatrixSetter(v, f, 9); }
600 void MatrixSetter10(Dali::Matrix &v, float f) { MatrixSetter(v, f,10); }
601 void MatrixSetter11(Dali::Matrix &v, float f) { MatrixSetter(v, f,11); }
602 void MatrixSetter12(Dali::Matrix &v, float f) { MatrixSetter(v, f,12); }
603 void MatrixSetter13(Dali::Matrix &v, float f) { MatrixSetter(v, f,13); }
604 void MatrixSetter14(Dali::Matrix &v, float f) { MatrixSetter(v, f,14); }
605 void MatrixSetter15(Dali::Matrix &v, float f) { MatrixSetter(v, f,15); }
606 void MatrixSetter16(Dali::Matrix &v, float f) { MatrixSetter(v, f,16); }
608 float Matrix3Getter0(const Dali::Matrix3 &v) { return MatrixGetter(v, 0); }
609 float Matrix3Getter1(const Dali::Matrix3 &v) { return MatrixGetter(v, 1); }
610 float Matrix3Getter2(const Dali::Matrix3 &v) { return MatrixGetter(v, 2); }
611 float Matrix3Getter3(const Dali::Matrix3 &v) { return MatrixGetter(v, 3); }
612 float Matrix3Getter4(const Dali::Matrix3 &v) { return MatrixGetter(v, 4); }
613 float Matrix3Getter5(const Dali::Matrix3 &v) { return MatrixGetter(v, 5); }
614 float Matrix3Getter6(const Dali::Matrix3 &v) { return MatrixGetter(v, 6); }
615 float Matrix3Getter7(const Dali::Matrix3 &v) { return MatrixGetter(v, 7); }
616 float Matrix3Getter8(const Dali::Matrix3 &v) { return MatrixGetter(v, 8); }
618 void Matrix3Setter0(Dali::Matrix3 &v, float f) { MatrixSetter(v, f, 0); }
619 void Matrix3Setter1(Dali::Matrix3 &v, float f) { MatrixSetter(v, f, 1); }
620 void Matrix3Setter2(Dali::Matrix3 &v, float f) { MatrixSetter(v, f, 2); }
621 void Matrix3Setter3(Dali::Matrix3 &v, float f) { MatrixSetter(v, f, 3); }
622 void Matrix3Setter4(Dali::Matrix3 &v, float f) { MatrixSetter(v, f, 4); }
623 void Matrix3Setter5(Dali::Matrix3 &v, float f) { MatrixSetter(v, f, 5); }
624 void Matrix3Setter6(Dali::Matrix3 &v, float f) { MatrixSetter(v, f, 6); }
625 void Matrix3Setter7(Dali::Matrix3 &v, float f) { MatrixSetter(v, f, 7); }
626 void Matrix3Setter8(Dali::Matrix3 &v, float f) { MatrixSetter(v, f, 8); }
628 val JavascriptUpdateCallback( val::undefined() );
629 bool JavascriptUpdateCallbackSet = false;
631 void JavascriptUpdate(int dt)
633 if( JavascriptUpdateCallbackSet )
635 JavascriptUpdateCallback( val(dt) );
639 void SetUpdateFunction( const emscripten::val& function )
641 JavascriptUpdateCallback = function;
642 JavascriptUpdateCallbackSet = true;
645 const emscripten::val& GetUpdateFunction()
647 return JavascriptUpdateCallback;
651 * Emscripten Bindings
653 * This uses Emscripten 'bind' (similar in design to Boost's python wrapper library).
654 * It provides a simplified way to wrap C++ classes and wraps Emscriptens type
657 * A convention below is that where there is a function or method name prepended
658 * with '__' there is a corresponding Javascript helper function to help with
659 * marshalling parameters and return values.
662 EMSCRIPTEN_BINDINGS(dali_wrapper)
664 // With a little help embind knows about vectors so we tell it which ones to instantiate
665 register_dali_vector<int>("DaliVectorInt");
666 register_vector<std::string>("VectorString");
667 register_vector<int>("VectorInt");
668 register_vector<float>("VectorFloat");
669 register_vector<Dali::Actor>("VectorActor");
672 // Creation functions.
674 emscripten::function("VersionString", &VersionString);
675 emscripten::function("__createActor", &CreateActor);
676 emscripten::function("__createHandle", &CreateHandle);
677 emscripten::function("__createSolidColorActor", &CreateSolidColorActor);
682 emscripten::function("javascriptValue", &JavascriptValue);
683 emscripten::function("__hitTest", &HitTest);
684 emscripten::function("sendMouseEvent", &EmscriptenMouseEvent);
685 emscripten::function("__updateOnce", &EmscriptenUpdateOnce);
686 emscripten::function("__renderOnce", &EmscriptenRenderOnce);
687 emscripten::function("generateControlPoints", &GenerateControlPoints);
690 // Global callback functions
692 emscripten::function("setCallbackGetGlyphImage", &SetCallbackGetGlyphImage);
693 emscripten::function("setCallbackGetImage", &SetCallbackGetImage);
694 emscripten::function("setCallbackGetImageMetadata", &SetCallbackGetImageMetadata);
695 emscripten::function("setCallbackRenderFinished", &SetCallbackRenderFinished);
696 emscripten::function("setUpdateFunction", &SetUpdateFunction);
697 emscripten::function("getUpdateFunction", &GetUpdateFunction);
700 // Property value creation (Javascript can't select on type)
702 emscripten::function("PropertyValueBoolean", &PropertyValueBoolean);
703 emscripten::function("PropertyValueFloat", &PropertyValueFloat);
704 emscripten::function("PropertyValueInteger", &PropertyValueInteger);
705 emscripten::function("PropertyValueString", &PropertyValueString);
706 emscripten::function("PropertyValueVector2", &PropertyValueVector2);
707 emscripten::function("PropertyValueVector3", &PropertyValueVector3);
708 emscripten::function("PropertyValueVector4", &PropertyValueVector4);
709 emscripten::function("PropertyValueMatrix", &PropertyValueMatrix);
710 emscripten::function("PropertyValueMatrix3", &PropertyValueMatrix3);
711 emscripten::function("PropertyValueMap", &PropertyValueContainer);
712 emscripten::function("PropertyValueArray", &PropertyValueContainer);
713 emscripten::function("PropertyValueEuler", &PropertyValueEuler);
714 emscripten::function("PropertyValueAxisAngle", &PropertyValueAxisAngle);
715 emscripten::function("PropertyValueString", &PropertyValueString);
716 emscripten::function("PropertyValueIntRect", &PropertyValueIntRect);
719 // One unfortunate aspect of wrapping for the browser is that we get no notification
720 // of object deletion so all JS wrapper objects must be wrapper.delete() correctly.
722 // Embind has a mechanism around this for simple c style structs decared as value_arrays.
723 // These are immediately transformed to Javascript arrays and don't need explicit
724 // destruction, however the API needs a member offset.
726 value_array<Dali::Internal::Emscripten::Statistics>("Statistics")
727 .element(&Dali::Internal::Emscripten::Statistics::on)
728 .element(&Dali::Internal::Emscripten::Statistics::frameCount)
729 .element(&Dali::Internal::Emscripten::Statistics::lastFrameDeltaSeconds)
730 .element(&Dali::Internal::Emscripten::Statistics::lastSyncTimeMilliseconds)
731 .element(&Dali::Internal::Emscripten::Statistics::nextSyncTimeMilliseconds)
732 .element(&Dali::Internal::Emscripten::Statistics::keepUpdating)
733 .element(&Dali::Internal::Emscripten::Statistics::needsNotification)
734 .element(&Dali::Internal::Emscripten::Statistics::secondsFromLastFrame)
737 value_array<Dali::Vector2>("Vector2")
738 .element(&Dali::Vector2::x)
739 .element(&Dali::Vector2::y)
742 value_array<Dali::Vector3>("Vector3")
743 .element(&Dali::Vector3::x)
744 .element(&Dali::Vector3::y)
745 .element(&Dali::Vector3::z)
748 value_array<Dali::Vector4>("Vector4")
749 .element(&Dali::Vector4::x)
750 .element(&Dali::Vector4::y)
751 .element(&Dali::Vector4::z)
752 .element(&Dali::Vector4::w)
755 value_array<Dali::Matrix>("Matrix")
756 .element(&MatrixGetter0, &MatrixSetter0)
757 .element(&MatrixGetter1, &MatrixSetter1)
758 .element(&MatrixGetter2, &MatrixSetter2)
759 .element(&MatrixGetter3, &MatrixSetter3)
760 .element(&MatrixGetter4, &MatrixSetter4)
761 .element(&MatrixGetter5, &MatrixSetter5)
762 .element(&MatrixGetter6, &MatrixSetter6)
763 .element(&MatrixGetter7, &MatrixSetter7)
764 .element(&MatrixGetter8, &MatrixSetter8)
765 .element(&MatrixGetter9, &MatrixSetter9)
766 .element(&MatrixGetter10, &MatrixSetter10)
767 .element(&MatrixGetter11, &MatrixSetter11)
768 .element(&MatrixGetter12, &MatrixSetter12)
769 .element(&MatrixGetter13, &MatrixSetter13)
770 .element(&MatrixGetter14, &MatrixSetter14)
771 .element(&MatrixGetter15, &MatrixSetter15)
774 value_array<Dali::Matrix3>("Matrix3")
775 .element(&Matrix3Getter0, &Matrix3Setter0)
776 .element(&Matrix3Getter1, &Matrix3Setter1)
777 .element(&Matrix3Getter2, &Matrix3Setter2)
778 .element(&Matrix3Getter3, &Matrix3Setter3)
779 .element(&Matrix3Getter4, &Matrix3Setter4)
780 .element(&Matrix3Getter5, &Matrix3Setter5)
781 .element(&Matrix3Getter6, &Matrix3Setter6)
782 .element(&Matrix3Getter7, &Matrix3Setter7)
783 .element(&Matrix3Getter8, &Matrix3Setter8)
789 enum_<Dali::Property::Type>("PropertyType")
790 .value("NONE", Dali::Property::NONE)
791 .value("BOOLEAN", Dali::Property::BOOLEAN)
792 .value("FLOAT", Dali::Property::FLOAT)
793 .value("INTEGER", Dali::Property::INTEGER)
794 .value("VECTOR2", Dali::Property::VECTOR2)
795 .value("VECTOR3", Dali::Property::VECTOR3)
796 .value("VECTOR4", Dali::Property::VECTOR4)
797 .value("MATRIX3", Dali::Property::MATRIX3)
798 .value("MATRIX", Dali::Property::MATRIX)
799 .value("RECTANGLE", Dali::Property::RECTANGLE)
800 .value("ROTATION", Dali::Property::ROTATION)
801 .value("STRING", Dali::Property::STRING)
802 .value("ARRAY", Dali::Property::ARRAY)
803 .value("MAP", Dali::Property::MAP)
806 enum_<Dali::ShaderEffect::GeometryHints>("GeometryHints")
807 .value("HINT_NONE", Dali::ShaderEffect::HINT_NONE)
808 .value("HINT_GRID_X", Dali::ShaderEffect::HINT_GRID_X)
809 .value("HINT_GRID_Y", Dali::ShaderEffect::HINT_GRID_Y)
810 .value("HINT_GRID", Dali::ShaderEffect::HINT_GRID)
811 .value("HINT_DEPTH_BUFFER", Dali::ShaderEffect::HINT_DEPTH_BUFFER)
812 .value("HINT_BLENDING", Dali::ShaderEffect::HINT_BLENDING)
813 .value("HINT_DOESNT_MODIFY_GEOMETRY", Dali::ShaderEffect::HINT_DOESNT_MODIFY_GEOMETRY)
816 enum_<Dali::Shader::ShaderHints>("ShaderHints")
817 .value("HINT_NONE", Dali::Shader::HINT_NONE)
818 .value("HINT_REQUIRES_SELF_DEPTH_TEST", Dali::Shader::HINT_REQUIRES_SELF_DEPTH_TEST)
819 .value("HINT_OUTPUT_IS_TRANSPARENT", Dali::Shader::HINT_OUTPUT_IS_TRANSPARENT)
820 .value("HINT_OUTPUT_IS_OPAQUE", Dali::Shader::HINT_OUTPUT_IS_OPAQUE)
821 .value("HINT_MODIFIES_GEOMETRY", Dali::Shader::HINT_MODIFIES_GEOMETRY)
824 enum_<Dali::Animation::EndAction>("EndAction")
825 .value("Bake", Dali::Animation::Bake)
826 .value("Discard", Dali::Animation::Discard)
827 .value("BakeFinal", Dali::Animation::BakeFinal)
830 enum_<Dali::Animation::Interpolation>("Interpolation")
831 .value("Linear", Dali::Animation::Interpolation::Linear)
832 .value("Cubic", Dali::Animation::Interpolation::Cubic)
835 enum_<Dali::Geometry::GeometryType>("GeometryType")
836 .value("POINTS", Dali::Geometry::POINTS)
837 .value("LINES", Dali::Geometry::LINES)
838 .value("LINE_LOOP", Dali::Geometry::LINE_LOOP)
839 .value("LINE_STRIP", Dali::Geometry::LINE_STRIP)
840 .value("TRIANGLES", Dali::Geometry::TRIANGLES)
841 .value("TRIANGLE_FAN", Dali::Geometry::TRIANGLE_FAN)
842 .value("TRIANGLE_STRIP", Dali::Geometry::TRIANGLE_STRIP)
845 enum_<Dali::Image::ReleasePolicy>("ReleasePolicy")
846 .value("UNUSED", Dali::Image::UNUSED)
847 .value("NEVER", Dali::Image::NEVER)
850 enum_<Dali::Pixel::Format>("PixelFormat")
851 .value("A8", Dali::Pixel::Format::A8)
852 .value("L8", Dali::Pixel::Format::L8)
853 .value("LA88", Dali::Pixel::Format::LA88)
854 .value("RGB565", Dali::Pixel::Format::RGB565)
855 .value("BGR565", Dali::Pixel::Format::BGR565)
856 .value("RGBA4444", Dali::Pixel::Format::RGBA4444)
857 .value("BGRA4444", Dali::Pixel::Format::BGRA4444)
858 .value("RGBA5551", Dali::Pixel::Format::RGBA5551)
859 .value("BGRA5551", Dali::Pixel::Format::BGRA5551)
860 .value("RGB888", Dali::Pixel::Format::RGB888)
861 .value("RGB8888", Dali::Pixel::Format::RGB8888)
862 .value("BGR8888", Dali::Pixel::Format::BGR8888)
863 .value("RGBA8888", Dali::Pixel::Format::RGBA8888)
864 .value("BGRA8888", Dali::Pixel::Format::BGRA8888)
865 // GLES 3 Standard compressed formats:
866 .value("COMPRESSED_R11_EAC", Dali::Pixel::Format::COMPRESSED_R11_EAC)
867 .value("COMPRESSED_SIGNED_R11_EAC", Dali::Pixel::Format::COMPRESSED_SIGNED_R11_EAC)
868 .value("COMPRESSED_RG11_EAC", Dali::Pixel::Format::COMPRESSED_RG11_EAC)
869 .value("COMPRESSED_SIGNED_RG11_EAC", Dali::Pixel::Format::COMPRESSED_SIGNED_RG11_EAC)
870 .value("COMPRESSED_RGB8_ETC2", Dali::Pixel::Format::COMPRESSED_RGB8_ETC2)
871 .value("COMPRESSED_SRGB8_ETC2", Dali::Pixel::Format::COMPRESSED_SRGB8_ETC2)
872 .value("COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2", Dali::Pixel::Format::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2)
873 .value("COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2", Dali::Pixel::Format::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2)
874 .value("COMPRESSED_RGBA8_ETC2_EAC", Dali::Pixel::Format::COMPRESSED_RGBA8_ETC2_EAC)
875 .value("COMPRESSED_SRGB8_ALPHA8_ETC2_EAC", Dali::Pixel::Format::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC)
876 // GLES 2 extension compressed formats:
877 .value("COMPRESSED_RGB8_ETC1", Dali::Pixel::Format::COMPRESSED_RGB8_ETC1)
878 .value("COMPRESSED_RGB_PVRTC_4BPPV1", Dali::Pixel::Format::COMPRESSED_RGB_PVRTC_4BPPV1)
881 enum_<Dali::Renderer::FaceCullingMode>("FaceCullingMode")
882 .value("NONE", Dali::Renderer::NONE)
883 .value("CULL_BACK", Dali::Renderer::CULL_BACK)
884 .value("CULL_FRONT", Dali::Renderer::CULL_FRONT)
885 .value("CULL_BACK_AND_FRONT", Dali::Renderer::CULL_BACK_AND_FRONT)
888 enum_<Dali::BlendingMode::Type>("BlendingMode")
889 .value("OFF", Dali::BlendingMode::OFF)
890 .value("AUTO", Dali::BlendingMode::AUTO)
891 .value("ON", Dali::BlendingMode::ON)
894 enum_<Dali::AlphaFunction::BuiltinFunction>("AlphaFunction")
895 .value("DEFAULT", Dali::AlphaFunction::BuiltinFunction::DEFAULT)
896 .value("LINEAR", Dali::AlphaFunction::BuiltinFunction::LINEAR)
897 .value("REVERSE", Dali::AlphaFunction::BuiltinFunction::REVERSE)
898 .value("EASE_IN_SQUARE", Dali::AlphaFunction::BuiltinFunction::EASE_IN_SQUARE)
899 .value("EASE_OUT_SQUARE", Dali::AlphaFunction::BuiltinFunction::EASE_OUT_SQUARE)
900 .value("EASE_IN", Dali::AlphaFunction::BuiltinFunction::EASE_IN)
901 .value("EASE_OUT", Dali::AlphaFunction::BuiltinFunction::EASE_OUT)
902 .value("EASE_IN_OUT", Dali::AlphaFunction::BuiltinFunction::EASE_IN_OUT)
903 .value("EASE_IN_SINE", Dali::AlphaFunction::BuiltinFunction::EASE_IN_SINE)
904 .value("EASE_OUT_SINE", Dali::AlphaFunction::BuiltinFunction::EASE_OUT_SINE)
905 .value("EASE_IN_OUT_SINE", Dali::AlphaFunction::BuiltinFunction::EASE_IN_OUT_SINE)
906 .value("BOUNCE", Dali::AlphaFunction::BuiltinFunction::BOUNCE)
907 .value("SIN", Dali::AlphaFunction::BuiltinFunction::SIN)
908 .value("EASE_OUT_BACK", Dali::AlphaFunction::BuiltinFunction::EASE_OUT_BACK)
915 // we need property map as an object rather than straight conversion to javascript 'object'
916 // because its ordered. And PropertyBuffer needs an order.
917 class_<Dali::Property::Map>("PropertyMap")
919 .function("count", &Dali::Property::Map::Count)
920 .function("empty", &Dali::Property::Map::Empty)
921 .function("__insert", select_overload< void(const std::string&, const Dali::Property::Value&) > (&Dali::Property::Map::Insert))
922 .function("__get", &PropertyMapGet)
923 .function("__getValue", &Dali::Property::Map::GetValue)
924 .function("getKey", &Dali::Property::Map::GetKey)
925 .function("clear", &Dali::Property::Map::Clear)
926 .function("merge", &Dali::Property::Map::Merge)
929 class_<Dali::Property::Value>("PropertyValue")
931 .function("getType", &PropertyGetType)
932 .function("getTypeName", &PropertyGetTypeName)
933 .function("getBoolean", &PropertyGetBoolean)
934 .function("getFloat", &PropertyGetFloat)
935 .function("getInteger", &PropertyGetInteger)
936 .function("getVector2", &PropertyGetVector2)
937 .function("getVector3", &PropertyGetVector3)
938 .function("getVector4", &PropertyGetVector4)
939 .function("getString", &PropertyGetString)
940 .function("getMap", &PropertyGetMap)
941 .function("getArray", &PropertyGetArray)
942 .function("getMatrix", &PropertyGetMatrix)
943 .function("getMatrix3", &PropertyGetMatrix3)
944 .function("getEuler", &PropertyGetEuler)
945 .function("getRotation", &PropertyGetRotation)
946 .function("getIntRect", &PropertyGetIntRect)
949 class_<Dali::BaseHandle>("BaseHandle")
950 .function("ok", &BaseHandleOk)
951 .function("getTypeName", &BaseHandle::GetTypeName)
954 class_<Dali::TypeInfo, base<Dali::BaseHandle>>("TypeInfo")
955 .function("getName", &Dali::TypeInfo::GetName)
956 .function("getBaseName", &Dali::TypeInfo::GetBaseName)
957 .function("getProperties", &GetAllProperties)
958 .function("getActions", &GetActions)
959 .function("getSignals", &GetSignals)
960 .function("getPropertyIndices", &Dali::TypeInfo::GetPropertyIndices)
963 class_<Dali::TypeRegistry>("TypeRegistry")
964 .constructor<>(&Dali::TypeRegistry::Get)
965 .function("getTypeNameCount", &Dali::TypeRegistry::GetTypeNameCount)
966 .function("getTypeName", &Dali::TypeRegistry::GetTypeName)
967 .function("getTypeInfo", select_overload< Dali::TypeInfo(const std::string&) > (&Dali::TypeRegistry::GetTypeInfo))
970 class_<SignalHolder>("SignalHolder")
974 class_<Dali::Handle, base<Dali::BaseHandle>>("Handle")
975 .function("__registerProperty", &RegisterProperty)
976 .function("__registerAnimatedProperty", &RegisterAnimatedProperty)
977 .function("setSelf", &SetSelf)
978 .function("setProperty", &SetProperty)
979 .function("getProperty", &GetProperty)
980 .function("getPropertyIndex", &GetPropertyIndex)
981 .function("getProperties", &GetProperties)
982 .function("getPropertyIndices", &Handle::GetPropertyIndices)
983 .function("getPropertyTypeFromName", &GetPropertyTypeFromName)
984 .function("getPropertyTypeName", &GetPropertyTypeName)
985 .function("registerProperty", &RegisterProperty)
986 .function("registerAnimatedProperty", &RegisterAnimatedProperty)
987 .function("getTypeInfo", &GetTypeInfo)
988 .function("isPropertyWritable", &Handle::IsPropertyWritable)
989 .function("isPropertyAnimatable", &Handle::IsPropertyAnimatable)
990 .function("isPropertyAConstraintInput", &Handle::IsPropertyAConstraintInput)
993 class_<Dali::Path, base<Dali::Handle>>("Path")
994 .constructor<>(&Dali::Path::New)
995 .function("addPoint", &Dali::Path::AddPoint)
996 .function("addControlPoint", &Dali::Path::AddControlPoint)
997 .function("generateControlPoints", &Dali::Path::GenerateControlPoints)
998 .function("sample", &Dali::Path::Sample)
999 .function("getPoint", &Dali::Path::GetPoint)
1000 .function("getControlPoint", &Dali::Path::GetControlPoint)
1001 .function("getPointCount", &Dali::Path::GetPointCount)
1004 class_<Dali::KeyFrames>("KeyFrames")
1005 .constructor<>(&Dali::KeyFrames::New)
1006 .function("add", select_overload<void (float progress, Property::Value value)>(&Dali::KeyFrames::Add))
1007 .function("addWithAlpha", &KeyFramesAddWithAlpha)
1010 class_<Dali::Animation>("Animation")
1011 .constructor<float>(&Dali::Animation::New)
1012 .function("__animateTo", &AnimateTo)
1013 .function("__animateBy", &AnimateBy)
1014 .function("__animateBetween", &AnimateBetween)
1015 .function("__animatePath", &AnimatePath)
1016 .function("setDuration", &Dali::Animation::SetDuration)
1017 .function("getDuration", &Dali::Animation::GetDuration)
1018 .function("setLooping", &Dali::Animation::SetLooping)
1019 .function("isLooping", &Dali::Animation::IsLooping)
1020 .function("setEndAction", &Dali::Animation::SetEndAction)
1021 .function("getEndAction", &Dali::Animation::GetEndAction)
1022 .function("setDisconnectAction", &Dali::Animation::SetDisconnectAction)
1023 .function("getDisconnectAction", &Dali::Animation::GetDisconnectAction)
1024 .function("setCurrentProgress", &Dali::Animation::SetCurrentProgress)
1025 .function("getCurrentProgress", &Dali::Animation::GetCurrentProgress)
1026 .function("setSpeedFactor", &Dali::Animation::SetSpeedFactor)
1027 .function("getSpeedFactor", &Dali::Animation::GetSpeedFactor)
1028 .function("setPlayRange", &Dali::Animation::SetPlayRange)
1029 .function("getPlayRange", &Dali::Animation::GetPlayRange)
1030 .function("play", &Dali::Animation::Play)
1031 .function("playFrom", &Dali::Animation::PlayFrom)
1032 .function("pause", &Dali::Animation::Pause)
1033 .function("stop", &Dali::Animation::Stop)
1034 .function("clear", &Dali::Animation::Clear)
1037 class_<Dali::PropertyBuffer>("PropertyBuffer")
1038 .constructor<Dali::Property::Map&>(Dali::PropertyBuffer::New)
1039 .function("setData", &SetPropertyBufferDataRaw)
1042 class_<Dali::Geometry>("Geometry")
1043 .constructor<>(&Dali::Geometry::New)
1044 .function("addVertexBuffer", &Dali::Geometry::AddVertexBuffer)
1045 .function("getNumberOfVertexBuffers", &Dali::Geometry::GetNumberOfVertexBuffers)
1046 .function("setIndexBuffer", &Dali::Geometry::SetIndexBuffer)
1047 .function("setGeometryType", &Dali::Geometry::SetGeometryType)
1048 .function("getGeometryType", &Dali::Geometry::GetGeometryType)
1049 .function("setRequiresDepthTesting", &Dali::Geometry::SetRequiresDepthTesting)
1050 .function("getRequiresDepthTesting", &Dali::Geometry::GetRequiresDepthTesting)
1053 class_<Dali::Image>("Image")
1056 class_<Dali::BufferImage, base<Dali::Image> >("BufferImage")
1057 .constructor<const std::string&, unsigned int, unsigned int, Dali::Pixel::Format>(&BufferImageNew)
1060 class_<Dali::EncodedBufferImage, base<Dali::Image> >("EncodedBufferImage")
1061 .constructor<const std::string&>(&EncodedBufferImageNew)
1064 class_<Dali::Sampler>("Sampler")
1065 .constructor<>(&Dali::Sampler::New)
1068 class_<Dali::Shader, base<Dali::Handle>>("Shader")
1069 .constructor<>(&Dali::Shader::New)
1072 class_<Dali::TextureSet, base<Dali::Handle>>("TextureSet")
1073 .constructor<>(&Dali::TextureSet::New)
1074 .function("setImage", &Dali::TextureSet::SetImage)
1075 .function("setSampler", &Dali::TextureSet::SetSampler)
1076 .function("getImage", &Dali::TextureSet::GetImage)
1077 .function("getSampler", &Dali::TextureSet::GetSampler)
1078 .function("getTextureCount", &Dali::TextureSet::GetTextureCount)
1081 class_<Dali::Renderer, base<Dali::Handle>>("Renderer")
1082 .constructor<>(&Dali::Renderer::New)
1083 .function("setGeometry", &Dali::Renderer::SetGeometry)
1084 .function("getGeometry", &Dali::Renderer::GetGeometry)
1085 .function("SetTextures", &Dali::Renderer::SetTextures)
1086 .function("SetTextures", &Dali::Renderer::SetTextures)
1089 class_<Dali::ShaderEffect, base<Dali::Handle>>("ShaderEffect")
1090 .constructor<const std::string&, const std::string&,
1091 const std::string&, const std::string&,
1092 int >(&CreateShaderEffect)
1093 .function("setEffectImage", &Dali::ShaderEffect::SetEffectImage)
1094 .function("__setUniform", &SetUniform)
1097 class_<Dali::Actor, base<Dali::Handle>>("Actor")
1098 .constructor<>(&Dali::Actor::New)
1099 .function("add", &Dali::Actor::Add)
1100 .function("remove", &Dali::Actor::Remove)
1101 .function("getId", &Dali::Actor::GetId)
1102 .function("__getParent", &Dali::Actor::GetParent)
1103 .function("__findChildById", &Dali::Actor::FindChildById)
1104 .function("__findChildByName", &Dali::Actor::FindChildByName)
1105 .function("__getChildAt", &Dali::Actor::GetChildAt)
1106 .function("getChildCount", &Dali::Actor::GetChildCount)
1107 .function("__screenToLocal",
1108 select_overload<std::vector<float> (Dali::Actor, float, float)>(&ScreenToLocal))
1109 .function("addressOf", &AddressOf)
1110 .function("__connect", &ConnectSignal)
1111 .function("__setPropertyNotification", &SetPropertyNotification)
1112 .function("addRenderer", &Dali::Actor::AddRenderer)
1113 .function("getRendererCount", &Dali::Actor::GetRendererCount)
1114 .function("removeRenderer",
1115 select_overload<void(unsigned int)>(&Dali::Actor::RemoveRenderer))
1116 .function("__getRendererAt", &Dali::Actor::GetRendererAt)
1119 class_<Dali::CameraActor, base<Dali::Actor>>("CameraActor")
1120 .constructor<>( select_overload<Dali::CameraActor()>(&Dali::CameraActor::New))
1123 class_<Dali::Layer, base<Dali::Actor>>("Layer")
1124 .constructor<>(&Dali::Layer::New)
1125 .function("raise", &Dali::Layer::Raise)
1126 .function("lower", &Dali::Layer::Lower)
1129 class_<Dali::Stage>("Stage")
1130 .constructor<>(&Dali::Stage::GetCurrent)
1131 .function("add", &Dali::Stage::Add)
1132 .function("remove", &Dali::Stage::Remove)
1133 .function("__getRootLayer", &Dali::Stage::GetRootLayer)
1134 .function("getLayer", &Dali::Stage::GetLayer)
1135 .function("getRenderTaskList", &Dali::Stage::GetRenderTaskList)
1136 .function("setBackgroundColor", &Dali::Stage::SetBackgroundColor)
1139 class_<Dali::RenderTaskList>("RenderTaskList")
1140 .function("createTask", &Dali::RenderTaskList::CreateTask)
1141 .function("removeTask", &Dali::RenderTaskList::RemoveTask)
1142 .function("getTaskCount", &Dali::RenderTaskList::GetTaskCount)
1143 .function("getTask", &Dali::RenderTaskList::GetTask)
1146 class_<Dali::RenderTask>("RenderTask")
1147 .function("__getCameraActor", &Dali::RenderTask::GetCameraActor)
1148 .function("setCameraActor", &Dali::RenderTask::SetCameraActor)
1149 .function("setSourceActor", &Dali::RenderTask::SetSourceActor)
1150 .function("setExclusive", &Dali::RenderTask::SetExclusive)
1151 .function("setInputEnabled", &Dali::RenderTask::SetInputEnabled)
1152 .function("setViewportPosition", &Dali::RenderTask::SetViewportPosition)
1153 .function("setViewportSize", &Dali::RenderTask::SetViewportSize)
1154 .function("getCurrentViewportPosition", &Dali::RenderTask::GetCurrentViewportPosition)
1155 .function("getCurrentViewportSize", &Dali::RenderTask::GetCurrentViewportSize)
1156 .function("setClearColor", &Dali::RenderTask::SetClearColor)
1157 .function("getClearColor", &Dali::RenderTask::GetClearColor)
1158 .function("setClearEnabled", &Dali::RenderTask::SetClearEnabled)
1159 .function("getClearEnabled", &Dali::RenderTask::GetClearEnabled)
1160 .function("screenToLocal",
1161 select_overload<Dali::Vector2(Dali::RenderTask, Dali::Actor, float, float)>(&ScreenToLocal))
1162 .function("worldToScreen", &WorldToScreen)
1167 }; // namespace Emscripten
1168 }; // namespace Internal
1169 }; // namespace Dali