3d65302ad0b9af3d7e04e652f722ed386b2afbef
[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
30         public delegate void AnimationEventHandler();
31         internal event AnimationEventHandler AnimationInitialized;
32         internal event AnimationEventHandler AnimationFinished;
33
34         internal DefaultFrameBroker(Window window) : base(window)
35         {
36             this.window = window;
37         }
38
39         protected override void OnFrameResumed(FrameData frame)
40         {
41             base.OnFrameResumed(frame);
42             if (AnimationInitialized != null)
43             {
44                 AnimationInitialized();
45             }
46
47             if (frame.DirectionForward)
48             {
49                 PlayAnimateTo(frame, ForwardAnimation);
50             }
51             else
52             {
53                 PlayAnimateTo(frame, BackwardAnimation);
54             }
55
56             StartAnimation();
57         }
58
59         private void PlayAnimateTo(FrameData frame, TransitionAnimation animation)
60         {
61             if (animation)
62             {
63                 providerImage = frame.Image;
64                 providerImage.Size = window.Size;
65                 window.Add(providerImage);
66
67                 providerImage.PositionX = animation.GetDefaultInitValue();
68
69                 animation.PlayAnimateTo(providerImage);
70             }
71             else
72             {
73                 FinishAnimation();
74             }
75         }
76
77         private TransitionAnimation forwardAnimation;
78         internal TransitionAnimation ForwardAnimation 
79         { 
80             get
81             {
82                 return forwardAnimation;
83             }
84             set
85             {
86                 forwardAnimation = value;
87                 forwardAnimation.Finished += Ani_Finished;
88             }
89         }
90
91         private TransitionAnimation backwardAnimation;
92         internal TransitionAnimation BackwardAnimation
93         {
94             get
95             { 
96                 return backwardAnimation;
97             }
98             set
99             {
100                 backwardAnimation = value;
101                 backwardAnimation.Finished += Ani_Finished;
102             }
103         }
104
105         private void Ani_Finished(object sender, EventArgs e)
106         {
107             if (AnimationFinished != null)
108             {
109                 AnimationFinished();
110             }
111
112             if (providerImage != null)
113             {
114                 providerImage.Unparent();
115                 providerImage.Dispose();
116                 providerImage = null;
117             }
118             FinishAnimation();
119         }
120     }
121 }