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 );
+ //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] );
}
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();
//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 )
{
Vector2 screenSize = stage.GetSize();
//Add background
- Toolkit::ImageView backView = Toolkit::ImageView::New(BACKGROUND_IMAGE);
- backView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
- stage.Add(backView);
-
- //Add 3D model control
- m3DLayer = Layer::New();
- stage.GetRootLayer().Add(m3DLayer);
-
- //3D models require 3D based rendering method, so it can use depth buffer, etc.
- m3DLayer.SetBehavior(Layer::LAYER_3D);
- m3DLayer.SetParentOrigin( ParentOrigin::CENTER );
- m3DLayer.SetAnchorPoint( AnchorPoint::CENTER );
+ Toolkit::ImageView backView = Toolkit::ImageView::New( BACKGROUND_IMAGE );
+ backView.SetParentOrigin( ParentOrigin::CENTER );
+ backView.SetAnchorPoint( AnchorPoint::CENTER );
+ stage.Add( backView );
mModelCounter = 0;
mModel3dView.SetProperty(Model3dView::Property::LIGHT_POSITION, Vector3(5,10.,0));
- m3DLayer.Add( mModel3dView );
+ backView.Add( mModel3dView );
mIlluminationShader = Model3dView::IlluminationType(mModel3dView.GetProperty<int>(Model3dView::Property::ILLUMINATION_TYPE));
mButtonLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
mButtonLayer.SetParentOrigin( ParentOrigin::CENTER );
mButtonLayer.SetAnchorPoint( AnchorPoint::CENTER );
- stage.GetRootLayer().Add(mButtonLayer);
+ stage.Add( mButtonLayer );
// Create button for model changing
Toolkit::PushButton editButton = Toolkit::PushButton::New();
int mModelCounter;
Model3dView mModel3dView;
- Layer m3DLayer;
Layer mButtonLayer;
TapGestureDetector mTapDetector;