#include <dali-toolkit/dali-toolkit.h>
-#include <dali/public-api/object/property-map.h>
using namespace Dali;
using namespace Dali::Toolkit;
namespace
{
- //Keeps information about each model for access.
- struct Model
- {
- Control control; // Control housing the mesh visual of the model.
- Vector2 rotation; // Keeps track of rotation about x and y axis for manual rotation.
- Animation rotationAnimation; // Automatically rotates when left alone.
- };
+// Keeps information about each model for access.
+struct Model
+{
+ Control control; // Control housing the mesh visual of the model.
+ Vector2 rotation; // Keeps track of rotation about x and y axis for manual rotation.
+ Animation rotationAnimation; // Automatically rotates when left alone.
+};
- //Files for meshes
- const char * const MODEL_FILE_TABLE[] =
- {
- DEMO_MODEL_DIR "Dino.obj",
- DEMO_MODEL_DIR "ToyRobot-Metal.obj",
- DEMO_MODEL_DIR "Toyrobot-Plastic.obj"
- };
+// Files for meshes
+const char * const MODEL_FILE_TABLE[] =
+{
+ DEMO_MODEL_DIR "Dino.obj",
+ DEMO_MODEL_DIR "ToyRobot-Metal.obj",
+ DEMO_MODEL_DIR "Toyrobot-Plastic.obj"
+};
- const char * const MATERIAL_FILE_TABLE[] =
- {
- DEMO_MODEL_DIR "Dino.mtl",
- DEMO_MODEL_DIR "ToyRobot-Metal.mtl",
- DEMO_MODEL_DIR "Toyrobot-Plastic.mtl"
- };
+const char * const MATERIAL_FILE_TABLE[] =
+{
+ DEMO_MODEL_DIR "Dino.mtl",
+ DEMO_MODEL_DIR "ToyRobot-Metal.mtl",
+ DEMO_MODEL_DIR "Toyrobot-Plastic.mtl"
+};
- const char * const TEXTURES_PATH( DEMO_IMAGE_DIR "" );
+const char * const TEXTURES_PATH( DEMO_IMAGE_DIR "" );
- //Possible shading modes.
- MeshVisual::ShadingMode::Value SHADING_MODE_TABLE[] =
- {
- MeshVisual::ShadingMode::TEXTURED_WITH_DETAILED_SPECULAR_LIGHTING,
- MeshVisual::ShadingMode::TEXTURED_WITH_SPECULAR_LIGHTING,
- MeshVisual::ShadingMode::TEXTURELESS_WITH_DIFFUSE_LIGHTING
- };
-
- //Button labels.
- const char * const PAUSE = " || ";
- const char * const PLAY = " > ";
- const char * const FIXED = "FIXED";
- const char * const MANUAL = "MANUAL";
- const char * const FRONT = "FRONT";
- const char * const BACK = "BACK";
-
- //Image urls for the light.
- const char * const LIGHT_URL_FRONT = DEMO_IMAGE_DIR "light-icon-front.png";
- const char * const LIGHT_URL_BACK = DEMO_IMAGE_DIR "light-icon-back.png";
-
- const float X_ROTATION_DISPLACEMENT_FACTOR = 60.0f;
- const float Y_ROTATION_DISPLACEMENT_FACTOR = 60.0f;
- const float MODEL_SCALE = 0.75f;
- const float LIGHT_SCALE = 0.15f;
- const float BUTTONS_OFFSET_BOTTOM = 0.08f;
- const float BUTTONS_OFFSET_SIDE = 0.2f;
- const int NUM_MESHES = 2;
-
- //Used to identify actors.
- const int MODEL_TAG = 0;
- const int LIGHT_TAG = 1;
- const int LAYER_TAG = 2;
-
-} //End namespace
+// Possible shading modes.
+MeshVisual::ShadingMode::Value SHADING_MODE_TABLE[] =
+{
+ MeshVisual::ShadingMode::TEXTURED_WITH_DETAILED_SPECULAR_LIGHTING,
+ MeshVisual::ShadingMode::TEXTURED_WITH_SPECULAR_LIGHTING,
+ MeshVisual::ShadingMode::TEXTURELESS_WITH_DIFFUSE_LIGHTING
+};
+
+// Button labels.
+const char * const PAUSE = " || ";
+const char * const PLAY = " > ";
+const char * const FIXED = "FIXED";
+const char * const MANUAL = "MANUAL";
+const char * const FRONT = "FRONT";
+const char * const BACK = "BACK";
+
+// Image urls for the light.
+const char * const LIGHT_URL_FRONT = DEMO_IMAGE_DIR "light-icon-front.png";
+const char * const LIGHT_URL_BACK = DEMO_IMAGE_DIR "light-icon-back.png";
+
+const float X_ROTATION_DISPLACEMENT_FACTOR = 60.0f;
+const float Y_ROTATION_DISPLACEMENT_FACTOR = 60.0f;
+const float MODEL_SCALE = 0.75f;
+const float LIGHT_SCALE = 0.15f;
+const float BUTTONS_OFFSET_BOTTOM = 0.08f;
+const float BUTTONS_OFFSET_SIDE = 0.2f;
+const int NUM_MESHES = 2;
+
+// Used to identify actors.
+const int MODEL_TAG = 0;
+const int LIGHT_TAG = 1;
+const int LAYER_TAG = 2;
+
+const Vector4 STAGE_COLOR( 211.0f / 255.0f, 211.0f / 255.0f, 211.0f / 255.0f, 1.0f ); ///< The color of the stage
+
+} // unnamed namespace
class MeshVisualController : public ConnectionTracker
{
{
// Get a handle to the stage
Stage stage = Stage::GetCurrent();
- stage.SetBackgroundColor( Vector4( 0.0, 0.5, 1.0, 1.0 ) );
-
- //Set up layer to place objects on.
- Layer baseLayer = Layer::New();
- baseLayer.SetParentOrigin( ParentOrigin::CENTER );
- baseLayer.SetAnchorPoint( AnchorPoint::CENTER );
- baseLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
- baseLayer.SetBehavior( Layer::LAYER_2D ); //We use a 2D layer as this is closer to UI work than full 3D scene creation.
- baseLayer.SetDepthTestDisabled( false ); //Enable depth testing, as otherwise the 2D layer would not do so.
- baseLayer.RegisterProperty( "Tag", LAYER_TAG ); //Used to differentiate between different kinds of actor.
- baseLayer.TouchedSignal().Connect( this, &MeshVisualController::OnTouch );
- stage.Add( baseLayer );
+ stage.SetBackgroundColor( STAGE_COLOR );
+
+ //Set up root layer to receive touch gestures.
+ Layer rootLayer = stage.GetRootLayer();
+ rootLayer.RegisterProperty( "Tag", LAYER_TAG ); //Used to differentiate between different kinds of actor.
+ rootLayer.TouchSignal().Connect( this, &MeshVisualController::OnTouch );
//Place models on the scene.
- SetupModels( baseLayer );
+ SetupModels( rootLayer );
//Place buttons on the scene.
- SetupButtons( baseLayer );
+ SetupButtons( rootLayer );
//Add a light to the scene.
- SetupLight( baseLayer );
+ SetupLight( rootLayer );
//Allow for exiting of the application via key presses.
stage.KeyEventSignal().Connect( this, &MeshVisualController::OnKeyEvent );
mContainers[i].SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
mContainers[i].RegisterProperty( "Tag", MODEL_TAG ); //Used to differentiate between different kinds of actor.
mContainers[i].RegisterProperty( "Model", Property::Value( i ) ); //Used to index into the model.
- mContainers[i].TouchedSignal().Connect( this, &MeshVisualController::OnTouch );
+ mContainers[i].TouchSignal().Connect( this, &MeshVisualController::OnTouch );
layer.Add( mContainers[i] );
}
modelButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeModelClicked );
modelButton.SetParentOrigin( ParentOrigin::TOP_CENTER );
modelButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
- modelButton.SetLabelText( "Model" );
+ modelButton.SetProperty( Toolkit::Button::Property::LABEL, "Model" );
positionActorModel.Add( modelButton );
//Create button for shading mode changing.
shadingModeButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeShadingModeClicked );
shadingModeButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
shadingModeButton.SetAnchorPoint( AnchorPoint::TOP_CENTER );
- shadingModeButton.SetLabelText( "Shading Mode" );
+ shadingModeButton.SetProperty( Toolkit::Button::Property::LABEL, "Shading Mode" );
positionActorModel.Add( shadingModeButton );
//Text label title for changing model or shading mode.
pauseButton.ClickedSignal().Connect( this, &MeshVisualController::OnPauseClicked );
pauseButton.SetParentOrigin( Vector3( 0.5, 1.0 - BUTTONS_OFFSET_BOTTOM, 0.5 ) );
pauseButton.SetAnchorPoint( AnchorPoint::CENTER );
- pauseButton.SetLabelText( PAUSE );
+ pauseButton.SetProperty( Toolkit::Button::Property::LABEL, PAUSE );
layer.Add( pauseButton );
//Actor for positioning light position buttons.
lightModeButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeLightModeClicked );
lightModeButton.SetParentOrigin( ParentOrigin::TOP_CENTER );
lightModeButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
- lightModeButton.SetLabelText( FIXED );
+ lightModeButton.SetProperty( Toolkit::Button::Property::LABEL, FIXED );
positionActorLight.Add( lightModeButton );
//Create button for switching between front and back light position.
lightSideButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeLightSideClicked );
lightSideButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
lightSideButton.SetAnchorPoint( AnchorPoint::TOP_CENTER );
- lightSideButton.SetLabelText( FRONT );
+ lightSideButton.SetProperty( Toolkit::Button::Property::LABEL, FRONT );
positionActorLight.Add( lightSideButton );
//Text label title for light position mode.
SetLightImage();
//Connect to touch signal for dragging.
- mLightSource.TouchedSignal().Connect( this, &MeshVisualController::OnTouch );
+ mLightSource.TouchSignal().Connect( this, &MeshVisualController::OnTouch );
//Place the light source on a layer above the base, so that it is rendered above everything else.
Layer upperLayer = Layer::New();
}
Property::Map lightMap;
- lightMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
+ lightMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
lightMap.Insert( ImageVisual::Property::URL, imageUrl );
mLightSource.SetProperty( Control::Property::BACKGROUND, Property::Value( lightMap ) );
}
{
//Create mesh property map
Property::Map map;
- map.Insert( Visual::Property::TYPE, Visual::MESH );
+ map.Insert( Toolkit::Visual::Property::TYPE, Visual::MESH );
+ map.Insert( Visual::Property::TRANSFORM,
+ Property::Map().Add( Visual::Transform::Property::ORIGIN, Align::CENTER )
+ .Add( Visual::Transform::Property::ANCHOR_POINT, Align::CENTER ) );
map.Insert( MeshVisual::Property::OBJECT_URL, MODEL_FILE_TABLE[mModelIndex] );
map.Insert( MeshVisual::Property::MATERIAL_URL, MATERIAL_FILE_TABLE[mModelIndex] );
map.Insert( MeshVisual::Property::TEXTURES_PATH, TEXTURES_PATH );
//If the light source is touched, move it by dragging it.
//If a model is touched, rotate it by panning around.
- bool OnTouch( Actor actor, const TouchEvent& event )
+ bool OnTouch( Actor actor, const TouchData& touch )
{
- //Get primary touch point.
- const Dali::TouchPoint& point = event.GetPoint( 0 );
-
- switch( point.state )
+ switch( touch.GetState( 0 ) )
{
- case TouchPoint::Down:
+ case PointState::DOWN:
{
//Determine what was touched.
actor.GetProperty( actor.GetPropertyIndex( "Tag" ) ).Get( mTag );
mModels[mSelectedModelIndex].rotationAnimation.Pause();
//Store start points.
- mPanStart = point.screen;
+ mPanStart = touch.GetScreenPosition( 0 );
mRotationStart = mModels[mSelectedModelIndex].rotation;
}
break;
}
- case TouchPoint::Motion:
+ case PointState::MOTION:
{
//Switch on the kind of actor we're interacting with.
switch( mTag )
case MODEL_TAG: //Rotate model
{
//Calculate displacement and corresponding rotation.
- Vector2 displacement = point.screen - mPanStart;
+ Vector2 displacement = touch.GetScreenPosition( 0 ) - mPanStart;
mModels[mSelectedModelIndex].rotation = Vector2( mRotationStart.x - displacement.y / Y_ROTATION_DISPLACEMENT_FACTOR, // Y displacement rotates around X axis
mRotationStart.y + displacement.x / X_ROTATION_DISPLACEMENT_FACTOR ); // X displacement rotates around Y axis
Quaternion rotation = Quaternion( Radian( mModels[mSelectedModelIndex].rotation.x ), Vector3::XAXIS) *
case LIGHT_TAG: //Drag light
{
//Set light source to new position and update the models accordingly.
- mLightSource.SetPosition( Vector3( point.screen ) );
+ mLightSource.SetPosition( Vector3( touch.GetScreenPosition( 0 ) ) );
UpdateLight();
break;
break;
}
- case TouchPoint::Interrupted: //Same as finished.
- case TouchPoint::Finished:
+ case PointState::INTERRUPTED: //Same as finished.
+ case PointState::FINISHED:
{
if( mTag == MODEL_TAG )
{
mModels[i].rotationAnimation.Pause();
}
- button.SetLabelText( PLAY );
+ button.SetProperty( Toolkit::Button::Property::LABEL, PLAY );
}
else //Unpause all animations again.
{
mModels[i].rotationAnimation.Play();
}
- button.SetLabelText( PAUSE );
+ button.SetProperty( Toolkit::Button::Property::LABEL, PAUSE );
}
return true;
if( mLightFixed )
{
- button.SetLabelText( FIXED );
+ button.SetProperty( Toolkit::Button::Property::LABEL, FIXED );
}
else
{
- button.SetLabelText( MANUAL );
+ button.SetProperty( Toolkit::Button::Property::LABEL, MANUAL );
}
SetLightMode();
if( mLightFront )
{
- button.SetLabelText( FRONT );
+ button.SetProperty( Toolkit::Button::Property::LABEL, FRONT );
}
else
{
- button.SetLabelText( BACK );
+ button.SetProperty( Toolkit::Button::Property::LABEL, BACK );
}
//Change light image.
bool mLightFront; //Bool for light being in front or behind the models.
};
-// Entry point for Linux & Tizen applications
-//
-int main( int argc, char **argv )
+int DALI_EXPORT_API main( int argc, char **argv )
{
Application application = Application::New( &argc, &argv );
MeshVisualController test( application );