2 * Copyright (c) 2016 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.Constants;
24 namespace UserAlphaFunctionTest
26 class Example : NUIApplication
28 private Animation _animation;
29 private TextLabel _text;
30 private View _view1, _view2, _view3;
31 private UserAlphaFunctionDelegate _user_alpha_func;
34 public static void Log(string str)
36 Tizen.Log.Debug("NUI", "[DALI C# SAMPLE] " + str);
39 public Example() : base()
43 public Example(string stylesheet) : base(stylesheet)
47 public Example(string stylesheet, WindowMode windowMode) : base(stylesheet, windowMode)
51 protected override void OnCreate()
57 // Declare user alpha function delegate
58 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
59 delegate float UserAlphaFunctionDelegate(float progress);
61 public void Initialize()
63 Log("Initialize() is called!");
64 Stage stage = Stage.Instance;
65 stage.BackgroundColor = Color.White;
66 stage.Touch += OnStageTouched;
67 stage.Touch += OnStageTouched2;
68 //stage.EventProcessingFinished += OnEventProcessingFinished;
69 stage.Wheel += OnStageWheelEvent;
71 // Add a _text label to the stage
72 _text = new TextLabel("Hello Mono World");
73 _text.ParentOrigin = ParentOrigin.BottomCenter;
74 _text.AnchorPoint = AnchorPoint.BottomCenter;
75 _text.HorizontalAlignment = HorizontalAlignment.Center;
76 _text.PointSize = 32.0f;
77 stage.GetDefaultLayer().Add(_text);
80 _view1.Size = new Vector3(200.0f, 200.0f, 0.0f);
81 _view1.BackgroundColor = Color.Green;
82 _view1.ParentOrigin = ParentOrigin.Center;
83 _view1.AnchorPoint = AnchorPoint.Center;
84 _view1.WidthResizePolicy = ResizePolicyType.Fixed;
85 _view1.HeightResizePolicy = ResizePolicyType.Fixed;
86 _view1.OnStageEvent += OnStage;
87 stage.GetDefaultLayer().Add(_view1);
90 _view2.BackgroundColor = Color.Red;
91 _view2.Size = new Vector3(50.0f, 50.0f, 0.0f);
92 _view2.ParentOrigin = ParentOrigin.TopLeft;
93 _view2.AnchorPoint = AnchorPoint.TopLeft;
94 _view2.WidthResizePolicy = ResizePolicyType.Fixed;
95 _view2.HeightResizePolicy = ResizePolicyType.Fixed;
99 _view3.BackgroundColor = Color.Blue;
100 _view3.Size = new Vector3(50.0f, 50.0f, 0.0f);
101 _view3.ParentOrigin = ParentOrigin.TopLeft;
102 _view3.AnchorPoint = AnchorPoint.TopLeft;
103 _view3.WidthResizePolicy = ResizePolicyType.Fixed;
104 _view3.HeightResizePolicy = ResizePolicyType.Fixed;
107 _user_alpha_func = new UserAlphaFunctionDelegate(body);
112 // User defines alpha function as custom alpha function
113 // Important Notification : when this custom alpha-function is implemented,
114 // the other function call nor other data excess is prevented.
115 // this method must be implemented to calculate the values of input and output purely.
116 // unless, this will cause application crash.
117 float body(float progress)
119 if (progress > 0.2f && progress < 0.7f)
121 return progress + 0.8f;
126 // Callback for _animation finished signal handling
127 public void AnimationFinished(object sender, EventArgs e)
129 Log("AnimationFinished() is called!");
133 public void MyAnimating()
135 // Create a new _animation
142 _animation = new Animation(10000); // 10000 milli-second of duration
143 _animation.AnimateTo(_view2, "Position", new Vector3(150.0f, 150.0f, 0.0f), 5000, 10000, new AlphaFunction(_user_alpha_func));
144 // Connect the signal callback for animaiton finished signal
145 _animation.Finished += AnimationFinished;
146 _animation.EndAction = Animation.EndActions.Discard;
147 // Play the _animation
151 // Callback for stage touched signal handling
152 public void OnStageTouched(object source, Stage.TouchEventArgs e)
154 // Only animate the _text label when touch down happens
155 if (e.Touch.GetState(0) == PointStateType.Down)
157 Log("OnStageTouched() is called! PointStateType.DOWN came!");
162 Log("_animation.Stop() is called!");
167 // Callback for stage touched signal handling
168 public void OnStageTouched2(object source, Stage.TouchEventArgs e)
170 Log("OnStageTouched2() is called!state=" + e.Touch.GetState(0));
173 public void OnEventProcessingFinished(object source)
175 Log("OnEventProcessingFinished() is called!");
178 public void OnStageWheelEvent(object source, Stage.WheelEventArgs e)
180 Log("OnStageWheelEvent() is called!");
181 //Log("OnStageWheelEvent() is called!direction="+ e.WheelEvent.direction + " timeStamp=" + e.WheelEvent.timeStamp );
185 public void OnStage(object source, EventArgs e)
187 Log("OnStage() is called!");
191 static void _Main(string[] args)
193 Log("Main() is called!");
195 Example example = new Example();
198 Log("After MainLoop()");