Commit 2b0bef8df6473451ed926bd6a79ad54e570b9b07

Authored by Agnelo Vaz
1 parent 06ff0486

TextScrolling example allows text color changes

Change-Id: I01f2785583486b5c26cee4ae8cfaa9ac1b40bb92
examples/text-scrolling/text-scrolling-example.cpp
1 1 /*
2   - * Copyright (c) 2016 Samsung Electronics Co., Ltd.
  2 + * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3 3 *
4 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 5 * you may not use this file except in compliance with the License.
... ... @@ -22,13 +22,13 @@
22 22  
23 23 // EXTERNAL INCLUDES
24 24 #include <dali-toolkit/dali-toolkit.h>
  25 +#include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
25 26  
26 27 using namespace Dali;
27 28 using namespace Dali::Toolkit;
28 29  
29 30 namespace
30 31 {
31   -const char* DESKTOP_IMAGE( DEMO_IMAGE_DIR "woodEffect.jpg" );
32 32 const Vector2 DESKTOP_SIZE( Vector2( 1440.f, 1600.f ) );
33 33 const Vector2 BOX_SIZE( Vector2(330.0f, 80.0f ) );
34 34 const Vector2 SCROLLING_BOX_SIZE( Vector2(330.0f, 40.0f ) );
... ... @@ -54,7 +54,8 @@ public:
54 54 TextScrollingExample( Application& application )
55 55 : mApplication( application ),
56 56 mTargetActorPosition(),
57   - mTargetActorSize()
  57 + mTargetActorSize(),
  58 + mToggleColor( false )
58 59 {
59 60 // Connect to the Application's Init signal
60 61 mApplication.InitSignal().Connect( this, &TextScrollingExample::Create );
... ... @@ -78,7 +79,7 @@ public:
78 79  
79 80 Dali::Property::Map border;
80 81 border.Insert( Visual::Property::TYPE, Visual::BORDER );
81   - border.Insert( BorderVisual::Property::COLOR, Color::WHITE );
  82 + border.Insert( BorderVisual::Property::COLOR, Color::BLUE );
82 83 border.Insert( BorderVisual::Property::SIZE, 1.f );
83 84 box.SetProperty( Control::Property::BACKGROUND, border );
84 85 }
... ... @@ -125,14 +126,13 @@ public:
125 126  
126 127 stage.Add( rootActor );
127 128  
  129 + mAnimation = Animation::New( 1.0f );
  130 +
128 131 const Size mTargetActorSize( mStageSize.width, DESKTOP_SIZE.height );
129 132  
130 133 // Create Desktop
131   - ImageView desktop = ImageView::New();
132   - Property::Map imageMap;
133   - imageMap[ "url" ] = DESKTOP_IMAGE;
134   - imageMap[ "synchronousLoading" ] = true;
135   - desktop.SetProperty( ImageView::Property::IMAGE, imageMap );
  134 + Control desktop = Control::New();
  135 + desktop.SetBackgroundColor( Color::WHITE );
136 136 desktop.SetName("desktopActor");
137 137 desktop.SetAnchorPoint( AnchorPoint::TOP_LEFT );
138 138 desktop.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
... ... @@ -172,9 +172,9 @@ public:
172 172 Toolkit::PushButton scrollSmallButton = Toolkit::PushButton::New();
173 173 scrollSmallButton.ClickedSignal().Connect( this, &TextScrollingExample::OnButtonClickedSmall );
174 174 CreateLabel( mSmallLabel, "A Quick Brown Fox", boxC , true, scrollSmallButton );
175   - mSmallLabel.SetProperty( TextLabel::Property::TEXT_COLOR, Color::WHITE );
  175 + mSmallLabel.SetProperty( TextLabel::Property::TEXT_COLOR, Color::BLACK );
176 176 mSmallLabel.SetProperty( TextLabel::Property::SHADOW_OFFSET, Vector2( 1.0f, 1.0f ) );
177   - mSmallLabel.SetProperty( TextLabel::Property::SHADOW_COLOR, Color::BLACK );
  177 + mSmallLabel.SetProperty( TextLabel::Property::SHADOW_COLOR, Color::CYAN );
178 178  
179 179 CreateBox( "boxD", boxD, desktop, SCROLLING_BOX_SIZE );
180 180 boxD.SetPosition( 0.0f, -200.0f, 1.0f );
... ... @@ -186,12 +186,25 @@ public:
186 186 boxE.SetPosition( 0.0f, -100.0f, 1.0f );
187 187 Toolkit::PushButton scrollRtlLongButton = Toolkit::PushButton::New();
188 188 scrollRtlLongButton.ClickedSignal().Connect( this, &TextScrollingExample::OnButtonClickedRtlLong );
189   - CreateLabel( mRtlLongLabel, " مرحبا بالعالم مرحبا بالعالم مرحبا بالعالم", boxE , false, scrollRtlLongButton );
190   -
  189 + CreateLabel( mRtlLongLabel, " مرحبا بالعالم مرحبا بالعالم مرحبا بالعالم مرحبا بالعالم مرحبا بالعالم مرحبا بالعالم مرحبا بالعالم مرحبا بالعالم مرحبا بالعالم", boxE , false, scrollRtlLongButton );
  190 + mRtlLongLabel.SetProperty(TextLabel::Property::AUTO_SCROLL_SPEED, 500);
  191 + mRtlLongLabel.SetProperty(TextLabel::Property::AUTO_SCROLL_GAP, 500);
  192 + mRtlLongLabel.SetProperty(TextLabel::Property::AUTO_SCROLL_LOOP_COUNT, 3);
191 193  
192 194 mPanGestureDetector = PanGestureDetector::New();
193 195 mPanGestureDetector.DetectedSignal().Connect(this, &TextScrollingExample::OnPanGesture );
194 196 mPanGestureDetector.Attach( desktop );
  197 +
  198 + Toolkit::PushButton colorButton = Toolkit::PushButton::New();
  199 + colorButton.SetProperty( Button::Property::TOGGLABLE, true );
  200 + colorButton.SetProperty( DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, Property::Map().Add ( Visual::Property::TYPE, Visual::COLOR ).Add( ColorVisual::Property::MIX_COLOR, Color::RED ) );
  201 + colorButton.SetProperty( DevelButton::Property::SELECTED_BACKGROUND_VISUAL, Property::Map().Add ( Visual::Property::TYPE, Visual::COLOR ).Add( ColorVisual::Property::MIX_COLOR, Color::BLACK ) );
  202 + colorButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
  203 + colorButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
  204 + colorButton.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
  205 + colorButton.SetSize(BOX_SIZE.height,BOX_SIZE.height);
  206 + colorButton.ClickedSignal().Connect( this, &TextScrollingExample::OnColorButtonClicked );
  207 + rootActor.Add( colorButton );
195 208 }
196 209  
197 210 void EnableScrolling( Labels labels )
... ... @@ -263,6 +276,28 @@ public:
263 276 return true;
264 277 }
265 278  
  279 + bool OnColorButtonClicked( Toolkit::Button button )
  280 + {
  281 + Vector4 color = Color::RED;
  282 +
  283 + if ( mToggleColor )
  284 + {
  285 + color = Color::BLACK;
  286 + mToggleColor = false;
  287 + }
  288 + else
  289 + {
  290 + mToggleColor = true;
  291 + }
  292 +
  293 + mSmallLabel.SetProperty( TextLabel::Property::SHADOW_COLOR, Color::BLACK );
  294 + mSmallLabel.SetProperty( TextLabel::Property::TEXT_COLOR, color );
  295 + mLargeLabel.SetProperty( TextLabel::Property::TEXT_COLOR, color );
  296 + mRtlLongLabel.SetProperty( TextLabel::Property::TEXT_COLOR, color );
  297 +
  298 + return true;
  299 + }
  300 +
266 301 /**
267 302 * Main key event handler
268 303 */
... ... @@ -274,6 +309,18 @@ public:
274 309 {
275 310 mApplication.Quit();
276 311 }
  312 + else
  313 + {
  314 + if ( event.keyPressedName == "2" )
  315 + {
  316 + mAnimation.AnimateTo( Property( mSmallLabel, Actor::Property::SCALE ), Vector3(1.2f, 1.2f, 0.0f), AlphaFunction::BOUNCE, TimePeriod( 1.0f, 1.0f ) );
  317 + mAnimation.AnimateTo( Property( mLargeLabel, Actor::Property::SCALE ), Vector3(1.2f, 1.2f, 0.0f), AlphaFunction::BOUNCE, TimePeriod( 1.0f, 1.0f ) );
  318 + mAnimation.AnimateTo( Property( mRtlLabel, Actor::Property::SCALE ), Vector3(1.2f, 1.2f, 0.0f), AlphaFunction::BOUNCE, TimePeriod( 1.0f, 1.0f ) );
  319 + mAnimation.AnimateTo( Property( mRtlLongLabel, Actor::Property::SCALE ), Vector3(1.2f, 1.2f, 0.0f), AlphaFunction::BOUNCE, TimePeriod( 1.0f, 1.0f ) );
  320 +
  321 + mAnimation.Play();
  322 + }
  323 + }
277 324 }
278 325 }
279 326  
... ... @@ -302,6 +349,10 @@ private:
302 349 TextLabel mSmallLabel;
303 350 TextLabel mRtlLabel;
304 351 TextLabel mRtlLongLabel;
  352 +
  353 + Animation mAnimation;
  354 +
  355 + bool mToggleColor;
305 356 };
306 357  
307 358 void RunTest( Application& application )
... ...