X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Ftext-scrolling%2Ftext-scrolling-example.cpp;h=e8863311d42a408d2e7615bf4b211bd13e3c8c41;hb=3e41735399af818651d561a71f6d47993820acc7;hp=febac32b328c7e8d03b4742cff1a49a21e800311;hpb=ea430be2511b493fe7f8d3fa00f2e36c1809a02c;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 febac32..e886331 100644 --- a/examples/text-scrolling/text-scrolling-example.cpp +++ b/examples/text-scrolling/text-scrolling-example.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2019 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. @@ -28,13 +28,20 @@ using namespace Dali::Toolkit; namespace { -const char* DESKTOP_IMAGE( DEMO_IMAGE_DIR "woodEffect.jpg" ); -const Vector2 DESKTOP_SIZE( Vector2( 1440.f, 1600.f ) ); +const float STAGE_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; const float SCREEN_BORDER = 5.0f; // Border around screen that Popups and handles will not exceed +const char * ALIGNMENT_TABLE[] = +{ + "BEGIN", + "CENTER", + "END" +}; +const unsigned int ALIGNMENT_TABLE_COUNT = sizeof( ALIGNMENT_TABLE ) / sizeof( ALIGNMENT_TABLE[ 0 ] ); + enum Labels { SMALL = 1u, @@ -54,7 +61,8 @@ public: TextScrollingExample( Application& application ) : mApplication( application ), mTargetActorPosition(), - mTargetActorSize() + mTargetActorSize(), + mToggleColor( false ) { // Connect to the Application's Init signal mApplication.InitSignal().Connect( this, &TextScrollingExample::Create ); @@ -77,9 +85,9 @@ public: parent.Add( box ); Dali::Property::Map border; - border.Insert( "rendererType", "BORDER" ); - border.Insert( "borderColor", Color::WHITE ); - border.Insert( "borderSize", 1.f ); + border.Insert( Toolkit::Visual::Property::TYPE, Visual::BORDER ); + border.Insert( BorderVisual::Property::COLOR, Color::BLUE ); + border.Insert( BorderVisual::Property::SIZE, 1.f ); box.SetProperty( Control::Property::BACKGROUND, border ); } @@ -125,14 +133,13 @@ public: stage.Add( rootActor ); - const Size mTargetActorSize( mStageSize.width, DESKTOP_SIZE.height ); + mAnimation = Animation::New( 1.0f ); + + const Size mTargetActorSize( mStageSize.width, mStageSize.height * STAGE_HEIGHT_MULTIPLIER ); // Create Desktop - ImageView desktop = ImageView::New(); - Property::Map imageMap; - imageMap[ "url" ] = DESKTOP_IMAGE; - imageMap[ "synchronousLoading" ] = true; - desktop.SetProperty( ImageView::Property::IMAGE, imageMap ); + Control desktop = Control::New(); + desktop.SetBackgroundColor( Color::WHITE ); desktop.SetName("desktopActor"); desktop.SetAnchorPoint( AnchorPoint::TOP_LEFT ); desktop.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS ); @@ -166,32 +173,68 @@ public: 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 ); Toolkit::PushButton scrollSmallButton = Toolkit::PushButton::New(); scrollSmallButton.ClickedSignal().Connect( this, &TextScrollingExample::OnButtonClickedSmall ); - CreateLabel( mSmallLabel, "A Quick Brown Fox", boxC , true, scrollSmallButton ); - mSmallLabel.SetProperty( TextLabel::Property::TEXT_COLOR, Color::WHITE ); - mSmallLabel.SetProperty( TextLabel::Property::SHADOW_OFFSET, Vector2( 1.0f, 1.0f ) ); - mSmallLabel.SetProperty( TextLabel::Property::SHADOW_COLOR, Color::BLACK ); + CreateLabel( mSmallLabel, "Hello Text", boxC , true, scrollSmallButton ); + mSmallLabel.SetProperty( TextLabel::Property::TEXT_COLOR, Color::BLACK ); + 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 ); Toolkit::PushButton scrollRtlButton = Toolkit::PushButton::New(); scrollRtlButton.ClickedSignal().Connect( this, &TextScrollingExample::OnButtonClickedRtl ); CreateLabel( mRtlLabel, "مرحبا بالعالم", boxD , true, scrollRtlButton ); + mRtlLabel.SetProperty(TextLabel::Property::AUTO_SCROLL_STOP_MODE, TextLabel::AutoScrollStopMode::IMMEDIATE ); + 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 ); Toolkit::PushButton scrollRtlLongButton = Toolkit::PushButton::New(); scrollRtlLongButton.ClickedSignal().Connect( this, &TextScrollingExample::OnButtonClickedRtlLong ); - CreateLabel( mRtlLongLabel, " مرحبا بالعالم مرحبا بالعالم مرحبا بالعالم", boxE , false, scrollRtlLongButton ); - + CreateLabel( mRtlLongLabel, " مرحبا بالعالم مرحبا بالعالم مرحبا بالعالم مرحبا بالعالم مرحبا بالعالم مرحبا بالعالم مرحبا بالعالم مرحبا بالعالم مرحبا بالعالم", boxE , false, scrollRtlLongButton ); + mRtlLongLabel.SetProperty(TextLabel::Property::AUTO_SCROLL_SPEED, 500); + mRtlLongLabel.SetProperty(TextLabel::Property::AUTO_SCROLL_GAP, 500); + mRtlLongLabel.SetProperty(TextLabel::Property::AUTO_SCROLL_LOOP_COUNT, 3); + mRtlLongLabel.SetProperty(TextLabel::Property::AUTO_SCROLL_STOP_MODE, TextLabel::AutoScrollStopMode::FINISH_LOOP ); mPanGestureDetector = PanGestureDetector::New(); mPanGestureDetector.DetectedSignal().Connect(this, &TextScrollingExample::OnPanGesture ); mPanGestureDetector.Attach( desktop ); + + Toolkit::PushButton colorButton = Toolkit::PushButton::New(); + colorButton.SetProperty( Button::Property::TOGGLABLE, true ); + 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.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); + colorButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); + colorButton.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS ); + colorButton.SetSize(BOX_SIZE.height,BOX_SIZE.height); + colorButton.ClickedSignal().Connect( this, &TextScrollingExample::OnColorButtonClicked ); + rootActor.Add( colorButton ); + + for( unsigned int i = 0; i < ALIGNMENT_TABLE_COUNT; ++i ) + { + Toolkit::RadioButton alignButton = Toolkit::RadioButton::New( ALIGNMENT_TABLE[ i ] ); + alignButton.ClickedSignal().Connect( this, &TextScrollingExample::OnAlignButtonClicked ); + alignButton.SetName( 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 ) ); + + rootActor.Add( alignButton ); + + if( i == 0 ) + { + // Set the first button as selected + alignButton.SetProperty( Button::Property::SELECTED, true ); + } + } } void EnableScrolling( Labels labels ) @@ -263,6 +306,49 @@ public: return true; } + bool OnColorButtonClicked( Toolkit::Button button ) + { + Vector4 color = Color::RED; + + if ( mToggleColor ) + { + color = Color::BLACK; + mToggleColor = false; + } + else + { + mToggleColor = true; + } + + 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 ); + mRtlLongLabel.SetProperty( TextLabel::Property::TEXT_COLOR, color ); + + return true; + } + + bool OnAlignButtonClicked( Toolkit::Button button ) + { + for( unsigned int index = 0; index < ALIGNMENT_TABLE_COUNT; ++index ) + { + const std::string& buttonName = button.GetName(); + if( buttonName == ALIGNMENT_TABLE[ index ] ) + { + mSmallLabel.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, ALIGNMENT_TABLE[ index ] ); + mRtlLabel.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, ALIGNMENT_TABLE[ index ] ); + mLargeLabel.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, ALIGNMENT_TABLE[ index ] ); + mRtlLongLabel.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, ALIGNMENT_TABLE[ index ] ); + break; + } + } + + return true; + } + /** * Main key event handler */ @@ -274,6 +360,18 @@ public: { mApplication.Quit(); } + else + { + if ( event.keyPressedName == "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 ) ); + mAnimation.AnimateTo( Property( mRtlLabel, Actor::Property::SCALE ), Vector3(1.2f, 1.2f, 0.0f), AlphaFunction::BOUNCE, TimePeriod( 1.0f, 1.0f ) ); + mAnimation.AnimateTo( Property( mRtlLongLabel, Actor::Property::SCALE ), Vector3(1.2f, 1.2f, 0.0f), AlphaFunction::BOUNCE, TimePeriod( 1.0f, 1.0f ) ); + + mAnimation.Play(); + } + } } } @@ -302,21 +400,16 @@ private: TextLabel mSmallLabel; TextLabel mRtlLabel; TextLabel mRtlLongLabel; -}; -void RunTest( Application& application ) -{ - TextScrollingExample test( application ); + Animation mAnimation; - application.MainLoop(); -} + bool mToggleColor; +}; -/** 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; }