Follow formatting NUI
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / FrameBroker / DefaultFrameBroker.cs
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
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 using System;
18 using System.Collections.Generic;
19 using System.ComponentModel;
20 using System.Text;
21 using Tizen.NUI.BaseComponents;
22
23 namespace Tizen.NUI
24 {
25     internal class DefaultFrameBroker : FrameBrokerBase
26     {
27         private Window window;
28         private ImageView providerImage;
29         private bool isAnimating;
30
31         public delegate void AnimationEventHandler();
32         internal event AnimationEventHandler AnimationInitialized;
33         internal event AnimationEventHandler AnimationFinished;
34
35         internal DefaultFrameBroker(Window window) : base(window)
36         {
37             this.window = window;
38             isAnimating = false;
39         }
40
41         protected override void OnFrameResumed(FrameData frame)
42         {
43             if (isAnimating)
44             {
45                 return;
46             }
47             isAnimating = true;
48             base.OnFrameResumed(frame);
49             if (AnimationInitialized != null)
50             {
51                 AnimationInitialized();
52             }
53
54             if (frame.DirectionForward)
55             {
56                 PlayAnimateTo(frame, ForwardAnimation);
57             }
58             else
59             {
60                 PlayAnimateTo(frame, BackwardAnimation);
61             }
62
63             StartAnimation();
64         }
65
66         private void PlayAnimateTo(FrameData frame, TransitionAnimation animation)
67         {
68             if (animation)
69             {
70                 providerImage = frame.Image;
71                 providerImage.PositionUsesPivotPoint = true;
72                 providerImage.PivotPoint = animation.GetDefaultPivotPoint();
73                 providerImage.ParentOrigin = animation.GetDefaultParentOrigin();
74                 providerImage.Position = animation.GetDefaultPosition();
75                 providerImage.Size = animation.GetDefaultSize();
76
77                 window.Add(providerImage);
78
79                 animation.PlayAnimateTo(providerImage);
80             }
81             else
82             {
83                 FinishAnimation();
84             }
85         }
86
87
88         private TransitionAnimation forwardAnimation;
89         internal TransitionAnimation ForwardAnimation
90         {
91             get
92             {
93                 return forwardAnimation;
94             }
95             set
96             {
97                 forwardAnimation = value;
98                 forwardAnimation.Finished += Ani_Finished;
99             }
100         }
101
102         private TransitionAnimation backwardAnimation;
103         internal TransitionAnimation BackwardAnimation
104         {
105             get
106             {
107                 return backwardAnimation;
108             }
109             set
110             {
111                 backwardAnimation = value;
112                 backwardAnimation.Finished += Ani_Finished;
113             }
114         }
115
116         private void Ani_Finished(object sender, EventArgs e)
117         {
118             if (AnimationFinished != null)
119             {
120                 AnimationFinished();
121             }
122
123             if (providerImage != null)
124             {
125                 providerImage.Unparent();
126                 providerImage.Dispose();
127                 providerImage = null;
128             }
129             FinishAnimation();
130             isAnimating = false;
131         }
132     }
133 }