2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <dali/dali.h>
18 #include <dali-toolkit/dali-toolkit.h>
20 #include <dali-toolkit/devel-api/visuals/animated-gradient-visual-properties-devel.h>
21 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
22 #include <dali/integration-api/debug.h>
25 using namespace Dali::Toolkit;
27 // This example shows how to create and display animated-gradient-effect
31 // The value for scale-change between wearable-mobile
32 // Can be changed on App-Create time
33 Vector2 STAGE_SIZE = Vector2( 360.0f, 360.0f );
34 Vector2 SCALED_STAGE_SIZE = Vector2( 1.0f, 1.0f );
35 Vector3 SCALED_STAGE_SIZE_3 = Vector3( 1.0f, 1.0f, 0.0f );
36 float SCALED_WIDTH = 1.0f;
37 float SCALED_HEIGHT = 1.0f;
38 float FONT_SCALE = 0.25f;
40 // const parameters for color and animation
41 const float CHANGE_DURATION = 0.2f;
42 const float CARD_MOVE_DURATION = 1.0f;
43 const float LOADING_ONE_CYCLE_DURATION = 2.0f;
44 const int LOADING_CYCLE_CNT = 4;
45 const int LOADING_CYCLE_DT = 10;
46 const Vector4 DEFAULT_COLOR = Vector4( 0.5f, 0.5f, 0.5f, 1.0f );
48 const float PSEUDO_SCROLL_TIME = 100.0f;
49 const float PSEUDO_SCROLL_OFFSET = 0.05f;
51 // const static parameters for cards when resolution is 360x360
52 const int CARD_NUM = 3;
53 const Vector2 CARD_SIZE = Vector2( 210.0f, 143.0f );
54 const Vector2 CARD_OFFSET = Vector2( 0.0f, 12.5f );
55 const Vector2 CARD_DIFF = Vector2( 240.0f, 0.0f );
56 const float CARD_BOUNCE_ANIMATION_RATE = 0.3f;
58 const Vector2 CARD_SIZE_BIG = Vector2( 292.0f, 199.0f );
59 const Vector2 CARD_BIG_OFFSET = Vector2( 0.0f, -5.5f );
60 const float CARD_MOVE_DIST = 40.0f;
62 // const private parameters for each cards
63 const Vector4 CARD_COLOR_START_LIST[] =
65 Vector4( 0x24, 0x2C, 0x93, 255.f ) / 255.f,
66 Vector4( 0x7A, 0x1C, 0x9E, 255.f ) / 255.f,
67 Vector4( 0xA9, 0x0C, 0x96, 255.f ) / 255.f,
69 const Vector4 CARD_COLOR_END_LIST[] =
71 Vector4( 0x04, 0x13, 0x23, 255.f ) / 255.f,
72 Vector4( 0x28, 0x01, 0x45, 255.f ) / 255.f,
73 Vector4( 0x37, 0x0A, 0x2E, 255.f ) / 255.f,
75 const Vector4 CARD_COLOR_BACKGROUND_LIST[] =
77 Vector4( 0x28, 0x2B, 0x6E, 255.f ) / 255.f,
78 Vector4( 0x4D, 0x15, 0x61, 255.f ) / 255.f,
79 Vector4( 0x70, 0x21, 0x61, 255.f ) / 255.f,
81 const char * const CARD_IMAGE_LIST[] =
83 ( DEMO_IMAGE_DIR "Card_01.png" ),
84 ( DEMO_IMAGE_DIR "Card_02.png" ),
85 ( DEMO_IMAGE_DIR "Card_03.png" ),
88 // const parameters for add button position and size when resolution is 360x360x
89 const Vector2 BUTTON_ADD_SIZE = Vector2( 292.0f, 52.0f );
90 const Vector3 BUTTON_ADD_POSITION = Vector3( 0.0f, 0.0f, 0.0f );
91 const char * const BUTTON_ADD_IMAGE( DEMO_IMAGE_DIR "Card_Add_Button.png" );
93 // const parameters for string position and size and font-size when resolution is 360x360
94 const Vector2 LABEL_TICKET_SIZE = Vector2( 148.0f, 31.0f );
95 const Vector3 LABEL_TICKET_POSITION = Vector3( 0.0f, 72.5f, 0.0f );
96 const Vector4 LABEL_TICKET_FONT_COLOR = Vector4( 0.98f, 0.98f, 0.98f, 1.0f );
97 const float LABEL_TICKET_FONT_SIZE = 25.0f;
98 const Vector2 LABEL_HOLD_SIZE = Vector2( 180.0f, 60.0f );
99 const Vector3 LABEL_HOLD_POSITION = Vector3( 1.0f, 103.0f, 0.0f );
100 const Vector4 LABEL_HOLD_FONT_COLOR = Vector4( 0.98f, 0.98f, 0.98f, 1.0f );
101 const float LABEL_HOLD_FONT_SIZE = 25.0f;
102 const Vector2 LABEL_TERMINAL_SIZE = Vector2( 180.0f, 60.0f );
103 const Vector3 LABEL_TERMINAL_POSITION = Vector3( 1.0f, 133.0f, 0.0f );
104 const Vector4 LABEL_TERMINAL_FONT_COLOR = Vector4( 0.98f, 0.98f, 0.98f, 1.0f );
105 const float LABEL_TERMINAL_FONT_SIZE = 25.0f;
108 const char * const LABEL_TICKET_STR( "Select Ticket" );
109 const char * const LABEL_HOLD_STR( "Hold near" );
110 const char * const LABEL_TERMINAL_STR( "terminal" );
116 : mSize( 0.0f, 0.0f ),
117 mOffset( 0.0f, 0.0f),
125 void Init(Stage& stage)
127 mSize = CARD_SIZE * SCALED_WIDTH;
128 mOffset = CARD_OFFSET * SCALED_WIDTH;
129 mDiff = CARD_DIFF * SCALED_WIDTH;
134 for( int k = 0; k < CARD_NUM; k++ )
136 mPosition[k] = mOffset + mDiff * k;
138 mColorStart[k] = CARD_COLOR_START_LIST[k];
139 mColorEnd[k] = CARD_COLOR_END_LIST[k];
140 mColorBackground[k] = CARD_COLOR_BACKGROUND_LIST[k];
142 mImageUrl[k] = CARD_IMAGE_LIST[k];
144 mCard[k] = ImageView::New();
145 mCard[k].SetImage( mImageUrl[k] );
146 mCard[k].SetParentOrigin( ParentOrigin::CENTER );
147 mCard[k].SetAnchorPoint( AnchorPoint::CENTER );
148 mCard[k].SetSize( mSize.x, mSize.y );
149 mCard[k].SetPosition( mPosition[k].x, mPosition[k].y );
151 stage.Add( mCard[k] );
155 bool MoveRight(float duration)
157 Animation anim = Animation::New( duration );
158 for( int k = 0; k < CARD_NUM; k++ )
162 anim.AnimateBy( Property( mCard[k], Actor::Property::POSITION_X ), mDiff.x * CARD_BOUNCE_ANIMATION_RATE, AlphaFunction::BOUNCE );
166 anim.AnimateBy( Property( mCard[k], Actor::Property::POSITION_X ), mDiff.x, AlphaFunction::EASE_OUT );
172 mCurIndex = (mCurIndex - 1) % CARD_NUM;
179 bool MoveLeft(float duration)
181 Animation anim = Animation::New( duration );
182 for( int k = 0; k < CARD_NUM; k++ )
184 if( mCurIndex == CARD_NUM - 1 )
186 anim.AnimateBy( Property( mCard[k], Actor::Property::POSITION_X ), -mDiff.x * CARD_BOUNCE_ANIMATION_RATE, AlphaFunction::BOUNCE );
190 anim.AnimateBy( Property( mCard[k], Actor::Property::POSITION_X ), -mDiff.x, AlphaFunction::EASE_OUT );
194 if( mCurIndex != CARD_NUM - 1 )
196 mCurIndex = (mCurIndex + 1) % CARD_NUM;
203 Vector4 GetColorStart(int index)
205 DALI_ASSERT_ALWAYS( index >= 0 && index < CARD_NUM );
206 return mColorStart[index];
209 Vector4 GetColorEnd(int index)
211 DALI_ASSERT_ALWAYS( index >= 0 && index < CARD_NUM );
212 return mColorEnd[index];
215 Vector4 GetColorBackground(int index)
217 DALI_ASSERT_ALWAYS( index >= 0 && index < CARD_NUM );
218 return mColorBackground[index];
221 ImageView& operator [](int index)
223 DALI_ASSERT_ALWAYS( index >= 0 && index < CARD_NUM );
227 ImageView mCard[CARD_NUM];
228 std::string mImageUrl[CARD_NUM];
229 Vector4 mColorStart[CARD_NUM];
230 Vector4 mColorEnd[CARD_NUM];
231 Vector4 mColorBackground[CARD_NUM];
232 Vector2 mPosition[CARD_NUM];
240 } // unnamed namespace
242 // This example shows how to render animated gradients
244 class CardController : public ConnectionTracker
247 CardController(Application& application)
248 : mApplication( application ),
249 mNormalColor( 0.0f, 0.0f, 0.0f, 0.0f ),
250 mNormalStartColor( 0.0f, 0.0f, 0.0f, 0.0f ),
251 mNormalEndColor( 0.0f, 0.0f, 0.0f, 0.0f),
252 mFirstTouchPos( 0.0f, 0.0f ),
253 mLastTouchPos( 0.0f, 0.0f ),
254 mCardDuration( 0.0f ),
256 mLoadingTime( 0.0f ),
258 mLoadingCountScale( 0 ),
260 mCancelSignal( false ),
261 mIsTouchedActor( false )
263 // Connect to the Application's Init signal
264 mApplication.InitSignal().Connect( this, &CardController::Create );
269 // Nothing to do here;
272 // The Init signal is received once (only) during the Application lifetime
273 void Create(Application& application)
275 // Get a handle to the stage
276 mStage = Stage::GetCurrent();
277 mStage.KeyEventSignal().Connect( this, &CardController::OnKeyEvent );
279 // Get current device's width and height.
280 STAGE_SIZE = mStage.GetSize();
281 SCALED_STAGE_SIZE = STAGE_SIZE / 360.0f;
282 SCALED_STAGE_SIZE_3 = Vector3( SCALED_STAGE_SIZE.x, SCALED_STAGE_SIZE.y, 0.0f );
283 SCALED_WIDTH = SCALED_STAGE_SIZE.x < SCALED_STAGE_SIZE.y ? SCALED_STAGE_SIZE.x : SCALED_STAGE_SIZE.y;
284 SCALED_HEIGHT = SCALED_WIDTH;
286 // Note that this is heuristic value
287 FONT_SCALE = 0.25f * STAGE_SIZE.y / STAGE_SIZE.x;
289 mBackground = Control::New();
290 mBackground.SetParentOrigin( ParentOrigin::CENTER );
291 mBackground.SetAnchorPoint( AnchorPoint::CENTER );
292 mBackground.SetSize( STAGE_SIZE );
294 mStage.Add( mBackground );
302 mStage.GetRootLayer().TouchSignal().Connect( this, &CardController::OnTouchLayer );
306 bool OnTouchCards(Actor actor, const TouchData &data)
308 if( data.GetPointCount() > 0 )
310 if( data.GetState( 0 ) == PointState::DOWN )
312 if( mCards.mCurState == 0 )
314 mIsTouchedActor = false;
315 if( mCards[mCards.mCurIndex] == actor )
317 mIsTouchedActor = true;
319 mCards.mCurState = 3;
320 mTempTimer = Timer::New( PSEUDO_SCROLL_TIME );
321 mTempTimer.TickSignal().Connect( this, &CardController::OnDetectMotionLayer );
324 mFirstTouchPos = data.GetScreenPosition( 0 );
325 mLastTouchPos = mFirstTouchPos;
327 else if( mCards.mCurState == 1 )
329 mCancelSignal = true;
335 mLastTouchPos = data.GetScreenPosition( 0 );
341 bool OnTouchLayer(Actor actor, const TouchData &data)
343 if( data.GetPointCount() > 0 )
345 if( data.GetState( 0 ) == PointState::DOWN )
347 if( mCards.mCurState == 0 )
349 mIsTouchedActor = false;
350 mCards.mCurState = 3;
351 mTempTimer = Timer::New( PSEUDO_SCROLL_TIME );
352 mTempTimer.TickSignal().Connect( this, &CardController::OnDetectMotionLayer );
355 mFirstTouchPos = data.GetScreenPosition( 0 );
356 mLastTouchPos = mFirstTouchPos;
361 mLastTouchPos = data.GetScreenPosition( 0 );
367 // Heuristic Scroll View
368 bool OnDetectMotionLayer()
370 if( mCards.mCurState == 3 )
372 Vector2 diff = (mLastTouchPos - mFirstTouchPos);
373 float offset = PSEUDO_SCROLL_OFFSET;
375 if( diff.x > mStage.GetSize().x * offset )
377 mCards.mCurState = 2;
379 mCardChanger = Timer::New( mCardDuration * 1000.0f );
380 mCardChanger.TickSignal().Connect( this, &CardController::OnTickLayer );
381 mCardChanger.Start();
384 else if( diff.x < -mStage.GetSize().x * offset )
386 mCards.mCurState = 2;
388 mCardChanger = Timer::New( mCardDuration * 1000.0f );
389 mCardChanger.TickSignal().Connect( this, &CardController::OnTickLayer );
390 mCardChanger.Start();
392 // Not a scroll input
395 // Run NFC Tag effect if we touch a card
398 mCards.mCurState = 1;
399 RunAnimation( mCards.mCurIndex );
416 void OnKeyEvent(const KeyEvent& event)
418 if( event.state == KeyEvent::Down )
420 if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) )
429 // Utility function to make animation parameter map. return Property::Map
430 Property::Value BuildMap(const Property::Value &start, const Property::Value &target, int dir, float duration, float delay, int repeat, float repeat_delay, int motion, int easing)
435 map.Insert( DevelAnimatedGradientVisual::AnimationParameter::Property::START, start );
436 map.Insert( DevelAnimatedGradientVisual::AnimationParameter::Property::TARGET, target );
439 map.Insert( DevelAnimatedGradientVisual::AnimationParameter::Property::DIRECTION, DevelAnimatedGradientVisual::AnimationParameter::DirectionType::FORWARD );
443 map.Insert( DevelAnimatedGradientVisual::AnimationParameter::Property::DIRECTION, DevelAnimatedGradientVisual::AnimationParameter::DirectionType::BACKWARD );
445 map.Insert( DevelAnimatedGradientVisual::AnimationParameter::Property::DURATION, duration );
446 map.Insert( DevelAnimatedGradientVisual::AnimationParameter::Property::DELAY, delay );
447 map.Insert( DevelAnimatedGradientVisual::AnimationParameter::Property::REPEAT, repeat );
448 map.Insert( DevelAnimatedGradientVisual::AnimationParameter::Property::REPEAT_DELAY, repeat_delay );
451 map.Insert( DevelAnimatedGradientVisual::AnimationParameter::Property::MOTION_TYPE, DevelAnimatedGradientVisual::AnimationParameter::MotionType::LOOP );
455 map.Insert( DevelAnimatedGradientVisual::AnimationParameter::Property::MOTION_TYPE, DevelAnimatedGradientVisual::AnimationParameter::MotionType::MIRROR );
459 map.Insert( DevelAnimatedGradientVisual::AnimationParameter::Property::EASING_TYPE, DevelAnimatedGradientVisual::AnimationParameter::EasingType::LINEAR );
461 else if( easing == 1 )
463 map.Insert( DevelAnimatedGradientVisual::AnimationParameter::Property::EASING_TYPE, DevelAnimatedGradientVisual::AnimationParameter::EasingType::IN );
465 else if( easing == 2 )
467 map.Insert( DevelAnimatedGradientVisual::AnimationParameter::Property::EASING_TYPE, DevelAnimatedGradientVisual::AnimationParameter::EasingType::OUT );
471 map.Insert( DevelAnimatedGradientVisual::AnimationParameter::Property::EASING_TYPE, DevelAnimatedGradientVisual::AnimationParameter::EasingType::IN_OUT );
474 return Property::Value( map );
477 // Setup background visual property during nothing action
480 mBackgroundNormalMap.Clear();
481 mBackgroundNormalMap.Insert( Visual::Property::TYPE, DevelVisual::ANIMATED_GRADIENT );
483 mBackgroundNormalMap.Insert( Toolkit::DevelAnimatedGradientVisual::Property::START_POSITION, Vector2( -0.5, -0.5 ) );
484 mBackgroundNormalMap.Insert( Toolkit::DevelAnimatedGradientVisual::Property::END_POSITION, Vector2( 0.5, 0.5 ) );
485 mBackgroundNormalMap.Insert( Toolkit::DevelAnimatedGradientVisual::Property::START_COLOR, mNormalColor );
486 mBackgroundNormalMap.Insert( Toolkit::DevelAnimatedGradientVisual::Property::END_COLOR, mNormalColor );
487 mBackgroundNormalMap.Insert( Toolkit::DevelAnimatedGradientVisual::Property::ROTATE_CENTER, Vector2( 0.0f, 0.0f ) );
488 mBackgroundNormalMap.Insert( Toolkit::DevelAnimatedGradientVisual::Property::ROTATE_AMOUNT, 0.0f );
489 mBackgroundNormalMap.Insert( Toolkit::DevelAnimatedGradientVisual::Property::OFFSET, 0.0f );
492 // Setup background visual property during NFC tagging start
495 mBackgroundMapStart.Clear();
496 mBackgroundMapStart.Insert( Visual::Property::TYPE, DevelVisual::ANIMATED_GRADIENT );
498 mBackgroundMapStart.Insert( Toolkit::DevelAnimatedGradientVisual::Property::START_POSITION, Vector2( -0.5, -0.5 ) );
499 mBackgroundMapStart.Insert( Toolkit::DevelAnimatedGradientVisual::Property::END_POSITION, Vector2( 0.5, 0.5 ) );
500 mBackgroundMapStart.Insert( Toolkit::DevelAnimatedGradientVisual::Property::START_COLOR, mNormalColor );
501 mBackgroundMapStart.Insert( Toolkit::DevelAnimatedGradientVisual::Property::END_COLOR, mNormalColor );
502 mBackgroundMapStart.Insert( Toolkit::DevelAnimatedGradientVisual::Property::ROTATE_CENTER, Vector2( 0.0f, 0.0f ) );
503 mBackgroundMapStart.Insert( Toolkit::DevelAnimatedGradientVisual::Property::ROTATE_AMOUNT, 0.0f );
504 mBackgroundMapStart.Insert( Toolkit::DevelAnimatedGradientVisual::Property::OFFSET, BuildMap( 0.0f, 2.0f, 0, mLoadingTime, 0.0f, -1, 0.0f, 0, 0 ) );
506 mColorAnimationStartStart = *( BuildMap( mNormalColor, Vector4( 0, 0, 0, 0 ), 0, mDuration, 0.0f, 1, 0.0f, 0, 0 ).GetMap() );
507 mColorAnimationStartEnd = *( BuildMap( mNormalColor, Vector4( 0, 0, 0, 0 ), 0, mDuration, 0.0f, 1, 0.0f, 0, 0 ).GetMap() );
510 // Setup background visual property during NFC tagging end
513 mBackgroundMapEnd.Clear();
514 mBackgroundMapEnd.Insert( Visual::Property::TYPE, DevelVisual::ANIMATED_GRADIENT );
516 mBackgroundMapEnd.Insert( Toolkit::DevelAnimatedGradientVisual::Property::START_POSITION, Vector2( -0.5, -0.5 ) );
517 mBackgroundMapEnd.Insert( Toolkit::DevelAnimatedGradientVisual::Property::END_POSITION, Vector2( 0.5, 0.5 ) );
518 mBackgroundMapEnd.Insert( Toolkit::DevelAnimatedGradientVisual::Property::START_COLOR, mNormalColor );
519 mBackgroundMapEnd.Insert( Toolkit::DevelAnimatedGradientVisual::Property::END_COLOR, mNormalColor );
520 mBackgroundMapEnd.Insert( Toolkit::DevelAnimatedGradientVisual::Property::ROTATE_CENTER, Vector2( 0.0f, 0.0f ) );
521 mBackgroundMapEnd.Insert( Toolkit::DevelAnimatedGradientVisual::Property::ROTATE_AMOUNT, 0.0f );
522 mBackgroundMapEnd.Insert( Toolkit::DevelAnimatedGradientVisual::Property::OFFSET, BuildMap( 0.0f, 2.0f, 0, mLoadingTime, 0.0f, -1, 0.0f, 0, 0 ) );
524 mColorAnimationEndStart = *( BuildMap( mNormalColor, Vector4( 0, 0, 0, 0 ), 1, mDuration, 0.0f, 1, 0.0f, 0, 0 ).GetMap() );
525 mColorAnimationEndEnd = *( BuildMap( mNormalColor, Vector4( 0, 0, 0, 0 ), 1, mDuration, 0.0f, 1, 0.0f, 0, 0 ).GetMap() );
528 // Setup background visual property during card change
531 mBackgroundMapMove.Clear();
532 mBackgroundMapMove.Insert( Visual::Property::TYPE, DevelVisual::ANIMATED_GRADIENT);
533 mBackgroundMapMove.Insert( Toolkit::DevelAnimatedGradientVisual::Property::SPREAD_TYPE, Toolkit::DevelAnimatedGradientVisual::SpreadType::CLAMP);
535 mBackgroundMapMove.Insert( Toolkit::DevelAnimatedGradientVisual::Property::START_POSITION, Vector2( -0.5, 0.0 ) );
536 mBackgroundMapMove.Insert( Toolkit::DevelAnimatedGradientVisual::Property::END_POSITION, Vector2( 0.5, 0.0 ) );
537 mBackgroundMapMove.Insert( Toolkit::DevelAnimatedGradientVisual::Property::START_COLOR, mNormalStartColor );
538 mBackgroundMapMove.Insert( Toolkit::DevelAnimatedGradientVisual::Property::END_COLOR, mNormalEndColor );
539 mBackgroundMapMove.Insert( Toolkit::DevelAnimatedGradientVisual::Property::ROTATE_CENTER, Vector2( 0.0f, 0.0f ) );
540 mBackgroundMapMove.Insert( Toolkit::DevelAnimatedGradientVisual::Property::ROTATE_AMOUNT, 0.0f );
541 mBackgroundMapMove.Insert( Toolkit::DevelAnimatedGradientVisual::Property::OFFSET, BuildMap( -1.0f, 1.0f, 0, mCardDuration, 0.0f, 1, 0.0f, 0, 2 ) );
552 // Setup const parameter values
553 void BuildParameter()
555 mNormalColor = DEFAULT_COLOR;
556 mCardDuration = CARD_MOVE_DURATION;
557 mDuration = CHANGE_DURATION;
558 mLoadingTime = LOADING_ONE_CYCLE_DURATION;
559 mLoadingCount = LOADING_CYCLE_CNT;
560 mLoadingCountScale = LOADING_CYCLE_DT;
562 mNormalStartColor = mNormalColor;
563 mNormalEndColor = mNormalColor;
566 void BuildAnimation()
573 mCards.Init( mStage );
574 for( int k = 0; k < CARD_NUM; k++ )
576 mCards[k].TouchSignal().Connect( this, &CardController::OnTouchCards );
578 mNormalStartColor = mCards.GetColorBackground( mCards.mCurIndex );
579 mNormalEndColor = mCards.GetColorBackground( mCards.mCurIndex );
582 // Create and Add to stage
585 mAddButton = ImageView::New();
586 mAddButton.SetImage( BUTTON_ADD_IMAGE );
587 mAddButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
588 mAddButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
589 mAddButton.SetSize( BUTTON_ADD_SIZE * SCALED_WIDTH );
590 mAddButton.SetPosition( BUTTON_ADD_POSITION * SCALED_WIDTH );
592 mLabel1 = TextLabel::New( LABEL_TICKET_STR );
593 mLabel1.SetParentOrigin( ParentOrigin::TOP_CENTER );
594 mLabel1.SetAnchorPoint( AnchorPoint::TOP_CENTER );
595 mLabel1.SetSize( LABEL_TICKET_SIZE * SCALED_WIDTH );
596 mLabel1.SetPosition( LABEL_TICKET_POSITION * SCALED_WIDTH );
597 mLabel1.SetVisible( true );
598 mLabel1.SetProperty( TextLabel::Property::TEXT_COLOR, LABEL_TICKET_FONT_COLOR );
599 mLabel1.SetProperty( TextLabel::Property::POINT_SIZE, LABEL_TICKET_FONT_SIZE * FONT_SCALE );
600 mLabel1.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
601 mLabel1.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
603 mLabel2 = TextLabel::New( LABEL_HOLD_STR );
604 mLabel2.SetParentOrigin( ParentOrigin::CENTER );
605 mLabel2.SetAnchorPoint( AnchorPoint::CENTER );
606 mLabel2.SetSize( LABEL_HOLD_SIZE * SCALED_WIDTH );
607 mLabel2.SetPosition( LABEL_HOLD_POSITION * SCALED_WIDTH );
608 mLabel2.SetVisible( false );
609 mLabel2.SetProperty( TextLabel::Property::TEXT_COLOR, LABEL_HOLD_FONT_COLOR );
610 mLabel2.SetProperty( TextLabel::Property::POINT_SIZE, LABEL_HOLD_FONT_SIZE * FONT_SCALE );
611 mLabel2.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
612 mLabel2.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
614 mLabel3 = TextLabel::New( LABEL_TERMINAL_STR );
615 mLabel3.SetParentOrigin( ParentOrigin::CENTER );
616 mLabel3.SetAnchorPoint( AnchorPoint::CENTER );
617 mLabel3.SetSize( LABEL_TERMINAL_SIZE * SCALED_WIDTH );
618 mLabel3.SetPosition( LABEL_TERMINAL_POSITION * SCALED_WIDTH );
619 mLabel3.SetVisible( false );
620 mLabel3.SetProperty( TextLabel::Property::TEXT_COLOR, LABEL_TERMINAL_FONT_COLOR );
621 mLabel3.SetProperty( TextLabel::Property::POINT_SIZE, LABEL_TERMINAL_FONT_SIZE * FONT_SCALE );
622 mLabel3.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
623 mLabel3.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
625 mStage.Add( mAddButton );
626 mStage.Add( mLabel1 );
627 mStage.Add( mLabel2 );
628 mStage.Add( mLabel3 );
631 void SetupAnimation()
633 mMoveFront = Animation::New( mDuration );
634 mMoveBack = Animation::New( mDuration );
637 // Run animations when 'index' card active
638 void RunAnimation(int index)
640 //set animated background color here
641 mColorAnimationStartStart[DevelAnimatedGradientVisual::AnimationParameter::Property::START] = mNormalStartColor;
642 mColorAnimationStartEnd[DevelAnimatedGradientVisual::AnimationParameter::Property::START] = mNormalStartColor;
643 mColorAnimationEndStart[DevelAnimatedGradientVisual::AnimationParameter::Property::START] = mNormalStartColor;
644 mColorAnimationEndEnd[DevelAnimatedGradientVisual::AnimationParameter::Property::START] = mNormalStartColor;
646 mColorAnimationStartStart[DevelAnimatedGradientVisual::AnimationParameter::Property::TARGET] = mCards.GetColorStart( index );
647 mColorAnimationStartEnd[DevelAnimatedGradientVisual::AnimationParameter::Property::TARGET] = mCards.GetColorEnd( index );
648 mColorAnimationEndStart[DevelAnimatedGradientVisual::AnimationParameter::Property::TARGET] = mCards.GetColorStart( index );
649 mColorAnimationEndEnd[DevelAnimatedGradientVisual::AnimationParameter::Property::TARGET] = mCards.GetColorEnd( index );
651 mBackgroundMapStart[Toolkit::DevelAnimatedGradientVisual::Property::START_COLOR] = mColorAnimationStartStart;
652 mBackgroundMapStart[Toolkit::DevelAnimatedGradientVisual::Property::END_COLOR] = mColorAnimationStartEnd;
653 mBackgroundMapEnd[Toolkit::DevelAnimatedGradientVisual::Property::START_COLOR] = mColorAnimationEndStart;
654 mBackgroundMapEnd[Toolkit::DevelAnimatedGradientVisual::Property::END_COLOR] = mColorAnimationEndEnd;
658 // Rotate background gradient
659 mBackgroundMapStart[Toolkit::DevelAnimatedGradientVisual::Property::ROTATE_AMOUNT] = BuildMap( 0.0f, Math::PI * 2.0f, 0, mLoadingTime, 0.0f, -1, 0.0f, 0, 0 );
661 else if( index == 2 )
663 // Rotate background gradient more slow
664 mBackgroundMapStart[Toolkit::DevelAnimatedGradientVisual::Property::ROTATE_AMOUNT] = BuildMap( 0.0f, Math::PI * 2.0f, 0, mLoadingTime * 2.0, 0.0f, -1, 0.0f, 0, 0 );
668 mBackgroundMapStart[Toolkit::DevelAnimatedGradientVisual::Property::ROTATE_AMOUNT] = 0.0f;
671 mBackground.SetProperty( Control::Property::BACKGROUND, mBackgroundMapStart );
674 mBackgroundChanger = Timer::New( mLoadingTime * 1000.0f / mLoadingCountScale );
675 mBackgroundChanger.TickSignal().Connect( this, &CardController::OnTickBackground );
676 mBackgroundChanger.Start();
678 mMoveFront.AnimateTo( Property( mCards[index], Actor::Property::SIZE_WIDTH ), CARD_SIZE_BIG.x * SCALED_WIDTH );
679 mMoveFront.AnimateTo( Property( mCards[index], Actor::Property::SIZE_HEIGHT ), CARD_SIZE_BIG.y * SCALED_HEIGHT );
680 mMoveFront.AnimateTo( Property( mCards[index], Actor::Property::POSITION_Y ), CARD_BIG_OFFSET.y * SCALED_HEIGHT );
681 mMoveBack.AnimateTo( Property( mCards[index], Actor::Property::SIZE_WIDTH ), CARD_SIZE.x * SCALED_WIDTH );
682 mMoveBack.AnimateTo( Property( mCards[index], Actor::Property::SIZE_HEIGHT ), CARD_SIZE.y * SCALED_HEIGHT );
683 mMoveBack.AnimateTo( Property( mCards[index], Actor::Property::POSITION_Y ), CARD_OFFSET.y * SCALED_HEIGHT );
684 for( int i = 0; i < index; i++ )
686 mMoveFront.AnimateBy( Property( mCards[i], Actor::Property::POSITION_X ), -CARD_MOVE_DIST * SCALED_WIDTH );
687 mMoveBack.AnimateBy( Property( mCards[i], Actor::Property::POSITION_X ), CARD_MOVE_DIST * SCALED_WIDTH );
689 for( int i = index + 1; i < CARD_NUM; i++ )
691 mMoveFront.AnimateBy( Property( mCards[i], Actor::Property::POSITION_X ), CARD_MOVE_DIST * SCALED_WIDTH );
692 mMoveBack.AnimateBy( Property( mCards[i], Actor::Property::POSITION_X ), -CARD_MOVE_DIST * SCALED_WIDTH );
694 mMoveFront.AnimateTo( Property( mAddButton, Actor::Property::POSITION_Y ), BUTTON_ADD_SIZE.y * SCALED_HEIGHT );
695 mMoveBack.AnimateTo( Property( mAddButton, Actor::Property::POSITION_Y ), 0.f * SCALED_HEIGHT );
697 mMoveFront.AnimateTo( Property( mLabel1, Actor::Property::VISIBLE), false );
698 mMoveFront.AnimateTo( Property( mLabel2, Actor::Property::VISIBLE), true );
699 mMoveFront.AnimateTo( Property( mLabel3, Actor::Property::VISIBLE), true );
700 mMoveBack.AnimateTo( Property( mLabel1, Actor::Property::VISIBLE), true );
701 mMoveBack.AnimateTo( Property( mLabel2, Actor::Property::VISIBLE), false );
702 mMoveBack.AnimateTo( Property( mLabel3, Actor::Property::VISIBLE), false );
706 bool OnTickBackground()
709 if( mCancelSignal || mTickCount >= mLoadingCount * mLoadingCountScale )
711 if( mCards.mCurState == 1 )
713 mCards.mCurState = 2;
714 mBackground.SetProperty( Control::Property::BACKGROUND, mBackgroundMapEnd );
716 mBackgroundChanger.SetInterval( mDuration * 1000.0f );
729 if( mCards.MoveRight( mCardDuration ) )
731 // Set smooth background color change here
732 mNormalEndColor = mCards.GetColorBackground( mCards.mCurIndex );
733 mBackgroundMapMove[Toolkit::DevelAnimatedGradientVisual::Property::START_COLOR] = mNormalEndColor;
734 mBackgroundMapMove[Toolkit::DevelAnimatedGradientVisual::Property::END_COLOR] = mNormalStartColor;
736 (*mBackgroundMapMove[Toolkit::DevelAnimatedGradientVisual::Property::OFFSET].GetMap())[DevelAnimatedGradientVisual::AnimationParameter::Property::DIRECTION] = Property::Value( DevelAnimatedGradientVisual::AnimationParameter::DirectionType::BACKWARD );
738 mBackground.SetProperty( Control::Property::BACKGROUND, mBackgroundMapMove );
743 if( mCards.MoveLeft( mCardDuration ) )
745 //Set smooth background color change here
746 mNormalEndColor = mCards.GetColorBackground( mCards.mCurIndex );
747 mBackgroundMapMove[Toolkit::DevelAnimatedGradientVisual::Property::START_COLOR] = mNormalStartColor;
748 mBackgroundMapMove[Toolkit::DevelAnimatedGradientVisual::Property::END_COLOR] = mNormalEndColor;
750 (*mBackgroundMapMove[Toolkit::DevelAnimatedGradientVisual::Property::OFFSET].GetMap())[DevelAnimatedGradientVisual::AnimationParameter::Property::DIRECTION] = Property::Value( DevelAnimatedGradientVisual::AnimationParameter::DirectionType::FORWARD );
752 mBackground.SetProperty( Control::Property::BACKGROUND, mBackgroundMapMove );
758 mCards.mCurState = 0;
759 mCancelSignal = false;
763 mNormalStartColor = mNormalEndColor;
764 mBackgroundNormalMap[Toolkit::DevelAnimatedGradientVisual::Property::START_COLOR] = mNormalStartColor;
765 mBackgroundNormalMap[Toolkit::DevelAnimatedGradientVisual::Property::END_COLOR] = mNormalEndColor;
766 mBackground.SetProperty(Control::Property::BACKGROUND, mBackgroundNormalMap);
770 Application& mApplication;
777 ImageView mAddButton;
782 Timer mBackgroundChanger;
786 Animation mMoveFront;
789 // Property for background animated gradient visual
790 Property::Map mBackgroundNormalMap;
791 Property::Map mBackgroundMapStart;
792 Property::Map mBackgroundMapEnd;
793 Property::Map mBackgroundMapMove;
795 // Property for animation of color in animated gradient visual
796 Property::Map mColorAnimationStartStart;
797 Property::Map mColorAnimationStartEnd;
798 Property::Map mColorAnimationEndStart;
799 Property::Map mColorAnimationEndEnd;
801 Vector4 mNormalColor;
802 Vector4 mNormalStartColor;
803 Vector4 mNormalEndColor;
805 Vector2 mFirstTouchPos;
806 Vector2 mLastTouchPos;
812 int mLoadingCountScale;
816 bool mIsTouchedActor;
819 int main(int argc, char **argv)
821 Application application = Application::New( &argc, &argv );
823 CardController test( application );
825 application.MainLoop();