Merge "Add LinearLayout weigth usage in LinearExample." into devel/master
[platform/core/uifw/dali-demo.git] / examples / frame-callback / frame-callback.cpp
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include "frame-callback.h"
20
21 #include <iostream>
22
23 using namespace Dali;
24
25 FrameCallback::FrameCallback()
26 : mActorIdContainer(),
27   stageHalfWidth( 0.0f )
28 {
29 }
30
31 void FrameCallback::SetStageWidth( float stageWidth )
32 {
33   stageHalfWidth = stageWidth * 0.5f;
34 }
35
36 void FrameCallback::AddId( unsigned int id )
37 {
38   mActorIdContainer.PushBack( id );
39 }
40
41 void FrameCallback::Update( Dali::UpdateProxy& updateProxy, float /* elapsedSeconds */ )
42 {
43   // Go through Actor ID container and check if we've hit the sides.
44   for( auto&& i : mActorIdContainer )
45   {
46     Vector3 position;
47     Vector3 size;
48     updateProxy.GetPositionAndSize( i, position, size ); // Retrieve the position and size using the Actor ID.
49
50     float halfWidthPoint = stageHalfWidth - size.width * 0.5f;
51     float xTranslation = std::abs( position.x );
52     if( xTranslation > halfWidthPoint )
53     {
54       // Actor has hit the edge, adjust the size accordingly.
55       float adjustment = xTranslation - halfWidthPoint;
56       size.width += adjustment * SIZE_MULTIPLIER;
57       size.height += adjustment * SIZE_MULTIPLIER;
58
59       updateProxy.SetSize( i, size ); // Set the size using the UpdateProxy.
60     }
61
62     // Retrieve the actor's position and set make it more transparent the closer it is to the middle.
63     Vector4 color = updateProxy.GetWorldColor( i );
64     color.a = xTranslation / halfWidthPoint;
65     updateProxy.SetWorldColor( i, color );
66   }
67 }