Add ValueChanged Event for C# ProgressBar and sample 00/114500/3
authorminho.sun <minho.sun@samsung.com>
Mon, 13 Feb 2017 12:43:34 +0000 (21:43 +0900)
committerminho.sun <minho.sun@samsung.com>
Mon, 27 Feb 2017 04:15:50 +0000 (13:15 +0900)
Convert ValueChangedSignal to ValueChanged Event for C# ProgressBar.
To check it works fine, add sample in control-dashboard app

Change-Id: I3c32b340f223d7c4755ef8816123637080bc7d99
Signed-off-by: minho.sun <minho.sun@samsung.com>
plugins/dali-swig/SWIG/dali-gc.i
plugins/dali-swig/SWIG/dali-toolkit.i
plugins/dali-swig/SWIG/dali.i
plugins/dali-swig/SWIG/events/progress-bar-event.i [new file with mode: 0644]
plugins/dali-swig/SWIG/signals.i
plugins/dali-swig/examples/control-dashboard.cs

index 8017ecc..3ef430c 100644 (file)
@@ -615,6 +615,9 @@ DALI_CREATE_CUSTOM_DISPOSE_FUNCTION_RENAME( Dali, Signal<void (const Dali::Touch
 //DALI_CREATE_CUSTOM_DESTRUCTOR_FUNCTION_RENAME( Dali, (std::pair< Dali::Radian, Dali::Radian >), AngleThresholdPair);
 //DALI_CREATE_CUSTOM_DISPOSE_FUNCTION_RENAME( Dali, (std::pair< Dali::Radian, Dali::Radian >), AngleThresholdPair);
 
 //DALI_CREATE_CUSTOM_DESTRUCTOR_FUNCTION_RENAME( Dali, (std::pair< Dali::Radian, Dali::Radian >), AngleThresholdPair);
 //DALI_CREATE_CUSTOM_DISPOSE_FUNCTION_RENAME( Dali, (std::pair< Dali::Radian, Dali::Radian >), AngleThresholdPair);
 
+DALI_CREATE_CUSTOM_DESTRUCTOR_FUNCTION_RENAME( Dali, Signal<void(Dali::Toolkit::ProgressBar, float, float)>, ProgressBarValueChangedSignal);
+DALI_CREATE_CUSTOM_DISPOSE_FUNCTION_RENAME( Dali, Signal<void(Dali::Toolkit::ProgressBar, float, float)>, ProgressBarValueChangedSignal);
+
 DALI_CREATE_CUSTOM_DESTRUCTOR_FUNCTION( Dali, ApplicationExtensions );
 DALI_CREATE_CUSTOM_DISPOSE_FUNCTION( Dali, ApplicationExtensions );
 
 DALI_CREATE_CUSTOM_DESTRUCTOR_FUNCTION( Dali, ApplicationExtensions );
 DALI_CREATE_CUSTOM_DISPOSE_FUNCTION( Dali, ApplicationExtensions );
 
index d70cc93..7d83bf8 100755 (executable)
@@ -311,6 +311,7 @@ typedef Dali::IntrusivePtr<Dali::Toolkit::Ruler> RulerPtr;
 %template(GaussianBlurViewSignal) Dali::Signal<void (Dali::Toolkit::GaussianBlurView)>;
 %template(PageTurnSignal) Dali::Signal<void(Dali::Toolkit::PageTurnView, unsigned int, bool)>;
 %template(PagePanSignal) Dali::Signal<void(Dali::Toolkit::PageTurnView)>;
 %template(GaussianBlurViewSignal) Dali::Signal<void (Dali::Toolkit::GaussianBlurView)>;
 %template(PageTurnSignal) Dali::Signal<void(Dali::Toolkit::PageTurnView, unsigned int, bool)>;
 %template(PagePanSignal) Dali::Signal<void(Dali::Toolkit::PageTurnView)>;
+%template(ProgressBarValueChangedSignal) Dali::Signal<void(Dali::Toolkit::ProgressBar, float, float)>;
 %template(ScrollViewSnapStartedSignal) Dali::Signal< void(const Dali::Toolkit::ScrollView::SnapEvent&)>;
 %template(ScrollableSignal) Dali::Signal< void(const Dali::Vector2&)>;
 %template(TextEditorSignal) Dali::Signal<void(Dali::Toolkit::TextEditor)>;
 %template(ScrollViewSnapStartedSignal) Dali::Signal< void(const Dali::Toolkit::ScrollView::SnapEvent&)>;
 %template(ScrollableSignal) Dali::Signal< void(const Dali::Vector2&)>;
 %template(TextEditorSignal) Dali::Signal<void(Dali::Toolkit::TextEditor)>;
index 4473091..92bd747 100755 (executable)
@@ -265,6 +265,7 @@ using namespace Dali::Toolkit;
 %include events/pinchgesture-event.i
 %include events/pageturnview-event.i
 %include events/pangesture-event.i
 %include events/pinchgesture-event.i
 %include events/pageturnview-event.i
 %include events/pangesture-event.i
+%include events/progress-bar-event.i
 %include events/propertynotification-event.i
 %include events/longpressgesture-event.i
 %include events/rectangle.i
 %include events/propertynotification-event.i
 %include events/longpressgesture-event.i
 %include events/rectangle.i
diff --git a/plugins/dali-swig/SWIG/events/progress-bar-event.i b/plugins/dali-swig/SWIG/events/progress-bar-event.i
new file mode 100644 (file)
index 0000000..4e1aaf0
--- /dev/null
@@ -0,0 +1,146 @@
+/*
+ * 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.
+ *
+ */
+
+%define PROGRESS_BAR_EVENTHANDLER_TYPEMAP_EVENTARG(NameSpace, ClassName)
+%typemap(csimports) NameSpace::ClassName %{
+using System;
+using System.Runtime.InteropServices;
+
+%}
+%enddef
+
+%define PROGRESS_BAR_EVENTHANDLER_TYPEMAP_HELPER(NameSpace, ClassName)
+%typemap(cscode) NameSpace::ClassName %{
+
+public class ValueChangedEventArgs : EventArgs
+{
+   private ProgressBar _progressBar;
+   private float _progressValue;
+   private float _secondaryProgressValue;
+
+   public ProgressBar ProgressBar
+   {
+      get
+      {
+         return _progressBar;
+      }
+      set
+      {
+         _progressBar = value;
+      }
+   }
+
+   public float ProgressValue
+   {
+      get
+      {
+         return _progressValue;
+      }
+      set
+      {
+         _progressValue = value;
+      }
+   }
+
+   public float SecondaryProgressValue
+   {
+      get
+      {
+         return _secondaryProgressValue;
+      }
+      set
+      {
+         _secondaryProgressValue = value;
+      }
+   }
+
+}
+
+  [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+  private delegate void ValueChangedCallbackDelegate(IntPtr progressBar, float progressValue, float secondaryProgressValue);
+  private DaliEventHandler<object,ValueChangedEventArgs> _progressBarValueChangedEventHandler;
+  private ValueChangedCallbackDelegate _progressBarValueChangedCallbackDelegate;
+
+  public event DaliEventHandler<object,ValueChangedEventArgs> ValueChanged
+  {
+     add
+     {
+        lock(this)
+        {
+           // Restricted to only one listener
+           if (_progressBarValueChangedEventHandler == null)
+           {
+              _progressBarValueChangedEventHandler += value;
+
+              _progressBarValueChangedCallbackDelegate = new ValueChangedCallbackDelegate(OnValueChanged);
+              this.ValueChangedSignal().Connect(_progressBarValueChangedCallbackDelegate);
+           }
+        }
+     }
+
+     remove
+     {
+        lock(this)
+        {
+           if (_progressBarValueChangedEventHandler != null)
+           {
+              this.ValueChangedSignal().Disconnect(_progressBarValueChangedCallbackDelegate);
+           }
+
+           _progressBarValueChangedEventHandler -= value;
+        }
+     }
+  }
+
+  // Callback for ProgressBar ValueChanged signal
+  private void OnValueChanged(IntPtr progressBar, float progressValue, float secondaryProgressValue)
+  {
+     ValueChangedEventArgs e = new ValueChangedEventArgs();
+
+     // Populate all members of "e" (ValueChangedEventArgs) with real page
+     e.ProgressBar = ProgressBar.GetProgressBarFromPtr( progressBar );
+     e.ProgressValue = progressValue;
+     e.SecondaryProgressValue = secondaryProgressValue;
+
+     if (_progressBarValueChangedEventHandler != null)
+     {
+       _progressBarValueChangedEventHandler(this, e);
+     }
+  }
+
+  public static ClassName Get ## ClassName ## FromPtr(global::System.IntPtr cPtr) {
+    ClassName ret = new ClassName(cPtr, false);
+   if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+    return ret;
+  }
+
+%}
+
+%enddef
+
+
+%define DALI_PROGRESS_BAR_EVENTHANDLER_PARAM( NameSpace, ClassName)
+
+  PROGRESS_BAR_EVENTHANDLER_TYPEMAP_EVENTARG( NameSpace, ClassName);
+  PROGRESS_BAR_EVENTHANDLER_TYPEMAP_HELPER( NameSpace, ClassName);
+
+%enddef
+
+namespace Dali
+{
+  DALI_PROGRESS_BAR_EVENTHANDLER_PARAM( Dali::Toolkit, ProgressBar);
+}
index 26d869c..0842c9b 100644 (file)
@@ -361,6 +361,9 @@ DALI_SIGNAL_3_PARAM( Dali::Toolkit::PageTurnView, unsigned int, bool );
 // void Signal< Dali::Toolkit::PageTurnView >;
 DALI_SIGNAL_1_PARAM( Dali::Toolkit::PageTurnView );
 
 // void Signal< Dali::Toolkit::PageTurnView >;
 DALI_SIGNAL_1_PARAM( Dali::Toolkit::PageTurnView );
 
+// void Signal< Dali::Toolkit::ProgressBar, float, float >;
+DALI_SIGNAL_3_PARAM( Dali::Toolkit::ProgressBar, float, float );
+
 // void Signal< const Dali::Toolkit::ScrollView::SnapEvent& >;
 DALI_SIGNAL_1_PARAM( const Dali::Toolkit::ScrollView::SnapEvent& );
 
 // void Signal< const Dali::Toolkit::ScrollView::SnapEvent& >;
 DALI_SIGNAL_1_PARAM( const Dali::Toolkit::ScrollView::SnapEvent& );
 
index 0ddd6f1..3ec656e 100755 (executable)
@@ -40,14 +40,16 @@ namespace MyCSharpExample
 
     private Dali.Application _application;
     private TableView _contentContainer;
 
     private Dali.Application _application;
     private TableView _contentContainer;
+    private Timer _timer;
     private Stage _stage;
     private Popup _popup;
     private Stage _stage;
     private Popup _popup;
+    private ProgressBar _progressBar;
 
     // List of items
     private Item[] mViewList = {
       new Item("PushButton", true),  new Item("DropDown", false),    new Item("Toggle", true),
       new Item("InputField", false),  new Item("AnimateGif", false),  new Item("Loading", false),
 
     // List of items
     private Item[] mViewList = {
       new Item("PushButton", true),  new Item("DropDown", false),    new Item("Toggle", true),
       new Item("InputField", false),  new Item("AnimateGif", false),  new Item("Loading", false),
-      new Item("ProgressBar", false), new Item("CheckBox", false),    new Item("RadioButton", true),
+      new Item("ProgressBar", true), new Item("CheckBox", false),    new Item("RadioButton", true),
       new Item("Tooltip", true),     new Item("Popup", true),       new Item("Toast", true),
       new Item("ItemView", false),    new Item("CheckBox", true)
     };
       new Item("Tooltip", true),     new Item("Popup", true),       new Item("Toast", true),
       new Item("ItemView", false),    new Item("CheckBox", true)
     };
@@ -191,7 +193,33 @@ namespace MyCSharpExample
         }
         if (item.name.CompareTo("ProgressBar") == 0)
         {
         }
         if (item.name.CompareTo("ProgressBar") == 0)
         {
+          _progressBar = new ProgressBar();
+          _progressBar.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.WIDTH);
+          _progressBar.SetResizePolicy(ResizePolicyType.FIXED, DimensionType.HEIGHT);
+          _progressBar.SetSize( 0, 50 );
 
 
+          _progressBar.ValueChanged += OnProgressBarValueChanged;
+
+          _timer = new Timer( 100 );
+          _timer.Tick += ( obj, e ) =>
+          {
+            float progress = (float)Math.Round( _progressBar.ProgressValue , 2 );
+
+            if( progress == 1.0f )
+            {
+              _progressBar.ProgressValue = 0.0f;
+              _progressBar.SecondaryProgressValue = 0.01f;
+            }
+            else
+            {
+              _progressBar.ProgressValue = progress + 0.01f;
+              _progressBar.SecondaryProgressValue = progress + 0.21f;
+            }
+            return true;
+          };
+          _timer.Start();
+
+          _contentContainer.AddChild(_progressBar, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
         }
         if (item.name.CompareTo("ScrollBar") == 0)
         {
         }
         if (item.name.CompareTo("ScrollBar") == 0)
         {
@@ -414,6 +442,15 @@ namespace MyCSharpExample
       return cancelButton;
     }
 
       return cancelButton;
     }
 
+    void OnProgressBarValueChanged( object source, ProgressBar.ValueChangedEventArgs e )
+    {
+      Property.Map labelVisual = new Property.Map();
+      labelVisual.Add( Dali.Constants.Visual.Property.Type, new Property.Value((int)Dali.Constants.Visual.Type.Text) )
+        .Add( Dali.Constants.TextVisualProperty.Text, new Property.Value( Math.Round( e.ProgressBar.ProgressValue, 2 ) +" / "+Math.Round( e.ProgressBar.SecondaryProgressValue, 2 )) );
+      e.ProgressBar.LabelVisual = labelVisual;
+      return;
+    }
+
     public void MainLoop()
     {
       _application.MainLoop();
     public void MainLoop()
     {
       _application.MainLoop();