# limitations under the License.
#
-SUBDIRS = dali-toolkit docs
+SUBDIRS = dali-toolkit
+
+if ENABLE_JAVASCRIPT_PLUGIN
+SUBDIRS +=plugins
+endif
+
+# perform documentation last, so it doesn't prevent code from building if there's an error
+SUBDIRS += docs
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = dali-toolkit.pc
[enable_debug=$enableval],
[enable_debug=no])
+# option for JavaScript plugin
+AC_ARG_ENABLE(javascript,
+ [AC_HELP_STRING([--enable-javascript],
+ [Enable JavaScript plugin])] ,
+ [enable_javascript=yes],
+ [enable_javascript=no])
+
if test "x$enable_debug" = "xyes"; then
DALI_TOOLKIT_CFLAGS="$DALI_TOOLKIT_CFLAGS -DDEBUG_ENABLED"
+ DALI_SCRIPTV8_CFLAGS="$DALI_TOOLKIT_CFLAGS -DDEBUG_ENABLED"
fi
if test "x$enable_debug" = "xno" -a "x$enable_exportall" = "xno"; then
DALI_TOOLKIT_CFLAGS="$DALI_TOOLKIT_CFLAGS -fvisibility=hidden -DHIDE_DALI_INTERNALS"
+ DALI_SCRIPTV8_CFLAGS="$DALI_TOOLKIT_CFLAGS -fvisibility=hidden -DHIDE_DALI_INTERNALS"
fi
+#set a variable for the makefile to conditionally compile the plugin
+AM_CONDITIONAL([ENABLE_JAVASCRIPT_PLUGIN], [test x$enable_javascript = xyes])
+
+
# Tizen Profile options
AC_ARG_ENABLE([profile],
[AC_HELP_STRING([--enable-profile=COMMON,MOBILE,LITE,WEARABLE,TV],
AC_SUBST(dataReadWriteDir)
AC_SUBST(dataReadOnlyDir)
AC_SUBST(DALI_TOOLKIT_CFLAGS)
+AC_SUBST(DALI_SCRIPTV8_CFLAGS)
+AC_SUBST(DALI_SCRIPTV8_LIBS)
# Specify the include directory for development headers
#devincludepath=${includedir}/dali/internal
AC_CONFIG_FILES([
Makefile
dali-toolkit/Makefile
+ plugins/Makefile
dali-toolkit.pc
docs/Makefile
docs/dali.doxy
-------------
Prefix: $prefix
Debug Build: $enable_debug
+ JavaScript support (V8 required) $enable_javascript
Profile: $dali_profile
Data Dir (Read/Write): $dataReadWriteDir
Data Dir (Read Only): $dataReadOnlyDir
publicapibubbleeffectdir = $(publicapidir)/shader-effects/bubble-effect
publicapistylingdir = $(publicapidir)/styling
publicapitransitioneffectsdir = $(publicapidir)/transition-effects
+publicapiscriptingdir = $(publicapidir)/scripting
publicapi_HEADERS = $(public_api_header_files)
publicapicontrols_HEADERS = $(public_api_controls_header_files)
publicapipageturnview_HEADERS = $(public_api_page_turn_view_header_files)
publicapipopup_HEADERS = $(public_api_popup_header_files)
publicapiscrollbar_HEADERS = $(public_api_scroll_bar_header_files)
+
publicapiscrollcomponent_HEADERS = $(public_api_scroll_component_header_files)
publicapiscrollable_HEADERS = $(public_api_scrollable_header_files)
publicapiscrollview_HEADERS = $(public_api_scroll_view_header_files)
publicapibubbleeffect_HEADERS = $(public_api_bubble_effect_header_files)
publicapistyling_HEADERS = $(public_api_styling_header_files)
publicapitransitioneffects_HEADERS = $(public_api_transition_effects_header_files)
+publicapiscripting_HEADERS = $(public_api_scripting_header_files)
+
--- /dev/null
+#
+# Copyright (c) 2015 Samsung Electronics Co., Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Build the Dali Toolkit library
+
+plugin_src_dir = ../../../plugins
+
+include ../../../plugins/dali-script-v8/file.list
+
+DALI_SCRIPTV8_LIBS="-lv8 -lpthread"
+
+lib_LTLIBRARIES = libdali-script-plugin-v8.la
+
+# force the source code to include the directory the wrapper file is in
+# e.g. actors/actor-api.h to copy the same include style as dali-core
+# The reason for including toolkit paths directly instead of just the
+# install path for dali-toolkit.h, is dali-toolkit.h is not installed yet.
+# It won't be installed until the rpm is installed, and unfortunately the
+# plugin is part of the same rpm
+script_plugin_v8_includes = -I../../../plugins/dali-script-v8/src \
+ -I../../../plugins/dali-script-v8/src/utils \
+ -I../../../
+
+
+libdali_script_plugin_v8_la_SOURCES = \
+ $(script_v8_plugin_src_files)
+
+libdali_script_plugin_v8_la_DEPENDENCIES =
+
+libdali_script_plugin_v8_la_CXXFLAGS = -DDALI_COMPILATION \
+ $(DALI_TOOLKIT_CFLAGS) \
+ $(DALICORE_CFLAGS) \
+ -DDALI_DATA_READ_ONLY_DIR="\"${dataReadOnlyDir}\"" \
+ $(DALI_CFLAGS) \
+ $(DLOG_CFLAGS) \
+ $(DALI_SCRIPTV8_CFLAGS) \
+ -I../../.. \
+ $(script_plugin_v8_includes) \
+ -Werror -Wall
+
+libdali_script_plugin_v8_la_LIBADD = \
+ $(DALICORE_LIBS) \
+ $(DALI_LIBS) \
+ $(DLOG_LIBS) \
+ $(DALI_SCRIPTV8_LIBS)
+
+libdali_script_plugin_v8_la_LDFLAGS = \
+ -rdynamic
#include <dali/dali.h>
// Toolkit
-
+#include <dali-toolkit/public-api/builder/builder.h>
+#include <dali-toolkit/public-api/builder/tree-node.h>
#include <dali-toolkit/public-api/controls/alignment/alignment.h>
#include <dali-toolkit/public-api/controls/bloom-view/bloom-view.h>
#include <dali-toolkit/public-api/controls/bubble-effect/bubble-emitter.h>
#include <dali-toolkit/public-api/markup-processor/markup-processor.h>
+#include <dali-toolkit/public-api/scripting/script.h>
+#include <dali-toolkit/public-api/scripting/script-plugin.h>
+
#include <dali-toolkit/public-api/shader-effects/alpha-discard-effect.h>
#include <dali-toolkit/public-api/shader-effects/bendy-effect.h>
#include <dali-toolkit/public-api/shader-effects/blind-effect.h>
$(toolkit_src_dir)/transition-effects/cube-transition-effect-impl.cpp \
$(toolkit_src_dir)/transition-effects/cube-transition-cross-effect-impl.cpp \
$(toolkit_src_dir)/transition-effects/cube-transition-fold-effect-impl.cpp \
- $(toolkit_src_dir)/transition-effects/cube-transition-wave-effect-impl.cpp
+ $(toolkit_src_dir)/transition-effects/cube-transition-wave-effect-impl.cpp \
+ $(toolkit_src_dir)/scripting/script-impl.cpp \
+ $(toolkit_src_dir)/scripting/script-plugin-proxy.cpp
+
--- /dev/null
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "script-impl.h"
+
+// INTERNAL INCLUDES
+#include <dali/integration-api/debug.h>
+#include "script-plugin-proxy.h"
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+namespace Internal
+{
+
+namespace
+{
+const char* PLUGIN_FILE = "libdali-script-plugin-v8.so";
+}
+
+void Script::ExecuteFile( const std::string& filename )
+{
+ if( mPlugin )
+ {
+ mPlugin->ExecuteFile(filename);
+ }
+}
+
+Script::Script(void) : mPlugin(NULL)
+{
+ ScriptPluginProxy *plugin = new ScriptPluginProxy( PLUGIN_FILE );
+
+ if( mPlugin )
+ {
+ DALI_LOG_WARNING("Reloading script plugin %s, is this what you wanted to do?",PLUGIN_FILE);
+ delete mPlugin;
+ mPlugin = NULL;
+ }
+
+ if( plugin->IsInitialized() )
+ {
+ mPlugin = plugin;
+ }
+ else
+ {
+ delete plugin;
+ }
+
+}
+
+Script::~Script()
+{
+ if( mPlugin )
+ {
+ delete mPlugin;
+ }
+}
+
+} // namespace Internal
+
+} // namespace Toolkit
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_TOOLKIT_INTERNAL_SCRIPT_H__
+#define __DALI_TOOLKIT_INTERNAL_SCRIPT_H__
+
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/public-api/scripting/script.h>
+#include <dali-toolkit/public-api/scripting/script-plugin.h>
+
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+namespace Internal
+{
+
+class Script;
+
+/**
+ * @copydoc Toolkit::Script
+ */
+class Script : public Dali::BaseObject
+{
+public:
+
+ /**
+ * @brief Constructor
+ */
+ Script();
+
+ /**
+ * @copydoc Toolkit::Script::ExecuteFile
+ */
+ void ExecuteFile( const std::string& filename );
+
+protected:
+
+ /**
+ * @brief virtual destructor
+ */
+ virtual ~Script();
+
+private:
+
+ /**
+ * @brief Undefined copy constructor
+ */
+ Script(const Script&);
+
+ /**
+ * @brief Undefined assignment operator
+ */
+ Script& operator=(const Script& rhs);
+
+private: // data
+
+ ScriptPlugin* mPlugin; ///< plugin
+
+};
+
+} // namespace Internal
+
+inline Internal::Script& GetImpl(Dali::Toolkit::Script& obj)
+{
+ DALI_ASSERT_ALWAYS(obj);
+
+ Dali::BaseObject& handle = obj.GetBaseObject();
+
+ return static_cast<Internal::Script&>(handle);
+}
+
+inline const Internal::Script& GetImpl(const Dali::Toolkit::Script& obj)
+{
+ DALI_ASSERT_ALWAYS(obj);
+
+ const Dali::BaseObject& handle = obj.GetBaseObject();
+
+ return static_cast<const Internal::Script&>(handle);
+}
+
+
+} // namespace Toolkit
+
+} // namespace Dali
+
+#endif // __DALI_TOOLKIT_INTERNAL_SCRIPT_H__
--- /dev/null
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "script-plugin-proxy.h"
+
+// INTERNAL INCLUDES
+#include <dali/integration-api/debug.h>
+
+// EXTERNAL INCLUDES
+#include <dlfcn.h>
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+namespace Internal
+{
+
+ScriptPluginProxy::ScriptPluginProxy( const std::string& sharedObjectName)
+: mLibHandle(NULL),
+ mCreatePluginFunctionPtr(NULL),
+ mDestroyPluginFunctionPtr(NULL),
+ mScriptingPlugin(NULL),
+ mSharedObjectName(sharedObjectName),
+ mIsInitialized(false)
+{
+ Initialize();
+}
+
+ScriptPluginProxy::~ScriptPluginProxy()
+{
+ UnInitialize();
+}
+
+void ScriptPluginProxy::SetFlags(const std::string& flags)
+{
+ if( mIsInitialized )
+ {
+ mScriptingPlugin->SetFlags( flags );
+ }
+}
+
+void ScriptPluginProxy::ExecuteBuffer(const std::string &buffer, const std::string &filename)
+{
+ if( mIsInitialized )
+ {
+ mScriptingPlugin->ExecuteBuffer( buffer, filename );
+ }
+}
+
+void ScriptPluginProxy::ExecuteFile(const std::string &filename)
+{
+ if( mIsInitialized )
+ {
+ mScriptingPlugin->ExecuteFile( filename );
+ }
+}
+
+bool ScriptPluginProxy::IsInitialized() const
+{
+ return mIsInitialized;
+};
+
+
+void ScriptPluginProxy::Initialize()
+{
+ if( mIsInitialized )
+ {
+ return;
+ }
+
+ // dl library maintains link counts if you call this twice on the same library
+ // (so its okay to do but we should close every handle we get too)
+ mLibHandle = dlopen( mSharedObjectName.c_str(), RTLD_NOW | RTLD_GLOBAL );
+ if( !mLibHandle )
+ {
+ DALI_LOG_ERROR( "Cannot load dali script plugin. %s\n", dlerror() );
+ return;
+ }
+
+ // reset errors
+ dlerror();
+
+ // load plugin
+ mCreatePluginFunctionPtr = reinterpret_cast<ScriptPlugin::Create*>( dlsym( mLibHandle, "CreateScriptPlugin" ) );
+ if( !mCreatePluginFunctionPtr )
+ {
+ DALI_LOG_ERROR( "Cannot load symbol CreateScriptPlugin(). %s\n", dlerror() );
+ return;
+ }
+
+ // reset errors
+ dlerror();
+
+ mDestroyPluginFunctionPtr = reinterpret_cast<ScriptPlugin::Destroy*>( dlsym( mLibHandle, "DestroyScriptPlugin" ) );
+ if( !mDestroyPluginFunctionPtr )
+ {
+ DALI_LOG_ERROR( "Cannot load symbol:DestroyScriptPlugin(). %s\n", dlerror() );
+ return;
+ }
+
+ // reset errors
+ dlerror();
+
+ mScriptingPlugin = mCreatePluginFunctionPtr();
+
+ if( !mScriptingPlugin )
+ {
+ DALI_LOG_ERROR( "Call to function CreateFeedbackPlugin() failed\n" );
+ return;
+ }
+
+ mIsInitialized = true;
+}
+
+void ScriptPluginProxy::UnInitialize()
+{
+ if( mScriptingPlugin )
+ {
+ mDestroyPluginFunctionPtr( mScriptingPlugin );
+ }
+
+ if( mLibHandle )
+ {
+ if( dlclose( mLibHandle ) )
+ {
+ DALI_LOG_ERROR( "Error closing dali plugin library: %s\n", dlerror() );
+ }
+ }
+ mIsInitialized = false;
+}
+} // namespace Adaptor
+
+} // namespace Internal
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_INTERNAL_SCRIPT_PLUGIN_PROXY_H__
+#define __DALI_INTERNAL_SCRIPT_PLUGIN_PROXY_H__
+
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <dali-toolkit/public-api/scripting/script-plugin.h>
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+namespace Internal
+{
+
+/**
+ * @brief Proxy class to dynamically load, use and unload script plugin.
+ *
+ *
+ */
+class ScriptPluginProxy : public ScriptPlugin
+{
+public:
+
+ /**
+ * @brief Constructor
+ * @param sharedObjectName so file to load
+ */
+ ScriptPluginProxy( const std::string& sharedObjectName);
+
+ /**
+ * @brief destructor
+ */
+ virtual ~ScriptPluginProxy();
+
+ /**
+ * Set engine configuration flags
+ * @param [in] flags string. Format dependent on the scripting engine.
+ */
+ virtual void SetFlags( const std::string& flags );
+
+ /**
+ * @brief Exececute the buffer contents as a script
+ * @param [in] buffer script file contents
+ * @param [in] filename a nominal name for the buffer contents.
+ * (NB filename extension may be used to disambiguate script language)
+ */
+ virtual void ExecuteBuffer( const std::string& buffer, const std::string& filename );
+
+ /**
+ * @brief execture the file as a script
+ * @param [in] filename the filename to read and execute
+ */
+ virtual void ExecuteFile( const std::string& fileName );
+
+ /**
+ * @brief check if the plugin is initialized
+ * @return true if it's initialized
+ */
+ bool IsInitialized() const;
+
+private:
+ /**
+ * @brief Dynamically loads the script plugin.
+ */
+ void Initialize();
+
+ /**
+ * @brief Unloads the script plugin.
+ */
+ void UnInitialize();
+
+private:
+
+ void* mLibHandle;
+ ScriptPlugin::Create* mCreatePluginFunctionPtr;
+ ScriptPlugin::Destroy* mDestroyPluginFunctionPtr;
+ ScriptPlugin* mScriptingPlugin;
+ std::string mSharedObjectName;
+ bool mIsInitialized;
+
+};
+
+} // namespace Adaptor
+
+} // namespace Internal
+
+} // namespace Dali
+
+#endif // __DALI_INTERNAL_SCRIPT_PLUGIN_PROXY_H__
$(public_api_src_dir)/transition-effects/cube-transition-effect.cpp \
$(public_api_src_dir)/transition-effects/cube-transition-fold-effect.cpp \
$(public_api_src_dir)/transition-effects/cube-transition-wave-effect.cpp \
+ $(public_api_src_dir)/scripting/script.cpp \
$(public_api_src_dir)/dali-toolkit-version.cpp \
$(public_api_src_dir)/enums.cpp
$(public_api_src_dir)/transition-effects/cube-transition-fold-effect.h \
$(public_api_src_dir)/transition-effects/cube-transition-wave-effect.h
+public_api_scripting_header_files = \
+ $(public_api_src_dir)/scripting/script.h \
+ $(public_api_src_dir)/scripting/script-plugin.h
+
--- /dev/null
+#ifndef __DALI_SCRIPT_PLUGIN_H__
+#define __DALI_SCRIPT_PLUGIN_H__
+
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <dali/public-api/common/dali-common.h>
+#include <string>
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+/**
+ * @brief Abstract interface to provide scripting support.
+ *
+ * A plugin must export the following functions to create / destroy the object
+ * CreateScriptPlugin() // returns a pointer to a ScriptPlugin object
+ * DestroyScriptPlugin() // destroys the plugin
+ */
+class DALI_IMPORT_API ScriptPlugin
+{
+public:
+
+
+ /**
+ * Function pointer called in toolkit to create a ScriptPlugin plugin instance.
+ * @return Pointer to the newly created plugin object
+ */
+ typedef ScriptPlugin* Create();
+
+ /**
+ * Function pointer called in toolkit to Unload the plugin.
+ * @param plugin The plugin object created and returned by CreateScriptPluginPlugin().
+ */
+ typedef void Destroy(ScriptPlugin* plugin);
+
+ /**
+ * virtual Destructor.
+ */
+ virtual ~ScriptPlugin() {};
+
+ /**
+ * Set engine configuration flags
+ * @param [in] flags string. Format dependent on the scripting engine.
+ */
+ virtual void SetFlags(const std::string& flags) = 0;
+
+ /**
+ * Exec buffer contents as a script
+ * @param buffer script file contents
+ * @param filename a nominal name for the buffer contents.
+ * (NB filename extension may be used to disambiguate script language)
+ */
+ virtual void ExecuteBuffer(const std::string& buffer, const std::string& filename) = 0;
+
+ /**
+ * Exec file as a script
+ * @param filename the filename to read and execute
+ */
+ virtual void ExecuteFile(const std::string& filename) = 0;
+
+}; // class ScriptPlugin
+
+} // namespace Toolkit
+
+} // namespace Dali
+
+#endif // __DALI_SCRIPT_PLUGIN_H__
--- /dev/null
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "script.h"
+
+// INTERNAL INCLUDES
+#include <dali/integration-api/debug.h>
+#include <dali-toolkit/internal/scripting/script-impl.h>
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+Script::Script()
+{
+}
+
+Script::~Script()
+{
+}
+
+Script Script::New(void)
+{
+ return Script(new Internal::Script());
+}
+
+Script::Script(Internal::Script *impl)
+ : BaseHandle(impl)
+{
+}
+
+void Script::ExecuteFile( const std::string &filename )
+{
+ GetImpl(*this).ExecuteFile( filename );
+}
+
+} // namespace Toolkit
+
+} // namespace Dali
+
--- /dev/null
+#ifndef __DALI_TOOLKIT_SCRIPT_H__
+#define __DALI_TOOLKIT_SCRIPT_H__
+
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// INTERNAL INCLUDES
+#include <dali/public-api/common/dali-common.h>
+#include <dali.h>
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+namespace Internal DALI_INTERNAL
+{
+class Script;
+}
+
+/**
+ * Script
+ * This class provides the ability to execute script in a supported language.
+ * Specific script language support is provided through plugins.
+ *
+ * For Example.
+ *
+ * @code
+ *
+ * Script script = Script::New();
+ *
+ * script.ExecuteFile("bump-map.js");
+ *
+ * @endcode
+ *
+ */
+class DALI_IMPORT_API Script : public BaseHandle
+{
+
+public:
+
+ /**
+ * Create an Script handle; this can be initialised with Script::New()
+ * Calling member functions with an uninitialised handle is not allowed.
+ */
+ Script();
+
+ /**
+ * Creates an Script object.
+ * @return A handle to the Script control.
+ */
+ static Script New();
+
+ /**
+ * Virtual destructor.
+ */
+ ~Script();
+
+ /**
+ * Executes the contents of filename in a scripted environment.
+ * @pre A Dali Application object exists
+ * @param filename A filename of a script file to execute
+ */
+ void ExecuteFile( const std::string& filename );
+
+private:
+
+ Script(Internal::Script *impl);
+
+}; // class Script
+
+} // namespace Toolkit
+
+} // namespace Dali
+
+#endif // __DALI_TOOLKIT_SCRIPT_H__
--- /dev/null
+/**
+ *
+
+Multi-Touch Events
+==================
+
+Touch events are received via signals.
+
+For C++ API see Dali::Actor::TouchedSignal() and Dali::Actor::HoveredSignal() for more details.
+
+For JavaScript use actor.connect( "touched", myCallback ) and actor.connect("hovered", myCallback );
+
+### Hit Testing Rules Summary:
+
+ - An actor is only hittable if the actor's touch signal has a connection.
+ - An actor is only hittable when it is between the camera's near and far planes.
+ - If an actor is made insensitive, then the actor and its children are not hittable; see Dali::Actor::IsSensitive()
+ - If an actor's visibility flag is unset, then none of its children are hittable either; see Dali::Actor::IsVisible()
+ - To be hittable, an actor must have a non-zero size.
+ - If an actor's world color is fully transparent, then it is not hittable; see GetCurrentWorldColor()
+
+### Hit Test Algorithm:
+
+ - RenderTasks
+ - Hit testing is dependent on the camera used, which is specific to each RenderTask.
+
+ - Layers
+ - For each RenderTask, hit testing starts from the top-most layer and we go through all the
+ layers until we have a hit or there are none left.
+ - Before we perform a hit test within a layer, we check if all the layer's parents are visible
+ and sensitive.
+ - If they are not, we skip hit testing the actors in that layer altogether.
+ - If a layer is set to consume all touch, then we do not check any layers behind this layer.
+
+ - Actors
+ - The final part of hit testing is performed by walking through the actor tree within a layer.
+ - The following pseudocode shows the algorithm used:
+
+
+~~~
+ HIT-TEST-WITHIN-LAYER( ACTOR )
+ {
+ // Only hit-test the actor and its children if it is sensitive and visible
+ IF ( ACTOR-IS-SENSITIVE &&
+ ACTOR-IS-VISIBLE )
+ {
+ // Depth-first traversal within current layer, visiting parent first
+
+ // Check whether current actor should be hit-tested
+ IF ( TOUCH-SIGNAL-NOT-EMPTY &&
+ ACTOR-HAS-NON-ZERO-SIZE &&
+ ACTOR-WORLD-COLOR-IS-NOT-TRANSPARENT )
+ {
+ // Hit-test current actor
+ IF ( ACTOR-HIT )
+ {
+ IF ( ACTOR-IS-OVERLAY || ( DISTANCE-TO-ACTOR < DISTANCE-TO-LAST-HIT-ACTOR ) )
+ {
+ // The current actor is the closest actor that was underneath the touch
+ LAST-HIT-ACTOR = CURRENT-ACTOR
+ }
+ }
+ }
+
+ // Keep checking children, in case we hit something closer
+ FOR-EACH CHILD (in order)
+ {
+ IF ( CHILD-IS-NOT-A-LAYER )
+ {
+ // Continue traversal for this child's sub-tree
+ HIT-TEST-WITHIN-LAYER ( CHILD )
+ }
+ // else we skip hit-testing the child's sub-tree altogether
+ }
+ }
+ }
+~~~
+ - Overlays always take priority (i.e. they're considered closer) regardless of distance.
+ The overlay children take priority over their parents, and overlay siblings take priority
+ over their previous siblings (i.e. reverse of rendering order):
+
+~~~
+ 1
+ / \
+ / \
+ 2 5
+ / \ \
+ / \ \
+3 4 6
+
+Hit Priority of above Actor tree (all overlays): 1 - Lowest. 6 - Highest.
+~~~
+
+ - Stencil Actors can be used to influence the result of hits within a layer.
+ If a Stencil Actor exists on a layer and that Actor is marked visible then a successful
+ hit can only take place in the area that the stencil Actor marks as visible.
+ The hit can be in any Stencil Actor in that layer, but must be in the region of one of them.
+ Stencil Actor inheritance behaves as with rendering in that any child of a Stencil Actor will
+ also be considered a Stencil Actor.
+
+ <i>Touch Event Delivery:</i>
+
+ - Delivery
+ - The hit actor's touch signal is emitted first; if it is not consumed by any of the listeners,
+ the parent's touch signal is emitted, and so on.
+ - If there are several touch points, then the delivery is only to the first touch point's hit
+ actor (and its parents). There will be NO touch signal delivery for the hit actors of the
+ other touch points.
+ - The local coordinates are from the top-left (0.0f, 0.0f, 0.5f) of the hit actor.
+ - The following pseudocode shows the delivery mechanism:
+
+~~~
+ EMIT-TOUCH-SIGNAL( ACTOR )
+ {
+ IF ( TOUCH-SIGNAL-NOT-EMPTY )
+ {
+ // Only do the emission if touch signal of actor has connections.
+ CONSUMED = TOUCHED-SIGNAL( TOUCH-EVENT )
+ }
+
+ IF ( NOT-CONSUMED )
+ {
+ // If event is not consumed then deliver it to the parent unless we reach the root actor
+ IF ( ACTOR-PARENT )
+ {
+ EMIT-TOUCH-SIGNAL( ACTOR-PARENT )
+ }
+ }
+ }
+~~~
+ - Leave State
+ - A "Leave" state is set when the first point exits the bounds of the previous first point's
+ hit actor (primary hit actor).
+ - When this happens, the last primary hit actor's touch signal is emitted with a "Leave" state
+ (only if it requires leave signals); see the actor property leaveRequired.
+
+
+ - Interrupted State
+ - If a system event occurs which interrupts the touch processing, then the last primary hit
+ actor's touch signals are emitted with an "Interrupted" state.
+ - If the last primary hit actor, or one of its parents, is no longer touchable, then its
+ touch signals are also emitted with an "Interrupted" state.
+ - If the consumed actor on touch-down is not the same as the consumed actor on touch-up, then
+ touch signals are also emitted from the touch-down actor with an "Interrupted" state.
+
+@class MultiTouch
+*
+*/
--- /dev/null
+docs/generated
--- /dev/null
+/generated/*
+
+
+
+
+
--- /dev/null
+// Follow instructions on the internets on how to install yuidoc
+// Then run this command
+
+yuidoc --config yuidoc.json -e ".cpp,.js,.md" -o generated .. ../../../docs/content/shared-javascript-and-cpp-documentation/
+
+// -e says what extensions to pass, we have comments in js and cpp files
+// -o specifies output directory ( in this case we output to a folder called generated)
+// The list of directories after the generated, is the folders to scan for documentation
+
+To view the output
+firefox generated/index.html &
--- /dev/null
+/**
+ *
+ ## Actor API
+
+ Actor is the primary object with which Dali applications interact. UI controls can be built by combining multiple actors.
+
+ There are different types of Actors supported by Dali. They all have the same
+ base functionality of the actor class.
+
+```
+var actor = new dali.Actor();
+var imageActor = new dali.ImageActor();
+var textActor = new dali.TextActor("hello world");
+var meshActor = new dali.MeshActor();
+var camera = new dali.CameraActor();
+var layer = new dali.Layer();
+```
+
+### Hello world example </h3>
+```
+var myActor = new dali.TextActor("hello-world");
+
+myActor.name = "my first actor";
+myActor.color = [ 1, 0, 0, 1]; // Red,Green,Blue, Alpha ( 1 == max, 0 = none )
+myActor.scale = [ 2, 2, 1]; // double the width and height
+
+// by default an actor is anchored to the top-left of it's parent actor
+// change it to the middle
+
+myActor.parentOrigin = [0.5,0.5,0.5];
+
+// add to the stage
+dali.stage.add( myActor );
+```
+
+
+### Positioning Actors
+
+An actor inherits its parent's position. The relative position between the actor & parent is determined by 3 properties:
+
+1) ParentOrigin. This Vector3 property defines a point within the parent actor's area.
+
+<img src="../assets/img/shared/parent-origin.png">
+
+The default is "top-left", which can be visualized in 2D as (0, 0), but is actually Vector3(0, 0, 0.5) in the 3D DALi world. The actor's position is relative to this point.
+```
+// to change parent origin to the centre
+myActor.parentOrigin = [0.5, 0.5, 0.5];
+```
+
+2) AnchorPoint. This Vector3 property defines a point within the child actor's area.
+
+<img src="../assets/img/shared/anchor-point.png">
+
+The default is "center", which can be visualized in 2D as (0.5, 0.5), but is actually Vector3(0.5, 0.5, 0.5) in the 3D DALi world. The actor's position is also relative to this point.
+```
+// setting anchor point to the centre
+myActor.anchorPoint = [0.5, 0.5, 0.5];
+```
+
+3) Position. This is the position vector between the parent-origin and anchor-point.
+
+<img src="../assets/img/shared/actor-position.png">
+
+Therefore by default, an actors position is the distance between its center and the top-left corner of its parent.
+
+An actor added directly to the stage with position (X = stageWidth*0.5, Y = stageHeight*0.5), would appear in the center of the screen. Likewise an actor with position (X = actorWidth*0.5, Y = actorWidth*0.5), would appear at the top-left of the screen.
+
+Note that since DALi is a 3D toolkit, this behaviour is the result of a default perspective camera setup.
+
+### Actor callback events
+
+The actor provides the following call back events
+
+| Name | Description | Parameters passed to call back |
+|-------------------|----------------------------------------|--------------------------|
+|touched | touch event | (actor, touchEvent ) |
+|hovered | mouse or pointer hovering over actor | (actor, hoverEvent) |
+|mouse-wheel-event | mouse wheel events | (actor, wheelEvent) |
+|on-stage | actor has been moved on stage | (actor) |
+|off-stage | actor has been moved off stage | (actor) |
+
+
+#### Touch event
+
+Used to detect multiple touch events on the actor. The state of each touch point can be:
++ "down" = touch down
++ "up" = Touch up
++ "motion" = Finger dragged or hovered
++ "leave" = Leave the boundary of an actor
++ "stationary" = No change from last event. Useful when a multi-point event occurs where
+all points are sent but indicates that this particular point has not changed since the last time
++ "interrupted" = A system event has occurred which has interrupted the touch or hover event sequence
+
+
+
+```
+touchEvent = {
+
+ pointCount: int, // number of points touched ( multi-touch )
+ time: int, // The time in milliseconds that the touch event occurred.
+ points = [ touchPoints ], // array of TouchPoints, to support
+
+ TouchPoint = {
+
+ "deviceId" : int, // Each touch point has a unique device ID
+ "state" : string, // touch state ="down,up,motion,leave,stationary, interrupted }
+ "sourceActor" : actor, // the actor that is emitting the callback (the actor that is hit maybe a child of it)
+ "hitActor" : actor, // actor that was hit
+ "local" : {x,y}, // co-ordinates of top left of hit actor (local.x, local.y)
+ "screen" : {x,y} // co-ordinates of top left of hit actor (screen.x, screen.y)
+ }
+}
+
+function OnPressed( actor, touchEvent )
+{
+ var firstPoint = touchEvent.points[0];
+ log("first touch point = " + firstPoint.screen.x + "," +firstPoint.screen.x + "actor= "+firstPoint.hitActor );
+
+ var anim = new dali.Animation( 4 );
+ var rotation = new dali.Rotation( 90, 0, 0 ); // pitch, yaw, roll
+ anim.animateBy( actor, "rotation", rotation );
+ anim.play();
+ return true;
+}
+
+// connect to touch events
+myActor.connect( "touched", onPressed );
+
+```
+
+#### Hover event
+
+```
+hoverEvent = {
+
+ pointCount // number of points hovered over
+ time // The time in milliseconds that the hover event occurred.
+ points[] // array of TouchPoints
+
+ TouchPoint = {
+ // See touchEvent TouchPoint object
+ }
+}
+```
+ // connect to touch events
+ myActor.connect( "hovered", onHover);
+
+#### Mouse wheel event
+
+```
+mouseWheelEvent = {
+
+ direction, // "vertical" or "horizontal" direction the wheel is being rolled
+ shiftPressed, // boolean, shift key is held
+ ctrlPressed, // boolean, ctrl key is held
+ altPressed, // boolean, alt key is held
+ keyModifiers, // bitmask of keys pressed
+ point {x,y}, // The co-ordinates of the mouse cursor relative to the top-left of the screen when the wheel is being rolled.
+ rolled, // offset of mouse wheel rolling, positive = rolling down, negative = rolling up
+ timestamp // The time in milliseconds that the mouse event occurred
+}
+
+// connect to touch events
+myActor.connect( "mouse-wheel-event", onMouseWheel );
+```
+#### Key events
+
+Key events are performed using the dali.stage object and dali.keyboardFocusManager.
+ - {{#crossLink "stage"}}Stage{{/crossLink}}
+
+
+#### Multi-touch events
+
+See
+ - {{#crossLink "MultiTouch"}}Multi Touch Events.{{/crossLink}}
+
+
+### Actor Properties
+
+ Name | Type | Writable | Animatable
+------------------------|------------|--------------|-----------
+ anchorPoint |VECTOR3 | ✔ | ✘
+ anchorPointX |FLOAT | ✔ | ✘
+ anchorPointY |FLOAT | ✔ | ✘
+ anchorPointZ |FLOAT | ✔ | ✘
+ size |VECTOR3 | ✔ | ✔
+ sizeWidth |FLOAT | ✔ | ✔
+ sizeHeight |FLOAT | ✔ | ✔
+ sizeDepth |FLOAT | ✔ | ✔
+ position |VECTOR3 | ✔ | ✔
+ positionX |FLOAT | ✔ | ✔
+ positionY |FLOAT | ✔ | ✔
+ positionZ |FLOAT | ✔ | ✔
+ worldPosition |VECTOR3 | ✘ | ✘
+ worldPositionX |FLOAT | ✘ | ✘
+ worldPositionY |FLOAT | ✘ | ✘
+ worldPositionZ |FLOAT | ✘ | ✘
+ rotation |ROTATION | ✔ | ✔
+ worldRotation |ROTATION | ✘ | ✘
+ scale |VECTOR3 | ✔ | ✔
+ scaleX |FLOAT | ✔ | ✔
+ scaleY |FLOAT | ✔ | ✔
+ scaleZ |FLOAT | ✔ | ✔
+ worldScale |VECTOR3 | ✘ | ✘
+ visible |BOOLEAN | ✔ | ✔
+ color |VECTOR4 | ✔ | ✔
+ colorRed |FLOAT | ✔ | ✔
+ colorGreen |FLOAT | ✔ | ✔
+ colorBlue |FLOAT | ✔ | ✔
+ colorAlpha |FLOAT | ✔ | ✔
+ worldColor |VECTOR4 | ✘ | ✘
+ worldMatrix |MATRIX | ✘ | ✘
+ name |STRING | ✔ | ✘
+ sensitive |BOOLEAN | ✔ | ✘
+ leaveRequired |BOOLEAN | ✔ | ✘
+ inheritRotation |BOOLEAN | ✔ | ✘
+ inheritScale |BOOLEAN | ✔ | ✘
+ colorMode |NUMBER | ✔ | ✘
+ positionInheritance |NUMBER | ✔ | ✘
+ drawMode |NUMBER | ✔ | ✘
+ sizeMode |NUMBER | ✔ | ✘
+ sizeModeFactor |VECTOR3 | ✔ | ✘
+
+
+
+
+ * @class Actor
+ */
+
+
+/**
+ * Actors parent origin
+ *
+ * @property parentOrigin
+ * @type dali Vector3
+ * @default TOP_LEFT (0.0, 0.0, 0.5).
+ */
+parentOrigin
+
+/**
+ * Actors parent origin X
+ *
+ * @property parentOriginX
+ * @readOnly
+ * @type Number
+ */
+parent - origin - x
+
+/**
+ * Actors parent origin-y
+ * @property parentOriginY
+ * @readOnly
+ * @type Number
+ */
+parent - origin - y
+
+/**
+ * Actors parent origin-z
+ * @property parentOriginZ
+ * @readOnly
+ * @type Number
+ */
+parent - origin - z
+
+/**
+ * Actors anchor point
+ * @property anchorPoint
+ * @type dali Vector3
+ * @default CENTER (0.5, 0.5, 0.5)
+ */
+ANCHOR_POINT;
+
+/**
+ * Actors anchor point x
+ * @property anchorPointX
+ * @type Number
+ */
+ANCHOR_POINT_X
+
+/**
+ * Actors anchor point y
+ * @property anchorPointY
+ * @type Number
+ */
+ANCHOR_POINT_Y
+
+/**
+ * Actors anchor point z
+ * @property anchorPointZ
+ * @type Number
+ */
+ANCHOR_POINT_Z
+
+/**
+ * Actors size
+ * @property size
+ * @type dali Vector3
+ */
+SIZE
+
+
+/**
+ * Actors width
+ * @property sizeWidth
+ * @type Number
+ */
+SIZE_WIDTH
+
+/**
+ * Actors height
+ * @property sizeHeight
+ * @type Number
+ */
+SIZE_HEIGHT
+
+/**
+ * Actors depth
+ * @property sizeDepth
+ * @type Number
+ */
+SIZE_DEPTH
+
+
+/**
+ * Actors position
+ * @property position
+ * @type dali Vector3
+ */
+POSITION
+
+/**
+ * Actors x position
+ * @property positionX
+ * @type Number
+ */
+POSITION_X
+
+/**
+ * Actors y position
+ * @property positionY
+ * @type Number
+ */
+POSITION_Y
+
+/**
+ * Actors z position
+ * @property positionZ
+ * @type Number
+ */
+POSITION_Z
+
+
+/**
+ * Actors world position
+ * @property position
+ * @type dali Vector3 ( read-only, not animatable )
+ */
+WORLD_POSITION
+
+/**
+ * Actors world x position
+ * @property worldPositionX
+ * @type Number ( read-only )
+ */
+WORLD_POSITION_X
+
+/**
+ * Actors world y position
+ * @property worldPositionY
+ * @type Number ( read-only )
+ */
+WORLD_POSITION_Y
+
+/**
+ * Actors world z position
+ * @property worldPositionZ
+ * @type Number ( read-only )
+ */
+WORLD_POSITION_Z
+
+
+/**
+ * Actors rotation
+ * @property rotation
+ * @type dali Rotation object
+ */
+ROTATION
+
+
+/**
+ * Actors world-rotation
+ * @property worldRotation
+ * @type dali Rotation object ( read only)
+ */
+WORLD_ROTATION
+
+/**
+ * Actors scale
+ * @property scale
+ * @type dali Vector3
+ */
+SCALE
+
+/**
+ * Actors x scale
+ * @property scaleX
+ * @type Number
+ */
+SCALE_X
+
+/**
+ * Actors y scale
+ * @property scaleY
+ * @type Number
+ */
+SCALE_Y
+
+/**
+ * Actors z scale
+ * @property scaleZ
+ * @type Number
+ */
+SCALE_Z
+
+/**
+ * Actors world scale
+ * @property worldScale
+ * @type dali Vector3 ( read only )
+ */
+WORLD_SCALE
+
+/**
+ * Actors visible flag
+ * If an actor is not visible, then the actor and its children will not be rendered.
+ * This is regardless of the individual visibility values of the children i.e. an actor will only be
+ * rendered if all of its parents have visibility set to true.
+ *
+ * @property visible
+ * @type Boolean
+ */
+VISIBLE
+
+/**
+ * Actors color.
+ * The final color of the actor depends on its color mode.
+ * 4 components, red, green, blue and alpha. Each range from 0..1
+ * @property color
+ * @type dali Vector 4
+ */
+COLOR
+
+/**
+ * Actors red color
+ * @property colorRed
+ * @type Number ( 0..1)
+ */
+COLOR_RED
+
+/**
+ * Actors green color
+ * @property colorGreen
+ * @type Number ( 0..1)
+ */
+COLOR_GREEN
+
+/**
+ * Actors blue color
+ * @property colorBlue
+ * @type Number ( 0..1)
+ */
+COLOR_BLUE
+
+/**
+ * Actors world color.
+ * 4 components, red, green, blue and alpha. Each range from 0..1
+ * @property worldColor
+ * @type dali Vector 4 ( read only)
+ */
+WORLD_COLOR
+
+/**
+ * Actors name
+ * @property name
+ * @type String
+ */
+
+/**
+ * Actors sensitive flag
+ * brief Sets whether an actor should emit touch event signals; @see SignalTouched().
+ *
+ * An actor is sensitive by default, which means that as soon as an application connects to the SignalTouched(),
+ * the touch event signal will be emitted.
+ *
+ * If the application wishes to temporarily disable the touch event signal emission, then they can do so by calling
+ *
+ * actor.sensitve = false;
+ *
+ * Then, to re-enable the touch event signal emission, the application should call:
+ *
+ * actor.sensitive = true;
+ *
+ * @property sensitive
+ * @type Boolean
+ * @default true ( is sensistive )
+ */
+SENSITIVE
+
+/**
+ * Controls whether the actor should receive a notification when touch motion events leave
+ * the boundary of the actor.
+ *
+ * Note: Need to connect to the SignalTouch to actually receive this event.
+ * Should be set to true if a Leave event is required
+ * @type Boolean
+ * @property leaveRequired
+ * @default false, this is set to false as most actors do not require this.
+ */
+LEAVE_REQUIRED
+
+/**
+ * Set whether a child actor inherits it's parent's orientation.
+ * @type Boolean
+ * @property inheritRotation
+ * @default true
+ */
+INHERIT_ROTATION,
+
+
+/**
+ * Set whether a child actor inherits it's parent's scale.
+ * @type Boolean
+ * @property inheritScale
+ * @default true
+ */
+INHERIT_SCALE,
+
+
+/**
+ * Set how the actor and its children should be drawn.
+ *
+ * Not all actors are renderable, but DrawMode can be inherited from any actor.
+ * By default a renderable actor will be drawn as a 3D object. It will be depth-tested against
+ * other objects in the world i.e. it may be obscured if other objects are in front.
+ *
+ * If OVERLAY is used, the actor and its children will be drawn as a 2D overlay.
+ * Overlay actors are drawn in a separate pass, after all non-overlay actors within the Layer.
+ * For overlay actors, the drawing order is determined by the hierachy (depth-first search order),
+ * and depth-testing will not be used.
+ *
+ * If STENCIL is used, the actor and its children will be used to stencil-test other actors
+ * within the Layer. Stencil actors are therefore drawn into the stencil buffer before any other
+ * actors within the Layer.
+ *
+ * @example
+ *
+ * var actor.drawMode = dali.DRAW_MODE_NORMAL; // binary 00. The default draw-mode
+ * var actor.drawMode = dali.DRAW_MODE_OVERLAY; // binary 01. Draw the actor and its children as an overlay
+ * var actor.drawMode = dali.DRAW_MODE_STENCIL ;// binary 11. Draw the actor and its children into the stencil buffer
+ *
+ *
+ * @type Number
+ * @property drawMode
+ * @default 0 (Normal )
+ */
+DRAW_MODE,
+
+
+/**
+ * Sets the actor's color mode.
+ *
+ * This specifies whether the Actor uses its own color, or inherits
+ * its parent color. The default is USE_OWN_MULTIPLY_PARENT_ALPHA.
+ *
+ * @example
+ * actor.colorMode = dali.COLOR_MODE_USE_OWN_COLOR; // Actor will use its own color
+ * actor.colorMode = dali.COLOR_MODE_USE_PARENT_COLOR; // Actor will use its parent color
+ * actor.colorMode = dali. COLOR_MODE_USE_OWN_MULTIPLY_PARENT_COLOR; // Actor will blend its color with its parents color.
+ * actor.colorMode = dali.COLOR_MODE_USE_OWN_MULTIPLY_PARENT_ALPHA ; // Actor will blend its alpha with its parents alpha. This means when parent fades in or out child does as well. This is the default.
+ *
+ *
+ * @type Number
+ * @property colorMode
+ * @default 2 (USE_OWN_MULTIPLY_PARENT_ALPHA )
+ */
+COLOR_MODE
+
+/**
+ * Set the actors position inheritance mode.
+ *
+ * @example
+ * actor.positionInheritance = dali.POSITION_INHERITANCE_INHERIT_PARENT_POSITION; // Actor will inherit its parent position. This is the default
+ * actor.positionInheritance = dali.POSITION_INHERITANCE_USE_PARENT_POSITION; // Actor will copy its parent position. This is useful if many actors are stacked together in the same place. This option ignores parent origin and anchor point.
+ * actor.positionInheritance = dali.POSITION_INHERITANCE_USE_PARENT_POSITION_PLUS_LOCAL_POSITION; // Actor will copy its parent position and add local position. This is useful if many actors are stacked together in the same place with an offset. This option ignores parent origin and anchor point.
+ * actor.positionInheritance = dali.POSITION_INHERITANCE_DONT_INHERIT_POSITION; // Actor will not inherit position. Local position is treated as world position. This is useful if a constraint is used to override local position or if an actor is positioned globally. This option ignores parent origin, anchor point and local position.
+ *
+ * Switching this off means that using SetPosition() sets the actor's world position.
+ * @type Number
+ * @property positionInheritance
+ * @default 0 (INHERIT_PARENT_POSITION )
+ */
+POSTITION_INHERITANCE
+
+
+/**
+ * Defines how a child actor's size is affected by its parent's size.
+ *
+ * The default is to ignore the parent's size and use the size property of this actor.
+ *
+ * If USE_OWN_SIZE is used, this option is bypassed and the actor's size
+ * property is used.
+ *
+ * If SIZE_EQUAL_TO_PARENT is used, this actor's size will be equal to that
+ * of its parent. The actor's size property is ignored.
+ *
+ * If SIZE_RELATIVE_TO_PARENT is used, this actor's size will be based on
+ * its parent's size by multiplying the parent size by
+ * SizeModeFactor.
+ *
+ * If SIZE_FIXED_OFFSET_FROM_PARENT is used, this actor's size will be based on
+ * its parent's size plus SizeModeFactor.
+ *
+ *
+ * @example
+ * actor.sizeMode = dali.USE_OWN_SIZE;
+ * actor.sizeMode = dali.SIZE_EQUAL_TO_PARENT;
+ * actor.sizeMode = dali.SIZE_RELATIVE_TO_PARENT;
+ * actor.sizeMode = dali.SIZE_FIXED_OFFSET_FROM_PARENT
+ *
+ * @type Number
+ * @property sizeMode
+ * @default 0 (dali.SIZE_MODE_USE_OWN_SIZE; )
+ */
+ SIZE_MODE
+
+/**
+ *
+ * @brief Sets the relative to parent size factor of the actor.
+ *
+ * This factor is only used when SizeMode is set to either:
+ * SIZE_RELATIVE_TO_PARENT or SIZE_FIXED_OFFSET_FROM_PARENT.
+ * This actor's size is set to the actor's parent size multipled by or added to this factor,
+ * depending on SideMode (See SetSizeMode).
+ * @type Vector3
+ * @property sizeModeFactor
+ */
+SIZE_MODE_FACTOR
\ No newline at end of file
--- /dev/null
+/**
+ *
+## Animation API
+
+ DALi Animation can be used to animate the properties of any number of objects, typically Actors.
+
+The API supports functionality such as:
+
+ - {{#crossLink "animation/play:method"}}{{/crossLink}}
+ - {{#crossLink "animation/pause:method"}}{{/crossLink}}
+ - {{#crossLink "animation/stop:method"}}{{/crossLink}}
+ - {{#crossLink "animation/setLooping:method"}}{{/crossLink}}, set whether the animation should loop
+ - {{#crossLink "animation/setSpeedFactor:method"}}{{/crossLink}}, speeds / slows down an animation
+ - {{#crossLink "animation/setPlayRange:method"}}{{/crossLink}}, only play part of the animation between a set range
+ - Key frame support. See {{#crossLink "animation/animateBetween:method"}}{{/crossLink}}
+ - Path Animations. See {{#crossLink "path"}}Path {{/crossLink}}
+ - Signals to be informed when an animation has finished.
+ - animate multiple properties, owned by multiple objects with a single animation object
+
+### Simple example of moving an actor to a set position
+
+```
+var myActor = new dali.TextActor( "hello world" );
+
+myActor.parentOrigin = dali.CENTER;
+dali.stage.add( myActor );
+
+var anim = new dali.Animation( 2 ); // 2 seconds
+
+// we're animation the property position of the actor.
+anim.animateTo( myActor, "position", [100, 100, 0] );
+
+function finished( animation )
+{
+ log("Animation finished \n");
+}
+
+anim.connect("finished", finished );
+
+anim.play();
+```
+
+### Multiple actor example
+
+```
+// Following demonstrates:
+// - aimating multiple properties on an object (actor properties in this example)
+// - animating multiple objects at the same time (2 actors in the example)
+// - using the optional, animation options object to set a delay time and alpha function (easing)
+
+// Sets the original position to be rotated and pushed into the distance
+
+var myActor1 = new dali.TextActor( "Hello" );
+var myActor2 = new dali.TextActor( "from DALi" );
+
+// centre both actors to the middle of the screen
+myActor1.parentOrigin = dali.CENTER;
+myActor2.parentOrigin = dali.CENTER;
+myActor1.scale=[2,2,1]; // scale up x and y by 2
+myActor2.scale=[2,2,1]; // scale up x and y by 2
+
+
+// reposition them to the left / right, and push them away from the camera
+myActor1.position=[-100,0,-2000]; // x = -100, y = 0 , z = -2000
+myActor2.position=[ 100,0,-2000]; // x = 100, y = 0 , z = -2000
+
+// start with actor rotated by 180 about x & y axis, so they can twist into place
+function createAnimation() {
+
+ var startRotation = new dali.Rotation(180, -180, 0);
+ myActor1.rotation = startRotation;
+ myActor2.rotation = startRotation;
+
+ dali.stage.add( myActor1 );
+ dali.stage.add( myActor2 );
+
+
+ var anim = new dali.Animation(1); // default duration is increased if length of all animations is greater than it.
+
+ var animOptions = {
+ alpha: "linear",
+ delay: 0.5, // used to delay the start of the animation
+ duration: 3, // duration of the animation
+ };
+
+ // move myActor1 z position back to 0
+ anim.animateTo(myActor1, "positionZ", 0, animOptions);
+
+ // rotate back to correct orientation
+ var endRotation = new dali.Rotation(0,0,0);
+
+ animOptions.alpha = "easeInOutSine";
+ anim.animateTo(myActor1, "rotation", endRotation, animOptions);
+
+ // Delay the myActor2 by a second
+ animOptions.delay = 0.0;
+ animOptions.alpha = "linear";
+ anim.animateTo(myActor2, "positionZ", 0, animOptions);
+
+ // rotate back to correct orientation
+ animOptions.alpha = "easeInOutSine";
+ anim.animateTo(myActor2, "rotation", endRotation, animOptions);
+
+ return anim;
+}
+
+
+var anim = createAnimation();
+
+anim.play();
+
+```
+
+### GL-ES shader animation example
+
+The example below does the following with a single animation object:
+
+ - rotates the image actor
+ - magnifies and color shifts the image using a fragment shader
+
+<img src="../assets/img/shader-animation.png">
+
+
+```
+// create an image actor in the centre of the stage
+createImageActor = function() {
+
+ var image = new dali.ResourceImage({ url:getImageDirectory()+"gallery-medium-50.jpg"});
+ var imageActor = new dali.ImageActor( image );
+ imageActor.parentOrigin = dali.CENTER;
+ dali.stage.add( imageActor );
+
+ return imageActor;
+}
+
+// Creates a simple fragment shader that has 2 uniforms.
+// uColorShift which can add a color to pixel
+// uScale which can simulate zooming into the texture
+
+createColorShiftAndZoomEffect = function() {
+
+ var fragShader =
+ " uniform lowp vec4 uColorShift; \
+ uniform lowp vec2 uScale; \
+ \
+ void main() \
+ { \
+ gl_FragColor = texture2D( sTexture, vTexCoord * uScale ) * uColor + uColorShift; \
+ }"
+
+ // Shader API
+ // geometryType = "image", "text", "mesh", "textured-mesh"
+ // fragmentPrefex ="" // prefix ( optional)
+ // fragmentShader = "" // fragment shader ( optional)
+ // geometryHints = [ "gridX", "gridY", "grid","depthBuffer","blending" ] ( optional)
+ //
+ var shaderOptions = {
+ geometryType: "image",
+ fragmentShader: fragShader,
+ geometryHints: ["blending"]
+ };
+
+ // create a new shader effect
+ var shader = new dali.ShaderEffect(shaderOptions);
+
+ // add the color shift uniform so we can animate it
+ // default the color shift to zero, so it has no effect
+ shader.setUniform("uColorShift", [0, 0, 0, 0]);
+
+ // add the zoom uniform so we can animate it
+ // default to 1,1 so no zoom is applied
+ var scale = new dali.Vector2([1, 1]);
+ shader.setUniform("uScale", scale);
+
+ return shader;
+}
+
+createShaderAnimation = function( shader, color, zoom, duration, delay )
+{
+ var shaderAnim = new dali.Animation(duration+delay);
+
+ var animOptions = {
+ alpha: "doubleEaseInOutSine60",
+ delay: delay,
+ duration: duration,
+ };
+
+ // animate the color uniform
+ shaderAnim.animateTo( shader, "uColorShift", color, animOptions);
+
+ // zoom in and out of the image while applying the color shift
+ shaderAnim.animateTo( shader, "uScale", zoom, animOptions);
+
+ return shaderAnim;
+}
+
+var imageActor = createImageActor();
+var shaderEffect = createColorShiftAndZoomEffect();
+
+// assign the shader effect to the actor ( it can be assigned to multiple actors).
+imageActor.setShaderEffect( shaderEffect );
+
+// create the shader animation
+var zoom = [0.5,0.5]; // zoom into the image by 2
+var color = dali.COLOR_BLUE; // color shift the image to blue
+var duration = 5; // 5 seconds
+var delay = 5; // wait 1 second before starting
+var shaderAnim = createShaderAnimation( shaderEffect, color,zoom, duration, delay);
+
+// also rotate the imageActor 90 degrees at the same time.
+var rotation = new dali.Rotation(90,0,0,1);
+shaderAnim.animateTo(imageActor, "rotation", rotation, { alpha:"linear", duration:duration, delay:delay });
+
+
+shaderAnim.play();
+
+```
+
+
+### Animation alpha functions
+
+| Name | Description |
+|--------------------|--------------|
+|default |Linear |
+|linear |Linear |
+|square |Square (x^2) |
+|reverse |Reverse linear |
+|easeIn |Speeds up and comes to a sudden stop |
+|easeOut |Sudden start and slows to a gradual stop|
+|easeInOut |Speeds up and slows to a gradual stop|
+|easeInSine |Speeds up and comes to a sudden stop|
+|easeOutSine |Sudden start and slows to a gradual stop|
+|easeInOutSine |Speeds up and slows to a gradual stop |
+|easeInSine33 |Speeds up and comes to a sudden stop |
+|easeOutSine33 |Sudden start and slows to a gradual stop |
+|easeInOutSine33 |Speeds up and slows to a gradual stop |
+|easeInOutSine50 |Speeds up and slows to a gradual stop |
+|easeInOutSine60 |Speeds up and slows to a gradual stop |
+|easeInOutSine70 |Speeds up and slows to a gradual stop |
+|easeInOutSine80 |Speeds up and slows to a gradual stop |
+|easeInOutSine90 |Speeds up and slows to a gradual stop |
+|doubleEaseInOutSine6|Speeds up and slows to a gradual stop, then speeds up again and slows to a gradual stop |
+|easeOutQuint50 |Sudden start and slows to a gradual stop |
+|easeOutQuint80 |Sudden start and slows to a gradual stop |
+|bounce |Sudden start, loses momentum and ** Returns to start position ** |
+|bounceBack |Sudden start, loses momentum and returns to exceed start position ** Returns to start position ** |
+|easeInBack |Slow start, exceed start position and quickly reach destination |
+|easeOutBack |Sudden start, exceed end position and return to a gradual stop|
+|easeInOutBack |Slow start, exceed start position, fast middle, exceed end position and return to a gradual stop|
+|sin |full 360 revolution ** Returns to start position ** |
+|sin2x |full 720 revolution ** Returns to start position ** |
+
+
+
+ @class Animation
+
+*/
--- /dev/null
+/**
+ ## Camera Actor API ( extends Actor API)
+
+
+Allows the developer to use actor semantics to control a camera.
+
+There are two types of camera actor, FREE_LOOK and LOOK_AT_TARGET. By default
+the camera actor will be FREE_LOOK.
+
+A FREE_LOOK camera uses actor's rotation to control where the camera is looking.
+If no additional rotations are specified, the camera looks in the negative Z direction.
+
+For LOOK_AT_TARGET the actor's rotation is ignored, instead the camera looks at TARGET_POSITION
+in world coordinates.
+```
+// get the camera currently used
+var defaultCamera = dali.stage.getRenderTaskList().getTask(0).getCameraActor();
+
+var fov = defaultCamera.fieldOfView;
+
+// increase field of view by 10%
+defaultCamera.fieldOfView = fov * 1.1;
+
+// shift the camera to the left, the rendered scene will shift to the right
+defaultCamera.x -= 10;
+```
+
+### Camera Actor Specific Properties
+
+| Name | Type | Writable | Animatable|
+|------------------------|------------|--------------|-----------|
+| type | dali.CAMERA_FREE_LOOK or dali.CAMERA_LOOK_AT_TARGET | ✔ | ✘ |
+| projectionMode | dali.CAMERA_ORTHOGRAPHIC_PROJECTION or dali.CAMERA_PERSPECTIVE_PROJECTION | ✔| ✘ |
+| fieldOfView | FLOAT | ✔ | ✘ |
+| aspectRatio | FLOAT | ✔ | ✘ |
+| nearPlaneDistance | FLOAT | ✔ | ✘ |
+| farPlaneDistance | FLOAT | ✔ | ✘ |
+| leftPlaneDistance | FLOAT | ✔ | ✘ |
+| rightPlaneDistance | FLOAT | ✔ | ✘ |
+| topPlaneDistance | FLOAT | ✔ | ✘ |
+| bottomPlaneDistance | FLOAT | ✔ | ✘ |
+| targetPosition | VECTOR3 | ✔ | ✘ |
+| projectionMatrix | MATRIX | ✔ | ✘ |
+| viewMatrix | MATRIX | ✔ | ✘ |
+| invertYAxis | BOOLEAN | ✔ | ✘ |
+
+
+
+ @class CameraActor
+ @extends Actor
+ */
--- /dev/null
+/**
+ *
+<h3> Dali Constants </h3>
+
+Constants accessible under the dali global object.
+
+ actor.parentOrigin = dali.BACK_TOP_LEFT;
+ actor.color = dali.COLOR_RED;
+ actor.setBlendFunc( dali.BLEND_FACTOR_ONE_MINUS_SRC_COLOR, dali.BLEND_FACTOR_SRC_ALPHA_SATURATE );
+
+
+| Constant Name | value |
+|---------------|-------|
+| ** actor.parentOrigin and actor.anchorPoint ** | |
+|BACK_TOP_LEFT | (0.0f, 0.0f, 0.0f) |
+|BACK_TOP_CENTER | (0.5f, 0.0f, 0.0f) |
+|BACK_TOP_RIGHT | (1.0f, 0.0f, 0.0f) |
+|BACK_CENTER_LEFT | (0.0f, 0.5f, 0.0f) |
+|BACK_CENTER | (0.5f, 0.5f, 0.0f) |
+|BACK_CENTER_RIGHT | (1.0f, 0.5f, 0.0f) |
+|BACK_BOTTOM_LEFT | (0.0f, 1.0f, 0.0f) |
+|BACK_BOTTOM_CENTER | (0.5f, 1.0f, 0.0f) |
+|BACK_BOTTOM_RIGHT | (1.0f, 1.0f, 0.0f) |
+|TOP_LEFT | (0.0f, 0.0f, 0.5f) |
+|TOP_CENTER | (0.5f, 0.0f, 0.5f) |
+|TOP_RIGHT | (1.0f, 0.0f, 0.5f) |
+|CENTER_LEFT | (0.0f, 0.5f, 0.5f) |
+|CENTER | (0.5f, 0.5f, 0.5f) |
+|CENTER_RIGHT | (1.0f, 0.5f, 0.5f) |
+|BOTTOM_LEFT | (0.0f, 1.0f, 0.5f) |
+|BOTTOM_CENTER | (0.5f, 1.0f, 0.5f) |
+|BOTTOM_RIGHT | (1.0f, 1.0f, 0.5f) |
+
+|FRONT_TOP_LEFT | (0.0f, 0.0f, 1.0f) |
+|FRONT_TOP_CENTER | (0.5f, 0.0f, 1.0f) |
+|FRONT_TOP_RIGHT | (1.0f, 0.0f, 1.0f) |
+|FRONT_CENTER_LEFT | (0.0f, 0.5f, 1.0f) |
+|FRONT_CENTER | (0.5f, 0.5f, 1.0f) |
+|FRONT_CENTER_RIGHT | (1.0f, 0.5f, 1.0f) |
+|FRONT_BOTTOM_LEFT | (0.0f, 1.0f, 1.0f) |
+|FRONT_BOTTOM_CENTER | (0.5f, 1.0f, 1.0f) |
+|FRONT_BOTTOM_RIGHT | (1.0f, 1.0f, 1.0f) |
+
+
+|** Vector3 ** | |
+|VECTOR3_ONE | (1.0f, 1.0f, 1.0f) |
+|VECTOR3_XAXIS | (1.0f, 0.0f, 0.0f) |
+|VECTOR3_YAXIS | (0.0f, 1.0f, 0.0f) |
+|VECTOR3_ZAXIS | (0.0f, 0.0f, 1.0f) |
+|VECTOR3_NEGATIVE_XAXIS | (-1.0f, 0.0f, 0.0f) |
+|VECTOR3_NEGATIVE_YAXIS | (0.0f, -1.0f, 0.0f) |
+|VECTOR3_NEGATIVE_ZAXIS | (0.0f, 0.0f, -1.0f) |
+|VECTOR3_ZERO | (0.0f, 0.0f, 0.0f) |
+
+|** Colors **| -|
+|COLOR_BLACK | ( 0.0f, 0.0f, 0.0f, 1.0f ) |
+|COLOR_WHITE | ( 1.0f, 1.0f, 1.0f, 1.0f ) |
+|COLOR_RED | ( 1.0f, 0.0f, 0.0f, 1.0f ) |
+|COLOR_GREEN | ( 0.0f, 1.0f, 0.0f, 1.0f ) |
+|COLOR_BLUE | ( 0.0f, 0.0f, 1.0f, 1.0f ) |
+|COLOR_YELLOW | ( 1.0f, 1.0f, 0.0f, 1.0f ) |
+|COLOR_MAGENTA | ( 1.0f, 0.0f, 1.0f, 1.0f ) |
+|COLOR_CYAN | ( 0.0f, 1.0f, 1.0f, 1.0f ) |
+|COLOR_TRANSPARENT | ( 0.0f, 0.0f, 0.0f, 0.0f ) |
+
+| ** actor.colorMode constants ** | -|
+| COLOR_MODE_USE_OWN_COLOR, | integer value |
+| COLOR_MODE_USE_PARENT_COLOR, | integer value |
+| COLOR_MODE_USE_OWN_MULTIPLY_PARENT_COLOR, | integer value |
+| COLOR_MODE_USE_OWN_MULTIPLY_PARENT_ALPHA, | integer value |
+
+|**actor.positionInheritance **| |
+|POSITION_INHERITANCE_INHERIT_PARENT_POSITION, | integer value |
+|POSITION_INHERITANCE_USE_PARENT_POSITION, | integer value |
+|POSITION_INHERITANCE_USE_PARENT_POSITION_PLUS_LOCAL_POSITION, | integer value |
+|POSITION_INHERITANCE_DONT_INHERIT_POSITION, | integer value |
+
+|**actor.drawMode **| |
+|DRAW_MODE_NORMAL | integer value |
+|DRAW_MODE_OVERLAY | integer value |
+|DRAW_MODE_STENCIL | integer value |
+
+|**Image load policy **| |
+|IMAGE_LOAD_POLICY_IMMEDIATE | integer value |
+|IMAGE_LOAD_POLICY_ON_DEMAND | integer value |
+
+|**actor.SetBlendFunc() ** | |
+|BLEND_FACTOR_ZERO | integer value |
+|BLEND_FACTOR_ONE | integer value |
+|BLEND_FACTOR_SRC_COLOR | integer value |
+|BLEND_FACTOR_ONE_MINUS_SRC_COLOR | integer value |
+|BLEND_FACTOR_SRC_ALPHA | integer value |
+|BLEND_FACTOR_ONE_MINUS_SRC_ALPHA | integer value |
+|BLEND_FACTOR_DST_ALPHA | integer value |
+|BLEND_FACTOR_ONE_MINUS_DST_ALPHA | integer value |
+|BLEND_FACTOR_DST_COLOR | integer value |
+|BLEND_FACTOR_ONE_MINUS_DST_COLOR | integer value |
+|BLEND_FACTOR_SRC_ALPHA_SATURATE | integer value |
+|BLEND_FACTOR_CONSTANT_COLOR | integer value |
+|BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR | integer value |
+|BLEND_FACTOR_CONSTANT_ALPHA | integer value |
+|BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA | integer value |
+
+|**actor.SetBlendMode() **| |
+|BLENDING_OFF | integer value |
+|BLENDING_AUTO | integer value |
+|BLENDING_ON | integer value |
+
+|**actor.SetBlendEquation() ** | |
+|BLEND_EQUATION_ADD | integer value |
+|BLEND_EQUATION_SUBTRACT | integer value |
+|BLEND_EQUATION_REVERSE_SUBTRACT | integer value |
+
+|**actor.SetCullFace()** | |
+|CULL_FACE_DISABLE | integer value |
+|CULL_FRONT_FACE | integer value |
+|CULL_BACK_FACE | integer value |
+|CULL_FRONT_AND_BACK_FACE | integer value |
+
+|**actor.sizeMode** | |
+|USE_OWN_SIZE | integer value |
+|SIZE_EQUAL_TO_PARENT | integer value |
+|SIZE_RELATIVE_TO_PARENT | integer value |
+|SIZE_FIXED_OFFSET_FROM_PARENT | integer value |
+
+
+|**animation.SetEndAction( mode ) ** | |
+|ANIMATION_BAKE | integer value |
+|ANIMATION_DISCARD | integer value |
+|ANIMATION_BAKE_FINAL | integer value |
+
+|**camera.type ** | |
+|CAMERA_FREE_LOOK | integer value |
+|CAMERA_LOOK_AT_TARGET | integer value |
+
+|**camera.projectionMode ** | |
+|CAMERA_PERSPECTIVE_PROJECTION | integer value |
+|CAMERA_ORTHOGRAPHIC_PROJECTION | integer value |
+
+
+|** Pixel formats ** | |
+| PIXEL_FORMAT_A8 | integer value |
+| PIXEL_FORMAT_L8 | integer value |
+| PIXEL_FORMAT_LA88 | integer value |
+| PIXEL_FORMAT_RGB565 | integer value |
+| PIXEL_FORMAT_BGR565 | integer value |
+| PIXEL_FORMAT_RGBA4444 | integer value |
+| PIXEL_FORMAT_BGRA4444 | integer value |
+| PIXEL_FORMAT_RGBA5551 | integer value |
+| PIXEL_FORMAT_BGRA5551 | integer value |
+| PIXEL_FORMAT_RGB888 | integer value |
+| PIXEL_FORMAT_RGB8888 | integer value |
+| PIXEL_FORMAT_BGR8888 | integer value |
+| PIXEL_FORMAT_RGBA8888 | integer value |
+| PIXEL_FORMAT_BGRA8888 | integer value |
+
+| **Pixel Compressed formats ** | |
+| PIXEL_FORMAT_COMPRESSED_R11_EAC | integer value |
+| PIXEL_FORMAT_COMPRESSED_SIGNED_R11_EAC | integer value |
+| PIXEL_FORMAT_COMPRESSED_RG11_EAC | integer value |
+| PIXEL_FORMAT_COMPRESSED_SIGNED_RG11_EAC | integer value |
+| PIXEL_FORMAT_COMPRESSED_RGB8_ETC2 | integer value |
+| PIXEL_FORMAT_COMPRESSED_SRGB8_ETC2 | integer value |
+| PIXEL_FORMAT_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 | integer value |
+| PIXEL_FORMAT_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 | integer value |
+| PIXEL_FORMAT_COMPRESSED_RGBA8_ETC2_EAC | integer value |
+| PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC | integer value |
+| PIXEL_FORMAT_COMPRESSED_RGB8_ETC1 | integer value |
+| PIXEL_FORMAT_COMPRESSED_RGB_PVRTC_4BPPV1 | integer value |
+</table>
+
+ * @class Constants
+ */
--- /dev/null
+/**
+ *
+
+## DALi 3D ( Dynamic Animation Library )
+
+DALi is a quick and easy way of allowing developers to create Rich UI Applications like:
+
+ + Image & Video galleries
+ + Music players
+ + Games
+ + Maps
+ + Homescreens / launch pads
+ + Advanced watch faces for wearable devices
+
+
+DALi is based on OpenGL ES 2.0 & 3.0, however it hides the complexity of
+the OpenGL API from developers and provides a clean cross-platform JavaScript framework.
+
++ Create Images, Text and Meshes
++ Create shaders using GLSL
++ Provide multiple cameras and render targets
++ Provides Layers to aid in 2D UI layout
++ Easy to use Animation framework
++ Automatic background loading of resources ( images / text / meshes )
++ Runs all animations in a seperate thread. This helps maintain 60 FPS even if JavaScript is performing a long operation ( e.g. Garbage Collection ).
++ Provides keyboard / touch / mouse handling
+
+
+<img src="../assets/img/shared/screenshot.png">
+
+## Running JavaScript from DALi C++ API
+```
+mScript = Dali::Toolkit::Script::New();
+
+mScript.ExecuteFile( mScriptFileName);
+```
+
+## Actors and the Stage
+
+A DALi application uses a hierachy of Dali::Actor objects to position visible content. An actor inherits a position relative to its parent, and can be moved relative to this point. UI controls can be built by combining multiple actors.
+
+To display the contents of an actor, it must be connected to the Dali::Stage. This provides an invisible root (top-level) actor, to which all other actors are added. A direct or indirect child of the root actor is considered "on-stage". Multi-touch events are received through signals emitted by on-stage actors.
+
+The following example shows how to connect a new actor to the stage:
+```
+ var actor = new dali.actor();
+
+ dali.stage.add(actor);
+```
+## The Coordinate System
+
+The Stage has a 2D size, which matches the size of the application window. The default coordinate system in DALi has the origin at the top-left corner, with positive X to right, and position Y going
+downwards. This is intended to be convenient when laying-out 2D views.
+
+<img src="../assets/img/shared/coordinate-system-and-stage.png">
+
+
+ * @module DALi
+ * @main DALi
+ */
--- /dev/null
+module.exports = {
+ daliName: function() {
+ return "dali";
+ }
+};
--- /dev/null
+/**
+## Image Actor API ( extends Actor API)
+
+An actor for displaying images.
+
+Allows the developer to add an actor to stage which displays the content of an Image object.
+
+By default CullFaceMode is set to CullNone to enable the ImageActor to be viewed from all angles.
+
+If an ImageActor is created without setting size, then the actor takes the size of the image -
+this is the natural size.
+Setting a size on the ImageActor, e.g through the SetSize api or through an animation will
+stop the natural size being used.
+
+Such a set size can be changed back to the image's size by calling {{#crossLink "ImageActor/setToNaturalSize:method"}}{{/crossLink}} .
+
+If a pixel area is set on an ImageActor with natural size, the actor size will change
+to match the pixel area. If a pixel area is set on an ImageActor that has had it's size set,
+then the size doesn't change, and the partial image will be stretched to fill the set size.
+
+Clearing the pixel area on an Image actor with natural size will cause the actor to show the
+whole image again, and will change size back to that of the image.
+
+Clearing the pixel area on an Image actor with a set size will cause the actor to show the
+whole image again, but will not change the image size.
+
+### Simple example
+```
+var image = new dali.ResourceImage( {url:"background.png"} );
+var imageActor = new dali.ImageActor( image );
+
+// by default an actor is anchored to the top-left of it's parent actor
+// change it to the middle
+imageActor.parentOrigin = dali.CENTER;
+
+// scale it up by 2 times in x,y
+imageActor.scale = [ 2, 2, 1 ];
+
+// add to the stage
+dali.stage.add( imageActor );
+```
+
+### Example using a pixel area ( needed for displaying images from a Texture Atlas )
+
+```
+var imageAtlas = new dali.ResourceImage( {url:"atlas.png"} )
+```
+<img src="../assets/img/example-javascript-code.png">
+
+### Image Actor Specific Properties
+
+
+|Name | Type | Writable | Animatable|
+|-----------------------|------------|--------------|-----------|
+| pixelArea | RECTANGE | ✔ | ✘ |
+| fadeIn | BOOLEAN | ✔ | ✘ |
+| fadeInDuration | FLOAT | ✔ | ✘ |
+| style | dali.IMAGE_ACTOR_STYLE_QUAD, dali.IMAGE_ACTOR_STYLE_NINE_PATCH, dali.IMAGE_ACTOR_STYLE_NINE_PATCH_NO_CENTER | ✔ | ✘ |
+| border | VECTOR4 | ✔ | ✘ |
+
+
+@class ImageActor
+@extends RenderableActor
+ */
\ No newline at end of file
--- /dev/null
+/**
+ *
+## Image API
+
+An Image object represents a resource that can be added to ImageActors and ShaderEffects.
+
+The image is discarded when all ImageActors using the Image object are discarded or in case they
+were created with dali.IMAGE_RELEASE_POLICY_UNUSED, taken off stage.
+
+Note: if a resource was shared between Image objects it exists until its last reference is gone.
+
+Image objects are responsible for the underlying resource's lifetime.
+
+### ReleasePolicies
+
+ - dali.IMAGE_RELEASE_POLICY_UNUSED: release resource once ImageActor using it is taken off stage.
+ - dali.IMAGE_RELEASE_POLICY_NEVER: keep resource alive until Image object is thrown away ( default).
+
+#### Resolution of conflicting policies
+ - If the same image is created more than once with conflicting policies, ReleasePolicy "Never" overrides "Unused".
+
+
+### The hierarchy of Image is:
+
+- {{#crossLink "image"}}Image base class {{/crossLink}} provides basic functionality
+ - {{#crossLink "ResourceImage"}}ResourceImage {{/crossLink}} used for loading image files and nine-patch files
+ - {{#crossLink "NinePatchImage"}}NinePatch {{/crossLink}} used just for nine patch files
+ - {{#crossLink "BufferImage"}}BufferImage {{/crossLink}} used for generating your own image
+ - {{#crossLink "FrameBufferImage"}}FrameBufferImage {{/crossLink}} contains the result of an 'off screen' render pass of a RenderTask.
+ - {{#crossLink "NativeImage"}}NativeImage {{/crossLink}} Its data is provided by native resources, such as shared bitmap memory or pixmap from X11 or ECORE-X11, etc.
+
+
+### Example:
+```
+var image = new dali.ResourceImage( {url: "background.png"} );
+
+var imageActor1 = new dali.ImageActor( image );
+var imageActor2 = new dali.ImageActor( image );
+
+shaderEffect.setEffectImage( image );
+
+
+```
+The API supports functionality such as:
+
++ {{#crossLink "image/Image:method"}}new dali.ResourceImage{{/crossLink}}
++ {{#crossLink "image/getWidth:method"}}{{/crossLink}}
++ {{#crossLink "image/getHeight:method"}}{{/crossLink}}
+
+### 9 patch images
+
+The Image class also has support for loading 9 patch Images if the filename contains .9.
+e.g.
+```
+var blackFrame = new dali.ResourceImage( url:"black-frame.9.png"});
+var borderNinePatch = new dali.ResourceImage( {url:"border.9.png"} );
+// or if the image doesn't have a .9 filename, you can use the NinePatchImage class
+var image = new dali.NinePatchImage( {url:"my_image.png"})
+```
+The nine patch image will scale automatically with the size of the actor.
+
+Tool for making 9 patches
+
+ http://romannurik.github.io/AndroidAssetStudio/nine-patches.html
+
+More information on them:
+
+ http://radleymarx.com/blog/simple-guide-to-9-patch/
+
+ http://developer.android.com/tools/help/draw9patch.html
+
+
+
+ @class Image
+ */
--- /dev/null
+/**
+ *
+
+## Keyboard Focus Manager API
+
+Keyboard focus manager controls the keyboard focus flow.
+
+It also allows you to set an actor that is used to high light the focused actor.
+
+{{#crossLink "KeyboardFocusManager/setFocusIndicatorActor:method"}}{{/crossLink}}
+
+The application is required to help the manager when moving focus.
+
+<img src="../assets/img/focus-manager.png">
+
+### keyboard-pre-focus-change
+
+Connect to the pre-focus-change call back as follows:
+```
+// listen for pre-focus change events
+dali.keyboardFocusManager.connect("keyboard-pre-focus-change", this.preFocusChanged);
+
+// example call back handler
+
+// currentFocusedActor = currently focused actor
+// proposed = keyboard focus managers guess at what actor should be next
+// direction = the direction of the focus is moving in
+//
+myApp.preFocusChanged = function( currentFocusedActor, proposedActorToFocus, direction)
+{
+
+ if (direction == "up" )
+ {
+ return actor above current actor;
+ }
+ if (direction == "right" )
+ {
+ return actor to the right of current actor;
+ }
+}
+
+dali.keyboardFocusManager.connect("keyboard-pre-focus-change", myCallback)
+```
+
+KeyboardFocusManager makes the best guess for which actor to focus towards the given direction, but applications might want to change that.
+
+By connecting with this signal, they can check the proposed actor to focus and return a different actor if they wish.
+
+This signal is only emitted when the navigation key is pressed and KeyboardFocusManager tries to move the focus automatically.
+
+It won't be emitted for focus movement by calling setCurrentFocusActor directly.
+
+### keyboard-focus-changed
+
+This signal is emitted after the current focused actor has been changed.
+```
+myCallback( originalFocusedActor, currentFocusedActor)
+{
+}
+
+dali.keyboardFocusManager.connect("keyboard-focus-change", myCallback)
+```
+
+@class KeyboardFocusManager
+
+ */
--- /dev/null
+/**
+## Layer Actor API ( extends Actor API)
+
+ Layers provide a mechanism for overlaying groups of actors on top of each other.
+
+ When added to the stage, a layer can be ordered relative to other layers. The bottom
+ layer is at depth zero. The stage provides a default layer for it's children.
+
+ Layered actors inherit position etc. as normal, but are drawn in an order determined
+ by the layers. The depth buffer is cleared before each layer is rendered unless depth
+ test is disabled or there's no need for it based on the layers contents;
+ actors in lower layers cannot obscure actors in higher layers.
+
+ If depth test is disabled, there is no performance overhead from clearing the depth buffer.
+
+
+### Simple example
+
+```
+
+var textActor1 = new dali.TextActor( "I'm above" );
+var textActor2 = new dali.TextActor( "I'm below" );
+
+// add first actor to the stage
+dali.stage.add( textActor1 );
+
+// create a layer and add second actor
+var layer = new dali.Layer();
+layer.add( textActor2 );
+dali.stage.add( layer ); // textActor2 is now above textActor1
+
+// shift layer to bottom
+layer.lowerToBottom(); // textActor2 is now below textActor1
+```
+
+### Layer Actor Specific Properties
+
+| Name | Type | Writable | Animatable|
+|------------------------|------------|--------------|-----------|
+| clippingEnabled |BOOLEAN | ✔ | ✘ |
+| clippingBox | RECTANGLE ([0,0,400,600]) | ✔ | ✘|
+
+ @class Layer
+ @extends Actor
+ */
--- /dev/null
+/**
+ ## Module loader
+
+ See {{#crossLink "ModuleLoader/require:method"}}{{/crossLink}}
+
+ @class ModuleLoader
+ */
+
--- /dev/null
+/**
+ *
+## PanGestureDetector API
+
+
+PanGestureDetector analyse a stream of touch events and looks for panning (or dragging) gestures.
+If an actor is attached to the pan gesture detector, the detector will emit a detected signal to
+the application when it recognises a pan gesture on the attached actor in its analysis.
+
+### Simple example
+
+```
+// Create a pan gesture detector
+var panGestureDetector = new dali.PanGestureDetector();
+
+var actor = new dali.Actor();
+dali.stage.add(actor);
+
+// Attach an actor to the detector
+panGestureDetector.attach(actor);
+
+// Connect the detected signal
+panGestureDetector.connect("pan-detected", onPan);
+
+onPan = function(actor, panGesture)
+{
+ log("Pan gesture state: " + panGesture.state + ", number of touches: " + panGesture.numberOfTouches + ", time stamp: " + panGesture.time + "\n");
+ log("local position: " + panGesture.position.x + ", " + panGesture.position.y + "\n");
+ log("local displacement: " + panGesture.displacement.x + ", " + panGesture.displacement.y + "\n");
+ log("local velocity: " + panGesture.velocity.x + ", " + panGesture.velocity.y + "\n");
+ log("screen position: " + panGesture.screenPosition.x + ", " + panGesture.screenPosition.y + "\n");
+ log("screen displacement: " + panGesture.screenDisplacement.x + ", " + panGesture.screenDisplacement.y + "\n");
+ log("screen velocity: " + panGesture.screenVelocity.x + ", " + panGesture.screenVelocity.y + "\n");
+}
+
+// Detach the actor from the detector
+panGestureDetector.detach(actor);
+```
+@class PanGestureDetector
+
+*/
\ No newline at end of file
--- /dev/null
+/**
+ *
+## Path Animation API
+
+Paths can be used to animate position and orientation of actors.
+
+<img src="../assets/img/path.png"/>
+
+Example
+
+```
+log("Path animation test\n");
+
+var point0 = [ 0.0, 80.0, 0.0 ];
+var point1 = [ 200.0, 200.0, 0.0 ];
+var point2 = [ 400.0, 80.0, 0.0 ];
+
+//Create a path
+var myPath = new dali.Path();
+myPath.points = [ point0, point1, point2 ];
+myPath.generateControlPoints( 0.25 );
+
+function begin()
+{
+
+ var image = new dali.ResourceImage( {url:"gallery-small-45.jpg"} );
+
+ var actor = new dali.ImageActor(image);
+
+ actor.position = [100,100,0];
+ dali.stage.add( actor );
+
+ var animation = new dali.Animation(2.0);
+ var animOptions = { alpha:"easeInOutSine", delay:0.5, duration:1.5 };
+ var forward = new dali.Vector3(1,0,0);
+ animation.animate( actor, myPath, forward, animOptions );
+
+ animation.setLooping( true );
+ animation.play();
+}
+
+begin();
+```
+@class Path
+
+*/
\ No newline at end of file
--- /dev/null
+/**
+ *
+
+## RenderTask API
+
+
+RenderTasks describe how the Dali scene should be rendered.
+
+The {{#crossLink "Stage/getRenderTaskList:method"}}{{/crossLink}} method provides access to an ordered list of render-tasks.
+
+Each RenderTask must specify the source actors to be rendered, and a camera actor from
+which the scene is viewed.
+
+
+RenderTasks may optionally target a frame-buffer, otherwise the default GL surface is used;
+typically this is a window provided by the native system.
+
+
+By default Dali provides a single RenderTask, which renders the entire actor hierachy using
+a default camera actor and GL surface. If stereoscopic rendering is enabled, Dali will create
+two additional render tasks, on for each eye. Each render task will have its own camera parented
+to the default camera actor.
+
+The first RenderTask used for input handling will be the last one rendered, which also has input enabled,
+and has a valid source & camera actor; see {{#crossLink "RenderTask/setInputEnabled:method"}}{{/crossLink}}.
+
+If none of the actors are hit in the last RenderTask rendered, then input handling will continue
+with the second last RenderTask rendered, and so on.
+
+All RenderTasks which target a frame-buffer (i.e. off screen) will be rendered before all RenderTasks
+which target the default GL surface. This allows the user to render intermediate targets which are used
+later when targetting the screen.
+
+A RenderTask targetting a frame-buffer can still be hit-tested, provided that the
+screen->frame-buffer coordinate conversion is successful; see SetScreenToFrameBufferMappingActor().
+```
+var tasklist = dali.stage.getRenderTaskList();
+
+var renderTask0 = tasklist.createTask();
+
+renderTask0.setSourceActor( myActor );
+renderTask0.setClearEnabled( true );
+renderTask0.clearColor = [1.0,0.0,0.0,0.0];
+
+renderTask0.clearColor = [1.0,0.0,0.0,0.0];
+
+var camera = new dali.CameraActor();
+
+renderTask0.setCameraActor( camera );
+```
+
+### Render Task Specific Properties
+
+
+| Name | Type | Writable | Animatable|
+|------------------------|------------|--------------|-----------|
+|viewportPosition | VECTOR2 | ✔ | ✘ |
+|viewportSize | VECTOR2 | ✔ | ✘ |
+|clearColor | VECTOR4 | ✔ | ✘ |
+
+
+@class RenderTask
+*/
+
+/**
+ * View port position
+ *
+ * @property viewportPosition
+ * @type dali Vector2
+ */
+viewportPosition
+
+/**
+ * View port size
+ *
+ * @property parentOrigin
+ * @type dali Vector3
+ */
+viewportSize
+
+ /**
+ * clear color
+ *
+ * @property clearColor
+ * @type dali Vector4
+ */
+ clearColor
\ No newline at end of file
--- /dev/null
+/**
+ *
+ * <h2> Renderable Actor ( Extends Actor API )</h2>
+ * Renderable actors are actors that can be drawn.
+ * These currently are:
+ * - {{#crossLink "ImageActor"}}{{/crossLink}}
+ * - {{#crossLink "TextActor"}}{{/crossLink}}
+ * - {{#crossLink "MeshActor"}}{{/crossLink}}
+ *
+ * @class RenderableActor
+ * @extends Actor
+ */
+
+
+
+
+
--- /dev/null
+/**
+ *
+## ResourceImage (extends Image)
+
+A resource image extends the basic {{#crossLink "image"}}Image class{{/crossLink}} with
+the ability to load an image from a file.
+
+ResourceImage supports two types of load policies
+
+- dali.IMAGE_LOAD_POLICY_IMMEDIATE // load image once it is created (default)
+- dali.IMAGE_LOAD_POLICY_ON_DEMAND // delay loading until the image is being used (a related actor is added to Stage)
+
+### Simple example
+```
+
+var image = new dali.ResourceImage( { url:"my_image.png" } );
+
+var imageActor = new dali.ImageActor( image );
+
+```
+### Advanced example
+```
+
+function imageLoaded( image )
+{
+ log("image loaded " +image.url + "\n");
+}
+
+var options = {
+ url:"my_image.png",
+ loadPolicy:dali.IMAGE_LOAD_POLICY_IMMEDIATE,
+ releasePolicy: dali.IMAGE_RELEASE_POLICY_UNUSED
+}
+var image = new dali.ResourceImage( options );
+
+image.connect("image-loading-finished", finished );
+
+var imageActor = new dali.ImageActor( image );
+
+```
+@class ResourceImage
+@extends Image
+ */
\ No newline at end of file
--- /dev/null
+/**
+ *
+
+## Shader Effects API
+
+Shader effects provide a visual effect for actors.
+
+For a Custom shader you can provide the vertex and fragment shader code as strings.
+Each shader is provided with default uniforms and attributes.
+For a vertex shader this part contains the following code:
+```
+precision highp float;
+attribute vec3 aPosition;
+attribute vec2 aTexCoord;
+uniform mat4 uMvpMatrix;
+uniform mat4 uModelMatrix;
+uniform mat4 uViewMatrix;
+uniform mat4 uModelView;
+uniform mat3 uNormalMatrix;
+uniform mat4 uProjection;
+uniform vec4 uColor;
+varying vec2 vTexCoord;
+```
+The custom shader part is expected to output the vertex position and texture coordinate.
+A basic custom vertex shader would contain the following code:
+```
+void main()
+{
+ gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);
+ vTexCoord = aTexCoord;
+}
+```
+For an Image fragment shader the default attributes and uniforms are:
+```
+precision mediump float;
+uniform sampler2D sTexture;
+uniform sampler2D sEffect;
+uniform vec4 uColor;
+varying vec2 vTexCoord;
+```
+The custom shader is expected to output the fragment color.
+The basic fragment shader for images would contain:
+```
+void main()
+{
+ gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;
+}
+```
+The API supports functionality such as:
+
++ new dali.{{#crossLink "ShaderEffect/ShaderEffect:method"}}{{/crossLink}}
++ {{#crossLink "ShaderEffect/setUniform:method"}}{{/crossLink}}
+
+### Example of using a custom uniform to brighten an Image (Fragment Shader)
+
+<img src="../assets/img/fragment-shader-color.png">
+```
+createColorEffect = function()
+{
+
+ // add uColorShift to the pixel color
+
+ var fragShader =
+ "uniform lowp vec4 uColorShift; \
+ \
+ void main() \
+ { \
+ gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor + uColorShift; \
+ }"
+
+ var shaderOptions = {
+ geometryType: "image",
+ fragmentShader: fragShader
+ };
+
+ // create a new shader effect
+ var shader = new dali.ShaderEffect(shaderOptions);
+
+ // add the color shift uniform so we can modify and animate it
+ shader.setUniform("uColorShift", [0.0, 0.0, 0.0, 0]);
+ return shader;
+}
+// create an image actor and add an image to it
+var image = new dali.ResourceImage( { url: getImageDirectory() +"gallery-medium-50.jpg"});
+var imageActor = new dali.ImageActor( image );
+imageActor.parentOrigin = dali.CENTER;
+dali.stage.add( imageActor );
+
+var colorShift = createColorEffect();
+
+colorShift.setUniform( "uColorShift", [0.5,0.5,0.5,0.0] ); // increase RGB by 50%
+
+imageActor.setShaderEffect( colorShift );
+```
+
+For an example of animating we can just do:
+```
+var shaderAnim = new dali.Animation(10);
+
+var animOptions = {
+ alpha: "doubleEaseInOutSine60",
+};
+
+// animate the color uniform to full white
+shaderAnim.animateTo( colorShift, "uColorShift", dali.COLOR_WHITE, animOptions);
+
+shaderAnim.play();
+```
+Like all animatable properties we can also use keyframes to animate the value.
+* * *
+
+### Example of animating a custom uniform to perform a mask operation (Fragment Shader)
+
+In this example we are using the OpenGL discard function to draw an image with a circular mask.
+
+<img src="../assets/img/fragment-shader-reveal.png">
+```
+createRevealEffect = function()
+{
+// texture co-ordinate is from 0..1
+// we shift the texture co-ordinate to -0.5 to 0.5 to center it
+// then work out the radius from the centre, using ( a^2 + b^2) = c^2
+// we use the dot product to perform the a^2 + b^2
+// then just perform uRadius * uRadius to workout c^2
+
+ var fragShader =
+ " uniform lowp float uRadius; \
+ \
+ void main() \
+ { \
+ lowp vec2 pos= vec2(vTexCoord.x-0.5,vTexCoord.y-0.5); \
+ lowp float radius = dot(pos, pos ) ; \
+ if( radius > (uRadius*uRadius) )\
+ discard; \
+ gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor ; \
+ }"
+
+ var shaderOptions = {
+ geometryType: "image",
+ fragmentShader: fragShader
+ };
+
+ // create a new shader effect
+ var shader = new dali.ShaderEffect(shaderOptions);
+
+ // set the uniform
+ shader.setUniform("uRadius",0.0);
+ return shader;
+}
+// create an image actor and add an image to it
+var filename = getImageDirectory() +"gallery-medium-50.jpg;
+var image = new dali.ResourceImage( {url: filename });
+var imageActor = new dali.ImageActor( image );
+imageActor.parentOrigin = dali.CENTER;
+dali.stage.add( imageActor );
+
+var revealEffect = createRevealEffect();
+
+imageActor.setShaderEffect( revealEffect );
+
+var shaderAnim = new dali.Animation(5);
+
+var animOptions = {
+ alpha: "easeInOutSine",
+ };
+
+// animate up to radius = 0.5 ( a full circle )
+// if we go to 1.0 then it will go to a full box
+shaderAnim.animateTo( revealEffect, "uRadius", 0.5,animOptions);
+shaderAnim.play();
+
+* * *
+### Example of paper twisting in the wind with color (Vertex + Fragment Shader)
+
+<img src="../assets/img/vertex-shader.png"><br>
+
+The example does the following:
+
++ Creates a varying variable called vColor in the vertex shader.
+ + The vColor is set to the position of the vertex, so the color changes depending on its position
++ Create a uniform called uOffset which modifies the xPosition of each vertex, creating a twist effect
+
+An ImageActor normally only has 4 vertices ( quad ). To allow the image to twist and bend we need it to have more
+vertices. To do this we can break the image into a grid using the gridX and gridY geometry hints.
+
+<img src="../assets/img/shader-grid-hint.png">
+
+
+createTwistEffect = function()
+{
+
+ // do some maths on the x-position to move it based on y,z pos + uOffset
+ var vertexShader =
+ " \
+ varying lowp vec4 vColor; \
+ uniform lowp float uOffset; \
+ \
+ void main() \
+ { \
+ vec4 pos = uProjection * uModelView * vec4(aPosition, 1.0); \
+ pos.x= 3*pos.z*(sin(1.57+uOffset+pos.y/1000.0)); \
+ gl_Position =pos; \
+ vColor = pos/500.0;\
+ vTexCoord = aTexCoord; \
+ }"
+
+ // add the vColor to the pixel color to tint it
+ var fragShader =
+ " \
+ varying lowp vec4 vColor; \
+ void main() \
+ { \
+ gl_FragColor = texture2D( sTexture, vTexCoord ) *uColor + vColor*0.2; \
+ }"
+
+ var shaderOptions = {
+ geometryType: "image",
+ vertexShader: vertexShader,
+ fragmentShader: fragShader,
+ geometryHints: ["grid"]
+ };
+
+ // create a new shader effect
+ var shader = new dali.ShaderEffect(shaderOptions);
+
+ // set the uniform
+ shader.setUniform("uOffset",0.0);
+ return shader;
+}
+
+
+dali.stage.setBackgroundColor( dali.COLOR_WHITE);
+
+var image = new dali.ResourceImage( { url:getImageDirectory() +"gallery-medium-50.jpg"});
+var imageActor = new dali.ImageActor( image );
+imageActor.parentOrigin = dali.CENTER;
+imageActor.setCullFace( dali.CULL_FACE_DISABLE ); // disable face culling so we can see both sides
+dali.stage.add( imageActor );
+
+// start it of tilted around the y-axis
+imageActor.rotation=new dali.Rotation(90, 0, 1, 0);
+
+var twistEffect = createTwistEffect();
+imageActor.setShaderEffect( twistEffect );
+
+var shaderAnim = new dali.Animation(1);
+var animOptions = {
+ alpha: "bounce",
+ duration:20
+ };
+shaderAnim.animateTo( twistEffect, "uOffset",20,animOptions);
+
+shaderAnim.play();
+```
+Note: In order for fade and color animations to work, the fragment shader needs to multiply the fragment color
+with the uniform color "uColor" of the node
+
+@class ShaderEffect
+*/
\ No newline at end of file
--- /dev/null
+/**
+## Stage API
+
+The Stage is a top-level object used for displaying a tree of Actors.
+
+ - Stage is a static object used by accessing the dali.stage object.
+ - Stage provides a top-level "root" actor.
+ - Stage provides Key Events to the application
+ - Stage has a background color you can set, see {{#crossLink "stage/setBackgroundColor:method"}}{{/crossLink}}
+
+When an actor is not required, remove it from the stage to save memory and help performance.
+```
+dali.stage.setBackgroundColor( dali.COLOR_WHITE);
+
+var stageSize = dali.stage.getSize();
+
+var imageActor = new dali.ImageActor( );
+
+dali.stage.add( imageActor );
+
+// when the actor is no longer required
+dali.stage.remove( imageActor );
+```
+
+<img src="../assets/img/stage.png"/>
+
+### Key Events
+
+Key events are received through the key-event callback.
+
+```
+daliApp.myCallback = function (keyEvent)
+{
+ switch (keyEvent.keyDescription) {
+ case "Up": log("up");
+ break;
+
+ case "Down": log("down");
+ break;
+
+ case "Left": log("left");
+ break;
+
+ case "Right": log("right");
+ break;
+
+ }
+}
+
+dali.stage.connect("key-event", daliApp.myCallback);
+```
+
+The key event object has the following properties
+```
+ KeyEvent = {
+ state, // boolean = "down" or "up" key state
+ shiftPressed, // boolean, shift key is held
+ ctrlPressed, // boolean, ctrl key is held
+ altPressed, // boolean, alt key is held
+ keyModifiers, // key modifiers
+ keyCode, // key code
+ keyDescription, // key description
+ timestamp // The time in milli-seconds when the event occured
+ }
+```
+ @class Stage
+*/
\ No newline at end of file
--- /dev/null
+/**
+## Text Actor API
+TextActor is a basic actor for displaying a text label
+
+By default the text actor always uses the natural size of the text, when the text property is set,
+unless SetSize is called to override the size or size is animated to some other size.
+
+Natural size for TextActor is the same as the size returned by dali.font.MeasureText( string )
+using the font that the TextActor is using.
+
+By default {{#crossLink "RenderableActor/setCullFace:method"}}CullFaceMode{{/crossLink}} is set to CullNone to enable the TextActor to be viewed from all angles.
+
+### Simple example
+```
+var textActor = new dali.TextActor( "Hello world" );
+
+// by default an actor is anchored to the top-left of it's parent actor
+// change it to the middle
+textActor.parentOrigin = [0.5,0.5,0.5];
+
+// scale it up by 4 times in x,y
+textActor.scale = [ 4, 4, 1 ];
+
+// add to the stage
+dali.stage.add( textActor );
+```
+
+### Example using a font and text options ###
+```
+var fontInfo =
+{
+ family : "Arial",
+ style :"Bold",
+ pointSize:20
+}
+
+var arialFont = new dali.Font( fontInfo );
+var textOptions =
+{
+ font: arialFont,
+ isRightToLeft: true,
+ fontDetection: true // default is true
+}
+
+var textActor1 = new dali.TextActor( "Hello-world" , textOptions );
+
+// this will automatically chose a different font that can display the text
+var textActor2 = new dali.TextActor( "繁體中文" , textOptions );
+```
+
+| Name | Type | Writable | Animatable|
+|------------------------|------------|--------------|-----------|
+| text | STRING | ✔ |✘ |
+| font | STRING | ✔ |✘ |
+| font-style | STRING | ✔ |✘ |
+| outline-enable | BOOLEAN | ✔ |✘ |
+| outline-color | VECTOR4 | ✔ |✘ |
+| outline-thickness-width| VECTOR2 | ✔ |✘ |
+| smooth-edge | FLOAT | ✔ |✘ |
+| glow-enable | BOOLEAN | ✔ |✘ |
+| glow-color | VECTOR4 | ✔ |✘ |
+| glow-intensity | FLOAT | ✔ |✘ |
+| shadow-enable | BOOLEAN | ✔ |✘ |
+| shadow-color | VECTOR4 | ✔ |✘ |
+| shadow-offset | VECTOR2 | ✔ |✘ |
+| italics-angle | FLOAT | ✔ |✘ |
+| underline | BOOLEAN | ✔ |✘ |
+| weight | INTEGER | ✔ |✘ |
+| font-detection-automati| BOOLEAN | ✔ |✘ |
+| gradient-color | VECTOR4 | ✔ |✘ |
+| gradient-start-point | VECTOR2 | ✔ |✘ |
+| gradient-end-point | VECTOR2 | ✔ |✘ |
+| shadow-size | FLOAT | ✔ |✘ |
+| text-color | VECTOR4 | ✔ |✘ |
+
+@class TextActor
+@extends RenderableActor
+ */
+
--- /dev/null
+/**
+ *
+
+## Using Texture Atlases in DALi
+
+
+### Example demo application
+
+<img src="../assets/img/shared/texture-atlas/image-wall.jpg">
+
+
+### Application above is running slow as there are many small individual images displayed (50)
+
+
+<table>
+ <tr>
+ <td> Launch Time </td>
+ <td> Slow </td>
+ <td> Has to perform: <br>- 50 file open requests and multiple reads for each image</td>
+ </tr>
+ <tr>
+ <td> Memory Usage </td>
+ <td> High </td>
+ <td> Has to create:
+ <br>- 50 Dali::Image objects
+ <br>- 50 OpenGL Textures
+ </td>
+ </tr>
+ <tr>
+ <td>Rendering Performance </td>
+ <td> Slow </td>
+ <td> Has to perform:
+ <br>- 50 glBindTexture calls per frame ( each OpenGL calls takes time)
+ <br>- 50 a frame = 3000 calls per second @60 FPS.
+ <br>- Texture switching is a major state change in the GPU
+ </td>
+ </tr>
+</table>
+<br><br>
+
+
+### Solutions to problem: Use a Texture Atlas
+
+A texture atlas is simply one larger image that contains smaller images.<br>
+A texture atlas is sometimes called a sprite sheet, bitmap sheet or texture pack.
+<br><br>
+<img src="../assets/img/shared/texture-atlas/atlas.jpg">
+<br><br>
+Dali::ImageActor has the ability to display a portion of an image using ImageActor::PixelArea setting.
+For example to display the first 3 image in the atlas
+<br><br>
+```
+var imageAtlas = new dali.ResourceImage( {url:"atlas.png"} )
+```
+<img src="../assets/img/example-javascript-code.png">
+<br>
+### Result of using an Atlas
+<table>
+ <tr>
+ <td> Launch Time </td>
+ <td> Fast </td>
+ <td> Has to perform: <br>- 1 file open request </td>
+ </tr>
+ <tr>
+ <td> Memory Usage </td>
+ <td> Better </td>
+ <td> Has to create:
+ <br>- 1 Dali::Image objects
+ <br>- 1 OpenGL Textures
+ </td>
+ </tr>
+ <tr>
+ <td>Rendering Performance </td>
+ <td> Fast </td>
+ <td> Has to perform:
+ <br>- 1 glBindTexture calls per frame ( each OpenGL calls takes time)
+ <br>- 1 a frame = 6- calls per second @60 FPS.
+ </td>
+ </tr>
+</table>
+<br>
+## Atlas creation guide
+
+Many tools exist for creating texture atlases.<br>
+In the following example we are using a tool called TexturePacker as DALi has an exporter script for it.
+The exporter automatically generates a source file that has the ImageActor::PixelArea pre-defined.
+<br>
+
++ Download http://www.codeandweb.com/texturepacker
++ Launch TexturePacker
++ Go to the menu File -> Preferences
++ Set the "Exporter directory" to be the location of <b>dali-toolkit/texture-atlas-exporter</b> <br>
+
+ <img src="../assets/img/shared/texture-atlas/texture-packer-preferences.jpg"> <br>
++ <b> Restart the application! </b>
++ Select DALi 3D framework for new project
+
+ <img src="../assets/img/shared/texture-atlas/texture-packer-startup.jpg"><br>
++ <h3> Create the atlas </h3>
+ <img src="../assets/img/shared/texture-atlas/texture-packer-add-sprites.jpg">
++ <h3> Click publish to produce the files </h3><br><br>
+ <img src="../assets/img/shared/texture-atlas/texture-packer-publish.jpg">
+
+## Using the generated cpp file
+
+The generated cpp file contains 3 different ways of describing the atlas.
+2 ways are designed for the DALi C++ API, the 3rd way is for JavaScript.
+Example exported property map from TexturePacker:
+```
+var ATLAS_IMAGE_LIST : [
+ { name: "add_user_usericon_bg", x: 2, y:109, w:105, h:105, dali.BLENDING_ON },
+ { name: "app_background", x: 180, y:183, w:1, h:1, dali.BLENDING_OFF },
+ { name: "btn_arrow_left", x: 141, y:183, w:11, h:20, dali.BLENDING_ON },
+ { name: "btn_arrow_right", x: 154, y:183, w:11, h:20, dali.BLENDING_ON },
+ { name: "icn_app_foc", x: 194, y:2, w:72, h:72, dali.BLENDING_ON },
+ { name: "icn_app_nor", x: 109, y:109, w:72, h:72, dali.BLENDING_ON }
+ ]
+var atlas = new dali.ResourceImage( { url: "atlas_filename.png" });
+
+// display the user icon using the size / position data in the ATLAS_IMAGE_LIST
+var userIconData = ATLAS_IMAGE_LIST[0];
+var userIconRect = [ userIconData.x, userIconData.y,userIconData.w,userIconData.h];
+
+var btnArrowLeft = new dali.ImageActor( atlas, userIconRect );
+```
+
+## Atlas creation tips
+
+
+ - Compress the atlas
+ - Avoid adding large images to the Atlas.
+ E.g. don't add background images to it. Medium to large images should
+ be kept seperate. <br><br>
+ <img src="../assets/img/shared/texture-atlas/atlas-size.jpg">
+
+ - Try to ensure the atlas contains only images that are frequently used. <br>
+ There's no point in having images taking up GPU texture memory if they're not displayed.<br>
+
+ - Avoid very large atlases <br>
+ Try to create multiple atlases based on how they are used within your application.<br>
+ <br>
+ Alternatively Texture packer has the option to split atlases ( search help for Multipack)
+ -
+
+
+
+ @class TextureAtlases
+ */
+
--- /dev/null
+
+/**
+ *
+
+## Texture Compression
+
+Using compressing the textures will:
+
+- Speed up rendering in time the GPU == less power used due to less texture data being transferred.
+- Reduce texture memory usage.
+- Speed up load times. Smaller files mean quicker load times.
+
+DALi supports the KTX file format.
+You just load the compressed texture like you would any other image.
+
+ var image = new dali.ResourceImage({url:"my_compressed_file.ktx"});
+
+ARMS texture compression tool<br>
+http://malideveloper.arm.com/develop-for-mali/tools/asset-creation/mali-gpu-texture-compression-tool/ <br>
+
+Here is an example of using the ARM compression tool.
+
+<img src="../assets/img/shared/texture-atlas/compression-options.jpg">
+
+<img src="../assets/img/shared/texture-atlas/compression-example.jpg">
+
+As shown above the ETC-1 compression format does not support alpha.<br> As a work around the tool will export
+the alpha as a seperate compressed image.
+In order to combine both the images you need to use a custom shader.
+Here is an example shader:
+```
+var fragSource = " \
+void main() \
+{ \
+ vec4 v4Color = (texture2D(sTexture, vTexCoord) * uColor); \
+ v4Color.a = texture2D(sEffect, vTexCoord ).r; \
+ gl_FragColor = v4Color; \
+}";
+
+var shaderEffect = new dali.ShaderEffect( "", fragSource);
+
+var atlasImageRGB = new dali.ResourceImage( { url:"ATLAS_RGB_FILENAME.KTX"} );
+
+var atlasImageAlpha = new dali.ResourceImage( { url:"ATLAS_ALPHA_FILENAME.KTX"} );
+
+shaderEffect.setEffectImage( atlasImageAlpha );
+
+// to create Image Actor
+ImageActor imageActor = ImageActor::New( mAtlasImageRGB, GetImagePosition( info) );
+
+imageActor.setShaderEffect( shaderEffect );
+
+imageActor.setBlendMode( dali.BLENDING_ON );
+```
+ @class TextureCompression
+
+
+ */
--- /dev/null
+/*
+Font sizes for all selectors other than the body are given in percentages,
+with 100% equal to 13px. To calculate a font size percentage, multiply the
+desired size in pixels by 7.6923076923.
+
+Here's a quick lookup table:
+
+10px - 76.923%
+11px - 84.615%
+12px - 92.308%
+13px - 100%
+14px - 107.692%
+15px - 115.385%
+16px - 123.077%
+17px - 130.769%
+18px - 138.462%
+19px - 146.154%
+20px - 153.846%
+*/
+
+html {
+ background: #fff;
+ color: #333;
+ overflow-y: scroll;
+}
+
+body {
+ /*font: 13px/1.4 'Lucida Grande', 'Lucida Sans Unicode', 'DejaVu Sans', 'Bitstream Vera Sans', 'Helvetica', 'Arial', sans-serif;*/
+ font: 13px/1.4 'Helvetica', 'Arial', sans-serif;
+ margin: 0;
+ padding: 0;
+}
+
+/* -- Links ----------------------------------------------------------------- */
+a {
+ color: #356de4;
+ text-decoration: none;
+}
+
+.hidden {
+ display: none;
+}
+
+a:hover { text-decoration: underline; }
+
+/* "Jump to Table of Contents" link is shown to assistive tools, but hidden from
+ sight until it's focused. */
+.jump {
+ position: absolute;
+ padding: 3px 6px;
+ left: -99999px;
+ top: 0;
+}
+
+.jump:focus { left: 40%; }
+
+/* -- Paragraphs ------------------------------------------------------------ */
+p { margin: 1.3em 0; }
+dd p, td p { margin-bottom: 0; }
+dd p:first-child, td p:first-child { margin-top: 0; }
+
+/* -- Headings -------------------------------------------------------------- */
+h1, h2, h3, h4, h5, h6 {
+ color: #D98527;/*was #f80*/
+ font-family: 'Trebuchet MS', sans-serif;
+ font-weight: bold;
+ line-height: 1.1;
+ margin: 1.1em 0 0.5em;
+}
+
+h1 {
+ font-size: 184.6%;
+ color: #30418C;
+ margin: 0.75em 0 0.5em;
+}
+
+h2 {
+ font-size: 153.846%;
+ color: #E48A2B;
+}
+
+h3 { font-size: 138.462%; }
+
+h4 {
+ border-bottom: 1px solid #DBDFEA;
+ color: #E48A2B;
+ font-size: 115.385%;
+ font-weight: normal;
+ padding-bottom: 2px;
+}
+
+h5, h6 { font-size: 107.692%; }
+
+/* -- Code and examples ----------------------------------------------------- */
+code, kbd, pre, samp {
+ font-family: Menlo, Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;
+ font-size: 92.308%;
+ line-height: 1.35;
+}
+
+p code, p kbd, p samp, li code {
+ background: #FCFBFA;
+ border: 1px solid #EFEEED;
+ padding: 0 3px;
+}
+
+a code, a kbd, a samp,
+pre code, pre kbd, pre samp,
+table code, table kbd, table samp,
+.intro code, .intro kbd, .intro samp,
+.toc code, .toc kbd, .toc samp {
+ background: none;
+ border: none;
+ padding: 0;
+}
+
+pre.code, pre.terminal, pre.cmd {
+ overflow-x: auto;
+ *overflow-x: scroll;
+ padding: 0.3em 0.6em;
+}
+
+pre.code {
+ background: #FCFBFA;
+ border: 1px solid #EFEEED;
+ border-left-width: 5px;
+}
+
+pre.terminal, pre.cmd {
+ background: #F0EFFC;
+ border: 1px solid #D0CBFB;
+ border-left: 5px solid #D0CBFB;
+}
+
+/* Don't reduce the font size of <code>/<kbd>/<samp> elements inside <pre>
+ blocks. */
+pre code, pre kbd, pre samp { font-size: 100%; }
+
+/* Used to denote text that shouldn't be selectable, such as line numbers or
+ shell prompts. Guess which browser this doesn't work in. */
+.noselect {
+ -moz-user-select: -moz-none;
+ -khtml-user-select: none;
+ -webkit-user-select: none;
+ -o-user-select: none;
+ user-select: none;
+}
+
+/* -- Lists ----------------------------------------------------------------- */
+dd { margin: 0.2em 0 0.7em 1em; }
+dl { margin: 1em 0; }
+dt { font-weight: bold; }
+
+/* -- Tables ---------------------------------------------------------------- */
+caption, th { text-align: left; }
+
+table {
+ border-collapse: collapse;
+ width: 100%;
+}
+
+td, th {
+ border: 1px solid #fff;
+ padding: 5px 12px;
+ vertical-align: top;
+}
+
+td { background: #E6E9F5; }
+td dl { margin: 0; }
+td dl dl { margin: 1em 0; }
+td pre:first-child { margin-top: 0; }
+
+th {
+ background: #D2D7E6;/*#97A0BF*/
+ border-bottom: none;
+ border-top: none;
+ color: #000;/*#FFF1D5*/
+ font-family: 'Trebuchet MS', sans-serif;
+ font-weight: bold;
+ line-height: 1.3;
+ white-space: nowrap;
+}
+
+
+/* -- Layout and Content ---------------------------------------------------- */
+#doc {
+ margin: auto;
+ min-width: 1024px;
+}
+
+.content { padding: 0 20px 0 25px; }
+
+.sidebar {
+ padding: 0 15px 0 10px;
+}
+#bd {
+ padding: 7px 0 130px;
+ position: relative;
+ width: 99%;
+}
+
+/* -- Table of Contents ----------------------------------------------------- */
+
+/* The #toc id refers to the single global table of contents, while the .toc
+ class refers to generic TOC lists that could be used throughout the page. */
+
+.toc code, .toc kbd, .toc samp { font-size: 100%; }
+.toc li { font-weight: bold; }
+.toc li li { font-weight: normal; }
+
+/* -- Intro and Example Boxes ----------------------------------------------- */
+/*
+.intro, .example { margin-bottom: 2em; }
+.example {
+ -moz-border-radius: 4px;
+ -webkit-border-radius: 4px;
+ border-radius: 4px;
+ -moz-box-shadow: 0 0 5px #bfbfbf;
+ -webkit-box-shadow: 0 0 5px #bfbfbf;
+ box-shadow: 0 0 5px #bfbfbf;
+ padding: 1em;
+}
+.intro {
+ background: none repeat scroll 0 0 #F0F1F8; border: 1px solid #D4D8EB; padding: 0 1em;
+}
+*/
+
+/* -- Other Styles ---------------------------------------------------------- */
+
+/* These are probably YUI-specific, and should be moved out of Selleck's default
+ theme. */
+
+.button {
+ border: 1px solid #dadada;
+ -moz-border-radius: 3px;
+ -webkit-border-radius: 3px;
+ border-radius: 3px;
+ color: #444;
+ display: inline-block;
+ font-family: Helvetica, Arial, sans-serif;
+ font-size: 92.308%;
+ font-weight: bold;
+ padding: 4px 13px 3px;
+ -moz-text-shadow: 1px 1px 0 #fff;
+ -webkit-text-shadow: 1px 1px 0 #fff;
+ text-shadow: 1px 1px 0 #fff;
+ white-space: nowrap;
+
+ background: #EFEFEF; /* old browsers */
+ background: -moz-linear-gradient(top, #f5f5f5 0%, #efefef 50%, #e5e5e5 51%, #dfdfdf 100%); /* firefox */
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f5f5f5), color-stop(50%,#efefef), color-stop(51%,#e5e5e5), color-stop(100%,#dfdfdf)); /* webkit */
+ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f5f5f5', endColorstr='#dfdfdf',GradientType=0 ); /* ie */
+}
+
+.button:hover {
+ border-color: #466899;
+ color: #fff;
+ text-decoration: none;
+ -moz-text-shadow: 1px 1px 0 #222;
+ -webkit-text-shadow: 1px 1px 0 #222;
+ text-shadow: 1px 1px 0 #222;
+
+ background: #6396D8; /* old browsers */
+ background: -moz-linear-gradient(top, #6396D8 0%, #5A83BC 50%, #547AB7 51%, #466899 100%); /* firefox */
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#6396D8), color-stop(50%,#5A83BC), color-stop(51%,#547AB7), color-stop(100%,#466899)); /* webkit */
+ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#6396D8', endColorstr='#466899',GradientType=0 ); /* ie */
+}
+
+.newwindow { text-align: center; }
+
+.header .version em {
+ display: block;
+ text-align: right;
+}
+
+
+#classdocs .item {
+ border-bottom: 1px solid #466899;
+ margin: 1em 0;
+ padding: 1.5em;
+}
+
+#classdocs .item .params p,
+ #classdocs .item .returns p,{
+ display: inline;
+}
+
+#classdocs .item em code, #classdocs .item em.comment {
+ color: green;
+}
+
+#classdocs .item em.comment a {
+ color: green;
+ text-decoration: underline;
+}
+
+#classdocs .foundat {
+ font-size: 11px;
+ font-style: normal;
+}
+
+.attrs .emits {
+ margin-left: 2em;
+ padding: .5em;
+ border-left: 1px dashed #ccc;
+}
+
+abbr {
+ border-bottom: 1px dashed #ccc;
+ font-size: 80%;
+ cursor: help;
+}
+
+.prettyprint li.L0,
+.prettyprint li.L1,
+.prettyprint li.L2,
+.prettyprint li.L3,
+.prettyprint li.L5,
+.prettyprint li.L6,
+.prettyprint li.L7,
+.prettyprint li.L8 {
+ list-style: decimal;
+}
+
+ul li p {
+ margin-top: 0;
+}
+
+.method .name {
+ font-size: 110%;
+}
+
+.apidocs .methods .extends .method,
+.apidocs .properties .extends .property,
+.apidocs .attrs .extends .attr,
+.apidocs .events .extends .event {
+ font-weight: bold;
+}
+
+.apidocs .methods .extends .inherited,
+.apidocs .properties .extends .inherited,
+.apidocs .attrs .extends .inherited,
+.apidocs .events .extends .inherited {
+ font-weight: normal;
+}
+
+#hd {
+ background: whiteSmoke;
+ background: -moz-linear-gradient(top,#DCDBD9 0,#F6F5F3 100%);
+ background: -webkit-gradient(linear,left top,left bottom,color-stop(0%,#DCDBD9),color-stop(100%,#F6F5F3));
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#dcdbd9',endColorstr='#F6F5F3',GradientType=0);
+ border-bottom: 1px solid #DFDFDF;
+ padding: 0 15px 1px 20px;
+ margin-bottom: 15px;
+}
+
+#hd img {
+ margin-right: 10px;
+ vertical-align: middle;
+}
+
+
+/* -- API Docs CSS ---------------------------------------------------------- */
+
+/*
+This file is organized so that more generic styles are nearer the top, and more
+specific styles are nearer the bottom of the file. This allows us to take full
+advantage of the cascade to avoid redundant style rules. Please respect this
+convention when making changes.
+*/
+
+/* -- Generic TabView styles ------------------------------------------------ */
+
+/*
+These styles apply to all API doc tabviews. To change styles only for a
+specific tabview, see the other sections below.
+*/
+
+.yui3-js-enabled .apidocs .tabview {
+ visibility: hidden; /* Hide until the TabView finishes rendering. */
+ _visibility: visible;
+}
+
+.apidocs .tabview.yui3-tabview-content { visibility: visible; }
+.apidocs .tabview .yui3-tabview-panel { background: #fff; }
+
+/* -- Generic Content Styles ------------------------------------------------ */
+
+/* Headings */
+h2, h3, h4, h5, h6 {
+ border: none;
+ color: #30418C;
+ font-weight: bold;
+ text-decoration: none;
+}
+
+.link-docs {
+ float: right;
+ font-size: 15px;
+ margin: 4px 4px 6px;
+ padding: 6px 30px 5px;
+}
+
+.apidocs { zoom: 1; }
+
+/* Generic box styles. */
+.apidocs .box {
+ border: 1px solid;
+ border-radius: 3px;
+ margin: 1em 0;
+ padding: 0 1em;
+}
+
+/* A flag is a compact, capsule-like indicator of some kind. It's used to
+ indicate private and protected items, item return types, etc. in an
+ attractive and unobtrusive way. */
+.apidocs .flag {
+ background: #bababa;
+ border-radius: 3px;
+ color: #fff;
+ font-size: 11px;
+ margin: 0 0.5em;
+ padding: 2px 4px 1px;
+}
+
+/* Class/module metadata such as "Uses", "Extends", "Defined in", etc. */
+.apidocs .meta {
+ background: #f9f9f9;
+ border-color: #efefef;
+ color: #555;
+ font-size: 11px;
+ padding: 3px 6px;
+}
+
+.apidocs .meta p { margin: 0; }
+
+/* Deprecation warning. */
+.apidocs .box.deprecated,
+.apidocs .flag.deprecated {
+ background: #fdac9f;
+ border: 1px solid #fd7775;
+}
+
+.apidocs .box.deprecated p { margin: 0.5em 0; }
+.apidocs .flag.deprecated { color: #333; }
+
+/* Module/Class intro description. */
+.apidocs .intro {
+ background: #f0f1f8;
+ border-color: #d4d8eb;
+}
+
+/* Loading spinners. */
+#bd.loading .apidocs,
+#api-list.loading .yui3-tabview-panel {
+ background: #fff url(../img/spinner.gif) no-repeat center 70px;
+ min-height: 150px;
+}
+
+#bd.loading .apidocs .content,
+#api-list.loading .yui3-tabview-panel .apis {
+ display: none;
+}
+
+.apidocs .no-visible-items { color: #666; }
+
+/* Generic inline list. */
+.apidocs ul.inline {
+ display: inline;
+ list-style: none;
+ margin: 0;
+ padding: 0;
+}
+
+.apidocs ul.inline li { display: inline; }
+
+/* Comma-separated list. */
+.apidocs ul.commas li:after { content: ','; }
+.apidocs ul.commas li:last-child:after { content: ''; }
+
+/* Keyboard shortcuts. */
+kbd .cmd { font-family: Monaco, Helvetica; }
+
+/* -- Generic Access Level styles ------------------------------------------- */
+.apidocs .item.protected,
+.apidocs .item.private,
+.apidocs .index-item.protected,
+.apidocs .index-item.deprecated,
+.apidocs .index-item.private {
+ display: none;
+}
+
+.show-deprecated .item.deprecated,
+.show-deprecated .index-item.deprecated,
+.show-protected .item.protected,
+.show-protected .index-item.protected,
+.show-private .item.private,
+.show-private .index-item.private {
+ display: block;
+}
+
+.hide-inherited .item.inherited,
+.hide-inherited .index-item.inherited {
+ display: none;
+}
+
+/* -- Generic Item Index styles --------------------------------------------- */
+.apidocs .index { margin: 1.5em 0 3em; }
+
+.apidocs .index h3 {
+ border-bottom: 1px solid #efefef;
+ color: #333;
+ font-size: 13px;
+ margin: 2em 0 0.6em;
+ padding-bottom: 2px;
+}
+
+.apidocs .index .no-visible-items { margin-top: 2em; }
+
+.apidocs .index-list {
+ border-color: #efefef;
+ font-size: 12px;
+ list-style: none;
+ margin: 0;
+ padding: 0;
+ -moz-column-count: 4;
+ -moz-column-gap: 10px;
+ -moz-column-width: 170px;
+ -ms-column-count: 4;
+ -ms-column-gap: 10px;
+ -ms-column-width: 170px;
+ -o-column-count: 4;
+ -o-column-gap: 10px;
+ -o-column-width: 170px;
+ -webkit-column-count: 4;
+ -webkit-column-gap: 10px;
+ -webkit-column-width: 170px;
+ column-count: 4;
+ column-gap: 10px;
+ column-width: 170px;
+}
+
+.apidocs .no-columns .index-list {
+ -moz-column-count: 1;
+ -ms-column-count: 1;
+ -o-column-count: 1;
+ -webkit-column-count: 1;
+ column-count: 1;
+}
+
+.apidocs .index-item { white-space: nowrap; }
+
+.apidocs .index-item .flag {
+ background: none;
+ border: none;
+ color: #afafaf;
+ display: inline;
+ margin: 0 0 0 0.2em;
+ padding: 0;
+}
+
+/* -- Generic API item styles ----------------------------------------------- */
+.apidocs .args {
+ display: inline;
+ margin: 0 0.5em;
+}
+
+.apidocs .flag.chainable { background: #46ca3b; }
+.apidocs .flag.protected { background: #9b86fc; }
+.apidocs .flag.private { background: #fd6b1b; }
+.apidocs .flag.async { background: #356de4; }
+.apidocs .flag.required { background: #e60923; }
+
+.apidocs .item {
+ border-bottom: 1px solid #efefef;
+ margin: 1.5em 0 2em;
+ padding-bottom: 2em;
+}
+
+.apidocs .item h4,
+.apidocs .item h5,
+.apidocs .item h6 {
+ color: #333;
+ font-family: inherit;
+ font-size: 100%;
+}
+
+.apidocs .item .description p,
+.apidocs .item pre.code {
+ margin: 1em 0 0;
+}
+
+.apidocs .item .meta {
+ background: none;
+ border: none;
+ padding: 0;
+}
+
+.apidocs .item .name {
+ display: inline;
+ font-size: 14px;
+}
+
+.apidocs .item .type,
+.apidocs .item .type a,
+.apidocs .returns-inline {
+ color: #555;
+}
+
+.apidocs .item .type,
+.apidocs .returns-inline {
+ font-size: 11px;
+ margin: 0 0 0 0;
+}
+
+.apidocs .item .type a { border-bottom: 1px dotted #afafaf; }
+.apidocs .item .type a:hover { border: none; }
+
+/* -- Item Parameter List --------------------------------------------------- */
+.apidocs .params-list {
+ list-style: square;
+ margin: 1em 0 0 2em;
+ padding: 0;
+}
+
+.apidocs .param { margin-bottom: 1em; }
+
+.apidocs .param .type,
+.apidocs .param .type a {
+ color: #666;
+}
+
+.apidocs .param .type {
+ margin: 0 0 0 0.5em;
+ *margin-left: 0.5em;
+}
+
+.apidocs .param-name { font-weight: bold; }
+
+/* -- Item "Emits" block ---------------------------------------------------- */
+.apidocs .item .emits {
+ background: #f9f9f9;
+ border-color: #eaeaea;
+}
+
+/* -- Item "Returns" block -------------------------------------------------- */
+.apidocs .item .returns .type,
+.apidocs .item .returns .type a {
+ font-size: 100%;
+ margin: 0;
+}
+
+/* -- Class Constructor block ----------------------------------------------- */
+.apidocs .constructor .item {
+ border: none;
+ padding-bottom: 0;
+}
+
+/* -- File Source View ------------------------------------------------------ */
+.apidocs .file pre.code,
+#doc .apidocs .file pre.prettyprint {
+ background: inherit;
+ border: none;
+ overflow: visible;
+ padding: 0;
+}
+
+.apidocs .L0,
+.apidocs .L1,
+.apidocs .L2,
+.apidocs .L3,
+.apidocs .L4,
+.apidocs .L5,
+.apidocs .L6,
+.apidocs .L7,
+.apidocs .L8,
+.apidocs .L9 {
+ background: inherit;
+}
+
+/* -- Submodule List -------------------------------------------------------- */
+.apidocs .module-submodule-description {
+ font-size: 12px;
+ margin: 0.3em 0 1em;
+}
+
+.apidocs .module-submodule-description p:first-child { margin-top: 0; }
+
+/* -- Sidebar TabView ------------------------------------------------------- */
+#api-tabview { margin-top: 0.6em; }
+
+#api-tabview-filter,
+#api-tabview-panel {
+ border: 1px solid #dfdfdf;
+}
+
+#api-tabview-filter {
+ border-bottom: none;
+ border-top: none;
+ padding: 0.6em 10px 0 10px;
+}
+
+#api-tabview-panel { border-top: none; }
+#api-filter { width: 97%; }
+
+/* -- Content TabView ------------------------------------------------------- */
+#classdocs .yui3-tabview-panel { border: none; }
+
+/* -- Source File Contents -------------------------------------------------- */
+.prettyprint li.L0,
+.prettyprint li.L1,
+.prettyprint li.L2,
+.prettyprint li.L3,
+.prettyprint li.L5,
+.prettyprint li.L6,
+.prettyprint li.L7,
+.prettyprint li.L8 {
+ list-style: decimal;
+}
+
+/* -- API options ----------------------------------------------------------- */
+#api-options {
+ font-size: 11px;
+ margin-top: 2.2em;
+ position: absolute;
+ right: 1.5em;
+}
+
+/*#api-options label { margin-right: 0.6em; }*/
+
+/* -- API list -------------------------------------------------------------- */
+#api-list {
+ margin-top: 1.5em;
+ *zoom: 1;
+}
+
+.apis {
+ font-size: 12px;
+ line-height: 1.4;
+ list-style: none;
+ margin: 0;
+ padding: 0.5em 0 0.5em 0.4em;
+}
+
+.apis a {
+ border: 1px solid transparent;
+ display: block;
+ margin: 0 0 0 -4px;
+ padding: 1px 4px 0;
+ text-decoration: none;
+ _border: none;
+ _display: inline;
+}
+
+.apis a:hover,
+.apis a:focus {
+ background: #E8EDFC;
+ background: -moz-linear-gradient(top, #e8edfc 0%, #becef7 100%);
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#E8EDFC), color-stop(100%,#BECEF7));
+ border-color: #AAC0FA;
+ border-radius: 3px;
+ color: #333;
+ outline: none;
+}
+
+.api-list-item a:hover,
+.api-list-item a:focus {
+ font-weight: bold;
+ text-shadow: 1px 1px 1px #fff;
+}
+
+.apis .message { color: #888; }
+.apis .result a { padding: 3px 5px 2px; }
+
+.apis .result .type {
+ right: 4px;
+ top: 7px;
+}
+
+.api-list-item .yui3-highlight {
+ font-weight: bold;
+}
+
--- /dev/null
+../../../../../../docs/content/images/
\ No newline at end of file
--- /dev/null
+<!doctype html>
+<html>
+ <head>
+ <title>Redirector</title>
+ <meta http-equiv="refresh" content="0;url=../">
+ </head>
+ <body>
+ <a href="../">Click here to redirect</a>
+ </body>
+</html>
--- /dev/null
+YUI.add('api-filter', function (Y) {
+
+Y.APIFilter = Y.Base.create('apiFilter', Y.Base, [Y.AutoCompleteBase], {
+ // -- Initializer ----------------------------------------------------------
+ initializer: function () {
+ this._bindUIACBase();
+ this._syncUIACBase();
+ },
+ getDisplayName: function(name) {
+
+ Y.each(Y.YUIDoc.meta.allModules, function(i) {
+ if (i.name === name && i.displayName) {
+ name = i.displayName;
+ }
+ });
+
+ return name;
+ }
+
+}, {
+ // -- Attributes -----------------------------------------------------------
+ ATTRS: {
+ resultHighlighter: {
+ value: 'phraseMatch'
+ },
+
+ // May be set to "classes" or "modules".
+ queryType: {
+ value: 'classes'
+ },
+
+ source: {
+ valueFn: function() {
+ var self = this;
+ return function(q) {
+ var data = Y.YUIDoc.meta[self.get('queryType')],
+ out = [];
+ Y.each(data, function(v) {
+ if (v.toLowerCase().indexOf(q.toLowerCase()) > -1) {
+ out.push(v);
+ }
+ });
+ return out;
+ };
+ }
+ }
+ }
+});
+
+}, '3.4.0', {requires: [
+ 'autocomplete-base', 'autocomplete-highlighters', 'autocomplete-sources'
+]});
--- /dev/null
+YUI.add('api-list', function (Y) {
+
+var Lang = Y.Lang,
+ YArray = Y.Array,
+
+ APIList = Y.namespace('APIList'),
+
+ classesNode = Y.one('#api-classes'),
+ inputNode = Y.one('#api-filter'),
+ modulesNode = Y.one('#api-modules'),
+ tabviewNode = Y.one('#api-tabview'),
+
+ tabs = APIList.tabs = {},
+
+ filter = APIList.filter = new Y.APIFilter({
+ inputNode : inputNode,
+ maxResults: 1000,
+
+ on: {
+ results: onFilterResults
+ }
+ }),
+
+ search = APIList.search = new Y.APISearch({
+ inputNode : inputNode,
+ maxResults: 100,
+
+ on: {
+ clear : onSearchClear,
+ results: onSearchResults
+ }
+ }),
+
+ tabview = APIList.tabview = new Y.TabView({
+ srcNode : tabviewNode,
+ panelNode: '#api-tabview-panel',
+ render : true,
+
+ on: {
+ selectionChange: onTabSelectionChange
+ }
+ }),
+
+ focusManager = APIList.focusManager = tabviewNode.plug(Y.Plugin.NodeFocusManager, {
+ circular : true,
+ descendants: '#api-filter, .yui3-tab-panel-selected .api-list-item a, .yui3-tab-panel-selected .result a',
+ keys : {next: 'down:40', previous: 'down:38'}
+ }).focusManager,
+
+ LIST_ITEM_TEMPLATE =
+ '<li class="api-list-item {typeSingular}">' +
+ '<a href="{rootPath}{typePlural}/{name}.html">{displayName}</a>' +
+ '</li>';
+
+// -- Init ---------------------------------------------------------------------
+
+// Duckpunch FocusManager's key event handling to prevent it from handling key
+// events when a modifier is pressed.
+Y.before(function (e, activeDescendant) {
+ if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) {
+ return new Y.Do.Prevent();
+ }
+}, focusManager, '_focusPrevious', focusManager);
+
+Y.before(function (e, activeDescendant) {
+ if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) {
+ return new Y.Do.Prevent();
+ }
+}, focusManager, '_focusNext', focusManager);
+
+// Create a mapping of tabs in the tabview so we can refer to them easily later.
+tabview.each(function (tab, index) {
+ var name = tab.get('label').toLowerCase();
+
+ tabs[name] = {
+ index: index,
+ name : name,
+ tab : tab
+ };
+});
+
+// Switch tabs on Ctrl/Cmd-Left/Right arrows.
+tabviewNode.on('key', onTabSwitchKey, 'down:37,39');
+
+// Focus the filter input when the `/` key is pressed.
+Y.one(Y.config.doc).on('key', onSearchKey, 'down:83');
+
+// Keep the Focus Manager up to date.
+inputNode.on('focus', function () {
+ focusManager.set('activeDescendant', inputNode);
+});
+
+// Update all tabview links to resolved URLs.
+tabview.get('panelNode').all('a').each(function (link) {
+ link.setAttribute('href', link.get('href'));
+});
+
+// -- Private Functions --------------------------------------------------------
+function getFilterResultNode() {
+ return filter.get('queryType') === 'classes' ? classesNode : modulesNode;
+}
+
+// -- Event Handlers -----------------------------------------------------------
+function onFilterResults(e) {
+ var frag = Y.one(Y.config.doc.createDocumentFragment()),
+ resultNode = getFilterResultNode(),
+ typePlural = filter.get('queryType'),
+ typeSingular = typePlural === 'classes' ? 'class' : 'module';
+
+ if (e.results.length) {
+ YArray.each(e.results, function (result) {
+ frag.append(Lang.sub(LIST_ITEM_TEMPLATE, {
+ rootPath : APIList.rootPath,
+ displayName : filter.getDisplayName(result.highlighted),
+ name : result.text,
+ typePlural : typePlural,
+ typeSingular: typeSingular
+ }));
+ });
+ } else {
+ frag.append(
+ '<li class="message">' +
+ 'No ' + typePlural + ' found.' +
+ '</li>'
+ );
+ }
+
+ resultNode.empty(true);
+ resultNode.append(frag);
+
+ focusManager.refresh();
+}
+
+function onSearchClear(e) {
+
+ focusManager.refresh();
+}
+
+function onSearchKey(e) {
+ var target = e.target;
+
+ if (target.test('input,select,textarea')
+ || target.get('isContentEditable')) {
+ return;
+ }
+
+ e.preventDefault();
+
+ inputNode.focus();
+ focusManager.refresh();
+}
+
+function onSearchResults(e) {
+ var frag = Y.one(Y.config.doc.createDocumentFragment());
+
+ if (e.results.length) {
+ YArray.each(e.results, function (result) {
+ frag.append(result.display);
+ });
+ } else {
+ frag.append(
+ '<li class="message">' +
+ 'No results found. Maybe you\'ll have better luck with a ' +
+ 'different query?' +
+ '</li>'
+ );
+ }
+
+
+ focusManager.refresh();
+}
+
+function onTabSelectionChange(e) {
+ var tab = e.newVal,
+ name = tab.get('label').toLowerCase();
+
+ tabs.selected = {
+ index: tab.get('index'),
+ name : name,
+ tab : tab
+ };
+
+ switch (name) {
+ case 'classes': // fallthru
+ case 'modules':
+ filter.setAttrs({
+ minQueryLength: 0,
+ queryType : name
+ });
+
+ search.set('minQueryLength', -1);
+
+ // Only send a request if this isn't the initially-selected tab.
+ if (e.prevVal) {
+ filter.sendRequest(filter.get('value'));
+ }
+ break;
+
+ case 'everything':
+ filter.set('minQueryLength', -1);
+ search.set('minQueryLength', 1);
+
+ if (search.get('value')) {
+ search.sendRequest(search.get('value'));
+ } else {
+ inputNode.focus();
+ }
+ break;
+
+ default:
+ // WTF? We shouldn't be here!
+ filter.set('minQueryLength', -1);
+ search.set('minQueryLength', -1);
+ }
+
+ if (focusManager) {
+ setTimeout(function () {
+ focusManager.refresh();
+ }, 1);
+ }
+}
+
+function onTabSwitchKey(e) {
+ var currentTabIndex = tabs.selected.index;
+
+ if (!(e.ctrlKey || e.metaKey)) {
+ return;
+ }
+
+ e.preventDefault();
+
+ switch (e.keyCode) {
+ case 37: // left arrow
+ if (currentTabIndex > 0) {
+ tabview.selectChild(currentTabIndex - 1);
+ inputNode.focus();
+ }
+ break;
+
+ case 39: // right arrow
+ if (currentTabIndex < (Y.Object.size(tabs) - 2)) {
+ tabview.selectChild(currentTabIndex + 1);
+ inputNode.focus();
+ }
+ break;
+ }
+}
+
+}, '3.4.0', {requires: [
+ 'api-filter', 'api-search', 'event-key', 'node-focusmanager', 'tabview'
+]});
--- /dev/null
+YUI.add('api-search', function (Y) {
+
+var Lang = Y.Lang,
+ Node = Y.Node,
+ YArray = Y.Array;
+
+Y.APISearch = Y.Base.create('apiSearch', Y.Base, [Y.AutoCompleteBase], {
+ // -- Public Properties ----------------------------------------------------
+ RESULT_TEMPLATE:
+ '<li class="result {resultType}">' +
+ '<a href="{url}">' +
+ '<h3 class="title">{name}</h3>' +
+ '<span class="type">{resultType}</span>' +
+ '<div class="description">{description}</div>' +
+ '<span class="className">{class}</span>' +
+ '</a>' +
+ '</li>',
+
+ // -- Initializer ----------------------------------------------------------
+ initializer: function () {
+ this._bindUIACBase();
+ this._syncUIACBase();
+ },
+
+ // -- Protected Methods ----------------------------------------------------
+ _apiResultFilter: function (query, results) {
+ // Filter components out of the results.
+ return YArray.filter(results, function (result) {
+ return result.raw.resultType === 'component' ? false : result;
+ });
+ },
+
+ _apiResultFormatter: function (query, results) {
+ return YArray.map(results, function (result) {
+ var raw = Y.merge(result.raw), // create a copy
+ desc = raw.description || '';
+
+ // Convert description to text and truncate it if necessary.
+ desc = Node.create('<div>' + desc + '</div>').get('text');
+
+ if (desc.length > 65) {
+ desc = Y.Escape.html(desc.substr(0, 65)) + ' …';
+ } else {
+ desc = Y.Escape.html(desc);
+ }
+
+ raw['class'] || (raw['class'] = '');
+ raw.description = desc;
+
+ // Use the highlighted result name.
+ raw.name = result.highlighted;
+
+ return Lang.sub(this.RESULT_TEMPLATE, raw);
+ }, this);
+ },
+
+ _apiTextLocator: function (result) {
+ return result.displayName || result.name;
+ }
+}, {
+ // -- Attributes -----------------------------------------------------------
+ ATTRS: {
+ resultFormatter: {
+ valueFn: function () {
+ return this._apiResultFormatter;
+ }
+ },
+
+ resultFilters: {
+ valueFn: function () {
+ return this._apiResultFilter;
+ }
+ },
+
+ resultHighlighter: {
+ value: 'phraseMatch'
+ },
+
+ resultListLocator: {
+ value: 'data.results'
+ },
+
+ resultTextLocator: {
+ valueFn: function () {
+ return this._apiTextLocator;
+ }
+ },
+
+ source: {
+ value: '/api/v1/search?q={query}&count={maxResults}'
+ }
+ }
+});
+
+}, '3.4.0', {requires: [
+ 'autocomplete-base', 'autocomplete-highlighters', 'autocomplete-sources',
+ 'escape'
+]});
--- /dev/null
+YUI().use(
+ 'yuidoc-meta',
+ 'api-list', 'history-hash', 'node-screen', 'node-style', 'pjax',
+function (Y) {
+
+var win = Y.config.win,
+ localStorage = win.localStorage,
+
+ bdNode = Y.one('#bd'),
+
+ pjax,
+ defaultRoute,
+
+ classTabView,
+ selectedTab;
+
+// Kill pjax functionality unless serving over HTTP.
+if (!Y.getLocation().protocol.match(/^https?\:/)) {
+ Y.Router.html5 = false;
+}
+
+// Create the default route with middleware which enables syntax highlighting
+// on the loaded content.
+defaultRoute = Y.Pjax.defaultRoute.concat(function (req, res, next) {
+ prettyPrint();
+ bdNode.removeClass('loading');
+
+ next();
+});
+
+pjax = new Y.Pjax({
+ container : '#docs-main',
+ contentSelector: '#docs-main > .content',
+ linkSelector : '#bd a',
+ titleSelector : '#xhr-title',
+
+ navigateOnHash: true,
+ root : '/',
+ routes : [
+ // -- / ----------------------------------------------------------------
+ {
+ path : '/(index.html)?',
+ callbacks: defaultRoute
+ },
+
+ // -- /classes/* -------------------------------------------------------
+ {
+ path : '/classes/:class.html*',
+ callbacks: [defaultRoute, 'handleClasses']
+ },
+
+ // -- /files/* ---------------------------------------------------------
+ {
+ path : '/files/*file',
+ callbacks: [defaultRoute, 'handleFiles']
+ },
+
+ // -- /modules/* -------------------------------------------------------
+ {
+ path : '/modules/:module.html*',
+ callbacks: defaultRoute
+ }
+ ]
+});
+
+// -- Utility Functions --------------------------------------------------------
+
+pjax.checkVisibility = function (tab) {
+ tab || (tab = selectedTab);
+
+ if (!tab) { return; }
+
+ var panelNode = tab.get('panelNode'),
+ visibleItems;
+
+ // If no items are visible in the tab panel due to the current visibility
+ // settings, display a message to that effect.
+ visibleItems = panelNode.all('.item,.index-item').some(function (itemNode) {
+ if (itemNode.getComputedStyle('display') !== 'none') {
+ return true;
+ }
+ });
+
+ panelNode.all('.no-visible-items').remove();
+
+ if (!visibleItems) {
+ if (Y.one('#index .index-item')) {
+ panelNode.append(
+ '<div class="no-visible-items">' +
+ '<p>' +
+ 'Some items are not shown due to the current visibility ' +
+ 'settings. Use the checkboxes at the upper right of this ' +
+ 'page to change the visibility settings.' +
+ '</p>' +
+ '</div>'
+ );
+ } else {
+ panelNode.append(
+ '<div class="no-visible-items">' +
+ '<p>' +
+ 'This class doesn\'t provide any methods, properties, ' +
+ 'attributes, or events.' +
+ '</p>' +
+ '</div>'
+ );
+ }
+ }
+
+ // Hide index sections without any visible items.
+ Y.all('.index-section').each(function (section) {
+ var items = 0,
+ visibleItems = 0;
+
+ section.all('.index-item').each(function (itemNode) {
+ items += 1;
+
+ if (itemNode.getComputedStyle('display') !== 'none') {
+ visibleItems += 1;
+ }
+ });
+
+ section.toggleClass('hidden', !visibleItems);
+ section.toggleClass('no-columns', visibleItems < 4);
+ });
+};
+
+pjax.initClassTabView = function () {
+ if (!Y.all('#classdocs .api-class-tab').size()) {
+ return;
+ }
+
+ if (classTabView) {
+ classTabView.destroy();
+ selectedTab = null;
+ }
+
+ classTabView = new Y.TabView({
+ srcNode: '#classdocs',
+
+ on: {
+ selectionChange: pjax.onTabSelectionChange
+ }
+ });
+
+ pjax.updateTabState();
+ classTabView.render();
+};
+
+pjax.initLineNumbers = function () {
+ var hash = win.location.hash.substring(1),
+ container = pjax.get('container'),
+ hasLines, node;
+
+ // Add ids for each line number in the file source view.
+ container.all('.linenums>li').each(function (lineNode, index) {
+ lineNode.set('id', 'l' + (index + 1));
+ lineNode.addClass('file-line');
+ hasLines = true;
+ });
+
+ // Scroll to the desired line.
+ if (hasLines && /^l\d+$/.test(hash)) {
+ if ((node = container.getById(hash))) {
+ win.scroll(0, node.getY());
+ }
+ }
+};
+
+pjax.initRoot = function () {
+ var terminators = /^(?:classes|files|modules)$/,
+ parts = pjax._getPathRoot().split('/'),
+ root = [],
+ i, len, part;
+
+ for (i = 0, len = parts.length; i < len; i += 1) {
+ part = parts[i];
+
+ if (part.match(terminators)) {
+ // Makes sure the path will end with a "/".
+ root.push('');
+ break;
+ }
+
+ root.push(part);
+ }
+
+ pjax.set('root', root.join('/'));
+};
+
+pjax.updateTabState = function (src) {
+ var hash = win.location.hash.substring(1),
+ defaultTab, node, tab, tabPanel;
+
+ function scrollToNode() {
+ if (node.hasClass('protected')) {
+ Y.one('#api-show-protected').set('checked', true);
+ pjax.updateVisibility();
+ }
+
+ if (node.hasClass('private')) {
+ Y.one('#api-show-private').set('checked', true);
+ pjax.updateVisibility();
+ }
+
+ setTimeout(function () {
+ // For some reason, unless we re-get the node instance here,
+ // getY() always returns 0.
+ var node = Y.one('#classdocs').getById(hash);
+ win.scrollTo(0, node.getY() - 70);
+ }, 1);
+ }
+
+ if (!classTabView) {
+ return;
+ }
+
+ if (src === 'hashchange' && !hash) {
+ defaultTab = 'index';
+ } else {
+ if (localStorage) {
+ defaultTab = localStorage.getItem('tab_' + pjax.getPath()) ||
+ 'index';
+ } else {
+ defaultTab = 'index';
+ }
+ }
+
+ if (hash && (node = Y.one('#classdocs').getById(hash))) {
+ if ((tabPanel = node.ancestor('.api-class-tabpanel', true))) {
+ if ((tab = Y.one('#classdocs .api-class-tab.' + tabPanel.get('id')))) {
+ if (classTabView.get('rendered')) {
+ Y.Widget.getByNode(tab).set('selected', 1);
+ } else {
+ tab.addClass('yui3-tab-selected');
+ }
+ }
+ }
+
+ // Scroll to the desired element if this is a hash URL.
+ if (node) {
+ if (classTabView.get('rendered')) {
+ scrollToNode();
+ } else {
+ classTabView.once('renderedChange', scrollToNode);
+ }
+ }
+ } else {
+ tab = Y.one('#classdocs .api-class-tab.' + defaultTab);
+
+ // When the `defaultTab` node isn't found, `localStorage` is stale.
+ if (!tab && defaultTab !== 'index') {
+ tab = Y.one('#classdocs .api-class-tab.index');
+ }
+
+ if (classTabView.get('rendered')) {
+ Y.Widget.getByNode(tab).set('selected', 1);
+ } else {
+ tab.addClass('yui3-tab-selected');
+ }
+ }
+};
+
+pjax.updateVisibility = function () {
+ var container = pjax.get('container');
+
+ container.toggleClass('hide-inherited',
+ !Y.one('#api-show-inherited').get('checked'));
+
+ container.toggleClass('show-deprecated',
+ Y.one('#api-show-deprecated').get('checked'));
+
+ container.toggleClass('show-protected',
+ Y.one('#api-show-protected').get('checked'));
+
+ container.toggleClass('show-private',
+ Y.one('#api-show-private').get('checked'));
+
+ pjax.checkVisibility();
+};
+
+// -- Route Handlers -----------------------------------------------------------
+
+pjax.handleClasses = function (req, res, next) {
+ var status = res.ioResponse.status;
+
+ // Handles success and local filesystem XHRs.
+ if (res.ioResponse.readyState === 4 && (!status || (status >= 200 && status < 300))) {
+ pjax.initClassTabView();
+ }
+
+ next();
+};
+
+pjax.handleFiles = function (req, res, next) {
+ var status = res.ioResponse.status;
+
+ // Handles success and local filesystem XHRs.
+ if (res.ioResponse.readyState === 4 && (!status || (status >= 200 && status < 300))) {
+ pjax.initLineNumbers();
+ }
+
+ next();
+};
+
+// -- Event Handlers -----------------------------------------------------------
+
+pjax.onNavigate = function (e) {
+ var hash = e.hash,
+ originTarget = e.originEvent && e.originEvent.target,
+ tab;
+
+ if (hash) {
+ tab = originTarget && originTarget.ancestor('.yui3-tab', true);
+
+ if (hash === win.location.hash) {
+ pjax.updateTabState('hashchange');
+ } else if (!tab) {
+ win.location.hash = hash;
+ }
+
+ e.preventDefault();
+ return;
+ }
+
+ // Only scroll to the top of the page when the URL doesn't have a hash.
+ this.set('scrollToTop', !e.url.match(/#.+$/));
+
+ bdNode.addClass('loading');
+};
+
+pjax.onOptionClick = function (e) {
+ pjax.updateVisibility();
+};
+
+pjax.onTabSelectionChange = function (e) {
+ var tab = e.newVal,
+ tabId = tab.get('contentBox').getAttribute('href').substring(1);
+
+ selectedTab = tab;
+
+ // If switching from a previous tab (i.e., this is not the default tab),
+ // replace the history entry with a hash URL that will cause this tab to
+ // be selected if the user navigates away and then returns using the back
+ // or forward buttons.
+ if (e.prevVal && localStorage) {
+ localStorage.setItem('tab_' + pjax.getPath(), tabId);
+ }
+
+ pjax.checkVisibility(tab);
+};
+
+// -- Init ---------------------------------------------------------------------
+
+pjax.on('navigate', pjax.onNavigate);
+
+pjax.initRoot();
+pjax.upgrade();
+pjax.initClassTabView();
+pjax.initLineNumbers();
+pjax.updateVisibility();
+
+Y.APIList.rootPath = pjax.get('root');
+
+Y.one('#api-options').delegate('click', pjax.onOptionClick, 'input');
+
+Y.on('hashchange', function (e) {
+ pjax.updateTabState('hashchange');
+}, win);
+
+});
--- /dev/null
+YUI().use('node', function(Y) {
+ var code = Y.all('.prettyprint.linenums');
+ if (code.size()) {
+ code.each(function(c) {
+ var lis = c.all('ol li'),
+ l = 1;
+ lis.each(function(n) {
+ n.prepend('<a name="LINENUM_' + l + '"></a>');
+ l++;
+ });
+ });
+ var h = location.hash;
+ location.hash = '';
+ h = h.replace('LINE_', 'LINENUM_');
+ location.hash = h;
+ }
+});
--- /dev/null
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <title>Change Log</title>
+ </head>
+ <body bgcolor="white">
+ <a style="float:right" href="README.html">README</a>
+
+ <h1>Known Issues</h1>
+ <ul>
+ <li>Perl formatting is really crappy. Partly because the author is lazy and
+ partly because Perl is
+ <a href="http://www.perlmonks.org/?node_id=663393">hard</a> to parse.
+ <li>On some browsers, <code><code></code> elements with newlines in the text
+ which use CSS to specify <code>white-space:pre</code> will have the newlines
+ improperly stripped if the element is not attached to the document at the time
+ the stripping is done. Also, on IE 6, all newlines will be stripped from
+ <code><code></code> elements because of the way IE6 produces
+ <code>innerHTML</code>. Workaround: use <code><pre></code> for code with
+ newlines.
+ </ul>
+
+ <h1>Change Log</h1>
+ <h2>29 March 2007</h2>
+ <ul>
+ <li>Added <a href="tests/prettify_test.html#PHP">tests</a> for PHP support
+ to address
+ <a href="http://code.google.com/p/google-code-prettify/issues/detail?id=3"
+ >issue 3</a>.
+ <li>Fixed
+ <a href="http://code.google.com/p/google-code-prettify/issues/detail?id=6"
+ >bug</a>: <code>prettyPrintOne</code> was not halting. This was not
+ reachable through the normal entry point.
+ <li>Fixed
+ <a href="http://code.google.com/p/google-code-prettify/issues/detail?id=4"
+ >bug</a>: recursing into a script block or PHP tag that was not properly
+ closed would not silently drop the content.
+ (<a href="tests/prettify_test.html#issue4">test</a>)
+ <li>Fixed
+ <a href="http://code.google.com/p/google-code-prettify/issues/detail?id=8"
+ >bug</a>: was eating tabs
+ (<a href="tests/prettify_test.html#issue8">test</a>)
+ <li>Fixed entity handling so that the caveat
+ <blockquote>
+ <p>Caveats: please properly escape less-thans. <tt>x&lt;y</tt>
+ instead of <tt>x<y</tt>, and use <tt>"</tt> instead of
+ <tt>&quot;</tt> for string delimiters.</p>
+ </blockquote>
+ is no longer applicable.
+ <li>Added noisefree's C#
+ <a href="http://code.google.com/p/google-code-prettify/issues/detail?id=4"
+ >patch</a>
+ <li>Added a <a href="http://google-code-prettify.googlecode.com/files/prettify-small.zip">distribution</a> that has comments and
+ whitespace removed to reduce download size from 45.5kB to 12.8kB.
+ </ul>
+ <h2>4 Jul 2008</h2>
+ <ul>
+ <li>Added <a href="http://code.google.com/p/google-code-prettify/issues/detail?id=17">language specific formatters</a> that are triggered by the presence
+ of a <code>lang-<language-file-extension></code></li>
+ <li>Fixed <a href="http://code.google.com/p/google-code-prettify/issues/detail?id=29">bug</a>: python handling of <code>'''string'''</code>
+ <li>Fixed bug: <code>/</code> in regex <code>[charsets] should not end regex</code>
+ </ul>
+ <h2>5 Jul 2008</h2>
+ <ul>
+ <li>Defined language extensions for Lisp and Lua</code>
+ </ul>
+ <h2>14 Jul 2008</h2>
+ <ul>
+ <li>Language handlers for F#, OCAML, SQL</code>
+ <li>Support for <code>nocode</code> spans to allow embedding of line
+ numbers and code annotations which should not be styled or otherwise
+ affect the tokenization of prettified code.
+ See the issue 22
+ <a href="tests/prettify_test.html#issue22">testcase</a>.</code>
+ </ul>
+ <h2>6 Jan 2009</h2>
+ <ul>
+ <li>Language handlers for Visual Basic, Haskell, CSS, and WikiText</li>
+ <li>Added <tt>.mxml</tt> extension to the markup style handler for
+ Flex <a href="http://en.wikipedia.org/wiki/MXML">MXML files</a>. See
+ <a
+ href="http://code.google.com/p/google-code-prettify/issues/detail?id=37"
+ >issue 37</a>.
+ <li>Added <tt>.m</tt> extension to the C style handler so that Objective
+ C source files properly highlight. See
+ <a
+ href="http://code.google.com/p/google-code-prettify/issues/detail?id=58"
+ >issue 58</a>.
+ <li>Changed HTML lexer to use the same embedded source mechanism as the
+ wiki language handler, and changed to use the registered
+ CSS handler for STYLE element content.
+ </ul>
+ <h2>21 May 2009</h2>
+ <ul>
+ <li>Rewrote to improve performance on large files.
+ See <a href="http://mikesamuel.blogspot.com/2009/05/efficient-parsing-in-javascript.html">benchmarks</a>.</li>
+ <li>Fixed bugs with highlighting of Haskell line comments, Lisp
+ number literals, Lua strings, C preprocessor directives,
+ newlines in Wiki code on Windows, and newlines in IE6.</li>
+ </ul>
+ <h2>14 August 2009</h2>
+ <ul>
+ <li>Fixed prettifying of <code><code></code> blocks with embedded newlines.
+ </ul>
+ <h2>3 October 2009</h2>
+ <ul>
+ <li>Fixed prettifying of XML/HTML tags that contain uppercase letters.
+ </ul>
+ <h2>19 July 2010</h2>
+ <ul>
+ <li>Added support for line numbers. Bug
+ <a href="http://code.google.com/p/google-code-prettify/issues/detail?id=22"
+ >22</a></li>
+ <li>Added YAML support. Bug
+ <a href="http://code.google.com/p/google-code-prettify/issues/detail?id=123"
+ >123</a></li>
+ <li>Added VHDL support courtesy Le Poussin.</li>
+ <li>IE performance improvements. Bug
+ <a href="http://code.google.com/p/google-code-prettify/issues/detail?id=102"
+ >102</a> courtesy jacobly.</li>
+ <li>A variety of markup formatting fixes courtesy smain and thezbyg.</li>
+ <li>Fixed copy and paste in IE[678].
+ <li>Changed output to use <code>&#160;</code> instead of
+ <code>&nbsp;</code> so that the output works when embedded in XML.
+ Bug
+ <a href="http://code.google.com/p/google-code-prettify/issues/detail?id=108"
+ >108</a>.</li>
+ </ul>
+ </body>
+</html>
--- /dev/null
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
--- /dev/null
+.pln{color:#000}@media screen{.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun,.opn,.clo{color:#660}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec,.var{color:#606}.fun{color:red}}@media print,projection{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun,.opn,.clo{color:#440}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}pre.prettyprint{padding:2px;border:1px solid #888}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee}
\ No newline at end of file
--- /dev/null
+window.PR_SHOULD_USE_CONTINUATION=true;var prettyPrintOne;var prettyPrint;(function(){var O=window;var j=["break,continue,do,else,for,if,return,while"];var v=[j,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"];var q=[v,"catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"];var m=[q,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"];var y=[q,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"];var T=[y,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,let,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var,virtual,where"];var s="all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,throw,true,try,unless,until,when,while,yes";var x=[q,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"];var t="caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END";var J=[j,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"];var g=[j,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"];var I=[j,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"];var B=[m,T,x,t+J,g,I];var f=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)\b/;var D="str";var A="kwd";var k="com";var Q="typ";var H="lit";var M="pun";var G="pln";var n="tag";var F="dec";var K="src";var R="atn";var o="atv";var P="nocode";var N="(?:^^\\.?|[+-]|[!=]=?=?|\\#|%=?|&&?=?|\\(|\\*=?|[+\\-]=|->|\\/=?|::?|<<?=?|>>?>?=?|,|;|\\?|@|\\[|~|{|\\^\\^?=?|\\|\\|?=?|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\\s*";function l(ab){var af=0;var U=false;var ae=false;for(var X=0,W=ab.length;X<W;++X){var ag=ab[X];if(ag.ignoreCase){ae=true}else{if(/[a-z]/i.test(ag.source.replace(/\\u[0-9a-f]{4}|\\x[0-9a-f]{2}|\\[^ux]/gi,""))){U=true;ae=false;break}}}var aa={b:8,t:9,n:10,v:11,f:12,r:13};function ad(aj){var ai=aj.charCodeAt(0);if(ai!==92){return ai}var ah=aj.charAt(1);ai=aa[ah];if(ai){return ai}else{if("0"<=ah&&ah<="7"){return parseInt(aj.substring(1),8)}else{if(ah==="u"||ah==="x"){return parseInt(aj.substring(2),16)}else{return aj.charCodeAt(1)}}}}function V(ah){if(ah<32){return(ah<16?"\\x0":"\\x")+ah.toString(16)}var ai=String.fromCharCode(ah);return(ai==="\\"||ai==="-"||ai==="]"||ai==="^")?"\\"+ai:ai}function Z(an){var ar=an.substring(1,an.length-1).match(new RegExp("\\\\u[0-9A-Fa-f]{4}|\\\\x[0-9A-Fa-f]{2}|\\\\[0-3][0-7]{0,2}|\\\\[0-7]{1,2}|\\\\[\\s\\S]|-|[^-\\\\]","g"));var ah=[];var ap=ar[0]==="^";var ao=["["];if(ap){ao.push("^")}for(var at=ap?1:0,al=ar.length;at<al;++at){var aj=ar[at];if(/\\[bdsw]/i.test(aj)){ao.push(aj)}else{var ai=ad(aj);var am;if(at+2<al&&"-"===ar[at+1]){am=ad(ar[at+2]);at+=2}else{am=ai}ah.push([ai,am]);if(!(am<65||ai>122)){if(!(am<65||ai>90)){ah.push([Math.max(65,ai)|32,Math.min(am,90)|32])}if(!(am<97||ai>122)){ah.push([Math.max(97,ai)&~32,Math.min(am,122)&~32])}}}}ah.sort(function(aw,av){return(aw[0]-av[0])||(av[1]-aw[1])});var ak=[];var aq=[];for(var at=0;at<ah.length;++at){var au=ah[at];if(au[0]<=aq[1]+1){aq[1]=Math.max(aq[1],au[1])}else{ak.push(aq=au)}}for(var at=0;at<ak.length;++at){var au=ak[at];ao.push(V(au[0]));if(au[1]>au[0]){if(au[1]+1>au[0]){ao.push("-")}ao.push(V(au[1]))}}ao.push("]");return ao.join("")}function Y(an){var al=an.source.match(new RegExp("(?:\\[(?:[^\\x5C\\x5D]|\\\\[\\s\\S])*\\]|\\\\u[A-Fa-f0-9]{4}|\\\\x[A-Fa-f0-9]{2}|\\\\[0-9]+|\\\\[^ux0-9]|\\(\\?[:!=]|[\\(\\)\\^]|[^\\x5B\\x5C\\(\\)\\^]+)","g"));var aj=al.length;var ap=[];for(var am=0,ao=0;am<aj;++am){var ai=al[am];if(ai==="("){++ao}else{if("\\"===ai.charAt(0)){var ah=+ai.substring(1);if(ah){if(ah<=ao){ap[ah]=-1}else{al[am]=V(ah)}}}}}for(var am=1;am<ap.length;++am){if(-1===ap[am]){ap[am]=++af}}for(var am=0,ao=0;am<aj;++am){var ai=al[am];if(ai==="("){++ao;if(!ap[ao]){al[am]="(?:"}}else{if("\\"===ai.charAt(0)){var ah=+ai.substring(1);if(ah&&ah<=ao){al[am]="\\"+ap[ah]}}}}for(var am=0;am<aj;++am){if("^"===al[am]&&"^"!==al[am+1]){al[am]=""}}if(an.ignoreCase&&U){for(var am=0;am<aj;++am){var ai=al[am];var ak=ai.charAt(0);if(ai.length>=2&&ak==="["){al[am]=Z(ai)}else{if(ak!=="\\"){al[am]=ai.replace(/[a-zA-Z]/g,function(aq){var ar=aq.charCodeAt(0);return"["+String.fromCharCode(ar&~32,ar|32)+"]"})}}}}return al.join("")}var ac=[];for(var X=0,W=ab.length;X<W;++X){var ag=ab[X];if(ag.global||ag.multiline){throw new Error(""+ag)}ac.push("(?:"+Y(ag)+")")}return new RegExp(ac.join("|"),ae?"gi":"g")}function b(aa,Y){var W=/(?:^|\s)nocode(?:\s|$)/;var ab=[];var Z=0;var X=[];var V=0;function U(ac){switch(ac.nodeType){case 1:if(W.test(ac.className)){return}for(var af=ac.firstChild;af;af=af.nextSibling){U(af)}var ae=ac.nodeName.toLowerCase();if("br"===ae||"li"===ae){ab[V]="\n";X[V<<1]=Z++;X[(V++<<1)|1]=ac}break;case 3:case 4:var ad=ac.nodeValue;if(ad.length){if(!Y){ad=ad.replace(/[ \t\r\n]+/g," ")}else{ad=ad.replace(/\r\n?/g,"\n")}ab[V]=ad;X[V<<1]=Z;Z+=ad.length;X[(V++<<1)|1]=ac}break}}U(aa);return{sourceCode:ab.join("").replace(/\n$/,""),spans:X}}function C(U,W,Y,V){if(!W){return}var X={sourceCode:W,basePos:U};Y(X);V.push.apply(V,X.decorations)}var w=/\S/;function p(U){var X=undefined;for(var W=U.firstChild;W;W=W.nextSibling){var V=W.nodeType;X=(V===1)?(X?U:W):(V===3)?(w.test(W.nodeValue)?U:X):X}return X===U?undefined:X}function h(W,V){var U={};var X;(function(){var af=W.concat(V);var aj=[];var ai={};for(var ad=0,ab=af.length;ad<ab;++ad){var aa=af[ad];var ae=aa[3];if(ae){for(var ag=ae.length;--ag>=0;){U[ae.charAt(ag)]=aa}}var ah=aa[1];var ac=""+ah;if(!ai.hasOwnProperty(ac)){aj.push(ah);ai[ac]=null}}aj.push(/[\0-\uffff]/);X=l(aj)})();var Z=V.length;var Y=function(aj){var ab=aj.sourceCode,aa=aj.basePos;var af=[aa,G];var ah=0;var ap=ab.match(X)||[];var al={};for(var ag=0,at=ap.length;ag<at;++ag){var ai=ap[ag];var ar=al[ai];var ak=void 0;var ao;if(typeof ar==="string"){ao=false}else{var ac=U[ai.charAt(0)];if(ac){ak=ai.match(ac[1]);ar=ac[0]}else{for(var aq=0;aq<Z;++aq){ac=V[aq];ak=ai.match(ac[1]);if(ak){ar=ac[0];break}}if(!ak){ar=G}}ao=ar.length>=5&&"lang-"===ar.substring(0,5);if(ao&&!(ak&&typeof ak[1]==="string")){ao=false;ar=K}if(!ao){al[ai]=ar}}var ad=ah;ah+=ai.length;if(!ao){af.push(aa+ad,ar)}else{var an=ak[1];var am=ai.indexOf(an);var ae=am+an.length;if(ak[2]){ae=ai.length-ak[2].length;am=ae-an.length}var au=ar.substring(5);C(aa+ad,ai.substring(0,am),Y,af);C(aa+ad+am,an,r(au,an),af);C(aa+ad+ae,ai.substring(ae),Y,af)}}aj.decorations=af};return Y}function i(V){var Y=[],U=[];if(V.tripleQuotedStrings){Y.push([D,/^(?:\'\'\'(?:[^\'\\]|\\[\s\S]|\'{1,2}(?=[^\']))*(?:\'\'\'|$)|\"\"\"(?:[^\"\\]|\\[\s\S]|\"{1,2}(?=[^\"]))*(?:\"\"\"|$)|\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$))/,null,"'\""])}else{if(V.multiLineStrings){Y.push([D,/^(?:\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$)|\`(?:[^\\\`]|\\[\s\S])*(?:\`|$))/,null,"'\"`"])}else{Y.push([D,/^(?:\'(?:[^\\\'\r\n]|\\.)*(?:\'|$)|\"(?:[^\\\"\r\n]|\\.)*(?:\"|$))/,null,"\"'"])}}if(V.verbatimStrings){U.push([D,/^@\"(?:[^\"]|\"\")*(?:\"|$)/,null])}var ab=V.hashComments;if(ab){if(V.cStyleComments){if(ab>1){Y.push([k,/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,null,"#"])}else{Y.push([k,/^#(?:(?:define|e(?:l|nd)if|else|error|ifn?def|include|line|pragma|undef|warning)\b|[^\r\n]*)/,null,"#"])}U.push([D,/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h(?:h|pp|\+\+)?|[a-z]\w*)>/,null])}else{Y.push([k,/^#[^\r\n]*/,null,"#"])}}if(V.cStyleComments){U.push([k,/^\/\/[^\r\n]*/,null]);U.push([k,/^\/\*[\s\S]*?(?:\*\/|$)/,null])}if(V.regexLiterals){var aa=("/(?=[^/*])(?:[^/\\x5B\\x5C]|\\x5C[\\s\\S]|\\x5B(?:[^\\x5C\\x5D]|\\x5C[\\s\\S])*(?:\\x5D|$))+/");U.push(["lang-regex",new RegExp("^"+N+"("+aa+")")])}var X=V.types;if(X){U.push([Q,X])}var W=(""+V.keywords).replace(/^ | $/g,"");if(W.length){U.push([A,new RegExp("^(?:"+W.replace(/[\s,]+/g,"|")+")\\b"),null])}Y.push([G,/^\s+/,null," \r\n\t\xA0"]);var Z=/^.[^\s\w\.$@\'\"\`\/\\]*/;U.push([H,/^@[a-z_$][a-z_$@0-9]*/i,null],[Q,/^(?:[@_]?[A-Z]+[a-z][A-Za-z_$@0-9]*|\w+_t\b)/,null],[G,/^[a-z_$][a-z_$@0-9]*/i,null],[H,new RegExp("^(?:0x[a-f0-9]+|(?:\\d(?:_\\d+)*\\d*(?:\\.\\d*)?|\\.\\d\\+)(?:e[+\\-]?\\d+)?)[a-z]*","i"),null,"0123456789"],[G,/^\\[\s\S]?/,null],[M,Z,null]);return h(Y,U)}var L=i({keywords:B,hashComments:true,cStyleComments:true,multiLineStrings:true,regexLiterals:true});function S(W,ah,aa){var V=/(?:^|\s)nocode(?:\s|$)/;var ac=/\r\n?|\n/;var ad=W.ownerDocument;var ag=ad.createElement("li");while(W.firstChild){ag.appendChild(W.firstChild)}var X=[ag];function af(am){switch(am.nodeType){case 1:if(V.test(am.className)){break}if("br"===am.nodeName){ae(am);if(am.parentNode){am.parentNode.removeChild(am)}}else{for(var ao=am.firstChild;ao;ao=ao.nextSibling){af(ao)}}break;case 3:case 4:if(aa){var an=am.nodeValue;var ak=an.match(ac);if(ak){var aj=an.substring(0,ak.index);am.nodeValue=aj;var ai=an.substring(ak.index+ak[0].length);if(ai){var al=am.parentNode;al.insertBefore(ad.createTextNode(ai),am.nextSibling)}ae(am);if(!aj){am.parentNode.removeChild(am)}}}break}}function ae(al){while(!al.nextSibling){al=al.parentNode;if(!al){return}}function aj(am,at){var ar=at?am.cloneNode(false):am;var ap=am.parentNode;if(ap){var aq=aj(ap,1);var ao=am.nextSibling;aq.appendChild(ar);for(var an=ao;an;an=ao){ao=an.nextSibling;aq.appendChild(an)}}return ar}var ai=aj(al.nextSibling,0);for(var ak;(ak=ai.parentNode)&&ak.nodeType===1;){ai=ak}X.push(ai)}for(var Z=0;Z<X.length;++Z){af(X[Z])}if(ah===(ah|0)){X[0].setAttribute("value",ah)}var ab=ad.createElement("ol");ab.className="linenums";var Y=Math.max(0,((ah-1))|0)||0;for(var Z=0,U=X.length;Z<U;++Z){ag=X[Z];ag.className="L"+((Z+Y)%10);if(!ag.firstChild){ag.appendChild(ad.createTextNode("\xA0"))}ab.appendChild(ag)}W.appendChild(ab)}function E(af){var X=/\bMSIE\s(\d+)/.exec(navigator.userAgent);X=X&&+X[1]<=8;var ao=/\n/g;var an=af.sourceCode;var ap=an.length;var Y=0;var ad=af.spans;var V=ad.length;var aj=0;var aa=af.decorations;var ab=aa.length;var ac=0;aa[ab]=ap;var av,at;for(at=av=0;at<ab;){if(aa[at]!==aa[at+2]){aa[av++]=aa[at++];aa[av++]=aa[at++]}else{at+=2}}ab=av;for(at=av=0;at<ab;){var aw=aa[at];var ae=aa[at+1];var Z=at+2;while(Z+2<=ab&&aa[Z+1]===ae){Z+=2}aa[av++]=aw;aa[av++]=ae;at=Z}ab=aa.length=av;var au=af.sourceNode;var ak;if(au){ak=au.style.display;au.style.display="none"}try{var ah=null;while(aj<V){var ai=ad[aj];var U=ad[aj+2]||ap;var ar=aa[ac+2]||ap;var Z=Math.min(U,ar);var am=ad[aj+1];var W;if(am.nodeType!==1&&(W=an.substring(Y,Z))){if(X){W=W.replace(ao,"\r")}am.nodeValue=W;var al=am.ownerDocument;var aq=al.createElement("span");aq.className=aa[ac+1];var ag=am.parentNode;ag.replaceChild(aq,am);aq.appendChild(am);if(Y<U){ad[aj+1]=am=al.createTextNode(an.substring(Z,U));ag.insertBefore(am,aq.nextSibling)}}Y=Z;if(Y>=U){aj+=2}if(Y>=ar){ac+=2}}}finally{if(au){au.style.display=ak}}}var u={};function d(W,X){for(var U=X.length;--U>=0;){var V=X[U];if(!u.hasOwnProperty(V)){u[V]=W}else{if(O.console){console.warn("cannot override language handler %s",V)}}}}function r(V,U){if(!(V&&u.hasOwnProperty(V))){V=/^\s*</.test(U)?"default-markup":"default-code"}return u[V]}d(L,["default-code"]);d(h([],[[G,/^[^<?]+/],[F,/^<!\w[^>]*(?:>|$)/],[k,/^<\!--[\s\S]*?(?:-\->|$)/],["lang-",/^<\?([\s\S]+?)(?:\?>|$)/],["lang-",/^<%([\s\S]+?)(?:%>|$)/],[M,/^(?:<[%?]|[%?]>)/],["lang-",/^<xmp\b[^>]*>([\s\S]+?)<\/xmp\b[^>]*>/i],["lang-js",/^<script\b[^>]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-css",/^<style\b[^>]*>([\s\S]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]),["default-markup","htm","html","mxml","xhtml","xml","xsl"]);d(h([[G,/^[\s]+/,null," \t\r\n"],[o,/^(?:\"[^\"]*\"?|\'[^\']*\'?)/,null,"\"'"]],[[n,/^^<\/?[a-z](?:[\w.:-]*\w)?|\/?>$/i],[R,/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^>\'\"\s]*(?:[^>\'\"\s\/]|\/(?=\s)))/],[M,/^[=<>\/]+/],["lang-js",/^on\w+\s*=\s*\"([^\"]+)\"/i],["lang-js",/^on\w+\s*=\s*\'([^\']+)\'/i],["lang-js",/^on\w+\s*=\s*([^\"\'>\s]+)/i],["lang-css",/^style\s*=\s*\"([^\"]+)\"/i],["lang-css",/^style\s*=\s*\'([^\']+)\'/i],["lang-css",/^style\s*=\s*([^\"\'>\s]+)/i]]),["in.tag"]);d(h([],[[o,/^[\s\S]+/]]),["uq.val"]);d(i({keywords:m,hashComments:true,cStyleComments:true,types:f}),["c","cc","cpp","cxx","cyc","m"]);d(i({keywords:"null,true,false"}),["json"]);d(i({keywords:T,hashComments:true,cStyleComments:true,verbatimStrings:true,types:f}),["cs"]);d(i({keywords:y,cStyleComments:true}),["java"]);d(i({keywords:I,hashComments:true,multiLineStrings:true}),["bsh","csh","sh"]);d(i({keywords:J,hashComments:true,multiLineStrings:true,tripleQuotedStrings:true}),["cv","py"]);d(i({keywords:t,hashComments:true,multiLineStrings:true,regexLiterals:true}),["perl","pl","pm"]);d(i({keywords:g,hashComments:true,multiLineStrings:true,regexLiterals:true}),["rb"]);d(i({keywords:x,cStyleComments:true,regexLiterals:true}),["js"]);d(i({keywords:s,hashComments:3,cStyleComments:true,multilineStrings:true,tripleQuotedStrings:true,regexLiterals:true}),["coffee"]);d(h([],[[D,/^[\s\S]+/]]),["regex"]);function e(X){var W=X.langExtension;try{var U=b(X.sourceNode,X.pre);var V=U.sourceCode;X.sourceCode=V;X.spans=U.spans;X.basePos=0;r(W,V)(X);E(X)}catch(Y){if(O.console){console.log(Y&&Y.stack?Y.stack:Y)}}}function z(Y,X,W){var U=document.createElement("pre");U.innerHTML=Y;if(W){S(U,W,true)}var V={langExtension:X,numberLines:W,sourceNode:U,pre:1};e(V);return U.innerHTML}function c(aj){function ab(al){return document.getElementsByTagName(al)}var ah=[ab("pre"),ab("code"),ab("xmp")];var V=[];for(var ae=0;ae<ah.length;++ae){for(var ac=0,Y=ah[ae].length;ac<Y;++ac){V.push(ah[ae][ac])}}ah=null;var Z=Date;if(!Z.now){Z={now:function(){return +(new Date)}}}var aa=0;var U;var af=/\blang(?:uage)?-([\w.]+)(?!\S)/;var ak=/\bprettyprint\b/;var W=/\bprettyprinted\b/;var ag=/pre|xmp/i;var ai=/^code$/i;var ad=/^(?:pre|code|xmp)$/i;function X(){var ar=(O.PR_SHOULD_USE_CONTINUATION?Z.now()+250:Infinity);for(;aa<V.length&&Z.now()<ar;aa++){var at=V[aa];var au=at.className;if(ak.test(au)&&!W.test(au)){var aw=false;for(var ao=at.parentNode;ao;ao=ao.parentNode){var ax=ao.tagName;if(ad.test(ax)&&ao.className&&ak.test(ao.className)){aw=true;break}}if(!aw){at.className+=" prettyprinted";var aq=au.match(af);var am;if(!aq&&(am=p(at))&&ai.test(am.tagName)){aq=am.className.match(af)}if(aq){aq=aq[1]}var ap;if(ag.test(at.tagName)){ap=1}else{var an=at.currentStyle;var al=(an?an.whiteSpace:(document.defaultView&&document.defaultView.getComputedStyle)?document.defaultView.getComputedStyle(at,null).getPropertyValue("white-space"):0);ap=al&&"pre"===al.substring(0,3)}var av=at.className.match(/\blinenums\b(?::(\d+))?/);av=av?av[1]&&av[1].length?+av[1]:true:false;if(av){S(at,av,ap)}U={langExtension:aq,sourceNode:at,numberLines:av,pre:ap};e(U)}}}if(aa<V.length){setTimeout(X,250)}else{if(aj){aj()}}}X()}var a=O.PR={createSimpleLexer:h,registerLangHandler:d,sourceDecorator:i,PR_ATTRIB_NAME:R,PR_ATTRIB_VALUE:o,PR_COMMENT:k,PR_DECLARATION:F,PR_KEYWORD:A,PR_LITERAL:H,PR_NOCODE:P,PR_PLAIN:G,PR_PUNCTUATION:M,PR_SOURCE:K,PR_STRING:D,PR_TAG:n,PR_TYPE:Q,prettyPrintOne:O.prettyPrintOne=z,prettyPrint:O.prettyPrint=c};if(typeof define==="function"&&define.amd){define("google-code-prettify",[],function(){return a})}})();PR.registerLangHandler(PR.createSimpleLexer([],[[PR.PR_DECLARATION,/^<!\w[^>]*(?:>|$)/],[PR.PR_COMMENT,/^<\!--[\s\S]*?(?:-\->|$)/],[PR.PR_PUNCTUATION,/^(?:<[%?]|[%?]>)/],["lang-",/^<\?([\s\S]+?)(?:\?>|$)/],["lang-",/^<%([\s\S]+?)(?:%>|$)/],["lang-",/^<xmp\b[^>]*>([\s\S]+?)<\/xmp\b[^>]*>/i],["lang-handlebars",/^<script\b[^>]*type\s*=\s*['"]?text\/x-handlebars-template['"]?\b[^>]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-js",/^<script\b[^>]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-css",/^<style\b[^>]*>([\s\S]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i],[PR.PR_DECLARATION,/^{{[#^>/]?\s*[\w.][^}]*}}/],[PR.PR_DECLARATION,/^{{&?\s*[\w.][^}]*}}/],[PR.PR_DECLARATION,/^{{{>?\s*[\w.][^}]*}}}/],[PR.PR_COMMENT,/^{{![^}]*}}/]]),["handlebars","hbs"]);PR.registerLangHandler(PR.createSimpleLexer([[PR.PR_PLAIN,/^[ \t\r\n\f]+/,null," \t\r\n\f"]],[[PR.PR_STRING,/^\"(?:[^\n\r\f\\\"]|\\(?:\r\n?|\n|\f)|\\[\s\S])*\"/,null],[PR.PR_STRING,/^\'(?:[^\n\r\f\\\']|\\(?:\r\n?|\n|\f)|\\[\s\S])*\'/,null],["lang-css-str",/^url\(([^\)\"\']*)\)/i],[PR.PR_KEYWORD,/^(?:url|rgb|\!important|@import|@page|@media|@charset|inherit)(?=[^\-\w]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|(?:\\[0-9a-f]+ ?))(?:[_a-z0-9\-]|\\(?:\\[0-9a-f]+ ?))*)\s*:/i],[PR.PR_COMMENT,/^\/\*[^*]*\*+(?:[^\/*][^*]*\*+)*\//],[PR.PR_COMMENT,/^(?:<!--|-->)/],[PR.PR_LITERAL,/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],[PR.PR_LITERAL,/^#(?:[0-9a-f]{3}){1,2}/i],[PR.PR_PLAIN,/^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i],[PR.PR_PUNCTUATION,/^[^\s\w\'\"]+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[[PR.PR_KEYWORD,/^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[[PR.PR_STRING,/^[^\)\"\']+/]]),["css-str"]);
\ No newline at end of file
--- /dev/null
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <title>{{htmlTitle}}</title>
+ <link rel="stylesheet" href="{{yuiGridsUrl}}">
+ <link rel="stylesheet" href="{{projectAssets}}/vendor/prettify/prettify-min.css">
+ <link rel="stylesheet" href="{{projectAssets}}/css/main.css" id="site_styles">
+ <link rel="shortcut icon" type="image/png" href="{{projectAssets}}/favicon.png">
+ <script src="{{yuiSeedUrl}}"></script>
+</head>
+<body class="yui3-skin-sam">
+
+<div id="doc">
+ <div id="hd" class="yui3-g header">
+ <div class="yui3-u-3-4">
+ {{#if projectLogo}}
+ <h1><img src="{{projectLogo}}" title="{{projectName}}"></h1>
+ {{else}}
+ <h1><img src="{{projectAssets}}/css/logo.png" title="{{projectName}}"></h1>
+ {{/if}}
+ </div>
+ <div class="yui3-u-1-4 version">
+ <em>API Docs for: {{projectVersion}}</em>
+ </div>
+ </div>
+ <div id="bd" class="yui3-g">
+
+ <div class="yui3-u-1-4">
+ <div id="docs-sidebar" class="sidebar apidocs">
+ {{>sidebar}}
+ </div>
+ </div>
+ <div class="yui3-u-3-4">
+ {{>options}}
+ <div class="apidocs">
+ <div id="docs-main">
+ <div class="content">
+{{>layout_content}}
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+</div>
+<script src="{{projectAssets}}/vendor/prettify/prettify-min.js"></script>
+<script>prettyPrint();</script>
+<script src="{{projectAssets}}/js/yui-prettify.js"></script>
+<script src="{{projectAssets}}/../api.js"></script>
+<script src="{{projectAssets}}/js/api-filter.js"></script>
+<script src="{{projectAssets}}/js/api-list.js"></script>
+<script src="{{projectAssets}}/js/api-search.js"></script>
+<script src="{{projectAssets}}/js/apidocs.js"></script>
+</body>
+</html>
--- /dev/null
+<div id="docs-main">
+ <div class="content">
+{{>layout_content}}
+ </div>
+</div>
+
+<div id="xhr-title" class="hidden">{{title}}</div>
--- /dev/null
+<div id="attr_{{name}}" class="attr item{{#if access}} {{access}}{{/if}}{{#if deprecated}} deprecated{{/if}}{{#if extended_from}} inherited{{/if}}">
+ <a name="config_{{name}}"></a> {{! For backwards compatibility }}
+ <h3 class="name"><code>{{name}}</code></h3>
+ <span class="type">{{#crossLink type}}{{/crossLink}}</span>
+
+ {{#if deprecated}}
+ <span class="flag deprecated"{{#if deprecationMessage}} title="{{deprecationMessage}}"{{/if}}>deprecated</span>
+ {{/if}}
+
+ {{#if access}}
+ <span class="flag {{access}}">{{access}}</span>
+ {{/if}}
+
+ {{#if final}}
+ <span class="flag final">final</span>
+ {{/if}}
+
+ {{#if static}}
+ <span class="flag static">static</span>
+ {{/if}}
+
+ {{#if optional}}
+ <span class="flag optional">optional</span>
+ {{/if}}
+
+ {{#if required}}
+ <span class="flag required">required</span>
+ {{/if}}
+
+ {{#if readonly}}
+ <span class="flag readonly">readonly</span>
+ {{/if}}
+
+ <div class="meta">
+ {{#if overwritten_from}}
+ <p>Inherited from
+ <a href="{{crossLinkRaw overwritten_from/class}}#attr_{{overwritten_from/name}}">
+ {{overwritten_from/class}}
+ </a>
+ {{#if foundAt}}
+ but overwritten in
+ {{/if}}
+ {{else}}
+ {{#if extended_from}}
+ <p>Inherited from
+ <a href="{{crossLinkRaw extended_from}}#attr_{{name}}">{{extended_from}}</a>:
+ {{else}}
+ {{#providedBy}}
+ <p>Provided by the <a href="../modules/{{.}}.html">{{.}}</a> module.</p>
+ {{/providedBy}}
+ <p>
+ {{#if foundAt}}
+ Defined in
+ {{/if}}
+ {{/if}}
+ {{/if}}
+ {{#if foundAt}}
+ <a href="{{foundAt}}">`{{{file}}}:{{{line}}}`</a>
+ {{/if}}
+ </p>
+
+ {{#if deprecationMessage}}
+ <p>Deprecated: {{deprecationMessage}}</p>
+ {{/if}}
+
+ {{#if since}}
+ <p>Available since {{since}}</p>
+ {{/if}}
+ </div>
+
+ <div class="description">
+ {{{attrDescription}}}
+ </div>
+
+ {{#if default}}
+ <p><strong>Default:</strong> {{default}}</p>
+ {{/if}}
+
+ {{#if emit}}
+ <div class="emits box">
+ <h4>Fires event <code>{{name}}Change</code></h4>
+
+ <p>
+ Fires when the value for the configuration attribute `{{{name}}}` is
+ changed. You can listen for the event using the `on` method if you
+ wish to be notified before the attribute's value has changed, or
+ using the `after` method if you wish to be notified after the
+ attribute's value has changed.
+ </p>
+
+ <div class="params">
+ <h4>Parameters:</h4>
+
+ <ul class="params-list">
+ <li class="param">
+ <code class="param-name">e</code>
+ <span class="type">{{#crossLink "EventFacade"}}{{/crossLink}}</span>
+
+ <div class="param-description">
+ An Event Facade object with the following
+ attribute-specific properties added:
+ </div>
+
+ <ul class="params-list">
+ <li class="param">
+ <code class="param-name">prevVal</code>
+ <span class="type">Any</span>
+ <div class="param-description">The value of the attribute, prior to it being set.</div>
+ </li>
+ <li class="param">
+ <code class="param-name">newVal</code>
+ <span class="type">Any</span>
+ <div class="param-description">The value the attribute is to be set to.</div>
+ </li>
+ <li class="param">
+ <code class="param-name">attrName</code>
+ <span class="type">{{#crossLink "String"}}{{/crossLink}}</span>
+ <div class="param-description">The name of the attribute being set.</div>
+ </li>
+ <li class="param">
+ <code class="param-name">subAttrName</code>
+ <span class="type">{{#crossLink "String"}}{{/crossLink}}</span>
+ <div class="param-description">If setting a property within the attribute's value, the name of the sub-attribute property being set.</div>
+ </li>
+ </ul>
+ </li>
+ </ul>
+ </div>
+ </div>
+ {{/if}}
+
+ {{#example}}
+ <div class="example">
+ <h4>Example:</h4>
+
+ <div class="example-content">
+ {{{.}}}
+ </div>
+ </div>
+ {{/example}}
+</div>
--- /dev/null
+<h1>{{name}} Class</h1>
+<div class="box meta">
+ {{#if uses}}
+ <div class="uses">
+ Uses
+ <ul class="inline commas">
+ {{#uses}}
+ <li><a href="{{.}}.html">{{.}}</a></li>
+ {{/uses}}
+ </ul>
+ </div>
+ {{/if}}
+
+ {{#if extends}}
+ <div class="extends">
+ Extends {{#crossLink extends}}{{/crossLink}}
+ </div>
+ {{/if}}
+
+ {{#if foundAt}}
+ <div class="foundat">
+ Defined in: <a href="{{foundAt}}">`{{{file}}}:{{{line}}}`</a>
+ </div>
+ {{/if}}
+
+ {{#if module}}
+ {{#if submodule}}
+ Module: {{#crossLinkModule submodule}}{{/crossLinkModule}}<br>
+ Parent Module: {{#crossLinkModule module}}{{/crossLinkModule}}
+ {{else}}
+ Module: {{#crossLinkModule module}}{{/crossLinkModule}}
+ {{/if}}
+ {{/if}}
+
+ {{#if since}}
+ <p>Available since {{since}}</p>
+ {{/if}}
+</div>
+
+{{#if deprecated}}
+ <div class="box deprecated">
+ <p>
+ {{#if deprecationMessage}}
+ <strong>Deprecated:</strong> {{deprecationMessage}}
+ {{else}}
+ This class is deprecated.
+ {{/if}}
+ </p>
+ </div>
+{{/if}}
+
+<div class="box intro">
+ {{{classDescription}}}
+</div>
+
+{{#is_constructor}}
+ <div class="constructor">
+ <h2>Constructor</h2>
+ {{>method}}
+ </div>
+{{/is_constructor}}
+
+<div id="classdocs" class="tabview">
+ <ul class="api-class-tabs">
+ <li class="api-class-tab index"><a href="#index">Index</a></li>
+
+ {{#if methods}}
+ <li class="api-class-tab methods"><a href="#methods">Methods</a></li>
+ {{/if}}
+ {{#if properties}}
+ <li class="api-class-tab properties"><a href="#properties">Properties</a></li>
+ {{/if}}
+ {{#if attrs}}
+ <li class="api-class-tab attrs"><a href="#attrs">Attributes</a></li>
+ {{/if}}
+ {{#if events}}
+ <li class="api-class-tab events"><a href="#events">Events</a></li>
+ {{/if}}
+ </ul>
+
+ <div>
+ <div id="index" class="api-class-tabpanel index">
+ <h2 class="off-left">Item Index</h2>
+
+ {{#if methods}}
+ <div class="index-section methods">
+ <h3>Methods</h3>
+
+ <ul class="index-list methods{{#if extends}} extends{{/if}}">
+ {{#methods}}
+ <li class="index-item method{{#if access}} {{access}}{{/if}}{{#if deprecated}} deprecated{{/if}}{{#if overwritten_from}} inherited{{/if}}{{#if extended_from}} inherited{{/if}}">
+ <a href="#method_{{name}}">{{name}}</a>
+
+ {{#if static}}
+ <span class="flag static">static</span>
+ {{/if}}
+ {{#if deprecated}}
+ <span class="flag deprecated">deprecated</span>
+ {{/if}}
+ </li>
+ {{/methods}}
+ </ul>
+ </div>
+ {{/if}}
+
+ {{#if properties}}
+ <div class="index-section properties">
+ <h3>Properties</h3>
+
+ <ul class="index-list properties{{#if extends}} extends{{/if}}">
+ {{#properties}}
+ <li class="index-item property{{#if access}} {{access}}{{/if}}{{#if deprecated}} deprecated{{/if}}{{#if overwritten_from}} inherited{{/if}}{{#if extended_from}} inherited{{/if}}">
+ <a href="#property_{{name}}">{{name}}</a>
+
+ {{#if static}}
+ <span class="flag static">static</span>
+ {{/if}}
+ {{#if deprecated}}
+ <span class="flag deprecated">deprecated</span>
+ {{/if}}
+ </li>
+ {{/properties}}
+ </ul>
+ </div>
+ {{/if}}
+
+ {{#if attrs}}
+ <div class="index-section attrs">
+ <h3>Attributes</h3>
+
+ <ul class="index-list attrs{{#if extends}} extends{{/if}}">
+ {{#attrs}}
+ <li class="index-item attr{{#if access}} {{access}}{{/if}}{{#if deprecated}} deprecated{{/if}}{{#if overwritten_from}} inherited{{/if}}{{#if extended_from}} inherited{{/if}}">
+ <a href="#attr_{{name}}">{{name}}</a>
+ </li>
+ {{/attrs}}
+ </ul>
+ </div>
+ {{/if}}
+
+ {{#if events}}
+ <div class="index-section events">
+ <h3>Events</h3>
+
+ <ul class="index-list events{{#if extends}} extends{{/if}}">
+ {{#events}}
+ <li class="index-item event{{#if access}} {{access}}{{/if}}{{#if deprecated}} deprecated{{/if}}{{#if overwritten_from}} inherited{{/if}}{{#if extended_from}} inherited{{/if}}">
+ <a href="#event_{{name}}">{{name}}</a>
+
+ {{#if static}}
+ <span class="flag static">static</span>
+ {{/if}}
+ {{#if deprecated}}
+ <span class="flag deprecated">deprecated</span>
+ {{/if}}
+ </li>
+ {{/events}}
+ </ul>
+ </div>
+ {{/if}}
+ </div>
+
+ {{#if methods}}
+ <div id="methods" class="api-class-tabpanel">
+ <h2 class="off-left">Methods</h2>
+
+ {{#methods}}
+{{>method}}
+ {{/methods}}
+ </div>
+ {{/if}}
+
+ {{#if properties}}
+ <div id="properties" class="api-class-tabpanel">
+ <h2 class="off-left">Properties</h2>
+
+ {{#properties}}
+ {{>props}}
+ {{/properties}}
+ </div>
+ {{/if}}
+
+ {{#if attrs}}
+ <div id="attrs" class="api-class-tabpanel">
+ <h2 class="off-left">Attributes</h2>
+
+ {{#attrs}}
+ {{>attrs}}
+ {{/attrs}}
+ </div>
+ {{/if}}
+
+ {{#if events}}
+ <div id="events" class="api-class-tabpanel">
+ <h2 class="off-left">Events</h2>
+
+ {{#events}}
+ {{>events}}
+ {{/events}}
+ </div>
+ {{/if}}
+ </div>
+</div>
--- /dev/null
+<div id="event_{{name}}" class="events item{{#if access}} {{access}}{{/if}}{{#if deprecated}} deprecated{{/if}}{{#if extended_from}} inherited{{/if}}">
+ <h3 class="name"><code>{{name}}</code></h3>
+ <span class="type">{{#crossLink type}}{{/crossLink}}</span>
+
+ {{#if deprecated}}
+ <span class="flag deprecated"{{#if deprecationMessage}} title="{{deprecationMessage}}"{{/if}}>deprecated</span>
+ {{/if}}
+
+ {{#if access}}
+ <span class="flag {{access}}">{{access}}</span>
+ {{/if}}
+
+ {{#if final}}
+ <span class="flag final">final</span>
+ {{/if}}
+
+ {{#if static}}
+ <span class="flag static">static</span>
+ {{/if}}
+
+ <div class="meta">
+ {{#if overwritten_from}}
+ <p>Inherited from
+ <a href="{{crossLinkRaw overwritten_from/class}}#event_{{overwritten_from/name}}">
+ {{overwritten_from/class}}
+ </a>
+ {{#if foundAt}}
+ but overwritten in
+ {{/if}}
+ {{else}}
+ {{#if extended_from}}
+ <p>Inherited from
+ <a href="{{crossLinkRaw extended_from}}#event_{{name}}">{{extended_from}}</a>:
+ {{else}}
+ {{#providedBy}}
+ <p>Provided by the <a href="../modules/{{.}}.html">{{.}}</a> module.</p>
+ {{/providedBy}}
+ <p>
+ {{#if foundAt}}
+ Defined in
+ {{/if}}
+ {{/if}}
+ {{/if}}
+ {{#if foundAt}}
+ <a href="{{foundAt}}">`{{{file}}}:{{{line}}}`</a>
+ {{/if}}
+ </p>
+
+ {{#if deprecationMessage}}
+ <p>Deprecated: {{deprecationMessage}}</p>
+ {{/if}}
+
+ {{#if since}}
+ <p>Available since {{since}}</p>
+ {{/if}}
+ </div>
+
+ <div class="description">
+ {{{eventDescription}}}
+ </div>
+
+ {{#if params}}
+ <div class="params">
+ <h4>Event Payload:</h4>
+
+ <ul class="params-list">
+ {{#params}}
+ <li class="param">
+ {{#if optional}}
+ <code class="param-name optional">[{{name}}{{#if optdefault}}={{optdefault}}{{/if}}]</code>
+ <span class="type">{{#crossLink type}}{{/crossLink}}</span>
+ <span class="flag optional" title="This parameter is optional.">optional</span>
+ {{else}}
+ <code class="param-name">{{name}}</code>
+ <span class="type">{{#crossLink type}}{{/crossLink}}</span>
+ {{/if}}
+
+ {{#if multiple}}
+ <span class="flag multiple" title="This parameter may occur one or more times.">Multiple</span>
+ {{/if}}
+
+ <div class="param-description">
+ {{{description}}}
+ </div>
+
+ {{#if props}}
+ <ul class="params-list">
+ {{#props}}
+ <li class="param">
+ {{#if optional}}
+ <code class="param-name optional">[{{name}}{{#if optdefault}}={{optdefault}}{{/if}}]</code>
+ <span class="type">{{#crossLink type}}{{/crossLink}}</span>
+ <span class="flag optional" title="This parameter is optional.">optional</span>
+ {{else}}
+ <code class="param-name">{{name}}</code>
+ <span class="type">{{#crossLink type}}{{/crossLink}}</span>
+ {{/if}}
+
+ <div class="param-description">
+ {{{description}}}
+ </div>
+
+ {{#if props}}
+ <ul class="params-list">
+ {{#props}}
+ <li class="param">
+ <code class="param-name">{{name}}</code>
+ <span class="type">{{#crossLink type}}{{/crossLink}}</span>
+
+ <div class="param-description">
+ {{{description}}}
+ </div>
+ </li>
+ {{/props}}
+ </ul>
+ {{/if}}
+ </li>
+ {{/props}}
+ </ul>
+ {{/if}}
+ </li>
+ {{/params}}
+ </ul>
+ </div>
+ {{/if}}
+
+
+ {{#example}}
+ <div class="example">
+ <h4>Example:</h4>
+
+ <div class="example-content">
+ {{{.}}}
+ </div>
+ </div>
+ {{/example}}
+</div>
--- /dev/null
+<h1 class="file-heading">File: {{fileName}}</h1>
+
+<div class="file">
+ <pre class="code prettyprint linenums">
+{{fileData}}
+ </pre>
+</div>
--- /dev/null
+ <div class="apidocs">
+ <div id="docs-main" class="content">
+ <p>
+ Browse to a module or class using the sidebar to view its API documentation.
+ </p>
+
+ <h2>Keyboard Shortcuts</h2>
+
+ <ul>
+ <li><p>Press <kbd>s</kbd> to focus the API search box.</p></li>
+
+ <li><p>Use <kbd>Up</kbd> and <kbd>Down</kbd> to select classes, modules, and search results.</p></li>
+
+ <li class="mac-only"><p>With the API search box or sidebar focused, use <kbd><span class="cmd">⌘</span>-Left</kbd> or <kbd><span class="cmd">⌘</span>-Right</kbd> to switch sidebar tabs.</p></li>
+
+ <li class="pc-only"><p>With the API search box or sidebar focused, use <kbd>Ctrl+Left</kbd> and <kbd>Ctrl+Right</kbd> to switch sidebar tabs.</p></li>
+ </ul>
+ </div>
+ </div>
+
+
--- /dev/null
+<div id="method_{{name}}" class="method item{{#if access}} {{access}}{{/if}}{{#if deprecated}} deprecated{{/if}}{{#if extended_from}} inherited{{/if}}">
+ <h3 class="name"><code>{{name}}</code></h3>
+
+ {{#if params}}
+ <div class="args">
+ <span class="paren">(</span><ul class="args-list inline commas">
+ {{#params}}
+ <li class="arg">
+ {{#if optional}}
+ <code class="optional">[{{name}}{{#if optdefault}}={{optdefault}}{{/if}}]</code>
+ {{else}}
+ <code>{{name}}</code>
+ {{/if}}
+ </li>
+ {{/params}}
+ </ul><span class="paren">)</span>
+ </div>
+ {{else}}
+ <span class="paren">()</span>
+ {{/if}}
+
+ {{#if return}}
+ <span class="returns-inline">
+ <span class="type">{{#crossLink returnType}}{{/crossLink}}</span>
+ </span>
+ {{/if}}
+
+ {{#if deprecated}}
+ <span class="flag deprecated"{{#if deprecationMessage}} title="{{deprecationMessage}}"{{/if}}>deprecated</span>
+ {{/if}}
+
+ {{#if access}}
+ <span class="flag {{access}}">{{access}}</span>
+ {{/if}}
+
+ {{#if final}}
+ <span class="flag final">final</span>
+ {{/if}}
+
+ {{#if static}}
+ <span class="flag static">static</span>
+ {{/if}}
+
+ {{#if chainable}}
+ <span class="flag chainable">chainable</span>
+ {{/if}}
+
+ {{#if async}}
+ <span class="flag async">async</span>
+ {{/if}}
+
+ <div class="meta">
+ {{#if overwritten_from}}
+ <p>Inherited from
+ <a href="{{crossLinkRaw overwritten_from/class}}#method_{{overwritten_from/name}}">
+ {{overwritten_from/class}}
+ </a>
+ {{#if foundAt}}
+ but overwritten in
+ {{/if}}
+ {{else}}
+ {{#if extended_from}}
+ <p>Inherited from
+ <a href="{{crossLinkRaw extended_from}}#method_{{name}}">{{extended_from}}</a>:
+ {{else}}
+ {{#providedBy}}
+ <p>Provided by the <a href="../modules/{{.}}.html">{{.}}</a> module.</p>
+ {{/providedBy}}
+ <p>
+ {{#if foundAt}}
+ Defined in
+ {{/if}}
+ {{/if}}
+ {{/if}}
+ {{#if foundAt}}
+ <a href="{{foundAt}}">`{{{file}}}:{{{line}}}`</a>
+ {{/if}}
+ </p>
+
+
+ {{#if deprecationMessage}}
+ <p>Deprecated: {{deprecationMessage}}</p>
+ {{/if}}
+
+ {{#if since}}
+ <p>Available since {{since}}</p>
+ {{/if}}
+ </div>
+
+ <div class="description">
+ {{{methodDescription}}}
+ </div>
+
+ {{#if params}}
+ <div class="params">
+ <h4>Parameters:</h4>
+
+ <ul class="params-list">
+ {{#params}}
+ <li class="param">
+ {{#if optional}}
+ <code class="param-name optional">[{{name}}{{#if optdefault}}={{optdefault}}{{/if}}]</code>
+ <span class="type">{{#crossLink type}}{{/crossLink}}</span>
+ <span class="flag optional" title="This parameter is optional.">optional</span>
+ {{else}}
+ <code class="param-name">{{name}}</code>
+ <span class="type">{{#crossLink type}}{{/crossLink}}</span>
+ {{/if}}
+
+ {{#if multiple}}
+ <span class="flag multiple" title="This argument may occur one or more times.">multiple</span>
+ {{/if}}
+
+ <div class="param-description">
+ {{{description}}}
+ </div>
+
+ {{#if props}}
+ <ul class="params-list">
+ {{#props}}
+ <li class="param">
+ {{#if optional}}
+ <code class="param-name optional">[{{name}}{{#if optdefault}}={{optdefault}}{{/if}}]</code>
+ <span class="type">{{#crossLink type}}{{/crossLink}}</span>
+ <span class="flag optional" title="This parameter is optional.">optional</span>
+ {{else}}
+ <code class="param-name">{{name}}</code>
+ <span class="type">{{#crossLink type}}{{/crossLink}}</span>
+ {{/if}}
+
+ <div class="param-description">
+ {{{description}}}
+ </div>
+
+ {{#if props}}
+ <ul class="params-list">
+ {{#props}}
+ <li class="param">
+ {{#if optional}}
+ <code class="param-name optional">[{{name}}{{#if optdefault}}={{optdefault}}{{/if}}]</code>
+ <span class="type">{{#crossLink type}}{{/crossLink}}</span>
+ <span class="flag optional" title="This parameter is optional.">optional</span>
+ {{else}}
+ <code class="param-name">{{name}}</code>
+ <span class="type">{{#crossLink type}}{{/crossLink}}</span>
+ {{/if}}
+
+ <div class="param-description">
+ {{{description}}}
+ </div>
+ </li>
+ {{/props}}
+ </ul>
+ {{/if}}
+ </li>
+ {{/props}}
+ </ul>
+ {{/if}}
+ </li>
+ {{/params}}
+ </ul>
+ </div>
+ {{/if}}
+
+ {{#return}}
+ <div class="returns">
+ <h4>Returns:</h4>
+
+ <div class="returns-description">
+ {{#if description}}
+ {{#if type}}
+ <span class="type">{{#crossLink type}}{{/crossLink}}</span>:
+ {{/if}}
+ {{{description}}}
+ {{else}}
+ {{#if type}}
+ <span class="type">{{#crossLink type}}{{/crossLink}}</span>:
+ {{/if}}
+ {{/if}}
+ </div>
+ </div>
+ {{/return}}
+
+ {{#throws}}
+ <div class="throws">
+ <h4>Throws:</h4>
+
+ <div class="throws-description">
+ {{#if description}}
+ {{#if type}}
+ <span class="type">{{#crossLink type}}{{/crossLink}}</span>:
+ {{/if}}
+ {{{description}}}
+ {{else}}
+ {{#if type}}
+ <span class="type">{{#crossLink type}}{{/crossLink}}</span>:
+ {{/if}}
+ {{/if}}
+ </div>
+ </div>
+ {{/throws}}
+
+ {{#example}}
+ <div class="example">
+ <h4>Example:</h4>
+
+ <div class="example-content">
+ {{{.}}}
+ </div>
+ </div>
+ {{/example}}
+</div>
--- /dev/null
+<h1>{{name}} Module</h1>
+<div class="box clearfix meta">
+ {{#extra}}
+ {{#selleck}}
+ <a class="button link-docs" href="/yui/docs/{{name}}">User Guide & Examples</a>
+ {{/selleck}}
+ {{/extra}}
+
+ {{#if requires}}
+ <div class="uses">
+ Requires
+ <ul class="inline commas">
+ {{#requires}}
+ <li>{{#crossLinkModule .}}{{/crossLinkModule}}</li>
+ {{/requires}}
+ </ul>
+ </div>
+ {{/if}}
+
+ {{#if foundAt}}
+ <div class="foundat">
+ Defined in: <a href="{{foundAt}}">`{{{file}}}:{{{line}}}`</a>
+ </div>
+ {{/if}}
+
+ {{#if since}}
+ <p>Available since {{since}}</p>
+ {{/if}}
+</div>
+
+{{#if deprecated}}
+ <div class="box deprecated">
+ <p>
+ {{#if deprecationMessage}}
+ <strong>Deprecated:</strong> {{deprecationMessage}}
+ {{else}}
+ This module is deprecated.
+ {{/if}}
+ </p>
+ </div>
+{{/if}}
+
+<div class="box intro">
+ {{{moduleDescription}}}
+</div>
+
+{{#example}}
+ <div class="example">
+ <h4>Example:</h4>
+ <div class="example-content">
+ {{{.}}}
+ </div>
+ </div>
+{{/example}}
+
+<div class="yui3-g">
+ <div class="yui3-u-1-2">
+ {{#if moduleClasses}}
+ <p>This module provides the following classes:</p>
+
+ <ul class="module-classes">
+ {{#moduleClasses}}
+ <li class="module-class">
+ <a href="{{../projectRoot}}classes/{{name}}.html">
+ {{displayName}}
+ </a>
+ </li>
+ {{/moduleClasses}}
+ </ul>
+ {{/if}}
+ </div>
+
+ <div class="yui3-u-1-2">
+ {{#if subModules}}
+ <p>This module is a rollup of the following modules:</p>
+
+ <ul class="module-submodules">
+ {{#subModules}}
+ <li class="module-submodule">
+ <a href="{{../projectRoot}}modules/{{name}}.html">
+ {{displayName}}
+ </a>
+
+ <div class="module-submodule-description">
+ {{{description}}}
+ </div>
+ </li>
+ {{/subModules}}
+ </ul>
+ {{/if}}
+ </div>
+</div>
--- /dev/null
+ <div id="api-options">
+ Show:
+ <label for="api-show-inherited">
+ <input type="checkbox" id="api-show-inherited" checked>
+ Inherited
+ </label>
+
+ <label for="api-show-protected">
+ <input type="checkbox" id="api-show-protected">
+ Protected
+ </label>
+
+ <label for="api-show-private">
+ <input type="checkbox" id="api-show-private">
+ Private
+ </label>
+ <label for="api-show-deprecated">
+ <input type="checkbox" id="api-show-deprecated">
+ Deprecated
+ </label>
+
+ </div>
+
--- /dev/null
+<div id="property_{{name}}" class="property item{{#if access}} {{access}}{{/if}}{{#if deprecated}} deprecated{{/if}}{{#if extended_from}} inherited{{/if}}">
+ <h3 class="name"><code>{{name}}</code></h3>
+ <span class="type">{{#crossLink type}}{{/crossLink}}</span>
+
+ {{#if deprecated}}
+ <span class="flag deprecated"{{#if deprecationMessage}} title="{{deprecationMessage}}"{{/if}}>deprecated</span>
+ {{/if}}
+
+ {{#if access}}
+ <span class="flag {{access}}">{{access}}</span>
+ {{/if}}
+
+ {{#if final}}
+ <span class="flag final">final</span>
+ {{/if}}
+
+ {{#if static}}
+ <span class="flag static">static</span>
+ {{/if}}
+
+ <div class="meta">
+ {{#if overwritten_from}}
+ <p>Inherited from
+ <a href="{{crossLinkRaw overwritten_from/class}}#property_{{overwritten_from/name}}">
+ {{overwritten_from/class}}
+ </a>
+ {{#if foundAt}}
+ but overwritten in
+ {{/if}}
+ {{else}}
+ {{#if extended_from}}
+ <p>Inherited from
+ <a href="{{crossLinkRaw extended_from}}#property_{{name}}">{{extended_from}}</a>:
+ {{else}}
+ {{#providedBy}}
+ <p>Provided by the <a href="../modules/{{.}}.html">{{.}}</a> module.</p>
+ {{/providedBy}}
+ <p>
+ {{#if foundAt}}
+ Defined in
+ {{/if}}
+ {{/if}}
+ {{/if}}
+ {{#if foundAt}}
+ <a href="{{foundAt}}">`{{{file}}}:{{{line}}}`</a>
+ {{/if}}
+ </p>
+
+ {{#if deprecationMessage}}
+ <p>Deprecated: {{deprecationMessage}}</p>
+ {{/if}}
+
+ {{#if since}}
+ <p>Available since {{since}}</p>
+ {{/if}}
+ </div>
+
+ <div class="description">
+ {{{propertyDescription}}}
+ </div>
+
+ {{#if default}}
+ <p><strong>Default:</strong> {{default}}</p>
+ {{/if}}
+
+ {{#example}}
+ <div class="example">
+ <h4>Example:</h4>
+
+ <div class="example-content">
+ {{{.}}}
+ </div>
+ </div>
+ {{/example}}
+
+ {{#if subprops}}
+ <h4>Sub-properties:</h4>
+
+ <ul class="params-list">
+ {{#subprops}}
+ <li class="param">
+ {{#if optional}}
+ <code class="param-name optional">[{{name}}{{#if optdefault}}={{optdefault}}{{/if}}]</code>
+ <span class="type">{{#crossLink type}}{{/crossLink}}</span>
+ <span class="flag optional" title="This property is optional.">optional</span>
+ {{else}}
+ <code class="param-name">{{name}}</code>
+ <span class="type">{{#crossLink type}}{{/crossLink}}</span>
+ {{/if}}
+
+ <div class="param-description">
+ {{{description}}}
+ </div>
+
+ {{#if subprops}}
+ <ul class="params-list">
+ {{#subprops}}
+ <li class="param">
+ {{#if optional}}
+ <code class="param-name optional">[{{name}}{{#if optdefault}}={{optdefault}}{{/if}}]</code>
+ <span class="type">{{#crossLink type}}{{/crossLink}}</span>
+ <span class="flag optional" title="This property is optional.">optional</span>
+ {{else}}
+ <code class="param-name">{{name}}</code>
+ <span class="type">{{#crossLink type}}{{/crossLink}}</span>
+ {{/if}}
+
+ <div class="param-description">
+ {{{description}}}
+ </div>
+ </li>
+ {{/subprops}}
+ </ul>
+ {{/if}}
+ </li>
+ {{/subprops}}
+ </ul>
+ {{/if}}
+</div>
--- /dev/null
+<div id="api-list">
+ <h2 class="off-left">APIs</h2>
+ <div id="api-tabview" class="tabview">
+ <ul class="tabs">
+ <li><a href="#api-classes">Classes</a></li>
+ <li><a href="#api-modules">Modules</a></li>
+ </ul>
+
+ <div id="api-tabview-filter">
+ <input type="search" id="api-filter" placeholder="Type to filter APIs">
+ </div>
+
+ <div id="api-tabview-panel">
+ <ul id="api-classes" class="apis classes">
+ {{#classes}}
+ <li><a href="{{../projectRoot}}classes/{{name}}.html">{{displayName}}</a></li>
+ {{/classes}}
+ </ul>
+
+ <ul id="api-modules" class="apis modules">
+ {{#allModules}}
+ <li><a href="{{../projectRoot}}modules/{{name}}.html">{{displayName}}</a></li>
+ {{/allModules}}
+ </ul>
+ </div>
+ </div>
+</div>
--- /dev/null
+{
+ "yuiGridsUrl": "http://yui.yahooapis.com/3.9.1/build/cssgrids/cssgrids-min.css",
+ "yuiSeedUrl": "http://yui.yahooapis.com/combo?3.9.1/build/yui/yui-min.js"
+}
--- /dev/null
+{
+ "name": "DALI JavaScript API",
+ "description": "DALI is a dynamic animtaion library for building advanced 3D applications",
+ "version": "1.0.0",
+ "themedir": "dali-theme",
+ "url": "https://review.tizen.org/gerrit/platform/core/uifw/dali-core",
+ "options": {
+ "outdir": "generated",
+ "markdown": {
+ "gfm":"true"
+ }
+ }
+}
--- /dev/null
+# Add local source files here
+
+v8_plugin_dir =\
+ $(plugin_src_dir)/dali-script-v8/src
+
+script_v8_plugin_src_files = \
+ $(v8_plugin_dir)/dali-script-v8.cpp \
+ $(v8_plugin_dir)/utils/v8-utils.cpp \
+ $(v8_plugin_dir)/dali-wrapper.cpp \
+ $(v8_plugin_dir)/shared/base-wrapped-object.cpp \
+ $(v8_plugin_dir)/shared/object-template-helper.cpp \
+ $(v8_plugin_dir)/actors/actor-wrapper.cpp \
+ $(v8_plugin_dir)/actors/actor-api.cpp \
+ $(v8_plugin_dir)/actors/layer-api.cpp \
+ $(v8_plugin_dir)/actors/text-actor-api.cpp \
+ $(v8_plugin_dir)/actors/image-actor-api.cpp \
+ $(v8_plugin_dir)/actors/camera-actor-api.cpp \
+ $(v8_plugin_dir)/actors/mesh-actor-api.cpp \
+ $(v8_plugin_dir)/actors/renderable-actor-api.cpp \
+ $(v8_plugin_dir)/constants/constants-wrapper.cpp \
+ $(v8_plugin_dir)/text/font-api.cpp \
+ $(v8_plugin_dir)/text/font-wrapper.cpp \
+ $(v8_plugin_dir)/animation/animation-api.cpp \
+ $(v8_plugin_dir)/animation/animation-wrapper.cpp \
+ $(v8_plugin_dir)/animation/path-api.cpp \
+ $(v8_plugin_dir)/animation/path-wrapper.cpp \
+ $(v8_plugin_dir)/stage/stage-wrapper.cpp \
+ $(v8_plugin_dir)/events/event-object-generator.cpp \
+ $(v8_plugin_dir)/events/pan-gesture-detector-api.cpp \
+ $(v8_plugin_dir)/events/pan-gesture-detector-wrapper.cpp \
+ $(v8_plugin_dir)/stage/stage-api.cpp \
+ $(v8_plugin_dir)/image/image-attributes-api.cpp \
+ $(v8_plugin_dir)/shader-effects/shader-effect-api.cpp \
+ $(v8_plugin_dir)/shader-effects/shader-effect-wrapper.cpp \
+ $(v8_plugin_dir)/image/image-attributes-wrapper.cpp \
+ $(v8_plugin_dir)/image/image-wrapper.cpp \
+ $(v8_plugin_dir)/image/image-api.cpp \
+ $(v8_plugin_dir)/image/buffer-image-api.cpp \
+ $(v8_plugin_dir)/image/native-image-api.cpp \
+ $(v8_plugin_dir)/image/frame-buffer-image-api.cpp \
+ $(v8_plugin_dir)/image/resource-image-api.cpp \
+ $(v8_plugin_dir)/image/nine-patch-image-api.cpp \
+ $(v8_plugin_dir)/object/handle-wrapper.cpp \
+ $(v8_plugin_dir)/object/property-value-wrapper.cpp \
+ $(v8_plugin_dir)/signals/signal-manager.cpp \
+ $(v8_plugin_dir)/render-tasks/render-task-list-api.cpp \
+ $(v8_plugin_dir)/render-tasks/render-task-list-wrapper.cpp \
+ $(v8_plugin_dir)/render-tasks/render-task-api.cpp \
+ $(v8_plugin_dir)/render-tasks/render-task-wrapper.cpp \
+ $(v8_plugin_dir)/toolkit/builder/builder-api.cpp \
+ $(v8_plugin_dir)/toolkit/builder/builder-wrapper.cpp \
+ $(v8_plugin_dir)/toolkit/focus-manager/keyboard-focus-manager-api.cpp \
+ $(v8_plugin_dir)/toolkit/focus-manager/keyboard-focus-manager-wrapper.cpp \
+ $(v8_plugin_dir)/signals/dali-any-javascript-converter.cpp \
+ $(v8_plugin_dir)/garbage-collector/garbage-collector.cpp \
+ $(v8_plugin_dir)/module-loader/module.cpp \
+ $(v8_plugin_dir)/module-loader/module-loader.cpp
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "actor-api.h"
+
+// EXTERNAL INCLUDES
+#include <dali-toolkit/public-api/controls/text-view/text-view.h>
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <actors/actor-wrapper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace // unanmed namespace
+{
+Actor GetActor( v8::Isolate* isolate, const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ HandleWrapper* handleWrapper = HandleWrapper::Unwrap( isolate, args.This() );
+ return Actor::DownCast( handleWrapper->mHandle );
+}
+} //unanmed namespace
+
+
+namespace TextViewApi
+{
+ Actor New( const v8::FunctionCallbackInfo< v8::Value >& args )
+ {
+ return Dali::Toolkit::TextView::New();
+ }
+}
+
+/***************************************
+ * ACTOR API FUNCTIONS
+ ****************************************/
+/**
+ * Constructor
+ *
+ * @for Actor
+ * @constructor
+ * @method Actor
+ * @return {Object} actor
+ */
+Actor ActorApi::New( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ return Actor::New();
+}
+
+/**
+ * get the actors unique id
+ *
+ * @for Actor
+ * @method getId
+ * @return {Integer} id
+ */
+void ActorApi::GetId( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Actor actor = GetActor( isolate, args );
+
+ args.GetReturnValue().Set( v8::Integer::New( isolate, actor.GetId() ) );
+}
+
+/**
+ * Query whether an actor is the root actor, which is owned by the Stage
+ *
+ * @for Actor
+ * @method isRoot
+ * @return {Boolean} true if it is root
+ *
+ */
+void ActorApi::IsRoot( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Actor actor = GetActor( isolate, args );
+
+ args.GetReturnValue().Set( v8::Boolean::New( isolate, actor.IsRoot() ) );
+}
+
+/**
+ *
+ * Query whether the actor is connected to the Stage.
+ * When an actor is connected, it will be directly or indirectly parented to the root Actor.
+ * The root Actor is provided automatically by dali.stage, and is always considered to be connected.
+ *
+ * @for Actor
+ * @method onStage
+ * @return {Boolean} True if the actor is connected to the Stage
+ */
+void ActorApi::OnStage( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Actor actor = GetActor( isolate, args );
+
+ args.GetReturnValue().Set( v8::Boolean::New( isolate, actor.OnStage() ) );
+}
+
+/**
+ * Query whether an actor is a layer
+ *
+ * @for Actor
+ * @method isLayer
+ * @return {Boolean} true if it is a layer
+ */
+void ActorApi::IsLayer( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Actor actor = GetActor( isolate, args );
+
+ args.GetReturnValue().Set( v8::Boolean::New( isolate, actor.IsLayer() ) );
+}
+
+/**
+ * Gets the layer in which the actor is present.
+ *
+ * @for Actor
+ * @method getLayer
+ * @return {Object} Layer
+ */
+void ActorApi::GetLayer( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Actor actor = GetActor( isolate, args );
+ Layer layer = actor.GetLayer();
+ if( layer ) // actors don't always have a layer
+ {
+ v8::Handle < v8::Object > wrappedLayer = ActorWrapper::ActorWrapper::WrapActor( isolate, layer, ActorWrapper::LAYER_ACTOR );
+ args.GetReturnValue().Set( wrappedLayer );
+ }
+ // else return an empty object
+}
+
+/**
+ * Adds a child Actor to this Actor.
+ *
+ * NOTE! if the child already has a parent, it will be removed from old parent
+ * and reparented to this actor. This may change childs position, color, shader effect,
+ * scale etc as it now inherits them from this actor
+ *
+ * Pre-conditions
+ * - The child actor is not the same as the parent actor.
+ * - The actor is not the Root actor
+
+ * Once added The child will be referenced by its parent. This means that the child will be kept alive,
+ * even if the handle passed into this method is reset or destroyed.
+ *
+ * @for Actor
+ * @method add
+ * @param {Object} Actor
+ */
+void ActorApi::AddActor( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Actor parent = GetActor( isolate, args );
+ bool found(false);
+ Actor child = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
+ if( found )
+ {
+ parent.Add( child );
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "child parameter missing" );
+ }
+}
+
+/**
+ * Removes a child Actor from this Actor.
+ *
+ * If the actor was not a child of this actor, this is a no-op.
+ *
+ * Preconditions:
+ * - The child actor is not the same as the parent actor.
+ *
+ * @for Actor
+ * @param{Object} Actor the child actor
+ * @method Remove
+ */
+void ActorApi::RemoveActor( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Actor parent = GetActor( isolate, args );
+ bool found( false );
+ Actor child = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
+
+ if( found )
+ {
+ parent.Remove( child );
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "child parameter missing" );
+ }
+}
+
+/**
+ * Checks whether an Actor is equal to this Actor.
+ *
+ * @for Actor
+ * @method iIsEqualTo
+ * @param {Object} Actor
+ */
+void ActorApi::IsEqualTo( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Actor self = GetActor( isolate, args );
+ bool found( false );
+
+ Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
+ if( found )
+ {
+ args.GetReturnValue().Set( v8::Boolean::New( isolate, (actor == self) ) );
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "actor parameter missing" );
+ }
+}
+
+/** Removes an actor from its parent.
+ *
+ * If the actor has no parent, this method does nothing.
+ *
+ * @for Actor
+ * @method Unparent
+ */
+void ActorApi::Unparent( const v8::FunctionCallbackInfo< v8::Value >& args)
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Actor actor = GetActor( isolate, args );
+ actor.Unparent();
+}
+
+/**
+ * get number of child actors
+ *
+ * @for Actor
+ * @method getChildCount
+ * @return {Integer} count
+ */
+void ActorApi::GetChildCount( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Actor actor = GetActor( isolate, args );
+
+ args.GetReturnValue().Set( v8::Integer::New( isolate, actor.GetChildCount() ) );
+}
+
+/**
+ * Retrieve and child actor by index.
+ *
+ * @for Actor
+ * @method getChildAt
+ * @param {Integer} actor index
+ * @return {Object} actor on success, empty actor handle if not found
+ */
+void ActorApi::GetChildAt( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Actor parent = GetActor( isolate, args );
+ bool found( false );
+ int id = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Integer parameter missing" );
+ return;
+ }
+ Actor childActor = parent.GetChildAt( id );
+ if( childActor )
+ {
+ // wrap the child
+ v8::Handle < v8::Object > wrappedActor = ActorWrapper::WrapActor( isolate, childActor );
+ args.GetReturnValue().Set( wrappedActor );
+ }
+}
+
+/**
+ * Search through this actor's hierarchy for an actor with the given name
+ * The actor itself is also considered in the search
+ *
+ * @for Actor
+ * @method findChildByName
+ * @param {String} actor name
+ * @return {Object} actor on success, empty actor handle if not found
+ */
+void ActorApi::FindChildByName( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Actor parent = GetActor( isolate, args );
+ bool found( false );
+ std::string name = V8Utils::GetStringParameter( PARAMETER_0, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "string parameter missing" );
+ return;
+ }
+ Actor childActor = parent.FindChildByName( name );
+ if( childActor )
+ {
+ // wrap the child
+ v8::Handle < v8::Object > wrappedLayer = ActorWrapper::WrapActor( isolate, childActor );
+ args.GetReturnValue().Set( wrappedLayer );
+ }
+}
+
+/**
+ * Search through this actor's hierarchy for an actor with the given name or alias.
+ *
+ * Actors can customize this function to provide actors with preferred alias'
+ * For example 'previous' could return the last selected child.
+ * If no aliased actor is found then FindChildByName() is called.
+ *
+ * @for Actor
+ * @method findChildByAlias
+ * @param {String} actor alias
+ * @return {Object} actor on success, empty actor handle if not found
+ */
+void ActorApi::FindChildByAlias( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Actor parent = GetActor( isolate, args );
+ bool found( false );
+ std::string name = V8Utils::GetStringParameter( PARAMETER_0, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "String parameter not found" );
+ return;
+ }
+ Actor childActor = parent.FindChildByAlias( name );
+ if( childActor )
+ {
+ // wrap the child
+ v8::Local < v8::Object > wrappedLayer = ActorWrapper::WrapActor( isolate, childActor );
+ args.GetReturnValue().Set( wrappedLayer );
+ }
+}
+
+/**
+ * Search through this actor's hierarchy for an actor with the given unique ID.
+ * The actor itself is also considered in the search
+ *
+ * @for Actor
+ * @method findChildById
+ * @param {Integer} id
+ * @return {Object} actor on success, empty actor handle if not found
+ */
+void ActorApi::FindChildById( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Actor parent = GetActor( isolate, args );
+
+ bool found( false );
+ int id = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Integer parameter missing" );
+ return;
+ }
+ Actor childActor = parent.FindChildById( id );
+ if( childActor )
+ {
+ // wrap the child
+ v8::Local < v8::Object > wrappedLayer = ActorWrapper::WrapActor( isolate, childActor );
+ args.GetReturnValue().Set( wrappedLayer );
+ }
+}
+
+
+/**
+ * retrieve the actor's parent.
+ *
+ * @for Actor
+ * @method getParent
+ * @return {Object} actor on success, empty actor handle if actor has no parent
+ */
+void ActorApi::GetParent( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Actor actor = GetActor( isolate, args );
+ Actor parent = actor.GetParent();
+
+ if( parent )
+ {
+ v8::Local < v8::Object > wrappedLayer = ActorWrapper::WrapActor( isolate, parent );
+ args.GetReturnValue().Set( wrappedLayer );
+ }
+}
+/**
+ * Converts screen coordinates into the actor's coordinate system using the default camera.
+ *
+ * The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
+ *
+ * @example
+ * var local = actor.screenToLocal( [ 10, 53 ]);
+ * var xPos = local.x;
+ * var yPos = local.y;
+ *
+ *
+ * @for Actor
+ * @method screenToLocal
+ * @param {Object} ScreenCoordinates array of 2 objects
+ * @return {Object} local coordinates object with x,y properties
+ */
+void ActorApi::ScreenToLocal( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Actor actor = GetActor( isolate, args );
+
+ //ool ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const;
+ bool found( false );
+
+ int argCount( args.Length() );
+ Vector2 vector;
+
+ if( argCount == 1 )
+ {
+ vector = V8Utils::GetVector2Parameter( PARAMETER_0, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "invalid parameters (x,y)" );
+ return;
+ }
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "invalid parameters (x,y)" );
+ return;
+ }
+ float localX, localY;
+ actor.ScreenToLocal( localX, localY, vector.x, vector.y );
+
+ v8::Local < v8::Object > localCoordinates = v8::Object::New( isolate );
+
+ localCoordinates->Set( v8::String::NewFromUtf8( isolate, "x" ), v8::Number::New( isolate, localX ) );
+ localCoordinates->Set( v8::String::NewFromUtf8( isolate, "y" ), v8::Number::New( isolate, localY ) );
+
+ args.GetReturnValue().Set( localCoordinates );
+
+}
+
+/**
+ * Sets whether the actor should be focusable by keyboard navigation.
+ *
+ * @for Actor
+ * @method setKeyboardFocusable
+ * @param {Boolean} folcusable
+ */
+void ActorApi::SetKeyboardFocusable( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Actor actor = GetActor( isolate, args );
+ bool parameterFound( false );
+ bool focus = V8Utils::GetBooleanParameter( PARAMETER_0, parameterFound, isolate, args );
+ if( !parameterFound )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "boolean parameter missing" );
+ return;
+ }
+
+ actor.SetKeyboardFocusable( focus );
+}
+
+/**
+ * Returns whether the actor is focusable by keyboard navigation.
+ *
+ *
+ * @for Actor
+ * @method isKeyboardFocusable
+ * @return {Boolean} folcusable
+ */
+void ActorApi::IsKeyboardFocusable( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Actor actor = GetActor( isolate, args );
+
+ args.GetReturnValue().Set( v8::Boolean::New( isolate, actor.IsKeyboardFocusable() ) );
+
+}
+/**
+ * retrieve the actor type
+ *
+ * @for Actor
+ * @method getActorType
+ * @return {String} Actor, ImageActor, TextActor, MeshActor, Layer, CameraActor ...
+ */
+void ActorApi::GetActorType( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Actor actor = GetActor( isolate, args );
+
+ std::string name = actor.GetTypeName();
+ v8::Local < v8::String > v8String = v8::String::NewFromUtf8( isolate, name.c_str() );
+ args.GetReturnValue().Set( v8String );
+}
+/**
+ * Move an actor relative to its existing position.
+ * @example
+ *
+ * // using an array
+ * actor.moveBy( [20,40,0] );
+ *
+ * @for Actor
+ * @method moveBy
+ * @param {object} an array of 3 numbers
+ */
+void ActorApi::MoveBy( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Actor actor = GetActor( isolate, args );
+
+ //Get displacement vector
+ Vector3 vector;
+ int argCount( args.Length() );
+ if( argCount == 1 )
+ {
+ bool found(false);
+ vector = V8Utils::GetVector3Parameter( PARAMETER_0, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Vector3 move parameter missing" );
+ return;
+ }
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Vector3 move parameter missing" );
+ return;
+ }
+ actor.MoveBy( vector );
+
+}
+
+
+/**
+ * Apply a relative rotation to an actor.
+ * @example
+ *
+ * var rotation =new dali.Rotation( pitch, roll, yaw );
+ * actor.rotateBy( rotation );
+ *
+ * @for Actor
+ * @method rotateBy
+ * @param {object} dali rotation object
+ */
+void ActorApi::RotateBy( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Actor actor = GetActor( isolate, args );
+
+ bool found( false );
+ Property::Value rotation = V8Utils::GetPropertyValueParameter( PARAMETER_0, found, isolate, args );
+
+ if( rotation.GetType() != Property::ROTATION )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Rotation parameter missing" );
+ return;
+ }
+ // the rotation parameter has to be either a AngleAxis or a Quaternion
+ // both will work when calling Get( Quaternion);
+
+ Quaternion quaternionValue;
+ rotation.Get( quaternionValue );
+
+ actor.RotateBy( quaternionValue );
+}
+
+/**
+ * Apply a relative scale to an actor.
+ * @example
+ * // Double actor width and height ( keep depth the same )
+ * // using an array
+ * actor.scaleBy( [2,2,1] );
+ *
+ *
+ * @for Actor
+ * @method scaleBy
+ * @param {object} JavaScript array
+ */
+void ActorApi::ScaleBy( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Actor actor = GetActor( isolate, args );
+
+ Vector3 vector;
+ int argCount( args.Length() );
+ if( argCount == 1 )
+ {
+ bool found(false);
+ vector = V8Utils::GetVector3Parameter( PARAMETER_0, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Vector3 move parameter missing" );
+ return;
+ }
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Vector3 parameter missing" );
+ return;
+ }
+ actor.ScaleBy( vector );
+}
+/**
+ * Apply a relative scale to an actor.
+ * Actor opacity ranges from 0 (see through ) to 1 ( solid )
+ * @example
+ * // reduce actor opactiy by a half
+ * actor.opaictyBy(-0.5);
+ *
+ * @for Actor
+ * @method OpacityBy
+ * @param {float} relative opacity
+ */
+void ActorApi::OpacityBy( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Actor actor = GetActor( isolate, args );
+
+ // void OpacityBy(float relativeOpacity);
+ bool found;
+ float opacity = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 0.f );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "float parameter missing" );
+ return;
+ }
+ actor.OpacityBy( opacity );
+}
+
+/**
+ * Apply a relative color change to an actor.
+ *
+ * @example
+ * // increase actor red by half
+ * actor.colorBy( [0.5, 0, 0, 0]);
+ *
+ *
+ * @for Actor
+ * @method colorBy
+ * @param {Object} Color JavaScript array
+ */
+void ActorApi::ColorBy( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Actor actor = GetActor( isolate, args );
+
+ bool found;
+ int argCount( args.Length() );
+ Vector4 color;
+
+ if( argCount == 1 )
+ {
+ color = V8Utils::GetVector4Parameter( PARAMETER_0, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Vector4 parameter missing" );
+ return;
+ }
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Vector4 parameter missing" );
+ return;
+ }
+
+ actor.ColorBy( color );
+}
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_ACTOR_API_H__
+#define __DALI_V8PLUGIN_ACTOR_API_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/public-api/actors/actor.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace TextViewApi
+{
+ /**
+ * Temporary TextView constructor
+ */
+ Actor New( const v8::FunctionCallbackInfo< v8::Value >& args );
+}
+
+namespace ActorApi
+{
+
+ /**
+ * constructor
+ */
+ Actor New( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ /**
+ * Actor API. See actor.h for description of functions
+ */
+ void IsRoot( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetId( const v8::FunctionCallbackInfo< v8::Value >& args);
+ void OnStage( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void IsLayer( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetLayer( const v8::FunctionCallbackInfo< v8::Value >& args);
+ void AddActor( const v8::FunctionCallbackInfo< v8::Value >& args);
+ void RemoveActor( const v8::FunctionCallbackInfo< v8::Value >& args);
+ void IsEqualTo( const v8::FunctionCallbackInfo<v8::Value>& args );
+ void Unparent( const v8::FunctionCallbackInfo< v8::Value >& args);
+ void GetChildAt( const v8::FunctionCallbackInfo< v8::Value >& args);
+ void FindChildByName( const v8::FunctionCallbackInfo< v8::Value >& args);
+ void FindChildByAlias( const v8::FunctionCallbackInfo< v8::Value >& args);
+ void FindChildById( const v8::FunctionCallbackInfo< v8::Value >& args);
+ void GetParent( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetChildCount( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void ScreenToLocal( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetKeyboardFocusable( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void IsKeyboardFocusable( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void MoveBy( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void RotateBy( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void ScaleBy( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void OpacityBy( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void ColorBy( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ // new function just for JavaScript API, to help developers know what type of actor
+ // they're dealing with, returns actor name as a string
+ void GetActorType( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+
+}; // namespace ActorApi
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header __DALI_V8PLUGIN_ACTOR_API_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "actor-wrapper.h"
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/object/type-registry.h>
+
+// INTERNAL INCLUDES
+#include <actors/layer-api.h>
+#include <actors/actor-api.h>
+#include <actors/image-actor-api.h>
+#include <actors/text-actor-api.h>
+#include <actors/mesh-actor-api.h>
+#include <actors/camera-actor-api.h>
+#include <actors/renderable-actor-api.h>
+#include <v8-utils.h>
+#include <dali-wrapper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+v8::Persistent<v8::ObjectTemplate> ActorWrapper::mActorTemplate;
+v8::Persistent<v8::ObjectTemplate> ActorWrapper::mImageActorTemplate;
+v8::Persistent<v8::ObjectTemplate> ActorWrapper::mTextActorTemplate;
+v8::Persistent<v8::ObjectTemplate> ActorWrapper::mMeshActorTemplate;
+v8::Persistent<v8::ObjectTemplate> ActorWrapper::mCameraActorTemplate;
+v8::Persistent<v8::ObjectTemplate> ActorWrapper::mLayerActorTemplate;
+v8::Persistent<v8::ObjectTemplate> ActorWrapper::mTextViewTemplate;
+
+namespace
+{
+
+
+/**
+ * pointer to a persistent template handle
+ */
+struct ActorTemplate
+{
+ v8::Persistent<v8::ObjectTemplate>* actorTemplate;
+};
+
+/**
+ * array of templates for each type of actor
+ */
+const ActorTemplate ActorTemplateLookup[]=
+{
+ { &ActorWrapper::mActorTemplate }, // ACTOR
+ { &ActorWrapper::mImageActorTemplate }, // IMAGE_ACTOR
+ { &ActorWrapper::mTextActorTemplate }, // TEXT_ACTOR
+ { &ActorWrapper::mMeshActorTemplate }, // MESH_ACTOR
+ { &ActorWrapper::mLayerActorTemplate }, // LAYER_ACTOR
+ { &ActorWrapper::mCameraActorTemplate}, // CAMERA_ACTOR
+ { &ActorWrapper::mTextViewTemplate }
+};
+
+/**
+ * Bitmask of API's that an actor can support
+ */
+enum ActorApiBitMask
+{
+ ACTOR_API = 1 << 0,
+ RENDERABLE_ACTOR_API = 1 << 1,
+ IMAGE_ACTOR_API = 1 << 2,
+ TEXT_ACTOR_API = 1 << 3,
+ MESH_ACTOR_API = 1 << 4,
+ LAYER_API = 1 << 5,
+ CAMERA_ACTOR_API = 1 << 6,
+};
+
+/**
+ * structure used for the ActorApiLookup.
+ */
+struct ActorApiStruct
+{
+ const char* actorName;
+ ActorWrapper::ActorType actorType;
+ Actor (*constructor)( const v8::FunctionCallbackInfo< v8::Value >& args);
+ int supportApis;
+};
+
+/**
+ * Lookup table to match a actor type with a constructor and supported API's.
+ */
+const ActorApiStruct ActorApiLookup[]=
+{
+ {"Actor", ActorWrapper::ACTOR, ActorApi::New, ACTOR_API },
+ {"ImageActor", ActorWrapper::IMAGE_ACTOR, ImageActorApi::New, ACTOR_API | RENDERABLE_ACTOR_API | IMAGE_ACTOR_API },
+ {"TextActor", ActorWrapper::TEXT_ACTOR, TextActorApi::New, ACTOR_API | RENDERABLE_ACTOR_API | TEXT_ACTOR_API },
+ {"MeshActor", ActorWrapper::MESH_ACTOR, MeshActorApi::New, ACTOR_API | RENDERABLE_ACTOR_API | MESH_ACTOR_API },
+ {"Layer", ActorWrapper::LAYER_ACTOR, LayerApi::New, ACTOR_API | LAYER_API },
+ {"CameraActor",ActorWrapper::CAMERA_ACTOR, CameraActorApi::New, ACTOR_API | CAMERA_ACTOR_API },
+ {"TextView", ActorWrapper::TEXT_VIEW, TextViewApi::New, ACTOR_API },
+
+};
+
+const unsigned int ActorApiLookupCount = sizeof(ActorApiLookup)/sizeof(ActorApiLookup[0]);
+
+
+
+/**
+ * Creates an actor given a type name
+ * Uses the type registry to create an actor of the correct type
+ */
+Actor CreateActor( const v8::FunctionCallbackInfo< v8::Value >& args,
+ const std::string& typeName )
+{
+ Actor actor;
+
+ ActorWrapper::ActorType actorType = ActorWrapper::GetActorType( typeName );
+
+ // if we don't currently support the actor type, then use type registry to create it
+ if( actorType == ActorWrapper::UNKNOWN_ACTOR )
+ {
+ Dali::TypeInfo typeInfo = Dali::TypeRegistry::Get().GetTypeInfo( typeName );
+ if( typeInfo ) // handle, check if it has a value
+ {
+ Dali::BaseHandle handle = typeInfo.CreateInstance();
+ if( handle )
+ {
+ actor = Actor::DownCast( handle );
+ }
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION(args.GetIsolate(),"Unknown actor type");
+ return Actor();
+ }
+ }
+ else
+ {
+ // run the constructor for this type of actor so it can pull out
+ // custom parameters, e.g. new TextActor("hello world"); or ImageActor( MyImage );
+ actor = (ActorApiLookup[actorType].constructor)( args );
+ }
+ return actor;
+}
+
+
+
+/**
+ * given an actor type return what api's it supports
+ */
+int GetActorSupportedApis( ActorWrapper::ActorType type )
+{
+ return ActorApiLookup[ type].supportApis;
+}
+
+/**
+ * Used for the ActorFunctionTable to map function names to functions
+ * with for a specific API
+ */
+struct ActorFunctions
+{
+ const char* name; ///< function name
+ void (*function)( const v8::FunctionCallbackInfo< v8::Value >& args);
+ ActorApiBitMask api;
+};
+
+/**
+ * Contains a list of all functions that can be called an
+ * actor / image-actor / mesh-actor/ layer / camera-actor
+ */
+const ActorFunctions ActorFunctionTable[]=
+{
+ /**************************************
+ * Actor API (in order of actor.h)
+ * Any properties that have accessor functions are ignored to avoid duplication
+ **************************************/
+ // ignore. GetName() use Actor.name
+ // ignore. SetName() use Actor.name
+ { "GetId", ActorApi::GetId, ACTOR_API },
+ { "IsRoot", ActorApi::IsRoot, ACTOR_API },
+ { "OnStage", ActorApi::OnStage, ACTOR_API },
+ { "IsLayer", ActorApi::IsLayer, ACTOR_API },
+ { "GetLayer", ActorApi::GetLayer, ACTOR_API },
+ { "Add", ActorApi::AddActor, ACTOR_API },
+ { "Remove", ActorApi::RemoveActor, ACTOR_API },
+ { "IsEqualTo" , ActorApi::IsEqualTo, ACTOR_API },
+ { "Unparent", ActorApi::Unparent, ACTOR_API },
+ { "GetChildCount", ActorApi::GetChildCount, ACTOR_API },
+ { "GetChildAt" , ActorApi::GetChildAt, ACTOR_API },
+ { "FindChildByName", ActorApi::FindChildByName, ACTOR_API },
+ { "FindChildByAlias", ActorApi::FindChildByAlias, ACTOR_API },
+ { "FindChildById", ActorApi::FindChildById, ACTOR_API },
+ { "GetParent" , ActorApi::GetParent, ACTOR_API },
+ { "GetActorType" , ActorApi::GetActorType, ACTOR_API }, // custom for javascript
+
+ // ignore. SetParentOrigin() use Actor.parentOrigin
+ // ignore. GetCurrentParentOrigin() use Actor.parentOrigin
+ // ignore. SetAnchorPoint() use Actor.anchorPoint
+ // ignore. GetCurrentAnchorPoint() use Actor.anchorPoint
+ // ignore. SetSize() use Actor.size
+ // ignore. GetCurrentSize() use Actor.size
+ // ignore. SetPosition(....) use Actor.position
+ // ignore. SetX, SetY, SetZ, use Actor.position.x, Actor.position.y, Actor.position.z
+ { "MoveBy", ActorApi::MoveBy, ACTOR_API },
+ // ignore GetCurrentPosition(). use Actor.position
+ // ignore GetCurrentWorldPosition() use Actor.worldPosition
+ // ignore SetPositionInheritanceMode() use Actor.positionInheritance
+ // ignore GetPositionInheritanceMode() use Actor.positionInheritance
+ // ignore SetRotation() use Actor.rotation
+ { "RotateBy", ActorApi::RotateBy, ACTOR_API },
+ // ignore GetCurrentRotation() use Actor.rotation
+ // ignore SetInheritRotation() use Actor.inheritRotation
+ // ignore IsRotationInherited() use Actor.inheritRotation
+ // ignore GetCurrentWorldRotation() use Actor.worldRotation
+ // ignore SetScale() use Actor.scale
+ { "ScaleBy", ActorApi::ScaleBy, ACTOR_API },
+ // ignore GetCurrentScale() use Actor.scale
+ // ignore GetCurrentWorldScale() use Actor.worldScale
+ // ignore SetInheritScale() use Actor.inheritScale
+ // ignore IsScaleInherited() use Actor.inheritScale
+ // ignore GetCurrentWorldMatrix() use Actor.worldMatrix
+ // ignore SetVisible() use Actor.visible
+ // ignore IsVisible() use Actor.visible
+ // ignore SetOpacity() use Actor.opacity
+ { "OpactiyBy", ActorApi::OpacityBy, ACTOR_API },
+ // ignore GetCurrentOpacity() use Actor.opacity
+ // ignore SetColor() use Actor.color
+ { "ColorBy", ActorApi::ColorBy, ACTOR_API },
+ // ignore GetCurrentColor() use Actor.color
+ // ignore SetColorMode() use Actor.colorMode
+ // ignore GetColorMode() use Actor.colorMode
+ // ignore GetCurrentWorldColor() use Actor.worldColor
+ // ignore SetInheritShaderEffect() use Actor.inheritShaderEffect
+ // ignore GetInheritShaderEffect() use Actor.inheritShaderEffect
+ // ignore SetDrawMode() use Actor.drawMode
+ // ignore GetDrawMode() use Actor.drawMode
+ // ignore SetSensitive() use Actor.sensitve
+ // ignore IsSensitive() use Actor.sensitive
+ { "ScreenToLocal" , ActorApi::ScreenToLocal, ACTOR_API},
+ // ignore SetLeaveRequired() use Actor.leaveRequired
+ // ignore GetLeaveRequired() use Actor.leaveRequired
+ { "SetKeyboardFocusable", ActorApi::SetKeyboardFocusable, ACTOR_API }, //-- should this be a property???
+ { "IsKeyboardFocusable" , ActorApi::IsKeyboardFocusable, ACTOR_API }, //-- should this be a property???
+
+ /**************************************
+ * Renderable Actor API (in order of renderable-actor.h)
+ **************************************/
+ { "SetSortModifier", RenderableActorApi::SetSortModifier, RENDERABLE_ACTOR_API },
+ { "GetSortModifier", RenderableActorApi::GetSortModifier, RENDERABLE_ACTOR_API },
+ { "SetCullFace", RenderableActorApi::SetCullFace, RENDERABLE_ACTOR_API },
+ { "GetCullFace", RenderableActorApi::GetCullFace, RENDERABLE_ACTOR_API },
+ { "SetBlendMode", RenderableActorApi::SetBlendMode, RENDERABLE_ACTOR_API },
+ { "GetBlendMode", RenderableActorApi::GetBlendMode, RENDERABLE_ACTOR_API },
+ { "SetBlendFunc", RenderableActorApi::SetBlendFunc, RENDERABLE_ACTOR_API },
+ { "GetBlendFunc", RenderableActorApi::GetBlendFunc, RENDERABLE_ACTOR_API },
+ { "SetBlendEquation", RenderableActorApi::SetBlendEquation, RENDERABLE_ACTOR_API },
+ { "GetBlendEquation", RenderableActorApi::GetBlendEquation, RENDERABLE_ACTOR_API },
+ { "SetBlendColor", RenderableActorApi::SetBlendColor, RENDERABLE_ACTOR_API },
+ { "GetBlendColor", RenderableActorApi::GetBlendColor, RENDERABLE_ACTOR_API },
+ { "SetShaderEffect", RenderableActorApi::SetShaderEffect, RENDERABLE_ACTOR_API },
+ { "GetShaderEffect", RenderableActorApi::GetShaderEffect, RENDERABLE_ACTOR_API },
+ { "RemoveShaderEffect", RenderableActorApi::RemoveShaderEffect,RENDERABLE_ACTOR_API },
+
+
+
+
+ /**************************************
+ * Layer API (in order of layer.h)
+ **************************************/
+ { "GetDepth", LayerApi::GetDepth, LAYER_API },
+ { "Raise", LayerApi::Raise, LAYER_API },
+ { "Lower", LayerApi::Lower, LAYER_API },
+ { "RaiseAbove", LayerApi::RaiseAbove, LAYER_API },
+ { "RaiseBelow", LayerApi::LowerBelow, LAYER_API },
+ { "RaiseToTop", LayerApi::RaiseToTop, LAYER_API },
+ { "LowerToBottom", LayerApi::ToBottom, LAYER_API },
+ { "MoveAbove", LayerApi::MoveAbove, LAYER_API },
+ { "MoveBelow", LayerApi::MoveBelow, LAYER_API },
+ // ignore SetClipping, use layer.clippingEnable
+ // ignore IsClipping, use layer.clippingEnable
+ // ignore SetClippingBox, use layer.clippingBox
+ { "SetDepthTestDisabled", LayerApi::SetDepthTestDisabled, LAYER_API },
+ { "IsDepthTestDisabled", LayerApi::IsDepthTestDisabled, LAYER_API },
+ // @todo SetSortFunction
+
+ /**************************************
+ * Image Actor API (in order of image-actor.h)
+ **************************************/
+
+ { "SetImage", ImageActorApi::SetImage, IMAGE_ACTOR_API },
+ { "GetImage", ImageActorApi::GetImage, IMAGE_ACTOR_API },
+ { "SetToNaturalSize", ImageActorApi::SetToNaturalSize, IMAGE_ACTOR_API },
+ // ignore SetPixelArea, use imageActor.pixelArea
+ // ignore GetPixelArea, use imageActor.pixelArea
+ { "IsPixelAreaSet", ImageActorApi::IsPixelAreaSet, IMAGE_ACTOR_API },
+ { "ClearPixelArea", ImageActorApi::ClearPixelArea, IMAGE_ACTOR_API },
+ // ignore SetStyle, use imageActor.style
+ // ignore GetStyle, use imageActor.style
+ // ignore SetNinePatchBorder use imageActor.border
+ // ignore GetNinePatchBorder use imageActor.border
+ // ignore SetFadeIn use imageActor.fadeIn
+ // ignore GetFadeIn use imageActor.fadeIn
+ // ignore SetFadeInDuration use imageActor.fadeInDuration
+ // ignore GetFadeInDuration use imageActor.fadeInDuration
+ //{ "GetCurrentImageSize", ImageActorApi::GetCurrentImageSize, IMAGE_ACTOR_API },
+
+
+ /**************************************
+ * Text Actor API (in order of text-actor.h)
+ **************************************/
+ //ignore SetText use textActor.text
+ { "SetToNaturalSize", TextActorApi::SetToNaturalSize, TEXT_ACTOR_API },
+ // ignore GetFont use textActor.font
+ // ignore SetFont use textActor.font
+ // ignore SetGradient use textActor.gradientColor
+ // ignore GetGradient textActor.gradientColor
+ // ignore SetGradientStartPoint use textActor.gradientStartPoint
+ // ignore GetGradientStartPoint textActor.gradientStartPoint
+ // ignore SetGradientEndPoint use textActor.gradientEndPoint
+ // ignore GetGradientEndPoint textActor.gradientEndPoint
+ // @todo? SetTextStyle ( can use individual properties as a work around )
+ // @todo? GetTextStyle ( can use individual properties as a work around )
+ // ignore SetTextColor use textActor.textColor
+ // ignore GetTextColor use textActor.textColor
+ // ignore SetSmoothEdge use textActor.smoothEdge
+ // ignore SetOutline use textActor.outLineEnable, outlineColor, thicknessWidth
+ // ignore SetGlow use textActor.glowEnable, glowColor, glowIntensity
+ // ignore SetShadow use textActor.shadowEnable, shadowColor, shadowOffset, shadowSize
+ // ignore SetItalics use textActor.italicsAngle ?
+ // ignore GetItalics @todo add italics flag? or just stick with angle
+ // ignore GetItalicsAngle use textActor.italicsAngle
+ // ignore SetUnderline use textActor.underline
+ // ignore GetUnderline use textActor.underline
+ // ignore SetWeight use textActor.weight
+ // ignore GetWeight use textActor.weight
+ // ignore SetFontDetectionAutomatic use textActor.fontDetectionAutomatic
+ // ignore IsFontDetectionAutomatic use textActor.fontDetectionAutomatic
+ // ignore GetLoadingState text is loaded synchronously
+ // ignore TextAvailableSignal text is loaded synchronously
+
+ /**************************************
+ * Mesh Actor API (in order of mesh-actor.h)
+ **************************************/
+ // @todo a version of MeshActor::New( mesh )
+ // @todo a version of MeshActor::New( AnimatableMesh )
+ // @todo SetMaterial
+ // @todo GetMaterial
+ // SetAffectedByLighting should be a property really
+ { "SetAffectedByLighting", MeshActorApi::SetAffectedByLighting, MESH_ACTOR_API },
+ { "IsAffectedByLighting", MeshActorApi::IsAffectedByLighting, MESH_ACTOR_API },
+ // @todo BindBonesToMesh
+
+ /**************************************
+ * Camera Actor API (in order of camera.h)
+ **************************************/
+ // ignore SetType use camera.type
+ // ignore GetType use camera.type
+ // ignore SetProjectionMode use camera.projectionMode
+ // ignore GetProjectionMode use camera.projectionMode
+ // ignore SetFieldOfView use camera.fieldOfView
+ // ignore GetFieldOfView use camera.fieldOfView
+ // ignore SetAspectRatio use camera.aspectRatio
+ // ignore GetAspectRatio use camera.aspectRatio
+ // ignore SetNearClippingPlane use camera.nearPlaneDistance
+ // ignore GetNearClippingPlane use camera.nearPlaneDistance
+ // ignore SetFarClippingPlane use camera.farPlaneDistance
+ // ignore GetFarClippingPlane use camera.farPlaneDistance
+ // ignore GetTargetPosition use camera.targetPosition
+ // ignore SetInvertYAxis use camera.invertYAxis
+ // ignore GetInvertYAxis use camera.invertYAxis
+ { "SetPerspectiveProjection", CameraActorApi::SetPerspectiveProjection, CAMERA_ACTOR_API },
+ { "SetOrthographicProjection", CameraActorApi::SetOrthographicProjection, CAMERA_ACTOR_API },
+
+};
+
+const unsigned int ActorFunctionTableCount = sizeof(ActorFunctionTable)/sizeof(ActorFunctionTable[0]);
+} //un-named space
+
+
+ActorWrapper::ActorWrapper( Actor actor,
+ GarbageCollectorInterface& gc )
+: HandleWrapper( BaseWrappedObject::ACTOR , actor, gc ),
+ mActor( actor )
+
+{
+}
+
+v8::Handle<v8::Object> ActorWrapper::WrapActor(v8::Isolate* isolate, Actor actor )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::Object> object = WrapActor( isolate, actor, GetActorType( actor.GetTypeName() ) );
+
+ return handleScope.Escape( object );
+}
+
+Actor ActorWrapper::GetActor()
+{
+ return mActor;
+}
+
+v8::Handle<v8::Object> ActorWrapper::WrapActor( v8::Isolate* isolate, Actor actor, ActorType actorType )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::ObjectTemplate> objectTemplate;
+
+ objectTemplate = GetActorTemplate( isolate, actorType );
+
+ // create an instance of the template
+ v8::Local<v8::Object> localObject = objectTemplate->NewInstance();
+
+ // create teh actor object
+ ActorWrapper* pointer = new ActorWrapper( actor, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() );
+
+ // assign the JavaScript object to the wrapper.
+ // This also stores Dali object, in an internal field inside the JavaScript object.
+ pointer->SetJavascriptObject( isolate, localObject );
+
+ return handleScope.Escape( localObject );
+}
+
+v8::Local<v8::ObjectTemplate> ActorWrapper::GetActorTemplate( v8::Isolate* isolate, ActorWrapper::ActorType type )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::ObjectTemplate> objectTemplate;
+
+ if( ActorTemplateLookup[type].actorTemplate->IsEmpty() )
+ {
+ objectTemplate = MakeDaliActorTemplate( isolate, type );
+ ActorTemplateLookup[type].actorTemplate->Reset( isolate, objectTemplate );
+ }
+ else
+ {
+ // get the object template
+ objectTemplate = v8::Local<v8::ObjectTemplate>::New( isolate, *ActorTemplateLookup[type].actorTemplate );
+ }
+
+ return handleScope.Escape( objectTemplate );
+}
+
+v8::Handle<v8::ObjectTemplate> ActorWrapper::MakeDaliActorTemplate( v8::Isolate* isolate, ActorType actorType )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+
+ v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
+
+ objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT );
+
+ // find out what API's this actor supports
+ int supportApis = GetActorSupportedApis( actorType );
+
+ // add our function properties
+ for( unsigned int i = 0; i < ActorFunctionTableCount; ++i )
+ {
+ const ActorFunctions property = ActorFunctionTable[i];
+
+ // check to see if the actor supports a certain type of API
+ // e.g. ImageActor will support ACTOR_API, RENDERABLE_API and IMAGE_ACTOR_API
+ if( supportApis & property.api )
+ {
+ std::string funcName = V8Utils::GetJavaScriptFunctionName( property.name);
+
+ objTemplate->Set( v8::String::NewFromUtf8( isolate, funcName.c_str() ),
+ v8::FunctionTemplate::New( isolate, property.function ) );
+ }
+ }
+
+ // property handle intercepts property getters and setters and signals
+ HandleWrapper::AddInterceptsToTemplate( isolate, objTemplate );
+
+
+ return handleScope.Escape( objTemplate );
+}
+
+void ActorWrapper::NewActor( const v8::FunctionCallbackInfo< v8::Value >& args)
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ if( !args.IsConstructCall() )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "constructor called without 'new" );
+ return;
+ }
+
+ // find out the callee function name...e.g. TextActor, ImageActor, MeshActor
+ v8::Local<v8::Function> callee = args.Callee();
+ v8::Local<v8::Value> v8String = callee->GetName();
+ std::string typeName = V8Utils::v8StringToStdString( v8String );
+
+ // create a new actor based on type, using the type registry.
+ Actor actor = CreateActor( args, typeName );
+
+ v8::Local<v8::Object> localObject = WrapActor( isolate, actor );
+
+ args.GetReturnValue().Set( localObject );
+}
+
+/**
+ * given an actor type name, e.g. ImageActor returns the type, e.g. ActorWrapper::IMAGE_ACTOR
+ */
+ActorWrapper::ActorType ActorWrapper::GetActorType( const std::string& name )
+{
+ for( unsigned int i = 0 ; i < ActorApiLookupCount ; i++ )
+ {
+ if( ActorApiLookup[i].actorName == name )
+ {
+ return ActorApiLookup[i].actorType;
+ }
+ }
+ return ActorWrapper::UNKNOWN_ACTOR;
+}
+
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_ACTOR_WRAPPER_H__
+#define __DALI_V8PLUGIN_ACTOR_WRAPPER_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/public-api/actors/actor.h>
+
+// INTERNAL INCLUDES
+#include <object/handle-wrapper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+
+/**
+ * Wraps a Dali Actor.
+ */
+class ActorWrapper : public HandleWrapper
+{
+
+public:
+
+ /**
+ * Actor type used an index
+ */
+ enum ActorType
+ {
+ UNKNOWN_ACTOR = -1,
+ ACTOR = 0,
+ IMAGE_ACTOR =1,
+ TEXT_ACTOR =2,
+ MESH_ACTOR =3,
+ LAYER_ACTOR =4,
+ CAMERA_ACTOR =5,
+ LIGHT_ACTOR =6,
+ TEXT_VIEW =7
+ };
+
+ /**
+ * Constructor
+ * @param actor DALi actor
+ * @param gc garbage collection interface
+ */
+ ActorWrapper( Actor actor,
+ GarbageCollectorInterface& gc );
+
+ /**
+ * destructor
+ */
+ virtual ~ActorWrapper()
+ {
+ }
+
+ /**
+ * @brief Creates a new Actor wrapped inside a Javascript Object.
+ * @note: the actor type ie 'ImageActor' is expected to be the name of the callee function.
+ * @param[in] args v8 function call arguments interpreted
+ */
+ static void NewActor( const v8::FunctionCallbackInfo< v8::Value >& args);
+
+ /**
+ * @brief Wraps an actor of a given type
+ */
+ static v8::Handle<v8::Object> WrapActor(v8::Isolate* isolate, Dali::Actor actor,ActorType actorType);
+
+ /**
+ * @brief Wraps an actor, the type is looked up from the actor
+ */
+ static v8::Handle<v8::Object> WrapActor(v8::Isolate* isolate, Dali::Actor actor );
+
+ // The Actor ObjectTemplates.
+ static v8::Persistent<v8::ObjectTemplate> mActorTemplate;
+ static v8::Persistent<v8::ObjectTemplate> mImageActorTemplate;
+ static v8::Persistent<v8::ObjectTemplate> mTextActorTemplate;
+ static v8::Persistent<v8::ObjectTemplate> mMeshActorTemplate;
+ static v8::Persistent<v8::ObjectTemplate> mCameraActorTemplate;
+ static v8::Persistent<v8::ObjectTemplate> mLayerActorTemplate;
+ static v8::Persistent<v8::ObjectTemplate> mTextViewTemplate;
+
+ /**
+ * @return the wrapped actor
+ */
+ Actor GetActor();
+
+ /**
+ * @return they actor type
+ */
+ static ActorWrapper::ActorType GetActorType( const std::string& name );
+
+private:
+
+ /**
+ * Helper to make the actor template
+ *
+ */
+ static v8::Handle<v8::ObjectTemplate> MakeDaliActorTemplate( v8::Isolate* isolate, ActorType actorType );
+
+ /**
+ * Helper, get an actor template given an actor type
+ */
+ static v8::Local<v8::ObjectTemplate> GetActorTemplate( v8::Isolate* isolate, ActorType type );
+
+ Actor mActor;
+
+};
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "camera-actor-api.h"
+
+// INTERNAL INCLUDES
+#include <object/handle-wrapper.h>
+#include <v8-utils.h>
+#include <shared/base-wrapped-object.h>
+#include <object/property-value-wrapper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace // un-named namespace
+{
+
+CameraActor GetCameraActor( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ HandleWrapper* handleWrapper = HandleWrapper::Unwrap( isolate, args.This() );
+ return CameraActor::DownCast( handleWrapper->mHandle );
+}
+
+} // un-named name space
+
+/***************************************
+ * CAMERA ACTOR FUNCTIONS
+ ****************************************/
+/**
+ * Constructor
+ *
+ * @constructor
+ * @method CameraActor
+ * @for CameraActor
+ * @return {Object} CameraActor
+ */
+Actor CameraActorApi::New( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ return CameraActor::New();
+}
+
+/**
+ *
+ * Sets the default camera perspective projection for the given canvas size.
+ *
+ * Sets the near and far clipping planes, the field of view, the aspect ratio
+ * and the Z position of the actor based on the canvas size so that 1 unit in
+ * XY (z=0) plane is 1 pixel on screen.
+ *
+ * If the canvas size is ZERO, it sets the default camera perspective
+ * projection for the stage's size.
+ *
+ * If size is non ZERO, \e width and \e height must be greater than zero.
+ *
+ *
+ * @example
+ * var camera = dali.stage.getRenderTaskList().getTask(0).getCameraActor();
+ *
+ * camera.setPerspectiveProjection( [100, 150] );
+ *
+ *
+ * @for CameraActor
+ * @method setPerspectiveProjection
+ * @param {Object} The canvas size, array of 2 numbers
+ */
+void CameraActorApi::SetPerspectiveProjection( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ CameraActor cameraActor = GetCameraActor( isolate, args );
+
+ bool found;
+ Vector2 size = V8Utils::GetVector2Parameter( PARAMETER_0, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
+ return;
+ }
+ cameraActor.SetPerspectiveProjection( size );
+}
+
+/**
+ *
+ * Sets the camera projection to use orthographic projection.
+ *
+ * The XY plane is centered on the camera axis. The units in the X/Y
+ * plane directly equate to pixels on an equivalently sized
+ * framebuffer.
+ *
+ * The Z position of the actor, and the near and far clip planes of the
+ * bounding box match those that would be created by using
+ * SetPerspectiveProjection with the same size.
+ *
+ *
+ * @example
+ * var camera = dali.stage.getRenderTaskList().getTask(0).getCameraActor();
+ * camera.setOrthographicProjection( [1920, 1080] );
+ *
+ * @for CameraActor
+ * @method setOrthographicProjection
+ * @param {Object} Size Size of XY plane (normal to camera axis)
+ */
+void CameraActorApi::SetOrthographicProjection( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ CameraActor cameraActor = GetCameraActor( isolate, args );
+
+ bool found;
+ Vector2 size = V8Utils::GetVector2Parameter( PARAMETER_0, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
+ return;
+ }
+ cameraActor.SetOrthographicProjection( size );
+}
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_CAMERA_ACTOR_API_H__
+#define __DALI_V8PLUGIN_CAMERA_ACTOR_API_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/public-api/actors/camera-actor.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace CameraActorApi
+{
+ /**
+ * constructor
+ */
+ Actor New( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+
+ /**
+ * Camera API see DALI camera.h
+ */
+ void SetPerspectiveProjection( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetOrthographicProjection( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+}; // namespace CameraActorApi
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header __DALI_V8PLUGIN_CAMERA_ACTOR_API_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "image-actor-api.h"
+
+// INTERNAL INCLUDES
+#include <object/handle-wrapper.h>
+#include <v8-utils.h>
+#include <object/property-value-wrapper.h>
+#include <image/image-api.h>
+#include <image/image-wrapper.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace //unnamed name space
+{
+
+ImageActor GetImageActor( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ HandleWrapper* handleWrapper = HandleWrapper::Unwrap( isolate, args.This() );
+ return ImageActor::DownCast( handleWrapper->mHandle );
+}
+
+} //unnamed name space
+
+/**
+ * Constructor
+ *
+ * @constructor
+ * @method ImageActor
+ * @for ImageActor
+ * @param {Object} [image] Image object
+ * @param {Object} [pixelArea] Vector4
+ * @return {Object} ImageActor
+ * @example
+ * new DALI.imageActor( image, [10,23,35,56] );
+ */
+Actor ImageActorApi::New( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ // Image actor has 3 different constructors
+ // New();
+ // New( image);
+ // New( image, PixelArea pixelArea);
+
+ if( args.Length() == 0 )
+ {
+ return ImageActor::New();
+ }
+
+ // args.Length> 0, must have an Image parameter
+ bool found( false );
+ Image image = V8Utils::GetImageParameter( PARAMETER_0, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing image from param 0" );
+ return ImageActor();
+ }
+
+ // check for PixelArea, accept a DALI Vector4 object ( which can be a JavaScript array)
+ // e.g. new DALI.imageActor( image, [10,23,35,56] );
+ // or new DALI.imageActor( image, Vector4 );
+
+ if( args.Length() > 1 )
+ {
+ Vector4 rect = V8Utils::GetVector4Parameter( PARAMETER_1, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, " bad parameters" );
+ return ImageActor();
+ }
+ Rect<int>rectangle( static_cast<int>(rect.x),
+ static_cast<int>(rect.y),
+ static_cast<int>(rect.z),
+ static_cast<int>(rect.w));
+
+ return ImageActor::New( image, rectangle );
+ }
+ else
+ {
+ return ImageActor::New( image );
+ }
+}
+
+/**
+ * Set the image rendered by the actor.
+ *
+ * When the image is loaded the actor's size will be reset to the image size,
+ * unless a custom size was chosen, e.g. via actor.size or a pixel area
+ * was set.
+ * Note: The old image will continue to be displayed until the given image has loaded.
+ * @for ImageActor
+ * @method setImage
+ * @param {Object} image The image to display.
+ *
+ */
+void ImageActorApi::SetImage( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ bool found( false );
+ Image image = V8Utils::GetImageParameter( PARAMETER_0, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "bad parameters" );
+ return;
+ }
+ ImageActor imageActor = GetImageActor( isolate, args );
+ imageActor.SetImage( image );
+}
+
+/**
+ * brief Retrieve the image rendered by the actor's attachment.
+ * @for ImageActor
+ * @method getImage
+ * @return {Object} the image.
+ */
+void ImageActorApi::GetImage( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ ImageActor imageActor = GetImageActor( isolate, args );
+ Image image = imageActor.GetImage();
+
+ // wrap the image
+ v8::Local<v8::Object> localObject = ImageWrapper::WrapImage( isolate, image );
+ args.GetReturnValue().Set( localObject );
+}
+
+/**
+ * Tell the image actor to use the natural size of the current image
+ * or future images.
+ *
+ * Calling SetSize on this actor or animating the size of the actor
+ * overrides this behaviour.
+ *
+ * The image actor uses the natural image size after an image
+ * has been loaded.
+ * @for ImageActor
+ * @method setToNaturalSize
+ */
+void ImageActorApi::SetToNaturalSize( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ ImageActor imageActor = GetImageActor( isolate, args );
+
+ imageActor.SetToNaturalSize();
+
+}
+
+/**
+ * Query whether a pixel area has been set.
+ * @for ImageActor
+ * @method isPixelAreaSet
+ * @return {Boolean} True if a pixel area has been set.
+ */
+void ImageActorApi::IsPixelAreaSet( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ ImageActor imageActor = GetImageActor( isolate, args );
+
+ args.GetReturnValue().Set( v8::Boolean::New( isolate, imageActor.IsPixelAreaSet() ) );
+}
+
+/**
+ * Remove any pixel areas specified with SetPixelArea; the entire image will be displayed.
+ *
+ * The actor size will change to that of the Image unless a custom size was set, e.g. via
+ * actor.size
+ * @for ImageActor
+ * @method clearPixelArea
+ */
+void ImageActorApi::ClearPixelArea( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ ImageActor imageActor = GetImageActor( isolate, args );
+
+ imageActor.ClearPixelArea();
+}
+
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_IMAGE_ACTOR_API_H__
+#define __DALI_V8PLUGIN_IMAGE_ACTOR_API_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/public-api/actors/image-actor.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace ImageActorApi
+{
+
+ /**
+ * constructor
+ */
+ Actor New( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ /**
+ * ImageActorApi API see image-actor.h for a description
+ * Most of the API is covered by the property system
+ */
+ void SetImage( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetImage( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetToNaturalSize( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void IsPixelAreaSet( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void ClearPixelArea( const v8::FunctionCallbackInfo< v8::Value >& args );
+}; // namespace ImageActorApi
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header __DALI_V8PLUGIN_IMAGE_ACTOR_API_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "layer-api.h"
+
+// INTERNAL INCLUDES
+#include <object/handle-wrapper.h>
+#include <v8-utils.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace //unnamed name space
+{
+
+Layer GetLayer( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ HandleWrapper* handleWrapper = HandleWrapper::Unwrap( isolate, args.This() );
+ return Layer::DownCast( handleWrapper->mHandle );
+}
+
+} //unnamed name space
+
+/***************************************
+ * LAYER FUNCTIONS
+ *
+ ****************************************/
+/**
+ * Constructor
+ *
+ * @constructor
+ * @method Layer
+ * @for Layer
+ * @return {Object} Layer
+ */
+Actor LayerApi::New( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ return Layer::New();
+}
+
+/**
+ * Query the depth of the layer
+ *
+ * 0 is bottom most layer, higher number is on top
+ * Condition: layer is on the stage
+ * If layer is not added to the stage, returns 0.
+ * @return {Number} the current depth of the layer.
+ */
+void LayerApi::GetDepth( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Layer layer = GetLayer( isolate, args );
+
+ args.GetReturnValue().Set( v8::Integer::New( isolate, layer.GetDepth() ) );
+
+}
+
+/**
+ * Increment the depth of the layer.
+ * Condition: layer is on the stage
+ * @method Raise
+ * @for Layer
+ *
+ */
+void LayerApi::Raise( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Layer layer = GetLayer( isolate, args );
+ layer.Raise();
+}
+
+/**
+ * Decrement the depth of the layer.
+ * Condition: layer is on the stage
+ * @for Layer
+ * @method lower
+ */
+void LayerApi::Lower( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Layer layer = GetLayer( isolate, args );
+ layer.Lower();
+}
+
+/**
+ * Ensures the layers depth is greater than the target layer.
+ *
+ * If the layer already is above target layer its depth is not changed
+ * If the layer was below target, its new depth will be immediately above target
+ * Note! All layers between this layer and target get new depth values
+ * Condition: layer is on the stage
+ * Condition: target layer is on the stage
+ * @for Layer
+ * @method raiseAbove
+ * @param target layer to get above of
+ */
+void LayerApi::RaiseAbove( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Layer layer = GetLayer( isolate, args );
+ bool found(false);
+
+ Layer target = V8Utils::GetLayerParameter( PARAMETER_0, found, isolate, args );
+ if( found )
+ {
+ layer.RaiseAbove( target );
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "layer param not found");
+ }
+}
+
+/**
+ * Ensures the layers depth is less than the target layer.
+ *
+ * If the layer already is below the layer its depth is not changed
+ * If the layer was above target, its new depth will be immediately below target
+ * Note! All layers between this layer and target get new depth values
+ * Conditions: layer is on the stage, target layer is on the stage
+ * @param target layer to get below of
+ * @for Layer
+ * @method lowerBelow
+ */
+void LayerApi::LowerBelow( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Layer layer = GetLayer( isolate, args );
+ bool found( false );
+
+ Layer target = V8Utils::GetLayerParameter( PARAMETER_0, found, isolate, args );
+
+ if( found )
+ {
+ layer.LowerBelow( target );
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "layer param not found");
+ }
+
+}
+
+/**
+ * Raises the layer to the top.
+ * Conditions: layer is on the stage
+ * @for Layer
+ * @method raiseToTop
+ */
+void LayerApi::RaiseToTop( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Layer layer = GetLayer( isolate, args );
+ layer.RaiseToTop();
+}
+
+/**
+ * Lowers the layer to the bottom.
+ * Conditions: layer is on the stage
+ * @for Layer
+ * @method lowerToBottom
+ */
+void LayerApi::ToBottom( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Layer layer = GetLayer( isolate, args );
+ layer.LowerToBottom();
+}
+
+/**
+ * Moves the layer directly above the given layer.
+ *
+ * After the call this layers depth will be immediately above target
+ * Note! All layers between this layer and target get new depth values
+ * Conditions: layer is on the stage, target layer is on the stage
+ * @param target layer to get on top of
+ * @for Layer
+ * @method moveAbove
+ */
+void LayerApi::MoveAbove( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Layer layer = GetLayer( isolate, args );
+ bool found( false );
+
+ Layer target = V8Utils::GetLayerParameter( PARAMETER_0, found, isolate, args );
+ if( found )
+ {
+ layer.MoveAbove( target );
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "layer param not found");
+ }
+}
+
+/**
+ * Moves the layer directly below the given layer.
+ *
+ * After the call this layers depth will be immediately below target
+ * Note! All layers between this layer and target get new depth values
+ * Condition: layer is on the stage
+ * Condition: target layer is on the stage
+ * @param target layer to get below of
+ * @for Layer
+ * @method moveBelow
+ */
+void LayerApi::MoveBelow( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Layer layer = GetLayer( isolate, args );
+ bool found( false );
+
+ Layer target = V8Utils::GetLayerParameter( PARAMETER_0, found, isolate, args );
+
+ if( found )
+ {
+ layer.MoveBelow( target );
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "layer param not found");
+ }
+}
+
+// should really be a property
+/**
+ * Whether to disable the depth test.
+ *
+ * By default a layer enables depth test if there is more than one opaque actor or if there is one opaque actor and one, or more, transparent actors.
+ * However, it's possible to disable the depth test by calling this method.
+ *
+ * @param {Boolean} disable true disables depth test. false sets the default behaviour.
+ * @for Layer
+ * @method setDepthTestDisabled
+ */
+void LayerApi::SetDepthTestDisabled( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Layer layer = GetLayer( isolate, args );
+ bool parameterFound( false );
+ bool depthTest = V8Utils::GetBooleanParameter( PARAMETER_0, parameterFound, isolate, args );
+ if( !parameterFound )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
+ return;
+ }
+ layer.SetDepthTestDisabled( depthTest );
+
+}
+
+/**
+ * Retrieves whether depth test is disabled.
+ *
+ * @return { Boolean} true if depth test is disabled.
+ * @for Layer
+ * @method isDepthTestDisabled
+ */
+void LayerApi::IsDepthTestDisabled( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Layer layer = GetLayer( isolate, args );
+ args.GetReturnValue().Set( v8::Boolean::New( isolate, layer.IsDepthTestDisabled() ) );
+}
+
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_LAYER_API_H__
+#define __DALI_V8PLUGIN_LAYER_API_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/public-api/actors/layer.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace LayerApi
+{
+ /**
+ * Layer constructor
+ */
+ Actor New( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ /**
+ * Layer API see layer.h for a description
+ */
+ void GetDepth( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void Raise( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void Lower( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void RaiseAbove( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void LowerBelow( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void RaiseToTop( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void ToBottom( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void MoveBelow( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void MoveAbove( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetDepthTestDisabled( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void IsDepthTestDisabled( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+
+}; // namespace LayerApi
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header __DALI_V8PLUGIN_LAYER_API_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "mesh-actor-api.h"
+
+// INTERNAL INCLUDES
+#include <object/handle-wrapper.h>
+#include <v8-utils.h>
+
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace //unnamed name space
+{
+
+MeshActor GetMeshActor( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ HandleWrapper* handleWrapper = HandleWrapper::Unwrap( isolate, args.This() );
+ return MeshActor::DownCast( handleWrapper->mHandle );
+}
+
+} //unnamed name space
+
+/***************************************
+ * MESH ACTOR FUNCTIONS
+ ****************************************/
+/**
+ * @constructor
+ * @for MeshActor
+ * @method MeshActor
+ * @return {Object} MeshActor
+ */
+Actor MeshActorApi::New( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ return MeshActor::New();
+}
+/**
+ *
+ * @for MeshActor
+ * @method SetAffectedByLighting
+ * @param {Boolean} true = yes affected by lighting
+ */
+void MeshActorApi::SetAffectedByLighting( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ MeshActor actor = GetMeshActor( isolate, args );
+
+ bool parameterFound( false );
+ bool afftedByLight = V8Utils::GetBooleanParameter( PARAMETER_0, parameterFound, isolate, args );
+ if( !parameterFound )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "bad parameter");
+ return;
+ }
+ actor.SetAffectedByLighting( afftedByLight );
+}
+/**
+ *
+ * @for MeshActor
+ * @method IsAffectedByLighting
+ * @return {Boolean} true = yes affected by lighting
+ */
+void MeshActorApi::IsAffectedByLighting( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ MeshActor actor = GetMeshActor( isolate, args );
+
+ args.GetReturnValue().Set( v8::Boolean::New( isolate, actor.IsAffectedByLighting() ) );
+
+}
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_MESH_ACTOR_API_H__
+#define __DALI_V8PLUGIN_MESH_ACTOR_API_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/public-api/actors/mesh-actor.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace MeshActorApi
+{
+ /**
+ * constructor
+ */
+ Actor New( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ /**
+ * Mesh actor API
+ */
+ void SetAffectedByLighting( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void IsAffectedByLighting( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+
+
+}; // namespace MeshActorApi
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header __DALI_V8PLUGIN_MESH_ACTOR_API_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "renderable-actor-api.h"
+
+// INTERNAL INCLUDES
+#include <object/handle-wrapper.h>
+#include <v8-utils.h>
+#include <object/property-value-wrapper.h>
+#include <shader-effects/shader-effect-api.h>
+#include <shader-effects/shader-effect-wrapper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace //unnamed name space
+{
+RenderableActor GetRenderableActor( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ HandleWrapper* handleWrapper = HandleWrapper::Unwrap( isolate, args.This() );
+ return RenderableActor::DownCast( handleWrapper->mHandle );
+}
+}
+/***************************************
+ * RENDERABLE ACTOR FUNCTIONS
+ *
+ ****************************************/
+/**
+ * Allows modification of an actors position in the depth sort algorithm.
+ *
+ * The offset can be altered for each coplanar actor hence allowing an order of painting.
+ * @param { Number } depthOffset the offset to be given to the actor. Positive values pushing it further back.
+ * @for RenderableActor
+ * @method setSortModifier
+ */
+void RenderableActorApi::SetSortModifier( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderableActor actor = GetRenderableActor( isolate, args );
+
+ bool found( false );
+ float value = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 0.f );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
+ return;
+ }
+ actor.SetSortModifier( value );
+}
+
+/**
+ * Retrieves the offset used to modify an actors position in the depth sort algorithm.
+ * @for RenderableActor
+ * @method getSortModifier .
+ * @return { Number} the offset that has been given to the actor. Positive values pushing it further back
+ */
+void RenderableActorApi::GetSortModifier( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderableActor actor = GetRenderableActor( isolate, args );
+
+ args.GetReturnValue().Set( v8::Number::New( isolate, actor.GetSortModifier() ) );
+
+}
+
+/**
+ * Set the face-culling mode for this actor.
+ * @for RenderableActor
+ * @method setCullFace
+ * @param {Number} cullMode
+ * @example
+ * // cull mode should be one of the following constants
+ * dali.CULL_FACE_DISABLE // Face culling disabled
+ * dali.CULL_FRONT_FACE // Cull front facing polygons
+ * dali.CULL_BACK_FACE // Cull back facing polygons
+ * dali.CULL_FRONT_AND_BACK_FACE // Cull front and back facing polygons
+ * actor.SetCullFace( dali.CULL_FRONT_FACE );
+ */
+void RenderableActorApi::SetCullFace( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderableActor actor = GetRenderableActor( isolate, args );
+
+ bool found( false );
+ int cullMode = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
+ return;
+ }
+
+ actor.SetCullFace( static_cast<Dali::CullFaceMode>( cullMode ) );
+
+}
+
+/**
+ * Retrieve the face-culling mode for this actor.
+ * @for RenderableActor
+ * @method getCullFace
+ * @return {Number} cullMode
+ * @example
+ * // cull mode is one of the following
+ * dali.CULL_FACE_DISABLE // Face culling disabled
+ * dali.CULL_FRONT_FACE // Cull front facing polygons
+ * dali.CULL_BACK_FACE // Cull back facing polygons
+ * dali.CULL_FRONT_AND_BACK_FACE // Cull front and back facing polygon
+ */
+void RenderableActorApi::GetCullFace( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderableActor actor = GetRenderableActor( isolate, args );
+
+ args.GetReturnValue().Set( v8::Integer::New( isolate, actor.GetCullFace() ) );
+
+}
+
+/**
+ * Sets the blending mode.
+ *
+ * If blending is disabled (BLENDING_OFF) fade in and fade out animations do not work.
+ *
+ * @example
+ * // blend mode is one of the following
+ * dali.BLENDING_OFF // Blending is disabled.
+ * dali.BLENDING_AUTO // Blending is enabled if there is alpha channel.
+ * dali.BLENDING_ON // Blending is enabled.
+ * actor.SetBlendMode( dali.BLENDING_AUTO );
+ *
+ * @for RenderableActor
+ * @method setBlendMode
+ * @param { Number } blendMode
+ */
+void RenderableActorApi::SetBlendMode( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderableActor actor = GetRenderableActor( isolate, args );
+
+ bool found( false );
+ int mode = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "invalid BlendMode parameter" );
+ return;
+ }
+ actor.SetBlendMode( static_cast<Dali::BlendingMode::Type>( mode ) );
+
+}
+
+/**
+ * @for RenderableActor
+ * @method getBlendMode
+ * @return { Number } blendMode
+ * @example returns one of the following:
+ *
+ * dali.BLENDING_OFF // Blending is disabled.
+ * dali.BLENDING_AUTO // Blending is enabled if there is alpha channel.
+ * dali.BLENDING_ON // Blending is enabled.
+ *
+ */
+void RenderableActorApi::GetBlendMode( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderableActor actor = GetRenderableActor( isolate, args );
+
+ args.GetReturnValue().Set( v8::Integer::New( isolate, actor.GetBlendMode() ) );
+
+}
+
+// 2 function definitions, as Dali uses 2 functions.
+// JavaScript can't overload but we can document it twice with different params
+/**
+ * @for RenderableActor
+ * @method setBlendFunc
+ * @param {Number} SourceBlending RGBA
+ * @param {Number} DestinationBlending RGBA
+ * @example
+ * blending constants
+ dali.BLEND_FACTOR_ZERO
+ dali.BLEND_FACTOR_ONE
+ dali.BLEND_FACTOR_SRC_COLOR
+ dali.BLEND_FACTOR_ONE_MINUS_SRC_COLOR
+ dali.BLEND_FACTOR_SRC_ALPHA
+ dali.BLEND_FACTOR_ONE_MINUS_SRC_ALPHA
+ dali.BLEND_FACTOR_DST_ALPHA
+ dali.BLEND_FACTOR_ONE_MINUS_DST_ALPHA
+ dali.BLEND_FACTOR_DST_COLOR
+ dali.BLEND_FACTOR_ONE_MINUS_DST_COLOR
+ dali.BLEND_FACTOR_SRC_ALPHA_SATURATE
+ dali.BLEND_FACTOR_CONSTANT_COLOR
+ dali.BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR
+ dali.BLEND_FACTOR_CONSTANT_ALPHA
+ dali.BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA
+
+ actor.setBlendFunc( dali.BLEND_FACTOR_ONE_MINUS_SRC_COLOR, dali.BLEND_FACTOR_ONE_MINUS_DST_COLOR);
+ */
+
+/**
+ * @for RenderableActor
+ * @method setBlendFunc
+ * @param {Number} SourceBlending RGB
+ * @param {Number} DestinationBlending RGB
+ * @param {Number} SourceBlending Alpha
+ * @param {Number} DestinatinoBlending Alpha
+ * @example
+ * //blending constants
+ dali.BLEND_FACTOR_ZERO
+ dali.BLEND_FACTOR_ONE
+ dali.BLEND_FACTOR_SRC_COLOR
+ dali.BLEND_FACTOR_ONE_MINUS_SRC_COLOR
+ dali.BLEND_FACTOR_SRC_ALPHA
+ dali.BLEND_FACTOR_ONE_MINUS_SRC_ALPHA
+ dali.BLEND_FACTOR_DST_ALPHA
+ dali.BLEND_FACTOR_ONE_MINUS_DST_ALPHA
+ dali.BLEND_FACTOR_DST_COLOR
+ dali.BLEND_FACTOR_ONE_MINUS_DST_COLOR
+ dali.BLEND_FACTOR_SRC_ALPHA_SATURATE
+ dali.BLEND_FACTOR_CONSTANT_COLOR
+ dali.BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR
+ dali.BLEND_FACTOR_CONSTANT_ALPHA
+ dali.BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA
+
+ actor.setBlendFunc( dali.BLEND_FACTOR_CONSTANT_COLOR, BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR,
+ dali.BLEND_FACTOR_CONSTANT_ALPHA, BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA);
+
+ );
+ */
+void RenderableActorApi::SetBlendFunc( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderableActor actor = GetRenderableActor( isolate, args );
+
+ int params[4];
+ if( args.Length() == 2 )
+ {
+ bool foundAllParams(false);
+ V8Utils::ReadIntegerArguments( foundAllParams, ¶ms[0], 2, args,0 );
+ if( foundAllParams )
+ {
+ actor.SetBlendFunc( static_cast< Dali::BlendingFactor::Type>(params[0]),
+ static_cast< Dali::BlendingFactor::Type>(params[1]) );
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "invalid BlendMode parameter");
+ return;
+ }
+ }
+ else if ( args.Length() == 4)
+ {
+ bool foundAllParams(false);
+ V8Utils::ReadIntegerArguments( foundAllParams, ¶ms[0], 4, args,0 );
+ if( foundAllParams )
+ {
+ actor.SetBlendFunc( static_cast< Dali::BlendingFactor::Type>(params[0]),
+ static_cast< Dali::BlendingFactor::Type>(params[1]),
+ static_cast< Dali::BlendingFactor::Type>(params[2]),
+ static_cast< Dali::BlendingFactor::Type>(params[3]));
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "invalid BlendMode parameter");
+ return;
+ }
+ }
+
+}
+
+/**
+ * @for RenderableActor
+ * @method GetBlendFunc
+ * @return {Object} BlendProperties
+ * @example Blend properties object has 4 fields
+ *
+ * blendProperties.sourceRgb // source rgb enum
+ * blendProperties.destinationRgb // destination rgb enum
+ * blendProperties.sourceAlpha source // alpha enum
+ * blendProperties.destinationAlpha // destination alpha enum
+ */
+void RenderableActorApi::GetBlendFunc( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ // @todo pass by reference doesn't work in Javascript so need to decide what to return
+ // for now just return a vector 4...
+
+ BlendingFactor::Type srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha;
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderableActor actor = GetRenderableActor( isolate, args );
+
+ actor.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
+
+ v8::Local<v8::Object> blendInfo = v8::Object::New( isolate );
+
+ blendInfo->Set( v8::String::NewFromUtf8( isolate, "sourceRgb" ), v8::Integer::New( isolate, srcFactorRgb) );
+ blendInfo->Set( v8::String::NewFromUtf8( isolate, "destinationRgb" ), v8::Integer::New( isolate, destFactorRgb ) );
+ blendInfo->Set( v8::String::NewFromUtf8( isolate, "sourceAlpha" ), v8::Integer::New( isolate, srcFactorAlpha ) );
+ blendInfo->Set( v8::String::NewFromUtf8( isolate, "destinationAlpha" ), v8::Integer::New( isolate, destFactorAlpha ) );
+
+ args.GetReturnValue().Set( blendInfo );
+
+}
+// 2 function definitions, as Dali uses 2 functions.
+// JavaScript can't overload but we can document it twice with different params
+/**
+ * @for RenderableActor
+ * @method setBlendEquation
+ * @param {Number } BlendEquation for RGBA
+ * @example
+ *
+ * //blending equation constants
+ dali.BLEND_EQUATION_ADD
+ dali.BLEND_EQUATION_SUBTRACT
+ dali.BLEND_EQUATION_REVERSE_SUBTRACT
+ actor.setBlendEquation( dali.BLEND_EQUATION_ADD );
+
+ */
+
+/**
+ * @for RenderableActor
+ * @method setBlendEquation
+ * @param {Number } BlendEquation for RGB
+ * @param {Number } BlendEquation for Alpha
+ * @example
+ *
+ * //blending equation constants
+ dali.BLEND_EQUATION_ADD
+ dali.BLEND_EQUATION_SUBTRACT
+ dali.BLEND_EQUATION_REVERSE_SUBTRACT
+ actor.setBlendEquationSeparate( dali.BLEND_EQUATION_ADD, dali.BLEND_EQUATION_SUBTRACT );
+
+ */
+void RenderableActorApi::SetBlendEquation( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderableActor actor = GetRenderableActor( isolate, args );
+
+ int params[2];
+ if( args.Length() == 1 )
+ {
+ bool foundAllParams( false );
+ V8Utils::ReadIntegerArguments( foundAllParams, ¶ms[0], 1, args, 0 );
+ if( foundAllParams )
+ {
+ actor.SetBlendEquation( static_cast<Dali::BlendingEquation::Type>( params[0] ) );
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "invalid BlendEquation parameter" );
+ return;
+ }
+ }
+ else if( args.Length() == 2 )
+ {
+ bool foundAllParams( false );
+ V8Utils::ReadIntegerArguments( foundAllParams, ¶ms[0], 2, args, 0 );
+ if( foundAllParams )
+ {
+ actor.SetBlendEquation( static_cast<Dali::BlendingEquation::Type>( params[0] ), static_cast<Dali::BlendingEquation::Type>( params[1] ) );
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "invalid BlendEquation parameter" );
+ return;
+ }
+ }
+}
+
+/**
+ * @for RenderableActor
+ * @method getBlendEquation
+ * @return {Object} equationProperties
+ * @example equation properties object has 2 fields
+ *
+ * equationProperties.equationRgb // rbg blend equation
+ * equationProperties.equationAlpha // alpha blend equation
+ */
+void RenderableActorApi::GetBlendEquation( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderableActor actor = GetRenderableActor( isolate, args );
+
+ BlendingEquation::Type equationRgb, equationAlpha;
+ actor.GetBlendEquation( equationRgb, equationAlpha );
+
+ v8::Local<v8::Object> object = v8::Object::New( isolate );
+
+ object->Set( v8::String::NewFromUtf8( isolate, "equationRgb" ), v8::Integer::New( isolate, equationRgb) );
+ object->Set( v8::String::NewFromUtf8( isolate, "equationAlpha" ), v8::Integer::New( isolate, equationAlpha ) );
+
+ args.GetReturnValue().Set( object );
+}
+
+/**
+ * @for RenderableActor
+ * @method setBlendColor
+ * @param {Vector4} Color
+ * @example
+ *
+ * actor.SetBlendColor( dali.COLOR_RED );
+ */
+void RenderableActorApi::SetBlendColor( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderableActor actor = GetRenderableActor( isolate, args );
+
+ Dali::Vector4 color;
+
+ bool foundAllArguments( false );
+
+ V8Utils::ReadFloatArguments( foundAllArguments, color.AsFloat(), 4, args, 1.f ); // read the parameters
+ if( !foundAllArguments )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "invalid color parameter, should red,green,blue,alpha" );
+ return;
+ }
+ actor.SetBlendColor( color );
+
+}
+
+/**
+ * @for RenderableActor
+ * @method getBlendColor
+ * @return {Object} Dali vector 4 object
+ */
+void RenderableActorApi::GetBlendColor( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderableActor actor = GetRenderableActor( isolate, args );
+
+ Dali::Vector4 color = actor.GetBlendColor();
+
+ Dali::Property::Value value( color );
+
+ v8::Local<v8::Object> object = PropertyValueWrapper::WrapDaliProperty( isolate, value );
+
+ args.GetReturnValue().Set( object );
+
+}
+
+
+/**
+ * @for RenderableActor
+ * @method getShaderEffect
+ * @return {Object} ShaderEffect object
+ *
+ * Retrieve the shader effect for the Actor.
+ *
+ * @example
+ * var shaderEffect = actor.getShaderEffect();
+ *
+ */
+void RenderableActorApi::GetShaderEffect( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderableActor actor = GetRenderableActor( isolate, args );
+
+ v8::Local < v8::Object > object = ShaderEffectWrapper::WrapShaderEffect( isolate, actor.GetShaderEffect() );
+ args.GetReturnValue().Set( object );
+
+}
+
+/**
+ * @for RenderableActor
+ * @method setShaderEffect
+ * @param {Object} shaderEffect The shader effect.
+ *
+ * Sets the shader effect for the Actor.
+ *
+ * Shader effects provide special effects like rippling and bending.
+ * Setting a shader effect removes any shader effect previously set by SetShaderEffect.
+ * @example
+ * // first create the shaderOptions, then the shaderEffect
+ * var shader = new dali.ShaderEffect( shaderOptions );
+ * actor.setShaderEffect( shader );
+ *
+ */
+void RenderableActorApi::SetShaderEffect( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderableActor actor = GetRenderableActor( isolate, args );
+
+ bool found( false );
+ ShaderEffect effect = ShaderEffectApi::GetShaderEffectFromParams( 0, found, isolate, args );
+ if( found )
+ {
+ actor.SetShaderEffect( effect );
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "shader effect parameter missing" );
+ }
+}
+
+/**
+ *
+ * Removes the current shader effect
+ *
+ * @example
+ * actor.removeShaderEffect();
+ *
+ * @for RenderableActor
+ * @method removeShaderEffect
+ */
+void RenderableActorApi::RemoveShaderEffect( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderableActor actor = GetRenderableActor( isolate, args );
+ actor.RemoveShaderEffect();
+}
+
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_RENDERABLE_ACTOR_API_H__
+#define __DALI_V8PLUGIN_RENDERABLE_ACTOR_API_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/public-api/actors/renderable-actor.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace RenderableActorApi
+{
+ /**
+ * RenderableActor API see renderable-actor.h for a description
+ * Unfortunately none of the functions are covered by the property system
+ */
+ void SetSortModifier( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetSortModifier( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetCullFace( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetCullFace( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetBlendMode( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetBlendMode( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetBlendFunc( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetBlendFunc( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetBlendEquation( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetBlendEquation( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetBlendColor( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetBlendColor( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetShaderEffect( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetShaderEffect( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void RemoveShaderEffect( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+
+}; // namespace RenderableActorApi
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header __DALI_V8PLUGIN_RENDERABLE_ACTOR_API_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "text-actor-api.h"
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/text/text-actor-parameters.h>
+
+// INTERNAL INCLUDES
+#include <object/handle-wrapper.h>
+#include <v8-utils.h>
+#include <object/property-value-wrapper.h>
+#include <text/font-api.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace //unnamed name space
+{
+
+struct TextActorParametersInternal
+{
+ TextActorParametersInternal()
+ : fontDetection( true )
+ {
+ }
+ bool fontDetection;
+ Font font;
+};
+
+
+TextActor GetTextActor( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ HandleWrapper* handleWrapper = HandleWrapper::Unwrap( isolate, args.This() );
+ return TextActor::DownCast( handleWrapper->mHandle );
+}
+
+
+void GetTextOptions( v8::Isolate* isolate,
+ v8::Local<v8::Value > options,
+ TextActorParametersInternal& textParams )
+{
+ // fontDetection: true / false ( default true)
+ // font: dali font object
+ v8::HandleScope handleScope( isolate );
+
+ if( options->IsObject() )
+ {
+ v8::Local<v8::Object> obj = options->ToObject();
+
+ v8::Local<v8::Value> fontDetect = obj->Get( v8::String::NewFromUtf8( isolate, "fontDetection" ) );
+ if( fontDetect->IsBoolean() )
+ {
+
+ textParams.fontDetection = fontDetect->ToBoolean()->Value();
+ }
+
+ v8::Local<v8::Value> fontValue = obj->Get( v8::String::NewFromUtf8( isolate, "font" ) );
+ if( fontValue->IsObject() )
+ {
+ textParams.font = FontApi::GetFont( isolate, fontValue );
+ }
+
+ }
+}
+
+}
+
+/**
+ * @constructor
+ * @for TextActor
+ * @method TextActor
+ * @param {String} text
+ * @param {Object} [textOptions] data
+ * Options text options struct
+ * @param {Boolean} [textOptions.fontDetection]
+ * if true the fontDetection is used to make sure the text is displayed.
+ * E.g. if the current font used by the text-actor does not support certain characters
+ * it will find a new font that does. Default = true.
+ * @param {Object} [textOptions.font]
+ * Dali font object
+ * @return {Object} TextActor
+ */
+Actor TextActorApi::New( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ //
+ // TextActor( text, options (optional) )
+ //
+ // options =
+ // {
+ // font: font
+ // fontDetection: true / false ( default true)
+ // }
+
+ // get the text (if passed in)
+
+ bool found( false );
+ std::string text = V8Utils::GetStringParameter( PARAMETER_0, found, isolate, args );
+
+ TextActorParametersInternal params;
+ TextActor actor;
+
+ GetTextOptions( isolate, args[1], params );
+
+ TextStyle style;
+
+ if( params.font )
+ {
+ style.SetFontName( params.font.GetName() );
+ style.SetFontStyle( params.font.GetStyle() );
+ style.SetFontPointSize( PointSize(params.font.GetPointSize()));
+
+ }
+ TextActorParameters textActorParameters( style, params.fontDetection? TextActorParameters::FONT_DETECTION_OFF:TextActorParameters::FONT_DETECTION_ON );
+
+ actor = TextActor::New( text, textActorParameters );
+
+ return actor;
+
+}
+
+/**
+ * Set text to the natural size of the text string.
+ *
+ * After this method the text actor always uses the natural size of the text
+ * when SetText is called unless SetSize is called to override the size.
+ *
+ * @for TextActor
+ * @method setToNaturalSize
+ */
+void TextActorApi::SetToNaturalSize( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ TextActor textActor = GetTextActor( isolate, args );
+ textActor.SetToNaturalSize();
+}
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_TEXT_ACTOR_API_H__
+#define __DALI_V8PLUGIN_TEXT_ACTOR_API_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/public-api/actors/text-actor.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace TextActorApi
+{
+ Actor New( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetToNaturalSize( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+}; // namespace TextActorApi
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header __DALI_V8PLUGIN_TEXT_ACTOR_API_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "animation-api.h"
+#include "path-wrapper.h"
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <dali/integration-api/debug.h>
+#include <animation/animation-wrapper.h>
+#include <object/property-value-wrapper.h>
+#include <dali/public-api/common/map-wrapper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace // un named namespace
+{
+
+// @todo think about alternative ways of passing around
+struct AlphaFuncStruct
+{
+ const char* const name;
+ AlphaFunction alphaFunc;
+};
+/**
+ * Contains a list of alpha functions that can be used.
+ * We use a stl map as lookup to map a string name to the function
+ */
+const AlphaFuncStruct AlphaFunctionTable[]=
+{
+ {"default" , AlphaFunctions::Default },
+ {"linear" , AlphaFunctions::Linear },
+ {"square" , AlphaFunctions::Square },
+ {"reverse" , AlphaFunctions::Reverse },
+ {"easeIn" , AlphaFunctions::EaseIn },
+ {"easeOut" , AlphaFunctions::EaseOut },
+ {"easeInOut" , AlphaFunctions::EaseInOut },
+ {"easeInSine" , AlphaFunctions::EaseInSine },
+ {"easeOutSine" , AlphaFunctions::EaseOutSine },
+ {"easeInOutSine" , AlphaFunctions::EaseInOutSine },
+ {"easeInSine33" , AlphaFunctions::EaseInSine33 },
+ {"easeOutSine33" , AlphaFunctions::EaseOutSine33 },
+ {"easeInOutSine33" , AlphaFunctions::EaseInOutSine33 },
+ {"easeInOutSine50" , AlphaFunctions::EaseInOutSine50 },
+ {"easeInOutSine60" , AlphaFunctions::EaseInOutSine60 },
+ {"easeInOutSine70" , AlphaFunctions::EaseInOutSine70 },
+ {"easeInOutSine80" , AlphaFunctions::EaseInOutSine80 },
+ {"easeInOutSine90" , AlphaFunctions::EaseInOutSine90 },
+ {"doubleEaseInOutSine60" , AlphaFunctions::DoubleEaseInOutSine60},
+ {"easeOutQuint50" , AlphaFunctions::EaseOutQuint50 },
+ {"easeOutQuint80" , AlphaFunctions::EaseOutQuint80 },
+ {"bounce" , AlphaFunctions::Bounce },
+ {"bounceBack" , AlphaFunctions::BounceBack },
+ {"easeInBack" , AlphaFunctions::EaseInBack },
+ {"easeOutBack" , AlphaFunctions::EaseOutBack },
+ {"easeInOutBack" , AlphaFunctions::EaseInOutBack },
+ {"sin" , AlphaFunctions::Sin },
+ {"sin2x" , AlphaFunctions::Sin2x }
+};
+const unsigned int AlphaFunctionTableCount = sizeof(AlphaFunctionTable)/sizeof(AlphaFunctionTable[0]);
+const char* const DEFAULT_ALPHA_NAME = "default";
+static AlphaFunction DEFAULT_ALPHA_FUNCTION = AlphaFunctions::Default;
+
+
+
+AlphaFunction GetAlphaFunction( const std::string& alphaFuncName )
+{
+ // This will normally get called just a few times during the application, so no point in doing anything clever
+ for( unsigned int i = 0; i < AlphaFunctionTableCount; i++)
+ {
+ const AlphaFuncStruct& alphaStruct( AlphaFunctionTable[i] );
+
+ if( std::strcmp( alphaStruct.name , alphaFuncName.c_str() ) == 0 )
+ {
+ return alphaStruct.alphaFunc;
+ }
+ }
+
+ DALI_LOG_ERROR("Failed to find alpha func |%s| \n", alphaFuncName.c_str() );
+ return AlphaFunctions::Default;
+}
+
+const char* const GetAlphaFunctionName( AlphaFunction alphaFunc )
+{
+ // This may get called 3 times during the application, so no point
+ // in doing anything clever
+
+ for( unsigned int i = 0; i < AlphaFunctionTableCount; i++)
+ {
+ const AlphaFuncStruct& alphaStruct( AlphaFunctionTable[i] );
+
+
+ if( alphaStruct.alphaFunc == alphaFunc )
+ {
+ return alphaStruct.name;
+ }
+ }
+ return "default";
+}
+
+
+struct AnimationParameters
+{
+ AnimationParameters( const Animation& anim)
+ : propertyIndex( Property::INVALID_INDEX ),
+ alphaFunction( DEFAULT_ALPHA_FUNCTION),
+ delay( 0.f ),
+ duration(anim.GetDuration()),
+ optionsFound( false )
+ {
+ }
+
+ Handle target;
+ Property::Index propertyIndex;
+ Property::Value value;
+ KeyFrames keyFrames;
+ AlphaFunction alphaFunction;
+ float delay;
+ float duration;
+ bool optionsFound;
+};
+
+void GetAnimationOptions( v8::Isolate* isolate,
+ v8::Local<v8::Value > options,
+ AnimationParameters& animParams )
+{
+ // animation options is an optional parameter passed in which holds
+ // optional settings
+ // var animOptions = {
+ // alpha: "Bounce",
+ // delay: 5,
+ // duration: 20
+ // };
+ v8::HandleScope handleScope( isolate );
+
+ if( options->IsObject() )
+ {
+ v8::Local<v8::Object> obj = options->ToObject();
+ v8::Local<v8::Value> alphaValue = obj->Get( v8::String::NewFromUtf8( isolate, "alpha" ) );
+ if( alphaValue->IsString() )
+ {
+ animParams.optionsFound = true;
+ std::string alphaName = V8Utils::v8StringToStdString( alphaValue );
+ animParams.alphaFunction = GetAlphaFunction( alphaName );
+ }
+
+ v8::Local<v8::Value> delayValue = obj->Get( v8::String::NewFromUtf8( isolate, "delay" ) );
+ if( delayValue->IsNumber() )
+ {
+ animParams.optionsFound = true;
+ v8::Local<v8::Number> num = delayValue->ToNumber();
+ animParams.delay = num->Value();
+ }
+
+ v8::Local<v8::Value> durationValue = obj->Get( v8::String::NewFromUtf8( isolate, "duration" ) );
+ if( durationValue->IsNumber() )
+ {
+ animParams.optionsFound = true;
+ v8::Local<v8::Number> num = durationValue->ToNumber();
+ animParams.duration = num->Value();
+ }
+
+ }
+}
+KeyFrames GetKeyFrames( v8::Isolate* isolate, v8::Local<v8::Value > keyFrameArray )
+{
+ // keyframe object is an array of
+ // {
+ // float: progress
+ // value: property value ( position/ rotation etc)
+ // alpha: function
+ //
+ v8::HandleScope handleScope( isolate );
+
+ if( !keyFrameArray->IsObject() || !keyFrameArray->IsArray() )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing keyframe array" );
+ return KeyFrames();
+ }
+
+ KeyFrames keyframes = KeyFrames::New();
+
+ v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast( keyFrameArray );
+ for( uint32_t i=0; i < array->Length() ; ++i)
+ {
+ v8::Handle<v8::Value> arrayItem = array->Get( i );
+
+ if(!arrayItem->IsObject() )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing keyframe object" );
+ return KeyFrames();
+ }
+ v8::Handle<v8::Object> keyFrameObject = arrayItem->ToObject();
+
+ // get keyframe.progress
+ v8::Handle<v8::Value> progress = keyFrameObject->Get(v8::String::NewFromUtf8( isolate, "progress"));
+ if( !progress->IsNumber() )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "keyframe missing progress property" );
+ return keyframes;
+ }
+
+ // get keyframe.value
+ bool found(false);
+ v8::Handle<v8::Value> propertyValue = keyFrameObject->Get(v8::String::NewFromUtf8( isolate, "value"));
+ Property::Value value = V8Utils::GetPropertyValueFromObject( found, isolate, propertyValue );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "keyframe missing value property" );
+ return keyframes;
+ }
+
+ // get keyframe.alpha
+ v8::Handle<v8::Value> alphaValue = keyFrameObject->Get(v8::String::NewFromUtf8( isolate, "alpha"));
+ if( alphaValue->IsString() )
+ {
+ std::string alphaName = V8Utils::v8StringToStdString( alphaValue );
+ AlphaFunction alphaFunction = GetAlphaFunction( alphaName );
+ keyframes.Add( progress->NumberValue(), value, alphaFunction );
+ }
+ else
+ {
+ keyframes.Add( progress->NumberValue(), value );
+ }
+
+ }
+ return keyframes;
+
+}
+bool GetAnimationParameters( v8::Isolate* isolate,
+ const v8::FunctionCallbackInfo< v8::Value >& args,
+ AnimationParameters& animParams,
+ AnimationApi::AnimationParameterType type)
+{
+ // used for things like anim.AnimateBy( myImageActor, property-name, property-value (or Javascript number array));
+ // 1 extract property handle from param1.
+ // 2 extract property name from param2 ( can be in the format "u-color" or "uColor"
+ // 3 extract PropertyValue from param3
+ // 4 extract animation options ( delay, duration, alpha func)
+
+ // 1 extract HANDLE
+ bool foundHandle;
+ animParams.target = V8Utils::GetHandleParameter( PARAMETER_0, foundHandle, isolate, args );
+ if( !foundHandle )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 0 (Handle)" );
+ return false;
+ }
+
+ // 2 extract property name
+ bool foundPropName;
+ std::string propertyName = V8Utils::GetStringParameter( PARAMETER_1, foundPropName, isolate, args );
+ if( !foundPropName )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 1 ( PropertyName )" );
+ return false;
+ }
+ // try both properties with dashes and without
+ Property::Index index = animParams.target.GetPropertyIndex( propertyName );
+
+ if( index == Property::INVALID_INDEX )
+ {
+ // convert the property name from "uColor" to "u-color"
+ std::string convetedName = V8Utils::JavaScriptNameToPropertyName( propertyName );
+ index = animParams.target.GetPropertyIndex( convetedName );
+ }
+
+ animParams.propertyIndex = index;
+
+ if( type == AnimationApi::PROPERTY_VALUE )
+ {
+ // 3 extract property value
+ bool foundPropValue( false );
+ animParams.value = V8Utils::GetPropertyValueParameter( PARAMETER_2, foundPropValue, isolate, args );
+ if( !foundPropValue )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 2 ( value )" );
+ return false;
+ }
+ }
+ else // type == KEYFRAMES
+ {
+ animParams.keyFrames = GetKeyFrames(isolate, args[2]);
+ }
+ // 4 extract animation options
+ GetAnimationOptions( isolate, args[3], animParams );
+
+ return true;
+}
+
+Animation GetAnimation( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::HandleScope handleScope( isolate );
+
+ v8::Local<v8::Object> object = args.This();
+ v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField( 0 ) );
+ void* ptr = field->Value();
+
+ AnimationWrapper* wrapper = static_cast<AnimationWrapper *>( ptr );
+ return wrapper->GetAnimation();
+}
+
+
+} // un-named namespace
+
+/**
+ * Constructor
+ *
+ * @constructor
+ * @for Animation
+ * @method Animation
+ * @param {float} duration
+ *
+ */
+Animation AnimationApi::New( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ bool found( false );
+ float value = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 1.f /* default */);
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
+ return Animation();
+ }
+ // get the duration
+ return Animation::New( value );
+}
+
+/**
+ * Set the animation duration.
+ * @method setDuration
+ * @for Animation
+ * @param {float} duration in seconds
+ *
+ */
+void AnimationApi::SetDuration( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Animation anim = GetAnimation( isolate, args );
+
+ bool found( false );
+ float value = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 1.f /* default */);
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
+ return;
+ }
+ anim.SetDuration( value );
+}
+/**
+ * Get the animation duration.
+ * @method getDuration
+ * @for Animation
+ * @return {float} duration in seconds
+ *
+ */
+void AnimationApi::GetDuration( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Animation anim = GetAnimation( isolate, args );
+
+ args.GetReturnValue().Set( v8::Number::New( isolate, anim.GetDuration() ) );
+
+}
+/**
+ * Set whether the animation will loop.
+ * @method setLooping
+ * @for Animation
+ * @param {bool} looping enabled
+ *
+ */
+void AnimationApi::SetLooping( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Animation anim = GetAnimation( isolate, args );
+
+ bool found( false );
+ bool value = V8Utils::GetBooleanParameter( PARAMETER_0, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
+ }
+ else
+ {
+ anim.SetLooping( value );
+ }
+
+}
+/**
+ * Query whether the animation will loop.
+ * @method isLooping
+ * @for Animation
+ * @return {bool} looping enabled
+ *
+ */
+void AnimationApi::IsLooping( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Animation anim = GetAnimation( isolate, args );
+
+ args.GetReturnValue().Set( v8::Boolean::New( isolate, anim.IsLooping() ) );
+}
+
+/**
+ * Set the end action of the animation.
+ *
+ * This action is performed when the animation ends.
+ * Default end action is bake
+ * @method setEndAction
+ * @for Animation
+ * @param {integer} bake mode
+ * @example
+ * anim.setEndAction( dali.ANIMATION_BAKE ); // When the animation ends, the animated property values are saved.
+ * anim.setEndAction( dali.ANIMATION_DISCARD ); // When the animation ends, the animated property values are forgotten.
+ * anim.setEndAction( dali.ANIMATION_BAKE_FINAL ); // If the animation is stopped, the animated property values are saved as if the animation had run to completion, otherwise behaves like Bake.
+ */
+void AnimationApi::SetEndAction( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Animation anim = GetAnimation( isolate, args );
+
+ bool found( false );
+ int value = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
+ }
+ else
+ {
+ anim.SetEndAction( static_cast<Animation::EndAction>( value ) );
+ }
+}
+
+/**
+ * Returns the end action of the animation.
+
+ * @method getEndAction
+ * @for Animation
+ * @return {integer} bake mode
+ *
+ * There are 3 different bake modes
+ * @example
+ * dali.ANIMATION_BAKE // When the animation ends, the animated property values are saved.
+ * dali.ANIMATION_DISCARD // When the animation ends, the animated property values are forgotten.
+ * dali.ANIMATION_BAKE_FINAL // If the animation is stopped, the animated property values are saved as if the animation had run to completion, otherwise behaves like Bake.
+ */
+void AnimationApi::GetEndAction( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Animation anim = GetAnimation( isolate, args );
+
+ args.GetReturnValue().Set( v8::Integer::New( isolate, anim.GetEndAction() ) );
+}
+
+/**
+ * Set the disconnect action of the animation.
+ * If any of the animated property owners are disconnected from the stage, this action is performed.
+ * Default disconnection action is BakeFinal.
+ * @method setDisconnectAction
+ * @for Animation
+ * @param {integer} end mode
+ *
+ * There are 3 different end modes
+ * @example
+ * dali.ANIMATION_BAKE // When the animation is destroyed, the animated property values are saved.
+ * dali.ANIMATION_DISCARD // When the animation is destroyed, the animated property values are forgotten.
+ * dali.ANIMATION_BAKE_FINAL // When the animation is destroyed, the animated property values are saved as if the animation had run to completion, otherwise behaves like Bake.
+ */
+void AnimationApi::SetDisconnectAction( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Animation anim = GetAnimation( isolate, args );
+
+ bool found( false );
+ int value = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
+ }
+ else
+ {
+ anim.SetDisconnectAction( static_cast<Animation::EndAction>( value ) );
+ }
+}
+
+/**
+ * Returns the disconnect action of the animation.
+ * @method getDisconnectAction
+ * @for Animation
+ * @return {integer} end mode
+ */
+void AnimationApi::GetDisconnectAction( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Animation anim = GetAnimation( isolate, args );
+
+ args.GetReturnValue().Set( v8::Integer::New( isolate, anim.GetDisconnectAction() ) );
+}
+/**
+ * Set the default alpha function for an animation.
+ * @method setDefaultAlphaFunction
+ * @for Animation
+ * @param {string} alpha function
+ */
+void AnimationApi::SetDefaultAlphaFunction( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Animation anim = GetAnimation( isolate, args );
+
+ bool found( false );
+ std::string alphaFunc = V8Utils::GetStringParameter( PARAMETER_0, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
+ }
+ else
+ {
+ AlphaFunction func = GetAlphaFunction( alphaFunc );
+ anim.SetDefaultAlphaFunction( func );
+ }
+
+}
+/**
+ * Get the default alpha function for an animation.
+ * @method getDefaultAlphaFunction
+ * @for Animation
+ * @return {string} alpha function
+ */
+void AnimationApi::GetDefaultAlphaFunction( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Animation anim = GetAnimation( isolate, args );
+
+ std::string alphaName = GetAlphaFunctionName( anim.GetDefaultAlphaFunction() );
+
+
+ args.GetReturnValue().Set( v8::String::NewFromUtf8( isolate, alphaName.c_str() ) );
+}
+
+/**
+ * Get the current progress of the animation.
+ * @method getCurrentProgress
+ * @for Animation
+ * @return {float} The current progress as a normalized value between [0..1].
+ *
+ */
+void AnimationApi::GetCurrentProgress( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Animation anim = GetAnimation( isolate, args );
+
+ args.GetReturnValue().Set( v8::Number::New( isolate, anim.GetCurrentProgress() ) );
+}
+
+/**
+ * Specifies an speed factor for the animation.
+ *
+ * The speed factor is a multiplier of the normal velocity of the animation. Values between [0,1] will
+ * slow down the animation and values above one will speed up the animation. It is also possible to specify a negative multiplier
+ * to play the animation in reverse.
+ *
+ * @method setSpeedFactor
+ * @for Animation
+ * @param {float} value which will multiply the velocity.
+ * @example
+ * anim.setSpeedFactor(2);
+ * anim.play(); // plays the animation twice as fast
+ *
+ *
+ * anim.setSpeedFactor(0.5);
+ * anim.play(); // plays the animation half speed
+ *
+ */
+void AnimationApi::SetSpeedFactor( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Animation anim = GetAnimation( isolate, args );
+
+ bool found( false );
+ float speedFactor = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 0.f );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "float parameter missing" );
+ }
+ else
+ {
+ anim.SetSpeedFactor( speedFactor );
+ }
+
+}
+
+/**
+ * Retrieve the speed factor of the animation
+ *
+ *
+ * @method getSpeedFactor
+ * @for Animation
+ * @return {float} speed factor
+ */
+void AnimationApi::GetSpeedFactor( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Animation anim = GetAnimation( isolate, args );
+
+ args.GetReturnValue().Set( v8::Number::New( isolate, anim.GetSpeedFactor() ) );
+}
+
+/**
+ * Set the playing range.
+ * Animation will play between the values specified.
+ * Both values ( range.x and range.y ) should be between 0-1,
+ * otherwise they will be ignored.
+ * If the range provided is not in proper order ( minimum,maximum), it will be reordered.
+ * @method setPlayRange
+ * @for Animation
+ * @param {Object} Range
+ * @param {Float} Range.start
+ * @param {Float} Range.end
+ * @example
+ * var range = { start:0.1, end:0.6 };
+ * anim.setPlayRange( range );
+ */
+void AnimationApi::SetPlayRange( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Animation anim = GetAnimation( isolate, args );
+ Vector2 range(0,0);
+
+ if( args.Length() != 1 )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing / invalid parameters" );
+ return;
+ }
+ v8::Local<v8::Value > rangeValue = args[0];
+ if( !rangeValue->IsObject() )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "invalid parameters" );
+ return;
+ }
+ v8::Local<v8::Object> obj = rangeValue->ToObject();
+ v8::Local<v8::Value> startValue = obj->Get( v8::String::NewFromUtf8( isolate, "start" ) );
+ v8::Local<v8::Value> endValue = obj->Get( v8::String::NewFromUtf8( isolate, "end" ) );
+
+ if( startValue->IsNumber() && endValue->IsNumber())
+ {
+ range.x= startValue->ToNumber()->Value();
+ range.y = endValue->ToNumber()->Value();
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing start/end value" );
+ return;
+ }
+
+ anim.SetPlayRange( range );
+
+}
+
+/**
+ * Get the playing range.
+ * @method getPlayRange
+ * @for Animation
+ * @return {Object} Range with { start: , end: } properties.
+ */
+void AnimationApi::GetPlayRange( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::EscapableHandleScope handleScope( isolate );
+ Animation anim = GetAnimation( isolate, args );
+
+
+ v8::Local<v8::Object> rangeObject = v8::Object::New( isolate );
+
+ Vector2 range = anim.GetPlayRange();
+
+ // set device id
+ rangeObject->Set( v8::String::NewFromUtf8( isolate, "start"), v8::Number::New( isolate,range.x ));
+
+ // set state
+ rangeObject->Set( v8::String::NewFromUtf8( isolate, "end"), v8::Number::New( isolate,range.y ));
+
+ args.GetReturnValue().Set( rangeObject );
+}
+
+
+/**
+ * Sets the progress of the animation.
+ * The animation will play (or continue playing) from this point. The progress
+ * must be in the 0-1 interval or in the play range interval if defined ( See SetPlayRange ),
+ * otherwise, it will be ignored.
+ *
+ * @method setCurrentProgress
+ * @for Animation
+ * @param {float} progress The new progress as a normalized value between [0,1] or between the
+ * play range if specified.
+ */
+void AnimationApi::SetCurrentProgress( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Animation anim = GetAnimation( isolate, args );
+
+ bool found( false );
+
+ float progress = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 0.f );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "float parameter missing" );
+ return;
+ }
+ anim.SetCurrentProgress( progress );
+
+}
+
+/**
+ *
+ * Play the animation from a given point.
+ * The progress must be in the 0-1 interval or in the play range interval if defined ( See SetPlayRange ),
+ * otherwise, it will be ignored.
+ * @method playFrom
+ * @for Animation
+ * @param {float} progress A value between [0,1], or between the play range if specified, form where the animation should start playing
+ */
+void AnimationApi::PlayFrom( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Animation anim = GetAnimation( isolate, args );
+
+ bool found( false );
+
+ float progress = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 0.f );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "float parameter missing" );
+ return;
+ }
+ anim.PlayFrom( progress );
+
+}
+
+/**
+ * Play the animation
+ * @method play
+ * @for Animation
+ */
+void AnimationApi::Play( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Animation anim = GetAnimation( isolate, args );
+ anim.Play();
+}
+/**
+ * Pause the animation
+ * @method pause
+ * @for Animation
+ */
+void AnimationApi::Pause( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Animation anim = GetAnimation( isolate, args );
+ anim.Pause();
+}
+/**
+ * Stop the animation
+ * @method stop
+ * @for Animation
+ */
+void AnimationApi::Stop( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Animation anim = GetAnimation( isolate, args );
+ anim.Stop();
+}
+/**
+ * Clear the animation
+ * This disconnects any objects that were being animated, effectively stopping the animation.
+ * @method clear
+ * @for Animation
+ */
+void AnimationApi::Clear( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Animation anim = GetAnimation( isolate, args );
+ anim.Clear();
+}
+
+
+void AnimationApi::Animate( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Animation anim = GetAnimation( isolate, args );
+ AnimationParameters animParams( anim );
+ bool found(false);
+
+ //Get actor
+ Dali::Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Missing actor parameter");
+ return;
+ }
+
+ //Get path
+ Dali::Path path;
+ BaseWrappedObject* wrapper = V8Utils::GetWrappedDaliObjectParameter( PARAMETER_1, BaseWrappedObject::PATH, isolate, args);
+ PathWrapper* pathWrapper = static_cast< PathWrapper*>( wrapper );
+ if( !pathWrapper )
+ {
+ return;
+ }
+ path = pathWrapper->GetPath();
+
+ //Get forward vector
+ bool bFound(false);
+ Vector3 forward = V8Utils::GetVector3Parameter( PARAMETER_2, bFound, isolate, args );
+ if( !bFound )
+ {
+ return;
+ }
+
+ //Get animation options
+ GetAnimationOptions( isolate, args[3], animParams );
+ if( animParams.optionsFound )
+ {
+ anim.Animate( actor, path, forward, animParams.alphaFunction, TimePeriod( animParams.delay, animParams.duration) );
+ }
+ else
+ {
+ anim.Animate( actor, path, forward );
+ }
+}
+
+/**
+ *
+ * Animate a property value by a relative amount.
+ *
+ * The effect will start & end when the animation begins & ends.
+ * @method animateBy
+ * @for Animation
+ * @param {Object} target object that contains a property to be animated (e.g. myActor )
+ * @param {String} property name (e.g. "position" )
+ * @param {Object} relativeValue The property value will change by this amount.
+ * @param {Object} [options] Animation options.
+ * @param {Float} [options.delay] amount to delay the start of the animation in seconds
+ * @param {Float} [options.duration] duration of the animation
+ * @param {String} [options.alpha] Animation alpha function (e.g. "linear")
+ *
+ * @example
+ *
+ * // animation x position
+ * var anim = new dali.Animation( 1 );
+ * anim.animateBy( imageActor,"positionX", 30 );
+ * anim.play();
+ *
+ * // animate x,y,z position with the optional animation options
+ * var options = {
+ * delay: 3, // 3 second delay before starting
+ * duration: 5, // 5 second duration
+ * alpha:"easeInOutSine" // Speeds up and slows to a gradual stop
+ * }
+ *
+ * anim.animateBy( imageActor,"position", [100,200,0], options );
+ *
+ */
+void AnimationApi::AnimateBy( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Animation anim = GetAnimation( isolate, args );
+ AnimationParameters animParams( anim );
+
+ // grab all the parameters
+ bool ok = GetAnimationParameters( isolate, args, animParams, AnimationApi::PROPERTY_VALUE);
+ if( !ok )
+ {
+ // GetAnimationParameters will log
+ return;
+ }
+
+ if( animParams.optionsFound )
+ {
+ anim.AnimateBy( Property( animParams.target, animParams.propertyIndex ),
+ animParams.value,
+ animParams.alphaFunction,
+ TimePeriod( animParams.delay, animParams.duration) );
+ }
+ else
+ {
+ anim.AnimateBy( Property( animParams.target, animParams.propertyIndex ), animParams.value );
+ }
+
+}
+
+/**
+ *
+ * Animate a property to a destination value.
+ *
+ * The effect will start & end when the animation begins & ends.
+ * @method animateTo
+ * @for Animation
+ * @param {Object} target object that contains a property to be animated (e.g. myActor )
+ * @param {String} property name (e.g. "position" )
+ * @param {Object} destinationValue The property value will changed to this value
+ * @param {Object} [options] Animation options.
+ * @param {Float} [options.delay] amount to delay the start of the animation in seconds
+ * @param {Float} [options.duration] duration of the animation
+ * @param {String} [options.alpha] Animation alpha function (e.g. "linear")
+ *
+ * @example
+ *
+ * var anim = new dali.Animation( 1 );
+ * anim.animateTo( imageActor,"positionX", 30 );
+ * anim.play();
+ *
+ *
+ * // with the optional animation options object
+ * var options = {
+ * delay: 3, // 3 second delay before starting
+ * duration: 5, // 5 second duration
+ * alpha:"easeInOutSine" // Speeds up and slows to a gradual stop
+ * }
+ *
+ * anim.animateTo( imageActor,"position", [100,200,0], options );
+ *
+ */
+void AnimationApi::AnimateTo( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Animation anim = GetAnimation( isolate, args );
+ AnimationParameters animParams( anim );
+
+ // grab all the parameters
+ bool ok = GetAnimationParameters( isolate, args, animParams, AnimationApi::PROPERTY_VALUE );
+ if( !ok )
+ {
+ // GetAnimationParameters will log
+ return;
+ }
+
+ if( animParams.optionsFound )
+ {
+
+ anim.AnimateTo( Property( animParams.target,animParams.propertyIndex ),
+ animParams.value,
+ animParams.alphaFunction,
+ TimePeriod( animParams.delay, animParams.duration) );
+ }
+ else
+ {
+ anim.AnimateTo( Property( animParams.target, animParams.propertyIndex ), animParams.value );
+ }
+}
+
+/**
+ *
+ * Animate a property between keyframes.
+ *
+ * The effect will start & end when the animation begins & ends.
+ * @method animateBetween
+ * @for Animation
+ * @param {Object} target object that contains a property to be animated (e.g. myActor )
+ * @param {String} property name (e.g. "position" )
+ * @param {Object} keyframes array of keyframe objects
+ * @param {Object} [options] Animation options.
+ * @param {Float} [options.delay] amount to delay the start of the animation in seconds
+ * @param {Float} [options.duration] duration of the animation
+ * @param {String} [options.alpha] Animation alpha function (e.g. "linear")
+ *
+ *
+ * @example
+ *
+ * create some keyframes to move an actor around a square, and return to the start
+ * </br >
+ * <img src="../assets/img/keyframe-animation.png">
+ *
+ *
+ * var keyframes = [
+ * {
+ * progress:0.0,
+ * value: [0,0,0]
+ * },
+ * {
+ * progress:0.25,
+ * value: [500,0,0]
+ * },
+ *
+ * {
+ * progress:0.5,
+ * value: [500,500,0]
+ * },
+ * {
+ * progress:0.75,
+ * value: [0,500,0]
+ * },
+ * {
+ * progress:1.0,
+ * value: [0,0,0]
+ * } ];
+ *
+ *
+ * anim.animateBetween( imageActor,"position", keyframes );
+ *
+ */
+void AnimationApi::AnimateBetween( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Animation anim = GetAnimation( isolate, args );
+ AnimationParameters animParams( anim );
+
+ // grab all the parameters
+ bool ok = GetAnimationParameters( isolate, args, animParams, AnimationApi::KEYFRAMES );
+ if( !ok )
+ {
+ // GetAnimationParameters will log
+ return;
+ }
+
+ // if animation options exist...
+ if( animParams.optionsFound )
+ {
+
+ anim.AnimateBetween( Property( animParams.target,animParams.propertyIndex ),
+ animParams.keyFrames,
+ animParams.alphaFunction,
+ TimePeriod( animParams.delay, animParams.duration) );
+ }
+ else
+ {
+ anim.AnimateBetween( Property( animParams.target, animParams.propertyIndex ), animParams.keyFrames );
+ }
+}
+
+/**
+ * show an actor during the animation.
+ *
+ * This is a helper, which simulates animating the visibility property of an actor
+ * with zero duration ( it is just a boolean).
+ * e.g. it performs anim.AnimateTo( actor,"visible",true, { delay:delay: duration:0 } );
+ * @method show
+ * @for Animation
+ * @param {Object} Actor
+ * @param {float} delay until the actor is shown
+ */
+void AnimationApi::Show( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Animation anim = GetAnimation( isolate, args );
+ bool found( false );
+
+ Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
+ if( !found)
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 0 actor" );
+ return;
+ }
+ // get the duration
+ float delay = V8Utils::GetFloatParameter( PARAMETER_1, found, isolate, args, 1.f /* default */);
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 1 delay" );
+ return;
+ }
+ anim.Show( actor, delay );
+
+}
+
+/**
+ * hide an actor during the animation.
+ *
+ * This is a helper, which simulates animating the visibility property of an actor
+ * with zero duration ( it is just a boolean).
+ * e.g. it performs anim.AnimateTo( actor,"visible",false, { delay:delay: duration:0 } );
+ * @method hide
+ * @for Animation
+ * @param {Object} Actor
+ * @param {float} delay until the actor is hidden
+ */
+void AnimationApi::Hide( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Animation anim = GetAnimation( isolate, args );
+ bool found( false );
+ Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 0 actor" );
+ return;
+ }
+
+ // get the duration
+ float delay = V8Utils::GetFloatParameter( PARAMETER_1, found, isolate, args, 1.f /* default */);
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 1 delay" );
+ return;
+ }
+ anim.Hide( actor, delay );
+}
+
+
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_ANIMATION_API_H__
+#define __DALI_V8PLUGIN_ANIMATION_API_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/public-api/animation/animation.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace AnimationApi
+{
+ /**
+ * Constructor
+ */
+ Animation New( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+
+ /**
+ * Animation API see animation.h for a description
+ */
+ void SetDuration( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetDuration( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetLooping( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void IsLooping( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetEndAction( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetEndAction( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetDisconnectAction( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetDisconnectAction( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetDefaultAlphaFunction( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetDefaultAlphaFunction( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetCurrentProgress( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetSpeedFactor( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetSpeedFactor( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetPlayRange( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetPlayRange( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetCurrentProgress( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void PlayFrom( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void Play( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void Pause( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void Stop( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void Clear( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void Animate( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void AnimateBy( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void AnimateTo( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void AnimateBetween( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void Show( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void Hide( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ enum AnimationParameterType
+ {
+ PROPERTY_VALUE,
+ KEYFRAMES
+ };
+
+}; // namespace AnimationApi
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header __DALI_V8PLUGIN_ANIMATION_API_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "animation-wrapper.h"
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <dali-wrapper.h>
+#include <animation/animation-api.h>
+#include <shared/api-function.h>
+#include <shared/object-template-helper.h>
+
+namespace Dali
+{
+namespace V8Plugin
+{
+
+v8::Persistent<v8::ObjectTemplate> AnimationWrapper::mAnimationTemplate;
+
+namespace
+{
+
+/**
+ * Contains a list of all functions that can be called
+ */
+const ApiFunction AnimationFunctionTable[]=
+{
+ /**************************************
+ * Animation API (in order of animation.h)
+ **************************************/
+
+ { "SetDuration" , AnimationApi::SetDuration },
+ { "GetDuration" , AnimationApi::GetDuration },
+ { "SetLooping" , AnimationApi::SetLooping },
+ { "IsLooping" , AnimationApi::IsLooping },
+ { "SetEndAction" , AnimationApi::SetEndAction },
+ { "GetEndAction" , AnimationApi::GetEndAction },
+ { "SetDisconnectAction" , AnimationApi::SetDisconnectAction },
+ { "GetDisconnectAction" , AnimationApi::GetDisconnectAction },
+ { "SetDefaultAlphaFunction" , AnimationApi::SetDefaultAlphaFunction },
+ { "GetDefaultAlphaFunction" , AnimationApi::GetDefaultAlphaFunction },
+ { "GetCurrentProgress" , AnimationApi::GetCurrentProgress },
+ { "SetSpeedFactor" , AnimationApi::SetSpeedFactor },
+ { "GetSpeedFactor" , AnimationApi::GetSpeedFactor },
+ { "SetPlayRange" , AnimationApi::SetPlayRange },
+ { "GetPlayRange" , AnimationApi::GetPlayRange },
+ { "SetCurrentProgress" , AnimationApi::SetCurrentProgress },
+ { "Play" , AnimationApi::Play },
+ { "PlayFrom" , AnimationApi::PlayFrom },
+ { "Pause" , AnimationApi::Pause },
+ { "Stop" , AnimationApi::Stop },
+ { "Clear" , AnimationApi::Clear },
+ { "Animate" , AnimationApi::Animate },
+ { "AnimateBy" , AnimationApi::AnimateBy },
+ { "AnimateTo" , AnimationApi::AnimateTo },
+ { "AnimateBetween" , AnimationApi::AnimateBetween },
+ { "Show" , AnimationApi::Show },
+ { "Hide" , AnimationApi::Hide },
+
+};
+
+const unsigned int AnimationFunctionTableCount = sizeof(AnimationFunctionTable)/sizeof(AnimationFunctionTable[0]);
+} //un-named space
+
+
+AnimationWrapper::AnimationWrapper( const Dali::Animation& animation, GarbageCollectorInterface& gc )
+: BaseWrappedObject( BaseWrappedObject::ANIMATION , gc )
+{
+ mAnimation = animation;
+}
+
+AnimationWrapper::~AnimationWrapper()
+{
+
+}
+
+v8::Handle<v8::Object> AnimationWrapper::WrapAnimation(v8::Isolate* isolate, const Dali::Animation& animation )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::ObjectTemplate> objectTemplate;
+
+ objectTemplate = GetAnimationTemplate( isolate);
+
+ // create an instance of the template
+ v8::Local<v8::Object> localObject = objectTemplate->NewInstance();
+
+ // create the Animation wrapper
+ AnimationWrapper* pointer = new AnimationWrapper( animation, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() );
+
+ // assign the JavaScript object to the wrapper.
+ pointer->SetJavascriptObject( isolate, localObject );
+
+ return handleScope.Escape( localObject );
+}
+
+v8::Local<v8::ObjectTemplate> AnimationWrapper::GetAnimationTemplate( v8::Isolate* isolate)
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::ObjectTemplate> objectTemplate;
+
+ if( mAnimationTemplate.IsEmpty() )
+ {
+ objectTemplate = MakeAnimationTemplate( isolate );
+ mAnimationTemplate.Reset( isolate, objectTemplate );
+ }
+ else
+ {
+ // get the object template
+ objectTemplate = v8::Local<v8::ObjectTemplate>::New( isolate, mAnimationTemplate );
+ }
+ return handleScope.Escape( objectTemplate );
+}
+
+v8::Handle<v8::ObjectTemplate> AnimationWrapper::MakeAnimationTemplate( v8::Isolate* isolate )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+
+ v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
+
+ // add intercepts for Signals, we can't use HandleWrapper::AddIntercepts because Animation doesn't inherit
+ // from Handle ( just baseHandle)
+ ObjectTemplateHelper::AddSignalConnectAndDisconnect( isolate, objTemplate );
+
+ objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT );
+
+ // add our function properties
+ ObjectTemplateHelper::InstallFunctions( isolate, objTemplate, AnimationFunctionTable, AnimationFunctionTableCount );
+
+ return handleScope.Escape( objTemplate );
+}
+
+void AnimationWrapper::NewAnimation( const v8::FunctionCallbackInfo< v8::Value >& args)
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate);
+
+ if( !args.IsConstructCall() )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Animation constructor called without 'new'" );
+ return;
+ }
+
+ Dali::Animation animation = AnimationApi::New( args );
+ v8::Local<v8::Object> localObject = WrapAnimation( isolate, animation );
+ args.GetReturnValue().Set( localObject );
+}
+
+
+Animation AnimationWrapper::GetAnimation()
+{
+ return mAnimation;
+}
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_ANIMATION_WRAPPER_H__
+#define __DALI_V8PLUGIN_ANIMATION_WRAPPER_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/public-api/animation/animation.h>
+
+// INTERNAL INCLUDES
+#include <shared/base-wrapped-object.h>
+#include <signals/signal-manager.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+/**
+ * Animation wrapper.
+ * Provides access to Animation specific functionality
+ */
+class AnimationWrapper : public BaseWrappedObject
+{
+
+public:
+
+ AnimationWrapper( const Animation& animation,
+ GarbageCollectorInterface& gc );
+
+ virtual ~AnimationWrapper();
+
+ /**
+ * @brief Creates a new Animation wrapped inside a Javascript Object.
+ * @param[in] args v8 function call arguments interpreted
+ */
+ static void NewAnimation( const v8::FunctionCallbackInfo< v8::Value >& args);
+
+ /**
+ * Wraps an animation
+ */
+ static v8::Handle<v8::Object> WrapAnimation(v8::Isolate* isolate, const Dali::Animation& );
+
+
+ // The AnimationAttribute ObjectTemplate, we cache templates so we don't have
+ // keep generating them everytime we want to create an Animation
+ static v8::Persistent<v8::ObjectTemplate> mAnimationTemplate;
+
+ Animation GetAnimation();
+ virtual SignalManager* GetSignalManager() { return &mSignalManager;}
+
+private:
+
+ Animation mAnimation; ///< animation object
+ SignalManager mSignalManager; ///< signal manager
+
+ static v8::Handle<v8::ObjectTemplate> MakeAnimationTemplate( v8::Isolate* isolate );
+ static v8::Local<v8::ObjectTemplate> GetAnimationTemplate( v8::Isolate* isolate );
+
+};
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // __DALI_V8PLUGIN_ANIMATION_WRAPPER_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "path-api.h"
+
+// INTERNAL INCLUDES
+#include <animation/path-wrapper.h>
+#include <object/property-value-wrapper.h>
+#include <v8-utils.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace // un named namespace
+{
+
+Path GetPath( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::HandleScope handleScope( isolate );
+
+ v8::Local<v8::Object> object = args.This();
+ v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField( 0 ) );
+ void* ptr = field->Value();
+
+ PathWrapper* wrapper = static_cast<PathWrapper *>( ptr );
+ return wrapper->GetPath();
+}
+
+} // un-named namespace
+
+
+/**
+ * Automatic generation of control points. Generated control points which result in a smooth join between the splines of each segment.
+ *
+ * The generating algorithm is as follows:
+ * For a given knot point K[N], find the vector that bisects K[N-1],[N] and [N],[N+1].
+ * Calculate the tangent vector by taking the normal of this bisector.
+ * The in control point is the length of the preceding segment back along this bisector multiplied by the curvature
+ * The out control point is the length of the succeeding segment forward along this bisector multiplied by the curvature
+ *
+ * @method generateControlPoints
+ * @for Path
+ * @param {float} curvature curvature The curvature of the spline. 0 gives straight lines between the knots,
+ * negative values means the spline contains loops, positive values up to
+ * 0.5 result in a smooth curve, positive values between 0.5 and 1 result
+ * in looped curves where the loops are not distinct (i.e. the curve appears
+ * to be non-continuous), positive values higher than 1 result in looped curves.
+ */
+void PathApi::GenerateControlPoints( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ bool found( false );
+ float curvature = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 1.0f /* default */);
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
+ return;
+ }
+
+ Path path = GetPath( isolate, args );
+ path.GenerateControlPoints( curvature );
+}
+
+
+/**
+ * Add a interpolation point.
+ * @method addPoint
+ * @for Path
+ * @param {Vector3} interpolationPoint The new interpolation point to be added
+ * @example
+ * path.addPoint([ 10,40,0] );
+ */
+void PathApi::AddPoint( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ bool found( false );
+ Vector3 value = V8Utils::GetVector3Parameter( PARAMETER_0, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
+ return;
+ }
+
+ Path path = GetPath( isolate, args );
+ path.AddPoint( value );
+}
+
+
+/**
+ * Add a control point.
+ * @method addControlPoint
+ * @for Path
+ * @param {Vector3} controlPoint The new control point to be added
+ * @example
+ * path.addControlPoint([ 10,40,0] );
+ */
+void PathApi::AddControlPoint( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ bool found( false );
+ Vector3 value = V8Utils::GetVector3Parameter( PARAMETER_0, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
+ return;
+ }
+
+ Path path = GetPath( isolate, args );
+ path.AddControlPoint( value );
+}
+
+/**
+ * Sample path at a given progress. Calculates position and tangent at that point of the curve
+ * @method sample
+ * @for Path
+ * @param {float} Progress A floating point value between 0.0 and 1.0.
+ * @return {Object} { position: Vector3, tangent:Vector3 }
+ */
+void PathApi::Sample( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ bool found( false );
+ float progress = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 0.0f /* default */);
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
+ return;
+ }
+
+ //Sample the path
+ Path path = GetPath( isolate, args );
+ Vector3 position, tangent;
+ path.Sample( progress, position, tangent );
+
+ //Create v8 object with the result
+ v8::Local<v8::Object> sampleObject = v8::Object::New( isolate );
+
+ Dali::Property::Value valuePosition( position );
+ sampleObject->Set( v8::String::NewFromUtf8( isolate, "position"), PropertyValueWrapper::WrapDaliProperty( isolate, valuePosition));
+
+ Dali::Property::Value valueTangent( tangent );
+ sampleObject->Set( v8::String::NewFromUtf8( isolate, "tangent"), PropertyValueWrapper::WrapDaliProperty( isolate, valueTangent));
+
+ args.GetReturnValue().Set( sampleObject );
+}
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_PATH_API_H__
+#define __DALI_V8PLUGIN_PATH_API_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/public-api/animation/path.h>
+
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace PathApi
+{
+ /**
+ * Path API see path.h for a description
+ */
+ void GenerateControlPoints( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void AddPoint( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void AddControlPoint( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void Sample( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+}; // namespace PathApi
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header __DALI_V8PLUGIN_PATH_API_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "path-wrapper.h"
+
+// INTERNAL INCLUDES
+#include <animation/path-api.h>
+#include <v8-utils.h>
+#include <dali-wrapper.h>
+#include <shared/object-template-helper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace
+{
+
+const ApiFunction PathFunctions[]=
+{
+ { "GenerateControlPoints", PathApi::GenerateControlPoints },
+ { "AddPoint", PathApi::AddPoint },
+ { "AddControlPoint", PathApi::AddControlPoint },
+ { "Sample", PathApi::Sample }
+};
+
+const unsigned int PathFunctionTableCount = sizeof(PathFunctions)/sizeof(PathFunctions[0]);
+} //un-named space
+
+
+PathWrapper::PathWrapper( Path path, GarbageCollectorInterface& gc )
+:HandleWrapper( BaseWrappedObject::PATH, path, gc ),
+ mPath( path )
+{
+}
+
+v8::Handle<v8::ObjectTemplate> PathWrapper::MakePathTemplate( v8::Isolate* isolate )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+
+ v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
+ objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT );
+
+ // add our function properties
+ ObjectTemplateHelper::InstallFunctions( isolate, objTemplate, PathFunctions, PathFunctionTableCount );
+
+ // property handle intercepts property getters and setters and signals
+ HandleWrapper::AddInterceptsToTemplate( isolate, objTemplate );
+
+ return handleScope.Escape( objTemplate );
+}
+
+v8::Handle<v8::Object> PathWrapper::WrapPath( v8::Isolate* isolate, Path path )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::ObjectTemplate> objectTemplate;
+
+ objectTemplate = MakePathTemplate( isolate );
+
+ // create an instance of the template
+ v8::Local<v8::Object> localObject = objectTemplate->NewInstance();
+
+ // create teh actor object
+ PathWrapper* pointer = new PathWrapper( path, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() );
+
+ // assign the JavaScript object to the wrapper.
+ // This also stores Dali object, in an internal field inside the JavaScript object.
+ pointer->SetJavascriptObject( isolate, localObject );
+
+ return handleScope.Escape( localObject );
+}
+
+Path PathWrapper::GetPath()
+{
+ return mPath;
+}
+
+/**
+ * Create an initialized Path handle.
+ * @constructor
+ * @for Path
+ * @method Path
+ */
+void PathWrapper::NewPath( const v8::FunctionCallbackInfo< v8::Value >& args)
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ if( !args.IsConstructCall() )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "constructor called without 'new" );
+ return;
+ }
+
+ // Create a new path
+ Path path = Path::New();
+ v8::Local<v8::Object> localObject = WrapPath( isolate, path );
+ args.GetReturnValue().Set( localObject );
+}
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_PATH_WRAPPER_H__
+#define __DALI_V8PLUGIN_PATH_WRAPPER_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/public-api/animation/path.h>
+
+// INTERNAL INCLUDES
+#include <object/handle-wrapper.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+/**
+ * Wraps a Path.
+ */
+class PathWrapper : public HandleWrapper
+{
+
+public:
+
+ /**
+ * Constructor
+ */
+ PathWrapper( Path path, GarbageCollectorInterface& gc );
+
+ /**
+ * Virtual destructor
+ */
+ virtual ~PathWrapper(){};
+
+ /**
+ * Creates a new Path wrapped inside a Javascript Object.
+ * @param[in] args v8 function call arguments interpreted
+ */
+ static void NewPath( const v8::FunctionCallbackInfo< v8::Value >& args);
+
+ /**
+ * Wraps a path inside a Javascript object
+ */
+ static v8::Handle<v8::Object> WrapPath(v8::Isolate* isolate, Path path );
+
+ /*
+ * Get the wrapped path
+ */
+ Path GetPath();
+
+private:
+
+ /**
+ * Create a v8 object template for the path
+ */
+ static v8::Handle<v8::ObjectTemplate> MakePathTemplate( v8::Isolate* isolate );
+
+ Path mPath;
+};
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "constants-wrapper.h"
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/common/constants.h>
+#include <dali/public-api/math/vector3.h>
+#include <dali/public-api/animation/animation.h>
+#include <dali/public-api/images/pixel.h>
+#include <dali/public-api/images/image.h>
+#include <dali/public-api/images/resource-image.h>
+#include <dali/public-api/actors/actor-enumerations.h>
+#include <dali/public-api/actors/draw-mode.h>
+#include <dali/public-api/actors/image-actor.h>
+#include <dali/public-api/actors/blending.h>
+#include <dali/public-api/actors/renderable-actor.h>
+#include <dali/public-api/actors/camera-actor.h>
+#include <dali/public-api/render-tasks/render-task.h>
+#include <dali/public-api/common/loading-state.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace
+{
+
+struct Vector3Pair
+{
+ const char* name;
+ const Vector3& value;
+};
+
+struct Vector4Pair
+{
+ const char* name;
+ const Vector4& value;
+};
+
+struct IntegerPair
+{
+ const char* name;
+ const int value;
+};
+
+
+const Vector3Pair Vector3Table[] =
+{
+ { "BACK_TOP_LEFT" , ParentOrigin::BACK_TOP_LEFT },
+ { "BACK_TOP_CENTER" , ParentOrigin::BACK_TOP_CENTER },
+ { "BACK_TOP_RIGHT" , ParentOrigin::BACK_TOP_RIGHT },
+ { "BACK_CENTER_LEFT" , ParentOrigin::BACK_CENTER_LEFT },
+ { "BACK_CENTER" , ParentOrigin::BACK_CENTER },
+ { "BACK_CENTER_RIGHT" , ParentOrigin::BACK_CENTER_RIGHT },
+ { "BACK_BOTTOM_LEFT" , ParentOrigin::BACK_BOTTOM_LEFT },
+ { "BACK_BOTTOM_CENTER" , ParentOrigin::BACK_BOTTOM_CENTER },
+ { "BACK_BOTTOM_RIGHT" , ParentOrigin::BACK_BOTTOM_RIGHT },
+
+ { "TOP_LEFT" , ParentOrigin::TOP_LEFT },
+ { "TOP_CENTER" , ParentOrigin::TOP_CENTER },
+ { "TOP_RIGHT" , ParentOrigin::TOP_RIGHT },
+ { "CENTER_LEFT" , ParentOrigin::CENTER_LEFT },
+ { "CENTER" , ParentOrigin::CENTER },
+ { "CENTER_RIGHT" , ParentOrigin::CENTER_RIGHT },
+ { "BOTTOM_LEFT" , ParentOrigin::BOTTOM_LEFT },
+ { "BOTTOM_CENTER" , ParentOrigin::BOTTOM_CENTER },
+ { "BOTTOM_RIGHT" , ParentOrigin::BOTTOM_RIGHT },
+
+ { "FRONT_TOP_LEFT" , ParentOrigin::FRONT_TOP_LEFT },
+ { "FRONT_TOP_CENTER" , ParentOrigin::FRONT_TOP_CENTER },
+ { "FRONT_TOP_RIGHT" , ParentOrigin::FRONT_TOP_RIGHT },
+ { "FRONT_CENTER_LEFT" , ParentOrigin::FRONT_CENTER_LEFT },
+ { "FRONT_CENTER" , ParentOrigin::FRONT_CENTER },
+ { "FRONT_CENTER_RIGHT" , ParentOrigin::FRONT_CENTER_RIGHT },
+ { "FRONT_BOTTOM_LEFT" , ParentOrigin::FRONT_BOTTOM_LEFT },
+ { "FRONT_BOTTOM_CENTER" , ParentOrigin::FRONT_BOTTOM_CENTER},
+ { "FRONT_BOTTOM_RIGHT" , ParentOrigin::FRONT_BOTTOM_RIGHT },
+
+
+ { "VECTOR3_ONE" , Vector3::ONE },
+ { "VECTOR3_XAXIS" , Vector3::XAXIS },
+ { "VECTOR3_YAXIS" , Vector3::YAXIS },
+ { "VECTOR3_ZAXIS" , Vector3::ZAXIS },
+ { "VECTOR3_NEGATIVE_XAXIS" , Vector3::NEGATIVE_XAXIS },
+ { "VECTOR3_NEGATIVE_YAXIS" , Vector3::NEGATIVE_YAXIS },
+ { "VECTOR3_NEGATIVE_ZAXIS" , Vector3::NEGATIVE_ZAXIS },
+ { "VECTOR3_ZERO" , Vector3::ZERO }
+
+
+};
+
+const unsigned int Vector3TableCount = sizeof(Vector3Table)/sizeof(Vector3Table[0]);
+
+const Vector4Pair Vector4Table[] =
+{
+ { "COLOR_BLACK" , Color::BLACK },
+ { "COLOR_WHITE" , Color::WHITE },
+ { "COLOR_RED" , Color::RED },
+ { "COLOR_GREEN" , Color::GREEN },
+ { "COLOR_BLUE" , Color::BLUE },
+ { "COLOR_YELLOW" , Color::YELLOW },
+ { "COLOR_MAGENTA" , Color::MAGENTA },
+ { "COLOR_CYAN" , Color::CYAN },
+ { "COLOR_TRANSPARENT" , Color::TRANSPARENT }
+
+};
+
+const unsigned int Vector4TableCount = sizeof(Vector4Table)/sizeof(Vector4Table[0]);
+
+const IntegerPair EnumTable[] =
+{
+
+ { "ANIMATION_BAKE", Animation::Bake },
+ { "ANIMATION_DISCARD", Animation::Discard },
+ { "ANIMATION_BAKE_FINAL", Animation::BakeFinal },
+ { "REFRESH_ONCE", RenderTask::REFRESH_ONCE },
+ { "REFRESH_ALWAYS", RenderTask::REFRESH_ALWAYS },
+
+ { "PIXEL_FORMAT_A8", Pixel::A8, },
+ { "PIXEL_FORMAT_L8", Pixel::L8, },
+ { "PIXEL_FORMAT_LA88", Pixel::LA88, },
+ { "PIXEL_FORMAT_RGB565", Pixel::RGB565, },
+ { "PIXEL_FORMAT_BGR565", Pixel::BGR565, },
+ { "PIXEL_FORMAT_RGBA4444", Pixel::RGBA4444, },
+ { "PIXEL_FORMAT_BGRA4444", Pixel::BGRA4444, },
+ { "PIXEL_FORMAT_RGBA5551", Pixel::RGBA5551, },
+ { "PIXEL_FORMAT_BGRA5551", Pixel::BGRA5551, },
+ { "PIXEL_FORMAT_RGB888", Pixel::RGB888, },
+ { "PIXEL_FORMAT_RGB8888", Pixel::RGB8888, },
+ { "PIXEL_FORMAT_BGR8888", Pixel::BGR8888, },
+ { "PIXEL_FORMAT_RGBA8888", Pixel::RGBA8888, },
+ { "PIXEL_FORMAT_BGRA8888", Pixel::BGRA8888, },
+
+ { "PIXEL_FORMAT_COMPRESSED_R11_EAC", Pixel::COMPRESSED_R11_EAC, },
+ { "PIXEL_FORMAT_COMPRESSED_SIGNED_R11_EAC", Pixel::COMPRESSED_SIGNED_R11_EAC, },
+ { "PIXEL_FORMAT_COMPRESSED_RG11_EAC", Pixel::COMPRESSED_RG11_EAC, },
+ { "PIXEL_FORMAT_COMPRESSED_SIGNED_RG11_EAC", Pixel::COMPRESSED_SIGNED_RG11_EAC, },
+ { "PIXEL_FORMAT_COMPRESSED_RGB8_ETC2", Pixel::COMPRESSED_RGB8_ETC2, },
+ { "PIXEL_FORMAT_COMPRESSED_SRGB8_ETC2", Pixel::COMPRESSED_SRGB8_ETC2, },
+ { "PIXEL_FORMAT_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2", Pixel::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, },
+ { "PIXEL_FORMAT_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2",Pixel::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2},
+ { "PIXEL_FORMAT_COMPRESSED_RGBA8_ETC2_EAC", Pixel::COMPRESSED_RGBA8_ETC2_EAC, },
+ { "PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC", Pixel::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, },
+ { "PIXEL_FORMAT_COMPRESSED_RGB8_ETC1", Pixel::COMPRESSED_RGB8_ETC1, },
+ { "PIXEL_FORMAT_COMPRESSED_RGB_PVRTC_4BPPV1", Pixel::COMPRESSED_RGB_PVRTC_4BPPV1 },
+
+
+ { "COLOR_MODE_USE_OWN_COLOR", USE_OWN_COLOR },
+ { "COLOR_MODE_USE_PARENT_COLOR", USE_PARENT_COLOR },
+ { "COLOR_MODE_USE_OWN_MULTIPLY_PARENT_COLOR", USE_OWN_MULTIPLY_PARENT_COLOR },
+ { "COLOR_MODE_USE_OWN_MULTIPLY_PARENT_ALPHA", USE_OWN_MULTIPLY_PARENT_ALPHA },
+
+
+ { "POSITION_INHERITANCE_INHERIT_PARENT_POSITION", INHERIT_PARENT_POSITION },
+ { "POSITION_INHERITANCE_USE_PARENT_POSITION", USE_PARENT_POSITION },
+ { "POSITION_INHERITANCE_USE_PARENT_POSITION_PLUS_LOCAL_POSITION", USE_PARENT_POSITION_PLUS_LOCAL_POSITION },
+ { "POSITION_INHERITANCE_DONT_INHERIT_POSITION", DONT_INHERIT_POSITION },
+
+ { "DRAW_MODE_NORMAL", DrawMode::NORMAL },
+ { "DRAW_MODE_OVERLAY", DrawMode::OVERLAY },
+ { "DRAW_MODE_STENCIL", DrawMode::STENCIL },
+
+ { "IMAGE_LOAD_POLICY_IMMEDIATE", ResourceImage::IMMEDIATE },
+ { "IMAGE_LOAD_POLICY_ON_DEMAND", ResourceImage::ON_DEMAND },
+
+ { "IMAGE_RELEASE_POLICY_UNUSED", Image::UNUSED },
+ { "IMAGE_RELEASE_POLICY_NEVER", Image::NEVER },
+
+ { "RESOURCE_LOADING", Dali::ResourceLoading },
+ { "RESOURCE_LOADING_SUCCEEDED", Dali::ResourceLoadingSucceeded },
+ { "RESOUCE_LOADING_FAILED", Dali::ResourceLoadingFailed },
+
+
+
+
+ { "BLEND_FACTOR_ZERO", BlendingFactor::ZERO },
+ { "BLEND_FACTOR_ONE", BlendingFactor::ONE },
+ { "BLEND_FACTOR_SRC_COLOR", BlendingFactor::SRC_COLOR },
+ { "BLEND_FACTOR_ONE_MINUS_SRC_COLOR", BlendingFactor::ONE_MINUS_SRC_COLOR },
+ { "BLEND_FACTOR_SRC_ALPHA", BlendingFactor::SRC_ALPHA },
+ { "BLEND_FACTOR_ONE_MINUS_SRC_ALPHA", BlendingFactor::ONE_MINUS_SRC_ALPHA },
+ { "BLEND_FACTOR_DST_ALPHA", BlendingFactor::DST_ALPHA },
+ { "BLEND_FACTOR_ONE_MINUS_DST_ALPHA", BlendingFactor::ONE_MINUS_DST_ALPHA },
+ { "BLEND_FACTOR_DST_COLOR", BlendingFactor::DST_COLOR },
+ { "BLEND_FACTOR_ONE_MINUS_DST_COLOR", BlendingFactor::ONE_MINUS_DST_COLOR },
+ { "BLEND_FACTOR_SRC_ALPHA_SATURATE", BlendingFactor::SRC_ALPHA_SATURATE },
+ { "BLEND_FACTOR_CONSTANT_COLOR", BlendingFactor::CONSTANT_COLOR },
+ { "BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR", BlendingFactor::ONE_MINUS_CONSTANT_COLOR },
+ { "BLEND_FACTOR_CONSTANT_ALPHA" , BlendingFactor::CONSTANT_ALPHA },
+ { "BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA", BlendingFactor::ONE_MINUS_CONSTANT_ALPHA },
+
+ { "BLENDING_OFF", BlendingMode::OFF },
+ { "BLENDING_AUTO", BlendingMode::AUTO },
+ { "BLENDING_ON", BlendingMode::ON },
+
+ { "BLEND_EQUATION_ADD", BlendingEquation::ADD },
+ { "BLEND_EQUATION_SUBTRACT", BlendingEquation::SUBTRACT },
+ { "BLEND_EQUATION_REVERSE_SUBTRACT", BlendingEquation::REVERSE_SUBTRACT },
+
+
+ { "CULL_FACE_DISABLE", CullNone },
+ { "CULL_FRONT_FACE", CullFront },
+ { "CULL_BACK_FACE", CullBack },
+ { "CULL_FRONT_AND_BACK_FACE", CullFrontAndBack },
+
+ { "USE_OWN_SIZE", USE_OWN_SIZE },
+ { "SIZE_EQUAL_TO_PARENT", SIZE_EQUAL_TO_PARENT },
+ { "SIZE_RELATIVE_TO_PARENT", SIZE_RELATIVE_TO_PARENT },
+ { "SIZE_FIXED_OFFSET_FROM_PARENT", SIZE_FIXED_OFFSET_FROM_PARENT },
+
+ { "CAMERA_FREE_LOOK" , Camera::FREE_LOOK },
+ { "CAMERA_LOOK_AT_TARGET" , Camera::LOOK_AT_TARGET },
+ { "CAMERA_PERSPECTIVE_PROJECTION" , Camera::PERSPECTIVE_PROJECTION },
+ { "CAMERA_ORTHOGRAPHIC_PROJECTION", Camera::ORTHOGRAPHIC_PROJECTION },
+
+ {"IMAGE_ACTOR_STYLE_QUAD", ImageActor::STYLE_QUAD},
+ {"IMAGE_ACTOR_STYLE_NINE_PATCH", ImageActor::STYLE_NINE_PATCH},
+ {"IMAGE_ACTOR_STYLE_NINE_PATCH_NO_CENTER",ImageActor::STYLE_NINE_PATCH_NO_CENTER }
+
+
+};
+const unsigned int EnumTableCount = sizeof(EnumTable)/sizeof(EnumTable[0]);
+
+
+
+
+
+
+} // un-named name space
+
+
+void ConstantsWrapper::AddDaliConstants( v8::Isolate* isolate, v8::Local<v8::Object >& obj )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+
+
+ for( unsigned int i = 0; i < EnumTableCount; ++i )
+ {
+ obj->Set( v8::String::NewFromUtf8( isolate, EnumTable[i].name ),
+ v8::Integer::New(isolate, EnumTable[i].value ) );
+ }
+
+ for( unsigned int i = 0; i < Vector3TableCount; ++i )
+ {
+ // create a JavaScript array object with 3 entries.
+ v8::Local<v8::Array> array = v8::Array::New( isolate ,3 );
+ array->Set( 0 , v8::Number::New(isolate, Vector3Table[i].value.x ));
+ array->Set( 1 , v8::Number::New(isolate, Vector3Table[i].value.y ));
+ array->Set( 2 , v8::Number::New(isolate, Vector3Table[i].value.z ));
+
+ obj->Set( v8::String::NewFromUtf8( isolate, Vector3Table[i].name),
+ array);
+ }
+
+
+ for( unsigned int i = 0; i < Vector4TableCount; ++i )
+ {
+ // create a JavaScript array object with 3 entries.
+ v8::Local<v8::Array> array = v8::Array::New( isolate ,4 );
+ array->Set( 0 , v8::Number::New(isolate, Vector4Table[i].value.x ));
+ array->Set( 1 , v8::Number::New(isolate, Vector4Table[i].value.y ));
+ array->Set( 2 , v8::Number::New(isolate, Vector4Table[i].value.z ));
+ array->Set( 3 , v8::Number::New(isolate, Vector4Table[i].value.w ));
+
+ obj->Set( v8::String::NewFromUtf8( isolate, Vector4Table[i].name),
+ array);
+ }
+
+}
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_DALI_CONSTANTS_WRAPPER
+#define __DALI_V8PLUGIN_DALI_CONSTANTS_WRAPPER
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace ConstantsWrapper
+{
+
+void AddDaliConstants( v8::Isolate* isolate, v8::Local<v8::Object >& obj );
+} // namespace ConstantsWrapper
+
+} // namespace V8Plugin
+
+} // namespace Dali
+#endif
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include "dali-script-v8.h"
+
+// EXTERNAL INCLUDES
+#include <iostream>
+#include <fstream>
+#include <dali/integration-api/debug.h>
+
+// INTERNAL INCLUDES
+#include <dali-script-v8.h>
+#include <dali-wrapper.h>
+#include <utils/v8-utils.h>
+
+// The plugin factories
+extern "C" DALI_EXPORT_API Dali::Toolkit::ScriptPlugin* CreateScriptPlugin(void)
+{
+ return new Dali::V8Plugin::DaliScriptV8;
+}
+
+extern "C" DALI_EXPORT_API void DestroyScriptPlugin(Dali::Toolkit::ScriptPlugin* plugin)
+{
+ delete plugin;
+}
+
+namespace Dali
+{
+namespace V8Plugin
+{
+
+DaliScriptV8::DaliScriptV8()
+{
+}
+
+DaliScriptV8::~DaliScriptV8()
+{
+ DaliWrapper::Get().Shutdown();
+}
+
+void DaliScriptV8::SetFlags(const std::string& s)
+{
+ DaliWrapper::Get().SetFlagsFromString(s);
+}
+
+void DaliScriptV8::ExecuteBuffer(const std::string& buffer, const std::string& filename)
+{
+ DaliWrapper::Get().ExecuteBuffer(buffer, filename);
+}
+
+void DaliScriptV8::ExecuteFile(const std::string& filename)
+{
+
+
+ DaliWrapper::Get().ExecuteFile( filename );
+}
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
--- /dev/null
+#ifndef __DALI_V8PLUGIN_SCRIPT_H__
+#define __DALI_V8PLUGIN_SCRIPT_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <dali-toolkit/public-api/scripting/script-plugin.h>
+#include <dali/public-api/common/dali-common.h>
+
+namespace Dali DALI_IMPORT_API
+{
+
+namespace V8Plugin
+{
+
+/**
+ * Executes JavaScript V8 scripts
+ */
+class DaliScriptV8 : public Dali::Toolkit::ScriptPlugin
+{
+public: // Construction & Destruction
+
+ /**
+ * Constructor
+ */
+ DaliScriptV8();
+
+ /**
+ * Destructor
+ */
+ virtual ~DaliScriptV8();
+
+public: // ScriptV8Plugin overrides
+
+ /**
+ * @copydoc Dali::Toolkit::ScriptPlugin::SetFlags()
+ */
+ virtual void SetFlags(const std::string& s);
+
+ /**
+ * @copydoc Dali::Toolkit::ScriptPlugin::ExecuteBuffer()
+ */
+ virtual void ExecuteBuffer(const std::string& buffer, const std::string& filename);
+
+ /**
+ * @copydoc Dali::Toolkit::ScriptPlugin::ExecuteFile()
+ */
+ virtual void ExecuteFile(const std::string& fileName);
+
+
+};
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // __FEEDBACK_PLUGIN_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "dali-wrapper.h"
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <object/property-value-wrapper.h>
+#include <dali/integration-api/debug.h>
+#include <actors/actor-wrapper.h>
+#include <stage/stage-wrapper.h>
+#include <image/image-attributes-wrapper.h>
+#include <image/image-wrapper.h>
+#include <text/font-wrapper.h>
+#include <animation/path-wrapper.h>
+#include <animation/animation-wrapper.h>
+#include <events/pan-gesture-detector-wrapper.h>
+#include <shader-effects/shader-effect-wrapper.h>
+#include <shared/object-template-helper.h>
+#include <constants/constants-wrapper.h>
+#include <toolkit/builder/builder-wrapper.h>
+#include <toolkit/focus-manager/keyboard-focus-manager-wrapper.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace
+{
+/**
+ * This string defines how the global DALi object/namespace is used from JavaScript
+ * E.g. new dali.Image or dali.stage.add( )
+ */
+const char* const DALI_API_NAME = "dali";
+
+/**
+ * lookup table for setting up function calls for creating Dali objects
+ * e.g. new dali.TextActor()
+ */
+const ApiFunction ConstructorFunctionTable[]=
+{
+ { "Rotation", PropertyValueWrapper::NewRotation},
+ { "Matrix", PropertyValueWrapper::NewMatrix},
+ { "Font", FontWrapper::NewFont },
+ { "Path", PathWrapper::NewPath },
+ { "Actor", ActorWrapper::NewActor },
+ { "TextActor", ActorWrapper::NewActor },
+ { "ImageActor", ActorWrapper::NewActor },
+ { "MeshActor", ActorWrapper::NewActor },
+ { "CameraActor", ActorWrapper::NewActor },
+ { "Layer", ActorWrapper::NewActor },
+ { "TextView", ActorWrapper::NewActor },
+ { "ResourceImage", ImageWrapper::NewImage },
+ { "BufferImage", ImageWrapper::NewImage },
+ { "NinePatchImage", ImageWrapper::NewImage },
+ { "FrameBufferImage", ImageWrapper::NewImage },
+ { "ImageAttributes", ImageAttributesWrapper::NewImageAttributes },
+ { "Animation", AnimationWrapper::NewAnimation},
+ { "ShaderEffect", ShaderEffectWrapper::NewShaderEffect},
+ { "Builder", BuilderWrapper::NewBuilder},
+ { "PanGestureDetector", PanGestureDetectorWrapper::NewPanGestureDetector},
+
+};
+
+const unsigned int PropertyFunctionTableCount = sizeof(ConstructorFunctionTable)/sizeof(ConstructorFunctionTable[0]);
+
+void FatalErrorCallback(const char* location, const char* message)
+{
+ DALI_LOG_ERROR("%s, %s \n",location,message);
+ DALI_ASSERT_ALWAYS( 0 && "V8 fatal error");
+}
+
+#if defined(DEBUG_ENABLED)
+// default to verbose logging
+Integration::Log::Filter* gLogExecuteFilter( Integration::Log::Filter::New(Debug::Verbose, false, "EXECUTE_JAVASCRIPT") );
+#endif
+} // un-named name space
+
+
+
+bool DaliWrapper::mInstanceCreated = false;
+DaliWrapper* DaliWrapper::mWrapper = NULL;
+
+DaliWrapper::DaliWrapper()
+:mIsolate( NULL )
+{
+}
+
+DaliWrapper::~DaliWrapper()
+{
+ mInstanceCreated = false;
+}
+
+DaliWrapper& DaliWrapper::Get()
+{
+ if(!mInstanceCreated)
+ {
+ mWrapper = new DaliWrapper();
+ mInstanceCreated = true;
+
+ if(mWrapper)
+ {
+ mWrapper->Initialize();
+ }
+ }
+
+ return *mWrapper;
+}
+
+void DaliWrapper::SetFlagsFromString(const std::string &flags)
+{
+ v8::V8::SetFlagsFromString(flags.c_str(), flags.size());
+}
+
+void DaliWrapper::Shutdown()
+{
+ DALI_LOG_WARNING("Destroying V8 DALi context\n");
+
+ if( !mContext.IsEmpty())
+ {
+ v8::HandleScope handleScope( mIsolate );
+ v8::Local<v8::Context> context = v8::Local<v8::Context>::New(mIsolate, mContext);
+ context->Exit(); // exit the context
+ mContext.Reset(); // destroys the context
+ }
+}
+
+void DaliWrapper::ExecuteBuffer(const std::string &sourceCode, const std::string &sourceFileName)
+{
+ mModuleLoader.ExecuteScript( mIsolate, sourceCode, sourceFileName );
+}
+
+void DaliWrapper::ExecuteFile( const std::string& sourceFileName )
+{
+ DALI_LOG_INFO( gLogExecuteFilter, Debug::Verbose, "Executing source file %s \n",sourceFileName.c_str() );
+
+ mModuleLoader.ExecuteScriptFromFile( mIsolate, sourceFileName );
+}
+
+GarbageCollectorInterface& DaliWrapper::GetDaliGarbageCollector()
+{
+ return mGarbageCollector;
+}
+
+void DaliWrapper::CreateContext( )
+{
+ v8::HandleScope handleScope( mIsolate );
+
+ // Create a global JavaScript object so we can set built-in global functions, like Log.
+ v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New( mIsolate );
+
+ // Add global objects ( functions/ values ) e.g. log function and V8_VERSION
+ global->Set( v8::String::NewFromUtf8( mIsolate, "log"), v8::FunctionTemplate::New( mIsolate, V8Utils::Log) );
+ global->Set( v8::String::NewFromUtf8( mIsolate, "logError"), v8::FunctionTemplate::New( mIsolate, V8Utils::LogError) );
+ global->Set( v8::String::NewFromUtf8( mIsolate, "require"), v8::FunctionTemplate::New( mIsolate, DaliWrapper::Require));
+ global->Set( v8::String::NewFromUtf8( mIsolate, "V8_VERSION") ,v8::String::NewFromUtf8( mIsolate, v8::V8::GetVersion() ));
+
+ // add the dali object to it, assume it won't be garbage collected until global is deleted
+ global->Set(v8::String::NewFromUtf8( mIsolate, DALI_API_NAME) , NewDaliObjectTemplate( mIsolate ));
+
+
+ // create a new context.
+ // Isolate = isolated copy of the V8 including a heap manager, a garbage collector
+ // Only 1 thread can access a single Isolate at a given time. However, multiple Isolates can be run in parallel.
+ // Context = multiple contexts can exist in a given Isolate, and share data between contexts
+ v8::Handle<v8::Context> context = v8::Context::New( mIsolate, NULL, global);
+
+ mGlobalObjectTemplate.Reset( mIsolate, global);
+
+ mContext.Reset( mIsolate, context);
+}
+
+void DaliWrapper::Initialize()
+{
+ if( !mIsolate )
+ {
+ v8::V8::Initialize();
+ v8::V8::InitializeICU();
+ v8::V8::SetFatalErrorHandler( FatalErrorCallback );
+ mIsolate = v8::Isolate::GetCurrent();
+ }
+ // if context is null, create it and add dali object to the global object.
+ if( mContext.IsEmpty())
+ {
+ v8::HandleScope handleScope( mIsolate );
+ CreateContext();
+ v8::Local<v8::Context> context = v8::Local<v8::Context>::New(mIsolate, mContext);
+
+ context->Enter();
+
+ // Add the dali global object. Used for creating objects, and accessing constant values
+ // e.g. var x = new dali.ImageActor(), or var col = dali.COLOR_RED;
+
+ v8::Local<v8::Object> daliObject = v8::Local<v8::Object>::Cast( context->Global()->Get( v8::String::NewFromUtf8( mIsolate, DALI_API_NAME)));
+
+ v8::Local<v8::Object> stageObject = StageWrapper::WrapStage( mIsolate, Stage::GetCurrent() );
+ daliObject->Set( v8::String::NewFromUtf8( mIsolate, "stage") , stageObject );
+
+ // fontObject provides static font functionality like GetFontList...
+ v8::Local<v8::Object> fontObject = FontWrapper::GetStaticFontObject( mIsolate );
+ daliObject->Set( v8::String::NewFromUtf8( mIsolate, "font") , fontObject );
+
+ // keyboard focus manager is a singleton
+ v8::Local<v8::Object> keyboardObject = KeyboardFocusManagerWrapper::WrapKeyboardFocusManager( mIsolate,Toolkit::KeyboardFocusManager::Get() );
+ daliObject->Set( v8::String::NewFromUtf8( mIsolate, "keyboardFocusManager") , keyboardObject );
+
+ ConstantsWrapper::AddDaliConstants( mIsolate, daliObject);
+
+ }
+ DALI_LOG_INFO( gLogExecuteFilter, Debug::Verbose, "V8 Library %s loaded \n", v8::V8::GetVersion() );
+}
+
+v8::Handle<v8::ObjectTemplate> DaliWrapper::NewDaliObjectTemplate( v8::Isolate* isolate )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+
+ // create the template
+ v8::Local< v8::ObjectTemplate > objTemplate = v8::ObjectTemplate::New( isolate );
+
+ // Add some value properties ( a property can be a primitive value, an object or a function).
+ objTemplate->Set( v8::String::NewFromUtf8( isolate, "BUILD"),
+ v8::String::NewFromUtf8( isolate, "Dali binary built on:" __DATE__ ", at " __TIME__));
+
+
+ // add the data data directory,
+ objTemplate->Set( v8::String::NewFromUtf8( isolate, "DALI_DATA_DIRECTORY"),
+ v8::String::NewFromUtf8( isolate, DALI_DATA_READ_ONLY_DIR));
+
+ // add our constructor functions
+ ObjectTemplateHelper::InstallFunctions( isolate,
+ objTemplate,
+ ConstructorFunctionTable,
+ PropertyFunctionTableCount,
+ ObjectTemplateHelper::CONSTRUCTOR_FUNCTIONS);
+
+ return handleScope.Escape( objTemplate );
+}
+
+void DaliWrapper::Require(const v8::FunctionCallbackInfo< v8::Value >& args)
+{
+ DaliWrapper& wrapper( DaliWrapper::Get() );
+ wrapper.mModuleLoader.Require( args, wrapper.mGlobalObjectTemplate );
+}
+
+
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_DALI_WRAP_H__
+#define __DALI_V8PLUGIN_DALI_WRAP_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/public-api/common/dali-common.h>
+
+// INTERNAL INCLUDES
+#include <garbage-collector/garbage-collector.h>
+#include <module-loader/module-loader.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+/**
+ * Sets up JavaScript context and environment and allows execution of JavaScript in the context
+ *
+ *
+ * Exceptions
+ * ----------
+ *
+ * Execptions can be raised by calling DALI_SCRIPT_EXCEPTION()
+ *
+ * Expections break JavaScript execution with a printout but do not cause a c++ exception.
+ * So always return from the calling function before attempting to run any further V8 code.
+ *
+ * Coding Style
+ * ------------
+ *
+ * Uses Tizen Web API coding style, which appears to be the same as this:
+ *
+ * https://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml
+ *
+ * "In general, use
+ *
+ * functionNamesLikeThis,
+ * variableNamesLikeThis,
+ * ClassNamesLikeThis,
+ * ConstructorsLikeThis,
+ * EnumNamesLikeThis,
+ * methodNamesLikeThis,
+ * CONSTANT_VALUES_LIKE_THIS,
+ * foo.namespaceNamesLikeThis.bar,
+ * filenameslikethis.js. "
+ */
+class DALI_INTERNAL DaliWrapper
+{
+public:
+
+ /**
+ * Constructor
+ */
+ DaliWrapper();
+
+ /**
+ * non virtual destructor, not intended as a base class
+ */
+ ~DaliWrapper();
+
+ /**
+ * Gets the DaliWrapper singleton.
+ *
+ * @return the wrapper
+ */
+ static DaliWrapper& Get();
+
+ /**
+ * Set V8 engine configuration flags
+ *
+ * @param[in] flags Configruation flags (See v8 documentation)
+ */
+ void SetFlagsFromString(const std::string& flags);
+
+ /**
+ * Delete the current V8 context
+ */
+ void Shutdown();
+
+ /**
+ * Excute the buffer in the v8 context
+ *
+ * @param[in] sourceCode The buffer containing javascript to execute
+ * @param[in] sourceFileName Filename associated with the buffer (for error tracing)
+ */
+ void ExecuteBuffer(const std::string &sourceCode, const std::string &sourceFileName);
+
+
+ /**
+ * Excute the buffer in the v8 context
+ *
+ * @param[in] sourceFileName Filename associated with the buffer (for error tracing)
+ */
+ void ExecuteFile( const std::string& sourceFileName);
+
+
+ /**
+ * Get DALi's own garbage collector
+ * @return garbage collector interface
+ */
+ GarbageCollectorInterface& GetDaliGarbageCollector();
+
+private:
+
+ /**
+ * Create V8 context
+ */
+ void CreateContext();
+
+ /**
+ * Initialize DaliWrapper
+ */
+ void Initialize();
+
+ /**
+ * Create Dali ObjectTemplate
+ * @return the Dali ObjectTemplate
+ */
+ static v8::Handle<v8::ObjectTemplate> NewDaliObjectTemplate( v8::Isolate* isolate );
+
+ /**
+ * Called when require keyword is found in a script
+ */
+ static void Require(const v8::FunctionCallbackInfo< v8::Value >& args);
+
+ static bool mInstanceCreated; ///< whether an instance has been created
+ static DaliWrapper* mWrapper; ///< static pointer to the wrapper
+
+ GarbageCollector mGarbageCollector; ///< DALi garbage collector
+ ModuleLoader mModuleLoader; ///< Module loader
+ v8::Persistent<v8::Context> mContext; ///< A sandboxed execution context with its own set of built-in objects and functions.
+ v8::Persistent<v8::ObjectTemplate> mGlobalObjectTemplate; ///< Global object template for storing things like dali global object
+ v8::Isolate* mIsolate; ///< represents an isolated instance of the V8 engine.
+
+};
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "event-object-generator.h"
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <actors/actor-wrapper.h>
+#include <object/property-value-wrapper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace
+{
+
+struct PointState
+{
+ TouchPoint::State state;
+ const char* name;
+};
+
+const PointState PointStateLookup[]=
+{
+ { TouchPoint::Down, "down" }, /**< Screen touched */
+ { TouchPoint::Up, "up" }, /**< Touch stopped */
+ { TouchPoint::Motion, "motion" }, /**< Touch stopped */
+ { TouchPoint::Leave, "leave" }, /**< Touch stopped */
+ { TouchPoint::Stationary, "stationary" }, /**< Touch stopped */
+ { TouchPoint::Interrupted, "interrupt" }, /**< Touch stopped */
+ { TouchPoint::Started, "started" }, /**< Touch or hover started */
+ { TouchPoint::Finished, "finished" }, /**< Touch or hover finished */
+};
+
+const unsigned int PointStateLookupCount = sizeof(PointStateLookup)/sizeof(PointStateLookup[0]);
+
+struct GestureState
+{
+ Gesture::State state;
+ const char* name;
+};
+
+const GestureState GestureStateLookup[]=
+{
+ { Gesture::Clear, "clear" }, /**< No state associated */
+ { Gesture::Started, "started" }, /**< Gesture started */
+ { Gesture::Continuing, "continuing" }, /**< Gesture continuing */
+ { Gesture::Finished, "finished" }, /**< Gesture finished */
+ { Gesture::Cancelled, "cancelled" }, /**< Gesture cancelled */
+ { Gesture::Possible, "possible" }, /**< Gesture is possible */
+};
+
+const unsigned int GestureStateLookupCount = sizeof(GestureStateLookup)/sizeof(GestureStateLookup[0]);
+
+const char* GetTouchPointStateName( TouchPoint::State state )
+{
+ // could use the enum as index, but dali-core may change, so for now just do a lookup
+ for( unsigned int i = 0; i < PointStateLookupCount; i++ )
+ {
+ if( PointStateLookup[i].state == state )
+ {
+ return PointStateLookup[i].name;
+ }
+ }
+ return "error point state not found";
+}
+
+const char* GetGestureStateName( Gesture::State state )
+{
+ // could use the enum as index, but dali-core may change, so for now just do a lookup
+ for( unsigned int i = 0; i < GestureStateLookupCount; i++ )
+ {
+ if( GestureStateLookup[i].state == state )
+ {
+ return GestureStateLookup[i].name;
+ }
+ }
+ return "error gesture state not found";
+}
+
+// create a point object, x,y
+v8::Local<v8::Object> CreateTouchPoint( v8::Isolate* isolate, const TouchPoint& touchPoint )
+{
+ /*
+ * touch point object
+ *
+ * { "deviceId", int } Each touch point has a unique device ID
+ * { "state", string } touch state ="Down,Up,Motion,Leave,Stationary, Interrupted }
+ * { "hitActor", actor } actor that was hit ( wrapped dali object)
+ * { "local", {x,y} } co-ordinates of top left of hit actor
+ * { "screen", {x,y} } co-ordinates of top left of hit actor
+ */
+ v8::EscapableHandleScope handleScope( isolate );
+
+ v8::Local<v8::Object> pointObject = v8::Object::New( isolate );
+
+ // set device id
+ pointObject->Set( v8::String::NewFromUtf8( isolate, "deviceId"), v8::Integer::New( isolate, touchPoint.deviceId ));
+
+ // set state
+ pointObject->Set( v8::String::NewFromUtf8( isolate, "state"), v8::String::NewFromUtf8( isolate, GetTouchPointStateName(touchPoint.state)));
+
+ // set the hit actor
+ pointObject->Set( v8::String::NewFromUtf8( isolate, "hitActor"), ActorWrapper::WrapActor(isolate, touchPoint.hitActor ));
+
+ // Think about changing these Vector 2 from wrapped objects to JavaScript objects...
+
+ // Set the local co-ordinates
+ v8::Local<v8::Object> localPointObject = v8::Object::New( isolate );
+ localPointObject->Set( v8::String::NewFromUtf8( isolate, "x"),v8::Integer::New( isolate, touchPoint.local.x) );
+ localPointObject->Set( v8::String::NewFromUtf8( isolate, "y"),v8::Integer::New( isolate, touchPoint.local.y) );
+ pointObject->Set( v8::String::NewFromUtf8( isolate, "local"), localPointObject);
+
+
+ // set the screen co-ordinates
+ v8::Local<v8::Object> screenPointObject = v8::Object::New( isolate );
+ screenPointObject->Set( v8::String::NewFromUtf8( isolate, "x"),v8::Integer::New( isolate, touchPoint.screen.x) );
+ screenPointObject->Set( v8::String::NewFromUtf8( isolate, "y"),v8::Integer::New( isolate, touchPoint.screen.y) );
+ pointObject->Set( v8::String::NewFromUtf8( isolate, "screen"), screenPointObject );
+
+
+ return handleScope.Escape( pointObject );
+}
+
+} // un-named namespace
+
+
+v8::Handle<v8::Object> EventObjectGenerator::CreateTouchEvent( v8::Isolate* isolate, const TouchEvent& touchEvent)
+{
+ // we are creating a touch event object that looks like this
+ //
+ // event.pointCount = points touched
+ // event.time = The time (in ms) that the touch event occurred.
+ // event.point[] = array of TouchPoints
+ //
+ // A TouchPoint =
+ // { "deviceId", int } Each touch point has a unique device ID
+ // { "state", string } touch state ="Down,Up,Motion,Leave,Stationary, Interrupted }
+ // { "sourceActor", actor } the actor that is emitting the callback (the actor that is hit maybe a child of it)
+ // { "hitActor", actor } actor that was hit
+ // { "local", {x,y} } co-ordinates of top left of hit actor
+ // { "screen", {x,y} } co-ordinates of top left of hit actor
+ //
+
+ v8::EscapableHandleScope handleScope( isolate );
+
+ v8::Local<v8::Object> touchObject = v8::Object::New( isolate );
+
+ // Set the pointCount
+ touchObject->Set( v8::String::NewFromUtf8( isolate, "pointCount" ), v8::Integer::New( isolate, touchEvent.GetPointCount() ) );
+
+ // Set the time
+ touchObject->Set( v8::String::NewFromUtf8( isolate, "time" ), v8::Number::New( isolate, touchEvent.time ) );
+
+ // Set the emitting actor
+ // touchObject->Set( v8::String::NewFromUtf8( isolate, "sourceActor" ), ActorWrapper::WrapActor(isolate, emittingActor));
+
+ // Create the array of touch points
+ v8::Local < v8::Array > pointArrayObject = v8::Array::New( isolate, touchEvent.GetPointCount() );
+ for( unsigned int i = 0 ; i < touchEvent.GetPointCount() ; ++i )
+ {
+ v8::Local < v8::Object > pointObject = CreateTouchPoint( isolate, touchEvent.points[i] );
+ pointArrayObject->Set( v8::Number::New( isolate, i ), pointObject );
+ }
+
+ // set the array
+ touchObject->Set( v8::String::NewFromUtf8( isolate, "points" ), pointArrayObject );
+
+ return handleScope.Escape( touchObject );
+}
+
+v8::Handle<v8::Object> EventObjectGenerator::CreateHoverEvent( v8::Isolate* isolate, const HoverEvent& hoverEvent)
+{
+ // we are creating a hover event object that looks like this
+ //
+ // event.pointCount = points hovered
+ // event.time = The time (in ms) that the hover event occurred.
+ // event.point[] = array of TouchPoints
+ //
+ // A TouchPoint =
+ // { "deviceId", int } Each touch point has a unique device ID
+ // { "state", string } touch state ="Down,Up,Motion,Leave,Stationary, Interrupted }
+ // { "sourceActor", actor } the actor that is emitting the callback (the actor that is hit maybe a child of it)
+ // { "hitActor", actor } actor that was hit
+ // { "local", {x,y} } co-ordinates of top left of hit actor
+ // { "screen", {x,y} } co-ordinates of top left of hit actor
+ //
+
+ v8::EscapableHandleScope handleScope( isolate );
+
+ v8::Local<v8::Object> hoverObject = v8::Object::New( isolate );
+
+ // Set the pointCount
+ hoverObject->Set( v8::String::NewFromUtf8( isolate, "pointCount" ), v8::Integer::New( isolate, hoverEvent.GetPointCount() ) );
+
+ // Set the time
+ hoverObject->Set( v8::String::NewFromUtf8( isolate, "time" ), v8::Number::New( isolate, hoverEvent.time ) );
+
+ // Set the emitting actor
+ // hoverObject->Set( v8::String::NewFromUtf8( isolate, "sourceActor" ), ActorWrapper::WrapActor(isolate, emittingActor));
+
+ // Create the array of touch points
+ v8::Local < v8::Array > pointArrayObject = v8::Array::New( isolate, hoverEvent.GetPointCount() );
+ for( unsigned int i = 0 ; i < hoverEvent.GetPointCount() ; ++i )
+ {
+ v8::Local < v8::Object > pointObject = CreateTouchPoint( isolate, hoverEvent.points[i] );
+ pointArrayObject->Set( v8::Number::New( isolate, i ), pointObject );
+ }
+
+ // set the array
+ hoverObject->Set( v8::String::NewFromUtf8( isolate, "points" ), pointArrayObject );
+
+ return handleScope.Escape( hoverObject );
+}
+
+v8::Handle<v8::Object> EventObjectGenerator::CreateMouseWheelEvent( v8::Isolate* isolate, const MouseWheelEvent& wheelEvent)
+{
+ // we are creating a mouse wheel event object that looks like this
+ //
+ // event.direction = "vertical" or "horizontal" direction the wheel is being rolled
+ // event.shiftPressed = boolean, shift key is held
+ // event.ctrlPressed = boolean, ctrl key is held
+ // event.altPressed = boolean, alt key is held
+ // event.keyModifiers = bitmask of keys pressed
+ // event.point {x,y} = The co-ordinates of the mouse cursor relative to the top-left of the screen when the wheel is being rolled.
+ // event.rolled = offset of mouse wheel rolling, positive = rolling down, negative = rolling up
+ // event.timestamp = The time (in ms) that the touch event occurred
+
+ v8::EscapableHandleScope handleScope( isolate );
+
+ v8::Local<v8::Object> wheelObject = v8::Object::New( isolate );
+
+ // Set the direction
+ std::string direction = wheelEvent.direction ? "vertical" : "horizontal";
+ wheelObject->Set( v8::String::NewFromUtf8( isolate, "direction" ), v8::String::NewFromUtf8( isolate, direction.c_str() ) );
+
+ // set shift / ctrl/ alt keys
+ wheelObject->Set( v8::String::NewFromUtf8( isolate, "shiftPressed" ), v8::Boolean::New( isolate, wheelEvent.IsShiftModifier()) );
+ wheelObject->Set( v8::String::NewFromUtf8( isolate, "ctrlPressed" ), v8::Boolean::New( isolate, wheelEvent.IsCtrlModifier()) );
+ wheelObject->Set( v8::String::NewFromUtf8( isolate, "altPressed" ), v8::Boolean::New( isolate, wheelEvent.IsAltModifier()) );
+
+ // set keyModifiers
+ wheelObject->Set( v8::String::NewFromUtf8( isolate, "keyModifiers" ), v8::Integer::New( isolate, wheelEvent.modifiers) );
+
+ // set Point
+ v8::Local<v8::Object> wheelPointObject = v8::Object::New( isolate );
+ wheelPointObject->Set( v8::String::NewFromUtf8( isolate, "x"),v8::Integer::New( isolate, wheelEvent.point.x ) );
+ wheelPointObject->Set( v8::String::NewFromUtf8( isolate, "y"),v8::Integer::New( isolate, wheelEvent.point.y ) );
+ wheelObject->Set( v8::String::NewFromUtf8( isolate, "point"), wheelPointObject );
+
+ // set rolledAmout
+ wheelObject->Set( v8::String::NewFromUtf8( isolate, "rolled" ), v8::Integer::New( isolate, wheelEvent.z) );
+
+ // set timestamp
+ wheelObject->Set( v8::String::NewFromUtf8( isolate, "timestamp" ), v8::Integer::New( isolate, wheelEvent.timeStamp) );
+
+ return handleScope.Escape( wheelObject );
+
+}
+
+v8::Handle<v8::Object> EventObjectGenerator::CreateKeyEvent( v8::Isolate* isolate, const KeyEvent& keyEvent)
+{
+ // keyCode
+ // keyModifier
+ // event.keyCode = key code
+ // event.key = key presssed
+ // event.keyDescription = key description, e.g. BackSpace
+ // event.state = "down" or "up" key state
+ // event.shiftPressed = boolean, shift key is held
+ // event.ctrlPressed = boolean, ctrl key is held
+ // event.altPressed = boolean, alt key is held
+ // event.keyModifiers = key modifiers
+ // event.timestamp = Time stamp
+
+ v8::EscapableHandleScope handleScope( isolate );
+
+ v8::Local<v8::Object> keyObject = v8::Object::New( isolate );
+
+ // Set the direction
+ std::string state ("up");
+ if ( keyEvent.state == KeyEvent::Down)
+ {
+ state = "down";
+ }
+
+ keyObject->Set( v8::String::NewFromUtf8( isolate, "state" ), v8::String::NewFromUtf8( isolate, state.c_str() ) );
+
+ // set keyCode
+ keyObject->Set( v8::String::NewFromUtf8( isolate, "keyCode" ), v8::Integer::New( isolate, keyEvent.keyCode) );
+
+ // set keyModifiers
+ keyObject->Set( v8::String::NewFromUtf8( isolate, "keyModifier" ), v8::Integer::New( isolate, keyEvent.keyModifier) );
+
+ // set Key pressed name
+ keyObject->Set( v8::String::NewFromUtf8( isolate, "keyDescription" ), v8::String::NewFromUtf8( isolate, keyEvent.keyPressedName.c_str() ) );
+
+ // set Key pressed
+ keyObject->Set( v8::String::NewFromUtf8( isolate, "key" ), v8::String::NewFromUtf8( isolate, keyEvent.keyPressed.c_str() ) );
+
+ // set time stamp
+ keyObject->Set( v8::String::NewFromUtf8( isolate, "timestamp" ), v8::Integer::New( isolate, keyEvent.time) );
+
+ // set shift / ctrl/ alt keys
+ keyObject->Set( v8::String::NewFromUtf8( isolate, "shiftPressed" ), v8::Boolean::New( isolate, keyEvent.IsShiftModifier()) );
+ keyObject->Set( v8::String::NewFromUtf8( isolate, "ctrlPressed" ), v8::Boolean::New( isolate, keyEvent.IsCtrlModifier()) );
+ keyObject->Set( v8::String::NewFromUtf8( isolate, "altPressed" ), v8::Boolean::New( isolate, keyEvent.IsAltModifier()) );
+
+ return handleScope.Escape( keyObject );
+
+}
+
+v8::Handle<v8::Object> EventObjectGenerator::CreatePanGesture( v8::Isolate* isolate, const PanGesture& panGesture)
+{
+ // gesture.numberOfTouches = total number of fingers touching the screen
+ // gesture.state = pan state {Clear, Started, Continuing, Finished, Cancelled, Possible}
+ // gesture.time = Time stamp
+ // gesture.velocity = pan velocity in actor coordinates
+ // gesture.displacement = pan displacement in actor coordinates
+ // gesture.position = pan position in actor coordinates
+ // gesture.screenVelocity = pan velocity in screen coordinates
+ // gesture.screenDisplacement = pan displacement in screen coordinates
+ // gesture.screenPosition = pan position in screen coordinates
+
+ v8::EscapableHandleScope handleScope( isolate );
+
+ v8::Local<v8::Object> panObject = v8::Object::New( isolate );
+
+ // Set the numberOfTouches
+ panObject->Set( v8::String::NewFromUtf8( isolate, "numberOfTouches" ), v8::Integer::New( isolate, panGesture.numberOfTouches ) );
+
+ // Set the state
+ panObject->Set( v8::String::NewFromUtf8( isolate, "state"), v8::String::NewFromUtf8( isolate, GetGestureStateName(panGesture.state)));
+
+ // Set the time
+ panObject->Set( v8::String::NewFromUtf8( isolate, "time" ), v8::Number::New( isolate, panGesture.time ) );
+
+ // Set the local velocity
+ v8::Local<v8::Object> velocityObject = v8::Object::New( isolate );
+ velocityObject->Set( v8::String::NewFromUtf8( isolate, "x"),v8::Number::New( isolate, panGesture.velocity.x) );
+ velocityObject->Set( v8::String::NewFromUtf8( isolate, "y"),v8::Number::New( isolate, panGesture.velocity.y) );
+ panObject->Set( v8::String::NewFromUtf8( isolate, "velocity"), velocityObject);
+
+ // Set the local displacement
+ v8::Local<v8::Object> displacementObject = v8::Object::New( isolate );
+ displacementObject->Set( v8::String::NewFromUtf8( isolate, "x"),v8::Number::New( isolate, panGesture.displacement.x) );
+ displacementObject->Set( v8::String::NewFromUtf8( isolate, "y"),v8::Number::New( isolate, panGesture.displacement.y) );
+ panObject->Set( v8::String::NewFromUtf8( isolate, "displacement"), displacementObject);
+
+ // Set the local position
+ v8::Local<v8::Object> positionObject = v8::Object::New( isolate );
+ positionObject->Set( v8::String::NewFromUtf8( isolate, "x"),v8::Number::New( isolate, panGesture.position.x) );
+ positionObject->Set( v8::String::NewFromUtf8( isolate, "y"),v8::Number::New( isolate, panGesture.position.y) );
+ panObject->Set( v8::String::NewFromUtf8( isolate, "position"), positionObject);
+
+ // Set the screen velocity
+ v8::Local<v8::Object> screenVelocityObject = v8::Object::New( isolate );
+ screenVelocityObject->Set( v8::String::NewFromUtf8( isolate, "x"),v8::Number::New( isolate, panGesture.screenVelocity.x) );
+ screenVelocityObject->Set( v8::String::NewFromUtf8( isolate, "y"),v8::Number::New( isolate, panGesture.screenVelocity.y) );
+ panObject->Set( v8::String::NewFromUtf8( isolate, "screenVelocity"), screenVelocityObject);
+
+ // Set the screen displacement
+ v8::Local<v8::Object> screenDisplacementObject = v8::Object::New( isolate );
+ screenDisplacementObject->Set( v8::String::NewFromUtf8( isolate, "x"),v8::Number::New( isolate, panGesture.screenDisplacement.x) );
+ screenDisplacementObject->Set( v8::String::NewFromUtf8( isolate, "y"),v8::Number::New( isolate, panGesture.screenDisplacement.y) );
+ panObject->Set( v8::String::NewFromUtf8( isolate, "screenDisplacement"), screenDisplacementObject);
+
+ // Set the screen position
+ v8::Local<v8::Object> screenPositionObject = v8::Object::New( isolate );
+ screenPositionObject->Set( v8::String::NewFromUtf8( isolate, "x"),v8::Number::New( isolate, panGesture.screenPosition.x) );
+ screenPositionObject->Set( v8::String::NewFromUtf8( isolate, "y"),v8::Number::New( isolate, panGesture.screenPosition.y) );
+ panObject->Set( v8::String::NewFromUtf8( isolate, "screenPosition"), screenPositionObject);
+
+ return handleScope.Escape( panObject );
+
+}
+
+
+
+} // V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_EVENT_OBJECT_GENERATOR_H__
+#define __DALI_V8PLUGIN_EVENT_OBJECT_GENERATOR_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/public-api/events/touch-event.h>
+#include <dali/public-api/events/hover-event.h>
+#include <dali/public-api/events/mouse-wheel-event.h>
+#include <dali/public-api/events/key-event.h>
+#include <dali/public-api/events/pan-gesture.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+
+/**
+ * Used to convert Dali event objects into pure JavaScript objects.
+ * The objects created are not wrappers around a Dali object,
+ * however TouchPoint.Actor is a wrapped actor
+ */
+namespace EventObjectGenerator
+{
+
+ v8::Handle<v8::Object> CreateTouchEvent( v8::Isolate* isolate, const TouchEvent& touchEvent);
+ v8::Handle<v8::Object> CreateHoverEvent( v8::Isolate* isolate, const HoverEvent& hoverEvent);
+ v8::Handle<v8::Object> CreateMouseWheelEvent( v8::Isolate* isolate, const MouseWheelEvent& wheelEvent);
+ v8::Handle<v8::Object> CreateKeyEvent( v8::Isolate* isolate, const KeyEvent& keyEvent);
+ v8::Handle<v8::Object> CreatePanGesture( v8::Isolate* isolate, const PanGesture& panGesture);
+
+
+
+};
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "pan-gesture-detector-api.h"
+
+// INTERNAL INCLUDES
+#include <events/pan-gesture-detector-wrapper.h>
+#include <object/property-value-wrapper.h>
+#include <v8-utils.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace // unnamed namespace
+{
+
+PanGestureDetector GetPanGestureDetector( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::HandleScope handleScope( isolate );
+
+ v8::Local<v8::Object> object = args.This();
+ v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField( 0 ) );
+ void* ptr = field->Value();
+
+ PanGestureDetectorWrapper* wrapper = static_cast<PanGestureDetectorWrapper *>( ptr );
+ return wrapper->GetPanGestureDetector();
+}
+
+} // unnamed namespace
+
+/**
+ * Constructor
+ *
+ * @constructor
+ * @for PanGestureDetector
+ * @method PanGestureDetector
+ */
+PanGestureDetector PanGestureDetectorApi::New( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ return PanGestureDetector::New();
+}
+
+/**
+ * Attaches an actor to the pan gesture.
+ *
+ * The pan-detected signal will be dispatched when the pan gesture occurs on
+ * the attached actor. You can attach several actors to a pan gesture detector.
+ * @method attach
+ * @for PanGestureDetector
+ * @param {Actor} actor The actor to attach to the pan gesture detector
+ * @example
+ * panGestureDetector.attach(actor);
+ */
+void PanGestureDetectorApi::Attach( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ bool found( false );
+ //Get actor
+ Dali::Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
+ if( found )
+ {
+ PanGestureDetector panGestureDetector = GetPanGestureDetector( isolate, args );
+ panGestureDetector.Attach( actor );
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
+ }
+}
+
+
+/**
+ * Detaches the attached actor from the pan gesture detector.
+ *
+ * The specified actor should have been attached to the pan gesture detector
+ * @method detach
+ * @for PanGestureDetector
+ * @param {Actor} actor The actor to detach from the pan gesture detector
+ * @example
+ * panGestureDetector.detach(actor);
+ */
+void PanGestureDetectorApi::Detach( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ bool found( false );
+ //Get actor
+ Dali::Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
+ if( found )
+ {
+ PanGestureDetector panGestureDetector = GetPanGestureDetector( isolate, args );
+ panGestureDetector.Detach( actor );
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
+ }
+}
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_PAN_GESTURE_DETECTOR_API_H__
+#define __DALI_V8PLUGIN_PAN_GESTURE_DETECTOR_API_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/public-api/events/pan-gesture-detector.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace PanGestureDetectorApi
+{
+ /**
+ * Constructor
+ */
+ PanGestureDetector New( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ /**
+ * PanGestureDetector API see gesture-detector.h for a description
+ */
+ void Attach( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void Detach( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+}; // namespace PanGestureDetectorApi
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header __DALI_V8PLUGIN_PAN_GESTURE_DETECTOR_API_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "pan-gesture-detector-wrapper.h"
+
+// INTERNAL INCLUDES
+#include <events/pan-gesture-detector-api.h>
+#include <v8-utils.h>
+#include <dali-wrapper.h>
+#include <shared/object-template-helper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace
+{
+
+const ApiFunction PanGestureDetectorFunctions[]=
+{
+ { "Attach", PanGestureDetectorApi::Attach },
+ { "Detach", PanGestureDetectorApi::Detach }
+};
+
+const unsigned int PanGestureDetectorFunctionTableCount = sizeof(PanGestureDetectorFunctions)/sizeof(PanGestureDetectorFunctions[0]);
+} //un-named space
+
+
+PanGestureDetectorWrapper::PanGestureDetectorWrapper( PanGestureDetector panGestureDetector, GarbageCollectorInterface& gc )
+:HandleWrapper( BaseWrappedObject::PAN_GESTURE_DETECTOR, panGestureDetector, gc ),
+ mPanGestureDetector( panGestureDetector )
+{
+}
+
+v8::Handle<v8::ObjectTemplate> PanGestureDetectorWrapper::MakePanGestureDetectorTemplate( v8::Isolate* isolate )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+
+ v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
+ objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT );
+
+ // add our function properties
+ ObjectTemplateHelper::InstallFunctions( isolate, objTemplate, PanGestureDetectorFunctions, PanGestureDetectorFunctionTableCount );
+
+ // property handle intercepts property getters and setters and signals
+ HandleWrapper::AddInterceptsToTemplate( isolate, objTemplate );
+
+ return handleScope.Escape( objTemplate );
+}
+
+v8::Handle<v8::Object> PanGestureDetectorWrapper::WrapPanGestureDetector( v8::Isolate* isolate, PanGestureDetector panGestureDetector )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::ObjectTemplate> objectTemplate;
+
+ objectTemplate = MakePanGestureDetectorTemplate( isolate );
+
+ // create an instance of the template
+ v8::Local<v8::Object> localObject = objectTemplate->NewInstance();
+
+ // create the Dali object
+ PanGestureDetectorWrapper* pointer = new PanGestureDetectorWrapper( panGestureDetector, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() );
+
+ // assign the JavaScript object to the wrapper.
+ // This also stores Dali object, in an internal field inside the JavaScript object.
+ pointer->SetJavascriptObject( isolate, localObject );
+
+ return handleScope.Escape( localObject );
+}
+
+PanGestureDetector PanGestureDetectorWrapper::GetPanGestureDetector()
+{
+ return mPanGestureDetector;
+}
+
+/**
+ * Create an initialized PanGestureDetector handle.
+ * @constructor
+ * @for PanGestureDetector
+ * @method PanGestureDetector
+ */
+void PanGestureDetectorWrapper::NewPanGestureDetector( const v8::FunctionCallbackInfo< v8::Value >& args)
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ if( !args.IsConstructCall() )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "constructor called without 'new" );
+ return;
+ }
+
+ // Create a new path
+ PanGestureDetector panGestureDetector = PanGestureDetector::New();
+ v8::Local<v8::Object> localObject = WrapPanGestureDetector( isolate, panGestureDetector );
+ args.GetReturnValue().Set( localObject );
+}
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_PAN_GESTURE_DETECTOR_WRAPPER_H__
+#define __DALI_V8PLUGIN_PAN_GESTURE_DETECTOR_WRAPPER_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/public-api/events/pan-gesture-detector.h>
+
+// INTERNAL INCLUDES
+#include <object/handle-wrapper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+/**
+ * Wraps a PanGestureDetector.
+ */
+class PanGestureDetectorWrapper : public HandleWrapper
+{
+
+public:
+
+ /**
+ * Constructor
+ */
+ PanGestureDetectorWrapper( PanGestureDetector panGestureDetector, GarbageCollectorInterface& gc );
+
+ /**
+ * Virtual destructor
+ */
+ virtual ~PanGestureDetectorWrapper(){};
+
+ /**
+ * Creates a new PanGestureDetector wrapped inside a Javascript Object.
+ * @param[in] args v8 function call arguments interpreted
+ */
+ static void NewPanGestureDetector( const v8::FunctionCallbackInfo< v8::Value >& args);
+
+ /**
+ * Wraps a PanGestureDetector inside a Javascript object
+ */
+ static v8::Handle<v8::Object> WrapPanGestureDetector(v8::Isolate* isolate, PanGestureDetector panGestureDetector );
+
+ /*
+ * Get the wrapped PanGestureDetector
+ */
+ PanGestureDetector GetPanGestureDetector();
+
+private:
+
+ /**
+ * Create a v8 object template for the PanGestureDetector
+ */
+ static v8::Handle<v8::ObjectTemplate> MakePanGestureDetectorTemplate( v8::Isolate* isolate );
+
+ PanGestureDetector mPanGestureDetector;
+};
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "garbage-collector.h"
+
+// INTERNAL INCLUDES
+#include <shared/base-wrapped-object.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+GarbageCollector::GarbageCollector()
+{
+
+}
+GarbageCollector::~GarbageCollector()
+{
+ GarbageCollect();
+}
+
+void GarbageCollector::Register( BaseWrappedObject* object )
+{
+ mObjectMap.insert( object );
+};
+
+
+void GarbageCollector::UnRegister( BaseWrappedObject* object )
+{
+ mObjectMap.erase( object );
+}
+
+
+void GarbageCollector::GarbageCollect()
+{
+ for( ObjectMap::iterator iter = mObjectMap.begin(); iter != mObjectMap.end(); )
+ {
+ BaseWrappedObject* object = *iter;
+ iter++; // iterator will be invalidated if we delete the object first.
+ delete object; // object will call GarbageCollector.UnRegister
+ }
+
+}
+
+} // V8Plugin
+
+} // Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_GARBAGE_COLLECTOR_H__
+#define __DALI_V8PLUGIN_GARBAGE_COLLECTOR_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+// INTERNAL INCLUDES
+#include <interfaces/garbage-collector-interface.h>
+#include <dali/public-api/common/set-wrapper.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+
+/**
+ * @brief concrete interface of Dali's garbage collector interface.
+ */
+class GarbageCollector : public GarbageCollectorInterface
+{
+
+public:
+
+ /**
+ * Constructor
+ */
+ GarbageCollector();
+
+ /**
+ * Destructor
+ */
+ ~GarbageCollector();
+
+ /**
+ * @copydoc GarbageCollectorInterface::Register()
+ */
+ virtual void Register( BaseWrappedObject* object );
+
+ /**
+ * @copydoc GarbageCollectorInterface::UnRegister()
+ */
+ virtual void UnRegister( BaseWrappedObject* object );
+
+ /**
+ * @copydoc GarbageCollectorInterface::GarbageCollect()
+ */
+ virtual void GarbageCollect();
+
+
+private:
+
+ /**
+ * Map between dali wrapped object (void *)
+ */
+ typedef std::set< BaseWrappedObject* > ObjectMap;
+ ObjectMap mObjectMap; ///< lookup
+
+};
+
+} // V8Plugin
+
+} // Dali
+
+#endif // header __DALI_V8PLUGIN_GARBAGE_COLLECTOR_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "buffer-image-api.h"
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <image/image-wrapper.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+/**
+ * ## BufferImage
+ * Bitmap represents an image resource that can be added to ImageActors.
+ * Its pixel buffer data is provided by the application developer.
+ *
+ * If the pixel format of the pixel buffer contains an alpha channel,
+ * then the image is considered to be have transparent pixels without
+ * regard for the actual content of the channel, and will be blended.
+ * @class BufferImage
+ * @extends Image
+ */
+BufferImage BufferImageApi::GetBufferImage( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::HandleScope handleScope( isolate );
+
+ v8::Local<v8::Object> object = args.This();
+ v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField(0) );
+ void* ptr = field->Value();
+
+ ImageWrapper* wrapper = static_cast< ImageWrapper *>(ptr);
+ return BufferImage::DownCast( wrapper->GetImage() );
+}
+
+/**
+ * Create a new buffer image object ** ( work in progress, will currently only work with no parameters ) **
+ * If no parameters are passed in, a single pixel white buffer image is created.
+ *
+ *
+ * For better performance and portability use power of two dimensions.
+ * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
+ *
+ * @note in case releasePolicy is "Unused", application has to call
+ * BufferImage::Update() whenever image is re-added to the stage
+ *
+ * Example of creating a Uint32Array buffer
+ * ```
+ * "var ab = new ArrayBuffer(256 x 256 );"
+ * var pixelBuffer = new Uint32Array(ab );
+ * ```
+ * @constructor
+ * @method BufferImage
+ * @for BufferImage
+ * @param {Object} options
+ * @param {Uint32Array} options.pixelBuffer Array of RGBA pixel data
+ * @param {Integer} options.width image width
+ * @param {Integer} options.height image height
+ * @param {Integer} options.pixelFormat pixel format ( see dali constants, e.g. dali.PIXEL_FORMAT_RGB8888)
+ * @param {Integer} [options.stride the] internal stride of the pixelbuffer in pixels (normally the width)
+ * @param {Integer} [options.releasePolicy] optionally release memory when image is not visible on screen.
+ * @return {Object} Image
+ */
+Image BufferImageApi::New( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ v8::Local<v8::Value> options( args[0] );
+ if( !options->IsObject() )
+ {
+ return BufferImage::WHITE();
+ }
+
+ v8::Local<v8::Object> obj = options->ToObject();
+
+ v8::Local<v8::Value> widthValue = obj->Get( v8::String::NewFromUtf8( isolate, "width" ) );
+ v8::Local<v8::Value> heightValue= obj->Get( v8::String::NewFromUtf8( isolate, "height" ) );
+
+ unsigned int width = 0;
+ unsigned int height = 0;
+
+ if( widthValue->IsUint32() && heightValue->IsUint32() )
+ {
+ width = widthValue->ToUint32()->Value();
+ height = heightValue->ToUint32()->Value();
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Missing valid width and height params");
+ return BufferImage();
+ }
+
+ Pixel::Format pixelFormat = Pixel::RGB8888;
+ v8::Local<v8::Value> pixelFormatValue = obj->Get( v8::String::NewFromUtf8( isolate, "pixelFormat" ) );
+ if( pixelFormatValue->IsUint32() )
+ {
+ pixelFormat = static_cast<Pixel::Format>( pixelFormatValue->ToUint32()->Value() );
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Pixel format not specified");
+ return BufferImage();
+ }
+
+ v8::Local<v8::Value> pixelArray= obj->Get( v8::String::NewFromUtf8( isolate, "pixelBuffer" ) );
+ if( pixelArray->IsUint32Array() )
+ {
+ //v8::Local<v8::Uint32Array> v8Array = v8::Local<v8::Uint32Array>::Cast( pixelArray );
+ // uint32_t elementCount = v8Array->Length();
+ DALI_SCRIPT_EXCEPTION( isolate, "pixel buffer currently not supported \n");
+ return BufferImage::WHITE();
+ }
+
+
+ unsigned int stride = width;
+ v8::Local<v8::Value> strideValue = obj->Get( v8::String::NewFromUtf8( isolate, "stride" ) );
+ if( strideValue->IsUint32() )
+ {
+ stride = strideValue->ToUint32()->Value();
+ }
+
+ Image::ReleasePolicy releasePolicy = Dali::Image::NEVER;
+ v8::Local<v8::Value> releasePolicyValue = obj->Get( v8::String::NewFromUtf8( isolate, "releasePolicy" ) );
+ if( releasePolicyValue->IsUint32() )
+ {
+ releasePolicy = static_cast<Image::ReleasePolicy>( releasePolicyValue->ToUint32()->Value() );
+ }
+
+ DALI_SCRIPT_EXCEPTION( isolate, "pixel buffer currently not supported \n");
+
+ return BufferImage::New( NULL, width, height, pixelFormat, stride, releasePolicy);
+
+}
+/**
+ * @brief Returns the pixel buffer of the Image **( currently not supported ) **
+ * @method getBuffer
+ * @for BufferImage
+ * @return {Object}
+ */
+void BufferImageApi::GetBuffer( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ BufferImage image = GetBufferImage( isolate, args );
+
+ //@todo figure out what the best thing to do here is...
+ // we could copy the data into a javascript array
+}
+
+/**
+ * @brief Returns buffer size in bytes.
+ * @method getBufferSize
+ * @for BufferImage
+ * @return {Object} buffer
+ */
+void BufferImageApi::GetBufferSize( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ BufferImage image = GetBufferImage( isolate, args );
+
+ args.GetReturnValue().Set( v8::Integer::New( isolate, image.GetBufferSize() ) );
+
+}
+/**
+ * @brief Returns buffer stride in bytes.
+ * @method getBufferStride
+ * @for BufferImage
+ * @return {Object}
+ */
+void BufferImageApi::GetBufferStride( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ BufferImage image = GetBufferImage( isolate, args );
+
+ args.GetReturnValue().Set( v8::Integer::New( isolate, image.GetBufferStride() ) );
+
+}
+/**
+ * @brief Returns pixel format
+ * @method getPixelFormat
+ * @for BufferImage
+ * @return {Integer} pixel format
+ */
+void BufferImageApi::GetPixelFormat( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ BufferImage image = GetBufferImage( isolate, args );
+
+ args.GetReturnValue().Set( v8::Integer::New( isolate, image.GetPixelFormat() ) );
+
+}
+
+/**
+ * @brief Inform Dali that the contents of the buffer have changed
+ * @todo support update an area
+ * @method update
+ * @for BufferImage
+ */
+void BufferImageApi::Update( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ BufferImage image = GetBufferImage( isolate, args );
+
+ image.Update();
+
+}
+/**
+ * @brief returns whether BufferImage uses external data source or not.
+ * @method isDataExternal
+ * @for BufferImage
+ * @return {Boolean} true if data is external
+ */
+void BufferImageApi::IsDataExternal( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ BufferImage image = GetBufferImage( isolate, args );
+
+ args.GetReturnValue().Set( v8::Boolean::New( isolate, image.IsDataExternal() ) );
+
+}
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_RESOURCE_BUFFER_IMAGE_API_H__
+#define __DALI_V8PLUGIN_RESOURCE_BUFFER_IMAGE_API_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/public-api/images/buffer-image.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace BufferImageApi
+{
+ /**
+ * Helper to get buffer-image from args.This()
+ */
+ BufferImage GetBufferImage( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args );
+
+
+ /**
+ * Constructor
+ */
+ Image New( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+
+ /**
+ * Buffer Image API see buffer-image.h for a description
+ */
+ void GetBuffer( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetBufferSize( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetBufferStride( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetPixelFormat( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void Update( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void IsDataExternal( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+}; // namespace BufferImageApi
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header __DALI_V8PLUGIN_RESOURCE_BUFFER_IMAGE_API_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "frame-buffer-image-api.h"
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/images/frame-buffer-image.h>
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <image/image-wrapper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace FrameBufferImageApi
+{
+
+/**
+ * FrameBufferImage represents a GLES Frame Buffer Object and contains the result
+ * of an 'off screen' render pass of a RenderTask.
+ * The FrameBufferImage can then be used with an ImageActor (with optional shader
+ * effects) and rendered to the screen.
+ * @class FrameBufferImage
+ * @extends Image
+ */
+
+/**
+ * @constructor
+ * @method FrameBufferImage
+ * @for FrameBufferImage
+ * @param {Object} options
+ * @param {Uint32Array} options.pixelBuffer Array of RGBA pixel data
+ * @param {Integer} options.width image width
+ * @param {Integer} options.height image height
+ * @param {Object } [options.nativeImage] ** currently not supported **
+ * @param {Integer} [options.pixelFormat] pixel format ( see dali constants, e.g. dali.PIXEL_FORMAT_RGB8888)
+ * @param {Integer} [options.releasePolicy] optionally release memory when image is not visible on screen.
+ * @return {Object} Image
+ */
+Image New( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ v8::Local<v8::Value> options( args[0] );
+ if( !options->IsObject() )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Missing param");
+ return FrameBufferImage();
+ }
+
+ v8::Local<v8::Object> obj = options->ToObject();
+
+ v8::Local<v8::Value> widthValue = obj->Get( v8::String::NewFromUtf8( isolate, "width" ) );
+ v8::Local<v8::Value> heightValue= obj->Get( v8::String::NewFromUtf8( isolate, "height" ) );
+
+ unsigned int width = 0;
+ unsigned int height = 0;
+
+ if( widthValue->IsUint32() && heightValue->IsUint32() )
+ {
+ width = widthValue->ToUint32()->Value();
+ height = heightValue->ToUint32()->Value();
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Missing valid width and height params");
+ return FrameBufferImage();
+ }
+
+ Pixel::Format pixelFormat = Pixel::RGB8888;
+ v8::Local<v8::Value> pixelFormatValue = obj->Get( v8::String::NewFromUtf8( isolate, "pixelFormat" ) );
+ if( pixelFormatValue->IsUint32() )
+ {
+ pixelFormat = static_cast<Pixel::Format>( pixelFormatValue->ToUint32()->Value() );
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Pixel format not specified");
+ return FrameBufferImage();
+ }
+
+ Image::ReleasePolicy releasePolicy = Dali::Image::NEVER;
+ v8::Local<v8::Value> releasePolicyValue = obj->Get( v8::String::NewFromUtf8( isolate, "releasePolicy" ) );
+ if( releasePolicyValue->IsUint32() )
+ {
+ releasePolicy = static_cast<Image::ReleasePolicy>( releasePolicyValue->ToUint32()->Value() );
+ }
+
+ return FrameBufferImage::New( width, height, pixelFormat, releasePolicy );
+}
+
+} // FrameBufferImageApi
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_FRAME_BUFFER_IMAGE_API_H__
+#define __DALI_V8PLUGIN_FRAME_BUFFER_IMAGE_API_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/public-api/images/image.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace FrameBufferImageApi
+{
+
+ /**
+ * Constructor
+ */
+ Image New( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+
+}; // namespace FrameBufferImageApi
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header __DALI_V8PLUGIN_FRAME_BUFFER_IMAGE_API_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "image-api.h"
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <image/image-wrapper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+Image ImageApi::GetImage( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::HandleScope handleScope( isolate );
+
+ v8::Local<v8::Object> object = args.This();
+ v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField(0) );
+ void* ptr = field->Value();
+
+ ImageWrapper* wrapper = static_cast< ImageWrapper *>(ptr);
+ return wrapper->GetImage();
+}
+
+/**
+ * @constructor Image
+ * @method Image
+ * @for Image
+ * @return {Object} Image
+ */
+Image ImageApi::New( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ DALI_SCRIPT_EXCEPTION( isolate, "Image base class can not be constructed, try new dali.ResourceImage()");
+ return Image();
+}
+
+/**
+ * Return the image release policy
+ * @method getReleasePolicy
+ * @return dali.IMAGE_RELEASE_POLICY_UNUSED or dali.IMAGE_RELEASE_POLICY_NEVER
+ * @for Image
+ */
+void ImageApi::GetReleasePolicy( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Image image = GetImage( isolate, args );
+
+ args.GetReturnValue().Set( v8::Integer::New( isolate, image.GetReleasePolicy() ) );
+}
+
+/**
+ * Return the image width in pixels
+ * @method getWidth
+ * @for Image
+ */
+void ImageApi::GetWidth( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Image image = GetImage( isolate, args );
+
+ args.GetReturnValue().Set( v8::Integer::New( isolate, image.GetWidth() ) );
+}
+/**
+ * Return the image height in pixels
+ * @method getHeight
+ * @for Image
+ */
+void ImageApi::GetHeight( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Image image = GetImage( isolate, args );
+
+ args.GetReturnValue().Set( v8::Integer::New( isolate, image.GetHeight() ) );
+}
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_IMAGE_API_H__
+#define __DALI_V8PLUGIN_IMAGE_API_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/public-api/images/image.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace ImageApi
+{
+
+ /**
+ * Helper to get image from args.This()
+ */
+ Image GetImage( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args );
+
+
+ /**
+ * Constructor
+ */
+ Image New( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ /**
+ * Image API see image.h for a description
+ */
+ void GetReleasePolicy( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetWidth( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetHeight( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+}; // namespace ImageApi
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header __DALI_V8PLUGIN_IMAGE_API_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "image-attributes-api.h"
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <image/image-attributes-wrapper.h>
+#include <object/property-value-wrapper.h>
+#include <shared/base-wrapped-object.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+ImageAttributes ImageAttributesApi::GetImageAttributesFromObject( v8::Isolate* isolate, v8::Local<v8::Object> object )
+{
+ v8::HandleScope handleScope( isolate);
+
+ if( BaseWrappedObject::IsWrappedType ( isolate, object, BaseWrappedObject::IMAGE_ATTRIBUTES ))
+ {
+ v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField(0) );
+ void* ptr = field->Value();
+ BaseWrappedObject* wrappedObject = static_cast< BaseWrappedObject *>(ptr);
+ ImageAttributesWrapper* wrapper = static_cast< ImageAttributesWrapper*>( wrappedObject );;
+ return wrapper->GetImageAttributes();
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "bad image attributes url");
+ return ImageAttributes();
+ }
+
+}
+
+/***************************************
+ * IMAGE ATTRIBUTES FUNCTIONS
+ *
+ ****************************************/
+ImageAttributes ImageAttributesApi::New( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ // two combinations of constructor
+ // 1 = no parameters
+ // 2 = width, height
+ bool foundParams( false );
+ int params[2];
+
+ V8Utils::ReadIntegerArguments( foundParams, ¶ms[0],2,args,0);
+ if( !foundParams )
+ {
+ if( args.Length() != 0 )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, " ImageAttributes::New invalid params");
+ return Dali::ImageAttributes();
+ }
+ return Dali::ImageAttributes::New();
+ }
+ else
+ {
+ return Dali::ImageAttributes::New( params[0], params[1] );
+ }
+
+}
+
+ImageAttributes& ImageAttributesApi::GetImageAttributes( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Local<v8::Object> object = args.This();
+ v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField(0) );
+ void* ptr = field->Value();
+
+ ImageAttributesWrapper* wrapper = static_cast< ImageAttributesWrapper *>(ptr);
+ return wrapper->GetImageAttributes();
+}
+
+void ImageAttributesApi::SetSize( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ ImageAttributes& attribs( GetImageAttributes( isolate, args ));
+
+ bool found;
+ Vector2 size = V8Utils::GetVector2Parameter( PARAMETER_0, found, isolate, args );
+ if (!found)
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "invalid size parameter" );
+ return;
+ }
+ else
+ {
+ attribs.SetSize( size );
+ }
+}
+
+void ImageAttributesApi::SetScalingMode( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ ImageAttributes& attribs( GetImageAttributes( isolate, args ));
+
+ bool found(false);
+ int value = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0);
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "invalid scaling mode parameter");
+ return;
+ }
+ if( value!= ImageAttributes::ShrinkToFit ||
+ value!= ImageAttributes::ScaleToFill ||
+ value!= ImageAttributes::FitWidth ||
+ value!= ImageAttributes::FitHeight )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "invalid scaling mode parameter");
+ return;
+ }
+
+ attribs.SetScalingMode(static_cast<ImageAttributes::ScalingMode >( value) );
+}
+
+void ImageAttributesApi::SetOrientationCorrection( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ ImageAttributes& attribs( GetImageAttributes( isolate, args ));
+
+ bool parameterFound(false);
+ bool value = V8Utils::GetBooleanParameter( PARAMETER_0 , parameterFound, isolate, args );
+
+ if( !parameterFound )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "boolean parameter not found");
+ return;
+ }
+ attribs.SetOrientationCorrection( value );
+}
+
+void ImageAttributesApi::GetWidth( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ ImageAttributes& attribs( GetImageAttributes( isolate, args ));
+
+ args.GetReturnValue().Set( v8::Integer::New( isolate, attribs.GetWidth() ) );
+}
+
+void ImageAttributesApi::GetHeight( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ ImageAttributes& attribs( GetImageAttributes( isolate, args ));
+
+ args.GetReturnValue().Set( v8::Integer::New( isolate, attribs.GetHeight() ) );
+
+}
+
+void ImageAttributesApi::GetSize( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ ImageAttributes& attribs( GetImageAttributes( isolate, args ));
+
+ Vector2 vec( attribs.GetSize() );
+ Dali::Property::Value value( vec );
+
+ v8::Local <v8::Object> object = PropertyValueWrapper::WrapDaliProperty( isolate, value);
+ args.GetReturnValue().Set( object );
+}
+
+void ImageAttributesApi::GetScalingMode( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ ImageAttributes& attribs( GetImageAttributes( isolate, args ));
+
+ args.GetReturnValue().Set( v8::Integer::New( isolate, attribs.GetScalingMode() ) );
+
+}
+
+void ImageAttributesApi::GetOrientationCorrection( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ ImageAttributes& attribs( GetImageAttributes( isolate, args ));
+
+ args.GetReturnValue().Set( v8::Boolean::New( isolate, attribs.GetOrientationCorrection() ) );
+
+}
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_IMAGE_ATTRIBUTES_API_H__
+#define __DALI_V8PLUGIN_IMAGE_ATTRIBUTES_API_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/public-api/images/image-attributes.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace ImageAttributesApi
+{
+ ImageAttributes& GetImageAttributes( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ ImageAttributes GetImageAttributesFromObject( v8::Isolate* isolate, v8::Local<v8::Object> object );
+
+ /**
+ * @brief Creates a new Image Attribute object based on some JavaScript parameters.
+ * @param[in] args constructor parameters
+ * @return ImageAttributes
+ */
+ ImageAttributes New( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ /**
+ * ImageAttributes API see image-attributes.h for a description
+ */
+ void SetSize( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetScalingMode( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetOrientationCorrection( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetWidth( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetHeight( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetSize( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetScalingMode( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetOrientationCorrection( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+}; // namespace ImageAttributesApi
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header __DALI_V8PLUGIN_IMAGE_ATTRIBUTES_API_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "image-attributes-wrapper.h"
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <image/image-attributes-api.h>
+#include <dali-wrapper.h>
+#include <shared/api-function.h>
+#include <shared/object-template-helper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+v8::Persistent<v8::ObjectTemplate> ImageAttributesWrapper::mImageAttributesTemplate;
+
+namespace
+{
+
+/**
+ * Contains a list of all functions that can be called
+ */
+const ApiFunction ImageAttributeFunctionTable[]=
+{
+ /**************************************
+ * ImageAttributes API (in order of image-attributes.h)
+ **************************************/
+ { "SetSize", ImageAttributesApi::SetSize },
+ { "SetScalingMode", ImageAttributesApi::SetScalingMode },
+ { "SetOrientationCorrection", ImageAttributesApi::SetOrientationCorrection },
+ { "GetWidth", ImageAttributesApi::GetWidth },
+ { "GetHeight", ImageAttributesApi::GetHeight },
+ { "GetSize", ImageAttributesApi::GetSize },
+ { "GetScalingMode", ImageAttributesApi::GetScalingMode },
+ { "GetOrientationCorrection", ImageAttributesApi::GetOrientationCorrection },
+};
+
+const unsigned int ImageAttributeFunctionTableCount = sizeof(ImageAttributeFunctionTable)/sizeof(ImageAttributeFunctionTable[0]);
+} //un-named space
+
+
+ImageAttributesWrapper::ImageAttributesWrapper( const Dali::ImageAttributes& imageAttributes, GarbageCollectorInterface& gc )
+: BaseWrappedObject( BaseWrappedObject::IMAGE_ATTRIBUTES , gc )
+{
+ mImageAttributes = imageAttributes;
+}
+
+v8::Handle<v8::Object> ImageAttributesWrapper::WrapImageAttributes(v8::Isolate* isolate, const Dali::ImageAttributes& attributes )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::ObjectTemplate> objectTemplate;
+
+ objectTemplate = GetImageAttributesTemplate( isolate);
+
+ // create an instance of the template
+ v8::Local<v8::Object> localObject = objectTemplate->NewInstance();
+
+ // create the ImageAttributes wrapper
+ ImageAttributesWrapper* pointer = new ImageAttributesWrapper( attributes, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() );
+
+ // assign the JavaScript object to the wrapper.
+ pointer->SetJavascriptObject( isolate, localObject );
+
+ return handleScope.Escape( localObject );
+}
+
+v8::Local<v8::ObjectTemplate> ImageAttributesWrapper::GetImageAttributesTemplate( v8::Isolate* isolate)
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::ObjectTemplate> objectTemplate;
+
+
+ if( mImageAttributesTemplate.IsEmpty() )
+ {
+ objectTemplate = MakeImageAttributesTemplate( isolate );
+ mImageAttributesTemplate.Reset( isolate, objectTemplate );
+ }
+ else
+ {
+ // get the object template
+ objectTemplate = v8::Local<v8::ObjectTemplate>::New( isolate, mImageAttributesTemplate );
+ }
+ return handleScope.Escape( objectTemplate );
+}
+
+v8::Handle<v8::ObjectTemplate> ImageAttributesWrapper::MakeImageAttributesTemplate( v8::Isolate* isolate )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+
+ v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
+
+ objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT );
+
+ // add our function properties
+ ObjectTemplateHelper::InstallFunctions( isolate, objTemplate, ImageAttributeFunctionTable, ImageAttributeFunctionTableCount );
+
+ return handleScope.Escape( objTemplate );
+}
+
+void ImageAttributesWrapper::NewImageAttributes( const v8::FunctionCallbackInfo< v8::Value >& args)
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate);
+
+ if(!args.IsConstructCall())
+ {
+ DALI_SCRIPT_EXCEPTION(isolate, "ImageAttributes constructor called without 'new'");
+ return;
+ }
+
+ // attribs can be passed by value
+ Dali::ImageAttributes attribs = ImageAttributesApi::New( args );
+ v8::Local<v8::Object> localObject = WrapImageAttributes( isolate, attribs );
+ args.GetReturnValue().Set( localObject );
+}
+
+
+ImageAttributes& ImageAttributesWrapper::GetImageAttributes()
+{
+ return mImageAttributes;
+}
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_IMAGE_ATTRIBUTES_WRAPPER_H__
+#define __DALI_V8PLUGIN_IMAGE_ATTRIBUTES_WRAPPER_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/public-api/images/image-attributes.h>
+
+// INTERNAL INCLUDES
+#include <shared/base-wrapped-object.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+
+/**
+ * An Image Attributes wrapper.
+ * Provides access to ImageAttributes specific functionality and V8 memory handling.
+ */
+class ImageAttributesWrapper : public BaseWrappedObject
+{
+
+public:
+
+ /**
+ * Constructor
+ */
+ ImageAttributesWrapper( const ImageAttributes& imageAttributes,
+ GarbageCollectorInterface& gc );
+
+ /**
+ * Destructor
+ */
+ virtual ~ImageAttributesWrapper(){};
+
+ /**
+ * Constructors
+ */
+ static void NewImageAttributes( const v8::FunctionCallbackInfo< v8::Value >& args);
+
+ /**
+ * Wraps an image attributes
+ */
+ static v8::Handle<v8::Object> WrapImageAttributes(v8::Isolate* isolate, const Dali::ImageAttributes& attributes);
+
+
+ // The ImageAttribute ObjectTemplate, we cache templates so we don't have
+ // keep generating them everytime we want to create an ImageAttribute
+ static v8::Persistent<v8::ObjectTemplate> mImageAttributesTemplate;
+
+ ImageAttributes& GetImageAttributes();
+private:
+
+ // ImageAttributes
+ ImageAttributes mImageAttributes;
+
+ static v8::Handle<v8::ObjectTemplate> MakeImageAttributesTemplate( v8::Isolate* isolate );
+ static v8::Local<v8::ObjectTemplate> GetImageAttributesTemplate( v8::Isolate* isolate );
+
+};
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "image-wrapper.h"
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <dali-wrapper.h>
+#include <image/image-api.h>
+#include <image/frame-buffer-image-api.h>
+#include <image/resource-image-api.h>
+#include <image/nine-patch-image-api.h>
+#include <image/buffer-image-api.h>
+#include <image/native-image-api.h>
+#include <shared/api-function.h>
+#include <shared/object-template-helper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+v8::Persistent<v8::ObjectTemplate> ImageWrapper::mImageTemplate;
+v8::Persistent<v8::ObjectTemplate> ImageWrapper::mResourceImageTemplate;
+v8::Persistent<v8::ObjectTemplate> ImageWrapper::mNinePatchImageTemplate;
+v8::Persistent<v8::ObjectTemplate> ImageWrapper::mBufferImageTemplate;
+v8::Persistent<v8::ObjectTemplate> ImageWrapper::mFrameBufferImageTemplate;
+v8::Persistent<v8::ObjectTemplate> ImageWrapper::mNativeImageTemplate;
+
+/**
+ * pointer to a persistent template handle
+ */
+struct ImageTemplate
+{
+ v8::Persistent<v8::ObjectTemplate>* imageTemplate;
+};
+
+/**
+ * array of templates for each type of image
+ */
+const ImageTemplate ImageTemplateLookup[]=
+{
+ { &ImageWrapper::mImageTemplate }, // IMAGE
+ { &ImageWrapper::mResourceImageTemplate }, // RESOURCE_IMAGE
+ { &ImageWrapper::mNinePatchImageTemplate }, // NINE PATCH IMAGE
+ { &ImageWrapper::mBufferImageTemplate }, // BITMAP_IMAGE
+ { &ImageWrapper::mFrameBufferImageTemplate }, // FRAME_BUFFER_IMAGE
+ { &ImageWrapper::mNativeImageTemplate }, // NATIVE_IMAGE
+
+};
+
+
+namespace // un-named name space
+{
+
+/**
+ * Bitmask of API's that an image can support
+ */
+enum ImageApiBitMask
+{
+ IMAGE_API = 1 << 0,
+ BITMAP_IMAGE_API = 1 << 1,
+ RESOURCE_IMAGE_API = 1 << 2,
+ NINE_PATCH_IMAGE_API = 1 << 3,
+ FRAME_BUFFER_IMAGE_API = 1 << 4,
+ NATIVE_IMAGE_API = 1 << 5,
+
+};
+
+/**
+ * structure used for the ImageApiLookup.
+ */
+struct ImageApiStruct
+{
+ const char* imageName; ///< name of the image, used to find out what type of image to construct
+ ImageWrapper::ImageType imageType; ///< image type
+ Image (*constructor)( const v8::FunctionCallbackInfo< v8::Value >& args); ///< constructor
+ int supportApis; ///< supported API's
+};
+
+/**
+ * Lookup table to match a image type with a constructor and supported API's.
+ */
+const ImageApiStruct ImageApiLookup[]=
+{
+ {"Image", ImageWrapper::IMAGE, ImageApi::New, IMAGE_API },
+ {"ResourceImage", ImageWrapper::RESOURCE_IMAGE, ResourceImageApi::New, IMAGE_API | RESOURCE_IMAGE_API },
+ {"NinePatchImage", ImageWrapper::NINE_PATCH_IMAGE, NinePatchImageApi::New, IMAGE_API | RESOURCE_IMAGE_API | NINE_PATCH_IMAGE_API },
+ {"BufferImage", ImageWrapper::BITMAP_IMAGE, BufferImageApi::New, IMAGE_API | BITMAP_IMAGE_API },
+ {"FrameBufferImage",ImageWrapper::FRAME_BUFFER_IMAGE, FrameBufferImageApi::New, IMAGE_API | FRAME_BUFFER_IMAGE_API },
+ {"NativeImage", ImageWrapper::NATIVE_IMAGE, NativeImageApi::New, IMAGE_API | NATIVE_IMAGE_API },
+
+};
+
+const unsigned int ImageApiLookupCount = sizeof(ImageApiLookup)/sizeof(ImageApiLookup[0]);
+
+
+/**
+ * given an image type return what api's it supports
+ */
+int GetImageSupportedApis( ImageWrapper::ImageType type )
+{
+ return ImageApiLookup[ type].supportApis;
+}
+
+/**
+ * Used for the ImageFunctionTable to map function names to functions
+ * with for a specific API
+ */
+struct ImageFunctions
+{
+ const char* name; ///< function name
+ void (*function)( const v8::FunctionCallbackInfo< v8::Value >& args);
+ ImageApiBitMask api;
+};
+
+/**
+ * Contains a list of all functions that can be called
+ */
+const ImageFunctions ImageFunctionTable[]=
+{
+ /**************************************
+ * Image API (in order of image.h)
+ **************************************/
+ { "GetWidth", ImageApi::GetWidth , IMAGE_API },
+ { "GetHeight", ImageApi::GetHeight, IMAGE_API },
+ { "GetReleasePolicy", ImageApi::GetReleasePolicy, IMAGE_API },
+
+ // resource-image API
+ { "GetLoadingState", ResourceImageApi::GetLoadingState, RESOURCE_IMAGE_API },
+ { "GetUrl", ResourceImageApi::GetUrl, RESOURCE_IMAGE_API },
+ { "GetLoadPolicy", ResourceImageApi::GetLoadPolicy, RESOURCE_IMAGE_API },
+ { "Reload", ResourceImageApi::Reload, RESOURCE_IMAGE_API },
+
+ // nine-patch API
+ { "GetStretchBorders", NinePatchImageApi::GetStretchBorders, NINE_PATCH_IMAGE_API },
+ { "GetChildRectangle", NinePatchImageApi::GetChildRectangle, NINE_PATCH_IMAGE_API },
+ { "CreateCroppedBufferImage",NinePatchImageApi::CreateCroppedBufferImage, NINE_PATCH_IMAGE_API },
+
+ // buffer image API
+ { "GetBuffer", BufferImageApi::GetBuffer, BITMAP_IMAGE_API },
+ { "GetBufferSize", BufferImageApi::GetBufferSize, BITMAP_IMAGE_API },
+ { "GetBufferStride", BufferImageApi::GetBufferStride, BITMAP_IMAGE_API },
+ { "GetPixelFormat", BufferImageApi::GetPixelFormat, BITMAP_IMAGE_API },
+ { "Update", BufferImageApi::Update, BITMAP_IMAGE_API },
+ { "IsDataExternal", BufferImageApi::IsDataExternal, BITMAP_IMAGE_API },
+
+ // Frame buffer image has no API
+ // Native image has no API
+
+};
+
+const unsigned int ImageFunctionTableCount = sizeof(ImageFunctionTable)/sizeof(ImageFunctionTable[0]);
+} //un-named space
+
+
+ImageWrapper::ImageWrapper( const Dali::Image& image, GarbageCollectorInterface& gc )
+: BaseWrappedObject( BaseWrappedObject::IMAGE , gc )
+{
+ mImage = image;
+}
+
+v8::Handle<v8::Object> ImageWrapper::WrapImage(v8::Isolate* isolate, const Dali::Image& image )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+
+ v8::Local<v8::Object> object = WrapImage( isolate, image, GetImageType( image.GetTypeName() ) );
+
+ return handleScope.Escape( object );
+}
+v8::Handle<v8::Object> ImageWrapper::WrapImage(v8::Isolate* isolate, const Dali::Image& image, ImageType imageType )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::ObjectTemplate> objectTemplate;
+
+ objectTemplate = GetImageTemplate( isolate, imageType);
+
+ // create an instance of the template
+ v8::Local<v8::Object> localObject = objectTemplate->NewInstance();
+
+ // create the Image wrapper
+ ImageWrapper* pointer = new ImageWrapper( image, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() );
+
+ // assign the JavaScript object to the wrapper.
+ // This also stores the Image object, in an internal field inside the JavaScript object.
+ pointer->SetJavascriptObject( isolate, localObject );
+
+ return handleScope.Escape( localObject );
+}
+
+v8::Local<v8::ObjectTemplate> ImageWrapper::GetImageTemplate( v8::Isolate* isolate, ImageType imageType )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::ObjectTemplate> objectTemplate;
+
+ if( ImageTemplateLookup[ imageType ].imageTemplate->IsEmpty() )
+ {
+ objectTemplate = MakeImageTemplate( isolate, imageType );
+ ImageTemplateLookup[ imageType ].imageTemplate->Reset( isolate, objectTemplate );
+ }
+ else
+ {
+ // get the object template
+ objectTemplate = v8::Local<v8::ObjectTemplate>::New( isolate, *ImageTemplateLookup[ imageType ].imageTemplate );
+ }
+
+ return handleScope.Escape( objectTemplate );
+}
+
+v8::Handle<v8::ObjectTemplate> ImageWrapper::MakeImageTemplate( v8::Isolate* isolate, ImageType imageType )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+
+ v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
+
+ objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT );
+
+ // add intercepts for Signals on ResourceImage, we can't use HandleWrapper::AddIntercepts because Image doesn't inherit
+ // from Handle ( just baseHandle)
+ if (( imageType == RESOURCE_IMAGE ) ||
+ ( imageType == NINE_PATCH_IMAGE ))
+ {
+ ObjectTemplateHelper::AddSignalConnectAndDisconnect( isolate, objTemplate );
+ }
+
+ // find out what API's this image supports
+ int supportApis = GetImageSupportedApis( imageType );
+
+ // add our function properties
+ for( unsigned int i = 0; i < ImageFunctionTableCount; ++i )
+ {
+ const ImageFunctions property = ImageFunctionTable[i];
+
+ // check to see if the image supports a certain type of API
+ // e.g. Bitmap will support IMAGE_API and BITMAP_IMAGE_API
+ if( supportApis & property.api )
+ {
+ std::string funcName = V8Utils::GetJavaScriptFunctionName( property.name);
+
+ objTemplate->Set( v8::String::NewFromUtf8( isolate, funcName.c_str() ),
+ v8::FunctionTemplate::New( isolate, property.function ) );
+ }
+ }
+
+ return handleScope.Escape( objTemplate );
+}
+
+
+void ImageWrapper::NewImage( const v8::FunctionCallbackInfo< v8::Value >& args)
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate);
+
+ if(!args.IsConstructCall())
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Image constructor called without 'new'");
+ return;
+ }
+
+ // find out the callee function name...e.g. BufferImage, ResourceImage
+ v8::Local<v8::Function> callee = args.Callee();
+ v8::Local<v8::Value> v8String = callee->GetName();
+ std::string typeName = V8Utils::v8StringToStdString( v8String );
+
+ ImageType imageType = GetImageType( typeName );
+
+ if( imageType == UNKNOWN_IMAGE_TYPE )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "unknown image type");
+ return;
+ }
+ Image image = (ImageApiLookup[imageType].constructor)( args );
+
+ if( ! image )
+ {
+ // a v8 exception will have been thrown by the constructor
+ return;
+ }
+
+ v8::Local<v8::Object> localObject = WrapImage( isolate, image, imageType );
+
+ args.GetReturnValue().Set( localObject );
+}
+
+Image ImageWrapper::GetImage()
+{
+ return mImage;
+}
+
+/**
+ * given an image type name, e.g. returns the type, e.g. ImageWrapper::BITMAP_IMAGE
+ */
+ImageWrapper::ImageType ImageWrapper::GetImageType( const std::string& name )
+{
+ for( unsigned int i = 0 ; i < ImageApiLookupCount ; i++ )
+ {
+ if( strncmp( ImageApiLookup[i].imageName, name.c_str(), name.length() ) == 0 )
+ {
+ return ImageApiLookup[i].imageType;
+ }
+ }
+ return ImageWrapper::UNKNOWN_IMAGE_TYPE;
+}
+
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_IMAGE_WRAPPER_H__
+#define __DALI_V8PLUGIN_IMAGE_WRAPPER_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/public-api/images/image.h>
+
+// INTERNAL INCLUDES
+#include <shared/base-wrapped-object.h>
+#include <signals/signal-manager.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+
+/**
+ * An Image wrapper.
+ * Provides access to Image specific functionality and V8 memory handling.
+ */
+class ImageWrapper : public BaseWrappedObject
+{
+
+public:
+
+ /**
+ * Image type used an index,
+ * please update the table in ImageApiLookup if this list changes ( the enum is used as an index)
+ */
+ enum ImageType
+ {
+ UNKNOWN_IMAGE_TYPE = -1,
+ IMAGE = 0,
+ RESOURCE_IMAGE = 1,
+ NINE_PATCH_IMAGE = 2,
+ BITMAP_IMAGE = 3,
+ FRAME_BUFFER_IMAGE = 4,
+ NATIVE_IMAGE = 5
+ };
+
+ /**
+ * Constructor
+ */
+ ImageWrapper( const Image& image,
+ GarbageCollectorInterface& gc );
+
+ /**
+ * Destructor
+ */
+ virtual ~ImageWrapper()
+ {
+ };
+
+ /**
+ * @brief Creates a new Image wrapped inside a Javascript Object.
+ * @note: the actor type ie 'ImageImage' is expected to be the name of the callee function.
+ * @param[in] args v8 function call arguments interpreted
+ */
+ static void NewImage( const v8::FunctionCallbackInfo< v8::Value >& args);
+
+ /**
+ * Wraps an image of a given type
+ */
+ static v8::Handle<v8::Object> WrapImage(v8::Isolate* isolate, const Dali::Image& image, ImageType imageType );
+
+ /**
+ * Wraps an image, the type is looked up from the image
+ */
+ static v8::Handle<v8::Object> WrapImage(v8::Isolate* isolate, const Dali::Image& image );
+
+ /**
+ * @return Image
+ */
+ Image GetImage();
+
+ /**
+ * @return signal manager pointer
+ */
+ virtual SignalManager* GetSignalManager() { return &mSignalManager;}
+
+ // The Image ObjectTemplate, we cache templates so we don't have
+ // keep generating them everytime we want to create an Image
+ static v8::Persistent<v8::ObjectTemplate> mImageTemplate;
+ static v8::Persistent<v8::ObjectTemplate> mResourceImageTemplate;
+ static v8::Persistent<v8::ObjectTemplate> mNinePatchImageTemplate;
+ static v8::Persistent<v8::ObjectTemplate> mBufferImageTemplate;
+ static v8::Persistent<v8::ObjectTemplate> mFrameBufferImageTemplate;
+ static v8::Persistent<v8::ObjectTemplate> mNativeImageTemplate;
+
+private:
+
+ /**
+ * Helper
+ */
+ static ImageType GetImageType( const std::string& name );
+
+ static v8::Handle<v8::ObjectTemplate> MakeImageTemplate( v8::Isolate* isolate, ImageType imageType );
+ static v8::Local<v8::ObjectTemplate> GetImageTemplate( v8::Isolate* isolate , ImageType imageType );
+
+
+ Image mImage; ///< Image handle
+ SignalManager mSignalManager; ///< Signal Manager
+
+};
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // __DALI_V8PLUGIN_IMAGE_WRAPPER_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "frame-buffer-image-api.h"
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/images/native-image.h>
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <image/image-wrapper.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace NativeImageApi
+{
+
+/**
+ * ## NativeImage **Not Supported**
+ * NativeImage represents an image resource that can be added to ImageActors.
+ * Its data is provided by native resources, such as shared bitmap memory or pixmap from X11 or ECORE-X11, etc.
+ * @class NativeImage
+ * @extends Image
+ */
+
+/**
+ * **Currently not supported. This is a Place holder**
+ * @constructor
+ * @method NativeImage
+ * @for NativeImage
+ * @return {Object} Image
+ */
+Image New( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ // return empty image handle
+ return NativeImage();
+}
+
+} // NativeImageApi
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_NATIVE_IMAGE_API_H__
+#define __DALI_V8PLUGIN_NATIVE_IMAGE_API_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/public-api/images/native-image.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace NativeImageApi
+{
+
+ /**
+ * Constructor
+ */
+ Image New( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+
+}; // namespace NativeImageApi
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header __DALI_V8PLUGIN_NATIVE_IMAGE_API_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "nine-patch-image-api.h"
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <image/image-wrapper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+/**
+ *
+ * NinePatchImage represents an image resource that can be added to ImageActors.
+ * It contains a bitmap that is synchronously loaded from the file system that contains
+ * a 9 patch border - a 1 pixel border that describes the stretch borders and the child
+ * area.
+ *
+ * The class offers an API to read the stretch area and child area, but it does not
+ * remove the border from it's bitmap. An API can be used to obtain a BufferImage with
+ * the border removed.
+ *
+ * Adding this image to an ImageActor using an Image handle will automatically convert
+ * to use the cropped BufferImage - if you don't retain a handle to this object, it will
+ * be automatically destroyed.
+ * @class NinePatchImage
+ * @extends ResourceImage
+ */
+
+NinePatchImage NinePatchImageApi::GetNinePatchImage( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::HandleScope handleScope( isolate );
+
+ v8::Local<v8::Object> object = args.This();
+ v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField(0) );
+ void* ptr = field->Value();
+
+ ImageWrapper* wrapper = static_cast< ImageWrapper *>(ptr);
+ return NinePatchImage ::DownCast( wrapper->GetImage() );
+}
+
+
+/**
+ * Create a new nine patch image object.
+ *
+ * @constructor
+ * @method NinePatchImage
+ * @for NinePatchImage
+ * @param {Object} options
+ * @param {String} options.url The URL of the nine patch image file to use.
+ * @return {Object} Image
+ */
+Image NinePatchImageApi::New( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ std::string url;
+ v8::Local<v8::Value> options( args[0] );
+
+ if( !options->IsObject() )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Missing params");
+ return NinePatchImage();
+ }
+
+ v8::Local<v8::Object> optionsObject = options->ToObject();
+
+ v8::Local<v8::Value> urlValue = optionsObject->Get( v8::String::NewFromUtf8( isolate, "url" ) );
+ if( urlValue->IsString() )
+ {
+ url = V8Utils::v8StringToStdString( urlValue );
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Missing url");
+ return NinePatchImage();
+ }
+
+ return NinePatchImage::New( url );
+}
+
+
+/**
+ * Get the Stretch Borders
+ *
+ * @method getStretchBorders
+ * @for NinePatchImage
+ * @return object containing x,y,w,h properties
+ */
+void NinePatchImageApi::GetStretchBorders( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ NinePatchImage image = GetNinePatchImage( isolate, args );
+
+ v8::Local<v8::Object> rectObject = v8::Object::New( isolate );
+
+ Vector4 borders = image.GetStretchBorders();
+ // Set the direction
+
+ rectObject->Set( v8::String::NewFromUtf8( isolate, "x" ), v8::Integer::New( isolate,borders.x ) );
+ rectObject->Set( v8::String::NewFromUtf8( isolate, "y" ), v8::Integer::New( isolate,borders.y ) );
+ rectObject->Set( v8::String::NewFromUtf8( isolate, "w" ), v8::Integer::New( isolate,borders.z ) );
+ rectObject->Set( v8::String::NewFromUtf8( isolate, "h" ), v8::Integer::New( isolate,borders.w ) );
+
+ args.GetReturnValue().Set( rectObject );
+}
+
+/**
+ * Get the child rectangle
+ * @method getChildRectangle
+ * @for NinePatchImage
+ * @return {Object} position/size of of the child rectangle with x,y,w,h properties
+ *
+ */
+void NinePatchImageApi::GetChildRectangle( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ NinePatchImage image = GetNinePatchImage( isolate, args );
+
+ v8::Local<v8::Object> rectObject = v8::Object::New( isolate );
+ Rect<int> childRect = image.GetChildRectangle();
+
+ rectObject->Set( v8::String::NewFromUtf8( isolate, "x" ), v8::Integer::New( isolate,childRect.x ) );
+ rectObject->Set( v8::String::NewFromUtf8( isolate, "y" ), v8::Integer::New( isolate,childRect.y ) );
+ rectObject->Set( v8::String::NewFromUtf8( isolate, "w" ), v8::Integer::New( isolate,childRect.width ) );
+ rectObject->Set( v8::String::NewFromUtf8( isolate, "h" ), v8::Integer::New( isolate,childRect.height ) );
+
+ args.GetReturnValue().Set( rectObject );
+}
+
+/**
+ * Creates a buffer image from the bitmap with the 1 pixel border cropped off.
+ * This does not change the internal bitmap.
+ * @method createCroppedBufferImage
+ * @for NinePatchImage
+ */
+void NinePatchImageApi::CreateCroppedBufferImage( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Image image = GetNinePatchImage( isolate, args );
+
+ args.GetReturnValue().Set( v8::Integer::New( isolate, image.GetWidth() ) );
+}
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_NINE_PATCH_IMAGE_API_H__
+#define __DALI_V8PLUGIN_NINE_PATCH_IMAGE_API_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/public-api/images/nine-patch-image.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace NinePatchImageApi
+{
+ /**
+ * Helper
+ */
+ NinePatchImage GetNinePatchImage( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args );
+
+
+ /**
+ * Constructor
+ */
+ Image New( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+
+ /**
+ * Ninepatch Image API see nine-patch-image.h for a description
+ */
+ void GetStretchBorders( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetChildRectangle( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void CreateCroppedBufferImage( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+}; // namespace NinePatchImageApi
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header __DALI_V8PLUGIN_NINE_PATCH_IMAGE_API_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "resource-image-api.h"
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <image/image-wrapper.h>
+#include <image/image-attributes-wrapper.h>
+#include <image/image-attributes-api.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+ResourceImage ResourceImageApi::GetResourceImage( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::HandleScope handleScope( isolate );
+
+ v8::Local<v8::Object> object = args.This();
+ v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField(0) );
+ void* ptr = field->Value();
+
+ ImageWrapper* wrapper = static_cast< ImageWrapper *>(ptr);
+ return ResourceImage::DownCast( wrapper->GetImage() );
+}
+
+/**
+ * Create a new resource image object.
+ *
+ * @constructor
+ * @method ResourceImage
+ * @for ResourceImage
+ * @param {Object} options
+ * @param {String} options.url The URL of the image file to use.
+ * @param {Object} [option.imageAttributes] image attributes object
+ * @param {Integer} [options.loadPolicy] The LoadPolicy to apply when loading the image resource.
+ * @param {Integer} [options.releasePolicy] optionally release memory when image is not visible on screen.
+ * @return {Object} Image
+ */
+Image ResourceImageApi::New( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ std::string url;
+ ResourceImage::LoadPolicy loadPolicy( ResourceImage::IMMEDIATE );
+ Image::ReleasePolicy releasePolicy( Image::NEVER);
+ ImageAttributes imageAttributes;
+ bool useImageAttributes = false;
+
+ v8::Local<v8::Value> options( args[0] );
+
+ if( !options->IsObject() )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Missing params" );
+ return Image();
+ }
+
+ v8::Local<v8::Object> optionsObject = options->ToObject();
+
+ v8::Local<v8::Value> urlValue = optionsObject->Get( v8::String::NewFromUtf8( isolate, "url" ) );
+ if( urlValue->IsString() )
+ {
+ url = V8Utils::v8StringToStdString( urlValue );
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Missing url");
+ return Image();
+ }
+
+ v8::Local<v8::Value> imageAttribsValue= optionsObject->Get( v8::String::NewFromUtf8( isolate, "imageAttributes" ) );
+ if( imageAttribsValue->IsObject() )
+ {
+ imageAttributes = ImageAttributesApi::GetImageAttributesFromObject( isolate, imageAttribsValue->ToObject() );
+ }
+
+
+
+ v8::Local<v8::Value> releasePolicyValue = optionsObject->Get( v8::String::NewFromUtf8( isolate, "releasePolicy" ) );
+ if( releasePolicyValue->IsUint32() )
+ {
+ releasePolicy = static_cast<Image::ReleasePolicy>( releasePolicyValue->ToUint32()->Value() );
+ }
+
+ v8::Local<v8::Value> loadPolicyValue = optionsObject->Get( v8::String::NewFromUtf8( isolate, "loadPolicy" ) );
+ if( loadPolicyValue->IsUint32() )
+ {
+ loadPolicy = static_cast< ResourceImage::LoadPolicy >( loadPolicyValue->ToUint32()->Value());
+ }
+
+ if( useImageAttributes )
+ {
+ return ResourceImage::New( url, imageAttributes, loadPolicy, releasePolicy);
+ }
+ else
+ {
+ return ResourceImage::New( url, loadPolicy, releasePolicy);
+ }
+}
+
+/**
+ * Get the load policy
+ *
+ * @method getLoadPolicy
+ * @for ResourceImage
+ * @return {Integer} load policy either dali.IMAGE_LOAD_POLICY_ON_DEMAND or dali.IMAGE_LOAD_POLICY_IMMEDIATE
+ */
+void ResourceImageApi::GetLoadPolicy( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ ResourceImage image = GetResourceImage( isolate, args );
+
+ args.GetReturnValue().Set( v8::Integer::New( isolate, image.GetLoadPolicy() ) );
+}
+
+/**
+ * Query whether the image data has loaded.
+ *
+ * The asynchronous loading begins when the Image object is created.
+ * After the Image object is discarded, the image data will be released from memory
+ * this will occur when the object is garbage collected.
+ * @method getLoadPolicy
+ * @for ResourceImage
+ * @return {Integer} loading state either dali.RESOURCE_LOADING, dali.RESOURCE_LOADING_SUCCEEDED or dali.RESOUCE_LOADING_FAILED
+ */
+void ResourceImageApi::GetLoadingState( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ ResourceImage image = GetResourceImage( isolate, args );
+
+ args.GetReturnValue().Set( v8::Integer::New( isolate, image.GetLoadingState() ) );
+}
+
+/**
+ * Return the image url
+ *
+ * @method getUrl
+ * @for ResourceImage
+ * @return {String} filename
+ */
+void ResourceImageApi::GetUrl( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ ResourceImage image = GetResourceImage( isolate, args );
+
+ v8::Local<v8::String> v8String = v8::String::NewFromUtf8( isolate, image.GetUrl().c_str() );
+ args.GetReturnValue().Set( v8String );
+}
+
+
+/**
+ * Reload the image
+ * The set ImageAttributes are used when requesting the image again.
+ * @note if Image is offstage and OnDemand policy is set, reload request is ignored.
+ * @method reload
+ * @for ResourceImage
+ */
+void ResourceImageApi::Reload( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ ResourceImage image = GetResourceImage( isolate, args );
+ image.Reload();
+}
+
+
+/**
+ * Return attributes for the image
+ * Only to be used after the image has finished loading.
+ * (Ticket's LoadingSucceeded callback was called)
+ * The returned value will reflect the true image dimensions once the asynchronous loading has finished.
+ *
+ * @method getAttributes
+ * @for ResourceImage
+ * @return {Object} ImageAttributes
+ */
+void ResourceImageApi::GetAttributes( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ ResourceImage image = GetResourceImage( isolate, args );
+
+ v8::Local<v8::Object> localObject = ImageAttributesWrapper::WrapImageAttributes(isolate, image.GetAttributes());
+
+ args.GetReturnValue().Set( localObject );
+}
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_RESOURCE_IMAGE_API_H__
+#define __DALI_V8PLUGIN_RESOURCE_IMAGE_API_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/public-api/images/resource-image.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace ResourceImageApi
+{
+ /**
+ * Helper
+ */
+ ResourceImage GetResourceImage( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ /**
+ * Constructor
+ */
+ Image New( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+
+ /**
+ * Resource Image API see resource-image.h for a description
+ */
+ void GetLoadPolicy( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetLoadingState( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetUrl( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void Reload( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetAttributes( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+}; // namespace ResourceImageApi
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header __DALI_V8PLUGIN_RESOURCE_IMAGE_API_H__
--- /dev/null
+#ifndef __DALI_V8PLUGIN_GARBAGE_COLLECTOR_INTERFACE_H__
+#define __DALI_V8PLUGIN_GARBAGE_COLLECTOR_INTERFACE_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+class BaseWrappedObject;
+
+/**
+ * @brief Tracks all Dali-wrapped objects that are used by v8.
+ * Required to delete any wrapped objects that are not cleaned up after V8 has shut down.
+ *
+ * Unfortunately the v8 garbage collection may never run while executing a script,
+ * and currently doesn't run on shutdown (for performance reasons with Chrome browser).
+ *
+ * This means we have to manually keep track of all objects, and perform our
+ * own garbage collection on shut down.
+ *
+ * For every object created:
+ * - Store a weak handle to it
+ * - Register a callback to be informed if v8 garbage collector decides it's no longer required.
+ * -- Call back is done using v8 SetWeak(), which states:
+ * "There is no guarantee as to *when* or even *if* the callback is invoked."
+ *
+ */
+class GarbageCollectorInterface
+{
+
+public:
+
+ /**
+ * Register an object with Dali's garbage collector
+ * @param object a wrapped object
+ */
+ virtual void Register( BaseWrappedObject* object ) = 0;
+
+ /**
+ * Un-register an object with Dali's garbage collector
+ * @param object a wrapped object
+ */
+ virtual void UnRegister( BaseWrappedObject* object ) = 0;
+
+ /**
+ * Delete all
+ */
+ virtual void GarbageCollect() = 0;
+
+protected:
+
+ /**
+ * Constructor
+ */
+ GarbageCollectorInterface()
+ {
+ }
+
+ /**
+ * virtual destructor
+ */
+ virtual ~GarbageCollectorInterface()
+ {
+ }
+
+ // Undefined copy constructor.
+ GarbageCollectorInterface( const GarbageCollectorInterface& );
+
+ // Undefined assignment operator.
+ GarbageCollectorInterface& operator=( const GarbageCollectorInterface& );
+
+
+};
+
+} // V8Plugin
+
+} // Dali
+
+#endif // header __DALI_V8PLUGIN_GARBAGE_COLLECTOR_INTERFACE_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "module-loader.h"
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+ModuleLoader::ModuleLoader()
+{
+
+}
+
+ModuleLoader::~ModuleLoader()
+{
+ VectorBase::SizeType count = mModules.Count();
+ for( VectorBase::SizeType i = 0; i < count ; ++i)
+ {
+ Module* module = mModules[i];
+ delete module;
+ }
+ mModules.Clear();
+}
+
+bool ModuleLoader::CompileAndRun(v8::Isolate* isolate,
+ const std::string& sourceCode,
+ const std::string& sourceFileName )
+{
+
+ v8::HandleScope handleScope( isolate );
+ v8::TryCatch tryCatch;
+
+ // convert from string to v8 string
+ v8::Local<v8::String> source = v8::String::NewFromUtf8( isolate, sourceCode.c_str());
+ v8::Local<v8::String> file = v8::String::NewFromUtf8( isolate, sourceFileName.c_str());
+ v8::ScriptOrigin origin(file);
+
+ // Compile the script
+ v8::Local<v8::Script> script = v8::Script::Compile( source, &origin);
+
+ // See if an exception has been thrown
+ if( tryCatch.HasCaught() || script.IsEmpty() )
+ {
+ // Print errors that happened during compilation.
+ V8Utils::ReportException( isolate, &tryCatch );
+ return false;
+ }
+
+ // Run the script
+ v8::Local<v8::Value> result = script->Run();
+
+ // in V8 test code ( they check for an exception and empty return object )
+ if( tryCatch.HasCaught() || result.IsEmpty() )
+ {
+ // Print errors that happened during execution.
+ V8Utils::ReportException( isolate, &tryCatch);
+ return false;
+ }
+
+ return true;
+}
+
+bool ModuleLoader::ExecuteScript( v8::Isolate* isolate,
+ const std::string& sourceCode,
+ const std::string& sourceFileName )
+{
+ StoreScriptInfo( sourceFileName );
+
+ return CompileAndRun(isolate, sourceCode, sourceFileName );
+}
+
+bool ModuleLoader::ExecuteScriptFromFile( v8::Isolate* isolate,
+ const std::string& fileName )
+{
+ std::string contents;
+
+ V8Utils::GetFileContents( fileName, contents );
+
+ return ExecuteScript( isolate, contents, fileName );
+}
+
+/**
+ * ### var module = require("module-name");
+ *
+ *
+ * There is no standard for modules or the 'require' keyword in JavaScript.<br />
+ * However CommonJS have this: http://wiki.commonjs.org/wiki/Modules/1.1.1 ( used by Node.js).
+ * <br /> <br />
+ *
+ * The concept behind 'require' keyword is simple, it allows you to include another
+ * JavaScript file, which exports an API / function / constructor / singleton.
+ *
+ *
+ * // example_module.js
+ * exports.hello = function() { return "hello world" }
+ *
+ * <br />
+ *
+ * // main.js
+ * var example = require( "example_module.js");
+ *
+ * log( example.hello() );
+ *
+ *
+
+ * ### Module writers guide:
+ *
+ *
+ * #### Exporting as a namespace
+ *
+ * Example of using a namespace to export functions / objects.
+ *
+ * // filesystem-helper.js
+ * exports.version = "FileSystem helper 1.0";
+ * exports.open = function() { }
+ * exports.close = function() { }
+ * exports.read = function() { }
+ * exports.write = function() { ... }
+ * exports.fileSize = function() {...}
+ *
+ * <br />
+ *
+ * // main.js
+ * var fs = require( "filesystem-helper.js");
+ *
+ * log( fs.version );
+ *
+ * var file = fs.open("myfile.txt");
+ * var data = fs.read( file );
+ *
+ *
+ *
+ * #### Exporting as a function
+ *
+ * In this example we are using module.exports directly to change it
+ * from an object literal with name-value pairs (exports object) to a function.
+ *
+ * // my_first_module.js
+ * module.exports = function() { log("hello-world"); }
+ *
+ * <br />
+ *
+ * // main.js
+ * var func = require("my_first_module.js");
+ * func(); // prints out hello-world
+ *
+ *
+ * #### Exporting as a constructor
+ *
+ *
+ * // ImageActor.js
+ * function ImageActor( position, rotation, image, name )
+ * {
+ * this = new dali.ImageActor( image );
+ * this.position = position;
+ * this.rotation = rotation;
+ * this.name = name;
+ * }
+ * module.exports = ImageActor;
+ *
+ * <br />
+ *
+ * // main.js
+ *
+ * var ImageActor = require(" ImageActor.js");
+ *
+ * var imageActor = new ImageActor( position, rotation, image, "my first image actor");
+ *
+ * #### Exporting as a singleton
+ *
+ * By exporting a singleton you have an object which has shared state between
+ * any modules using it.
+ *
+ * example:
+ *
+ * // image-database.js
+ *
+ * function ImageDatabase( )
+ * {
+ * this.addImage = function() { ... };
+ * this.removeImage = function() { ... };
+ * this.getImage = function() { ...};
+ * this.getImageCount = function() { ... };
+ * }
+ *
+ * module.exports = new ImageDatabase();
+ *
+ *
+ * <br />
+ *
+ * // main.js
+ *
+ * var database = require('image-database.js');
+ *
+ * database.addImage( myImage );
+ *
+ * <br />
+ *
+ * // another-module.js
+ * var database = require('image-database.js');
+ *
+ * // gets the same database object as main.js
+ *
+ *
+ * The first call to require('image-database.js') will create the image database.
+ * Further calls, will return the same instance, because require caches module.exports.
+ * Otherwise it would have to recompile and run the module every time require is called.
+ *
+ * ## Notes
+ *
+ * #### Automatic wrapping of a module by DALi:
+ *
+ * The module is automatically wrapped in a function by DALi before being executed ( similar technique to Node.js). </br>
+ * This is to prevent any functions / variables declared by the module entering the global namespace. </br>
+ * Currently the module will have access to all DALi global functions, like log, require and the DALi API ( actors / stage etc).</br>
+ *
+ *
+ * // Parameters passed to the internally generated function
+ * // module = reference to current module
+ * // module.exports = defines what the module exports
+ * // exports = reference to module.exports
+ * // __filename = module filename
+ * // __dirname = module directory
+ *
+ * function createModuleXYZ( exports ( === module.exports), module, __filename, __dirname )
+ * {
+ * //
+ * // Module code automatically inserted here.
+ * //
+ * log(" my first module ");
+ * var version = "1.3"; // this won't pollute global namespace
+ * exports.version = version;
+ * exports.logActorPosition = function( actorName )
+ * {
+ * var actor = dali.stage.getRootLayer().findChildByName(actorName );
+ * log( actor.x + "," + actor.y + "," + actor.z );
+ * }
+ * //
+ * // End module code
+ * //
+ *
+ * return module.exports;
+ * }
+
+ *
+ * Initially module.exports is an object literal with name-value pairs ( exports object).
+ * However it can be re-assigned to a constructor / function / singleton object as shown
+ * in the examples above.
+ *
+ *
+ * ### Circular dependencies:
+ *
+ * DALi JS supports circular dependencies as required by the CommonJS specification.
+ *
+ * #### a.js
+ *
+ *
+ * export.version = "1.3"
+ * export.loaded = false;
+ * var bModule = require('b.js')
+ * export.loaded = true;
+ *
+ * #### b.js
+ *
+ * var aModule = require('a.js')
+ * log( "aModule version = " + aModule.version + ", aModule loaded = " + aModule.loaded );
+ *
+ * //prints aModule = 1.3, aModule loaded = false
+ *
+ * #### main.js
+ *
+ * var aModule = require("a.js");
+ *
+ *
+ * When b.js requires a.js, it is given everything that is exported from a.js, up to the point
+ * b.js is required by a.js.
+ *
+ * ### 'require' background
+ *
+ * There is alternative to module spec in CommonJS called RequireJs ( http://requirejs.org/docs/node.html) <br />
+ * DALi JS tries to follows the CommonJS specification (used by Node.js) as it
+ * is supposed to be better suited to server side development. <br /><br />
+ *
+ * @method require
+ * @for ModuleLoader
+ *
+ */
+void ModuleLoader::Require(const v8::FunctionCallbackInfo< v8::Value >& args,
+
+ v8::Persistent<v8::ObjectTemplate>& globalObjectTemplate )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ bool found( false );
+ std::string fileName = V8Utils::GetStringParameter( PARAMETER_0, found, isolate , args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "require missing module name");
+ return;
+ }
+
+ // strip off any path / .js
+ std::string moduleName;
+ V8Utils::GetModuleName( fileName, moduleName );
+
+ // see if the module already exists
+ const Module* existingModule = FindModule( moduleName );
+ if( existingModule )
+ {
+ // printf(" using existing module %s \n",moduleName.c_str() );
+ args.GetReturnValue().Set( existingModule->mExportsObject );
+ return;
+ }
+
+ std::string path = mCurrentScriptPath; // path of top level script being executed
+ std::string contents;
+ V8Utils::GetFileContents(path + fileName, contents);
+
+ // wrap the module in a function to protect global namespace.
+ // the create function itself is global so we make it unique for each module
+ // For reference nodeJs does this as an anonymous function, but we're calling it from native side
+ // so need to pass parameters / get a name for it.
+ std::string functionName ="__createModule" + moduleName;
+ std::string source = "function " + functionName + "( exports, module, __filename, __directory) { ";
+ source+= contents;
+ source+=" \n };"; // close the function
+
+ CompileAndRun( isolate, source, fileName );
+
+ // We need to create module object, so that the module can read / write properties to it
+
+ v8::Local<v8::Object> moduleObject = v8::Object::New( isolate );
+ v8::Local<v8::Object> exportsObject = v8::Object::New( isolate );
+ moduleObject->Set( v8::String::NewFromUtf8( isolate, "exports"), exportsObject );
+ moduleObject->Set( v8::String::NewFromUtf8( isolate, "id"), v8::String::NewFromUtf8( isolate ,moduleName.c_str() ) );
+
+ // store the module exports object now, this is to allow for circular dependencies.
+ // If this-module requires another module, which then requires this module ( creating a circle), it will be given an export object
+ // which contains everything exported so far.
+ Module* module = StoreModule( path, fileName, moduleName, isolate, exportsObject );
+
+ v8::Local<v8::Context> currentContext = isolate->GetCurrentContext();
+
+ // get the CreateModule function
+ v8::Local<v8::Function> createModule = v8::Local<v8::Function>::Cast(currentContext->Global()->Get(v8::String::NewFromUtf8( isolate, functionName.c_str() )));
+
+ // add the arguments
+ std::vector< v8::Local<v8::Value> > arguments;
+ arguments.push_back( exportsObject );
+ arguments.push_back( moduleObject );
+ arguments.push_back( v8::String::NewFromUtf8( isolate, fileName.c_str() ));
+ arguments.push_back( v8::String::NewFromUtf8( isolate, path.c_str() ));
+
+
+ // call the CreateModule function
+ createModule->Call( createModule, arguments.size(), &arguments[0]); //[0]
+
+ // get the module.export object, the module writer may have re-assinged module.exports, so the exports object
+ // no longer references it.
+ v8::Local<v8::Value> moduleExportsValue = moduleObject->Get( v8::String::NewFromUtf8( isolate, "exports"));
+ v8::Local<v8::Object> moduleExports = moduleExportsValue->ToObject();
+
+ // Re-store the export ( possible nothing happens, because exports hasn't been re-assigned).
+ module->mExportsObject.Reset( isolate, moduleExports);
+
+ args.GetReturnValue().Set( moduleExports );
+
+}
+void ModuleLoader::StoreScriptInfo( const std::string& sourceFileName )
+{
+ V8Utils::GetFileDirectory( sourceFileName, mCurrentScriptPath);
+}
+
+Module* ModuleLoader::StoreModule( const std::string& path,
+ const std::string& fileName,
+ const std::string& moduleName,
+
+ v8::Isolate* isolate,
+ v8::Local<v8::Object>& moduleExportsObject )
+{
+ Module* module = new Module( path, fileName, moduleName, isolate, moduleExportsObject );
+ mModules.PushBack( module );
+ return module;
+
+}
+
+const Module* ModuleLoader::FindModule( const std::string& moduleName )
+{
+ VectorBase::SizeType count = mModules.Count();
+ for( VectorBase::SizeType i = 0; i < count ; ++i)
+ {
+ const Module* module = mModules[i];
+ if (module->mModuleName == moduleName )
+ {
+ return module;
+ }
+ }
+ return NULL;
+}
+
+
+} // V8Plugin
+
+} // Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_MODULE_LOADER_H__
+#define __DALI_V8PLUGIN_MODULE_LOADER_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <string.h>
+#include <dali/public-api/common/dali-vector.h>
+
+// INTERNAL INCLUDES
+#include <module-loader/module.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+/**
+ *
+ * Responsible for executing JavaScript source code.
+ * This includes loading other JavaScript files that may be referenced
+ * inside JavaScript using the 'require' keyword.
+ *
+ * Notes:
+ *
+ * A module named with a forward slash is loaded as an absolute path:
+ * E.g. require "/usr/apps/scripts/my_module.js"
+ *
+ * A module pre-fixed with a dot slash ( current directory) then the path is relative
+ * to the calling scripts path. E.g.
+ *
+ * -- my_first.js --
+ * require "./circle.js"; // load circle.js from same directory as my_first.js
+ *
+ * @TODO
+ * ----------
+ * Without a leading '/' or './' the module is loaded from the DALi modules directory or
+ * the applications user defined module directory.
+ * E.g. require "dali-spline.js" // search dali-module directory first, then any user
+ * defined module locations.
+ * ------------
+ *
+ *
+ */
+class ModuleLoader
+{
+public:
+
+ /**
+ * Constructor
+ */
+ ModuleLoader();
+
+ /**
+ * non virtual destructor, not intended as a base class
+ */
+ ~ModuleLoader();
+
+
+ /**
+ * Execute a script from a file
+ * @param[in] fileName file name
+ */
+ bool ExecuteScriptFromFile( v8::Isolate* isolate, const std::string& fileName );
+
+
+ /**
+ * Execute a script
+ * @param[in] sourceCode source code to run
+ * @param[in] sourceFileName source file name
+ */
+ bool ExecuteScript( v8::Isolate* isolate,
+ const std::string& sourceCode,
+ const std::string& sourceFileName );
+
+
+ /**
+ * Implements JavaScript Require functionality
+ */
+ void Require(const v8::FunctionCallbackInfo< v8::Value >& args, v8::Persistent<v8::ObjectTemplate>& globalObjectTemplate );
+
+private:
+
+ /**
+ * Compile and run the JavaScript code
+ * @param[in] sourceCode source code to run
+ * @param[in] sourceFileName source file name
+ */
+ bool CompileAndRun(v8::Isolate* isolate,
+ const std::string& sourceCode,
+ const std::string& sourceFileName );
+
+ /**
+ * Store information about the current script
+ * @param[in] sourceFileName source file name
+ */
+ void StoreScriptInfo( const std::string& sourceFileName );
+
+ /**
+ * Store module information
+ * @param[in] sourceFileName source file name
+ * @return module object
+ */
+ Module* StoreModule( const std::string& path,
+ const std::string& fileName,
+ const std::string& moduleName,
+ v8::Isolate* isolate,
+ v8::Local<v8::Object>& moduleExportsObject );
+
+ /**
+ * Find a module
+ * @param[in] moduleName module name
+ * @return module
+ */
+ const Module* FindModule( const std::string& moduleName );
+
+private:
+
+ Dali::Vector< Module*> mModules; ///< vector of modules
+ std::string mCurrentScriptPath; ///< path of the current script being executed (via ExecuteScript).
+
+};
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header MODULE_LOADER
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "module.h"
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+Module::Module()
+{
+
+}
+
+Module::Module( const std::string& path,
+ const std::string& fileName,
+ const std::string& moduleName,
+
+ v8::Isolate* isolate,
+ v8::Local<v8::Object>& exportsObject)
+:mFileName( fileName ),
+ mPath( path),
+ mModuleName(moduleName)
+
+{
+ mExportsObject.Reset( isolate, exportsObject);
+}
+
+Module::~Module()
+{
+
+}
+
+
+
+} // V8Plugin
+
+} // Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_MODULE_H__
+#define __DALI_V8PLUGIN_MODULE_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <string>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+/**
+ *
+ * Module class,
+ * contains
+ *
+ */
+class Module
+{
+public:
+
+ Module(const std::string& path,
+ const std::string& fileName,
+ const std::string& moduleName,
+
+ v8::Isolate* isolate,
+ v8::Local<v8::Object>& exportsObject);
+
+ ~Module();
+
+ std::string mFileName;
+ std::string mPath;
+ std::string mModuleName;
+
+
+ /**
+ * holds the exports object
+ * e.g. exports.hello = function() {" hello world"}
+ */
+ v8::Persistent<v8::Object> mExportsObject;
+
+ /*
+ * Currently we allow the modules context to be released after it has been
+ * compiled and run ( so we don't need to store it).
+ * Data is shared between contexts which suggests
+ * the module exports object can be kept alive if the context it was created in is deleted.
+ * If this is not the case, then start to store the context.
+ */
+ // v8::Persistent<v8::Context> mContext.
+
+private:
+
+ Module();
+
+ Module( const Module& ); ///< undefined copy constructor
+ Module& operator=( const Module& ); ///< undefined assignment operator
+
+
+
+};
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header MODULE_LOADER
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "handle-wrapper.h"
+
+// EXTERNAL INCLUDES
+#include <sstream>
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <shared/base-wrapped-object.h>
+#include <shared/object-template-helper.h>
+#include <object/property-value-wrapper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+HandleWrapper::HandleWrapper( BaseWrappedObject::Type type,
+ Handle handle,
+ GarbageCollectorInterface& gc ) :
+ BaseWrappedObject( type, gc ),
+ mHandle( handle )
+{
+}
+
+HandleWrapper::~HandleWrapper()
+{
+
+}
+HandleWrapper* HandleWrapper::Unwrap( v8::Isolate* isolate, v8::Handle< v8::Object> obj)
+{
+ v8::HandleScope handleScope( isolate );
+
+ v8::Local<v8::External> field = v8::Local<v8::External>::Cast( obj->GetInternalField(0) );
+ void* ptr = field->Value();
+ return static_cast< HandleWrapper *>(ptr);
+}
+
+// may have to do this IsUpper to intercept function calls or as function?
+void HandleWrapper::PropertyGet( v8::Local<v8::String> propertyName,
+ const v8::PropertyCallbackInfo<v8::Value>& info)
+{
+ v8::Isolate* isolate = info.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ // get the property name
+ std::string name = V8Utils::v8StringToStdString( propertyName );
+
+ if( std::isupper( name[0] ))
+ {
+ return;
+ }
+
+ // unwrap the object
+ HandleWrapper* handleWrapper = Unwrap( isolate, info.This() );
+ Handle handle = handleWrapper->mHandle;
+
+ // get the property index
+ // convert from camel case to dali property style with hyphens
+ std::string daliPropertyName = V8Utils::JavaScriptNameToPropertyName(name);
+ Dali::Property::Index index = handle.GetPropertyIndex( daliPropertyName );
+
+ if(index != Dali::Property::INVALID_INDEX)
+ {
+ Dali::Property::Value value = handle.GetProperty(index);
+
+ // Simple Dali properties (ints, strings, bools etc) are stored as JavaScript primitives (v8::Boolean ...)
+ // more complex properties (Vectors, Rectangles...) are wrapped by a JavaScript object
+ v8::Local<v8::Object> ret = PropertyValueWrapper::WrapDaliProperty( isolate, value );
+
+ info.GetReturnValue().Set( ret );
+ }
+ else
+ {
+ // std::string error="Invalid property Get for "+name + "\n";
+ // DALI_SCRIPT_EXCEPTION( isolate, error );
+ }
+
+}
+void HandleWrapper::PropertySet( v8::Local<v8::String> propertyName,
+ v8::Local<v8::Value> javaScriptValue,
+ const v8::PropertyCallbackInfo<v8::Value>& info)
+{
+
+ v8::Isolate* isolate = info.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ // get the property name
+ std::string name = V8Utils::v8StringToStdString( propertyName );
+
+ // try to filter out function calls before going to the property system
+ // @todo use installed functions to generate a map
+ if( ( name.compare(0,2,"is") == 0 ) ||
+ ( name.compare(0,3,"get") == 0 ) ||
+ ( name.compare(0,3,"add") == 0 ) ||
+ ( name.compare(0,3,"set") == 0 ) ||
+ ( name.compare(0,3,"get") == 0 ) ||
+ ( name.compare(0,4,"find") == 0 ) ||
+ ( name.compare(0,6,"remove") == 0 )
+ )
+ {
+ //
+ return;
+ }
+ // unwrap the object
+ HandleWrapper* handleWrapper = Unwrap( isolate, info.This() );
+ if( !handleWrapper )
+ {
+ // printf("setting property name %s \n", name.c_str());
+ return;
+ }
+
+ // DALI_ASSERT_DEBUG( handleWrapper && "not a dali object");
+ Handle handle = handleWrapper->mHandle;
+
+ // convert from camel case to dali property style with hyphens
+ std::string daliPropertyName = V8Utils::JavaScriptNameToPropertyName(name);
+ Dali::Property::Index index = handle.GetPropertyIndex( daliPropertyName );
+
+ if(index != Dali::Property::INVALID_INDEX)
+ {
+ Dali::Property::Type type = handle.GetPropertyType(index);
+
+ // we know the type we want to set ( int, vector, etc..)
+ // try and convert the javascript value in to the type we want.
+ Dali::Property::Value value = PropertyValueWrapper::ExtractPropertyValue( isolate, javaScriptValue, type);
+
+ if( Dali::Property::NONE == value.GetType() )
+ {
+ std::stringstream msg;
+ msg << "Invalid property Set: '";
+ msg << name;
+ msg << "(Index = ";
+ msg << index;
+ msg << ")";
+ msg << "' Cannot convert value to correct type: (";
+ msg << type;
+ msg << ")";
+ msg << Dali::PropertyTypes::GetName(type);
+ DALI_SCRIPT_EXCEPTION( isolate, msg.str().c_str());
+ }
+ else
+ {
+ handle.SetProperty( index, value );
+ }
+ }
+ else
+ {
+ std::string error="Invalid property Set for "+name + "\n";
+ DALI_SCRIPT_EXCEPTION( isolate, error );
+ }
+}
+
+void HandleWrapper::AddInterceptsToTemplate( v8::Isolate* isolate, v8::Local<v8::ObjectTemplate>& objTemplate )
+{
+ v8::HandleScope handleScope( isolate );
+
+ objTemplate->SetNamedPropertyHandler( HandleWrapper::PropertyGet, HandleWrapper::PropertySet);
+
+ ObjectTemplateHelper::AddSignalConnectAndDisconnect( isolate, objTemplate );
+
+}
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_HANDLE_WRAPPER_H__
+#define __DALI_V8PLUGIN_HANDLE_WRAPPER_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/public-api/object/handle.h>
+
+// INTERNAL INCLUDES
+#include <shared/base-wrapped-object.h>
+#include <signals/signal-manager.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+class BaseCallBack;
+
+class HandleWrapper : public BaseWrappedObject
+{
+public:
+ HandleWrapper( BaseWrappedObject::Type type,
+ Handle handle,
+ GarbageCollectorInterface& gc );
+
+ virtual ~HandleWrapper();
+
+ /**
+ * @brief get the value for a property for JavaScript object than contains a Dali Handle.
+ * E.g. Get( "x", JavaScript object that wraps a Dali Handle )
+ * @param[in] propertyName property name
+ * @param[in] info reference to PropertyCallbackInfo structure (contains the Javascript
+ * object and the return value).
+ */
+ static void PropertyGet( v8::Local<v8::String> propertyName,
+ const v8::PropertyCallbackInfo<v8::Value>& info);
+
+ /**
+ * @brief Set the value for a property for JavaScript object than contains a Dali Handle.
+ * E.g. Set( "x", 103, JavaScript object that wraps a Dali Handle)
+ * @param[in] propertyName property name
+ * @param[in] javaScriptValue javascript value to set, this is typically a number
+ * @param[in] info reference to PropertyCallbackInfo structure (contains the Javascript
+ * object).
+ */
+ static void PropertySet( v8::Local<v8::String> propertyName,
+ v8::Local<v8::Value> javaScriptValue,
+ const v8::PropertyCallbackInfo<v8::Value>& info);
+
+ static HandleWrapper* Unwrap( v8::Isolate* isolate, v8::Handle< v8::Object> obj);
+
+ /**
+ * Should be called by an class that inherits from HandleWrapper to add
+ * property get / set functionality to the javascript object
+ * along with Signal connect / disconnect
+ */
+ static void AddInterceptsToTemplate( v8::Isolate* isolate, v8::Local<v8::ObjectTemplate>& objTemplate );
+
+
+ Handle GetHandle() { return mHandle; }
+ Handle mHandle;
+ ConnectionTracker mConnectionTracker;
+
+
+ virtual SignalManager* GetSignalManager() { return &mSignalManager;}
+
+private:
+
+ SignalManager mSignalManager;
+
+};
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+// CLASS HEADER
+#include "property-value-wrapper.h"
+
+// EXTERNAL INCLUDES
+#include <dali/integration-api/debug.h>
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <dali-wrapper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace
+{
+
+struct WrapTypeInfo
+{
+ Dali::Property::Type propertyType;
+ BaseWrappedObject::Type wrappedType;
+};
+/**
+ * lookup table to convert between dali property types and wrapped types
+ * Wrapped types includes actors / timers / render tasks, hence we can't just
+ * use the dali property types to encode what a wrapped pointer contains
+ */
+const WrapTypeInfo WrapTypeInfoLookup[]=
+{
+ { Dali::Property::VECTOR2, BaseWrappedObject::VECTOR2 },
+ { Dali::Property::VECTOR3, BaseWrappedObject::VECTOR3 },
+ { Dali::Property::VECTOR4, BaseWrappedObject::VECTOR4 },
+ { Dali::Property::RECTANGLE, BaseWrappedObject::RECTANGLE },
+ { Dali::Property::ROTATION, BaseWrappedObject::ROTATION },
+ { Dali::Property::MATRIX, BaseWrappedObject::MATRIX },
+ { Dali::Property::MATRIX3, BaseWrappedObject::MATRIX3 },
+
+
+};
+const unsigned int WrapTypeLookupCount = sizeof( WrapTypeInfoLookup ) / sizeof( WrapTypeInfo );
+
+BaseWrappedObject::Type GetWrappedType( Dali::Property::Type type )
+{
+ for( unsigned int i = 0; i < WrapTypeLookupCount; ++i)
+ {
+ if( WrapTypeInfoLookup[ i ].propertyType == type )
+ {
+ return WrapTypeInfoLookup[ i ].wrappedType;
+ }
+ }
+ DALI_LOG_ERROR("GetWrappedType failed \n");
+ return BaseWrappedObject::UNKNOWN;
+}
+
+// Templates for setting members on propertys, like, x,y,z on a vector
+template <typename T, typename S>
+void SetX( Dali::Property::Value &value, S& v)
+{
+ // to set a property value, we need to read into a temporary
+ // then assign it back.
+ // E.g. Vector2 temp = value.Get<Vector2>();
+ // temp.x = 10;
+ // value = temp;
+ T tmp( value.Get<T>() );
+ tmp.x = v;
+ value = tmp;
+}
+
+template <typename T, typename S>
+void SetY( Dali::Property::Value &value, S& v)
+{
+ T tmp = value.Get<T>();
+ tmp.y = v;
+ value = tmp ;
+}
+
+template <typename T, typename S>
+void SetZ( Dali::Property::Value &value, S& v)
+{
+ T tmp = value.Get<T>();
+ tmp.z = v;
+ value = tmp ;
+}
+
+template <typename T, typename S>
+void SetW( Dali::Property::Value &value, S& v)
+{
+ T tmp = value.Get<T>();
+ tmp.w = v;
+ value = tmp ;
+}
+template <typename T, typename S>
+void SetWidth( Dali::Property::Value &value, S& v)
+{
+ T tmp = value.Get<T>();
+ tmp.width = v;
+ value = tmp ;
+}
+
+template <typename T, typename S>
+void SetHeight( Dali::Property::Value &value, S& v)
+{
+ T tmp = value.Get<T>();
+ tmp.height = v;
+ value = tmp ;
+}
+
+v8::Handle< v8::Value > GetV8ValueFrom( v8::Isolate* isolate,
+ const Dali::Property::Value& value,
+ const std::string& field)
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::Value> ret;
+
+ Dali::Property::Type type = value.GetType();
+ std::string objectType="Unknown type";
+
+ // simple property values are handled by the actor wrapper so we just handle property values with sub fields
+ switch(type)
+ {
+ case Dali::Property::VECTOR2:
+ {
+ objectType = "Vector2";
+
+ if( field == "x" || field == "width" )
+ {
+ Dali::Vector2 v2 = value.Get<Dali::Vector2>() ;
+ ret = v8::Number::New( isolate, v2.x) ;
+ }
+ else if(field == "y" || field == "height")
+ {
+ Dali::Vector2 v2 = value.Get<Dali::Vector2>() ;
+ ret = v8::Number::New( isolate, v2.y) ;
+ }
+
+ break;
+ }
+ case Dali::Property::VECTOR3:
+ {
+ objectType = "Vector3";
+
+ if(field == "x" || field == "width" || field == "r")
+ {
+ Dali::Vector3 v3 = value.Get<Dali::Vector3>() ;
+ ret = v8::Number::New( isolate, v3.x) ;
+ }
+ else if(field == "y" || field == "height" || field == "g")
+ {
+ Dali::Vector3 v3 = value.Get<Dali::Vector3>() ;
+ ret = v8::Number::New( isolate, v3.y) ;
+ }
+ else if(field == "z" || field == "depth" || field == "b")
+ {
+ Dali::Vector3 v3 = value.Get<Dali::Vector3>() ;
+ ret = v8::Number::New( isolate, v3.z) ;
+ }
+ break;
+ }
+ case Dali::Property::VECTOR4:
+ {
+ objectType = "vector4";
+
+ if(field == "x" || field == "s" || field == "r")
+ {
+ Dali::Vector4 v4 = value.Get<Dali::Vector4>() ;
+ ret = v8::Number::New( isolate, v4.x) ;
+ }
+ else if(field == "y" || field == "g" || field == "t")
+ {
+ Dali::Vector4 v4 = value.Get<Dali::Vector4>() ;
+ ret = v8::Number::New( isolate, v4.y) ;
+ }
+ else if(field == "z" || field == "r" || field == "b")
+ {
+ Dali::Vector4 v4 = value.Get<Dali::Vector4>() ;
+ ret = v8::Number::New( isolate, v4.z) ;
+ }
+ else if(field == "w" || field == "a" || field == "q")
+ {
+ Dali::Vector4 v4 = value.Get<Dali::Vector4>() ;
+ ret = v8::Number::New( isolate, v4.w) ;
+ }
+
+ break;
+ }
+ case Dali::Property::ROTATION:
+ {
+ objectType = "rotation";
+
+ if(field == "roll")
+ {
+ Dali::Vector4 v4 = value.Get<Dali::Quaternion>().EulerAngles();
+ ret = v8::Number::New( isolate, v4.z) ;
+ }
+ else if(field == "pitch")
+ {
+ Dali::Vector4 v4 = value.Get<Dali::Quaternion>().EulerAngles();
+ ret = v8::Number::New( isolate, v4.x) ;
+ }
+ else if(field == "yaw")
+ {
+ Dali::Vector4 v4 = value.Get<Dali::Quaternion>().EulerAngles();
+ ret = v8::Number::New( isolate, v4.y) ;
+ }
+
+ else if(field == "axis")
+ {
+ Dali::Vector3 axis;
+ float angle;
+ value.Get<Dali::Quaternion>().ToAxisAngle(axis, angle);
+ ret = PropertyValueWrapper::WrapDaliProperty( isolate , Dali::Property::Value( axis ) );
+ }
+ else if(field == "angle")
+ {
+ Dali::Vector3 axis;
+ float angle;
+ value.Get<Dali::Quaternion>().ToAxisAngle(axis, angle);
+ ret = PropertyValueWrapper::WrapDaliProperty( isolate , Dali::Property::Value( angle ) );
+ }
+ break;
+ }
+ case Dali::Property::RECTANGLE:
+ {
+ objectType = "rectangle";
+
+ if(field == "x")
+ {
+ Dali::Rect<int> r = value.Get<Dali::Rect<int> >() ;
+ ret = v8::Number::New( isolate, r.x) ;
+ }
+ else if(field == "y")
+ {
+ Dali::Rect<int> r = value.Get<Dali::Rect<int> >() ;
+ ret = v8::Number::New( isolate, r.y) ;
+ }
+ else if(field == "width")
+ {
+ Dali::Rect<int> r = value.Get<Dali::Rect<int> >() ;
+ ret = v8::Number::New( isolate, r.width) ;
+ }
+ else if(field == "height")
+ {
+ Dali::Rect<int> r = value.Get<Dali::Rect<int> >() ;
+ ret = v8::Number::New( isolate, r.height) ;
+ }
+ break;
+ }
+
+ default:
+ {
+ // will trigger a type error as ret.IsEmpty() == true
+ break;
+ }
+
+ } // switch type
+
+ if ( ret.IsEmpty() )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Cannot get property with field " + objectType+ ":" + field );
+ }
+ return handleScope.Escape(ret);
+}
+
+
+/*
+ * Setting a field on a property, e.g. Position.x = 5 or Rect.Width = 100
+ * The only property field that supports a struct is rotation.axis
+ */
+void SetFromV8Value(v8::Isolate* isolate,
+ Dali::Property::Value& value,
+ const std::string& field,
+ v8::Local<v8::Value> v8Value )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+
+ Dali::Property::Type type = value.GetType();
+
+ float asFloat = 0.f;
+ int asInt = 0;
+
+ // all are numbers at the moment
+ if( v8Value->IsNumber() )
+ {
+ asFloat = static_cast<float>(v8Value->NumberValue());
+ asInt = static_cast<int>(asFloat);
+ }
+ else
+ {
+ // if the v8 value isn't a number, then then only Dali object we support is a Vector3 part of a rotation
+ if( ! (type == Dali::Property::ROTATION && field == "axis") )
+ {
+ DALI_SCRIPT_EXCEPTION(isolate,std::string("Cannot set property with field (value is not a number):") + field);
+ return;
+ }
+ }
+
+ // simple property values are handled by the actor wrapper so we just handle property values with sub fields
+ switch(type)
+ {
+ case Dali::Property::VECTOR2:
+ {
+ if(field == "x" || field == "width")
+ {
+ SetX<Dali::Vector2>(value, asFloat) ;
+ }
+ else if(field == "y" || field == "height")
+ {
+ SetY<Dali::Vector2>(value, asFloat) ;
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION(isolate, std::string("Cannot set property with field (unknown type):") + field);
+ return;
+ }
+ break;
+ }
+ case Dali::Property::VECTOR3:
+ {
+ if(field == "x" || field == "width" || field == "r")
+ {
+ SetX<Dali::Vector3>(value, asFloat) ;
+ }
+ else if(field == "y" || field == "height" || field == "g")
+ {
+ SetY<Dali::Vector3>(value, asFloat) ;
+ }
+ else if(field == "z" || field == "depth" || field == "b")
+ {
+ SetZ<Dali::Vector3>(value, asFloat) ;
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION(isolate, std::string("Cannot set property with field (unknown type):") + field);
+ return;
+ }
+ break;
+ }
+ case Dali::Property::VECTOR4:
+ {
+ if(field == "x" || field == "s" || field == "r")
+ {
+ SetX<Dali::Vector4>(value, asFloat) ;
+ }
+ else if(field == "y" || field == "g" || field == "t")
+ {
+ SetY<Dali::Vector4>(value, asFloat) ;
+ }
+ else if(field == "z" || field == "r" || field == "b")
+ {
+ SetZ<Dali::Vector4>(value, asFloat) ;
+ }
+ else if(field == "w" || field == "a" || field == "q")
+ {
+ SetW<Dali::Vector4>(value, asFloat) ;
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, std::string("Cannot set property with field (unknown type):") + field);
+ return;
+ }
+ break;
+ }
+ case Dali::Property::ROTATION:
+ {
+ if(field == "roll")
+ {
+ Dali::Vector4 v4 = value.Get<Dali::Quaternion>().EulerAngles();
+ v4.z = asFloat;
+ value = Dali::Quaternion(v4.x, v4.y, v4.z);
+ }
+ else if(field == "pitch")
+ {
+ Dali::Vector4 v4 = value.Get<Dali::Quaternion>().EulerAngles();
+ v4.x = asFloat;
+ value = Dali::Quaternion(v4.x, v4.y, v4.z);
+ }
+ else if(field == "yaw")
+ {
+ Dali::Vector4 v4 = value.Get<Dali::Quaternion>().EulerAngles();
+ v4.y = asFloat;
+ value = Dali::Quaternion(v4.x, v4.y, v4.z);
+ }
+ else if(field == "axis")
+ {
+ Dali::Vector3 axis;
+ float angle;
+ value.Get<Dali::Quaternion>().ToAxisAngle(axis, angle);
+
+ if( v8Value->IsObject() )
+ {
+ v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast( v8Value );
+
+ PropertyValueWrapper* wrapper = PropertyValueWrapper::Unwrap( isolate, object );
+ Dali::Property::Value v3 = wrapper->GetValue();
+
+ if(v3.GetType() == Dali::Property::VECTOR3)
+ {
+ value = Dali::Quaternion(angle, v3.Get<Dali::Vector3>());
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Axis expects a Vector3:");
+ return;
+ }
+
+ }
+ }
+ else if(field == "angle")
+ {
+ Dali::Vector3 axis;
+ float angle;
+ value.Get<Dali::Quaternion>().ToAxisAngle(axis, angle);
+ value = Dali::Quaternion(asFloat, axis);
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, std::string("Cannot set property with field (unknown type):") + field);
+ return;
+ }
+ break;
+ }
+ case Dali::Property::RECTANGLE:
+ {
+ if(field == "x")
+ {
+ SetX<Dali::Rect<int> >(value, asInt) ;
+ }
+ else if(field == "y")
+ {
+ SetY<Dali::Rect<int> >(value, asInt) ;
+ }
+ else if(field == "width")
+ {
+ SetWidth<Dali::Rect<int> >(value, asInt) ;
+ }
+ else if(field == "height")
+ {
+ SetHeight<Dali::Rect<int> >(value, asInt);
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, std::string("Cannot set property with field (unknown type):") + field);
+ return;
+ }
+ break;
+ }
+ default:
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, std::string("Cannot set property with field (unknown type):") + field);
+ return;
+ break;
+ }
+
+ } // switch type
+
+} // SetFromV8Value
+
+
+bool IsPrimitive( const Dali::Property::Value &value )
+{
+ switch( value.GetType() )
+ {
+ case Dali::Property::BOOLEAN:
+ case Dali::Property::INTEGER:
+ case Dali::Property::UNSIGNED_INTEGER:
+ case Dali::Property::STRING:
+ case Dali::Property::FLOAT:
+ {
+ return true;
+ }
+ default:
+ {
+ return false;
+ }
+ }
+}
+v8::Local<v8::Object> CreateJavaScriptPrimitive( v8::Isolate* isolate, const Dali::Property::Value &value )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+
+ v8::Local<v8::Value> v8Value ;
+
+ switch( value.GetType() )
+ {
+ case Dali::Property::FLOAT:
+ {
+ v8Value = v8::Number::New( isolate, value.Get<float>() );
+ break;
+ }
+ case Dali::Property::BOOLEAN:
+ {
+ v8Value = v8::Boolean::New( isolate, value.Get<bool>());
+ break;
+ }
+ case Dali::Property::INTEGER:
+ {
+ v8Value = v8::Integer::New( isolate, value.Get<int>());
+ break;
+ }
+ case Dali::Property::UNSIGNED_INTEGER:
+ {
+ v8Value = v8::Integer::New( isolate, value.Get<unsigned int>());
+ break;
+ }
+ case Dali::Property::STRING:
+ {
+ std::string string = value.Get< std::string >();
+ v8Value = v8::String::NewFromUtf8( isolate, string.c_str());
+ break;
+ }
+ default:
+ {
+ DALI_LOG_ERROR("Primitive mismatch \n");
+ break;
+ }
+ }
+ v8::Local<v8::Object> ret = v8Value->ToObject();
+
+ return handleScope.Escape( ret );
+}
+
+
+} // un-named namespace
+
+
+
+Dali::Property::Value PropertyValueWrapper::VectorOrMatrixFromV8Array( v8::Isolate* isolate, const v8::Local<v8::Value>& v8Value)
+{
+ v8::EscapableHandleScope handleScope( isolate );
+
+ Dali::Property::Value ret;
+
+ if( !v8Value->IsArray() )
+ {
+ return ret;
+ }
+ v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast( v8Value );//v8::Array::Cast( *v8Value);
+ uint32_t len = array->Length();
+ float out[16] = {0.f, 0.f, 0.f, 0.f,0.f, 0.f, 0.f, 0.f,0.f, 0.f, 0.f, 0.f,0.f, 0.f, 0.f, 0.f};
+ const unsigned int size = sizeof(out) / sizeof(float);
+ for( uint32_t i=0; i < (len > size? size:len); ++i)
+ {
+ v8::Handle<v8::Value> entry = array->Get( i);// v8::Integer::New( isolate, i));
+ if( V8Utils::IsNumberPrimitiveOrObject( entry ) )
+ {
+ out[i] = V8Utils::GetNumberValue( isolate, entry );
+ //printf("entry is a number %d , entry is a int %f \n",(int)i , out[i] );
+ }
+ }
+ if(16 == len )
+ {
+ ret = Dali::Matrix( out[0] );
+ }
+ else if ( 9 == len )
+ {
+ ret = Dali::Matrix3( out[0],out[1],out[2],out[3],out[4],out[5],out[6],out[7],out[8] );
+ }
+ else if(4 == len)
+ {
+ ret = Dali::Vector4(out[0], out[1], out[2], out[3]);
+ }
+ else if(3 == len)
+ {
+ ret = Dali::Vector3(out[0], out[1], out[2]);
+ }
+ else if(2 == len)
+ {
+ ret = Dali::Vector2(out[0], out[1]);
+ }
+ else if(1 == len)
+ {
+ ret = out[0];
+ }
+
+ return ret;
+}
+
+Dali::Property::Value PropertyValueWrapper::ArrayFromV8Array( v8::Isolate* isolate, const v8::Local<v8::Value>& v8Value)
+{
+ v8::EscapableHandleScope handleScope( isolate );
+
+ if( !v8Value->IsArray() )
+ {
+ return Dali::Property::Value();
+ }
+
+ //Cast v8::Value to v8::Array
+ v8::Local<v8::Array> v8Array = v8::Local<v8::Array>::Cast( v8Value );
+ uint32_t elementCount = v8Array->Length();
+ Dali::Property::Array data( elementCount );
+ bool bFound(false);
+ for( uint32_t i(0); i<elementCount; ++i )
+ {
+ //Get Property::Value for each element in the array
+ data[i] = V8Utils::GetPropertyValueFromObject( bFound, isolate, v8Array->Get(i) );
+ }
+
+ //return the Property::Value
+ return Dali::Property::Value( data );
+}
+
+v8::Persistent<v8::ObjectTemplate> PropertyValueWrapper::mTemplatePrimitive;
+
+
+PropertyValueWrapper::~PropertyValueWrapper()
+{
+
+}
+
+PropertyValueWrapper::PropertyValueWrapper( const Dali::Property::Value& value, GarbageCollectorInterface& gc )
+ : BaseWrappedObject( GetWrappedType( value.GetType() ), gc ),
+ mValue(value)
+{
+}
+
+Dali::Property::Value PropertyValueWrapper::ExtractPropertyValue( v8::Isolate* isolate, v8::Local< v8::Value> v8Value, Dali::Property::Type type)
+{
+ v8::HandleScope handleScope( isolate);
+
+ Dali::Property::Value daliPropertyValue;
+
+ // check if it's a dali object (vector, rect etc)
+ if( v8Value->IsObject() )
+ {
+ v8::Local<v8::Object> object = v8::Handle<v8::Object>::Cast(v8Value);
+ if( object->InternalFieldCount() == BaseWrappedObject::FIELD_COUNT )
+ {
+ if( BaseWrappedObject::IsWrappedType( isolate, object, GetWrappedType(type) ) )
+ {
+ PropertyValueWrapper* propertyWrapper = Unwrap( isolate, object );
+ return propertyWrapper->GetValue();
+ }
+ }
+ }
+
+ // check if it's a javascript Array
+ Dali::Property::Value array = VectorOrMatrixFromV8Array( isolate, v8Value );
+
+ switch(type)
+ {
+ case Dali::Property::BOOLEAN:
+ {
+ if( V8Utils::IsBooleanPrimitiveOrObject( v8Value ) )
+ {
+ daliPropertyValue = Dali::Property::Value( V8Utils::GetBooleanValue( isolate, v8Value));
+ }
+ break;
+ }
+ case Dali::Property::FLOAT:
+ {
+ if( V8Utils::IsNumberPrimitiveOrObject( v8Value ) )
+ {
+ daliPropertyValue = Dali::Property::Value( V8Utils::GetNumberValue( isolate, v8Value) );
+ }
+
+ break;
+ }
+ case Dali::Property::INTEGER: // todo is it wise to distinguish int from float in javascript?!
+ {
+ if( v8Value->IsInt32() )
+ {
+ daliPropertyValue = Dali::Property::Value( v8Value->Int32Value() ) ;//static_cast<int>( V8Utils::GetNumberValue( isolate, v8Value) ));
+ }
+ break;
+ }
+ case Dali::Property::UNSIGNED_INTEGER:
+ {
+ if( v8Value->IsUint32() )
+ {
+ daliPropertyValue = Dali::Property::Value( v8Value->Uint32Value() );//static_cast<unsigned int>( V8Utils::GetNumberValue( isolate, v8Value) ));
+ }
+ break;
+ }
+ case Dali::Property::STRING:
+ {
+ if( V8Utils::IsStringPrimitiveOrObject( v8Value) )
+ {
+ daliPropertyValue = Dali::Property::Value( V8Utils::GetStringValue( isolate, v8Value) );
+ }
+
+
+ break;
+ }
+ case Dali::Property::VECTOR2:
+ {
+ if( array.GetType() == Dali::Property::VECTOR2 )
+ {
+ daliPropertyValue = array;
+ }
+ break;
+ }
+ case Dali::Property::VECTOR3:
+ {
+ if( array.GetType() == Dali::Property::VECTOR3)
+ {
+ daliPropertyValue = array;
+ }
+ break;
+ }
+ case Dali::Property::VECTOR4:
+ {
+
+ if( array.GetType() == Dali::Property::VECTOR4)
+ {
+ daliPropertyValue = array;
+ }
+ break;
+ }
+ case Dali::Property::ROTATION:
+ {
+ if( array.GetType() == Dali::Property::VECTOR4)
+ {
+ // v4 treated as axis angle
+ Dali::Vector4 v = array.Get<Dali::Vector4>();
+ daliPropertyValue = Dali::AngleAxis(Dali::Degree(v[0]), Dali::Vector3(v[1], v[2], v[3]));
+ }
+ else if(array.GetType() == Dali::Property::VECTOR3)
+ {
+ // v3 treated as euler
+ Dali::Vector3 v = array.Get<Dali::Vector3>();
+ daliPropertyValue = Dali::Quaternion(v[0], v[1], v[2]);
+ }
+ break;
+ }
+ case Dali::Property::MATRIX:
+ {
+ Dali::Matrix mat = array.Get<Dali::Matrix>();
+ daliPropertyValue = mat;
+ break;
+ }
+ case Dali::Property::MATRIX3:
+ {
+ Dali::Matrix3 mat = array.Get<Dali::Matrix3>();
+ daliPropertyValue = mat;
+ break;
+ }
+ case Dali::Property::ARRAY:
+ {
+ daliPropertyValue = ArrayFromV8Array( isolate, v8Value );
+ break;
+ }
+ case Dali::Property::NONE:
+ case Dali::Property::TYPE_COUNT:
+ default:
+ {
+ break;
+ }
+ } // switch type
+
+ return daliPropertyValue;
+}
+
+void PropertyValueWrapper::NewRotation( const v8::FunctionCallbackInfo< v8::Value >& args)
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate);
+
+ if(!args.IsConstructCall())
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Rotation constructor called without 'new'");
+ return;
+ }
+ v8::Local<v8::Object > object;
+
+ float v[4] = {0.f,0.f,0.f,0.f} ;
+
+ bool foundAllArguments(false);
+ V8Utils::ReadFloatArguments( foundAllArguments, v, 4, args, 0.f );
+
+ int len = args.Length();
+
+ // if length = 4 create AngleAxis, else create Quaternion
+
+ if(len > 3)
+ {
+ Dali::AngleAxis axis( Dali::Degree(v[0] ), Dali::Vector3(v[1], v[2], v[3]) );
+ object = WrapDaliProperty( isolate , Dali::Property::Value( axis ) );
+ }
+ else if(len > 2)
+ {
+ Dali::Quaternion quaternion( v[0], v[1], v[2] );
+ object = WrapDaliProperty( isolate , Dali::Property::Value( quaternion ) );
+ }
+ else
+ {
+ Dali::Quaternion quaternion( Dali::Quaternion(0.f, Dali::Vector4::YAXIS));
+ object = WrapDaliProperty( isolate , Dali::Property::Value( quaternion ) );
+ }
+
+ args.GetReturnValue().Set( object );
+}
+
+//
+void PropertyValueWrapper::NewMatrix( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate);
+
+ if(!args.IsConstructCall())
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Rotation constructor called without 'new'");
+ return;
+ }
+ v8::Local<v8::Object > object;
+
+ // we're constructing either a 4x4 Dali::Matrix or a 3x3 Dali::Matrix
+ // we're expecting an array of floats
+ // 4x4 = m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33
+ // 3x3 or m00, m01, m02, m10, m11, m12,m20, m21, m22, m30, m31, m32,
+ bool foundAllArguments( false );
+
+ if( args.Length() == 16 )
+ {
+ float v[16];
+ V8Utils::ReadFloatArguments( foundAllArguments, v, 16, args, 0.f );
+ if(! foundAllArguments )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "invalid Matrix parameters");
+ return;
+ }
+ Dali::Matrix matrix( v[0] );
+ object = WrapDaliProperty( isolate , Dali::Property::Value( matrix ) );
+ }
+ else if ( args.Length() == 9 )
+ {
+ float v[9];
+ V8Utils::ReadFloatArguments( foundAllArguments, v, 9, args, 0.f );
+ if(! foundAllArguments )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "invalid Matrix parameters");
+ return;
+ }
+ Dali::Matrix3 matrix( v[0], v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8] );
+ object = WrapDaliProperty( isolate , Dali::Property::Value( matrix ) );
+ }
+ args.GetReturnValue().Set( object );
+
+
+}
+
+v8::Handle<v8::ObjectTemplate> PropertyValueWrapper::MakeDaliPropertyTemplate( v8::Isolate* isolate )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+
+ v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
+
+ objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT );
+
+ // property handle intercepts property getters and setters
+ objTemplate->SetNamedPropertyHandler( PropertyGet, PropertySet);
+
+ return handleScope.Escape( objTemplate );
+
+}
+
+v8::Handle<v8::Object> PropertyValueWrapper::WrapDaliProperty(v8::Isolate* isolate, const Dali::Property::Value &value)
+{
+ v8::EscapableHandleScope handleScope( isolate );
+
+ // Simple Dali properties (ints, strings, bools etc) are stored as JavaScript primitives (v8::Boolean ...)
+ // more complex properties (Vectors, Rectangles...) are wrapped by a JavaScript object
+ if( IsPrimitive( value ))
+ {
+ return handleScope.Escape( CreateJavaScriptPrimitive( isolate, value) );
+ }
+
+ // This will wrap a Dali structure (Vector, Rect, Matrix etc) inside a JavaScript object.
+
+ v8::Local<v8::ObjectTemplate> objectTemplate;
+
+ if(PropertyValueWrapper::mTemplatePrimitive.IsEmpty() )
+ {
+ objectTemplate = MakeDaliPropertyTemplate( isolate );
+ PropertyValueWrapper::mTemplatePrimitive.Reset( isolate, objectTemplate);
+ }
+ else
+ {
+ // get the object template
+ objectTemplate = v8::Local<v8::ObjectTemplate>::New( isolate, PropertyValueWrapper::mTemplatePrimitive );
+ }
+
+ v8::Local<v8::Object> localObject = objectTemplate->NewInstance();
+
+ PropertyValueWrapper* pointer = new PropertyValueWrapper( value, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() );
+
+ // assign the JavaScript object to the wrapper.
+ // This also stores Dali object, in an internal field inside the JavaScript object.
+ pointer->SetJavascriptObject( isolate, localObject );
+
+ return handleScope.Escape( localObject );
+
+}
+
+// Utility function that extracts the C++ map pointer from a wrapper
+// object.
+
+PropertyValueWrapper* PropertyValueWrapper::Unwrap( v8::Isolate* isolate, v8::Handle< v8::Object> obj)
+{
+ v8::HandleScope handleScope( isolate );
+
+ v8::Local<v8::External> field = v8::Local<v8::External>::Cast( obj->GetInternalField(0) );
+ void* ptr = field->Value();
+ return static_cast< PropertyValueWrapper *>(ptr);
+}
+
+void PropertyValueWrapper::PropertyGet( v8::Local<v8::String> propertyName,
+ const v8::PropertyCallbackInfo<v8::Value>& info)
+{
+ v8::Isolate* isolate = info.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ std::string name = V8Utils::v8StringToStdString( propertyName );
+
+ // unwrap the object
+ PropertyValueWrapper* propWrapper = Unwrap( isolate, info.This() );
+
+ v8::Local<v8::Value> value = GetV8ValueFrom( isolate, propWrapper->mValue, name );
+
+ info.GetReturnValue().Set( value );
+}
+
+void PropertyValueWrapper::PropertySet( v8::Local<v8::String> propertyName,
+ v8::Local<v8::Value> javaScriptValue,
+ const v8::PropertyCallbackInfo<v8::Value>& info)
+{
+ v8::Isolate* isolate = info.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ std::string name = V8Utils::v8StringToStdString( propertyName );
+
+ PropertyValueWrapper* propWrapper = Unwrap( isolate, info.This() );
+
+ SetFromV8Value( isolate, propWrapper->mValue, name, javaScriptValue );
+
+}
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_PROPERTYVALUE_WRAPPER_H__
+#define __DALI_V8PLUGIN_PROPERTYVALUE_WRAPPER_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/public-api/object/property-value.h>
+
+// INTERNAL INCLUDES
+#include <shared/base-wrapped-object.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+
+/**
+ * An PropertyValue wrapper.
+ * Provides access to Property Value specific functionality and V8 memory handling.
+ *
+ * Only wraps complex types.
+ * Native JavaScript Property Value types such as float, bool string etc are handled by the actor wrapper.
+ * This supports sub property access for maps and vector.x etc and math functionality not easily mapped
+ * to JavaScript objects.
+ *
+ */
+class PropertyValueWrapper : public BaseWrappedObject
+{
+public:
+
+ /**
+ * @brief Constructor
+ * @param[in] value property value to wrap
+ * @param[in] gc Dali garbage collector interface
+ */
+ explicit PropertyValueWrapper( const Dali::Property::Value& value, GarbageCollectorInterface& gc );
+
+ /**
+ * @brief Destructor
+ */
+ virtual ~PropertyValueWrapper();
+
+ /**
+ * @brief Creates a new Rotation wrapped inside a Javascript Object.
+ * @param[in] args v8 function call arguments interpreted as (x=0,y=0)
+ */
+ static void NewRotation( const v8::FunctionCallbackInfo< v8::Value >& args);
+
+ /**
+ * @brief Creates a new Matrix wrapped inside a Javascript Object.
+ * @param[in] args v8 function call arguments can be a 4 x 4 matrix or a 3 x 3 matrix
+ */
+ static void NewMatrix( const v8::FunctionCallbackInfo< v8::Value >& args);
+
+ /**
+ * @brief Wraps a dali property value inside a JavaScript object
+ * @return JavaScript object
+ */
+ static v8::Handle<v8::Object> WrapDaliProperty(v8::Isolate* isolate, const Dali::Property::Value &value);
+
+ /**
+ * @brief Extract a property value wrapper from a javascript object
+ * @return property value wrapper
+ */
+ static PropertyValueWrapper* Unwrap( v8::Isolate* isolate, v8::Handle< v8::Object> obj);
+
+ /**
+ * Extract a property value from a javascript object, of a given type
+ * @return property value
+ */
+ static Dali::Property::Value ExtractPropertyValue( v8::Isolate* isolate, v8::Local< v8::Value> v8Value, Dali::Property::Type type);
+
+ /**
+ * @brief Extract a vector or a matrix from a JavaScript array
+ * @return property value ( vector or matrix)
+ */
+ static Dali::Property::Value VectorOrMatrixFromV8Array( v8::Isolate* isolate, const v8::Local<v8::Value>& v8Value);
+
+ /**
+ * @brief Extract a Dali Property::Array from a JavaScript array
+ * @return array property value ( vector or matrix)
+ */
+ static Dali::Property::Value ArrayFromV8Array( v8::Isolate* isolate, const v8::Local<v8::Value>& v8Value);
+
+ /**
+ * @return property value
+ */
+ Dali::Property::Value GetValue()
+ {
+ return mValue;
+ }
+
+private:
+
+
+ /**
+ * @brief get the value for a property for JavaScript object than contains a Dali object.
+ * E.g. Get( "x", JavaScript object that wraps a Dali Vector2 )
+ * @param[in] propertyName property name
+ * @param[in] info reference to PropertyCallbackInfo structure (contains the Javascript
+ * object and the return value).
+ */
+ static void PropertyGet( v8::Local<v8::String> propertyName,
+ const v8::PropertyCallbackInfo<v8::Value>& info);
+
+
+ /**
+ * @brief Set the value for a property for JavaScript object than contains a Dali object.
+ * E.g. Set( "x", 103, JavaScript object that wraps a Dali Vector2 )
+ * @param[in] propertyName property name
+ * @param[in] javaScriptValue javascript value to set, this is typically a number
+ * @param[in] info reference to PropertyCallbackInfo structure (contains the Javascript
+ * object).
+ */
+ static void PropertySet( v8::Local<v8::String> propertyName,
+ v8::Local<v8::Value> javaScriptValue,
+ const v8::PropertyCallbackInfo<v8::Value>& info);
+
+
+
+
+ // The Property Value ObjectTemplates
+ static v8::Persistent<v8::ObjectTemplate> mTemplatePrimitive;
+
+ /**
+ * @brief used to make Vectors, rotation and rect template
+ * Just produces an object template with 2 internal fields
+ * A type and a pointer to the dali object
+ */
+ static v8::Handle<v8::ObjectTemplate> MakeDaliPropertyTemplate( v8::Isolate* isolate );
+
+private:
+
+ Dali::Property::Value mValue; ///< property value
+};
+
+} // V8Plugin
+
+} // Dali
+
+#endif // header
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+// CLASS HEADER
+#include "render-task-api.h"
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <render-tasks/render-task-wrapper.h>
+#include <image/image-wrapper.h>
+#include <actors/actor-wrapper.h>
+#include <dali/public-api/render-tasks/render-task.h>
+#include <dali/public-api/actors/camera-actor.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace // un named namespace
+{
+
+
+RenderTask GetRenderTask( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::HandleScope handleScope( isolate );
+
+ v8::Local<v8::Object> object = args.This();
+ v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField(0) );
+ void* ptr = field->Value();
+
+ RenderTaskWrapper* wrapper = static_cast< RenderTaskWrapper *>(ptr);
+ return wrapper->GetRenderTask();
+}
+
+}
+
+/**
+ * Set the actors to be rendered
+ * @method setSourceActor
+ * @for RenderTask
+ * @param {Object} actor This actor and its children will be rendered.
+ */
+void RenderTaskApi::SetSourceActor( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderTask renderTask = GetRenderTask( isolate, args );
+ bool found( false );
+ Actor sourceActor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
+
+ if( found )
+ {
+ renderTask.SetSourceActor( sourceActor );
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "source actor not found" );
+ }
+
+}
+/**
+ * Get the actor to be rendered
+ * @method getSourceActor
+ * @for RenderTask
+ * @param {Object} actor source actor
+ */
+void RenderTaskApi::GetSourceActor(const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderTask renderTask = GetRenderTask( isolate, args );
+
+ Actor source = renderTask.GetSourceActor();
+
+ v8::Handle < v8::Object > wrappedActor = ActorWrapper::WrapActor( isolate, source );
+ args.GetReturnValue().Set( wrappedActor );
+}
+
+/**
+ * Set whether the RenderTask has exclusive access to the source actors; the default is false.
+ * @method setExclusive
+ * @for RenderTask
+ * @param {Boolean} exclusive True if the source actors will only be rendered by this render-task.
+ */
+void RenderTaskApi::SetExclusive( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderTask renderTask = GetRenderTask( isolate, args );
+
+ bool found( false );
+ bool exclusive = V8Utils::GetBooleanParameter( PARAMETER_0, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "boolean parameter missing" );
+ return;
+ }
+ renderTask.SetExclusive( exclusive );
+
+}
+
+/**
+ * Query whether the RenderTask has exclusive access to the source actors.
+ * @method isExclusive
+ * @for RenderTask
+ * @return {Boolean} exclusive True if the source actors will only be rendered by this render-task.
+ */
+void RenderTaskApi::IsExclusive( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderTask renderTask = GetRenderTask( isolate, args );
+
+ args.GetReturnValue().Set( v8::Boolean::New( isolate, renderTask.IsExclusive() ) );
+
+}
+
+/**
+ * Set whether the render-task should be considered for input handling; the default is true.
+ *
+ * The task used for input handling will be last task in the RenderTaskList which has input enabled,
+ * and has a valid source & camera actor.
+ * A RenderTask targetting a frame-buffer can still be hit-tested, provided that the screen->frame-buffer
+ * coordinate conversion is successful; see also SetScreenToFrameBufferFunction().
+ * @method setInputEnabled
+ * @for RenderTask
+ * @param {Boolean} enabled True if the render-task should be considered for input handling.
+ */
+void RenderTaskApi::SetInputEnabled( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderTask renderTask = GetRenderTask( isolate, args );
+
+ bool found( false );
+ bool inputEnabled = V8Utils::GetBooleanParameter( PARAMETER_0, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "boolean parameter missing" );
+ return;
+ }
+ renderTask.SetInputEnabled( inputEnabled );
+
+}
+
+/**
+ * Query whether the render-task should be considered for input handling.
+ * @method getInputEnabled
+ * @for RenderTask
+ * @return {Boolean} enabled True if the render-task should be considered for input handling.
+ */
+void RenderTaskApi::GetInputEnabled( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderTask renderTask = GetRenderTask( isolate, args );
+
+ args.GetReturnValue().Set( v8::Boolean::New( isolate, renderTask.GetInputEnabled() ) );
+
+
+}
+
+/**
+ * Set the actor from which the scene is viewed.
+ * @method setCameraActor
+ * @for RenderTask
+ * @param {Object} cameraActor The scene is viewed from the perspective of this actor.
+ */
+void RenderTaskApi::SetCameraActor( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderTask renderTask = GetRenderTask( isolate, args );
+ bool found (false );
+ CameraActor cameraActor;
+ Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
+ if( found )
+ {
+ cameraActor = CameraActor::DownCast( actor );
+ }
+
+ if( cameraActor )
+ {
+ renderTask.SetCameraActor( cameraActor );
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "source actor not found" );
+ }
+
+}
+
+/**
+ * Retrieve the actor from which the scene is viewed..
+ * @method getCameraActor
+ * @for RenderTask
+ * @return {Object} cameraActor The scene is viewed from the perspective of this actor.
+ */
+void RenderTaskApi::GetCameraActor( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderTask renderTask = GetRenderTask( isolate, args );
+
+ Actor cameraActor = renderTask.GetSourceActor();
+
+ v8::Handle < v8::Object > wrappedActor = ActorWrapper::WrapActor( isolate, cameraActor );
+ args.GetReturnValue().Set( wrappedActor );
+
+}
+
+/**
+ * Set the frame-buffer used as a render target.
+ * @method setTargetFrameBuffer
+ * @for RenderTask
+ * @param {Object} frameBuffer A valid frame-buffer handle to enable off-screen rendering, or an uninitialized handle to disable.
+ */
+void RenderTaskApi::SetTargetFrameBuffer(const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderTask renderTask = GetRenderTask( isolate, args );
+
+ bool found( false );
+ // @TODO Test this, may need to implement a Framebuffer image.?
+ Image image = V8Utils::GetImageParameter( PARAMETER_0, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "bad parameters" );
+ return;
+ }
+
+ FrameBufferImage frameBufferImage = FrameBufferImage::DownCast(image);
+
+ renderTask.SetTargetFrameBuffer( frameBufferImage );
+
+}
+
+
+/**
+ * Get the frame-buffer used as a render target.
+ * @method getTargetFrameBuffer
+ * @for RenderTask
+ * @return {Object} frameBuffer A valid frame-buffer handle to enable off-screen rendering, or an uninitialized handle to disable.
+ */
+void RenderTaskApi::GetTargetFrameBuffer( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderTask renderTask = GetRenderTask( isolate, args );
+
+ // wrap the image
+ // @TODO Test this, may need to implement a Framebuffer image wrapper.?
+ v8::Local<v8::Object> localObject = ImageWrapper::WrapImage( isolate, renderTask.GetTargetFrameBuffer(),ImageWrapper::FRAME_BUFFER_IMAGE );
+ args.GetReturnValue().Set( localObject );
+}
+
+
+/**
+ * Set the actor used to convert screen coordinates to frame-buffer coordinates.
+ *
+ * The local coordinates of the actor are mapped as frame-buffer coordinates.
+ * This is useful for hit-testing actors which are rendered off-screen.
+ * Note: The mapping actor needs to be rendered by the default render task to make the mapping work properly.
+ * @method setScreenToFrameBufferMappingActor
+ * @for RenderTask
+ * @param {Object} mappingActor The actor used for conversion.
+ */
+void RenderTaskApi::SetScreenToFrameBufferMappingActor( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderTask renderTask = GetRenderTask( isolate, args );
+ bool found( false );
+ Actor sourceActor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
+
+ if( found )
+ {
+ renderTask.SetScreenToFrameBufferMappingActor( sourceActor );
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "source actor not found" );
+ }
+}
+
+/**
+ * Retrieve the actor used to convert screen coordinates to frame-buffer coordinates.
+ *
+ * @method getScreenToFrameBufferMappingActor
+ * @for RenderTask
+ * @return {Object} actor used for conversion.
+ */
+void RenderTaskApi::GetScreenToFrameBufferMappingActor( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderTask renderTask = GetRenderTask( isolate, args );
+
+ Actor source = renderTask.GetScreenToFrameBufferMappingActor();
+
+ v8::Handle < v8::Object > wrappedActor = ActorWrapper::WrapActor( isolate, source );
+ args.GetReturnValue().Set( wrappedActor );
+}
+
+/**
+ * Retrieve the GL viewport used when rendering.
+ *
+ * @method getViewport
+ * @for RenderTask
+ * @return {Object} object with the properties { x,y,width,height }
+ */
+void RenderTaskApi::GetViewport( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderTask renderTask = GetRenderTask( isolate, args );
+
+ v8::Local<v8::Object> viewportObject = v8::Object::New( isolate );
+
+ Viewport viewPort = renderTask.GetViewport();
+
+ viewportObject->Set( v8::String::NewFromUtf8( isolate, "x"), v8::Number::New( isolate,viewPort.x ));
+ viewportObject->Set( v8::String::NewFromUtf8( isolate, "y"), v8::Number::New( isolate,viewPort.y ));
+ viewportObject->Set( v8::String::NewFromUtf8( isolate, "width"), v8::Number::New( isolate,viewPort.width ));
+ viewportObject->Set( v8::String::NewFromUtf8( isolate, "height"), v8::Number::New( isolate,viewPort.height ));
+
+ args.GetReturnValue().Set( viewportObject );
+
+}
+
+/**
+ * Set the GL viewport used when rendering.
+ * This specifies the transformation between normalized device coordinates and target window (or frame-buffer) coordinates.
+ * By default this will match the target window or frame-buffer size.
+ * Unlike the glViewport method, the x & y coordinates refer to the top-left of the viewport rectangle.
+ * @method setViewport
+ * @for RenderTask
+ * @param {Object} object with the properties { x,y,width,height }
+ */
+void RenderTaskApi::SetViewport( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderTask renderTask = GetRenderTask( isolate, args );
+
+ if( args.Length() != 1 )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing / invalid parameters" );
+ return;
+ }
+ v8::Local<v8::Value > viewportValue = args[0];
+ if( !viewportValue->IsObject() )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "invalid parameters" );
+ return;
+ }
+ v8::Local<v8::Object> obj = viewportValue->ToObject();
+ v8::Local<v8::Value> xValue = obj->Get( v8::String::NewFromUtf8( isolate, "x" ) );
+ v8::Local<v8::Value> yValue = obj->Get( v8::String::NewFromUtf8( isolate, "y" ) );
+ v8::Local<v8::Value> widthValue = obj->Get( v8::String::NewFromUtf8( isolate, "width" ) );
+ v8::Local<v8::Value> heightValue = obj->Get( v8::String::NewFromUtf8( isolate, "height" ) );
+
+ if( xValue->IsNumber() && yValue->IsNumber() && widthValue->IsNumber() && heightValue->IsNumber())
+ {
+ Viewport viewPort;
+ viewPort.x= xValue->ToNumber()->Value();
+ viewPort.y = yValue->ToNumber()->Value();
+ viewPort.width = widthValue->ToNumber()->Value();
+ viewPort.height = heightValue->ToNumber()->Value();
+ renderTask.SetViewport( viewPort );
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing x,y,width,height property" );
+ return;
+ }
+}
+
+/**
+ * Set whether the render-task will clear the results of previous render-tasks.
+ *
+ * The default is false.
+ *
+ * The default GL surface is cleared automatically at the
+ * beginning of each frame; this setting is only useful when 2+
+ * render-tasks are used, and the result of the first task needs to
+ * be (partially) cleared before rendering the second. * @method setViewport
+ * @for RenderTask
+ * @method setClearEnabled
+ * @param {Boolean} enabled True if the render-task should clear
+ */
+void RenderTaskApi::SetClearEnabled( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderTask renderTask = GetRenderTask( isolate, args );
+
+ bool found( false );
+ bool clearEnabled = V8Utils::GetBooleanParameter( PARAMETER_0, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "boolean parameter missing" );
+ return;
+ }
+ renderTask.SetClearEnabled( clearEnabled );
+
+}
+
+/**
+ * Query whether the render-task will clear the results of previous render-tasks.
+ *
+ * @for RenderTask
+ * @method getClearEnabled
+ * @return {Boolean} True if the render-task should clear.
+ */
+void RenderTaskApi::GetClearEnabled( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderTask renderTask = GetRenderTask( isolate, args );
+
+ args.GetReturnValue().Set( v8::Boolean::New( isolate, renderTask.GetClearEnabled() ) );
+}
+
+/**
+ * Set whether the render task will cull the actors to the camera's view frustum.
+ * Note that this will only affect image actors that use the default vertex shader.
+ * The default mode is to cull actors.
+ * @for RenderTask
+ * @method setCullMode
+ * @param {Boolean} cullMode True if the renderers should be culled.
+ */
+void RenderTaskApi::SetCullMode ( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderTask renderTask = GetRenderTask( isolate, args );
+
+ bool found( false );
+ bool cullMode = V8Utils::GetBooleanParameter( PARAMETER_0, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "boolean parameter missing" );
+ return;
+ }
+ renderTask.SetCullMode( cullMode );
+}
+
+/**
+ * Get the cull mode
+ * @for RenderTask
+ * @method getCullMode
+ * @return {Boolean} cullMode True if the renderers should be culled.
+ */
+void RenderTaskApi::GetCullMode( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderTask renderTask = GetRenderTask( isolate, args );
+
+ args.GetReturnValue().Set( v8::Boolean::New( isolate, renderTask.GetCullMode() ) );
+}
+
+/**
+ * Set the refresh-rate of the RenderTask.
+ *
+ * The default is dali.REFRESH_ALWAYS (1), meaning that the RenderTask will be processed every frame.
+ * It may be desirable to process less frequently e.g. SetRefreshRate(3) will process once every 3 frames.
+ * The dali.REFRESH_ONCE value means that the RenderTask will be processed once only, to take a snap-shot of the scene.
+ * Repeatedly calling setRefreshRate(dali.REFRESH_ONCE) will cause more snap-shots to be taken.
+ * @method setRefreshRate
+ * @param {Integer} refresh rate (0 = dali.REFRESH_ONCE, 1= dali.REFRESH_ALWAYS)
+ */
+void RenderTaskApi::SetRefreshRate( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderTask renderTask = GetRenderTask( isolate, args );
+
+ bool found( false );
+ int rate = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Integer parameter missing" );
+ return;
+ }
+ renderTask.SetRefreshRate( rate );
+}
+
+/**
+ * Query the refresh-rate of the RenderTask.
+ * @method getRefreshRate
+ * @return {Integer} refresh rate (0 = dali.REFRESH_ONCE, 1= dali.REFRESH_ALWAYS)
+ */
+void RenderTaskApi::GetRefreshRate( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderTask renderTask = GetRenderTask( isolate, args );
+
+ args.GetReturnValue().Set( v8::Integer::New( isolate, renderTask.GetRefreshRate() ) );
+}
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_RENDER_TASK_API_H__
+#define __DALI_V8PLUGIN_RENDER_TASK_API_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace RenderTaskApi
+{
+
+
+ /**
+ * RenderTask API see render-task.h for a description
+ */
+ void SetSourceActor( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetSourceActor(const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetExclusive( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void IsExclusive( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetInputEnabled( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetInputEnabled( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetCameraActor( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetCameraActor( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetTargetFrameBuffer(const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetTargetFrameBuffer( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetScreenToFrameBufferMappingActor( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetScreenToFrameBufferMappingActor( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetViewport( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetViewport( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetClearEnabled( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetClearEnabled( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetCullMode ( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetCullMode( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetRefreshRate( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetRefreshRate( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+}; // namespace RenderTaskApi
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header __DALI_V8PLUGIN_RENDER_TASK_API_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "render-task-list-api.h"
+
+// EXTERNAL INCLUDES
+#include <dali/integration-api/debug.h>
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <render-tasks/render-task-list-wrapper.h>
+#include <render-tasks/render-task-wrapper.h>
+#include <render-tasks/render-task-api.h>
+#include <object/property-value-wrapper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace // un named namespace
+{
+
+/**
+ *
+## RenderTaskList API
+
+
+An ordered list of Dali::RenderTasks
+
+These tasks describe how the Dali scene should be rendered;
+See {{#crossLink "RenderTask"}}{{/crossLink}}
+
+ @class RenderTaskList
+*/
+
+
+RenderTaskList GetRenderTaskList( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::HandleScope handleScope( isolate );
+
+ v8::Local<v8::Object> object = args.This();
+ v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField( 0 ) );
+ void* ptr = field->Value();
+
+ RenderTaskListWrapper* wrapper = static_cast<RenderTaskListWrapper *>( ptr );
+ return wrapper->GetRenderTaskList();
+}
+
+
+} // un-named namespace
+
+/**
+ * Create a new RenderTask.
+ * This will be appended to the list of render-tasks.
+ * @method createTask
+ * @for RenderTaskList
+ * @return {Object} RenderTask
+ */
+void RenderTaskListApi::CreateTask( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderTaskList taskList = GetRenderTaskList( isolate, args);
+
+ RenderTask renderTask = taskList.CreateTask();
+
+ v8::Handle<v8::Object> wrappedTask = RenderTaskWrapper::WrapRenderTask(isolate, renderTask);
+ args.GetReturnValue().Set( wrappedTask );
+
+}
+
+/**
+ * Remove a RenderTask from the list of render-tasks.
+ * @method removeTask
+ * @for RenderTaskList
+ * @param{Object} RenderTask to remove
+ */
+void RenderTaskListApi::RemoveTask( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderTaskList taskList = GetRenderTaskList( isolate, args );
+
+ bool found( false );
+ RenderTask renderTask = V8Utils::GetRenderTaskParameter( PARAMETER_0, found, isolate, args );
+ if(! found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "render-task parameter missing" );
+ return;
+ }
+ taskList.RemoveTask( renderTask );
+}
+/**
+ * Query the number of render-tasks in the list.
+ * This is ordered i.e. the task with index 0 is the first to be processed each frame.
+ * @method getTaskCount
+ * @for RenderTaskList
+ * @return {Number} The number of render-tasks.
+ */
+void RenderTaskListApi::GetTaskCount( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderTaskList taskList = GetRenderTaskList( isolate, args );
+
+ args.GetReturnValue().Set( v8::Integer::New( isolate, taskList.GetTaskCount() ) );
+
+}
+/**
+ * Retrieve a render-task.
+ * index should be in range i.e. less than GetTaskCount().
+ * @method getTask
+ * @for RenderTaskList
+ * @param {Number} index The index of the render task to retrieve
+ * @return {Object} The render-task
+ */
+void RenderTaskListApi::GetTask( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ RenderTaskList taskList = GetRenderTaskList( isolate, args );
+
+ bool found( false );
+ int index = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Integer parameter missing" );
+ return;
+ }
+ RenderTask renderTask = taskList.GetTask( index );
+
+ v8::Handle<v8::Object> wrappedTask = RenderTaskWrapper::WrapRenderTask(isolate, renderTask);
+ args.GetReturnValue().Set( wrappedTask );
+}
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_RENDER_TASK_LIST_API_H__
+#define __DALI_V8PLUGIN_RENDER_TASK_LIST_API_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/public-api/render-tasks/render-task-list.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace RenderTaskListApi
+{
+ /**
+ * Constructor
+ */
+ RenderTaskList New( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+
+ /**
+ * RenderTaskList API see render-task-list.h for a description
+ */
+ void CreateTask( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void RemoveTask( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetTaskCount( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetTask( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+}; // namespace RenderTaskListApi
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header __DALI_V8PLUGIN_RENDER_TASK_LIST_API_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "render-task-list-wrapper.h"
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <dali-wrapper.h>
+#include <render-tasks/render-task-list-api.h>
+#include <shared/api-function.h>
+#include <shared/object-template-helper.h>
+
+namespace Dali
+{
+namespace V8Plugin
+{
+
+v8::Persistent<v8::ObjectTemplate> RenderTaskListWrapper::mRenderTaskListTemplate;
+
+namespace
+{
+
+/**
+ * Contains a list of all functions that can be called
+ */
+const ApiFunction RenderTaskListFunctionTable[]=
+{
+ /**************************************
+ * RenderTaskList API (in order of renderTaskList.h)
+ **************************************/
+
+ { "CreateTask" , RenderTaskListApi::CreateTask },
+ { "RemoveTask" , RenderTaskListApi::RemoveTask },
+ { "GetTaskCount" , RenderTaskListApi::GetTaskCount },
+ { "GetTask" , RenderTaskListApi::GetTask },
+
+
+};
+
+const unsigned int RenderTaskListFunctionTableCount = sizeof(RenderTaskListFunctionTable)/sizeof(RenderTaskListFunctionTable[0]);
+} //un-named space
+
+
+RenderTaskListWrapper::RenderTaskListWrapper( const Dali::RenderTaskList& renderTaskList, GarbageCollectorInterface& gc )
+: BaseWrappedObject( BaseWrappedObject::RENDER_TASK_LIST , gc )
+{
+ mRenderTaskList = renderTaskList;
+}
+
+RenderTaskListWrapper::~RenderTaskListWrapper()
+{
+
+}
+
+v8::Handle<v8::Object> RenderTaskListWrapper::WrapRenderTaskList(v8::Isolate* isolate, const Dali::RenderTaskList& renderTaskList )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::ObjectTemplate> objectTemplate;
+
+ objectTemplate = GetRenderTaskListTemplate( isolate);
+
+ // create an instance of the template
+ v8::Local<v8::Object> localObject = objectTemplate->NewInstance();
+
+ // create the RenderTaskList wrapper
+ RenderTaskListWrapper* pointer = new RenderTaskListWrapper( renderTaskList, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() );
+
+ // assign the JavaScript object to the wrapper.
+ pointer->SetJavascriptObject( isolate, localObject );
+
+ return handleScope.Escape( localObject );
+}
+
+v8::Local<v8::ObjectTemplate> RenderTaskListWrapper::GetRenderTaskListTemplate( v8::Isolate* isolate)
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::ObjectTemplate> objectTemplate;
+
+ if( mRenderTaskListTemplate.IsEmpty() )
+ {
+ objectTemplate = MakeRenderTaskListTemplate( isolate );
+ mRenderTaskListTemplate.Reset( isolate, objectTemplate );
+ }
+ else
+ {
+ // get the object template
+ objectTemplate = v8::Local<v8::ObjectTemplate>::New( isolate, mRenderTaskListTemplate );
+ }
+ return handleScope.Escape( objectTemplate );
+}
+
+v8::Handle<v8::ObjectTemplate> RenderTaskListWrapper::MakeRenderTaskListTemplate( v8::Isolate* isolate )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+
+ v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
+
+ // add intercepts for Signals, we can't use HandleWrapper::AddIntercepts because RenderTaskList doesn't inherit
+ // from Handle ( just baseHandle)
+ ObjectTemplateHelper::AddSignalConnectAndDisconnect( isolate, objTemplate );
+
+ objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT );
+
+ // add our function properties
+ ObjectTemplateHelper::InstallFunctions( isolate, objTemplate, RenderTaskListFunctionTable, RenderTaskListFunctionTableCount );
+
+ return handleScope.Escape( objTemplate );
+}
+
+// v8::Local<v8::Object> localObject = WrapRenderTaskList( isolate, renderTaskList );
+ // args.GetReturnValue().Set( localObject );
+
+
+
+RenderTaskList RenderTaskListWrapper::GetRenderTaskList()
+{
+ return mRenderTaskList;
+}
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_RENDER_TASK_LIST_WRAPPER_H__
+#define __DALI_V8PLUGIN_RENDER_TASK_LIST_WRAPPER_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/public-api/render-tasks/render-task-list.h>
+
+// INTERNAL INCLUDES
+#include <shared/base-wrapped-object.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+/**
+ * RenderTaskList wrapper.
+ * Provides access to RenderTaskList specific functionality
+ */
+class RenderTaskListWrapper : public BaseWrappedObject
+{
+
+public:
+
+ RenderTaskListWrapper( const RenderTaskList& renderTaskList,
+ GarbageCollectorInterface& gc );
+
+ virtual ~RenderTaskListWrapper();
+
+ /**
+ * Wraps an renderTaskList
+ */
+ static v8::Handle<v8::Object> WrapRenderTaskList(v8::Isolate* isolate, const Dali::RenderTaskList& );
+
+
+ // The RenderTaskListAttribute ObjectTemplate, we cache templates so we don't have
+ // keep generating them everytime we want to create an RenderTaskList
+ static v8::Persistent<v8::ObjectTemplate> mRenderTaskListTemplate;
+
+ RenderTaskList GetRenderTaskList();
+
+
+private:
+
+ RenderTaskList mRenderTaskList; ///< renderTaskList object
+
+ static v8::Handle<v8::ObjectTemplate> MakeRenderTaskListTemplate( v8::Isolate* isolate );
+ static v8::Local<v8::ObjectTemplate> GetRenderTaskListTemplate( v8::Isolate* isolate );
+
+};
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // __DALI_V8PLUGIN_RENDER_TASK_LIST_WRAPPER_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "render-task-wrapper.h"
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <render-tasks/render-task-api.h>
+#include <shared/api-function.h>
+#include <shared/object-template-helper.h>
+#include <signals/signal-manager.h>
+#include <dali-wrapper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+v8::Persistent<v8::ObjectTemplate> RenderTaskWrapper::mRenderTaskTemplate;
+
+namespace // un-named name space
+{
+
+/**
+ * Contains a list of all functions that can be called
+ */
+const ApiFunction RenderTaskFunctionTable[]=
+{
+ /**************************************
+ * RenderTask API (in order of renderTask.h)
+ **************************************/
+
+ { "SetSourceActor" , RenderTaskApi::SetSourceActor },
+ { "GetSourceActor" , RenderTaskApi::GetSourceActor },
+ { "SetExclusive" , RenderTaskApi::SetExclusive },
+ { "IsExclusive" , RenderTaskApi::IsExclusive },
+ { "SetInputEnabled" , RenderTaskApi::SetInputEnabled },
+ { "GetInputEnabled" , RenderTaskApi::GetInputEnabled },
+ { "SetCameraActor" , RenderTaskApi::SetCameraActor },
+ { "GetCameraActor" , RenderTaskApi::GetCameraActor },
+ { "SetTargetFrameBuffer" , RenderTaskApi::SetTargetFrameBuffer },
+ { "GetTargetFrameBuffer" , RenderTaskApi::GetTargetFrameBuffer },
+ { "SetScreenToFrameBufferMappingActor" , RenderTaskApi::SetScreenToFrameBufferMappingActor },
+ { "GetScreenToFrameBufferMappingActor" , RenderTaskApi::GetScreenToFrameBufferMappingActor },
+
+ // USE viewportPosition property "SetViewportPosition" , RenderTaskApi::SetViewportPosition },
+ // USE viewportPosition property{ "GetCurrentViewportPosition" , RenderTaskApi::GetCurrentViewportPosition },
+ // USE viewportSize property { "SetViewportSize" , RenderTaskApi::SetViewportSize },
+ // USE viewportSize property { "SetViewportSize" , RenderTaskApi::SetViewportSize },
+
+ { "GetViewport" , RenderTaskApi::GetViewport },
+ { "SetViewport" , RenderTaskApi::SetViewport },
+
+ // USE clearColor property, { "SetClearColor" , RenderTaskApi::SetClearColor },
+ // USE clearColor property, // { "GetClearColor" , RenderTaskApi::GetClearColor },
+
+ { "SetClearEnabled" , RenderTaskApi::SetClearEnabled },
+ { "GetClearEnabled" , RenderTaskApi::GetClearEnabled },
+ { "SetCullMode" , RenderTaskApi::SetCullMode },
+ { "GetCullMode" , RenderTaskApi::GetCullMode },
+ { "SetRefreshRate" , RenderTaskApi::SetRefreshRate },
+ { "GetRefreshRate" , RenderTaskApi::GetRefreshRate },
+
+};
+
+const unsigned int RenderTaskFunctionTableCount = sizeof(RenderTaskFunctionTable)/sizeof(RenderTaskFunctionTable[0]);
+} //un-named space
+
+
+RenderTaskWrapper::RenderTaskWrapper( const Dali::RenderTask& renderTask, GarbageCollectorInterface& gc )
+: HandleWrapper( BaseWrappedObject::RENDER_TASK , renderTask, gc )
+{
+ mRenderTask = renderTask;
+}
+
+v8::Handle<v8::Object> RenderTaskWrapper::WrapRenderTask(v8::Isolate* isolate, const Dali::RenderTask& renderTask )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::ObjectTemplate> objectTemplate;
+
+ objectTemplate = GetRenderTaskTemplate( isolate);
+
+ // create an instance of the template
+ v8::Local<v8::Object> localObject = objectTemplate->NewInstance();
+
+ // create the RenderTask wrapper
+ RenderTaskWrapper* pointer = new RenderTaskWrapper( renderTask, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() );
+
+ // assign the JavaScript object to the wrapper.
+ pointer->SetJavascriptObject( isolate, localObject );
+
+ return handleScope.Escape( localObject );
+}
+
+v8::Local<v8::ObjectTemplate> RenderTaskWrapper::GetRenderTaskTemplate( v8::Isolate* isolate)
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::ObjectTemplate> objectTemplate;
+
+ if( mRenderTaskTemplate.IsEmpty() )
+ {
+ objectTemplate = MakeRenderTaskTemplate( isolate );
+ mRenderTaskTemplate.Reset( isolate, objectTemplate );
+ }
+ else
+ {
+ // get the object template
+ objectTemplate = v8::Local<v8::ObjectTemplate>::New( isolate, mRenderTaskTemplate );
+ }
+ return handleScope.Escape( objectTemplate );
+}
+
+v8::Handle<v8::ObjectTemplate> RenderTaskWrapper::MakeRenderTaskTemplate( v8::Isolate* isolate )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+
+ v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
+
+ // property handle intercepts property getters and setters and signals
+ HandleWrapper::AddInterceptsToTemplate( isolate, objTemplate );
+
+ objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT );
+
+ // add our function properties
+ ObjectTemplateHelper::InstallFunctions( isolate, objTemplate, RenderTaskFunctionTable, RenderTaskFunctionTableCount );
+
+ return handleScope.Escape( objTemplate );
+}
+
+
+RenderTask RenderTaskWrapper::GetRenderTask()
+{
+ return mRenderTask;
+}
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_SHADER_EFFECT_WRAPPER_H__
+#define __DALI_V8PLUGIN_SHADER_EFFECT_WRAPPER_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/public-api/render-tasks/render-task.h>
+
+// INTERNAL INCLUDES
+#include <object/handle-wrapper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+
+/**
+ * An RenderTask wrapper.
+ * Provides access to RenderTask specific functionality and V8 memory handling.
+ */
+class RenderTaskWrapper : public HandleWrapper
+{
+
+public:
+
+ RenderTaskWrapper( const RenderTask& shaderEffect,
+ GarbageCollectorInterface& gc );
+
+ virtual ~RenderTaskWrapper() {}
+
+
+ /**
+ * Wraps a render task
+ */
+ static v8::Handle<v8::Object> WrapRenderTask(v8::Isolate* isolate, const Dali::RenderTask& );
+
+
+ // The RenderTaskAttribute ObjectTemplate, we cache templates so we don't have
+ // keep generating them everytime we want to create an RenderTask
+ static v8::Persistent<v8::ObjectTemplate> mRenderTaskTemplate;
+
+ RenderTask GetRenderTask();
+
+
+private:
+
+ // RenderTask
+ RenderTask mRenderTask;
+
+ static v8::Handle<v8::ObjectTemplate> MakeRenderTaskTemplate( v8::Isolate* isolate );
+ static v8::Local<v8::ObjectTemplate> GetRenderTaskTemplate( v8::Isolate* isolate );
+
+};
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // __DALI_V8PLUGIN_SHADER_EFFECT_WRAPPER_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+// CLASS HEADER
+#include "shader-effect-api.h"
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <shader-effects/shader-effect-wrapper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace // un named namespace
+{
+
+typedef std::vector< std::string > HintsArray;
+
+
+struct GeometryTypePair
+{
+ const char* name;
+ GeometryType type;
+};
+
+const GeometryTypePair GeometryTypeTable[]=
+{
+ {"image", GEOMETRY_TYPE_IMAGE },
+ {"text", GEOMETRY_TYPE_TEXT },
+ {"mesh", GEOMETRY_TYPE_UNTEXTURED_MESH },
+ {"textured-mesh", GEOMETRY_TYPE_TEXTURED_MESH },
+};
+
+const unsigned int GeometryTypeTableCount = sizeof(GeometryTypeTable)/sizeof(GeometryTypeTable[0]);
+
+struct GeometryHintPair
+{
+ const char* name;
+ ShaderEffect::GeometryHints hint;
+};
+
+const GeometryHintPair GeometryHintTable[]=
+{
+ {"gridX", ShaderEffect::HINT_GRID_X },
+ {"gridY", ShaderEffect::HINT_GRID_Y },
+ {"grid", ShaderEffect::HINT_GRID },
+ {"depthBuffer", ShaderEffect::HINT_DEPTH_BUFFER },
+ {"blending", ShaderEffect::HINT_BLENDING },
+ {"doesntModifyGeometry", ShaderEffect::HINT_DOESNT_MODIFY_GEOMETRY }
+};
+
+const unsigned int GeometryHintTableCount = sizeof(GeometryHintTable)/sizeof(GeometryHintTable[0]);
+
+
+
+
+struct ShaderParameters
+{
+ ShaderParameters()
+ : mType( GEOMETRY_TYPE_IMAGE),
+ mHints( ShaderEffect::HINT_NONE )
+ {
+ }
+
+ void SetGeometryType( v8::Isolate* isolate, const std::string& typeName )
+ {
+ for( unsigned int i = 0; i < GeometryTypeTableCount; ++i )
+ {
+ if( typeName == GeometryTypeTable[i].name )
+ {
+ mType = GeometryTypeTable[i].type;
+ return;
+ }
+ }
+ DALI_SCRIPT_EXCEPTION( isolate, "Geometry type not found\n");
+ }
+
+ ShaderEffect::GeometryHints GetGeometryHint( const std::string& hint )
+ {
+ for( unsigned int i = 0 ; i < GeometryHintTableCount; ++i )
+ {
+ if( hint == GeometryHintTable[i].name )
+ {
+ return GeometryHintTable[i].hint;
+ }
+ }
+ return ShaderEffect::HINT_NONE;
+ }
+
+ void ProcessHintsArray( const HintsArray& hintsArray )
+ {
+ for( HintsArray::const_iterator iter = hintsArray.begin(); iter != hintsArray.end() ; ++iter )
+ {
+ mHints= static_cast<ShaderEffect::GeometryHints>( mHints | GetGeometryHint( *iter ) );
+ }
+ }
+
+
+
+ ShaderEffect NewShader()
+ {
+ return ShaderEffect::NewWithPrefix( mVertexPrefix ,
+ mVertex,
+ mFragmentPrefix,
+ mFragment,
+ mType,
+ mHints);
+ }
+ std::string mVertexPrefix;
+ std::string mVertex;
+ std::string mFragmentPrefix;
+ std::string mFragment;
+ GeometryType mType;
+ ShaderEffect::GeometryHints mHints;
+};
+
+ShaderEffect GetShaderEffect( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::HandleScope handleScope( isolate );
+
+ v8::Local<v8::Object> object = args.This();
+ v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField(0) );
+ void* ptr = field->Value();
+
+ ShaderEffectWrapper* wrapper = static_cast< ShaderEffectWrapper *>(ptr);
+ return wrapper->GetShaderEffect();
+}
+
+} // unnamed space
+
+/**
+ * Create a new ShaderEffect
+ * @constructor
+ * @for ShaderEffect
+ * @method ShaderEffect
+ * @param {Object} shaderOptions
+ * @param {String} [shaderOptions.geometryType] Type of geometry to be rendered with the effect. "image", "text", "mesh", "textured-mesh", default is image.
+ * @param {String} [shaderOptions.vertexShaderPrefix] This string will be inserted before the default uniforms for the vertex shader(ideal for #defines)
+ * @param {String} [shaderOptions.vertexShader] VertexShader code for the effect. If not defined, the default version will be used
+ * @param {String} [shaderOptions.fragmentShaderPrefix] This string will be inserted before the default uniforms for the fragment shader(ideal for #defines)
+ * @param {String} [shaderOptions.fragmentShader] FragmentShader code for the effect. If not defined, the default version will be used
+ * @param {Array} [shaderOptions.geometryHints] Hints for rendering the geometry, e.g. [ "gridX", "gridY", "grid","depthBuffer","blending","doesntModifyGeometry" ]
+ * @return {Object} ShaderEffect
+ * @example
+
+ // this will match the default shaders for image
+ var vertexShader = " void main() \
+ { \
+ gl_Position = uProjection * uModelView * vec4(aPosition, 1.0); \
+ vTexCoord = aTexCoord; \
+ }; "
+ var fragShader = " void main() \
+ { \
+ gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\
+ }; "
+ var shaderOptions = {
+ geometryType: "image",
+ vertexShader: vertexShader,
+ fragmentShader: fragShader
+ };
+
+ var shader = new dali.ShaderEffect(shaderOptions);
+
+ imageActor.setShaderEffect( shader );
+
+ *
+ *
+ *
+ */
+ShaderEffect ShaderEffectApi::New( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+
+
+ v8::HandleScope handleScope( isolate );
+
+ ShaderParameters shaderParams;
+
+ if( args[0]->IsObject() )
+ {
+ v8::Local<v8::Object > obj = args[0]->ToObject();
+
+ v8::Local<v8::Value> geometryTypeValue = obj->Get(v8::String::NewFromUtf8( isolate, "geometryType"));
+ if( geometryTypeValue->IsString() )
+ {
+ std::string geometryTypeName = V8Utils::v8StringToStdString( geometryTypeValue );
+ // printf(" geometry type found %s \n", geometryTypeName.c_str() );
+ shaderParams.SetGeometryType( isolate, geometryTypeName );
+ }
+
+ v8::Local<v8::Value> vertexPrefixValue = obj->Get(v8::String::NewFromUtf8( isolate, "vertexShaderPrefix"));
+ if( vertexPrefixValue->IsString() )
+ {
+ shaderParams.mVertexPrefix = V8Utils::v8StringToStdString( vertexPrefixValue );
+ }
+
+ v8::Local<v8::Value> fragmentPrefixValue = obj->Get(v8::String::NewFromUtf8( isolate, "fragmentShaderPrefix"));
+ if( fragmentPrefixValue->IsString() )
+ {
+ shaderParams.mFragmentPrefix = V8Utils::v8StringToStdString( fragmentPrefixValue );
+ }
+
+ v8::Local<v8::Value> vertexValue = obj->Get(v8::String::NewFromUtf8( isolate, "vertexShader"));
+ if( vertexValue->IsString() )
+ {
+ shaderParams.mVertex = V8Utils::v8StringToStdString( vertexValue );
+ }
+
+ v8::Local<v8::Value> fragmentValue = obj->Get(v8::String::NewFromUtf8( isolate, "fragmentShader"));
+ if( fragmentValue->IsString() )
+ {
+ shaderParams.mFragment = V8Utils::v8StringToStdString( fragmentValue );
+ }
+ // Get any hints
+ v8::Local<v8::Value> hints = obj->Get(v8::String::NewFromUtf8( isolate, "geometryHints"));
+ if( hints->IsArray() )
+ {
+ HintsArray hintsArray;
+ v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast( hints );
+ for( uint32_t i=0; i < array->Length(); ++i)
+ {
+ v8::Handle<v8::Value> entry = array->Get( v8::Integer::New( isolate, i) );
+ if( entry->IsString() )
+ {
+ std::string entryString = V8Utils::v8StringToStdString( entry );
+ hintsArray.push_back( entryString );
+ }
+ }
+ shaderParams.ProcessHintsArray( hintsArray );
+ }
+ }
+ return shaderParams.NewShader();
+
+}
+
+ShaderEffect ShaderEffectApi::GetShaderEffectFromParams( int paramIndex,
+ bool& found,
+ v8::Isolate* isolate,
+ const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ found = false;
+
+ v8::HandleScope handleScope( isolate );
+ BaseWrappedObject* wrappedObject = V8Utils::GetWrappedDaliObjectParameter( paramIndex, BaseWrappedObject::SHADER_EFFECT, isolate, args );
+ if( wrappedObject )
+ {
+ found = true;
+ ShaderEffectWrapper* wrapper = static_cast< ShaderEffectWrapper *>(wrappedObject);
+ return wrapper->GetShaderEffect();
+ }
+ else
+ {
+ return ShaderEffect();
+ }
+}
+
+/**
+ * Set a shader effect image.
+ * This image texture will be bound to the "sEffect" sampler
+ * so it can be used in fragment shader for effects
+ * @method setEffectImage
+ * @for ShaderEffect
+ * @param {Object} image
+ * @example
+ *
+ * shader.setEffectImage( image );
+ *
+ * // example of a fragment shader than can use the effect image (sEffect and main texture sTexture)
+ *
+ * "void main() \
+ * { \
+ * vec4 v4Color = (texture2D(sTexture, vTexCoord) * uColor); \
+ * v4Color = v4Color* texture2D(sEffect, vTexCoord);\
+ * gl_FragColor = v4Color; \"
+ * }";
+ */
+void ShaderEffectApi::SetEffectImage( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ bool found( false );
+ Image image = V8Utils::GetImageParameter( PARAMETER_0, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, " Image::SetEffectImage invalid params");
+ return;
+ }
+ ShaderEffect effect = GetShaderEffect( isolate, args );
+ effect.SetEffectImage( image );
+}
+
+
+/**
+ * Sets and registers a uniform property.
+ * If name matches a uniform in the shader source, this value will be uploaded when rendering.
+ * This uniform can then be animated / modified and the change will be made to the shader.
+ * @method setUniform
+ * @for ShaderEffect
+ * @param {String} name
+ * @param {Object} value must be a: float, vector2 vector3, vector4, matrix
+ * @param {String} [uniformCoordinateType] The coordinate type of the uniform.
+ * either "viewPortPosition" or "viewPortDirection"
+ * @example
+
+ var fragShader =
+ " uniform lowp vec4 uColorShift; \
+ \
+ void main() \
+ { \
+
+ gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor + uColorShift; \
+ }"
+
+ var shaderOptions = {
+ geometryType: "image",
+ fragmentShader: fragShader
+ };
+
+ // create a new shader effect
+ var shader = new dali.ShaderEffect(shaderOptions);
+
+ // add the color shift uniform so we can animate it
+ // default the color shift to zero, so it has no effect
+ shader.setUniform("uColorShift", [0.0, 0.0, 0.0, 0]);
+ */
+void ShaderEffectApi::SetUniform( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ ShaderEffect effect = GetShaderEffect( isolate, args );
+
+ bool found(false);
+ std::string uniformName = V8Utils::GetStringParameter( PARAMETER_0 , found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "SetUniform: uniform name not found\n");
+ return;
+ }
+
+ Property::Value propValue = V8Utils::GetPropertyValueParameter( PARAMETER_1 , found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "SetUniform: value not found\n");
+ return;
+ }
+
+ std::string coordinateType = V8Utils::GetStringParameter( PARAMETER_2, found, isolate, args );
+ ShaderEffect::UniformCoordinateType uniformCoordinateType( ShaderEffect::COORDINATE_TYPE_DEFAULT );
+ if( found )
+ {
+ if( coordinateType == "viewPortPosition")
+ {
+ uniformCoordinateType = ShaderEffect::COORDINATE_TYPE_VIEWPORT_POSITION;
+ }
+ else if ( coordinateType == "viewPortDirection ")
+ {
+ uniformCoordinateType = ShaderEffect::COORDINATE_TYPE_VIEWPORT_DIRECTION;
+ }
+ }
+
+ switch( propValue.GetType() )
+ {
+ case Property::FLOAT:
+ {
+ effect.SetUniform( uniformName, propValue.Get<float>(), uniformCoordinateType );
+ break;
+ }
+ case Property::VECTOR2:
+ {
+ effect.SetUniform( uniformName, propValue.Get<Vector2>(), uniformCoordinateType );
+ break;
+ }
+ case Property::VECTOR3:
+ {
+ effect.SetUniform( uniformName, propValue.Get<Vector3>(), uniformCoordinateType );
+ break;
+ }
+ case Property::VECTOR4:
+ {
+ effect.SetUniform( uniformName, propValue.Get<Vector4>(), uniformCoordinateType );
+ break;
+ }
+ case Property::MATRIX:
+ {
+ effect.SetUniform( uniformName, propValue.Get<Matrix>(), uniformCoordinateType );
+ break;
+ }
+ case Property::MATRIX3:
+ {
+ effect.SetUniform( uniformName, propValue.Get<Matrix3>(), uniformCoordinateType );
+ break;
+ }
+ default:
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "value type not recognised \n");
+ break;
+ }
+ }
+}
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_SHADER_EFFECT_API_H__
+#define __DALI_V8PLUGIN_SHADER_EFFECT_API_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/public-api/shader-effects/shader-effect.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace ShaderEffectApi
+{
+
+ /**
+ * Constructor
+ */
+ ShaderEffect New( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ ShaderEffect GetShaderEffectFromParams( int paramIndex,
+ bool& found,
+ v8::Isolate* isolate,
+ const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ /**
+ * ShaderEffect API see shader-effect.h for a description
+ */
+ void SetEffectImage( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetUniform( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+}; // namespace ShaderEffectApi
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header __DALI_V8PLUGIN_SHADER_EFFECT_API_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "shader-effect-wrapper.h"
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <shader-effects/shader-effect-api.h>
+#include <shared/api-function.h>
+#include <shared/object-template-helper.h>
+#include <signals/signal-manager.h>
+#include <dali-wrapper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+v8::Persistent<v8::ObjectTemplate> ShaderEffectWrapper::mShaderEffectTemplate;
+
+namespace // un-named name space
+{
+
+/**
+ * Contains a list of all functions that can be called
+ */
+const ApiFunction ShaderEffectFunctionTable[]=
+{
+ /**************************************
+ * ShaderEffect API (in order of shaderEffect.h)
+ **************************************/
+
+ { "SetEffectImage" , ShaderEffectApi::SetEffectImage },
+ { "SetUniform" , ShaderEffectApi::SetUniform },
+};
+
+const unsigned int ShaderEffectFunctionTableCount = sizeof(ShaderEffectFunctionTable)/sizeof(ShaderEffectFunctionTable[0]);
+} //un-named space
+
+
+ShaderEffectWrapper::ShaderEffectWrapper( const Dali::ShaderEffect& shaderEffect, GarbageCollectorInterface& gc )
+: HandleWrapper( BaseWrappedObject::SHADER_EFFECT , shaderEffect, gc )
+{
+ mShaderEffect = shaderEffect;
+}
+
+v8::Handle<v8::Object> ShaderEffectWrapper::WrapShaderEffect(v8::Isolate* isolate, const Dali::ShaderEffect& shaderEffect )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::ObjectTemplate> objectTemplate;
+
+ objectTemplate = GetShaderEffectTemplate( isolate);
+
+ // create an instance of the template
+ v8::Local<v8::Object> localObject = objectTemplate->NewInstance();
+
+ // create the ShaderEffect wrapper
+ ShaderEffectWrapper* pointer = new ShaderEffectWrapper( shaderEffect, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() );
+
+ // assign the JavaScript object to the wrapper.
+ pointer->SetJavascriptObject( isolate, localObject );
+
+ return handleScope.Escape( localObject );
+}
+
+v8::Local<v8::ObjectTemplate> ShaderEffectWrapper::GetShaderEffectTemplate( v8::Isolate* isolate)
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::ObjectTemplate> objectTemplate;
+
+ if( mShaderEffectTemplate.IsEmpty() )
+ {
+ objectTemplate = MakeShaderEffectTemplate( isolate );
+ mShaderEffectTemplate.Reset( isolate, objectTemplate );
+ }
+ else
+ {
+ // get the object template
+ objectTemplate = v8::Local<v8::ObjectTemplate>::New( isolate, mShaderEffectTemplate );
+ }
+ return handleScope.Escape( objectTemplate );
+}
+
+v8::Handle<v8::ObjectTemplate> ShaderEffectWrapper::MakeShaderEffectTemplate( v8::Isolate* isolate )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+
+ v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
+
+ // property handle intercepts property getters and setters and signals
+ HandleWrapper::AddInterceptsToTemplate( isolate, objTemplate );
+
+ objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT );
+
+ // add our function properties
+ ObjectTemplateHelper::InstallFunctions( isolate, objTemplate, ShaderEffectFunctionTable, ShaderEffectFunctionTableCount );
+
+ return handleScope.Escape( objTemplate );
+}
+
+void ShaderEffectWrapper::NewShaderEffect( const v8::FunctionCallbackInfo< v8::Value >& args)
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate);
+
+ if(!args.IsConstructCall())
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "ShaderEffect constructor called without 'new'");
+ return;
+ }
+ Dali::ShaderEffect shaderEffect = ShaderEffectApi::New( isolate, args );
+
+ v8::Local<v8::Object> localObject = WrapShaderEffect( isolate, shaderEffect );
+ args.GetReturnValue().Set( localObject );
+}
+
+
+ShaderEffect ShaderEffectWrapper::GetShaderEffect()
+{
+ return mShaderEffect;
+}
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_SHADER_EFFECT_WRAPPER_H__
+#define __DALI_V8PLUGIN_SHADER_EFFECT_WRAPPER_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/public-api/shader-effects/shader-effect.h>
+
+// INTERNAL INCLUDES
+#include <object/handle-wrapper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+
+/**
+ * An ShaderEffect wrapper.
+ * Provides access to ShaderEffect specific functionality and V8 memory handling.
+ */
+class ShaderEffectWrapper : public HandleWrapper
+{
+
+public:
+
+ ShaderEffectWrapper( const ShaderEffect& shaderEffect,
+ GarbageCollectorInterface& gc );
+
+ virtual ~ShaderEffectWrapper()
+ {
+ };
+
+ /**
+ * @brief Creates a new ShaderEffect wrapped inside a Javascript Object.
+ * @param[in] args v8 function call arguments interpreted
+ */
+ static void NewShaderEffect( const v8::FunctionCallbackInfo< v8::Value >& args);
+
+ /**
+ * Wraps a shaderEffect
+ */
+ static v8::Handle<v8::Object> WrapShaderEffect(v8::Isolate* isolate, const Dali::ShaderEffect& );
+
+
+ // The ShaderEffectAttribute ObjectTemplate, we cache templates so we don't have
+ // keep generating them everytime we want to create an ShaderEffect
+ static v8::Persistent<v8::ObjectTemplate> mShaderEffectTemplate;
+
+ ShaderEffect GetShaderEffect();
+
+
+private:
+
+ // ShaderEffect
+ ShaderEffect mShaderEffect;
+
+ static v8::Handle<v8::ObjectTemplate> MakeShaderEffectTemplate( v8::Isolate* isolate );
+ static v8::Local<v8::ObjectTemplate> GetShaderEffectTemplate( v8::Isolate* isolate );
+
+};
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // __DALI_V8PLUGIN_SHADER_EFFECT_WRAPPER_H__
--- /dev/null
+#ifndef __DALI_V8PLUGIN_API_FUNCTION_H__
+#define __DALI_V8PLUGIN_API_FUNCTION_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+
+/**
+ * @brief Used for mapping a string to a static function, for defining functions that are exposed to JavaScript.
+ * E.g.
+ * @code
+ * const ApiFunction AnimationFunctionTable[]=
+ * {
+ * { "setDuration" , AnimationApi::SetDuration },
+ * { "getDuration" , AnimationApi::GetDuration },
+ * { "setLooping" , AnimationApi::SetLooping },
+ * }
+ * @endcode
+ */
+struct ApiFunction
+{
+ const char* const name; ///< function name
+ void (*function)( const v8::FunctionCallbackInfo< v8::Value >& args);
+};
+
+
+} // V8Plugin
+
+} // Dali
+
+#endif
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "base-wrapped-object.h"
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+BaseWrappedObject::BaseWrappedObject( Type type, GarbageCollectorInterface& gc )
+: mWrappedType( type ),
+ mGarbageCollector( gc )
+{
+ mGarbageCollector.Register( this );
+}
+
+BaseWrappedObject::~BaseWrappedObject()
+{
+ mGarbageCollector.UnRegister( this );
+}
+
+bool BaseWrappedObject::IsReferenced()
+{
+ if( mWeakPersistentHandle.IsEmpty() )
+ {
+ return false;
+ }
+ if( mWeakPersistentHandle.IsNearDeath() )
+ {
+ return false;
+ }
+ return true;
+}
+void BaseWrappedObject::WeakCallback( const v8::WeakCallbackData<v8::Object,BaseWrappedObject >& data)
+{
+ BaseWrappedObject* wrappedObject = data.GetParameter();
+ wrappedObject->mWeakPersistentHandle.Reset(); // moved from destructor due to crash on shutdown
+ delete wrappedObject;
+}
+
+void BaseWrappedObject::SetJavascriptObject( v8::Isolate* isolate, v8::Local<v8::Object>& object )
+{
+ v8::HandleScope handleScope( isolate );
+
+ v8::Handle<v8::External> ptr = v8::External::New( isolate, this );
+ object->SetInternalField( FIELD_POINTER, ptr );
+
+ v8::Local<v8::Value> theType = v8::Integer::New( isolate ,mWrappedType );
+ object->SetInternalField( FIELD_TYPE, theType );
+
+ // reset sets the the handle
+ mWeakPersistentHandle.Reset( isolate, object );
+
+ // set the weak call back which is triggered when nothing else is referencing the object
+ // note, this may never called.
+ mWeakPersistentHandle.SetWeak( this, &WeakCallback );
+}
+
+bool BaseWrappedObject::IsWrappedType(v8::Isolate* isolate, const v8::Local<v8::Object>& object, BaseWrappedObject::Type type)
+{
+ v8::HandleScope handleScope( isolate );
+
+ // we've been passed a javascript object, it could be anything!
+ // so we safely check the internal field count matches the number of fields
+ // in BaseWrappedObject. Then check if the second field is an integer value
+ // possibly alternative v8 functions we could use
+ // GetConstructorName
+ // GetIdentityHash
+ if( object->InternalFieldCount() == BaseWrappedObject::FIELD_COUNT )
+ {
+ v8::Handle<v8::Value> value = object->GetInternalField(BaseWrappedObject::FIELD_TYPE);
+
+ if( value->IsInt32() )
+ {
+ BaseWrappedObject::Type objectType = static_cast<BaseWrappedObject::Type>( value->ToInt32()->Value());
+ return (type == objectType);
+ }
+ }
+ return false;
+}
+
+bool BaseWrappedObject::IsWrappedTypeAPropertyValue(const v8::Local<v8::Object>& object)
+{
+
+ if( object->InternalFieldCount() == BaseWrappedObject::FIELD_COUNT )
+ {
+ v8::Handle<v8::Value> value = object->GetInternalField(BaseWrappedObject::FIELD_TYPE);
+
+ if( value->IsInt32() )
+ {
+ BaseWrappedObject::Type objectType = static_cast<BaseWrappedObject::Type>( value->ToInt32()->Value());
+ return ( (objectType > PROPERTY_VALUE_START_RANGE) && ( objectType < PROPERTY_VALUE_END_RANGE) );
+ }
+ }
+ return false;
+}
+
+BaseWrappedObject* BaseWrappedObject::UnWrap( v8::Isolate* isolate, const v8::Local<v8::Object>& object)
+{
+ v8::HandleScope handleScope( isolate );
+
+ v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField(BaseWrappedObject::FIELD_POINTER) );
+ void* ptr = field->Value();
+ return static_cast< BaseWrappedObject *>(ptr);
+}
+
+BaseWrappedObject::Type BaseWrappedObject::GetType()
+{
+ return mWrappedType;
+}
+
+SignalManager* BaseWrappedObject::GetSignalManager()
+{
+ return NULL;
+}
+} // V8Plugin
+
+} // Dali
+
--- /dev/null
+#ifndef __DALI_V8PLUGIN_BASE_WRAPPED_OBJECT_H__
+#define __DALI_V8PLUGIN_BASE_WRAPPED_OBJECT_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+
+// INTERNAL INCLUDES
+#include <interfaces/garbage-collector-interface.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+class SignalManager;
+
+/**
+ * @brief Used as a base class for all wrapped objects.
+ *
+ * Dali JavaScript objects look like this
+ *
+ * \code
+ * _______________________________________ ________________________________________
+ * | JavaScript Object | | C++ WrappedObject (e.g. ImageWrapper)|
+ * |---------------------------------------| |----------------------------------------|
+ * | Hidden internal fields | | Handle to a Dali::Image object |
+ * | *Pointer to a BaseWrappedObject | ----> |________________________________________|
+ * | Type of wrapped object (e.g. Image) |
+ * -----------------------------------------
+ *
+ * \endcode
+ *
+ * Whenever we want to access functions / properties of that wrapped object, we unwrap it
+ * to get access to the Dali object.
+ *
+ * Each wrapped object registers with Dali garbage collector so they can be deleted
+ * when Dali shuts down
+ */
+class BaseWrappedObject
+{
+
+public:
+
+ /*
+ * A type enum for the wrapped object
+ */
+ enum Type
+ {
+ UNKNOWN = -1,
+ HANDLE = 0 ,
+ HANDLE_SIGNAL,
+ CONNECTION,
+ ANIMATION,
+ PATH,
+ BUILDER,
+ STAGE,
+ FONT,
+ IMAGE,
+ IMAGE_ATTRIBUTES,
+ ACTOR,
+ ACTOR_PROPERTY,
+ RENDER_TASK,
+ RENDER_TASK_LIST,
+ TIMER,
+ TAP_GESTURE,
+ SHADER_EFFECT,
+ PAN_GESTURE,
+ LONGPRESS_GESTURE,
+ PINCH_GESTURE,
+ KEYBOARD_FOCUS_MANAGER,
+ PAN_GESTURE_DETECTOR,
+ ////////////////////////////////////////////////////////
+ PROPERTY_VALUE_START_RANGE, // start of property values
+ VECTOR2,
+ VECTOR3,
+ VECTOR4,
+ MATRIX,
+ MATRIX3,
+ RECTANGLE,
+ ROTATION,
+ PROPERTY_VALUE_END_RANGE, // end of property values
+ ///////////////////////////////////////////////////////
+ };
+
+ /*
+ * A type enum for the wrapped object internal field
+ */
+ enum Field
+ {
+ FIELD_POINTER = 0,
+ FIELD_TYPE = 1,
+ FIELD_COUNT = 2 // increase if more fields are added
+ };
+
+ /**
+ * @brief virtual destructor
+ */
+ virtual ~BaseWrappedObject();
+
+ /**
+ * @return true if nothing else is referencing this object
+ */
+ bool IsReferenced();
+
+ /**
+ * @brief Called when the v8 garbage collector decides the JavaScript object (which contains the Dali wrapped object)
+ * is no longer used / reachable.
+ */
+ static void WeakCallback( const v8::WeakCallbackData<v8::Object,BaseWrappedObject >& data);
+
+ /**
+ * @brief create and set the internal fields of a JavaScript object.
+ * Currently has 2 internal fields, 1 is a pointer to dali wrapped object, 2nd is the type.
+ */
+ void SetJavascriptObject( v8::Isolate* isolate, v8::Local<v8::Object>& object );
+
+ /**
+ * @return true if the object is of a certain wrapped type (e.g. ImageActor )
+ */
+ static bool IsWrappedType( v8::Isolate* isolate, const v8::Local<v8::Object>& object, BaseWrappedObject::Type type);
+
+ /**
+ * @return true if the object is a wrapped property value
+ */
+ static bool IsWrappedTypeAPropertyValue(const v8::Local<v8::Object>& object);
+
+ /**
+ * @brief Extracts the Dali wrapped object from the javascript object
+ */
+ static BaseWrappedObject* UnWrap( v8::Isolate* isolate, const v8::Local<v8::Object>& object);
+
+ /**
+ * @return the wrapped type
+ */
+ Type GetType();
+
+ virtual SignalManager* GetSignalManager();
+
+protected:
+
+ /**
+ * Constructor
+ * @param type wrapped type
+ * @param gc garbage collector interface
+ */
+ BaseWrappedObject( Type type, GarbageCollectorInterface& gc );
+
+private:
+
+ BaseWrappedObject();
+
+ /**
+ * We store a persistent handle to the JavaScript object and then set it to weak.
+ * This means we be notified when v8 decides it's no longer required and we can delete
+ * the associated Dali object
+ */
+ v8::Persistent<v8::Object > mWeakPersistentHandle;
+ Type mWrappedType; ///< wrapped type
+ GarbageCollectorInterface& mGarbageCollector; ///< Dali garbage collector
+};
+
+} // V8Plugin
+
+} // Dali
+
+#endif // header __DALI_V8PLUGIN_DALI_OBJECT_LIFETIME_MANAGER_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// HEADER
+#include "object-template-helper.h"
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <signals/signal-manager.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace ObjectTemplateHelper
+{
+
+void AddSignalConnectAndDisconnect( v8::Isolate* isolate, v8::Local<v8::ObjectTemplate>& objTemplate )
+{
+ objTemplate->Set( v8::String::NewFromUtf8( isolate, "connect"),
+ v8::FunctionTemplate::New( isolate, SignalManager::SignalConnect) );
+
+
+
+ objTemplate->Set( v8::String::NewFromUtf8( isolate, "disconnect"),
+ v8::FunctionTemplate::New( isolate, SignalManager::SignalDisconnect) );
+}
+
+
+
+
+void InstallFunctions( v8::Isolate* isolate,
+ v8::Local<v8::ObjectTemplate>& objTemplate,
+ const ApiFunction* functionTable,
+ unsigned int tableCount,
+ FunctionType type )
+{
+ // add our function properties
+ for( unsigned int i = 0; i < tableCount; ++i )
+ {
+ const ApiFunction property = functionTable[i];
+
+ std::string funcName;
+
+ if( type == NORMAL_FUNCTIONS )
+ {
+ funcName = V8Utils::GetJavaScriptFunctionName( property.name);
+ }
+ else
+ {
+
+ funcName = property.name;
+ }
+ // printf("Installing function %s \n", funcName.c_str() );
+ objTemplate->Set( v8::String::NewFromUtf8( isolate, funcName.c_str() ),
+ v8::FunctionTemplate::New( isolate, property.function ) );
+ }
+}
+
+} // ObjectTemplateHelper
+
+} // V8Plugin
+
+} // Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_OBJECT_TEMPLATE_HELPER_H__
+#define __DALI_V8PLUGIN_OBJECT_TEMPLATE_HELPER_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+
+// INTERNAL INCLUDES
+#include <shared/api-function.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace ObjectTemplateHelper
+{
+
+
+
+/**
+ * @brief Used for adding signal connect / disconnect functionality to an object template
+ * E.g.
+ */
+void AddSignalConnectAndDisconnect( v8::Isolate* isolate, v8::Local<v8::ObjectTemplate>& objTemplate );
+
+enum FunctionType
+{
+ NORMAL_FUNCTIONS = 0,
+ CONSTRUCTOR_FUNCTIONS = 1
+};
+
+/**
+ * Installs a list of functions on to an object template (e.g. actor.add, actor.setDrawMode() )
+ */
+void InstallFunctions( v8::Isolate* isolate,
+ v8::Local<v8::ObjectTemplate>& objTemplate,
+ const ApiFunction* functionTable,
+ unsigned int tableCount,
+ FunctionType type = NORMAL_FUNCTIONS);
+
+
+}
+} // V8Plugin
+
+} // Dali
+
+#endif // __DALI_V8PLUGIN_OBJECT_TEMPLATE_HELPER_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "dali-any-javascript-converter.h"
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <object/property-value-wrapper.h>
+#include <actors/actor-wrapper.h>
+#include <events/event-object-generator.h>
+#include <animation/animation-wrapper.h>
+#include <image/image-wrapper.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+v8::Local<v8::Value> DaliAnyConverter::ConvertToJavaScriptObject(v8::Isolate* isolate, Dali::Any& value )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::Value> returnValue;
+
+ const std::type_info& typeInfo( value.GetType());
+
+ // check the type of the Any and convert it to a JavaScript object
+ // if we wanted to speed this up, it would be possible to hash the typeInfo.name() field.
+
+ if( typeInfo == typeid( Dali::Actor ))
+ {
+ Actor actor = value.Get<Actor>();
+ if( actor )
+ {
+ returnValue = ActorWrapper::WrapActor( isolate, actor );
+ }
+ else
+ {
+ returnValue = v8::Undefined( isolate );
+ }
+ }
+ else if( typeInfo == typeid( std::string ) )
+ {
+
+ std::string string = value.Get< std::string >();
+ //printf(" converting %s to a javascript object \n", string.c_str());
+ returnValue = v8::String::NewFromUtf8( isolate, string.c_str());
+ }
+ else if( typeInfo == typeid( Dali::Vector3 ) )
+ {
+ returnValue = PropertyValueWrapper::WrapDaliProperty( isolate, value.Get<Vector3>() );
+ }
+ else if( typeInfo == typeid( Dali::TouchEvent ) )
+ {
+ returnValue = EventObjectGenerator::CreateTouchEvent( isolate, value.Get<TouchEvent>() );
+ }
+ else if( typeInfo == typeid( Dali::HoverEvent ) )
+ {
+ returnValue = EventObjectGenerator::CreateHoverEvent( isolate, value.Get<HoverEvent>() );
+ }
+ else if( typeInfo == typeid( Dali::MouseWheelEvent ) )
+ {
+ returnValue = EventObjectGenerator::CreateMouseWheelEvent( isolate, value.Get<MouseWheelEvent>() );
+ }
+ else if( typeInfo == typeid( Dali::KeyEvent ) )
+ {
+ returnValue = EventObjectGenerator::CreateKeyEvent( isolate, value.Get<KeyEvent>() );
+ }
+ else if( typeInfo == typeid( Dali::PanGesture ) )
+ {
+ returnValue = EventObjectGenerator::CreatePanGesture( isolate, value.Get<PanGesture>() );
+ }
+ else if( typeInfo == typeid( Dali::Animation ) )
+ {
+ returnValue = AnimationWrapper::WrapAnimation( isolate, value.Get<Animation>() );
+ }
+ else if( typeInfo == typeid( Dali::Image ) )
+ {
+ returnValue = ImageWrapper::WrapImage( isolate, value.Get<Image>() );
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, " Failed to find Dali::Any to JavaScript converter \n" );
+ }
+
+ return handleScope.Escape( returnValue );
+}
+
+Dali::Any DaliAnyConverter::ConvertToDaliAny( v8::Isolate* isolate, v8::Local<v8::Value> value, const Dali::Any& requestedType)
+{
+ v8::HandleScope handleScope( isolate );
+
+ if( value.IsEmpty() )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Callback missing a return value \n");
+ return Dali::Any();
+ }
+ // try to match the return value types
+ if( requestedType.GetType() == typeid( bool ))
+ {
+ if( value->IsBoolean() )
+ {
+ return value->ToBoolean()->Value();
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Invalid return type from callback, wanted a bool \n");
+ }
+ }
+ else if( requestedType.GetType() == typeid( unsigned int ) )
+ {
+ if( value->IsUint32() )
+ {
+ return value->ToUint32()->Value();
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Invalid return type from callback, wanted an unsigned int\n");
+ }
+ }
+ // allow positive and negative numbers for int,@todo test how v8 behaves with numbers returned
+ else if( requestedType.GetType() == typeid( int ))
+ {
+ if( value->IsInt32() )
+ {
+ return value->ToInt32()->Value();
+ }
+ else if( value->IsUint32() )
+ {
+ return static_cast<int>( value->ToUint32()->Value());
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION(isolate, "Invalid return type from callback, wanted an int\n");
+ }
+ }
+ else if( requestedType.GetType() == typeid( float ))
+ {
+ if( value->IsNumber() )
+ {
+ return value->ToNumber()->Value();
+ }
+ else if( value->IsInt32() )
+ {
+ return static_cast<float>(value->ToInt32()->Value());
+ }
+ else if( value->IsUint32() )
+ {
+ return static_cast<float>( value->ToUint32()->Value() );
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION(isolate, "Invalid return type from callback, wanted a float\n");
+ }
+ }
+ else if( requestedType.GetType() == typeid( Actor ))
+ {
+ if( value->IsObject() )
+ {
+ HandleWrapper* handleWrapper = HandleWrapper::Unwrap( isolate, value->ToObject() );
+ if( handleWrapper )
+ {
+ return Actor::DownCast( handleWrapper->mHandle );
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION(isolate, "Invalid return type from callback, wanted an Actor \n");
+ }
+ }
+ else
+ {
+ // undefined is used to describe an empty actor handle
+ if (value->IsUndefined())
+ {
+ return Actor();
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION(isolate, "missing return type, wanted an Actor \n");
+ }
+ }
+
+ }
+ return Dali::Any(); // empty any
+}
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_DALI_ANY_JAVASCRIPT_CONVERTER_H__
+#define __DALI_V8PLUGIN_DALI_ANY_JAVASCRIPT_CONVERTER_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/public-api/object/any.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace DaliAnyConverter
+{
+
+
+/**
+ * Converts a Dali::Any object to a JavaScript object based on it's type
+ */
+v8::Local<v8::Value> ConvertToJavaScriptObject( v8::Isolate* isolate, Dali::Any& value );
+
+
+/**
+ * Converts from a JavaScript object back into a Dali::Any object
+ * Used for return values from JavaScript callbacks
+ * E.g. to convert from a JavaScript bool object to a C++ bool
+ */
+
+Dali::Any ConvertToDaliAny( v8::Isolate* isolate, v8::Local<v8::Value>, const Dali::Any& requestedType);
+
+}
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // __DALI_V8PLUGIN_DALI_ANY_JAVASCRIPT_CONVERTER_H__
--- /dev/null
+#ifndef __DALI_V8PLUGIN_EMIT_NOTIFICATION_INTERFACE_H__
+#define __DALI_V8PLUGIN_EMIT_NOTIFICATION_INTERFACE_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+/**
+ * abstract interface to allow the signal manager know if
+ * a JavaScript disconnect/ connect has been called, while inside a callback
+ */
+class EmitNotificationInterface
+{
+
+ public:
+
+ /**
+ * Constructor
+ */
+ EmitNotificationInterface() {}
+
+ /**
+ * Virtual destructor
+ */
+ virtual ~EmitNotificationInterface() {}
+
+ /**
+ * Call back has been entered.
+ * E.g. Actor on touch has called a JavaScript function
+ */
+ virtual void CallbackEnter() =0 ;
+
+ /**
+ * Call back has been entered.
+ * E.g. Actor on touch has called a JavaScript function
+ */
+ virtual void CallbackExit() =0 ;
+
+};
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // __DALI_V8PLUGIN_EMIT_NOTIFICATION_INTERFACE_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "signal-manager.h"
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <object/handle-wrapper.h>
+#include <object/property-value-wrapper.h>
+#include <actors/actor-wrapper.h>
+#include <image/image-wrapper.h>
+#include <animation/animation-wrapper.h>
+#include <stage/stage-wrapper.h>
+#include <events/pan-gesture-detector-wrapper.h>
+#include <toolkit/focus-manager/keyboard-focus-manager-wrapper.h>
+#include <signals/dali-any-javascript-converter.h>
+#include <dali/public-api/images/resource-image.h>
+#include <dali/public-api/object/any.h>
+#include <dali/public-api/events/pan-gesture-detector.h>
+#include <dali/public-api/object/any.h>
+#include <dali/public-api/images/image.h>
+#include <dali/public-api/events/touch-event.h>
+#include <dali/public-api/events/hover-event.h>
+#include <dali/public-api/events/mouse-wheel-event.h>
+#include <dali/public-api/events/key-event.h>
+#include <dali/public-api/events/pan-gesture.h>
+
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace // un-named namespace
+{
+const char* const SIGNAL_TOUCHED = "touched";
+const char* const SIGNAL_HOVERED = "hovered";
+const char* const SIGNAL_MOUSE_WHEEL_EVENT = "mouse-wheel-event";
+const char* const SIGNAL_ON_STAGE = "on-stage";
+const char* const SIGNAL_OFF_STAGE = "off-stage";
+const char* const ANIMATION_SIGNAL_FINISHED = "finished";
+const char* const SIGNAL_PAN_DETECTED = "pan-detected";
+
+const char* const STAGE_SIGNAL_KEY_EVENT = "key-event";
+const char* const STAGE_SIGNAL_EVENT_PROCESSING_FINISHED = "event-processing-finished";
+const char* const STAGE_SIGNAL_TOUCHED = "touched";
+const char* const SIGNAL_IMAGE_LOADING_FINISHED = "image-loading-finished";
+const char* const SIGNAL_IMAGE_UPLOADED = "uploaded";
+
+const char* const KEYBOARD_FOCUS_MANAGER_SIGNAL_PRE_FOCUS_CHANGE = "keyboard-pre-focus-change";
+const char* const KEYBOARD_FOCUS_MANAGER_SIGNAL_FOCUS_CHANGED = "keyboard-focus-changed";
+const char* const KEYBOARD_FOCUS_MANAGER_SIGNAL_FOCUS_GROUP_CHANGED = "keyboard-focus-group-changed";
+const char* const KEYBOARD_FOCUS_MANAGER_SIGNAL_FOCUSED_ACTOR_ACTIVATED = "keyboard-focused-actor-activated";
+const unsigned int MAX_SIGNAL_NAME_LENGTH = 64;
+
+} // un-named name space
+
+class BaseJavaScriptCallback
+{
+public:
+
+ BaseJavaScriptCallback( v8::Isolate* isolate, const v8::Local<v8::Function>& callback )
+ :mIsolate( isolate ),mEmitInterface( NULL )
+ {
+ mCallback.Reset( isolate, callback);
+ }
+ ~BaseJavaScriptCallback()
+ {
+ mCallback.Reset();
+ };
+
+ bool IsFunction( const v8::Local<v8::Function>& function)
+ {
+ v8::HandleScope handleScope( mIsolate );
+ v8::Local<v8::Function> localCallback = v8::Local<v8::Function>::New( mIsolate, mCallback );
+ return ( localCallback == function );
+ }
+
+ void Call( Dali::Any& returnValue, std::vector< Dali::Any >& data )
+ {
+ mEmitInterface->CallbackEnter();
+
+ v8::HandleScope handleScope( mIsolate );
+ v8::TryCatch tryCatch;
+
+ // create a vector of JavaScript arguments to pass to the JavaScript function
+ std::vector< v8::Local<v8::Value> > arguments;
+
+ for( unsigned int i = 0; i < data.size(); ++i )
+ {
+ // convert each Dali::Any object into a JavaScript object based on it's type
+ arguments.push_back( DaliAnyConverter::ConvertToJavaScriptObject( mIsolate, data[i]));
+ }
+
+ // call the javascript function
+ v8::Local<v8::Function> localCallback = v8::Local<v8::Function>::New( mIsolate, mCallback );
+ v8::Local<v8::Value> javaScriptReturnVal = v8::Local<v8::Value>::Cast( localCallback->Call( localCallback, arguments.size(), &arguments[0] ));
+
+ // Print errors that happened during execution.
+ if( tryCatch.HasCaught() )
+ {
+ V8Utils::ReportException( mIsolate, &tryCatch);
+ DALI_ASSERT_ALWAYS( 0 && "Script error \n");
+ }
+
+ // convert will log an error, if the return type we want isn't found
+ returnValue = DaliAnyConverter::ConvertToDaliAny( mIsolate, javaScriptReturnVal, returnValue );
+
+ mEmitInterface->CallbackExit();
+
+ }
+
+ void SetEmitInterface( EmitNotificationInterface* interface)
+ {
+ mEmitInterface = interface;
+ }
+protected:
+ v8::Isolate* mIsolate;
+ v8::Persistent<v8::Function> mCallback;
+ EmitNotificationInterface* mEmitInterface;
+
+};
+/**
+ * base class for callback
+ */
+class BaseCallBack : public ConnectionTracker
+{
+public:
+ BaseCallBack( v8::Isolate* isolate, const v8::Local<v8::Function>& callback, const std::string& signalName )
+ :mSignalName( signalName ),
+ mJavaFunctor( isolate, callback)
+ {
+
+ }
+ void CallJavaScript( Dali::Any& returnValue, std::vector< Dali::Any >& data )
+ {
+ mJavaFunctor.Call( returnValue, data);
+ }
+
+ bool IsFunction( const v8::Local<v8::Function>& function)
+ {
+ return mJavaFunctor.IsFunction(function);
+ }
+
+ void SetEmitInterface( EmitNotificationInterface* interface)
+ {
+ mJavaFunctor.SetEmitInterface( interface );
+ }
+ virtual ~BaseCallBack() {}
+
+ std::string mSignalName;
+ BaseJavaScriptCallback mJavaFunctor;
+};
+
+namespace
+{
+
+class ActorCallback : public BaseCallBack
+{
+public:
+
+ ActorCallback(v8::Isolate* isolate, const v8::Local<v8::Function>& callback ,const std::string& signalName )
+ : BaseCallBack( isolate, callback, signalName )
+ {
+ }
+ bool OnTouch( Actor actor, const TouchEvent& event)
+ {
+ std::vector< Dali::Any > arguments; // Dali::Vector considers Dali::Any to be a non trivial type so won't compile
+ Dali::Any returnValue(false);
+ arguments.push_back( actor );
+ arguments.push_back( event );
+ CallJavaScript( returnValue, arguments );
+ bool ret;
+ returnValue.Get(ret);
+ return ret;
+ }
+ bool OnHover( Actor actor, const HoverEvent& event)
+ {
+ std::vector< Dali::Any > arguments; // Dali::Vector considers Dali::Any to be a non trivial type so won't compile
+ Dali::Any returnValue(false);
+ arguments.push_back( actor );
+ arguments.push_back( event );
+ CallJavaScript( returnValue, arguments );
+ bool ret;
+ returnValue.Get(ret);
+ return ret;
+ }
+ bool OnMouseWheel( Actor actor, const MouseWheelEvent& event)
+ {
+ std::vector< Dali::Any > arguments;
+ Dali::Any returnValue(false);
+ arguments.push_back( actor );
+ arguments.push_back( event );
+ CallJavaScript( returnValue, arguments );
+ bool ret;
+ returnValue.Get(ret);
+ return ret;
+ }
+ void OnStage( Actor actor)
+ {
+ std::vector< Dali::Any > arguments;
+ Dali::Any returnValue; //no return
+ arguments.push_back( actor );
+ CallJavaScript( returnValue, arguments );
+ }
+ void OffStage( Actor actor)
+ {
+ std::vector< Dali::Any > arguments;
+ Dali::Any returnValue; //no return
+ arguments.push_back( actor );
+ CallJavaScript( returnValue, arguments );
+ }
+
+private:
+
+};
+
+
+class AnimationCallback : public BaseCallBack
+{
+public:
+
+ AnimationCallback(v8::Isolate* isolate, const v8::Local<v8::Function>& callback ,const std::string& signalName )
+ : BaseCallBack( isolate, callback, signalName )
+ {
+ }
+ void Finished( Animation& animation)
+ {
+ std::vector< Dali::Any > arguments; // Dali::Vector considers Dali::Any to be a non trivial type so won't compile
+ Dali::Any returnValue; //no return
+ arguments.push_back( animation );
+ CallJavaScript( returnValue, arguments );
+ }
+};
+
+
+class ImageCallback : public BaseCallBack
+{
+public:
+
+ ImageCallback(v8::Isolate* isolate, const v8::Local<v8::Function>& callback ,const std::string& signalName )
+ : BaseCallBack( isolate, callback, signalName )
+ {
+ }
+ void LoadingFinished( ResourceImage image)
+ {
+ std::vector< Dali::Any > arguments; // Dali::Vector considers Dali::Any to be a non trivial type so won't compile
+ Dali::Any returnValue; //no return
+ arguments.push_back( image );
+ CallJavaScript( returnValue, arguments );
+ }
+};
+class StageCallback : public BaseCallBack
+{
+public:
+
+ StageCallback(v8::Isolate* isolate, const v8::Local<v8::Function>& callback ,const std::string& signalName )
+ : BaseCallBack( isolate, callback, signalName )
+ {
+ }
+
+ void KeyEventSignal( const KeyEvent& keyEvent )
+ {
+ std::vector< Dali::Any > arguments;
+ Dali::Any returnValue; //no return
+ arguments.push_back( keyEvent );
+ CallJavaScript( returnValue, arguments );
+ }
+ void EventProcessingFinishedSignal()
+ {
+ std::vector< Dali::Any > arguments;
+ Dali::Any returnValue; //no return
+ CallJavaScript( returnValue, arguments );
+ }
+ void TouchedSignal( const TouchEvent& touchEvent)
+ {
+ std::vector< Dali::Any > arguments;
+ Dali::Any returnValue; //no return
+ arguments.push_back( touchEvent );
+ CallJavaScript( returnValue, arguments );
+ }
+};
+
+class KeyboardFocusCallback : public BaseCallBack
+{
+public:
+
+ KeyboardFocusCallback(v8::Isolate* isolate, const v8::Local<v8::Function>& callback ,const std::string& signalName )
+ : BaseCallBack( isolate, callback, signalName )
+ {
+ }
+
+ Actor PreFocusChangeSignal(Actor currentFocusedActor,
+ Actor proposedActorToFocus,
+ Toolkit::Control::KeyboardFocusNavigationDirection direction )
+ {
+ std::vector< Dali::Any > arguments;
+ Dali::Any returnValue = Actor(); // we want an actor as a return value
+
+ arguments.push_back( currentFocusedActor );
+ arguments.push_back( proposedActorToFocus );
+
+ std::string name = KeyboardFocusManagerWrapper::GetDirectionName( direction );
+ arguments.push_back( name );
+
+ CallJavaScript( returnValue, arguments );
+
+ Actor ret;
+ returnValue.Get(ret);
+ return ret;
+ }
+ void FocusChangedSignal(Actor originalFocusedActor, Actor currentFocusedActor)
+ {
+ std::vector< Dali::Any > arguments;
+ Dali::Any returnValue; //no return
+ arguments.push_back( originalFocusedActor );
+ arguments.push_back( currentFocusedActor );
+ CallJavaScript( returnValue, arguments );
+ }
+ void FocusGroupSignal( Actor currentFocusedActor, bool forward )
+ {
+ std::vector< Dali::Any > arguments;
+ Dali::Any returnValue; //no return
+ arguments.push_back( currentFocusedActor );
+ arguments.push_back( forward );
+ CallJavaScript( returnValue, arguments );
+ }
+ void FocusedActorSignal( Actor activatedActor )
+ {
+ std::vector< Dali::Any > arguments;
+ Dali::Any returnValue; //no return
+ arguments.push_back( activatedActor );
+ CallJavaScript( returnValue, arguments );
+ }
+};
+
+class PanGestureDetectorCallback : public BaseCallBack
+{
+public:
+
+ PanGestureDetectorCallback(v8::Isolate* isolate, const v8::Local<v8::Function>& callback ,const std::string& signalName )
+ : BaseCallBack( isolate, callback, signalName )
+ {
+ }
+ void OnPan( Actor actor, const PanGesture& panGesture)
+ {
+ std::vector< Dali::Any > arguments;
+ Dali::Any returnValue; //no return
+ arguments.push_back( actor );
+ arguments.push_back( panGesture );
+ CallJavaScript( returnValue, arguments );
+ }
+};
+
+void ActorConnection( v8::Isolate* isolate,
+ v8::Local<v8::Function> javaScriptCallback,
+ ActorWrapper* actorWrapper,
+ const std::string& signalName,
+ Actor actor )
+{
+ bool connected(true);
+
+ ActorCallback* callback =new ActorCallback( isolate, javaScriptCallback, signalName );
+
+ if( strcmp( signalName.c_str(), SIGNAL_TOUCHED ) == 0 )
+ {
+ actor.TouchedSignal().Connect( callback, &ActorCallback::OnTouch );
+ }
+ else if( strcmp( signalName.c_str(), SIGNAL_HOVERED ) == 0 )
+ {
+ actor.HoveredSignal().Connect( callback, &ActorCallback::OnHover );
+ }
+ else if ( strcmp( signalName.c_str(), SIGNAL_MOUSE_WHEEL_EVENT ) == 0 )
+ {
+ actor.MouseWheelEventSignal().Connect( callback, &ActorCallback::OnMouseWheel );
+ }
+ else if ( strcmp( signalName.c_str(), SIGNAL_ON_STAGE ) == 0 )
+ {
+ actor.OnStageSignal().Connect( callback, &ActorCallback::OnStage);
+ }
+ else if ( strcmp( signalName.c_str(), SIGNAL_OFF_STAGE ) == 0 )
+ {
+ actor.OffStageSignal().Connect( callback, &ActorCallback::OffStage);
+ }
+ else
+ {
+ connected = false;
+ }
+
+ if( connected )
+ {
+ actorWrapper->GetSignalManager()->AddCallback( static_cast<BaseCallBack*>(callback) );
+ }
+ else
+ {
+ delete callback;
+ }
+}
+
+void AnimationConnection( v8::Isolate* isolate,
+ v8::Local<v8::Function> javaScriptCallback,
+ AnimationWrapper* animWrapper,
+ const std::string& signalName,
+ Animation anim )
+{
+ if( signalName == ANIMATION_SIGNAL_FINISHED)
+ {
+ AnimationCallback* callback =new AnimationCallback( isolate, javaScriptCallback, signalName );
+ anim.FinishedSignal().Connect( callback, &AnimationCallback::Finished );
+ animWrapper->GetSignalManager()->AddCallback( static_cast<BaseCallBack*>(callback) );
+ }
+}
+
+void ImageConnection( v8::Isolate* isolate,
+ v8::Local<v8::Function> javaScriptCallback,
+ ImageWrapper* imageWrapper,
+ const std::string& signalName,
+ Image image)
+{
+ // Nine patch will downcast to ResourceImage
+ ResourceImage resourceImage( ResourceImage::DownCast( image ) );
+ if( !resourceImage )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "can only connect to Resource / NinePatch Images");
+ return;
+ }
+
+ if( strcmp( signalName.c_str(), SIGNAL_IMAGE_LOADING_FINISHED ) == 0 )
+ {
+ ImageCallback* callback =new ImageCallback( isolate, javaScriptCallback, signalName );
+
+ resourceImage.LoadingFinishedSignal().Connect( callback, &ImageCallback::LoadingFinished );
+ imageWrapper->GetSignalManager()->AddCallback( static_cast<BaseCallBack*>(callback) );
+ }
+ else if ( strcmp( signalName.c_str() , SIGNAL_IMAGE_UPLOADED ) == 0 )
+ {
+ ImageCallback* callback =new ImageCallback( isolate, javaScriptCallback, signalName );
+ resourceImage.LoadingFinishedSignal().Connect( callback, &ImageCallback::LoadingFinished );
+ imageWrapper->GetSignalManager()->AddCallback( static_cast<BaseCallBack*>(callback) );
+ }
+}
+
+void StageConnection( v8::Isolate* isolate,
+ v8::Local<v8::Function> javaScriptCallback,
+ StageWrapper* stageWrapper,
+ const std::string& signalName,
+ Stage stage)
+{
+ bool connected( true );
+ StageCallback* callback =new StageCallback( isolate, javaScriptCallback, signalName );
+
+ if( strcmp( signalName.c_str() ,STAGE_SIGNAL_KEY_EVENT) == 0 )
+ {
+ stage.KeyEventSignal().Connect( callback, &StageCallback::KeyEventSignal );
+ }
+ else if ( strcmp( signalName.c_str(), STAGE_SIGNAL_EVENT_PROCESSING_FINISHED ) == 0)
+ {
+ stage.EventProcessingFinishedSignal().Connect( callback, &StageCallback::EventProcessingFinishedSignal );
+ }
+ else if (strcmp( signalName.c_str(), STAGE_SIGNAL_TOUCHED ) == 0 )
+ {
+ stage.TouchedSignal().Connect( callback, &StageCallback::TouchedSignal );
+ }
+ else
+ {
+ connected = false;
+ }
+
+ if( connected )
+ {
+ stageWrapper->GetSignalManager()->AddCallback( static_cast<BaseCallBack*>(callback) );
+ }
+ else
+ {
+ delete callback;
+ }
+}
+
+void KeyboardFocusManagerConnection( v8::Isolate* isolate,
+ v8::Local<v8::Function> javaScriptCallback,
+ KeyboardFocusManagerWrapper* keyboardFocusWrapper,
+ const std::string& signalName,
+ Toolkit::KeyboardFocusManager keyboardFocusManager)
+{
+ bool connected( true );
+ KeyboardFocusCallback* callback =new KeyboardFocusCallback( isolate, javaScriptCallback, signalName );
+
+ if( strcmp( signalName.c_str(), KEYBOARD_FOCUS_MANAGER_SIGNAL_PRE_FOCUS_CHANGE ) == 0 )
+ {
+ keyboardFocusManager.PreFocusChangeSignal().Connect( callback, &KeyboardFocusCallback::PreFocusChangeSignal );
+ }
+ else if ( strcmp( signalName.c_str(), KEYBOARD_FOCUS_MANAGER_SIGNAL_FOCUS_CHANGED ) == 0 )
+ {
+ keyboardFocusManager.FocusChangedSignal().Connect( callback, &KeyboardFocusCallback::FocusChangedSignal );
+ }
+ else if ( strcmp( signalName.c_str(), KEYBOARD_FOCUS_MANAGER_SIGNAL_FOCUS_GROUP_CHANGED ) == 0 )
+ {
+ keyboardFocusManager.FocusGroupChangedSignal().Connect( callback, &KeyboardFocusCallback::FocusGroupSignal );
+ }
+ else if ( strcmp( signalName.c_str(), KEYBOARD_FOCUS_MANAGER_SIGNAL_FOCUSED_ACTOR_ACTIVATED ) == 0 )
+ {
+ keyboardFocusManager.FocusedActorActivatedSignal().Connect( callback, &KeyboardFocusCallback::FocusedActorSignal );
+ }
+ else
+ {
+ connected = false;
+ }
+
+ if( connected )
+ {
+ keyboardFocusWrapper->GetSignalManager()->AddCallback( static_cast<BaseCallBack*>(callback) );
+ }
+ else
+ {
+ delete callback;
+ }
+}
+
+void PanGestureDetectorConnection( v8::Isolate* isolate,
+ v8::Local<v8::Function> javaScriptCallback,
+ PanGestureDetectorWrapper* panGestureDetectorWrapper,
+ const std::string& signalName,
+ PanGestureDetector panGestureDetector )
+{
+ if( strcmp( signalName.c_str() , SIGNAL_PAN_DETECTED ) == 0 )
+ {
+ PanGestureDetectorCallback* callback =new PanGestureDetectorCallback( isolate, javaScriptCallback, signalName );
+ panGestureDetector.DetectedSignal().Connect( callback, &PanGestureDetectorCallback::OnPan );
+ panGestureDetectorWrapper->GetSignalManager()->AddCallback( static_cast<BaseCallBack*>(callback) );
+ }
+}
+
+} // un-named namespace
+
+
+SignalManager::SignalManager()
+:mInsideCallback(false)
+{
+
+}
+SignalManager::~SignalManager()
+{
+ // the object owning the signal manager ( e.g. an actor wrapper ) has been deleted
+ // delete the callbacks objects
+ for( CallBackContainer::Iterator iter = mCallbacks.Begin(); iter != mCallbacks.End(); ++iter )
+ {
+ BaseCallBack* callback = (*iter);
+ delete callback;
+ }
+ for( CallBackContainer::Iterator iter = mDisconnectedCallbacks.Begin(); iter != mDisconnectedCallbacks.End(); ++iter )
+ {
+ BaseCallBack* callback = (*iter);
+ delete callback;
+ }
+}
+
+
+void SignalManager::SignalConnect( const v8::FunctionCallbackInfo< v8::Value >& args)
+{
+ // format is
+ // first paramter = signal to connect to
+ // Second parameter = function ( to run )
+ // args.This() = myActor
+ // e.g. myActor.Connect("touched", myJavaScriptActorTouched );
+
+ // Inside Callback on myJavaScriptActorTouched
+ // myActor.Disconnect("touched", myJavaScriptActorTouched );
+
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ if( !args[1]->IsFunction() )
+ {
+ DALI_SCRIPT_EXCEPTION(isolate, "function parameter not found ");
+ return;
+ }
+
+ // get the function
+ v8::Local<v8::Function> func =v8::Handle<v8::Function>::Cast(args[1]);
+
+ // get the handle wrapper
+ BaseWrappedObject* baseObject = BaseWrappedObject::UnWrap( isolate, args.This() );
+
+ // First paramter = signal name as a string
+ bool found( false );
+ std::string signal = V8Utils::GetStringParameter( PARAMETER_0, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION(isolate, "signal name parameter not found ");
+ return;
+ }
+
+ if( signal.empty() || ( signal.length() > MAX_SIGNAL_NAME_LENGTH ) )
+ {
+ DALI_SCRIPT_EXCEPTION(isolate, "signal name length out of range");
+ return;
+ }
+ // We need to determine what type of function needs to be hooked
+ // see if we're connecting to an Actor
+ switch( baseObject->GetType() )
+ {
+ case BaseWrappedObject::ACTOR:
+ {
+ ActorWrapper* actorWrapper = static_cast< ActorWrapper*>( baseObject );
+ ActorConnection( isolate, func, actorWrapper, signal, actorWrapper->GetActor() );
+ break;
+ }
+ case BaseWrappedObject::ANIMATION:
+ {
+ AnimationWrapper* animWrapper = static_cast< AnimationWrapper*>( baseObject );
+ AnimationConnection( isolate, func, animWrapper, signal, animWrapper->GetAnimation() );
+ break;
+ }
+ case BaseWrappedObject::IMAGE:
+ {
+ ImageWrapper* imageWrapper = static_cast< ImageWrapper*>( baseObject );
+ ImageConnection( isolate, func, imageWrapper, signal, imageWrapper->GetImage() );
+ break;
+ }
+ case BaseWrappedObject::STAGE:
+ {
+ StageWrapper* stageWrapper = static_cast< StageWrapper*>( baseObject );
+ StageConnection( isolate, func, stageWrapper, signal, stageWrapper->GetStage() );
+ break;
+ }
+ case BaseWrappedObject::KEYBOARD_FOCUS_MANAGER:
+ {
+ KeyboardFocusManagerWrapper* keyboardFocusWrapper = static_cast< KeyboardFocusManagerWrapper*>( baseObject );
+ KeyboardFocusManagerConnection( isolate, func, keyboardFocusWrapper, signal, keyboardFocusWrapper->GetKeyboardFocusManager() );
+ break;
+ }
+ case BaseWrappedObject::PAN_GESTURE_DETECTOR:
+ {
+ PanGestureDetectorWrapper* panGestureDetectorWrapper = static_cast< PanGestureDetectorWrapper*>( baseObject );
+ PanGestureDetectorConnection( isolate, func, panGestureDetectorWrapper, signal, panGestureDetectorWrapper->GetPanGestureDetector() );
+ break;
+ }
+ default:
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "object does not support connections");
+ break;
+ }
+ }
+
+}
+
+void SignalManager::SignalDisconnect( const v8::FunctionCallbackInfo< v8::Value >& args)
+{
+ // we can get the function name.... use that to disconnect from the object
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ if( !args[1]->IsFunction() )
+ {
+ DALI_SCRIPT_EXCEPTION(isolate, "function parameter not found ");
+ return;
+ }
+
+ // get the function
+ v8::Local<v8::Function> func =v8::Handle<v8::Function>::Cast(args[1]);
+
+ // get the handle wrapper
+ BaseWrappedObject* baseObject = BaseWrappedObject::UnWrap( isolate, args.This() );
+
+ // First parameter = signal name as a string
+ bool found( false );
+ std::string signal = V8Utils::GetStringParameter( PARAMETER_0, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION(isolate, "signal name parameter not found ");
+ return;
+ }
+
+ SignalManager* signalManager = baseObject->GetSignalManager();
+ if(signalManager )
+ {
+ signalManager->RemoveCallback( isolate, signal, func);
+ }
+
+
+}
+void SignalManager::AddCallback( BaseCallBack* callback )
+{
+ // used by the callback to inform signal manager when it is being triggered.
+ callback->SetEmitInterface( this );
+
+ mCallbacks.PushBack( callback );
+}
+void SignalManager::RemoveCallback( v8::Isolate* isolate, const std::string& signalName, const v8::Local<v8::Function>& function )
+{
+ // lets disconnect
+ for( CallBackContainer::Iterator iter = mCallbacks.Begin(); iter != mCallbacks.End(); ++iter )
+ {
+ BaseCallBack* callback = (*iter);
+ if( ( callback->mSignalName == signalName ) &&
+ ( callback->IsFunction( function ) ) )
+ {
+ mCallbacks.Erase( iter );
+
+ // if we're inside a callback::Call function, then deleting it will cause a seg fault
+ if( mInsideCallback )
+ {
+ callback->DisconnectAll();
+ mDisconnectedCallbacks.PushBack( callback );
+ }
+ else
+ {
+ delete callback;
+ }
+ return;
+ }
+ }
+}
+
+void SignalManager::CallbackEnter()
+{
+ mInsideCallback = true;
+}
+
+void SignalManager::CallbackExit()
+{
+ // this gets called when we've finished calling into JavaScript, e.g. as a result of animation finishing
+ // which is being listened to by a javascript function.
+
+ // it possible that inside the JavaScript call, it tries to disconnect.
+ // If this happens the callback is added to the mDisconnectedCallbacks list.
+ // We then delay deleting of the callback object until the JavaScript call has finished in this function.
+
+ mInsideCallback = false;
+
+ // lets delete any call backs that were disconnect during the JavaScript call
+ for( CallBackContainer::Iterator iter = mDisconnectedCallbacks.Begin(); iter != mDisconnectedCallbacks.End(); ++iter )
+ {
+ BaseCallBack* callback = (*iter);
+ delete callback;
+ }
+ mDisconnectedCallbacks.Clear();
+
+}
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_SIGNAL_MANAGER_H__
+#define __DALI_V8PLUGIN_SIGNAL_MANAGER_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <string>
+#include <dali/public-api/common/dali-vector.h>
+
+// INTERNAL INCLUDES
+#include <signals/emit-notification-interface.h>
+
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+class BaseCallBack;
+class HandleWrapper;
+
+/**
+ * Manages signal connection / disconnection.
+ *
+ * How it works...
+ * 1) SignalConnect, SignalDisconnect is installed on to a dali-wrapped object template. E.g.
+ *
+ * objTemplate->Set( v8::String::NewFromUtf8( isolate, "Connect"),
+ v8::FunctionTemplate::New( isolate, SignalManager::SignalConnect) );
+ *
+ * 2) When the actor.Connect(...) is called, v8 runs SignalManager::SignalConnect( args )
+ *
+ * args.This() == Dali object ( e.g. Actor / Animation / Image ).
+ * args[ 0 ] == Signal name, e.g. "touched"
+ * args[ 1 ] == JavaScript function to run when the signal is fired.
+ *
+ * 3) SignalManager uses the signal name, to decide what type of Dali Signal is required.
+ * It then creates a C++ object which can be connected to the Signal.
+ * That object also holds a pointer to the JavaScript callback function
+ *
+ * 4) When the signal is fired, it triggers the signal in the C++ object, which then fires
+ * the JavaScript function. See ActorCallback::OnTouch
+ *
+ * When the object that holds SignalManager dies (e.g. an ActorWrapper), the signal manager for that
+ * object is destroyed, which automatically disconnects any signal connections.
+ *
+ * @TODO
+ * Currently DALi Core supports 'DoConnectSignal' which passes in no parameters and expects no return value.
+ * If we could extend this, so DoConnect supports a generic function such as
+ * Dali::Any (*CallbackFunction) (Dali::Vector< Dali::Any > parameters );
+ * then we should be able to remove most of the code in this file.
+ * As this is how BaseJavaScriptCallback::Call() in SignalManager.cpp works.
+ *
+ *
+ *
+ */
+class SignalManager : public EmitNotificationInterface
+{
+public:
+
+ /**
+ * Constructor
+ */
+ SignalManager();
+
+ /**
+ * Destructor
+ */
+ virtual ~SignalManager();
+
+ /**
+ * signal connect function, installed on dali-wrapped object
+ */
+ static void SignalConnect( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ /**
+ * signal disconnect function, installed on dali-wrapped object
+ */
+ static void SignalDisconnect( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ /**
+ * Add a callback
+ * @param[in] callback
+ */
+ void AddCallback( BaseCallBack* callback );
+
+ /**
+ * Remove a callback
+ * @param[in] signalName name
+ * @param[in] function to remove
+ */
+ void RemoveCallback( v8::Isolate* isolate, const std::string& signalName, const v8::Local<v8::Function>& function );
+
+private:
+
+public:
+
+ /**
+ * @copydoc EmitNotificationInterface::CallbackEnter()
+ */
+ virtual void CallbackEnter();
+
+ /**
+ * @copydoc EmitNotificationInterface::CallbackExit()
+ */
+ virtual void CallbackExit();
+
+
+ // typically an object will only have 1 callback, so a vector is ok, e.g.
+ // there's no point in storing a map of callbacks for an actor that will only have 1 connection
+ // for OnTouch.
+ typedef Dali::Vector< BaseCallBack* > CallBackContainer;
+
+ CallBackContainer mCallbacks; ///< List of callbacks
+ CallBackContainer mDisconnectedCallbacks; ///< List of disconnected callbacks
+ bool mInsideCallback; ///< To prevent recursive loops
+
+};
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "stage-api.h"
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <object/property-value-wrapper.h>
+#include <actors/actor-wrapper.h>
+#include <actors/actor-api.h>
+#include <render-tasks/render-task-list-wrapper.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+
+/***************************************
+ * STAGE FUNCTIONS
+ *
+ ****************************************/
+Dali::Stage StageApi::GetStage(v8::Isolate* isolate, const v8::FunctionCallbackInfo<v8::Value>& args)
+{
+ // the stage object should be in args, but for now just use GetCurrent
+ return Stage::GetCurrent();
+}
+
+/**
+ * Adds a child Actor to the Stage.
+ * @method add
+ * @for Stage
+ * @param {Object} Actor
+ */
+void StageApi::Add( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Stage stage = GetStage( isolate, args );
+ bool found( false );
+ Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
+ if( found )
+ {
+ stage.Add( actor );
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing actor parameter");
+ }
+}
+
+/**
+ * Removes a child Actor to the Stage.
+ * @method remove
+ * @for Stage
+ * @param {Object} Actor
+ */
+void StageApi::Remove( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Stage stage = GetStage( isolate, args );
+ bool found( false );
+
+ Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
+ if( found )
+ {
+ stage.Remove( actor );
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing actor parameter");
+ }
+}
+/**
+ * Get the size of the stage
+ * @method getSize
+ * @for Stage
+ * @return {Object} size with properties { x: , y: }
+ */
+void StageApi::GetSize( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Stage stage = GetStage( isolate, args );
+ Vector2 size( stage.GetSize() );
+
+ v8::Local<v8::Object> sizeObject = v8::Object::New( isolate );
+ sizeObject->Set( v8::String::NewFromUtf8( isolate, "x"), v8::Number::New( isolate,size.width ));
+ sizeObject->Set( v8::String::NewFromUtf8( isolate, "y"), v8::Number::New( isolate,size.height ));
+
+ // set return value
+ args.GetReturnValue().Set( sizeObject );
+
+}
+/**
+ * Retrieve the list of render-tasks.
+ * @method getRenderTaskList
+ * @for Stage
+ * @return {Object} render task list
+ */
+void StageApi::GetRenderTaskList( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Stage stage = GetStage( isolate, args );
+
+ RenderTaskList taskList = stage.GetRenderTaskList();
+
+ v8::Local <v8::Object> object = RenderTaskListWrapper::WrapRenderTaskList( isolate, taskList );
+
+ args.GetReturnValue().Set( object );
+}
+/**
+ * Query the number of on-stage layers.
+ * Note that a default layer is always provided (count >= 1).
+ * @method getLayerCount
+ * @for Stage
+ * @return {Number} number of layers
+ */
+void StageApi::GetLayerCount( const v8::FunctionCallbackInfo<v8::Value>& args)
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Stage stage = GetStage( isolate, args );
+
+ args.GetReturnValue().Set( v8::Integer::New( isolate, stage.GetLayerCount() ) );
+
+}
+/**
+ * Retrieve the list of render-tasks.
+ * @method getLayer
+ * @for Stage
+ * @param {Integer} depth
+ * @return {Object} layer
+ */
+void StageApi::GetLayer( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Stage stage = GetStage( isolate, args );
+
+ bool found( false );
+ unsigned int depth = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Integer parameter missing" );
+ return;
+ }
+ Layer rootLayer = stage.GetLayer( depth );
+
+ v8::Handle < v8::Object > wrappedLayer = ActorWrapper::WrapActor( isolate, rootLayer );
+ args.GetReturnValue().Set( wrappedLayer );
+}
+/**
+ * Returns the Stage's Root Layer.
+ * @method getRootLayer
+ * @for Stage
+ * @return {Object} root layer
+ */
+void StageApi::GetRootLayer( const v8::FunctionCallbackInfo<v8::Value>& args)
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Stage stage = GetStage( isolate, args );
+
+ Layer rootLayer = stage.GetRootLayer();
+
+ v8::Handle < v8::Object > wrappedLayer = ActorWrapper::WrapActor( isolate, rootLayer );
+ args.GetReturnValue().Set( wrappedLayer );
+}
+
+/**
+ * Set the background color of the stage
+ * @method setBackgroundColor
+ * @for Stage
+ * @param {Object} Array of [Red,Green,Blue,Alpha], e.g. dali.COLOR_RED, or [1,0,0,1] (full red and alpha);
+ * @example
+ * dali.stage.setBackgroundColor( dali.COLOR_RED );
+ *
+ * dali.stage.setBackgroundColor( [0.5,0.5,0.5,1 ] ); // set the background to grey
+ */
+void StageApi::SetBackgroundColor( const v8::FunctionCallbackInfo<v8::Value>& args)
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Stage stage = GetStage( isolate, args );
+ bool found( false );
+
+ Vector4 backgroundColor = V8Utils::GetVector4Parameter( PARAMETER_0, found, isolate, args);
+ if (!found)
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "no parameter not found" );
+ return;
+ }
+ stage.SetBackgroundColor( backgroundColor );
+}
+/**
+ * Get the background color of the stage
+ * @method getBackgroundColor
+ * @for Stage
+ * @return {Object} object that contains the properties [red:,green:,blue,alpha:]
+ */
+void StageApi::GetBackgroundColor( const v8::FunctionCallbackInfo<v8::Value>& args)
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Stage stage = GetStage( isolate, args );
+
+ Vector4 color = stage.GetBackgroundColor();
+
+ v8::Local<v8::Object> colorObject = v8::Object::New( isolate );
+
+ colorObject->Set( v8::String::NewFromUtf8( isolate, "red"), v8::Number::New( isolate,color.r));
+ colorObject->Set( v8::String::NewFromUtf8( isolate, "green"), v8::Number::New( isolate,color.g));
+ colorObject->Set( v8::String::NewFromUtf8( isolate, "blue"), v8::Number::New( isolate,color.b));
+ colorObject->Set( v8::String::NewFromUtf8( isolate, "alpha"), v8::Number::New( isolate,color.a));
+
+ // set return value
+ args.GetReturnValue().Set( colorObject );
+
+
+}
+/**
+ * Retrieve the DPI of the display device to which the stage is connected.
+ * @method getDpi
+ * @for Stage
+ * @return {Object} object that contains the properties [x:,y:]
+ */
+void StageApi::GetDpi( const v8::FunctionCallbackInfo<v8::Value>& args)
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Stage stage = GetStage( isolate, args );
+
+ Vector2 dpi( stage.GetDpi() );
+
+ v8::Local<v8::Object> dpiObject = v8::Object::New( isolate );
+ dpiObject->Set( v8::String::NewFromUtf8( isolate, "x"), v8::Number::New( isolate,dpi.x));
+ dpiObject->Set( v8::String::NewFromUtf8( isolate, "y"), v8::Number::New( isolate,dpi.y));
+
+
+ args.GetReturnValue().Set( dpiObject );
+}
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_STAGE_API_H__
+#define __DALI_V8PLUGIN_STAGE_API_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/public-api/common/stage.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace StageApi
+{
+
+ /**
+ * helper
+ */
+ Dali::Stage GetStage( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ /**
+ * StageApi API see image-actor.h for a description
+ */
+ void Add( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void Remove( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetSize( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetRenderTaskList( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetLayer( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetLayerCount( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetRootLayer( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetBackgroundColor( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetBackgroundColor( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetDpi( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+}; // namespace StageApi
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header __DALI_V8PLUGIN_STAGE_API_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "stage-wrapper.h"
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <dali-wrapper.h>
+#include <stage/stage-api.h>
+#include <shared/api-function.h>
+#include <shared/object-template-helper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace
+{
+
+/**
+ * Contains a list of all functions that can be called on the stage
+ */
+const ApiFunction StageFunctionTable[]=
+{
+ /**************************************
+ * Stage API (in order of stage.h)
+ * Any properties that have accessor functions are ignored to avoid duplication
+ **************************************/
+ { "Add", StageApi::Add },
+ { "Remove", StageApi::Remove },
+ { "GetSize", StageApi::GetSize },
+ { "GetRenderTaskList", StageApi::GetRenderTaskList },
+ { "GetLayerCount", StageApi::GetLayerCount },
+ { "GetLayer", StageApi::GetLayer },
+ { "GetRootLayer", StageApi::GetRootLayer },
+ { "SetBackgroundColor", StageApi::SetBackgroundColor },
+ { "GetBackgroundColor", StageApi::GetBackgroundColor },
+ { "GetDpi", StageApi::GetDpi },
+};
+
+const unsigned int StageFunctionTableCount = sizeof(StageFunctionTable)/sizeof(StageFunctionTable[0]);
+} //un-named space
+
+
+StageWrapper::StageWrapper( const Dali::Stage& stage, GarbageCollectorInterface& gc )
+: BaseWrappedObject( BaseWrappedObject::STAGE , gc )
+{
+ mStage = stage;
+}
+
+v8::Handle<v8::Object> StageWrapper::WrapStage(v8::Isolate* isolate, const Dali::Stage& stage )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::ObjectTemplate> objectTemplate;
+
+ objectTemplate = GetStageTemplate( isolate);
+
+ // create an instance of the template
+ v8::Local<v8::Object> localObject = objectTemplate->NewInstance();
+
+ // create the Stage wrapper
+ StageWrapper* pointer = new StageWrapper( stage, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() );
+
+ // assign the JavaScript object to the wrapper.
+ pointer->SetJavascriptObject( isolate, localObject );
+
+ return handleScope.Escape( localObject );
+}
+
+v8::Local<v8::ObjectTemplate> StageWrapper::GetStageTemplate( v8::Isolate* isolate)
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::ObjectTemplate> objectTemplate;
+ objectTemplate = MakeStageTemplate( isolate );
+ return handleScope.Escape( objectTemplate );
+}
+
+v8::Handle<v8::ObjectTemplate> StageWrapper::MakeStageTemplate( v8::Isolate* isolate )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+
+ v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
+
+ // add intercepts for Signals, we can't use HandleWrapper::AddIntercepts because Stage doesn't inherit
+ // from Handle ( just baseHandle)
+ ObjectTemplateHelper::AddSignalConnectAndDisconnect( isolate, objTemplate );
+
+ objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT );
+
+ // add our function properties
+ ObjectTemplateHelper::InstallFunctions( isolate, objTemplate, StageFunctionTable, StageFunctionTableCount );
+
+ return handleScope.Escape( objTemplate );
+}
+
+Stage StageWrapper::GetStage()
+{
+ return mStage;
+}
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_STAGE_WRAPPER_H__
+#define __DALI_V8PLUGIN_STAGE_WRAPPER_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/public-api/common/stage.h>
+
+// INTERNAL INCLUDES
+#include <shared/base-wrapped-object.h>
+#include <signals/signal-manager.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+
+/**
+ * An Stage wrapper.
+ * Provides access to Stage specific functionality and V8 memory handling.
+ */
+class DALI_INTERNAL StageWrapper : public BaseWrappedObject
+{
+
+public:
+
+ StageWrapper( const Stage& stage,
+ GarbageCollectorInterface& gc );
+
+ virtual ~StageWrapper() {};
+
+ /**
+ * Wraps a stage
+ */
+ static v8::Handle<v8::Object> WrapStage(v8::Isolate* isolate, const Dali::Stage& );
+
+ Stage GetStage();
+
+ virtual SignalManager* GetSignalManager() { return &mSignalManager;}
+
+
+private:
+
+ // Stage
+ Stage mStage;
+ SignalManager mSignalManager;
+
+ static v8::Handle<v8::ObjectTemplate> MakeStageTemplate( v8::Isolate* isolate );
+ static v8::Local<v8::ObjectTemplate> GetStageTemplate( v8::Isolate* isolate );
+
+};
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // __DALI_V8PLUGIN_STAGE_WRAPPER_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "font-api.h"
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <text/font-wrapper.h>
+#include <object/property-value-wrapper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace // un named namespace
+{
+
+
+
+
+} //un named namespace
+
+/***************************************
+ * IMAGE FUNCTIONS
+ *
+ ****************************************/
+Font FontApi::GetFont( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::HandleScope handleScope( isolate );
+
+ v8::Local<v8::Object> object = args.This();
+ v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField(0) );
+ void* ptr = field->Value();
+
+ FontWrapper* wrapper = static_cast< FontWrapper *>(ptr);
+ return wrapper->GetFont();
+}
+Font FontApi::GetFont( v8::Isolate* isolate, v8::Local<v8::Value>& value )
+{
+ v8::HandleScope handleScope( isolate );
+ v8::Local<v8::Object> object = value->ToObject();
+ v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField(0) );
+ void* ptr = field->Value();
+
+ FontWrapper* wrapper = static_cast< FontWrapper *>(ptr);
+ return wrapper->GetFont();
+}
+
+struct FontParams
+{
+ typedef enum
+ {
+ NO_SIZE_SET,
+ USE_POINT_SIZE,
+ USE_PIXEL_SIZE,
+ USE_CAP_SIZE,
+ } SizeType;
+
+
+ FontParams()
+ :pointSize( 0 ),
+ pixelSize( 0 ),
+ capsSize( 0 ),
+ sizeType( FontParams::NO_SIZE_SET )
+ {
+ }
+
+ std::string family;
+ std::string style;
+ PointSize pointSize;
+ PixelSize pixelSize;
+ CapsHeight capsSize;
+ SizeType sizeType;
+
+
+};
+
+
+void ReadFontParameters( v8::Isolate* isolate,
+ v8::Local<v8::Value > options,
+ FontParams& fontParams )
+{
+ // foont options is an optional parameter passed in which holds
+ // optional settings
+ // var fontOptions = {
+ // family: "arial",
+ // style: "bold",
+ // // one of the following
+ // pixelSize: xx
+ // pointSize: xx
+ // capsHeight:xx // height of a capital letter above the baseline for a particular typeface.
+ //
+ // };
+ v8::HandleScope handleScope( isolate );
+ if( !options->IsObject() )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 0 ( font parameters)" );
+ return;
+ }
+ v8::Local<v8::Object> obj = options->ToObject();
+
+ v8::Local<v8::Value> familyValue = obj->Get( v8::String::NewFromUtf8( isolate, "family" ) );
+ if( familyValue->IsString() )
+ {
+ fontParams.family = V8Utils::v8StringToStdString( familyValue );
+ }
+
+ v8::Local<v8::Value> styleValue = obj->Get( v8::String::NewFromUtf8( isolate, "style" ) );
+ if( styleValue->IsString() )
+ {
+ fontParams.style = V8Utils::v8StringToStdString( styleValue );
+ }
+
+ v8::Local<v8::Value> pixelSize = obj->Get( v8::String::NewFromUtf8( isolate, "pixelSize" ) );
+ v8::Local<v8::Value> pointSize = obj->Get( v8::String::NewFromUtf8( isolate, "pointSize" ) );
+ v8::Local<v8::Value> capsHeight = obj->Get( v8::String::NewFromUtf8( isolate, "capsHeight" ) );
+
+ if( pixelSize->IsUint32() )
+ {
+ fontParams.pixelSize.value = pixelSize->ToUint32()->Value();
+ fontParams.sizeType = FontParams::USE_PIXEL_SIZE;
+ }
+ else if( pointSize->IsUint32() )
+ {
+ fontParams.pointSize.value = pointSize->ToUint32()->Value();
+ fontParams.sizeType = FontParams::USE_POINT_SIZE;
+ }
+ else if( capsHeight->IsUint32() )
+ {
+ fontParams.capsSize.value = capsHeight->ToUint32()->Value();
+ fontParams.sizeType = FontParams::USE_CAP_SIZE;
+ }
+
+}
+
+Font FontApi::New( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ // if no parameters just create a default font
+ if ( args.Length() == 0)
+ {
+ return Font::New();
+ }
+ FontParams params;
+
+ ReadFontParameters( isolate, args[0], params );
+
+ FontParameters fontParams;
+ // construct a dali font parameters object
+ switch( params.sizeType)
+ {
+ case FontParams::USE_PIXEL_SIZE:
+ {
+ fontParams = FontParameters( params.family, params.style, params.pixelSize );
+ break;
+ }
+ case FontParams::USE_POINT_SIZE:
+ {
+ fontParams = FontParameters( params.family, params.style, params.pointSize );
+ break;
+ }
+ case FontParams::USE_CAP_SIZE:
+ {
+ fontParams = FontParameters( params.family, params.style, params.capsSize );
+ break;
+ }
+ default:
+ {
+ fontParams = FontParameters( params.family, params.style, PointSize(0.f));
+ break;
+ }
+ }
+ return Font::New( fontParams );
+
+}
+
+
+void FontApi::GetFamilyForText( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+
+ bool foundString;
+ std::string text = V8Utils::GetStringParameter( PARAMETER_0, foundString, isolate, args );
+ if( !foundString )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 0 ( text )" );
+ return;
+ }
+ std::string family = Font::GetFamilyForText( text );
+
+ args.GetReturnValue().Set( v8::String::NewFromUtf8( isolate, family.c_str()) );
+
+}
+void FontApi::GetLineHeightFromCapsHeight( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ FontParams params;
+ ReadFontParameters( isolate, args[0], params );
+ if( params.sizeType != FontParams::USE_CAP_SIZE )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "caps height not found" );
+ return;
+ }
+
+ PixelSize size = Font::GetLineHeightFromCapsHeight( params.family, params.style, params.capsSize);
+ args.GetReturnValue().Set( v8::Integer::New( isolate, size.value ) );
+}
+
+void FontApi::GetInstalledFonts( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ bool found( false );
+ std::vector<std::string> fontList;
+
+ std::string mode = V8Utils::GetStringParameter( PARAMETER_0, found, isolate, args );
+
+ if( mode == "LIST_APPLICATION_FONTS" )
+ {
+ fontList = Font::GetInstalledFonts( Font::LIST_APPLICATION_FONTS );
+ }
+ else if( mode == "LIST_ALL_FONTS")
+ {
+ fontList = Font::GetInstalledFonts( Font::LIST_ALL_FONTS );
+ }
+ else // default
+ {
+ fontList = Font::GetInstalledFonts( Font::LIST_SYSTEM_FONTS );
+ }
+ // create a javascript array
+ v8::Local<v8::Array> array = v8::Array::New(isolate, fontList.size() );
+ for( std::size_t i = 0; i < fontList.size(); i++)
+ {
+ const char* fontName = fontList[i].c_str();
+ array->Set(v8::Integer::New(args.GetIsolate(), i), v8::String::NewFromUtf8( isolate,fontName));
+ }
+
+ args.GetReturnValue().Set( array );
+}
+
+void FontApi::MeasureTextWidth( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Font font = GetFont( isolate, args );
+
+ //float MeasureTextWidth(const std::string& text, float textHeightPx) const;
+
+ bool found( false );
+ std::string text = V8Utils::GetStringParameter( PARAMETER_0, found, isolate, args );
+ if(! found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "text not found" );
+ return;
+ }
+ int height = V8Utils::GetIntegerParameter( PARAMETER_1, found, isolate, args, 0 );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing text height" );
+ return;
+ }
+ float width = font.MeasureTextWidth( text, height );
+
+ args.GetReturnValue().Set( v8::Integer::New( isolate, width ) );
+
+}
+void FontApi::MeasureTextHeight( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Font font = GetFont( isolate, args );
+
+ //float MeasureTextHeight(const std::string& text, float textHeightPx) const;
+
+ bool found( false );
+ std::string text = V8Utils::GetStringParameter( PARAMETER_0, found, isolate, args );
+ if(! found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "text not found" );
+ return;
+ }
+ int width= V8Utils::GetIntegerParameter( PARAMETER_1, found, isolate, args, 0 );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing text height" );
+ return;
+ }
+ float height = font.MeasureTextHeight( text, width );
+
+ args.GetReturnValue().Set( v8::Integer::New( isolate, height ) );
+}
+void FontApi::MeasureText( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Font font = GetFont( isolate, args );
+
+ bool found( false );
+ std::string text = V8Utils::GetStringParameter( PARAMETER_0, found, isolate, args );
+ if(! found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "text not found" );
+ return;
+ }
+
+ Vector3 vec3 = font.MeasureText( text );
+ Dali::Property::Value value( vec3 );
+ v8::Local <v8::Object> object = PropertyValueWrapper::WrapDaliProperty( isolate, value);
+ args.GetReturnValue().Set( object );
+
+}
+void FontApi::AllGlyphsSupported( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Font font = GetFont( isolate, args );
+
+ bool found( false );
+ std::string text = V8Utils::GetStringParameter( PARAMETER_0, found, isolate, args );
+ if(! found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "text not found" );
+ return;
+ }
+
+ bool supported = font.AllGlyphsSupported( text );
+ args.GetReturnValue().Set( v8::Boolean::New( isolate, supported) );
+
+}
+
+// This one function is use to create a property map, instead of the many individual property
+// getters used by the C++ Dali API.
+// propertyMap
+// {
+// name:
+// style:
+// pointSize:
+// pixelSize:
+// lineHeight:
+// ascender:
+// underlineThickness:
+// underlinePosition:
+// isDefaultSystemFont:
+// isDefaultSystemSize:
+// }
+
+void FontApi::GetProperties( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Font font = GetFont( isolate, args );
+
+ v8::Local<v8::Object> keyObject = v8::Object::New( isolate );
+
+ keyObject->Set( v8::String::NewFromUtf8( isolate, "family" ), v8::String::NewFromUtf8( isolate, font.GetName().c_str() ) );
+ keyObject->Set( v8::String::NewFromUtf8( isolate, "style" ), v8::String::NewFromUtf8( isolate, font.GetStyle().c_str() ) );
+ keyObject->Set( v8::String::NewFromUtf8( isolate, "pointSize" ), v8::Integer::New( isolate, font.GetPointSize() ) );
+ keyObject->Set( v8::String::NewFromUtf8( isolate, "pixelSize" ), v8::Integer::New( isolate, font.GetPixelSize() ) );
+ keyObject->Set( v8::String::NewFromUtf8( isolate, "lineHeight" ), v8::Integer::New( isolate, font.GetLineHeight() ) );
+ keyObject->Set( v8::String::NewFromUtf8( isolate, "ascender" ), v8::Integer::New( isolate, font.GetAscender() ) );
+ keyObject->Set( v8::String::NewFromUtf8( isolate, "underlineThickness" ), v8::Integer::New( isolate, font.GetUnderlineThickness() ) );
+ keyObject->Set( v8::String::NewFromUtf8( isolate, "underlinePosition" ), v8::Integer::New( isolate, font.GetUnderlinePosition()) );
+ keyObject->Set( v8::String::NewFromUtf8( isolate, "isDefaultSystemFont" ), v8::Boolean::New( isolate, font.IsDefaultSystemFont() ) );
+ keyObject->Set( v8::String::NewFromUtf8( isolate, "isDefaultSystemSize" ), v8::Boolean::New( isolate, font.IsDefaultSystemSize() ) );
+
+ args.GetReturnValue().Set( keyObject );
+
+}
+
+void FontApi::GetMetrics( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Font font = GetFont( isolate, args );
+
+ bool found( false );
+ std::string text = V8Utils::GetStringParameter( PARAMETER_0, found, isolate, args );
+
+ if(! found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "character not found" );
+ return;
+ }
+
+ Text textObject( text );
+
+ Font::Metrics metric = font.GetMetrics( textObject[0] );
+
+ v8::Local<v8::Object> keyObject = v8::Object::New( isolate );
+ keyObject->Set( v8::String::NewFromUtf8( isolate, "advance" ), v8::Integer::New( isolate, metric.GetAdvance() ) );
+ keyObject->Set( v8::String::NewFromUtf8( isolate, "bearing" ), v8::Integer::New( isolate, metric.GetBearing() ) );
+ keyObject->Set( v8::String::NewFromUtf8( isolate, "width" ), v8::Integer::New( isolate, metric.GetWidth() ) );
+ keyObject->Set( v8::String::NewFromUtf8( isolate, "height" ), v8::Integer::New( isolate, metric.GetHeight() ) );
+
+ args.GetReturnValue().Set( keyObject );
+
+}
+
+
+void FontApi::PointsToPixels( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ bool found(false);
+ int pointSize= V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing pointSize" );
+ return;
+ }
+ args.GetReturnValue().Set( v8::Integer::New( isolate, Font::PointsToPixels(pointSize) ) );
+
+}
+void FontApi::PixelsToPoints( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ bool found(false);
+ int pixelSize= V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing pixelSize" );
+ return;
+ }
+ args.GetReturnValue().Set( v8::Integer::New( isolate, Font::PixelsToPoints(pixelSize) ) );
+}
+
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_FONT_API_H__
+#define __DALI_V8PLUGIN_FONT_API_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/public-api/text/font.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace FontApi
+{
+ Font GetFont( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args );
+ Font GetFont( v8::Isolate* isolate, v8::Local<v8::Value>& value );
+
+ Font GetFontFromParams( int paramIndex,
+ bool& found,
+ v8::Isolate* isolate,
+ const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ /**
+ * Constructor
+ */
+ Font New( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ /**
+ * Font API see image.h for a description
+ */
+ void GetFamilyForText( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetLineHeightFromCapsHeight( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetInstalledFonts( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void MeasureTextWidth( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void MeasureTextHeight( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void MeasureText( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void AllGlyphsSupported( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetProperties( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetMetrics( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void PointsToPixels( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void PixelsToPoints( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+}; // namespace FontApi
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header __DALI_V8PLUGIN_FONT_API_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "font-wrapper.h"
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <dali-wrapper.h>
+#include <text/font-api.h>
+#include <shared/api-function.h>
+#include <shared/object-template-helper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace // un-named name space
+{
+
+/**
+ * Contains a list of all functions that can be called on the font object
+ */
+const ApiFunction FontFunctionTable[]=
+{
+ /**************************************
+ * Font API (in order of font.h)
+ **************************************/
+ { "MeasureTextWidth", FontApi::MeasureTextWidth },
+ { "MeasureTextHeight", FontApi::MeasureTextHeight },
+ { "MeasureText", FontApi::MeasureText },
+ { "AllGlyphsSupported", FontApi::AllGlyphsSupported },
+ { "GetProperties", FontApi::GetProperties }, // replace all getters
+ { "GetMetrics", FontApi::GetMetrics },
+};
+
+const unsigned int FontFunctionTableCount = sizeof(FontFunctionTable)/sizeof(FontFunctionTable[0]);
+
+/**
+ * Contains a list of all functions that can be called
+ */
+const ApiFunction StaticFontFunctionTable[]=
+{
+ /**************************************
+ * Static font functions, called without a font object
+ **************************************/
+ { "GetFamilyForText", FontApi::GetFamilyForText },
+ { "GetLineHeightFromCapsHeight", FontApi::GetLineHeightFromCapsHeight },
+ { "GetInstalledFonts", FontApi::GetInstalledFonts },
+ { "PointsToPixels", FontApi::PointsToPixels },
+ { "PixelsToPoints", FontApi::PixelsToPoints },
+};
+
+const unsigned int StaticFontFunctionTableCount = sizeof(StaticFontFunctionTable)/sizeof(FontFunctionTable[0]);
+
+} //un-named space
+
+
+FontWrapper::FontWrapper( const Dali::Font& font, GarbageCollectorInterface& gc )
+: BaseWrappedObject( BaseWrappedObject::FONT , gc )
+{
+ mFont = font;
+}
+
+v8::Handle<v8::Object> FontWrapper::WrapFont(v8::Isolate* isolate, const Dali::Font& font )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::ObjectTemplate> objectTemplate;
+
+ objectTemplate = MakeFontTemplate( isolate );
+
+ // create an instance of the template
+ v8::Local<v8::Object> localObject = objectTemplate->NewInstance();
+
+ // create the Font wrapper
+ FontWrapper* pointer = new FontWrapper( font, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() );
+
+ // assign the JavaScript object to the wrapper.
+ pointer->SetJavascriptObject( isolate, localObject );
+
+ printf("Created Font!\n");
+ return handleScope.Escape( localObject );
+}
+
+
+v8::Handle<v8::ObjectTemplate> FontWrapper::MakeFontTemplate( v8::Isolate* isolate )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+
+ v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
+
+ objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT );
+
+ // add our function properties
+ ObjectTemplateHelper::InstallFunctions( isolate, objTemplate, FontFunctionTable, FontFunctionTableCount );
+
+ return handleScope.Escape( objTemplate );
+}
+
+void FontWrapper::NewFont( const v8::FunctionCallbackInfo< v8::Value >& args)
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate);
+
+ if(!args.IsConstructCall())
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Font constructor called without 'new'");
+ return;
+ }
+
+ // attribs can be passed by value
+ Dali::Font font = FontApi::New( args );
+ if( !font )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "bad font parameters\n");
+ return;
+ }
+
+ v8::Local<v8::Object> localObject = WrapFont( isolate, font );
+ args.GetReturnValue().Set( localObject );
+}
+
+Font FontWrapper::GetFont()
+{
+ return mFont;
+}
+
+v8::Handle<v8::Object> FontWrapper::GetStaticFontObject(v8::Isolate* isolate)
+{
+ v8::EscapableHandleScope handleScope( isolate );
+
+ v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
+
+ // add our functions properties
+ ObjectTemplateHelper::InstallFunctions( isolate, objTemplate, StaticFontFunctionTable, StaticFontFunctionTableCount );
+
+ v8::Local<v8::Object> localObject = objTemplate->NewInstance();
+
+ return handleScope.Escape( localObject );
+
+ }
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_FONT_WRAPPER_H__
+#define __DALI_V8PLUGIN_FONT_WRAPPER_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/public-api/text/font.h>
+
+// INTERNAL INCLUDES
+#include <shared/base-wrapped-object.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+
+/**
+ * An Font wrapper.
+ * Provides access to Font specific functionality and V8 memory handling.
+ */
+class FontWrapper : public BaseWrappedObject
+{
+
+public:
+
+ FontWrapper( const Font& font,
+ GarbageCollectorInterface& gc );
+
+ virtual ~FontWrapper()
+ {
+ };
+
+ /**
+ * @brief Creates a new Font wrapped inside a Javascript Object.
+ * @note: the actor type ie 'FontFont' is expected to be the name of the callee function.
+ * @param[in] args v8 function call arguments interpreted
+ */
+ static void NewFont( const v8::FunctionCallbackInfo< v8::Value >& args);
+
+ /**
+ * Wraps a font
+ */
+ static v8::Handle<v8::Object> WrapFont(v8::Isolate* isolate, const Dali::Font& );
+
+ Font GetFont();
+
+ static v8::Handle<v8::Object> GetStaticFontObject(v8::Isolate* isolate);
+
+private:
+
+ Font mFont;
+ static v8::Handle<v8::ObjectTemplate> MakeFontTemplate( v8::Isolate* isolate );
+
+};
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // __DALI_V8PLUGIN_FONT_WRAPPER_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "builder-api.h"
+
+// EXTERNAL INCLUDES
+#include <dali/integration-api/debug.h>
+#include <string>
+#include <fstream>
+#include <streambuf>
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <object/property-value-wrapper.h>
+#include <object/handle-wrapper.h>
+#include <toolkit/builder/builder-wrapper.h>
+#include <actors/actor-wrapper.h>
+#include <image/image-wrapper.h>
+#include <animation/animation-wrapper.h>
+#include <text/font-wrapper.h>
+#include <shader-effects/shader-effect-wrapper.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace // un named namespace
+{
+
+
+Dali::Toolkit::Builder GetBuilder( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::HandleScope handleScope( isolate );
+
+ v8::Local<v8::Object> object = args.This();
+ v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField( 0 ) );
+ void* ptr = field->Value();
+
+ BuilderWrapper* wrapper = static_cast<BuilderWrapper *>( ptr );
+ return wrapper->GetBuilder();
+}
+
+
+void GetMapAndString( v8::Isolate* isolate,
+ std::string stringKey,
+ std::string& stringValue,
+ std::string mapKey,
+ Dali::Property::Map& map,
+ v8::Local<v8::Object> object)
+{
+ v8::Local<v8::Value> stringNameValue = object->Get( v8::String::NewFromUtf8( isolate, stringKey.c_str() ) );
+ if( !stringNameValue->IsString() )
+ {
+ std::string message = "missing field :"+stringKey;
+ DALI_SCRIPT_EXCEPTION( isolate, message);
+ return;
+ }
+ stringValue = V8Utils::v8StringToStdString( stringNameValue );
+
+ // constants is optional
+
+ v8::Local<v8::Value> constants = object->Get( v8::String::NewFromUtf8( isolate, mapKey.c_str() ) );
+ if( constants->IsObject() )
+ {
+ map = V8Utils::GetPropertyMapFromObject( isolate, constants->ToObject() );
+ }
+}
+
+
+} // un-named namespace
+
+
+Dali::Toolkit::Builder BuilderApi::New( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ return Dali::Toolkit::Builder::New();
+}
+
+void BuilderApi::LoadFromString( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Dali::Toolkit::Builder builder = GetBuilder( isolate, args );
+
+ bool found(false);
+ std::string str = V8Utils::GetStringParameter( 0, found, isolate, args );
+ if( found )
+ {
+ builder.LoadFromString( str );
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing string parameter");
+ }
+}
+
+void BuilderApi::LoadFromFile( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Dali::Toolkit::Builder builder = GetBuilder( isolate, args );
+
+ bool found(false);
+ std::string fileName= V8Utils::GetStringParameter( 0, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing string parameter");
+ return;
+ }
+
+ std::ifstream fileStream( fileName.c_str() );
+ if( !fileStream.is_open() )
+ {
+ std::string message = "failed to open JSON file" + fileName;
+ DALI_SCRIPT_EXCEPTION( isolate, message );
+ return;
+ }
+
+ //single-pass input iterator that reads successive characters from the input stream
+ std::string json = std::string( (std::istreambuf_iterator< char >( fileStream )), std::istreambuf_iterator< char >() );
+
+ builder.LoadFromString( json );
+
+}
+
+void BuilderApi::AddConstants( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Dali::Toolkit::Builder builder = GetBuilder( isolate, args );
+
+ bool found(false);
+ Dali::Property::Map map = V8Utils::GetPropertyMapParameter( 0,found, isolate, args );
+
+ if( found )
+ {
+ builder.AddConstants( map );
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "no constants found" );
+ }
+
+}
+
+void BuilderApi::GetConstants( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Dali::Toolkit::Builder builder = GetBuilder( isolate, args );
+
+ const Dali::Property::Map& map = builder.GetConstants();
+
+ v8::Local<v8::Object> object = v8::Object::New( isolate );
+
+ V8Utils::CreatePropertyMap( isolate, map, object );
+
+ args.GetReturnValue().Set( object );
+
+}
+void BuilderApi::CreateAnimation( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ // options =
+ // {
+ // animation: ..
+ // constants:
+ // actor:
+ // }
+ //
+
+ Dali::Toolkit::Builder builder = GetBuilder( isolate, args );
+
+ if( !args[0]->IsObject() )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "invalid property map, expecting { animation: x, constants: y, actor: z}" );
+ return;
+ }
+ v8::Local<v8::Object> object = args[0]->ToObject();
+
+ std::string animationName;
+ Dali::Property::Map map;
+
+ // get the animation name and constant map
+
+ GetMapAndString( isolate,
+ "animation",
+ animationName,
+ "constants",
+ map,
+ object );
+
+ // actor is optional
+ Actor actor;
+ v8::Local<v8::Value> actorValue = object->Get( v8::String::NewFromUtf8( isolate, "actor" ) );
+ if( actorValue->IsObject() )
+ {
+ HandleWrapper* handleWrapper = HandleWrapper::Unwrap( isolate, actorValue->ToObject() );
+ if( handleWrapper )
+ {
+ actor = Actor::DownCast( handleWrapper->mHandle );
+ }
+ }
+ Animation anim;
+ if( actor )
+ {
+ // Animation CreateAnimation( const std::string& animationName, const Dali::Property::Map& map, Dali::Actor sourceActor );
+ anim = builder.CreateAnimation( animationName, map, actor );
+ }
+ else
+ {
+ anim = builder.CreateAnimation( animationName, map);
+ }
+ v8::Local<v8::Object> localObject = AnimationWrapper::WrapAnimation( isolate, anim );
+ args.GetReturnValue().Set( localObject );
+}
+
+void BuilderApi::Create( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Dali::Toolkit::Builder builder = GetBuilder( isolate, args );
+
+ if( !args[0]->IsObject() )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "invalid param");
+ return;
+ }
+ v8::Local<v8::Object> object = args[0]->ToObject();
+
+ // options =
+ // {
+ // template: "my-temppalte",
+ // constants: { IMAGE_DIR: "/usr/apps" , SHADER_DIR: "/usr/apps/.."}
+ // }
+ //
+ std::string templateName;
+ Dali::Property::Map map;
+
+ GetMapAndString( isolate,
+ "template",
+ templateName,
+ "constants",
+ map,
+ object );
+
+ BaseHandle handle = builder.Create( templateName, map );
+ std::string typeName = handle.GetTypeName();
+ ActorWrapper::ActorType actorType = ActorWrapper::GetActorType( typeName );
+
+ if( actorType != ActorWrapper::UNKNOWN_ACTOR )
+ {
+ v8::Local<v8::Object> actorObject = ActorWrapper::WrapActor(isolate, Actor::DownCast(handle),actorType);
+ args.GetReturnValue().Set( actorObject );
+ return;
+ }
+
+ if( typeName == "Animation")
+ {
+ v8::Local<v8::Object> animation = AnimationWrapper::WrapAnimation(isolate, Animation::DownCast(handle) );
+ args.GetReturnValue().Set( animation );
+ }
+
+ if( typeName == "Image")
+ {
+ v8::Local<v8::Object> image = ImageWrapper::WrapImage(isolate, Image::DownCast(handle) );
+ args.GetReturnValue().Set( image );
+ }
+ if( typeName == "Font ")
+ {
+ v8::Local<v8::Object> font = FontWrapper::WrapFont(isolate, Font::DownCast(handle) );
+ args.GetReturnValue().Set( font );
+ }
+ if( typeName == "Shader")
+ {
+ v8::Local<v8::Object> shader = ShaderEffectWrapper::WrapShaderEffect(isolate, ShaderEffect::DownCast( handle ));
+ args.GetReturnValue().Set( shader );
+ }
+
+}
+void BuilderApi::ApplyStyle( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Dali::Toolkit::Builder builder = GetBuilder( isolate, args );
+
+ // bool ApplyStyle( const std::string& styleName, Handle& handle );
+
+ bool found(false);
+ std::string styleName = V8Utils::GetStringParameter( PARAMETER_0, found, isolate, args);
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing style name" );
+ return;
+ }
+
+ Dali::Handle handle = V8Utils::GetHandleParameter( PARAMETER_1, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing handle parameter" );
+ return;
+ }
+
+ builder.ApplyStyle( styleName, handle );
+
+}
+
+void BuilderApi::ApplyFromJson( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Dali::Toolkit::Builder builder = GetBuilder( isolate, args );
+
+ bool found;
+
+ Dali::Handle handle = V8Utils::GetHandleParameter( PARAMETER_0, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing handle parameter" );
+ return;
+ }
+ std::string jsonString = V8Utils::GetStringParameter( PARAMETER_1, found, isolate, args);
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing JSON string" );
+ return;
+ }
+ builder.ApplyFromJson( handle, jsonString );
+}
+
+void BuilderApi::AddActors( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Dali::Toolkit::Builder builder = GetBuilder( isolate, args );
+
+ //{
+ // actor:actor
+ // section: name
+ //}
+
+ Actor actor;
+
+ if( !args[0]->IsObject() )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "invalid param");
+ return;
+ }
+ v8::Local<v8::Object> object = args[0]->ToObject();
+
+ v8::Local<v8::Value> actorValue = object->Get( v8::String::NewFromUtf8( isolate, "actor" ) );
+ if( actorValue->IsObject() )
+ {
+ HandleWrapper* handleWrapper = HandleWrapper::Unwrap( isolate, actorValue->ToObject() );
+ if( handleWrapper )
+ {
+ actor = Actor::DownCast( handleWrapper->mHandle );
+ }
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "actor field not found in param");
+ return;
+ }
+
+ v8::Local<v8::Value> stringNameValue = object->Get( v8::String::NewFromUtf8( isolate, "section" ) );
+ if( !stringNameValue->IsString() )
+ {
+ std::string message = "missing field: section";
+ DALI_SCRIPT_EXCEPTION( isolate, message);
+ return;
+ }
+ std::string sectionName = V8Utils::v8StringToStdString( stringNameValue );
+ if( !sectionName.empty() )
+ {
+ builder.AddActors( sectionName, actor );
+ }
+ else
+ {
+ builder.AddActors( actor );
+ }
+
+}
+
+void BuilderApi::CreateRenderTask( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Dali::Toolkit::Builder builder = GetBuilder( isolate, args );
+ bool found(false);
+ std::string str = V8Utils::GetStringParameter( 0, found, isolate, args );
+
+ if( found )
+ {
+ builder.CreateRenderTask( str );
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "render task name");
+ }
+}
+
+void BuilderApi::GetShaderEffect( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Dali::Toolkit::Builder builder = GetBuilder( isolate, args );
+
+ bool found(false);
+ std::string str = V8Utils::GetStringParameter( 0, found, isolate, args );
+ if( found )
+ {
+ ShaderEffect handle = builder.GetShaderEffect( str );
+ v8::Local<v8::Object> shader = ShaderEffectWrapper::WrapShaderEffect(isolate, handle);
+ args.GetReturnValue().Set( shader );
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing shader name");
+ }
+}
+
+void BuilderApi::GetFrameBufferImage( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Dali::Toolkit::Builder builder = GetBuilder( isolate, args );
+
+ bool found(false);
+ std::string str = V8Utils::GetStringParameter( 0, found, isolate, args );
+ if( found )
+ {
+ // wrap the image
+ // @TODO Test this, may need to implement a Framebuffer image wrapper.?
+ v8::Local<v8::Object> localObject = ImageWrapper::WrapImage( isolate, builder.GetFrameBufferImage(str) );
+ args.GetReturnValue().Set( localObject );
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "frame buffer name");
+ }
+
+}
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_BUILDER_API_H__
+#define __DALI_V8PLUGIN_BUILDER_API_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali-toolkit/public-api/builder/builder.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace BuilderApi
+{
+ /**
+ * Constructor
+ */
+ Dali::Toolkit::Builder New( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ /**
+ * Builder API see animation.h for a description
+ */
+ void SetDuration( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void LoadFromString( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void LoadFromFile( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void AddConstants( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetConstants( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void CreateAnimation( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ void Create( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void ApplyStyle( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void ApplyFromJson(const v8::FunctionCallbackInfo< v8::Value >& args);
+ void AddActors( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void CreateRenderTask( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetShaderEffect( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetFrameBufferImage( const v8::FunctionCallbackInfo< v8::Value >& args );
+}; // namespace BuilderApi
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header __DALI_V8PLUGIN_BUILDER_API_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "builder-wrapper.h"
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <dali-wrapper.h>
+#include <toolkit/builder/builder-api.h>
+#include <shared/api-function.h>
+#include <shared/object-template-helper.h>
+
+namespace Dali
+{
+namespace V8Plugin
+{
+namespace
+{
+
+/**
+ * Contains a list of all functions that can be called
+ */
+const ApiFunction BuilderFunctionTable[]=
+{
+ /**************************************
+ * Builder API (in order of builder.h)
+ **************************************/
+
+ { "LoadFromString" , BuilderApi::LoadFromString },
+ { "LoadFromFile" , BuilderApi::LoadFromFile },
+ { "AddConstants" , BuilderApi::AddConstants },
+ { "GetConstants" , BuilderApi::GetConstants },
+ { "CreateAnimation" , BuilderApi::CreateAnimation },
+ { "Create" , BuilderApi::Create },
+ { "ApplyStyle" , BuilderApi::ApplyStyle },
+ { "ApplyFromJson" , BuilderApi::ApplyFromJson },
+ { "AddActors" , BuilderApi::AddActors },
+ { "CreateRenderTask" , BuilderApi::CreateRenderTask },
+ { "GetShaderEffect" , BuilderApi::GetShaderEffect },
+ { "GetFrameBufferImage" , BuilderApi::GetFrameBufferImage }
+};
+
+const unsigned int BuilderFunctionTableCount = sizeof(BuilderFunctionTable)/sizeof(BuilderFunctionTable[0]);
+} //un-named space
+
+
+BuilderWrapper::BuilderWrapper( const Dali::Toolkit::Builder& builder, GarbageCollectorInterface& gc )
+: BaseWrappedObject( BaseWrappedObject::BUILDER , gc )
+{
+ mBuilder = builder;
+}
+
+BuilderWrapper::~BuilderWrapper()
+{
+
+}
+
+v8::Handle<v8::Object> BuilderWrapper::WrapBuilder(v8::Isolate* isolate, const Dali::Toolkit::Builder& builder )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::ObjectTemplate> objectTemplate;
+
+ objectTemplate = GetBuilderTemplate( isolate);
+
+ // create an instance of the template
+ v8::Local<v8::Object> localObject = objectTemplate->NewInstance();
+
+ // create the Builder wrapper
+ BuilderWrapper* pointer = new BuilderWrapper( builder, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() );
+
+ // assign the JavaScript object to the wrapper.
+ pointer->SetJavascriptObject( isolate, localObject );
+
+ return handleScope.Escape( localObject );
+}
+
+v8::Local<v8::ObjectTemplate> BuilderWrapper::GetBuilderTemplate( v8::Isolate* isolate)
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::ObjectTemplate> objectTemplate;
+
+ v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
+
+ objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT );
+
+ // add our function properties
+ ObjectTemplateHelper::InstallFunctions( isolate, objTemplate, BuilderFunctionTable, BuilderFunctionTableCount );
+
+ return handleScope.Escape( objTemplate );
+
+}
+
+void BuilderWrapper::NewBuilder( const v8::FunctionCallbackInfo< v8::Value >& args)
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate);
+
+ if( !args.IsConstructCall() )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Builder constructor called without 'new'" );
+ return;
+ }
+
+ Dali::Toolkit::Builder builder = BuilderApi::New( args );
+ v8::Local<v8::Object> localObject = WrapBuilder( isolate, builder );
+ args.GetReturnValue().Set( localObject );
+}
+
+
+Dali::Toolkit::Builder BuilderWrapper::GetBuilder()
+{
+ return mBuilder;
+}
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_BUILDER_WRAPPER_H__
+#define __DALI_V8PLUGIN_BUILDER_WRAPPER_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali-toolkit/public-api/builder/builder.h>
+
+// INTERNAL INCLUDES
+#include <shared/base-wrapped-object.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+/**
+ * Builder wrapper.
+ * Provides access to Builder specific functionality
+ */
+class BuilderWrapper : public BaseWrappedObject
+{
+
+public:
+
+ BuilderWrapper( const Dali::Toolkit::Builder& builder,
+ GarbageCollectorInterface& gc );
+
+ virtual ~BuilderWrapper();
+
+ /**
+ * @brief Creates a new Builder wrapped inside a Javascript Object.
+ * @param[in] args v8 function call arguments interpreted
+ */
+ static void NewBuilder( const v8::FunctionCallbackInfo< v8::Value >& args);
+
+ /**
+ * Wraps a builder
+ */
+ static v8::Handle<v8::Object> WrapBuilder(v8::Isolate* isolate, const Dali::Toolkit::Builder& );
+
+
+ Dali::Toolkit::Builder GetBuilder();
+
+
+private:
+
+ static v8::Local<v8::ObjectTemplate> GetBuilderTemplate( v8::Isolate* isolate );
+ Dali::Toolkit::Builder mBuilder;
+};
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // __DALI_V8PLUGIN_BUILDER_WRAPPER_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "keyboard-focus-manager-api.h"
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <dali/integration-api/debug.h>
+#include <dali-toolkit/dali-toolkit.h>
+#include <actors/actor-wrapper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace // un named namespace
+{
+
+
+Toolkit::Control::KeyboardFocusNavigationDirection GetDirection( std::string name, v8::Isolate* isolate )
+{
+ if( name == "left")
+ {
+ return Dali::Toolkit::Control::Left;
+ }
+ if( name == "right")
+ {
+ return Dali::Toolkit::Control::Right;
+ }
+ if( name == "up")
+ {
+ return Dali::Toolkit::Control::Up;
+ }
+ if( name == "down")
+ {
+ return Dali::Toolkit::Control::Down;
+ }
+
+ DALI_SCRIPT_EXCEPTION( isolate, "direction not found ( wanted left,right,up,down)" );
+
+
+ return Dali::Toolkit::Control::Up;
+
+}
+}; //un-named namespace
+
+/**
+ * Move the keyboard focus to the given actor.
+ * Only one actor can be focused at the same time. The actor must
+ * be in the stage already and be keyboard focusable.
+ *
+ * @method setCurrentFocusActor
+ * @for KeyboardFocusManager
+ * @param {Object} Actor
+ */
+void KeyboardFocusManagerApi::SetCurrentFocusActor( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ bool found( false );
+ Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
+ if( ! found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "no actor found" );
+ return;
+ }
+
+ Toolkit::KeyboardFocusManager::Get().SetCurrentFocusActor( actor );
+}
+
+/**
+ * Get the current focused actor.
+ *
+ * @method getCurrentFocusActor
+ * @for KeyboardFocusManager
+ * @return {Object} Actor
+ */
+void KeyboardFocusManagerApi::GetCurrentFocusActor( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ v8::Handle < v8::Object > wrappedActor = ActorWrapper::WrapActor( isolate, Toolkit::KeyboardFocusManager::Get().GetCurrentFocusActor() );
+ args.GetReturnValue().Set( wrappedActor );
+}
+
+/**
+ * Move the focus to the next focusable actor in the focus
+ * chain in the given direction (according to the focus traversal
+ * order).
+ *
+ * @method moveFocus
+ * @for KeyboardFocusManager
+ * @param {String} direction The direction of focus movement ( left, right, up, down)
+ */
+void KeyboardFocusManagerApi::MoveFocus( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ bool found(false);
+ std::string direction = V8Utils::GetStringParameter( PARAMETER_0, found,isolate, args);
+
+ if( ! found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "no direction found" );
+ return;
+ }
+
+ Toolkit::Control::KeyboardFocusNavigationDirection dir = GetDirection( direction, isolate );
+
+ Toolkit::KeyboardFocusManager::Get().MoveFocus( dir );
+}
+/**
+ * Clear the focus from the current focused actor if any, so
+ * that no actor is focused in the focus chain.
+ * It will emit focus changed signal without current focused actor
+ * @method clearFocus
+ * @for KeyboardFocusManager
+ */
+void KeyboardFocusManagerApi::ClearFocus( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ Toolkit::KeyboardFocusManager::Get().ClearFocus();
+}
+
+/**
+ * Set whether an actor is a focus group that can limit the
+ * scope of focus movement to its child actors in the focus chain.
+ *
+ * @method setAsFocusGroup
+ * @param {Boolean} enabled Whether the focus movement should be looped
+ * @for KeyboardFocusManager
+ */
+void KeyboardFocusManagerApi::SetAsFocusGroup( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ // void SetAsFocusGroup(Actor actor, bool isFocusGroup);
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ bool found( false );
+
+ Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
+
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing actor param" );
+ return;
+ }
+
+ bool isFocusGroup = V8Utils::GetBooleanParameter( PARAMETER_1, found,isolate, args);
+ if( ! found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "boolean param missing" );
+ return;
+ }
+
+ Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup( actor,isFocusGroup );
+
+}
+/**
+ * Check whether the actor is set as a focus group or not.
+ * @method isFocusGroup
+ * @param {Object} Actor The actor to be checked.
+ * @for KeyboardFocusManager
+ */
+void KeyboardFocusManagerApi::IsFocusGroup( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ bool found( false );
+ Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
+
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Missing actor parameter");
+ return;
+ }
+ args.GetReturnValue().Set( v8::Boolean::New( isolate, Toolkit::KeyboardFocusManager::Get().IsFocusGroup(actor) ) );
+}
+
+/**
+ * Returns the closest ancestor of the given actor that is a focus group.
+ * @method getFocusGroup
+ * @param {Object} Actor The actor to be checked.
+ * @for KeyboardFocusManager
+ */
+void KeyboardFocusManagerApi::GetFocusGroup( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ bool found( false );
+
+ Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Missing actor parameter");
+ return;
+ }
+ Actor retActor = Toolkit::KeyboardFocusManager::Get().GetFocusGroup( actor );
+ v8::Handle < v8::Object > wrappedActor = ActorWrapper::WrapActor( isolate, retActor );
+ args.GetReturnValue().Set( wrappedActor );
+
+}
+
+/**
+ * Get whether the focus movement should be looped within the same focus group.
+ * @method setFocusGroupLoop
+ * @param {Object} Actor he actor to be set as a focus group.
+ * @param {Boolean} isFocusGroup Whether to set the actor as a focus group or not.
+ * @for KeyboardFocusManager
+ */
+void KeyboardFocusManagerApi::SetFocusGroupLoop( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ bool found(false);
+ bool enable = V8Utils::GetBooleanParameter( PARAMETER_0, found,isolate, args);
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "boolean param missing" );
+ return;
+ }
+ Toolkit::KeyboardFocusManager::Get().SetFocusGroupLoop( enable );
+}
+
+/**
+ * Get whether the focus movement should be looped within the same focus group.
+ * @method getFocusGroupLoop
+ * @return {Boolean} Whether the focus movement should be looped
+ * @for KeyboardFocusManager
+ */
+void KeyboardFocusManagerApi::GetFocusGroupLoop( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ args.GetReturnValue().Set( v8::Boolean::New( isolate, Toolkit::KeyboardFocusManager::Get().GetFocusGroupLoop()) );
+}
+
+/**
+ * Set the focus indicator actor.
+ *
+ * This will replace the default focus indicator actor in
+ * KeyboardFocusManager and will be added to the focused actor as a
+ * highlight.
+ * @method setFocusIndicatorActor
+ * @param {Object} Actor The indicator actor to be added
+ * @for KeyboardFocusManager
+ */
+void KeyboardFocusManagerApi::SetFocusIndicatorActor( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ bool found(false);
+
+ Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
+
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Missing actor parameter");
+ return;
+ }
+
+ // the actor may be an empty handle
+ Toolkit::KeyboardFocusManager::Get().SetFocusIndicatorActor( actor );
+}
+
+
+/**
+ * Get the focus indicator actor.
+ *
+ * @method getFocusIndicatorActor
+ * @param {Object} Actor The indicator actor to be added
+ * @for KeyboardFocusManager
+ */
+void KeyboardFocusManagerApi::GetFocusIndicatorActor( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ v8::Handle < v8::Object > wrappedActor = ActorWrapper::WrapActor( isolate, Toolkit::KeyboardFocusManager::Get().GetFocusIndicatorActor() );
+ args.GetReturnValue().Set( wrappedActor );
+
+}
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_KEYBOARD_FOCUS_MANAGER_API_H__
+#define __DALI_V8PLUGIN_KEYBOARD_FOCUS_MANAGER_API_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace KeyboardFocusManagerApi
+{
+ /**
+ * Constructor
+ */
+ Dali::Toolkit::KeyboardFocusManager New( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ /**
+ * KeyboardFocusManager API see keyboard-focus-manager.h for a description
+ */
+ void SetCurrentFocusActor( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetCurrentFocusActor( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void MoveFocus( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void ClearFocus( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ void SetAsFocusGroup( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void IsFocusGroup( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetFocusGroup( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ void SetFocusGroupLoop( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetFocusGroupLoop( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ void SetFocusIndicatorActor( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetFocusIndicatorActor( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+}; // namespace KeyboardFocusManagerApi
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header __DALI_V8PLUGIN_KEYBOARD_FOCUS_MANAGER_API_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "keyboard-focus-manager-wrapper.h"
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <dali-wrapper.h>
+#include <shared/api-function.h>
+#include <shared/object-template-helper.h>
+#include <toolkit/focus-manager/keyboard-focus-manager-api.h>
+
+namespace Dali
+{
+namespace V8Plugin
+{
+namespace
+{
+
+/**
+ * Contains a list of all functions that can be called
+ */
+const ApiFunction KeyboardFocusManagerFunctionTable[]=
+{
+ /**************************************
+ * KeyboardFocusManager API (in order of keyboard-focus-manager.h)
+ **************************************/
+
+ { "SetCurrentFocusActor" , KeyboardFocusManagerApi::SetCurrentFocusActor },
+ { "GetCurrentFocusActor" , KeyboardFocusManagerApi::GetCurrentFocusActor },
+ { "MoveFocus" , KeyboardFocusManagerApi::MoveFocus },
+ { "ClearFocus" , KeyboardFocusManagerApi::ClearFocus },
+ { "SetAsFocusGroup" , KeyboardFocusManagerApi::SetAsFocusGroup },
+ { "IsFocusGroup" , KeyboardFocusManagerApi::IsFocusGroup },
+ { "GetFocusGroup" , KeyboardFocusManagerApi::GetFocusGroup },
+ { "SetFocusGroupLoop" , KeyboardFocusManagerApi::SetFocusGroupLoop },
+ { "GetFocusGroupLoop" , KeyboardFocusManagerApi::GetFocusGroupLoop },
+ { "SetFocusIndicatorActor" , KeyboardFocusManagerApi::SetFocusIndicatorActor },
+ { "GetFocusIndicatorActor" , KeyboardFocusManagerApi::GetFocusIndicatorActor },
+};
+
+const unsigned int KeyboardFocusManagerFunctionTableCount = sizeof(KeyboardFocusManagerFunctionTable)/sizeof(KeyboardFocusManagerFunctionTable[0]);
+} //un-named space
+
+
+KeyboardFocusManagerWrapper::KeyboardFocusManagerWrapper( const Dali::Toolkit::KeyboardFocusManager& keyboardFocusManager, GarbageCollectorInterface& gc )
+: BaseWrappedObject( BaseWrappedObject::KEYBOARD_FOCUS_MANAGER , gc )
+{
+ mKeyboardFocusManager = keyboardFocusManager;
+}
+
+KeyboardFocusManagerWrapper::~KeyboardFocusManagerWrapper()
+{
+
+}
+
+v8::Handle<v8::Object> KeyboardFocusManagerWrapper::WrapKeyboardFocusManager(v8::Isolate* isolate, const Dali::Toolkit::KeyboardFocusManager& keyboardFocusManager )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::ObjectTemplate> objectTemplate;
+
+ objectTemplate = GetKeyboardFocusManagerTemplate( isolate);
+
+ // create an instance of the template
+ v8::Local<v8::Object> localObject = objectTemplate->NewInstance();
+
+ // create the KeyboardFocusManager wrapper
+ KeyboardFocusManagerWrapper* pointer = new KeyboardFocusManagerWrapper( keyboardFocusManager, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() );
+
+ // assign the JavaScript object to the wrapper.
+ pointer->SetJavascriptObject( isolate, localObject );
+
+ return handleScope.Escape( localObject );
+}
+
+v8::Local<v8::ObjectTemplate> KeyboardFocusManagerWrapper::GetKeyboardFocusManagerTemplate( v8::Isolate* isolate)
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::ObjectTemplate> objectTemplate;
+
+ v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
+
+ objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT );
+
+ // add intercepts for Signals, we can't use HandleWrapper::AddIntercepts because KeyboardFocusManager doesn't inherit
+ // from Handle ( just baseHandle)
+ ObjectTemplateHelper::AddSignalConnectAndDisconnect( isolate, objTemplate );
+
+ // add our function properties
+ ObjectTemplateHelper::InstallFunctions( isolate, objTemplate, KeyboardFocusManagerFunctionTable, KeyboardFocusManagerFunctionTableCount );
+
+ return handleScope.Escape( objTemplate );
+
+}
+
+
+std::string KeyboardFocusManagerWrapper::GetDirectionName( Toolkit::Control::KeyboardFocusNavigationDirection dir )
+{
+ switch( dir )
+ {
+ case Dali::Toolkit::Control::Left:
+ {
+ return "left";
+ break;
+ }
+ case Dali::Toolkit::Control::Right:
+ {
+ return "right";
+ break;
+ }
+ case Dali::Toolkit::Control::Up:
+ {
+ return "up";
+ break;
+ }
+ case Dali::Toolkit::Control::Down:
+ {
+ return "down";
+ break;
+ }
+ }
+ return "unknown direction";
+}
+
+
+Dali::Toolkit::KeyboardFocusManager KeyboardFocusManagerWrapper::GetKeyboardFocusManager()
+{
+ return mKeyboardFocusManager;
+}
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_KEYBOARD_FOCUS_MANAGER_WRAPPER_H__
+#define __DALI_V8PLUGIN_KEYBOARD_FOCUS_MANAGER_WRAPPER_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h>
+
+// INTERNAL INCLUDES
+#include <shared/base-wrapped-object.h>
+#include <signals/signal-manager.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+/**
+ * KeyboardFocusManager wrapper.
+ * Provides access to KeyboardFocusManager specific functionality
+ */
+class KeyboardFocusManagerWrapper : public BaseWrappedObject
+{
+
+public:
+
+ KeyboardFocusManagerWrapper( const Dali::Toolkit::KeyboardFocusManager& keyboardFocusManager,
+ GarbageCollectorInterface& gc );
+
+ virtual ~KeyboardFocusManagerWrapper();
+
+/*
+ *
+ * @brief Creates a new KeyboardFocusManager wrapped inside a Javascript Object.
+ * @param[in] args v8 function call arguments interpreted
+
+ static void NewKeyboardFocusManager( const v8::FunctionCallbackInfo< v8::Value >& args);
+*/
+
+ /**
+ * Wraps a keyboardFocusManager
+ */
+ static v8::Handle<v8::Object> WrapKeyboardFocusManager(v8::Isolate* isolate, const Dali::Toolkit::KeyboardFocusManager& );
+
+
+ Dali::Toolkit::KeyboardFocusManager GetKeyboardFocusManager();
+
+
+ virtual SignalManager* GetSignalManager() { return &mSignalManager;}
+
+ static std::string GetDirectionName( Toolkit::Control::KeyboardFocusNavigationDirection dir );
+
+private:
+
+
+ static v8::Local<v8::ObjectTemplate> GetKeyboardFocusManagerTemplate( v8::Isolate* isolate );
+ Dali::Toolkit::KeyboardFocusManager mKeyboardFocusManager;
+ SignalManager mSignalManager;
+};
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // __DALI_V8PLUGIN_KEYBOARD_FOCUS_MANAGER_WRAPPER_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// HEADER
+#include "v8-utils.h"
+
+// EXTERNAL INCLUDES
+#include <iostream>
+#include <fstream>
+#include <sstream>
+#include <dali/integration-api/debug.h>
+
+// INTERNAL INCLUDES
+#include <object/property-value-wrapper.h>
+#include <actors/actor-wrapper.h>
+#include <object/handle-wrapper.h>
+#include <image/image-wrapper.h>
+#include <render-tasks/render-task-wrapper.h>
+#include <object/property-value-wrapper.h>
+
+
+/**
+ * Similar to DALI_LOG_ERROR except the PRETTY_FUNCTION
+ * is removed because it makes no sense for scripting errors.
+ */
+#define DALI_LOG_SCRIPT_ERROR(format, args...) Dali::Integration::Log::LogMessage(Dali::Integration::Log::DebugError, format, ## args)
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace V8Utils
+{
+
+void Log(const v8::FunctionCallbackInfo< v8::Value >& args)
+{
+ v8::HandleScope handleScope( args.GetIsolate());
+
+ bool first = true;
+ for (int i = 0; i < args.Length(); i++)
+ {
+ if (first)
+ {
+ first = false;
+ }
+ else
+ {
+ std::cout << " ";
+ }
+ v8::String::Utf8Value utf8_value( args[i] );
+ std::cout << *utf8_value;
+ }
+}
+
+void LogError(const v8::FunctionCallbackInfo< v8::Value >& args)
+{
+ v8::HandleScope handleScope( args.GetIsolate());
+ std::string output;
+ bool first = true;
+ for (int i = 0; i < args.Length(); i++)
+ {
+ if (first)
+ {
+ first = false;
+ }
+ else
+ {
+ output +=" ";
+ }
+ v8::String::Utf8Value utf8_value( args[i] );
+ output += *utf8_value;
+ }
+ DALI_LOG_ERROR_NOFN( "JavaScript: %s",output.c_str() );
+}
+
+void GetFileContents(const std::string &fileName, std::string& contents)
+{
+ std::ifstream t(fileName.c_str());
+ contents = std::string((std::istreambuf_iterator<char>(t)), std::istreambuf_iterator<char>());
+};
+
+void GetFileDirectory( const std::string& fileName, std::string& directory )
+{
+ directory = "";
+
+ // get the position of the last slash
+ size_t pos = fileName.find_last_of("\\/");
+
+ // if it doesn't exist, return nothing
+ if( (std::string::npos == pos ) )
+ {
+ return;
+ }
+ else
+ {
+ // check an edge case where the string ends in a forward slash "mydir/"
+ if( (pos+1) < fileName.length() )
+ {
+ directory = fileName.substr(0, pos+1);
+ return;
+ }
+ }
+}
+
+void GetFileName( const std::string& fullPathName, std::string& fileName )
+{
+ // look for last slash
+ size_t pos = fullPathName.find_last_of("\\/");
+
+ if( std::string::npos == pos )
+ {
+ fileName = fullPathName;
+ }
+ else
+ {
+ fileName = fullPathName.substr(pos,fileName.length());
+ }
+}
+
+void GetModuleName( const std::string& fileName, std::string& moduleName )
+{
+ std::string fileNameNoPath;
+ GetFileName( fileName , fileNameNoPath );
+ size_t pos = fileNameNoPath.find_last_of(".");
+ if( std::string::npos == pos )
+ {
+ moduleName = fileNameNoPath;
+ }
+ else
+ {
+ moduleName = fileName.substr(0, pos );
+ }
+}
+
+void ReportException( v8::Isolate* isolate, v8::TryCatch* tryCatch)
+{
+ v8::HandleScope handleScope( isolate );
+
+ v8::String::Utf8Value exception(tryCatch->Exception());
+ v8::Handle<v8::Message> message = tryCatch->Message();
+
+ if (message.IsEmpty())
+ {
+ // V8 didn't provide any extra information about this error; just
+ // print the exception.
+ DALI_LOG_SCRIPT_ERROR("%s\n", *exception);
+ }
+ else
+ {
+
+ // Print (filename):(line number): (message).
+ v8::String::Utf8Value filename(message->GetScriptResourceName());
+
+ DALI_LOG_SCRIPT_ERROR("\n\n====== Error found in JavaScript: ========= \n");
+
+
+ int linenum = message->GetLineNumber();
+ DALI_LOG_SCRIPT_ERROR("File: %s\n", *filename, linenum, *exception);
+
+ DALI_LOG_SCRIPT_ERROR("Error: :%s\n", *exception );
+ DALI_LOG_SCRIPT_ERROR("Line: :%i\n", linenum );
+
+ // Print line of source code.
+ v8::String::Utf8Value sourceline(message->GetSourceLine());
+
+ DALI_LOG_SCRIPT_ERROR("Source: %s\n", *sourceline);
+
+ // Print wavy underline (GetUnderline is deprecated).
+
+ std::stringstream msg;
+
+ int start = message->GetStartColumn();
+ for (int i = 0; i < start; i++)
+ {
+ msg << " ";
+ }
+ int end = message->GetEndColumn();
+ for (int i = start; i < end; i++)
+ {
+ msg << "↑";
+ }
+
+ DALI_LOG_SCRIPT_ERROR(" %s\n", msg.str().c_str());
+
+ v8::String::Utf8Value stack_trace(tryCatch->StackTrace());
+ if (stack_trace.length() > 0)
+ {
+ DALI_LOG_SCRIPT_ERROR("%s\n", *stack_trace);
+ }
+ DALI_LOG_SCRIPT_ERROR("\n=========================================== \n");
+
+ }
+}
+
+std::string GetJavaScriptFunctionName( const char* functionName )
+{
+ // @todo if we are 100% decided on lower case, go through
+ // every api and manually change the function names to lower case first character
+ std::string name( functionName );
+ name[0]=tolower( functionName[0] );
+ return name;
+}
+
+void Version(const v8::FunctionCallbackInfo< v8::Value >& args)
+{
+ v8::HandleScope handleScope( args.GetIsolate());
+
+ v8::Handle<v8::String> ver = v8::String::NewFromUtf8(args.GetIsolate(), v8::V8::GetVersion());
+
+ args.GetReturnValue().Set(ver);
+}
+
+
+std::string v8StringToStdString( const v8::Handle<v8::Value>& value )
+{
+ v8::String::Utf8Value utf8(value);
+ return std::string(*utf8);
+}
+
+
+std::string PropertyNameToJavaScriptName(const std::string& hyphenatedName)
+{
+ std::string ret;
+
+ ret.reserve(hyphenatedName.size());
+
+ bool capitlizeNext = false ;
+ for(unsigned int i = 0; i < hyphenatedName.size(); ++i)
+ {
+ char c = hyphenatedName[i];
+ if(c == '-')
+ {
+ capitlizeNext = true;
+ }
+ else
+ {
+ if(capitlizeNext)
+ {
+ ret.push_back(std::toupper(c));
+ capitlizeNext = false;
+ }
+ else
+ {
+ ret.push_back(c);
+ }
+ }
+ }
+
+ return ret;
+}
+
+
+
+std::string JavaScriptNameToPropertyName(const std::string& camelCase)
+{
+ std::string ret;
+
+ int countUpper = 0;
+ for(unsigned int i = 0; i < camelCase.size(); ++i)
+ {
+ if(std::isupper(camelCase[i]))
+ {
+ countUpper++;
+ }
+ }
+
+ if(countUpper)
+ {
+ ret.reserve(camelCase.size() + countUpper);
+
+ for(unsigned int i = 0; i < camelCase.size(); ++i)
+ {
+ char c = camelCase[i];
+ if(std::isupper(c))
+ {
+ ret.push_back('-');
+ }
+
+ ret.push_back(std::tolower(c));
+ }
+ }
+ else
+ {
+ return camelCase ;
+ }
+
+ return ret;
+}
+
+void ScriptError( const char* function, v8::Isolate* isolate, std::string errorString )
+{
+ v8::EscapableHandleScope scope( isolate);
+ std::string errorMsg = std::string(function) + std::string("(), ") + errorString;
+
+ // log out to DALI_LOG_ERROR first, so we know something has gone wrong
+ DALI_LOG_ERROR("%s \n", errorMsg.c_str() );
+
+ // throw a V8 exception, DALi will keep running but we will get a print out
+ // of where the error occured in the JavaScript source
+ isolate->ThrowException( v8::String::NewFromUtf8( isolate, errorMsg.c_str()) );
+}
+
+bool IsBooleanPrimitiveOrObject( const v8::Local<v8::Value>& value )
+{
+ return ( value->IsBoolean() || value->IsBooleanObject());
+}
+
+bool GetBooleanValue( v8::Isolate* isolate, const v8::Local<v8::Value>& value )
+{
+ v8::EscapableHandleScope scope( isolate); // may not be required.
+
+ if( value->IsBoolean() )
+ {
+ return value->ToBoolean()->Value();
+ }
+ else if (value->IsBooleanObject() )
+ {
+ const v8::Local<v8::BooleanObject> object = v8::Local<v8::BooleanObject>::Cast(value);
+ return object->ValueOf();
+ }
+ DALI_SCRIPT_EXCEPTION(isolate, "no bool found");
+ return false;
+}
+
+bool IsNumberPrimitiveOrObject( const v8::Local<v8::Value>& value )
+{
+ return ( value->IsNumber() || value->IsNumberObject());
+}
+
+float GetNumberValue( v8::Isolate* isolate, const v8::Local<v8::Value>& value )
+{
+ v8::EscapableHandleScope scope( isolate); // may not be required.
+
+ if( value->IsNumber() )
+ {
+ return value->ToNumber()->Value();
+ }
+ else if (value->IsNumberObject() )
+ {
+ const v8::Local<v8::NumberObject> object = v8::Local<v8::NumberObject>::Cast(value);
+ return object->ValueOf();
+ }
+
+ DALI_SCRIPT_EXCEPTION(isolate, "no number found?");
+ return 0.f;
+}
+
+bool IsStringPrimitiveOrObject( const v8::Local<v8::Value>& value )
+{
+ return ( value->IsString() || value->IsStringObject());
+}
+
+std::string GetStringValue( v8::Isolate* isolate, const v8::Local<v8::Value>& value )
+{
+ v8::EscapableHandleScope scope( isolate); // may not be required.
+
+ if( value->IsString() )
+ {
+ return V8Utils::v8StringToStdString(value);
+ }
+ else if (value->IsStringObject() )
+ {
+ const v8::Local<v8::StringObject> object = v8::Local<v8::StringObject>::Cast(value);
+ return V8Utils::v8StringToStdString( object->ValueOf() );
+ }
+
+ DALI_SCRIPT_EXCEPTION(isolate, "no string found?");
+ return "";
+}
+
+
+Property::Value GetPropertyValueFromObject( bool& found, v8::Isolate* isolate, const v8::Local<v8::Value >& value )
+{
+ v8::HandleScope handleScope( isolate);
+
+ Property::Value daliPropertyValue;// creates a property with Property::INVALID
+
+ found = false;
+
+ if( value->IsObject() )
+ {
+ v8::Local<v8::Object> object = v8::Handle<v8::Object>::Cast( value );
+
+ if( BaseWrappedObject::IsWrappedTypeAPropertyValue( object ) )
+ {
+ found = true;
+ PropertyValueWrapper* propertyWrapper = PropertyValueWrapper::Unwrap( isolate, object );
+ return propertyWrapper->GetValue();
+ }
+ else if( value->IsArray() )
+ {
+ found = true;
+ return PropertyValueWrapper::VectorOrMatrixFromV8Array( isolate, object);//todo check for V8 array / map?
+ }
+ }
+ else if( value->IsBoolean() )
+ {
+ found = true;
+ v8::Local<v8::Boolean> v = value->ToBoolean();
+ return Dali::Property::Value(v->Value());
+ }
+ else if( value->IsNumber() )
+ {
+ found = true;
+ v8::Local<v8::Number> v = value->ToNumber();
+ return Dali::Property::Value(static_cast<float>(v->Value()));
+ }
+ else if( value->IsInt32() )
+ {
+ found = true;
+ v8::Local<v8::Int32> v = value->ToInt32();
+ return Dali::Property::Value(static_cast<int>(v->Value()));
+ }
+ else if ( value->IsUint32() )
+ {
+ found = true;
+ v8::Local<v8::Uint32> v = value->ToUint32();
+ return Dali::Property::Value(static_cast<unsigned int>(v->Value()));
+ }
+ return daliPropertyValue;
+
+}
+
+Property::Map GetPropertyMapFromObject( v8::Isolate* isolate, const v8::Local<v8::Object>& object)
+{
+ v8::Local<v8::Array> properties = object->GetPropertyNames();
+ Property::Map propertyMap; // empty map
+
+ for( unsigned int i = 0; i < properties->Length(); ++i)
+ {
+ // Get the key
+ v8::Local<v8::Value> key = properties->Get( i );
+ std::string keyString = v8StringToStdString( key );
+
+ // Get the value
+ v8::Local<v8::Value> value = object->Get( key );
+ std::string valueString = V8Utils::v8StringToStdString( value );
+
+ propertyMap[ keyString ] = valueString.c_str();
+
+ }
+ return propertyMap;
+}
+
+Actor GetActorFromObject( v8::Isolate* isolate, bool& found, v8::Local<v8::Object>& object)
+{
+ v8::HandleScope handleScope( isolate);
+ found = false;
+
+ if( BaseWrappedObject::IsWrappedType ( isolate, object, BaseWrappedObject::ACTOR ))
+ {
+ HandleWrapper* handleWrapper = HandleWrapper::Unwrap( isolate, object );
+ return Actor::DownCast( handleWrapper->mHandle );
+ }
+ return Actor();
+}
+
+
+int GetIntegerParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args, int defaultValue )
+{
+ found = false;
+ unsigned int length = args.Length();
+ if( index >= length )
+ {
+ return defaultValue;
+ }
+ if( args[ index ]->IsInt32() )
+ {
+ found = true;
+ return args[ index ]->Int32Value();
+ }
+ {
+ return defaultValue;
+ }
+}
+
+float GetFloatParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args, float defaultValue )
+{
+ found = false;
+ unsigned int length = args.Length();
+ if( index >= length )
+ {
+ return defaultValue;
+ }
+ if( args[ index ]->IsNumber() )
+ {
+ found = true;
+ return args[ index ]->NumberValue();
+ }
+ {
+ return defaultValue;
+ }
+}
+
+std::string GetStringParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ found = false;
+ unsigned int length = args.Length();
+
+ if( index >= length )
+ {
+ return std::string();
+ }
+ if( args[ index ]->IsString() )
+ {
+ found = true;
+ return v8StringToStdString( args[ index ]);
+ }
+ else
+ {
+ return std::string();
+ }
+}
+
+bool GetBooleanParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::HandleScope handleScope( isolate);
+
+ found = false;
+ unsigned int length = args.Length();
+ if( index >= length )
+ {
+ return false;
+ }
+ if( args[ index ]->IsBoolean() )
+ {
+ found = true;
+ v8::Local<v8::Boolean> v = args[ index ]->ToBoolean();
+ return v->Value();
+ }
+ else
+ {
+ return false;
+ }
+}
+
+Handle GetHandleParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::HandleScope handleScope( isolate);
+
+ found = false;
+ unsigned int length = args.Length();
+ if( index >= length )
+ {
+ return Handle();
+ }
+
+ if( args[ index ]->IsObject() )
+ {
+ v8::Local<v8::Object> object = args[ index ]->ToObject();
+ v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField(0) );
+ void* ptr = field->Value();
+ if( ptr )
+ {
+ found = true;
+ HandleWrapper* wrapper = static_cast< HandleWrapper *>(ptr);
+ return wrapper->GetHandle();
+ }
+ }
+ return Handle();
+}
+
+Vector2 GetVector2Parameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::HandleScope handleScope( isolate);
+ unsigned int length = args.Length();
+ Vector2 ret;
+ found = false;
+
+ if( index < length )
+ {
+ if( args[ index ]->IsObject() )
+ {
+ Dali::Property::Value value;
+ value = PropertyValueWrapper::ExtractPropertyValue( isolate, args[index], Dali::Property::VECTOR2 );
+ if( value.GetType() == Dali::Property::VECTOR2)
+ {
+ found = true;
+ value.Get(ret);
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION(isolate, "Missing Vector2 parameter");
+ }
+ }
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION(isolate, "Missing Vector2 parameter");
+ }
+
+ return ret;
+}
+
+Vector2 GetVector2ParameterFrom2Float( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ Vector2 ret(0.0f,0.0f);
+ bool bFound(false);
+ unsigned int argCount( args.Length() );
+
+ if( index+2 >= argCount )
+ {
+ DALI_SCRIPT_EXCEPTION(isolate, "Missing parameter");
+ }
+
+ found = true;
+ ret.x = V8Utils::GetFloatParameter( index, bFound, isolate, args, 0.0f );
+ found = found && bFound;
+ ret.y = V8Utils::GetFloatParameter( index+1, bFound, isolate, args, 0.0f );
+ found = found && bFound;
+
+ return ret;
+}
+
+Vector3 GetVector3Parameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args)
+{
+ v8::HandleScope handleScope( isolate);
+ unsigned int argCount( args.Length() );
+ Vector3 ret;
+ found = false;
+ if( index < argCount )
+ {
+ if( args[ index ]->IsObject() )
+ {
+ Dali::Property::Value value;
+ value = PropertyValueWrapper::ExtractPropertyValue( isolate, args[index], Dali::Property::VECTOR3 );
+ if( value.GetType() == Dali::Property::VECTOR3)
+ {
+ found = true;
+ value.Get(ret);
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION(isolate, "Missing Vector3 parameter");
+ }
+ }
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION(isolate, "Missing Vector3 parameter");
+
+ }
+
+ return ret;
+}
+
+Vector4 GetVector4Parameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args)
+{
+ v8::HandleScope handleScope( isolate);
+ unsigned int argCount( args.Length() );
+ Vector4 ret;
+ found = false;
+
+ if( index < argCount )
+ {
+ if( args[ index ]->IsObject() )
+ {
+ Dali::Property::Value value;
+ value = PropertyValueWrapper::ExtractPropertyValue( isolate, args[index], Dali::Property::VECTOR4 );
+ if( value.GetType() == Dali::Property::VECTOR4)
+ {
+ found = true;
+ value.Get(ret);
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION(isolate, "Missing Vector4 parameter");
+ }
+ }
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION(isolate, "Missing Vector4 parameter");
+ }
+
+ return ret;
+}
+
+
+Rect<int> GetRectIntParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::HandleScope handleScope( isolate);
+
+ found = false;
+ int length = args.Length() - index;
+
+ // if it's an array read the 2 numbers into a vector2
+ if( length == 4 )
+ {
+ if( args[ 0 + index ]->IsInt32() &&
+ args[ 1 + index ]->IsInt32() &&
+ args[ 2 + index ]->IsInt32() &&
+ args[ 3 + index ]->IsInt32() )
+ {
+ found = true;
+ Rect<int> rect( args[ 0 + index ]->Int32Value(),
+ args[ 1 + index ]->Int32Value(),
+ args[ 2 + index ]->Int32Value(),
+ args[ 3 + index ]->Int32Value() );
+ return rect;
+ }
+ }
+ // this will extract a Vector4, if it is a Vector4 or a Javascript array object
+ if( args[ index ]->IsObject() )
+ {
+ Dali::Property::Value value;
+ value = PropertyValueWrapper::ExtractPropertyValue( isolate, args[index], Dali::Property::RECTANGLE );
+ if( value.GetType() == Dali::Property::RECTANGLE)
+ {
+ found = true;
+ Rect<int> rect;
+ value.Get(rect);
+ return rect;
+ }
+
+ // @todo support vector4 as well?
+ }
+ return Rect<int>();
+}
+
+Actor GetActorParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ BaseWrappedObject* wrapper = GetWrappedDaliObjectParameter( index, BaseWrappedObject::ACTOR, isolate, args);
+ ActorWrapper* actorWrapper = static_cast< ActorWrapper*>( wrapper );
+ if( actorWrapper )
+ {
+ found = true;
+ return actorWrapper->GetActor();
+ }
+ else
+ {
+ return Actor();
+ }
+}
+
+Layer GetLayerParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ Actor actor = GetActorParameter( index, found, isolate, args );
+ return Layer::DownCast( actor );
+}
+
+Image GetImageParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ BaseWrappedObject* wrappedObject = V8Utils::GetWrappedDaliObjectParameter( index, BaseWrappedObject::IMAGE, isolate, args );
+ if( wrappedObject )
+ {
+ found = true;
+ ImageWrapper* wrapper = static_cast< ImageWrapper *>(wrappedObject);
+ return wrapper->GetImage();
+ }
+ else
+ {
+ return Image();
+ }
+
+}
+RenderTask GetRenderTaskParameter( unsigned int paramIndex, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ found = false;
+ BaseWrappedObject* wrappedObject = V8Utils::GetWrappedDaliObjectParameter( paramIndex, BaseWrappedObject::RENDER_TASK, isolate, args );
+ if( wrappedObject )
+ {
+ found = true;
+ RenderTaskWrapper* wrapper = static_cast< RenderTaskWrapper *>(wrappedObject);
+ return wrapper->GetRenderTask();
+ }
+ else
+ {
+ return RenderTask(); // empty handle
+ }
+}
+
+
+BaseWrappedObject* GetWrappedDaliObjectParameter( unsigned int index, BaseWrappedObject::Type type, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::HandleScope handleScope( isolate);
+ unsigned int length = args.Length();
+
+ if( index >= length )
+ {
+ return NULL;
+ }
+
+ if( !args[ index ]->IsObject() )
+ {
+ return NULL;
+ }
+
+ v8::Local<v8::Object> object = args[ index ]->ToObject();
+
+ if( BaseWrappedObject::IsWrappedType ( isolate, object, type ))
+ {
+ v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField(0) );
+ void* ptr = field->Value();
+ BaseWrappedObject* wrapper = static_cast< BaseWrappedObject *>(ptr);
+ return wrapper;
+ }
+ return NULL;
+}
+
+
+Property::Value GetPropertyValueParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::HandleScope handleScope( isolate);
+
+ Property::Value daliPropertyValue;// creates a property with Property::INVALID
+
+ found = false;
+ unsigned int length = args.Length();
+
+ if( index >= length )
+ {
+ return daliPropertyValue;
+ }
+ v8::Local<v8::Value > value = args[ index ];
+
+ return GetPropertyValueFromObject( found, isolate, value);
+}
+
+Property::Map GetPropertyMapParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::HandleScope handleScope( isolate);
+
+ Property::Map propertyMap; // empty map
+
+ found = false;
+ unsigned int length = args.Length();
+
+ if( index >= length )
+ {
+ return propertyMap;
+ }
+
+ if( !args[ index ]->IsObject() )
+ {
+ return propertyMap;
+ }
+ found = true;
+
+ // go through each key value pair
+ v8::Local<v8::Object> obj = args[ index ]->ToObject();
+
+ return GetPropertyMapFromObject( isolate, obj );
+
+}
+
+void CreatePropertyMap( v8::Isolate* isolate, const Property::Map& map, v8::Local<v8::Object>& object )
+{
+ v8::HandleScope handleScope( isolate);
+
+ // we're converting a dali property map in to a JavaScript property map
+ if( map.Count() == 0 )
+ {
+ return;
+ }
+
+ for( unsigned int index = 0; index < map.Count() - 1; ++index )
+ {
+ const std::string& key = map.GetKey( index );
+ Property::Value& value = map.GetValue( index );
+ v8::Local<v8::Value> v8Value;
+
+ switch( value.GetType() )
+ {
+ case Dali::Property::FLOAT:
+ {
+ v8Value = v8::Number::New( isolate, value.Get<float>() );
+ break;
+ }
+ case Dali::Property::BOOLEAN:
+ {
+ v8Value = v8::Boolean::New( isolate, value.Get<bool>());
+ break;
+ }
+ case Dali::Property::INTEGER:
+ {
+ v8Value = v8::Integer::New( isolate, value.Get<int>());
+ break;
+ }
+ case Dali::Property::UNSIGNED_INTEGER:
+ {
+ v8Value = v8::Integer::New( isolate, value.Get<unsigned int>());
+ break;
+ }
+ case Dali::Property::STRING:
+ {
+ std::string string = value.Get< std::string >();
+ v8Value = v8::String::NewFromUtf8( isolate, string.c_str());
+ break;
+ }
+ case Dali::Property::VECTOR2:
+ {
+ // create a vector2
+ Vector2 vec = value.Get<Vector2>();
+ v8::Local<v8::Array> array= v8::Array::New( isolate, 2 );
+ array->Set( 0 , v8::Number::New(isolate, vec.x));
+ array->Set( 1 , v8::Number::New(isolate, vec.y));
+ v8Value = array;
+ break;
+ }
+ case Dali::Property::VECTOR3:
+ {
+ // create a vector 3
+ Vector3 vec = value.Get<Vector3>();
+ v8::Local<v8::Array> array= v8::Array::New( isolate, 3 );
+ array->Set( 0 , v8::Number::New(isolate, vec.x));
+ array->Set( 1 , v8::Number::New(isolate, vec.y));
+ array->Set( 2 , v8::Number::New(isolate, vec.z));
+ v8Value = array;
+ break;
+ }
+ case Dali::Property::VECTOR4:
+ {
+ // create a vector 4
+ Vector4 vec = value.Get<Vector4>();
+ v8::Local<v8::Array> array= v8::Array::New( isolate, 4 );
+ array->Set( 0 , v8::Number::New(isolate, vec.x));
+ array->Set( 1 , v8::Number::New(isolate, vec.y));
+ array->Set( 2 , v8::Number::New(isolate, vec.z));
+ array->Set( 3 , v8::Number::New(isolate, vec.w));
+ v8Value = array;
+ break;
+ }
+
+ default:
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Primitive mismatch \n");
+ return;
+ }
+ }
+ object->Set( v8::String::NewFromUtf8( isolate, key.c_str() ), v8Value );
+ }
+}
+
+void ReadFloatArguments( bool& foundAllArguments, float* data, unsigned int dataSize, const v8::FunctionCallbackInfo< v8::Value >& args, float defaultValue )
+{
+ foundAllArguments = true;
+ unsigned int length = args.Length();
+
+ if( length < dataSize )
+ {
+ foundAllArguments = false;
+ }
+
+ for( unsigned int i = 0; i< dataSize ;i++ )
+ {
+ if( i < length )
+ {
+ if( args[ i ]->IsNumber() )
+ {
+ data[i] = args[i]->NumberValue();
+ }
+ else
+ {
+ data[i] = defaultValue;
+ foundAllArguments = false; // bad argument
+ }
+ }
+ else
+ {
+ data[i] = defaultValue; // not enough arguments
+ }
+ }
+
+}
+
+void ReadIntegerArguments( bool& foundAllArguments, int* data, int dataSize, const v8::FunctionCallbackInfo< v8::Value >& args, int defaultValue )
+{
+ foundAllArguments = true;
+ int length = args.Length();
+ if( length < dataSize )
+ {
+ foundAllArguments = false;
+ }
+
+ for( int i = 0; i< dataSize ;i++ )
+ {
+ if( i < length )
+ {
+ if( args[ i ]->IsInt32() )
+ {
+ data[i] = args[i]->Int32Value();
+ }
+ else
+ {
+ data[i] = defaultValue;
+ foundAllArguments = false; // bad argument
+ }
+ }
+ else
+ {
+ data[i] = defaultValue; // not enough arguments
+ }
+ }
+
+}
+} // namespace V8Utils
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_V8_UTILS_H__
+#define __DALI_V8PLUGIN_V8_UTILS_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <string>
+#include <v8.h>
+#include <dali/public-api/math/vector2.h>
+#include <dali/public-api/math/vector3.h>
+#include <dali/public-api/math/vector4.h>
+#include <dali/public-api/math/rect.h>
+#include <dali/public-api/actors/actor.h>
+#include <dali/public-api/actors/layer.h>
+#include <dali/public-api/render-tasks/render-task.h>
+#include <dali/public-api/object/property-value.h>
+#include <dali/public-api/object/property-map.h>
+
+// INTERNAL INCLUDES
+#include <shared/base-wrapped-object.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+enum
+{
+ PARAMETER_0 = 0, ///< first parameter of a function call
+ PARAMETER_1 = 1, ///< second parameter of a function call
+ PARAMETER_2 = 2, ///< third parameter of a function call
+ PARAMETER_3 = 3, ///< forth parameter of a function call
+};
+
+#define DALI_SCRIPT_EXCEPTION( isolate, message ) V8Utils::ScriptError( __FUNCTION__ , isolate, message );
+
+namespace V8Utils
+{
+/**
+ * Print the list of arguments to std out
+ * @param[in] args v8 function args interpreted as (string, string,...)
+ */
+void Log(const v8::FunctionCallbackInfo< v8::Value >& args) ;
+
+/**
+ * Print out using DALI_LOG_ERROR
+ * @param[in] args v8 function args interpreted as (string, string,...)
+ */
+void LogError(const v8::FunctionCallbackInfo< v8::Value >& args) ;
+
+/**
+ * Read a files contents
+ *
+ * @param[in] filename The filename
+ * @param[out] contents string contents of the file
+ */
+void GetFileContents( const std::string &filename, std::string& contents );
+
+/**
+ * Extract the directory path from a full path filename
+ * @param fileName file name
+ * @param directory directory name
+ */
+void GetFileDirectory( const std::string& fileName, std::string& directory );
+
+/**
+ * Extract file name from a full path + file name
+ * @param[in] fullPathName full path + file name
+ * @param[out] fileName file name
+ */
+void GetFileName( const std::string& fullPathName, std::string& fileName);
+
+/**
+ * Return the module name, e.g. if the module is
+ * my_module.js it will get 'my_module'
+ * @param[in] fileName full path module name
+ * @param[out] moduleName module name
+ */
+void GetModuleName( const std::string& fileName, std::string& moduleName );
+
+/**
+ * Report an exception by writing as a warning to the Dali Log
+ *
+ * @param[in] try_catch The v8 TryCatch exception object
+ */
+void ReportException( v8::Isolate* isolate, v8::TryCatch* try_catch) ;
+
+/**
+ * Depending on what coding standard used this can
+ * convert the first character to lower case,
+ * E.g. GetId becomes getId
+ */
+std::string GetJavaScriptFunctionName( const char* functionName );
+
+ /**
+ * Get V8 Version
+ *
+ * @param[in] args v8 function args ignored
+ * @return a version string
+ */
+ void Version(const v8::FunctionCallbackInfo< v8::Value >& args) ;
+
+/**
+ * Convert v8 string as a std::string
+ * @param[in] value v8 function args interpreted as (v8_string)
+ * @return std string
+ */
+ std::string v8StringToStdString( const v8::Handle<v8::Value>& value) ;
+
+/**
+ * Convert hyphenated to camelCase (Dali property to wrapper property name)
+ *
+ * @param[in] hyphenatedName a hyphenated std::string to convert
+ * @return a camelCase'd std::string
+ */
+ std::string PropertyNameToJavaScriptName(const std::string& hyphenatedName);
+
+/**
+ * Convert camelCase to hyphenated to (Wrapper property name to Dali property)
+ * E.g. anchorPoint to "anchor-point"
+ * @param[in] camelCase a std::string camelCase
+ * @return a hyphenated std::string conversion
+ */
+ std::string JavaScriptNameToPropertyName(const std::string& camelCase);
+
+/**
+ * Script error, throws an exception
+ */
+void ScriptError( const char* function, v8::Isolate* isolate, std::string errorString );
+
+/**
+ * @return in the value is a boolean primitive or a boolean object
+ */
+bool IsBooleanPrimitiveOrObject( const v8::Local<v8::Value>& value );
+
+/**
+ * @return the value of boolean primitive or boolean object value
+ */
+bool GetBooleanValue( v8::Isolate* isolate, const v8::Local<v8::Value>& value );
+
+/**
+ * @return true if the value is a number or a number object
+ */
+bool IsNumberPrimitiveOrObject( const v8::Local<v8::Value>& value );
+
+/**
+ * @return the number of a number primitive or number object value
+ */
+float GetNumberValue( v8::Isolate* isolate, const v8::Local<v8::Value>& value );
+
+/**
+ * @return if the value is a string primitve or a string object
+ */
+bool IsStringPrimitiveOrObject( const v8::Local<v8::Value>& value );
+
+/**
+ * @return true if the value is a string or a string object
+ */
+bool IsStringPrimitiveOrObject( const v8::Local<v8::Value>& value );
+
+/**
+ * @return the string from a string value or a string object
+ */
+std::string GetStringValue( v8::Isolate* isolate, const v8::Local<v8::Value>& value );
+
+/******************************************
+ * Helper functions for extracting a DALi object from a JavaScript object
+ *******************************************/
+
+/**
+ * Given a JavaScript object, either extract the embedded DALi property value or
+ * convert it to a property value
+ * @param[out] found whether the property was found
+ * @return property value
+ */
+Property::Value GetPropertyValueFromObject( bool& found, v8::Isolate* isolate, const v8::Local<v8::Value >& value );
+
+/**
+ * Given a JavaScript object with
+ * @param [in] object JavaScrript object
+ * @return DALi ProperyMap from the JavaScript object
+ */
+Property::Map GetPropertyMapFromObject( v8::Isolate* isolate, const v8::Local<v8::Object>& object);
+
+/**
+ * Extract a DALi wrapped object, from a JavaScript object held in a function argument
+ * @param[in] index argument index the object is held in
+ * @param[in] type type of wrapped object to extract
+ */
+
+Actor GetActorFromObject( v8::Isolate* isolate, bool& found, v8::Local<v8::Object>& object);
+
+
+/******************************************
+ * Helper functions to extract a C++ native type (int,float,string) or a DALi object
+ * ( handle, vector, actor, layer, property value, property map ) from a
+ * JavaScript function argument.
+ * E.g.
+ * // JavaScript code
+ * myJavaScriptFunction( 23, 345, myActor );
+ *
+ * // C++ code
+ * bool found;
+ *
+ * Actor myActor = v8Utils::GetActorParameter( PARAMETER_2, found, JavaScript Args );
+ ******************************************/
+/**
+ * @param [in] index parameter index, e.g. callMyFunc( index0, index1, index2).
+ * @param[out] found whether the parameter was found
+ * @return integer value from the JavaScript function arguments
+ */
+int GetIntegerParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args, int defaultValue );
+
+/**
+ * @param [in] index parameter index, e.g. callMyFunc( index0, index1, index2).
+ * @param[out] found whether the parameter was found
+ * @return float value from the JavaScript function arguments
+ */
+float GetFloatParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args, float defaultValue );
+
+/**
+ * @param [in] index parameter index, e.g. callMyFunc( index0, index1, index2).
+ * @param[out] found whether the parameter was found
+ * @return string value from the JavaScript function arguments
+ */
+std::string GetStringParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args );
+
+/**
+ * @param [in] index parameter index, e.g. callMyFunc( index0, index1, index2).
+ * @param[out] found whether the parameter was found
+ * @return boolean value from the JavaScript function arguments
+ */
+bool GetBooleanParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args );
+
+/**
+ * @param [in] index parameter index, e.g. callMyFunc( index0, index1, index2).
+ * @param[out] found whether the parameter was found
+ * @return DALi Handle value from the JavaScript function arguments
+ */
+Handle GetHandleParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args );
+
+/**
+ * @param [in] index parameter index, e.g. callMyFunc( index0, index1, index2).
+ * @param[out] found whether the parameter was found
+ * @return Vector2 from the JavaScript function arguments
+ */
+Vector2 GetVector2Parameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args );
+
+/**
+ * @param [in] index parameter index, e.g. callMyFunc( index0, index1, index2).
+ * @param[out] found whether the parameter was found
+ * @return Vector3 from the JavaScript function arguments
+ */
+Vector3 GetVector3Parameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args);
+
+/**
+ * @param [in] index parameter index, e.g. callMyFunc( index0, index1, index2).
+ * @param[out] found whether the parameter was found
+ * @return Vector4 from the JavaScript function arguments
+ */
+Vector4 GetVector4Parameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args);
+
+/**
+ * @param [in] index parameter index, e.g. callMyFunc( index0, index1, index2).
+ * @param[out] found whether the parameter was found
+ * @return Rect<int> from the JavaScript function arguments
+ */
+Rect<int> GetRectIntParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args );
+
+/**
+ * @param [in] index parameter index, e.g. callMyFunc( index0, index1, index2).
+ * @param[out] found whether the parameter was found
+ * @return Actor from the JavaScript function arguments
+ */
+Actor GetActorParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args );
+
+/**
+ * @param [in] index parameter index, e.g. callMyFunc( index0, index1, index2).
+ * @param[out] found whether the parameter was found
+ * @return Layer from the JavaScript function arguments
+ */
+Layer GetLayerParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args );
+
+/**
+ * @param [in] index parameter index, e.g. callMyFunc( index0, index1, index2).
+ * @param[out] found whether the parameter was found
+ * @return Image from the JavaScript function arguments
+ */
+Image GetImageParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args );
+
+/**
+ * @param [in] index parameter index, e.g. callMyFunc( index0, index1, index2).
+ * @param[out] found whether the parameter was found
+ * @return RenderTask from the JavaScript function arguments
+ */
+RenderTask GetRenderTaskParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args );
+
+/**
+ * Extract a DALi wrapped object, from a JavaScript object held in a function argument
+ * @param[in] index argument index the object is held in
+ * @param[in] type type of wrapped object to extract
+ */
+BaseWrappedObject* GetWrappedDaliObjectParameter( unsigned int index, BaseWrappedObject::Type type, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args );
+
+/**
+ * @param [in] index parameter index, e.g. callMyFunc( index0, index1, index2).
+ * @param[out] found whether the parameter was found
+ * @return ProperyValue from the JavaScript function arguments
+ */
+Property::Value GetPropertyValueParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args );
+
+/**
+ * @param [in] index parameter index, e.g. callMyFunc( index0, index1, index2).
+ * @param[out] found whether the parameter was found
+ * @return ProperyMap from the JavaScript function arguments
+ */
+Property::Map GetPropertyMapParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args );
+
+/**
+ * Generate a JavaScript property map, from a DALi property map
+ * @param [in] DALi map property map
+ * @param [in] JavaScript property map
+ */
+void CreatePropertyMap( v8::Isolate* isolate, const Property::Map& map, v8::Local<v8::Object>& object );
+
+
+/**
+ * Read multiple float arguments from v8 args object
+ * e.g. myJavaFunc( 3.4, 7.6, 8.5 );
+ *
+ * @param[out] foundAllArguments flag to say all arguments are found
+ * @param[out] data pointer to a pre-allocated array of floats
+ * @param[in] dataSize the nunber of floats in the data parameter
+ * @param[in] defaultValue default value assigned to floats that don't exist in the arguments
+ */
+void ReadFloatArguments( bool& foundAllArguments, float* data, unsigned int dataSize, const v8::FunctionCallbackInfo< v8::Value >& args, float defaultValue );
+
+/**
+ * Read multiple integer arguments from v8 args object
+ * e.g. myJavaFunc( 3, 7, 8 );
+ *
+ * @param[out] foundAllArguments flag to say all arguments are found
+ * @param[out] data pointer to a pre-allocated array of integers
+ * @param[in] dataSize the nunber of integers in the data parameter
+ * @param[in] defaultValue default value assigned to integers that don't exist in the arguments
+ */
+void ReadIntegerArguments( bool& foundAllArguments, int* data, int dataSize, const v8::FunctionCallbackInfo< v8::Value >& args, int defaultValue );
+
+} // namespace V8Utils
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+
+#endif // __DALI_V8PLUGIN_V8_UTILS_H__
+