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.Constants;
23 namespace UserAlphaFunctionTest
25 class Example : NUIApplication
27 private Animation _animation;
28 private TextLabel _text;
29 private View _view1, _view2, _view3;
30 private UserAlphaFunctionDelegate _user_alpha_func;
33 public static void Log(string str)
35 Console.WriteLine("[DALI C# SAMPLE] " + str);
38 public Example() : base()
42 public Example(string stylesheet) : base(stylesheet)
46 public Example(string stylesheet, WindowMode windowMode) : base(stylesheet, windowMode)
50 protected override void OnCreate()
56 // Declare user alpha function delegate
57 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
58 delegate float UserAlphaFunctionDelegate(float progress);
60 public void Initialize()
62 Log("Initialize() is called!");
63 Stage stage = Stage.Instance;
64 stage.BackgroundColor = Color.White;
65 stage.Touch += OnStageTouched;
66 stage.Touch += OnStageTouched2;
67 //stage.EventProcessingFinished += OnEventProcessingFinished;
68 stage.Wheel += OnStageWheelEvent;
70 // Add a _text label to the stage
71 _text = new TextLabel("Hello Mono World");
72 _text.ParentOrigin = ParentOrigin.BottomCenter;
73 _text.AnchorPoint = AnchorPoint.BottomCenter;
74 _text.HorizontalAlignment = "CENTER";
75 _text.PointSize = 32.0f;
76 stage.GetDefaultLayer().Add(_text);
79 _view1.Size = new Vector3(200.0f, 200.0f, 0.0f);
80 _view1.BackgroundColor = Color.Green;
81 _view1.ParentOrigin = ParentOrigin.Center;
82 _view1.AnchorPoint = AnchorPoint.Center;
83 _view1.WidthResizePolicy = ResizePolicyType.Fixed;
84 _view1.HeightResizePolicy = ResizePolicyType.Fixed;
85 _view1.OnStageEvent += OnStage;
86 stage.GetDefaultLayer().Add(_view1);
89 _view2.BackgroundColor = Color.Red;
90 _view2.Size = new Vector3(50.0f, 50.0f, 0.0f);
91 _view2.ParentOrigin = ParentOrigin.TopLeft;
92 _view2.AnchorPoint = AnchorPoint.TopLeft;
93 _view2.WidthResizePolicy = ResizePolicyType.Fixed;
94 _view2.HeightResizePolicy = ResizePolicyType.Fixed;
98 _view3.BackgroundColor = Color.Blue;
99 _view3.Size = new Vector3(50.0f, 50.0f, 0.0f);
100 _view3.ParentOrigin = ParentOrigin.TopLeft;
101 _view3.AnchorPoint = AnchorPoint.TopLeft;
102 _view3.WidthResizePolicy = ResizePolicyType.Fixed;
103 _view3.HeightResizePolicy = ResizePolicyType.Fixed;
106 _user_alpha_func = new UserAlphaFunctionDelegate(body);
111 // User defines alpha function as custom alpha function
112 // Important Notification : when this custom alpha-function is implemented,
113 // the other function call nor other data excess is prevented.
114 // this method must be implemented to calculate the values of input and output purely.
115 // unless, this will cause application crash.
116 float body(float progress)
118 if (progress > 0.2f && progress < 0.7f)
120 return progress + 0.8f;
125 // Callback for _animation finished signal handling
126 public void AnimationFinished(object sender, EventArgs e)
128 Log("AnimationFinished() is called!");
132 public void MyAnimating()
134 // Create a new _animation
141 _animation = new Animation(10000); // 10000 milli-second of duration
142 _animation.AnimateTo(_view2, "Position", new Vector3(150.0f, 150.0f, 0.0f), 5000, 10000, new AlphaFunction(_user_alpha_func));
143 // Connect the signal callback for animaiton finished signal
144 _animation.Finished += AnimationFinished;
145 _animation.EndAction = Animation.EndActions.Discard;
146 // Play the _animation
150 // Callback for stage touched signal handling
151 public void OnStageTouched(object source, Stage.TouchEventArgs e)
153 // Only animate the _text label when touch down happens
154 if (e.Touch.GetState(0) == PointStateType.Down)
156 Log("OnStageTouched() is called! PointStateType.DOWN came!");
161 Log("_animation.Stop() is called!");
166 // Callback for stage touched signal handling
167 public void OnStageTouched2(object source, Stage.TouchEventArgs e)
169 Log("OnStageTouched2() is called!state=" + e.Touch.GetState(0));
172 public void OnEventProcessingFinished(object source)
174 Log("OnEventProcessingFinished() is called!");
177 public void OnStageWheelEvent(object source, Stage.WheelEventArgs e)
179 Log("OnStageWheelEvent() is called!");
180 //Log("OnStageWheelEvent() is called!direction="+ e.WheelEvent.direction + " timeStamp=" + e.WheelEvent.timeStamp );
184 public void OnStage(object source, EventArgs e)
186 Log("OnStage() is called!");
190 static void _Main(string[] args)
192 Log("Main() is called!");
194 Example example = new Example();
197 Log("After MainLoop()");