Updated demos to use DALi clang-format
[platform/core/uifw/dali-demo.git] / examples / frame-callback / frame-callback.cpp
1 /*
2  * Copyright (c) 2020 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 using namespace Dali;
22 using namespace std;
23
24 FrameCallback::FrameCallback()
25 : mActorIdContainer(),
26   windowHalfWidth(0.0f)
27 {
28 }
29
30 void FrameCallback::SetWindowWidth(float windowWidth)
31 {
32   windowHalfWidth = windowWidth * 0.5f;
33 }
34
35 void FrameCallback::AddId(uint32_t id)
36 {
37   mActorIdContainer.PushBack(id);
38 }
39
40 void FrameCallback::Update(Dali::UpdateProxy& updateProxy, float /* elapsedSeconds */)
41 {
42   // Go through Actor ID container and check if we've hit the sides.
43   for(auto&& i : mActorIdContainer)
44   {
45     Vector3 position;
46     Vector3 size;
47     if(updateProxy.GetPositionAndSize(i, position, size)) // Retrieve the position and size using the Actor ID.
48     {
49       float halfWidthPoint = windowHalfWidth - size.width * 0.5f;
50       float xTranslation   = abs(position.x);
51       if(xTranslation > halfWidthPoint)
52       {
53         // Actor has hit the edge, adjust the size accordingly.
54         float adjustment = xTranslation - halfWidthPoint;
55         size.width += adjustment * SIZE_MULTIPLIER;
56         size.height += adjustment * SIZE_MULTIPLIER;
57
58         updateProxy.SetSize(i, size); // Set the size using the UpdateProxy.
59       }
60
61       // Retrieve the actor's position and set make it more transparent the closer it is to the middle.
62       Vector4 color;
63       if(updateProxy.GetColor(i, color))
64       {
65         color.a = xTranslation / halfWidthPoint;
66         updateProxy.SetColor(i, color);
67       }
68     }
69   }
70 }