X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Fbezier-curve%2Fbezier-curve-example.cpp;h=07eb159b57820c6c9e6042a6b2b6555f1e35c220;hb=1a473d5189ca7e7d55aca3a64a8a4ff2dc3b6c67;hp=b83021dc52c361509150166c56fbb4d208fdc29e;hpb=34c45dcde92eaac27f376a0eea27c6ae1bbeb15a;p=platform%2Fcore%2Fuifw%2Fdali-demo.git diff --git a/examples/bezier-curve/bezier-curve-example.cpp b/examples/bezier-curve/bezier-curve-example.cpp index b83021d..07eb159 100644 --- a/examples/bezier-curve/bezier-curve-example.cpp +++ b/examples/bezier-curve/bezier-curve-example.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 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. @@ -17,12 +17,14 @@ #include #include +#include #include "shared/view.h" #include using namespace Dali; using namespace Dali::Toolkit; +using namespace std; namespace { @@ -38,7 +40,8 @@ const char* const ANIMATION_BACKGROUND( DEMO_IMAGE_DIR "slider-skin.9.png" ); const char* APPLICATION_TITLE("Bezier curve animation"); const float ANIM_LEFT_FACTOR(0.2f); const float ANIM_RIGHT_FACTOR(0.8f); - +const int AXIS_LABEL_POINT_SIZE(7); +const float AXIS_LINE_SIZE(1.0f); const char* CURVE_VERTEX_SHADER = DALI_COMPOSE_SHADER ( @@ -106,8 +109,33 @@ public: BezierCurveExample( Application& application ) : mApplication( application ), - mDuration(2.0f), - mGoingRight(true) + mControlPoint1(), + mControlPoint2(), + mControlLine1(), + mControlLine2(), + mAnimIcon1(), + mAnimIcon2(), + mDragActor(), + mCurve(), + mCoefficientLabel(), + mContentLayer(), + mGrid(), + mTimer(), + mDragAnimation(), + mBezierAnimation(), + mCurveVertices(), + mLine1Vertices(), + mLine2Vertices(), + mRelativeDragPoint(), + mLastControlPointPosition1(), + mLastControlPointPosition2(), + mPositionFactorIndex(), + mDuration( 2.0f ), + mControlPoint1Id( 0.0f ), + mControlPoint2Id( 0.0f ), + mControlPointScale( 0.5f ), + mControlPointZoomScale( mControlPointScale * 2.0 ), + mGoingRight( true ) { // Connect to the Application's Init signal mApplication.InitSignal().Connect( this, &BezierCurveExample::Create ); @@ -121,30 +149,27 @@ public: // The Init signal is received once (only) during the Application lifetime void Create( Application& application ) { - // Hide the indicator bar - application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE ); - - Stage stage = Stage::GetCurrent(); - stage.KeyEventSignal().Connect( this, &BezierCurveExample::OnKeyEvent ); + Window window = mApplication.GetWindow(); + window.KeyEventSignal().Connect( this, &BezierCurveExample::OnKeyEvent ); - CreateBackground(stage); + CreateBackground(window); mControlPointScale = 0.5f; mControlPointZoomScale = mControlPointScale * 2.0f; mContentLayer = Layer::New(); mContentLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mContentLayer.TouchSignal().Connect(this, &BezierCurveExample::OnTouchLayer); - mContentLayer.SetParentOrigin( ParentOrigin::CENTER ); - stage.Add( mContentLayer ); + mContentLayer.TouchedSignal().Connect(this, &BezierCurveExample::OnTouchLayer); + mContentLayer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + window.Add( mContentLayer ); // 6 rows: title, grid, coords, play, anim1, anim2 TableView contentLayout = TableView::New(5, 1); - contentLayout.SetName("contentLayout"); + contentLayout.SetProperty( Dali::Actor::Property::NAME,"contentLayout"); contentLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); contentLayout.SetCellPadding( Size( 30, 30 ) ); - contentLayout.SetParentOrigin(ParentOrigin::TOP_CENTER); - contentLayout.SetAnchorPoint(AnchorPoint::TOP_CENTER); + contentLayout.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_CENTER); + contentLayout.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_CENTER); mContentLayer.Add( contentLayout ); // Create a TextLabel for the application title. @@ -160,20 +185,21 @@ public: mGrid.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH ); mGrid.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT ); - mGrid.SetParentOrigin(ParentOrigin::CENTER); - mGrid.SetAnchorPoint(AnchorPoint::CENTER); + mGrid.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); + mGrid.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER); mGrid.SetBackgroundColor(GRID_BACKGROUND_COLOR); contentLayout.Add( mGrid ); contentLayout.SetCellAlignment(1, HorizontalAlignment::CENTER, VerticalAlignment::CENTER ); CreateCubic(mGrid); CreateControlPoints( mGrid ); // Control points constrained to double height of grid + CreateAxisLabels( mGrid ); mCoefficientLabel = TextLabel::New(); mCoefficientLabel.SetProperty( TextLabel::Property::ENABLE_MARKUP, true ); mCoefficientLabel.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); mCoefficientLabel.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); - mCoefficientLabel.SetParentOrigin(ParentOrigin::CENTER); + mCoefficientLabel.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); contentLayout.Add( mCoefficientLabel ); SetLabel( Vector2(0,0), Vector2(1,1)); @@ -183,9 +209,9 @@ public: // Setup Play button and 2 icons to show off current anim and linear anim PushButton play = PushButton::New(); - play.SetName("Play"); - play.SetParentOrigin(ParentOrigin::CENTER); - play.SetLabelText("Play"); + play.SetProperty( Dali::Actor::Property::NAME,"Play"); + play.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); + play.SetProperty( Button::Property::LABEL, "Play"); play.ClickedSignal().Connect( this, &BezierCurveExample::OnPlayClicked ); contentLayout.Add( play ); @@ -193,8 +219,8 @@ public: contentLayout.SetFitHeight(3); auto animContainer = Control::New(); - animContainer.SetName("AnimationContainer"); - animContainer.SetParentOrigin( ParentOrigin::CENTER ); + animContainer.SetProperty( Dali::Actor::Property::NAME,"AnimationContainer"); + animContainer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); animContainer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); auto animRail = Control::New(); @@ -202,16 +228,16 @@ public: .Add( Visual::Property::TYPE, Visual::IMAGE ) .Add( ImageVisual::Property::URL, ANIMATION_BACKGROUND ) ); animRail.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - animRail.SetSizeModeFactor( Vector3( 0.666f, 0.2f, 1.0f ) ); - animRail.SetParentOrigin( ParentOrigin::CENTER ); + animRail.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.666f, 0.2f, 1.0f ) ); + animRail.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); animContainer.Add( animRail ); contentLayout.Add( animContainer ); contentLayout.SetFixedHeight(4, 150 ); mAnimIcon1 = ImageView::New( CIRCLE1_IMAGE ); - mAnimIcon1.SetParentOrigin( ParentOrigin::CENTER ); - mAnimIcon1.SetAnchorPoint( AnchorPoint::CENTER ); + mAnimIcon1.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + mAnimIcon1.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); // Would like some means of setting and animating position as a percentage of // parent size without using constraints, but this will have to suffice for the moment. @@ -249,18 +275,18 @@ public: UpdateCurve(); } - void CreateBackground( Stage stage ) + void CreateBackground( Window window ) { Toolkit::Control background = Dali::Toolkit::Control::New(); - background.SetAnchorPoint( Dali::AnchorPoint::CENTER ); - background.SetParentOrigin( Dali::ParentOrigin::CENTER ); + background.SetProperty( Actor::Property::ANCHOR_POINT, Dali::AnchorPoint::CENTER ); + background.SetProperty( Actor::Property::PARENT_ORIGIN, Dali::ParentOrigin::CENTER ); background.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS ); Property::Map map; map.Insert( Visual::Property::TYPE, Visual::COLOR ); map.Insert( ColorVisual::Property::MIX_COLOR, Vector4( 253/255.0f, 245/255.0f, 230/255.0f, 1.0f ) ); background.SetProperty( Dali::Toolkit::Control::Property::BACKGROUND, map ); - stage.Add( background ); + window.Add( background ); } void CreateCubic(Actor parent) @@ -268,13 +294,13 @@ public: // Create a mesh to draw the cubic as a single line mCurve = Actor::New(); mCurve.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mCurve.SetParentOrigin( ParentOrigin::CENTER ); + mCurve.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); Shader shader = Shader::New( CURVE_VERTEX_SHADER, CURVE_FRAGMENT_SHADER ); Property::Map curveVertexFormat; curveVertexFormat["aPosition"] = Property::VECTOR2; - mCurveVertices = PropertyBuffer::New( curveVertexFormat ); + mCurveVertices = VertexBuffer::New( curveVertexFormat ); Vector2 vertexData[2] = { Vector2(-0.5f, 0.5f), Vector2( 0.5f, -0.5f ) }; mCurveVertices.SetData( vertexData, 2 ); @@ -290,8 +316,8 @@ public: Actor CreateControlPoint( Actor parent, const char* url, Vector3 position) { Actor actor = ImageView::New( url ); - actor.SetScale( mControlPointScale); - actor.SetParentOrigin( ParentOrigin::CENTER ); + actor.SetProperty( Actor::Property::SCALE, mControlPointScale); + actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); // Curve and line drawing works off current value (i.e. last update frame's value). Need to animate to ensure // initial position is baked to both frames before initially drawing the curve. auto positionAnimation = Animation::New( 0.01f ); @@ -304,15 +330,15 @@ public: constraint.AddSource( Source( parent, Actor::Property::SIZE ) ); constraint.Apply(); - actor.TouchSignal().Connect(this, &BezierCurveExample::OnTouchControlPoint); + actor.TouchedSignal().Connect(this, &BezierCurveExample::OnTouchControlPoint); return actor; } - Actor CreateControlLine( PropertyBuffer vertexBuffer ) + Actor CreateControlLine( VertexBuffer vertexBuffer ) { Actor line = Actor::New(); line.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - line.SetParentOrigin( ParentOrigin::CENTER ); + line.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); Shader shader = Shader::New( CURVE_VERTEX_SHADER, CURVE_FRAGMENT_SHADER ); Geometry geometry = Geometry::New(); @@ -329,17 +355,17 @@ public: mControlPoint1 = CreateControlPoint( parent, CIRCLE1_IMAGE, CONTROL_POINT1_ORIGIN ); - mControlPoint1Id = mControlPoint1.GetId(); + mControlPoint1Id = mControlPoint1.GetProperty< int >( Actor::Property::ID ); mControlPoint2 = CreateControlPoint( parent, CIRCLE2_IMAGE, CONTROL_POINT2_ORIGIN ); - mControlPoint2Id = mControlPoint2.GetId(); + mControlPoint2Id = mControlPoint2.GetProperty< int >( Actor::Property::ID ); Property::Map lineVertexFormat; lineVertexFormat["aPosition"] = Property::VECTOR2; - mLine1Vertices = PropertyBuffer::New( lineVertexFormat ); - mLine2Vertices = PropertyBuffer::New( lineVertexFormat ); + mLine1Vertices = VertexBuffer::New( lineVertexFormat ); + mLine2Vertices = VertexBuffer::New( lineVertexFormat ); mControlLine1 = CreateControlLine( mLine1Vertices ); mControlLine2 = CreateControlLine( mLine2Vertices ); @@ -350,6 +376,36 @@ public: parent.Add( mControlPoint2 ); } + void CreateAxisLabels( Actor parent ) + { + TextLabel progressionLabel = TextLabel::New( "Progression" ); + progressionLabel.SetProperty( TextLabel::Property::POINT_SIZE, AXIS_LABEL_POINT_SIZE ); + progressionLabel.SetProperty( Actor::Property::ORIENTATION, Quaternion( Radian( Degree(-90.0f) ), Vector3::ZAXIS ) ); + progressionLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_LEFT ); + progressionLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_LEFT ); + CreateLine( progressionLabel, ParentOrigin::BOTTOM_LEFT ); + + TextLabel timeLabel = TextLabel::New( "Time" ); + timeLabel.SetProperty( TextLabel::Property::POINT_SIZE, AXIS_LABEL_POINT_SIZE ); + timeLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + timeLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_LEFT ); + CreateLine( timeLabel, ParentOrigin::TOP_LEFT ); + + parent.Add( progressionLabel ); + parent.Add( timeLabel ); + } + + void CreateLine( Actor parent, const Vector3& parentOrigin ) + { + Control control = Control::New(); + control.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + control.SetProperty( Actor::Property::PARENT_ORIGIN, parentOrigin ); + control.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); + control.SetProperty( Actor::Property::SIZE_HEIGHT, AXIS_LINE_SIZE ); + control.SetBackgroundColor( Color::BLACK ); + parent.Add( control ); + } + void SetLabel( Vector2 pos1, Vector2 pos2 ) { std::ostringstream oss; @@ -373,8 +429,8 @@ public: { Vector3 gridSize = mGrid.GetProperty( Actor::Property::SIZE ); // Get target value - pt1 = AlignToGrid( mControlPoint1.GetCurrentPosition(), gridSize ); - pt2 = AlignToGrid( mControlPoint2.GetCurrentPosition(), gridSize ); + pt1 = AlignToGrid( mControlPoint1.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ), gridSize ); + pt2 = AlignToGrid( mControlPoint2.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ), gridSize ); } /** @@ -385,9 +441,9 @@ public: void GetPoint( Actor actor, Vector2& point, Vector2& position) { auto gridSize = mGrid.GetProperty( Actor::Property::SIZE ); // Get target value - auto currentPosition = actor.GetCurrentPosition(); // Get constrained current value + auto currentPosition = actor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ); // Get constrained current value - position = Vector2( std::floor( currentPosition.x ), std::floor( currentPosition.y ) ); + position = Vector2( floor( currentPosition.x ), floor( currentPosition.y ) ); point.x = Clamp( position.x / gridSize.x, -0.5f, 0.5f ) + 0.5f; point.y = 0.5f - position.y / gridSize.y; @@ -436,7 +492,7 @@ public: } } - bool OnTouchControlPoint( Actor controlPoint, const TouchData& event ) + bool OnTouchControlPoint( Actor controlPoint, const TouchEvent& event ) { if( event.GetPointCount() > 0 ) { @@ -444,7 +500,7 @@ public: { Vector2 screenPoint = event.GetScreenPosition( 0 ); mRelativeDragPoint = screenPoint; - mRelativeDragPoint -= Vector2(controlPoint.GetCurrentPosition()); + mRelativeDragPoint -= Vector2(controlPoint.GetCurrentProperty< Vector3 >( Actor::Property::POSITION )); mDragActor = controlPoint; mDragAnimation = Animation::New(0.25f); mDragAnimation.AnimateTo( Property(mDragActor, Actor::Property::SCALE), Vector3( mControlPointZoomScale, mControlPointZoomScale, 1.0f), AlphaFunction::EASE_OUT); @@ -454,7 +510,7 @@ public: return false; // Don't mark this as consumed - let the layer get the touch } - bool OnTouchLayer( Actor actor, const TouchData& event ) + bool OnTouchLayer( Actor actor, const TouchEvent& event ) { if( event.GetPointCount() > 0 ) { @@ -462,7 +518,7 @@ public: { Vector3 position( event.GetScreenPosition( 0 ) ); - mDragActor.SetPosition( position - Vector3( mRelativeDragPoint ) ); + mDragActor.SetProperty( Actor::Property::POSITION, position - Vector3( mRelativeDragPoint ) ); if( event.GetState( 0 ) == PointState::UP ) // Stop dragging { @@ -517,7 +573,7 @@ public: void OnKeyEvent(const KeyEvent& event) { - if( event.state == KeyEvent::Down && (IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK )) ) + if( event.GetState() == KeyEvent::DOWN && (IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK )) ) { mApplication.Quit(); } @@ -539,9 +595,9 @@ private: Timer mTimer; Animation mDragAnimation; Animation mBezierAnimation; - PropertyBuffer mCurveVertices; - PropertyBuffer mLine1Vertices; - PropertyBuffer mLine2Vertices; + VertexBuffer mCurveVertices; + VertexBuffer mLine1Vertices; + VertexBuffer mLine2Vertices; Vector2 mRelativeDragPoint; Vector2 mLastControlPointPosition1; Vector2 mLastControlPointPosition2; @@ -555,7 +611,7 @@ private: }; -int main( int argc, char **argv ) +int DALI_EXPORT_API main( int argc, char **argv ) { Application application = Application::New( &argc, &argv );