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;
23 namespace MyCSharpExample
27 private Dali.Application _application;
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 Console.WriteLine("[DALI C# SAMPLE] " + str);
39 public Example(Dali.Application application)
41 _application = application;
42 _application.Initialized += Initialize;
45 // Declare user alpha function delegate
46 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
47 delegate float UserAlphaFunctionDelegate(float progress);
49 public void Initialize(object source, NUIApplicationInitEventArgs e)
51 Log("Initialize() is called!");
52 Stage stage = Stage.GetCurrent();
53 stage.BackgroundColor = Color.White;
54 stage.TouchEvent += OnStageTouched;
55 stage.TouchEvent += OnStageTouched2;
56 //stage.EventProcessingFinished += OnEventProcessingFinished;
57 stage.WheelEvent += OnStageWheelEvent;
59 // Add a _text label to the stage
60 _text = new TextLabel("Hello Mono World");
61 _text.ParentOrigin = ParentOrigin.BottomCenter;
62 _text.AnchorPoint = AnchorPoint.BottomCenter;
63 _text.HorizontalAlignment = "CENTER";
64 _text.PointSize = 32.0f;
68 _view1.Size = new Vector3(200.0f, 200.0f, 0.0f);
69 _view1.BackgroundColor = Color.Green;
70 _view1.ParentOrigin = ParentOrigin.Center;
71 _view1.AnchorPoint = AnchorPoint.Center;
72 _view1.SetResizePolicy(ResizePolicyType.FIXED, DimensionType.ALL_DIMENSIONS);
73 _view1.OnStageEvent += OnStage;
77 _view2.BackgroundColor = Color.Red;
78 _view2.Size = new Vector3(50.0f, 50.0f, 0.0f);
79 _view2.ParentOrigin = ParentOrigin.TopLeft;
80 _view2.AnchorPoint = AnchorPoint.TopLeft;
81 _view2.SetResizePolicy(ResizePolicyType.FIXED, DimensionType.ALL_DIMENSIONS);
85 _view3.BackgroundColor = Color.Blue;
86 _view3.Size = new Vector3(50.0f, 50.0f, 0.0f);
87 _view3.ParentOrigin = ParentOrigin.TopLeft;
88 _view3.AnchorPoint = AnchorPoint.TopLeft;
89 _view3.SetResizePolicy(ResizePolicyType.FIXED, DimensionType.ALL_DIMENSIONS);
92 _user_alpha_func = new UserAlphaFunctionDelegate(body);
97 // User defines alpha function as custom alpha function
98 // Important Notification : when this custom alpha-function is implemented,
99 // the other function call nor other data excess is prevented.
100 // this method must be implemented to calculate the values of input and output purely.
101 // unless, this will cause application crash.
102 float body(float progress)
104 if (progress > 0.2f && progress< 0.7f)
106 return progress + 0.8f;
111 // Callback for _animation finished signal handling
112 public void AnimationFinished(object sender, EventArgs e)
114 Log("AnimationFinished() is called!");
118 public void MyAnimating()
120 // Create a new _animation
127 _animation = new Animation(10000); // 10000 milli-second of duration
128 _animation.StartTime = 5000;
129 _animation.EndTime = 10000;
130 _animation.TargetProperty = "Position";
131 _animation.AlphaFunction = new AlphaFunction(_user_alpha_func);
132 _animation.Destination = new Vector3(150.0f, 150.0f, 0.0f);
133 _animation.AnimateTo(_view2);
134 // Connect the signal callback for animaiton finished signal
135 _animation.Finished += AnimationFinished;
136 _animation.EndAction = Animation.EndActions.Discard;
137 // Play the _animation
141 // Callback for stage touched signal handling
142 public void OnStageTouched(object source, Stage.TouchEventArgs e)
144 // Only animate the _text label when touch down happens
145 if( e.TouchData.GetState(0) == PointStateType.DOWN )
147 Log("OnStageTouched() is called! PointStateType.DOWN came!");
152 Log("_animation.Stop() is called!");
157 // Callback for stage touched signal handling
158 public void OnStageTouched2(object source, Stage.TouchEventArgs e)
160 Log("OnStageTouched2() is called!state="+ e.TouchData.GetState(0) );
163 public void OnEventProcessingFinished(object source)
165 Log("OnEventProcessingFinished() is called!");
168 public void OnStageWheelEvent(object source, Stage.WheelEventArgs e)
170 Log("OnStageWheelEvent() is called!");
171 //Log("OnStageWheelEvent() is called!direction="+ e.WheelEvent.direction + " timeStamp=" + e.WheelEvent.timeStamp );
175 public void OnStage(object source , View.OnStageEventArgs e)
177 Log("OnStage() is called!");
180 public void MainLoop()
182 _application.MainLoop ();
186 static void Main(string[] args)
188 Log("Main() is called!");
190 Example example = new Example(Application.NewApplication());
193 Log("After MainLoop()");