2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 using System.Runtime.InteropServices;
21 using Tizen.NUI.UIComponents;
22 using Tizen.NUI.BaseComponents;
23 using Tizen.NUI.Constants;
25 namespace UserAlphaFunctionTest
27 class Example : NUIApplication
29 private Animation _animation;
30 private TextLabel _text;
31 private View _view1, _view2, _view3;
32 private UserAlphaFunctionDelegate _user_alpha_func;
35 public static void Log(string str)
37 Tizen.Log.Debug("NUI", "[DALI C# SAMPLE] " + str);
40 public Example() : base()
44 public Example(string stylesheet) : base(stylesheet)
48 public Example(string stylesheet, WindowMode windowMode) : base(stylesheet, windowMode)
52 protected override void OnCreate()
58 // Declare user alpha function delegate
59 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
60 delegate float UserAlphaFunctionDelegate(float progress);
62 public void Initialize()
64 Log("Initialize() is called!");
65 Window window = Window.Instance;
66 window.BackgroundColor = Color.White;
67 window.TouchEvent += OnWindowTouched;
68 window.TouchEvent += OnWindowTouched2;
69 //window.EventProcessingFinished += OnEventProcessingFinished;
70 window.WheelEvent += OnWindowWheelEvent;
72 // Add a _text label to the window
73 _text = new TextLabel("Hello Mono World");
74 _text.ParentOrigin = ParentOrigin.BottomCenter;
75 _text.PivotPoint = PivotPoint.BottomCenter;
76 _text.HorizontalAlignment = HorizontalAlignment.Center;
77 _text.PointSize = 32.0f;
81 _view1.Size2D = new Size2D(200, 200);
82 _view1.BackgroundColor = Color.Green;
83 _view1.ParentOrigin = ParentOrigin.Center;
84 _view1.PivotPoint = PivotPoint.Center;
85 _view1.WidthResizePolicy = ResizePolicyType.Fixed;
86 _view1.HeightResizePolicy = ResizePolicyType.Fixed;
87 _view1.AddedToWindow += OnWindow;
91 _view2.BackgroundColor = Color.Red;
92 _view2.Size2D = new Size2D(50, 50);
93 _view2.ParentOrigin = ParentOrigin.TopLeft;
94 _view2.PivotPoint = PivotPoint.TopLeft;
95 _view2.WidthResizePolicy = ResizePolicyType.Fixed;
96 _view2.HeightResizePolicy = ResizePolicyType.Fixed;
100 _view3.BackgroundColor = Color.Blue;
101 _view3.Size2D = new Size2D(50, 50);
102 _view3.ParentOrigin = ParentOrigin.TopLeft;
103 _view3.PivotPoint = PivotPoint.TopLeft;
104 _view3.WidthResizePolicy = ResizePolicyType.Fixed;
105 _view3.HeightResizePolicy = ResizePolicyType.Fixed;
108 _user_alpha_func = new UserAlphaFunctionDelegate(body);
113 // User defines alpha function as custom alpha function
114 // Important Notification : when this custom alpha-function is implemented,
115 // the other function call nor other data excess is prevented.
116 // this method must be implemented to calculate the values of input and output purely.
117 // unless, this will cause application crash.
118 float body(float progress)
120 if (progress > 0.2f && progress < 0.7f)
122 return progress + 0.8f;
127 // Callback for _animation finished signal handling
128 public void AnimationFinished(object sender, EventArgs e)
130 Log("AnimationFinished() is called!");
134 public void MyAnimating()
136 // Create a new _animation
143 _animation = new Animation(10000); // 10000 milli-second of duration
144 _animation.AnimateTo(_view2, "Position", new Vector3(150.0f, 150.0f, 0.0f), 5000, 10000, new AlphaFunction(_user_alpha_func));
145 // Connect the signal callback for animaiton finished signal
146 _animation.Finished += AnimationFinished;
147 _animation.EndAction = Animation.EndActions.Discard;
148 // Play the _animation
152 // Callback for window touched signal handling
153 public void OnWindowTouched(object source, Window.TouchEventArgs e)
155 // Only animate the _text label when touch down happens
156 if (e.Touch.GetState(0) == PointStateType.Down)
158 Log("OnWindowTouched() is called! PointStateType.DOWN came!");
163 Log("_animation.Stop() is called!");
168 // Callback for window touched signal handling
169 public void OnWindowTouched2(object source, Window.TouchEventArgs e)
171 Log("OnWindowTouched2() is called!state=" + e.Touch.GetState(0));
174 public void OnEventProcessingFinished(object source)
176 Log("OnEventProcessingFinished() is called!");
179 public void OnWindowWheelEvent(object source, Window.WheelEventArgs e)
181 Log("OnWindowWheelEvent() is called!");
182 //Log("OnWindowWheelEvent() is called!direction="+ e.WheelEvent.direction + " timeStamp=" + e.WheelEvent.timeStamp );
186 public void OnWindow(object source, EventArgs e)
188 Log("OnWindow() is called!");
192 static void _Main(string[] args)
194 Log("Main() is called!");
196 Example example = new Example();
199 Log("After MainLoop()");