#include "actor-api.h"
// EXTERNAL INCLUDES
-#include <dali-toolkit/public-api/controls/text-view/text-view.h>
+#include <dali-toolkit/public-api/controls/text-controls/text-label.h>
// INTERNAL INCLUDES
#include <v8-utils.h>
#include <actors/actor-wrapper.h>
+#include <animation/path-constrainer-wrapper.h>
+#include <rendering/renderer-wrapper.h>
+#include <rendering/renderer-api.h>
namespace Dali
{
} //unanmed namespace
-namespace TextViewApi
+namespace TextLabelApi
{
Actor New( const v8::FunctionCallbackInfo< v8::Value >& args )
{
- return Dali::Toolkit::TextView::New();
+ return Dali::Toolkit::TextLabel::New();
}
}
}
/**
- * 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 getActorType
- * @return {String} Actor, ImageActor, TextActor, MeshActor, Layer, CameraActor ...
+ * @return {String} Actor, ImageActor, MeshActor, Layer, CameraActor ...
*/
void ActorApi::GetActorType( const v8::FunctionCallbackInfo<v8::Value>& args )
{
args.GetReturnValue().Set( v8String );
}
/**
+ * Return the natural size of the actor.
+ *
+ * @for Actor
+ * @method getNaturalSize
+ * @return {Object} { x, y, z }
+ */
+void ActorApi::GetNaturalSize( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Actor actor = GetActor( isolate, args );
+
+ Vector3 size( actor.GetNaturalSize() );
+
+ v8::Local<v8::Object> sizeObject = v8::Object::New( isolate );
+
+ sizeObject->Set( v8::String::NewFromUtf8( isolate, "x" ), v8::Integer::New( isolate, size.width ) );
+ sizeObject->Set( v8::String::NewFromUtf8( isolate, "y" ), v8::Integer::New( isolate, size.height ) );
+ sizeObject->Set( v8::String::NewFromUtf8( isolate, "z" ), v8::Integer::New( isolate, size.depth ) );
+
+ args.GetReturnValue().Set( sizeObject );
+}
+
+/**
+ * Calculate the width of the actor given a height
+ *
+ * The natural size is used for default calculation.
+ * size 0 is treated as aspect ratio 1:1.
+ * @for Actor
+ * @method getWidthForHeight
+ * @param {Float} height to use
+ * @return {Float} Return the width based on the height
+ * @example
+ * myTextLabel.getWidthForHeight(40);
+ *
+ * // DALi uses this formula internally
+ * // width = naturalSize.width * height / naturalSize.height;
+ *
+ *
+ */
+void ActorApi::GetWidthForHeight( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Actor actor = GetActor( isolate, args );
+
+ bool found;
+ float height = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 0.f );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing height parameter");
+ return;
+ }
+ args.GetReturnValue().Set( v8::Number::New( isolate, actor.GetWidthForHeight( height ) ) );
+}
+
+/**
+ * Calculate the height of the actor given a width
+ *
+ * The natural size is used for default calculation.
+ * size 0 is treated as aspect ratio 1:1.
+ * @for Actor
+ * @method getHeightForWidth
+ * @param {Float} width to use
+ * @return {Float} Return the height based on the width
+ * @example
+ * myTextLabel.getHeightForWidth(250);
+ *
+ * // DALi uses this formula internally
+ * // height = naturalSize.height * width / naturalSize.width
+ */
+void ActorApi::GetHeightForWidth( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Actor actor = GetActor( isolate, args );
+
+ bool found;
+ float width = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 0.f );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing width parameter");
+ return;
+ }
+ args.GetReturnValue().Set( v8::Number::New( isolate, actor.GetHeightForWidth( width ) ) );
+}
+/**
* Move an actor relative to its existing position.
* @example
*
* // using an array
- * actor.moveBy( [20,40,0] );
+ * actor.translateBy( [20,40,0] );
*
* @for Actor
- * @method moveBy
+ * @method translateBy
* @param {object} an array of 3 numbers
*/
-void ActorApi::MoveBy( const v8::FunctionCallbackInfo<v8::Value>& args )
+void ActorApi::TranslateBy( const v8::FunctionCallbackInfo<v8::Value>& args )
{
v8::Isolate* isolate = args.GetIsolate();
v8::HandleScope handleScope( isolate );
DALI_SCRIPT_EXCEPTION( isolate, "Vector3 move parameter missing" );
return;
}
- actor.MoveBy( vector );
+ actor.TranslateBy( vector );
}
}
actor.ScaleBy( vector );
}
+
/**
- * Apply a relative scale to an actor.
- * Actor opacity ranges from 0 (see through ) to 1 ( solid )
+ * Add a renderer to this actor.
* @example
- * // reduce actor opactiy by a half
- * actor.opaictyBy(-0.5);
+ *
+ * var renderer = new dali.Renderer( geometry, material );
+ * actor.addRenderer( renderer );
*
* @for Actor
- * @method OpacityBy
- * @param {float} relative opacity
+ * @method addRenderer
+ * @param {object} renderer Renderer to add to the actor
+ * @return {integer} The index of the Renderer that was added
*/
-void ActorApi::OpacityBy( const v8::FunctionCallbackInfo<v8::Value>& args )
+void ActorApi::AddRenderer( 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 )
+ unsigned int index = 0;
+
+ bool found( false );
+ Renderer renderer = RendererApi::GetRendererFromParams( 0, found, isolate, args );
+ if( found )
+ {
+ index = actor.AddRenderer(renderer);
+ }
+ else
{
- DALI_SCRIPT_EXCEPTION( isolate, "float parameter missing" );
+ DALI_SCRIPT_EXCEPTION( isolate, "Renderer parameter missing" );
return;
}
- actor.OpacityBy( opacity );
+
+ args.GetReturnValue().Set( v8::Integer::New( isolate, index ) );
}
/**
- * Apply a relative color change to an actor.
+ * Get the number of renderers on this actor.
+ * @example
+ *
+ * var count = actor.getRendererCount();
*
+ * @for Actor
+ * @method getRendererCount
+ * @return {integer} the number of renderers on this actor
+ */
+void ActorApi::GetRendererCount( 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.GetRendererCount() ) );
+}
+
+/**
+ * Get a Renderer by index.
* @example
- * // increase actor red by half
- * actor.colorBy( [0.5, 0, 0, 0]);
*
+ * var renderer = actor.getRendererAt( 0 );
*
* @for Actor
- * @method colorBy
- * @param {Object} Color JavaScript array
+ * @method getRendererAt
+ * @param {integer} index The index of the renderer to fetch, which must be between 0 and getRendererCount()-1
+ * @return {object} The renderer at the specified index
*/
-void ActorApi::ColorBy( const v8::FunctionCallbackInfo<v8::Value>& args )
+void ActorApi::GetRendererAt( 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;
+ Renderer renderer;
- if( argCount == 1 )
+ bool found( false );
+ int index = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0);
+ if( !found )
{
- color = V8Utils::GetVector4Parameter( PARAMETER_0, found, isolate, args );
- if( !found )
+ DALI_SCRIPT_EXCEPTION( isolate, "invalid index parameter" );
+ return;
+ }
+ else
+ {
+ renderer = actor.GetRendererAt(static_cast<unsigned int>(index));
+ if( !renderer )
{
- DALI_SCRIPT_EXCEPTION( isolate, "Vector4 parameter missing" );
+ DALI_SCRIPT_EXCEPTION( isolate, "renderer not found" );
return;
}
}
+
+ // Wrap the renderer
+ v8::Local<v8::Object> localObject = RendererWrapper::WrapRenderer( isolate, renderer );
+ args.GetReturnValue().Set( localObject );
+}
+
+/**
+ * Remove an renderer from the actor by index.
+ * @example
+ *
+ * actor.removeRenderer( 0 );
+ *
+ * @for Actor
+ * @method removeRenderer
+ * @param {integer} index Index of the renderer to be removed, which must be between 0 and getRendererCount()-1
+ */
+void ActorApi::RemoveRenderer( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Actor actor = GetActor( isolate, args );
+
+ bool found( false );
+ int index = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0);
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "invalid index parameter" );
+ }
else
{
- DALI_SCRIPT_EXCEPTION( isolate, "Vector4 parameter missing" );
- return;
+ actor.RemoveRenderer(static_cast<unsigned int>(index));
}
-
- actor.ColorBy( color );
}