X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Ftext-scrolling%2Ftext-scrolling-example.cpp;h=0350418d7ab7dc5976a17458da262980b081bd49;hb=74d1c0223d3597dfbdb427a58c56feb86857303e;hp=5a4ff9e3f68d0beea693e1c07f2afc8caf11b2e3;hpb=1c161ead142a0ff889708effe1ba6d02b64c1754;p=platform%2Fcore%2Fuifw%2Fdali-demo.git diff --git a/examples/text-scrolling/text-scrolling-example.cpp b/examples/text-scrolling/text-scrolling-example.cpp index 5a4ff9e..0350418 100644 --- a/examples/text-scrolling/text-scrolling-example.cpp +++ b/examples/text-scrolling/text-scrolling-example.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 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. @@ -22,14 +22,13 @@ // EXTERNAL INCLUDES #include -#include using namespace Dali; using namespace Dali::Toolkit; namespace { -const Vector2 DESKTOP_SIZE( Vector2( 1440.f, 1600.f ) ); +const float WINDOW_HEIGHT_MULTIPLIER( 1.5f ); const Vector2 BOX_SIZE( Vector2(330.0f, 80.0f ) ); const Vector2 SCROLLING_BOX_SIZE( Vector2(330.0f, 40.0f ) ); const float MAX_OFFSCREEN_RENDERING_SIZE = 2048.f; @@ -77,12 +76,12 @@ public: void CreateBox( const std::string& name, Actor& box, Actor parent, const Vector2& size ) { - box.SetName(name); - box.SetAnchorPoint( AnchorPoint::CENTER ); - box.SetParentOrigin( ParentOrigin::CENTER ); + box.SetProperty( Dali::Actor::Property::NAME,name); + box.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); + box.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); box.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT ); box.SetResizePolicy( ResizePolicy::FIXED, Dimension::WIDTH ); - box.SetSize( size.width, 0.f ); + box.SetProperty( Actor::Property::SIZE, Vector2( size.width, 0.f ) ); parent.Add( box ); Dali::Property::Map border; @@ -97,9 +96,9 @@ public: label = TextLabel::New( text ); label.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); label.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT ); - label.SetPadding( Padding( 1.0f, 1.0f, 1.0f, 1.0f ) ); - label.SetAnchorPoint( AnchorPoint::CENTER ); - label.SetParentOrigin( ParentOrigin::CENTER ); + label.SetProperty( Actor::Property::PADDING, Padding( 1.0f, 1.0f, 1.0f, 1.0f ) ); + label.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); + label.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); parent.Add( label ); if ( scrollOnStart ) @@ -108,9 +107,9 @@ public: } button.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS ); - button.SetSize(BOX_SIZE.height,BOX_SIZE.height); - button.SetParentOrigin( ParentOrigin::TOP_RIGHT ); - button.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + button.SetProperty( Actor::Property::SIZE, Vector2(BOX_SIZE.height,BOX_SIZE.height) ); + button.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT ); + button.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); parent.Add(button); } @@ -120,31 +119,31 @@ public: */ void Create( Application& application ) { - Stage stage = Stage::GetCurrent(); - mStageSize = stage.GetSize(); + Window window = application.GetWindow(); + mWindowSize = window.GetSize(); - stage.KeyEventSignal().Connect(this, &TextScrollingExample::OnKeyEvent); + window.KeyEventSignal().Connect(this, &TextScrollingExample::OnKeyEvent); // Create Root actor Actor rootActor = Actor::New(); - rootActor.SetName("rootActor"); + rootActor.SetProperty( Dali::Actor::Property::NAME,"rootActor"); rootActor.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS ); - rootActor.SetSize( mStageSize ); - rootActor.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + rootActor.SetProperty( Actor::Property::SIZE, mWindowSize ); + rootActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - stage.Add( rootActor ); + window.Add( rootActor ); mAnimation = Animation::New( 1.0f ); - const Size mTargetActorSize( mStageSize.width, DESKTOP_SIZE.height ); + const Size mTargetActorSize( mWindowSize.width, mWindowSize.height * WINDOW_HEIGHT_MULTIPLIER ); // Create Desktop Control desktop = Control::New(); desktop.SetBackgroundColor( Color::WHITE ); - desktop.SetName("desktopActor"); - desktop.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + desktop.SetProperty( Dali::Actor::Property::NAME,"desktopActor"); + desktop.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); desktop.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS ); - desktop.SetSize( mTargetActorSize ); + desktop.SetProperty( Actor::Property::SIZE, mTargetActorSize ); rootActor.Add( desktop ); // Add desktop (content) to offscreen actor @@ -156,36 +155,37 @@ public: Control boxE = Control::New(); CreateBox( "boxA", boxA, desktop, BOX_SIZE ); - boxA.SetPosition( 0.0f, -500.0f, 1.0f ); + boxA.SetProperty( Actor::Property::POSITION, Vector3( 0.0f, -500.0f, 1.0f )); // Create TextField TextField field = TextField::New(); field.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - field.SetPadding( Padding( 1.0f, 1.0f, 1.0f, 1.0f ) ); - field.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + field.SetProperty( Actor::Property::PADDING, Padding( 1.0f, 1.0f, 1.0f, 1.0f ) ); + field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "Enter Folder Name" ); - field.SetProperty( TextField::Property::DECORATION_BOUNDING_BOX, Rect( SCREEN_BORDER, SCREEN_BORDER, mStageSize.width - SCREEN_BORDER*2, mStageSize.height - SCREEN_BORDER*2 ) ); + field.SetProperty( TextField::Property::DECORATION_BOUNDING_BOX, Rect( SCREEN_BORDER, SCREEN_BORDER, mWindowSize.width - SCREEN_BORDER*2, mWindowSize.height - SCREEN_BORDER*2 ) ); boxA.Add( field ); - boxA.SetSize(BOX_SIZE); + boxA.SetProperty( Actor::Property::SIZE, BOX_SIZE); CreateBox( "boxB", boxB, desktop, SCROLLING_BOX_SIZE ); - boxB.SetPosition( 0.0f, -400.0f, 1.0f ); + boxB.SetProperty( Actor::Property::POSITION, Vector3( 0.0f, -400.0f, 1.0f )); Toolkit::PushButton scrollLargeButton = Toolkit::PushButton::New(); scrollLargeButton.ClickedSignal().Connect( this, &TextScrollingExample::OnButtonClickedLarge ); CreateLabel( mLargeLabel, "A Quick Brown Fox Jumps Over The Lazy Dog", boxB, false ,scrollLargeButton ); - CreateBox( "boxC", boxC, desktop, SCROLLING_BOX_SIZE ); - boxC.SetPosition( 0.0f, -300.0f, 1.0f ); + boxC.SetProperty( Actor::Property::POSITION, Vector3( 0.0f, -300.0f, 1.0f )); Toolkit::PushButton scrollSmallButton = Toolkit::PushButton::New(); scrollSmallButton.ClickedSignal().Connect( this, &TextScrollingExample::OnButtonClickedSmall ); CreateLabel( mSmallLabel, "Hello Text", boxC , true, scrollSmallButton ); mSmallLabel.SetProperty( TextLabel::Property::TEXT_COLOR, Color::BLACK ); - mSmallLabel.SetProperty( TextLabel::Property::SHADOW_OFFSET, Vector2( 1.0f, 1.0f ) ); - mSmallLabel.SetProperty( TextLabel::Property::SHADOW_COLOR, Color::CYAN ); + Property::Map shadowMap; + shadowMap.Insert( "color", Color::CYAN ); + shadowMap.Insert( "offset", Vector2( 1.0f, 1.0f ) ); + mSmallLabel.SetProperty( TextLabel::Property::SHADOW, shadowMap ); CreateBox( "boxD", boxD, desktop, SCROLLING_BOX_SIZE ); - boxD.SetPosition( 0.0f, -200.0f, 1.0f ); + boxD.SetProperty( Actor::Property::POSITION, Vector3( 0.0f, -200.0f, 1.0f )); Toolkit::PushButton scrollRtlButton = Toolkit::PushButton::New(); scrollRtlButton.ClickedSignal().Connect( this, &TextScrollingExample::OnButtonClickedRtl ); CreateLabel( mRtlLabel, "مرحبا بالعالم", boxD , true, scrollRtlButton ); @@ -193,7 +193,7 @@ public: mRtlLabel.SetProperty(TextLabel::Property::AUTO_SCROLL_LOOP_DELAY, 0.3f ); CreateBox( "boxE", boxE, desktop, SCROLLING_BOX_SIZE ); - boxE.SetPosition( 0.0f, -100.0f, 1.0f ); + boxE.SetProperty( Actor::Property::POSITION, Vector3( 0.0f, -100.0f, 1.0f )); Toolkit::PushButton scrollRtlLongButton = Toolkit::PushButton::New(); scrollRtlLongButton.ClickedSignal().Connect( this, &TextScrollingExample::OnButtonClickedRtlLong ); CreateLabel( mRtlLongLabel, " مرحبا بالعالم مرحبا بالعالم مرحبا بالعالم مرحبا بالعالم مرحبا بالعالم مرحبا بالعالم مرحبا بالعالم مرحبا بالعالم مرحبا بالعالم", boxE , false, scrollRtlLongButton ); @@ -208,12 +208,12 @@ public: Toolkit::PushButton colorButton = Toolkit::PushButton::New(); colorButton.SetProperty( Button::Property::TOGGLABLE, true ); - colorButton.SetProperty( DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, Property::Map().Add ( Toolkit::Visual::Property::TYPE, Visual::COLOR ).Add( ColorVisual::Property::MIX_COLOR, Color::RED ) ); - colorButton.SetProperty( DevelButton::Property::SELECTED_BACKGROUND_VISUAL, Property::Map().Add ( Toolkit::Visual::Property::TYPE, Visual::COLOR ).Add( ColorVisual::Property::MIX_COLOR, Color::BLACK ) ); - colorButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); - colorButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); + colorButton.SetProperty( Button::Property::UNSELECTED_BACKGROUND_VISUAL, Property::Map().Add ( Toolkit::Visual::Property::TYPE, Visual::COLOR ).Add( ColorVisual::Property::MIX_COLOR, Color::RED ) ); + colorButton.SetProperty( Button::Property::SELECTED_BACKGROUND_VISUAL, Property::Map().Add ( Toolkit::Visual::Property::TYPE, Visual::COLOR ).Add( ColorVisual::Property::MIX_COLOR, Color::BLACK ) ); + colorButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER ); + colorButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER ); colorButton.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS ); - colorButton.SetSize(BOX_SIZE.height,BOX_SIZE.height); + colorButton.SetProperty( Actor::Property::SIZE, Vector2(BOX_SIZE.height,BOX_SIZE.height) ); colorButton.ClickedSignal().Connect( this, &TextScrollingExample::OnColorButtonClicked ); rootActor.Add( colorButton ); @@ -221,11 +221,11 @@ public: { Toolkit::RadioButton alignButton = Toolkit::RadioButton::New( ALIGNMENT_TABLE[ i ] ); alignButton.ClickedSignal().Connect( this, &TextScrollingExample::OnAlignButtonClicked ); - alignButton.SetName( ALIGNMENT_TABLE[ i ] ); + alignButton.SetProperty( Dali::Actor::Property::NAME, ALIGNMENT_TABLE[ i ] ); // Place first button to left aligned, second center aligned and third right aligned - alignButton.SetAnchorPoint( Vector3( i * 0.5f, 0.0f, 0.5f ) ); - alignButton.SetParentOrigin( Vector3( i * 0.5f, 0.0f, 0.5f ) ); + alignButton.SetProperty( Actor::Property::ANCHOR_POINT, Vector3( i * 0.5f, 0.0f, 0.5f ) ); + alignButton.SetProperty( Actor::Property::PARENT_ORIGIN, Vector3( i * 0.5f, 0.0f, 0.5f ) ); rootActor.Add( alignButton ); @@ -320,7 +320,9 @@ public: mToggleColor = true; } - mSmallLabel.SetProperty( TextLabel::Property::SHADOW_COLOR, Color::BLACK ); + Property::Map shadowMap; + shadowMap.Insert( "color", Color::BLACK ); + mSmallLabel.SetProperty( TextLabel::Property::SHADOW, shadowMap ); mSmallLabel.SetProperty( TextLabel::Property::TEXT_COLOR, color ); mRtlLabel.SetProperty( TextLabel::Property::TEXT_COLOR, color ); mLargeLabel.SetProperty( TextLabel::Property::TEXT_COLOR, color ); @@ -333,7 +335,7 @@ public: { for( unsigned int index = 0; index < ALIGNMENT_TABLE_COUNT; ++index ) { - const std::string& buttonName = button.GetName(); + const std::string& buttonName = button.GetProperty< std::string >( Dali::Actor::Property::NAME ); if( buttonName == ALIGNMENT_TABLE[ index ] ) { mSmallLabel.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, ALIGNMENT_TABLE[ index ] ); @@ -352,7 +354,7 @@ public: */ void OnKeyEvent(const KeyEvent& event) { - if(event.state == KeyEvent::Down) + if(event.GetState() == KeyEvent::Down) { if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) { @@ -360,7 +362,7 @@ public: } else { - if ( event.keyPressedName == "2" ) + if ( event.GetKeyName() == "2" ) { mAnimation.AnimateTo( Property( mSmallLabel, Actor::Property::SCALE ), Vector3(1.2f, 1.2f, 0.0f), AlphaFunction::BOUNCE, TimePeriod( 1.0f, 1.0f ) ); mAnimation.AnimateTo( Property( mLargeLabel, Actor::Property::SCALE ), Vector3(1.2f, 1.2f, 0.0f), AlphaFunction::BOUNCE, TimePeriod( 1.0f, 1.0f ) ); @@ -380,8 +382,8 @@ public: Vector2 position = Vector2( gesture.displacement ); mTargetActorPosition.y = mTargetActorPosition.y + position.y; mTargetActorPosition.y = std::min( mTargetActorPosition.y, -mTargetActorSize.height ); - mTargetActorPosition.y = std::max( mTargetActorPosition.y, ( mTargetActorSize.height - mStageSize.height*0.25f ) ); - actor.SetPosition( 0.0f, mTargetActorPosition.y ); + mTargetActorPosition.y = std::max( mTargetActorPosition.y, ( mTargetActorSize.height - mWindowSize.height*0.25f ) ); + actor.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, mTargetActorPosition.y )); } } @@ -392,7 +394,7 @@ private: Vector2 mTargetActorPosition; Vector2 mTargetActorSize; - Vector2 mStageSize; + Vector2 mWindowSize; TextLabel mLargeLabel; TextLabel mSmallLabel; @@ -404,19 +406,10 @@ private: bool mToggleColor; }; -void RunTest( Application& application ) -{ - TextScrollingExample test( application ); - - application.MainLoop(); -} - -/** Entry point for Linux & Tizen applications */ int DALI_EXPORT_API main( int argc, char **argv ) { Application application = Application::New( &argc, &argv, DEMO_THEME_PATH ); - - RunTest( application ); - + TextScrollingExample test( application ); + application.MainLoop(); return 0; }