Size, Position, Color high level class added
[platform/core/uifw/dali-toolkit.git] / plugins / dali-swig / examples / hello-world.cs
index c2caeb5..60c7791 100755 (executable)
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
+* Copyright (c) 2016 Samsung Electronics Co., Ltd.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
 
 using System;
 using System.Runtime.InteropServices;
 using Dali;
+using Dali.Constants;
 
 namespace MyCSharpExample
 {
     class Example
     {
-        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
-        delegate void CallbackDelegate(IntPtr data);
-
-        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
-        delegate void TouchCallbackDelegate(IntPtr data);
-
-        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
-        delegate void AnimationCallbackDelegate(IntPtr data);
-
         private Dali.Application _application;
-
         private Animation _animation;
         private TextLabel _text;
+        private Stage _stage;
 
         public Example(Dali.Application application)
         {
             _application = application;
-            _application.Initialized += new Dali.AUIApplicationInitEventHandler(Initialize);
+            _application.Initialized += Initialize;
         }
 
-        public void Initialize(object source, AUIApplicationInitEventArgs e)
+        public void Initialize(object source, NUIApplicationInitEventArgs e)
         {
             Console.WriteLine("Customized Application Initialize event handler");
-            Stage stage = Stage.GetCurrent();
-            stage.BackgroundColor = NDalic.WHITE;
-
-            stage.Touched += new Dali.Stage.TouchEventHandler(OnStageTouched);
+            _stage = Stage.Instance;
+            _stage.BackgroundColor = Color.White;
+            _stage.Touch += OnStageTouched;
 
             // Add a _text label to the stage
             _text = new TextLabel("Hello Mono World");
-            _text.ParentOrigin = NDalic.ParentOriginCenter;
-            _text.AnchorPoint = NDalic.AnchorPointCenter;
+            _text.ParentOrigin = ParentOrigin.Center;
+            _text.AnchorPoint = AnchorPoint.Center;
             _text.HorizontalAlignment = "CENTER";
             _text.PointSize = 32.0f;
+            _text.TextColor = Color.Magenta;
+            _stage.Add(_text);
 
-            stage.Add(_text);
+            _animation = new Animation
+            {
+                StartTime = 0,
+                EndTime = 500,
+                TargetProperty = "Orientation",
+                Destination = new Rotation(new Radian(new Degree(180.0f)), PositionAxis.X)
+            };
+            _animation.AnimateTo(_text);
+
+            _animation.StartTime = 500;
+            _animation.EndTime = 1000;
+            _animation.TargetProperty = "Orientation";
+            _animation.Destination = new Rotation(new Radian(new Degree(0.0f)), PositionAxis.X);
+            _animation.AnimateTo(_text);
+
+            _animation.StartTime = 1000;
+            _animation.EndTime = 1500;
+            _animation.TargetProperty = "ScaleX";
+            _animation.Destination = 3.0f;
+            _animation.AnimateBy(_text);
+
+            _animation.StartTime = 1500;
+            _animation.EndTime = 2000;
+            _animation.TargetProperty = "ScaleY";
+            _animation.Destination = 4.0f;
+            _animation.AnimateBy(_text);
+
+            _animation.EndAction = Animation.EndActions.Discard;
+
+            // Connect the signal callback for animaiton finished signal
+            _animation.Finished += AnimationFinished;
         }
 
         // Callback for _animation finished signal handling
-        public void AnimationFinished(object source, Animation.FinishedEventArgs e)
+        public void AnimationFinished(object sender, EventArgs e)
         {
-            Console.WriteLine("Customized Animation Finished Event handler");
-            Console.WriteLine("Animation finished: duration = " + e.Animation.Duration);
+            Console.WriteLine("AnimationFinished()!");
+            if (_animation)
+            {
+                Console.WriteLine("Duration= " + _animation.Duration);
+                Console.WriteLine("EndAction= " + _animation.EndAction);
+            }
         }
 
         // Callback for stage touched signal handling
-        public void OnStageTouched(object source, Stage.TouchEventArgs e)
+        public void OnStageTouched(object sender, Stage.TouchEventArgs e)
         {
-            //TouchData touchData = TouchData.GetTouchDataFromPtr( data );
-
             // Only animate the _text label when touch down happens
-            if( e.TouchData.GetState(0) == PointStateType.DOWN )
+            if (e.Touch.GetState(0) == PointStateType.DOWN)
             {
                 Console.WriteLine("Customized Stage Touch event handler");
+
                 // Create a new _animation
-                if( _animation )
+                if (_animation)
                 {
-                    _animation.Reset();
+                    _animation.Stop();
                 }
-
-                _animation = new Animation(1.0f); // 1 second of duration
-
-                _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));
-                _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));
-
-                // Connect the signal callback for animaiton finished signal
-      _animation.Finished += new Dali.Animation.FinishedEventHandler(AnimationFinished);
-
                 // Play the _animation
                 _animation.Play();
             }
@@ -98,20 +115,20 @@ namespace MyCSharpExample
 
         public void MainLoop()
         {
-            _application.MainLoop ();
+            _application.MainLoop();
         }
 
         /// <summary>
         /// The main entry point for the application.
         /// </summary>
-
         [STAThread]
         static void Main(string[] args)
         {
-            Console.WriteLine ("Hello Mono World");
+            Console.WriteLine("Main() called!");
 
             Example example = new Example(Application.NewApplication());
-            example.MainLoop ();
+            example.MainLoop();
         }
     }
 }
+