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;
22 namespace MyCSharpExample
26 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
27 delegate void CallbackDelegate(IntPtr data);
29 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
30 delegate void TouchCallbackDelegate(IntPtr data);
32 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
33 delegate void AnimationCallbackDelegate(IntPtr data);
35 private Dali.Application _application;
37 private Animation _animation;
38 private TextLabel _text;
40 public Example(Dali.Application application)
42 _application = application;
44 CallbackDelegate initializeCallback = new CallbackDelegate( Initialize );
45 _application.InitSignal().Connect( initializeCallback );
48 private void Initialize(IntPtr appPtr)
50 Stage stage = Stage.GetCurrent();
51 stage.SetBackgroundColor( NDalic.WHITE );
53 // Connect the signal callback for stage touched signal
54 TouchCallbackDelegate stageTouchedCallback = new TouchCallbackDelegate( OnStageTouched );
55 stage.TouchSignal().Connect( stageTouchedCallback );
57 // Add a _text label to the stage
58 _text = new TextLabel("Hello Mono World");
59 _text.ParentOrigin = NDalic.ParentOriginCenter;
60 _text.AnchorPoint = NDalic.AnchorPointCenter;
61 _text.HorizontalAlignment = "CENTER";
62 _text.PointSize = 32.0f;
67 // Callback for _animation finished signal handling
68 private void AnimationFinished(IntPtr data)
70 Animation _animation = Animation.GetAnimationFromPtr( data );
71 Console.WriteLine("Animation finished: duration = " + _animation.GetDuration());
74 // Callback for stage touched signal handling
75 private void OnStageTouched(IntPtr data)
77 TouchData touchData = TouchData.GetTouchDataFromPtr( data );
79 // Only animate the _text label when touch down happens
80 if( touchData.GetState(0) == PointStateType.DOWN )
82 // Create a new _animation
88 _animation = new Animation(1.0f); // 1 second of duration
90 _animation.AnimateTo(new Property(_text, Actor.Property.ORIENTATION), new Property.Value(new Quaternion( new Radian( new Degree( 180.0f ) ), Vector3.XAXIS )), new AlphaFunction(AlphaFunction.BuiltinFunction.LINEAR), new TimePeriod(0.0f, 0.5f));
91 _animation.AnimateTo(new Property(_text, Actor.Property.ORIENTATION), new Property.Value(new Quaternion( new Radian( new Degree( 0.0f ) ), Vector3.XAXIS )), new AlphaFunction(AlphaFunction.BuiltinFunction.LINEAR), new TimePeriod(0.5f, 0.5f));
93 // Connect the signal callback for animaiton finished signal
94 AnimationCallbackDelegate animFinishedDelegate = new AnimationCallbackDelegate( AnimationFinished );
95 _animation.FinishedSignal().Connect( animFinishedDelegate );
97 // Play the _animation
102 public void MainLoop()
104 _application.MainLoop ();
108 /// The main entry point for the application.
112 static void Main(string[] args)
114 Console.WriteLine ("Hello Mono World");
116 Example example = new Example(Application.NewApplication());