ff76b857ac1231f0b1e5bd52403ab916dd506738
[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                 if (animation is SlideIn)
68                 {
69                     SlideIn slideIn = animation as SlideIn;
70                     providerImage.PositionX = slideIn.GetDefaultInitValue();
71                 }
72
73                 animation.PlayAnimateTo(providerImage);
74             }
75             else
76             {
77                 FinishAnimation();
78             }
79         }
80
81         private TransitionAnimation forwardAnimation;
82         internal TransitionAnimation ForwardAnimation 
83         { 
84             get
85             {
86                 return forwardAnimation;
87             }
88             set
89             {
90                 forwardAnimation = value;
91                 forwardAnimation.Finished += Ani_Finished;
92             }
93         }
94
95         private TransitionAnimation backwardAnimation;
96         internal TransitionAnimation BackwardAnimation
97         {
98             get
99             { 
100                 return backwardAnimation;
101             }
102             set
103             {
104                 backwardAnimation = value;
105                 backwardAnimation.Finished += Ani_Finished;
106             }
107         }
108
109         private void Ani_Finished(object sender, EventArgs e)
110         {
111             if (AnimationFinished != null)
112             {
113                 AnimationFinished();
114             }
115
116             if (providerImage != null)
117             {
118                 providerImage.Unparent();
119                 providerImage.Dispose();
120                 providerImage = null;
121             }
122             FinishAnimation();
123         }
124     }
125 }