From: minho.sun Date: Mon, 13 Feb 2017 12:43:34 +0000 (+0900) Subject: Add ValueChanged Event for C# ProgressBar and sample X-Git-Tag: dali_1.2.29~3^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=82f6769c830085ecdf4a32b2d671a96a3430fb4a Add ValueChanged Event for C# ProgressBar and sample 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 --- diff --git a/plugins/dali-swig/SWIG/dali-gc.i b/plugins/dali-swig/SWIG/dali-gc.i index 8017ecc..3ef430c 100644 --- a/plugins/dali-swig/SWIG/dali-gc.i +++ b/plugins/dali-swig/SWIG/dali-gc.i @@ -615,6 +615,9 @@ DALI_CREATE_CUSTOM_DISPOSE_FUNCTION_RENAME( Dali, Signal), AngleThresholdPair); //DALI_CREATE_CUSTOM_DISPOSE_FUNCTION_RENAME( Dali, (std::pair< Dali::Radian, Dali::Radian >), AngleThresholdPair); +DALI_CREATE_CUSTOM_DESTRUCTOR_FUNCTION_RENAME( Dali, Signal, ProgressBarValueChangedSignal); +DALI_CREATE_CUSTOM_DISPOSE_FUNCTION_RENAME( Dali, Signal, ProgressBarValueChangedSignal); + DALI_CREATE_CUSTOM_DESTRUCTOR_FUNCTION( Dali, ApplicationExtensions ); DALI_CREATE_CUSTOM_DISPOSE_FUNCTION( Dali, ApplicationExtensions ); diff --git a/plugins/dali-swig/SWIG/dali-toolkit.i b/plugins/dali-swig/SWIG/dali-toolkit.i index d70cc93..7d83bf8 100755 --- a/plugins/dali-swig/SWIG/dali-toolkit.i +++ b/plugins/dali-swig/SWIG/dali-toolkit.i @@ -311,6 +311,7 @@ typedef Dali::IntrusivePtr RulerPtr; %template(GaussianBlurViewSignal) Dali::Signal; %template(PageTurnSignal) Dali::Signal; %template(PagePanSignal) Dali::Signal; +%template(ProgressBarValueChangedSignal) Dali::Signal; %template(ScrollViewSnapStartedSignal) Dali::Signal< void(const Dali::Toolkit::ScrollView::SnapEvent&)>; %template(ScrollableSignal) Dali::Signal< void(const Dali::Vector2&)>; %template(TextEditorSignal) Dali::Signal; diff --git a/plugins/dali-swig/SWIG/dali.i b/plugins/dali-swig/SWIG/dali.i index 4473091..92bd747 100755 --- a/plugins/dali-swig/SWIG/dali.i +++ b/plugins/dali-swig/SWIG/dali.i @@ -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/progress-bar-event.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 index 0000000..4e1aaf0 --- /dev/null +++ b/plugins/dali-swig/SWIG/events/progress-bar-event.i @@ -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 _progressBarValueChangedEventHandler; + private ValueChangedCallbackDelegate _progressBarValueChangedCallbackDelegate; + + public event DaliEventHandler 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); +} diff --git a/plugins/dali-swig/SWIG/signals.i b/plugins/dali-swig/SWIG/signals.i index 26d869c..0842c9b 100644 --- a/plugins/dali-swig/SWIG/signals.i +++ b/plugins/dali-swig/SWIG/signals.i @@ -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::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& ); diff --git a/plugins/dali-swig/examples/control-dashboard.cs b/plugins/dali-swig/examples/control-dashboard.cs index 0ddd6f1..3ec656e 100755 --- a/plugins/dali-swig/examples/control-dashboard.cs +++ b/plugins/dali-swig/examples/control-dashboard.cs @@ -40,14 +40,16 @@ namespace MyCSharpExample private Dali.Application _application; private TableView _contentContainer; + private Timer _timer; 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), - 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) }; @@ -191,7 +193,33 @@ namespace MyCSharpExample } 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) { @@ -414,6 +442,15 @@ namespace MyCSharpExample 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();