1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
18 using System.Runtime.InteropServices;
22 namespace MyCSharpExample
26 private Dali.Application _application;
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(Dali.Application application)
40 _application = application;
41 _application.Initialized += Initialize;
44 // Declare user alpha function delegate
45 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
46 delegate float UserAlphaFunctionDelegate(float progress);
48 public void Initialize(object source, NUIApplicationInitEventArgs e)
50 Log("Initialize() is called!");
51 Stage stage = Stage.GetCurrent();
52 stage.BackgroundColor = Color.White;
53 stage.Touch += OnStageTouched;
54 stage.Touch += OnStageTouched2;
55 stage.Wheel += OnStageWheelEvent;
57 // Add a _text label to the stage
58 _text = new TextLabel("Hello Mono World");
59 _text.ParentOrigin = ParentOrigin.BottomCenter;
60 _text.AnchorPoint = AnchorPoint.BottomCenter;
61 _text.HorizontalAlignment = "CENTER";
62 _text.PointSize = 32.0f;
66 _view1.Size = new Vector3(200.0f, 200.0f, 0.0f);
67 _view1.BackgroundColor = Color.Green;
68 _view1.ParentOrigin = ParentOrigin.Center;
69 _view1.AnchorPoint = AnchorPoint.Center;
70 _view1.SetResizePolicy(ResizePolicyType.FIXED, DimensionType.ALL_DIMENSIONS);
71 _view1.OnStageEvent += OnStage;
75 _view2.BackgroundColor = Color.Red;
76 _view2.Size = new Vector3(50.0f, 50.0f, 0.0f);
77 _view2.ParentOrigin = ParentOrigin.TopLeft;
78 _view2.AnchorPoint = AnchorPoint.TopLeft;
79 _view2.SetResizePolicy(ResizePolicyType.FIXED, DimensionType.ALL_DIMENSIONS);
83 _view3.BackgroundColor = Color.Blue;
84 _view3.Size = new Vector3(50.0f, 50.0f, 0.0f);
85 _view3.ParentOrigin = ParentOrigin.TopLeft;
86 _view3.AnchorPoint = AnchorPoint.TopLeft;
87 _view3.SetResizePolicy(ResizePolicyType.FIXED, DimensionType.ALL_DIMENSIONS);
90 _user_alpha_func = new UserAlphaFunctionDelegate(body);
95 // User defines alpha function as custom alpha function
96 // Important Notification : when this custom alpha-function is implemented,
97 // the other function call nor other data excess is prevented.
98 // this method must be implemented to calculate the values of input and output purely.
99 // unless, this will cause application crash.
100 float body(float progress)
102 if (progress > 0.2f && progress < 0.7f)
104 return progress + 0.8f;
109 // Callback for _animation finished signal handling
110 public void AnimationFinished(object sender, EventArgs e)
112 Log("AnimationFinished() is called!");
116 public void MyAnimating()
118 // Create a new _animation
125 _animation = new Animation(10000); // 10000 milli-second of duration
126 _animation.StartTime = 5000;
127 _animation.EndTime = 10000;
128 _animation.TargetProperty = "Position";
129 _animation.AlphaFunction = new AlphaFunction(_user_alpha_func);
130 _animation.Destination = new Vector3(150.0f, 150.0f, 0.0f);
131 _animation.AnimateTo(_view2);
132 // Connect the signal callback for animaiton finished signal
133 _animation.Finished += AnimationFinished;
134 _animation.EndAction = Animation.EndActions.Discard;
135 // Play the _animation
139 // Callback for stage touched signal handling
140 public void OnStageTouched(object source, Stage.TouchEventArgs e)
142 // Only animate the _text label when touch down happens
143 if (e.Touch.GetState(0) == PointStateType.DOWN)
145 Log("OnStageTouched() is called! PointStateType.DOWN came!");
150 Log("_animation.Stop() is called!");
155 // Callback for stage touched signal handling
156 public void OnStageTouched2(object source, Stage.TouchEventArgs e)
158 Log("OnStageTouched2() is called!state=" + e.Touch.GetState(0));
161 public void OnEventProcessingFinished(object source)
163 Log("OnEventProcessingFinished() is called!");
166 public void OnStageWheelEvent(object source, Stage.WheelEventArgs e)
168 Log("OnStageWheelEvent() is called!");
172 public void OnStage(object source, View.OnStageEventArgs e)
174 Log("OnStage() is called!");
177 public void MainLoop()
179 _application.MainLoop();
183 static void Main(string[] args)
185 Log("Main() is called!");
187 Example example = new Example(Application.NewApplication());
190 Log("After MainLoop()");