2 * Copyright (c) 2014 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 #include <dali-toolkit/internal/controls/slider/slider-impl.h>
22 #include <cstring> // for strcmp
25 #include <dali/public-api/events/touch-event.h>
26 #include <dali/public-api/object/type-registry.h>
27 #include <dali/devel-api/object/type-registry-helper.h>
28 #include <dali/public-api/images/resource-image.h>
31 #include <dali-toolkit/public-api/controls/control-impl.h>
44 namespace // Unnamed namespace
49 return Dali::Toolkit::Slider::New();
52 // Setup properties, signals and actions using the type-registry.
53 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::Slider, Toolkit::Control, Create )
55 DALI_PROPERTY_REGISTRATION( Toolkit, Slider, "lower-bound", FLOAT, LOWER_BOUND )
56 DALI_PROPERTY_REGISTRATION( Toolkit, Slider, "upper-bound", FLOAT, UPPER_BOUND )
57 DALI_PROPERTY_REGISTRATION( Toolkit, Slider, "value", FLOAT, VALUE )
58 DALI_PROPERTY_REGISTRATION( Toolkit, Slider, "hit-region", VECTOR2, HIT_REGION )
59 DALI_PROPERTY_REGISTRATION( Toolkit, Slider, "backing-region", VECTOR2, BACKING_REGION )
60 DALI_PROPERTY_REGISTRATION( Toolkit, Slider, "handle-region", VECTOR2, HANDLE_REGION )
61 DALI_PROPERTY_REGISTRATION( Toolkit, Slider, "backing-image-name", STRING, BACKING_IMAGE_NAME )
62 DALI_PROPERTY_REGISTRATION( Toolkit, Slider, "handle-image-name", STRING, HANDLE_IMAGE_NAME )
63 DALI_PROPERTY_REGISTRATION( Toolkit, Slider, "progress-image-name", STRING, PROGRESS_IMAGE_NAME )
64 DALI_PROPERTY_REGISTRATION( Toolkit, Slider, "popup-image-name", STRING, POPUP_IMAGE_NAME )
65 DALI_PROPERTY_REGISTRATION( Toolkit, Slider, "popup-arrow-image-name", STRING, POPUP_ARROW_IMAGE_NAME )
66 DALI_PROPERTY_REGISTRATION( Toolkit, Slider, "disable-color", VECTOR4, DISABLE_COLOR )
67 DALI_PROPERTY_REGISTRATION( Toolkit, Slider, "popup-text-color", VECTOR4, POPUP_TEXT_COLOR )
68 DALI_PROPERTY_REGISTRATION( Toolkit, Slider, "value-precision", INTEGER, VALUE_PRECISION )
69 DALI_PROPERTY_REGISTRATION( Toolkit, Slider, "show-popup", BOOLEAN, SHOW_POPUP )
70 DALI_PROPERTY_REGISTRATION( Toolkit, Slider, "show-value", BOOLEAN, SHOW_VALUE )
71 DALI_PROPERTY_REGISTRATION( Toolkit, Slider, "enabled", BOOLEAN, ENABLED )
72 DALI_PROPERTY_REGISTRATION( Toolkit, Slider, "marks", ARRAY, MARKS )
73 DALI_PROPERTY_REGISTRATION( Toolkit, Slider, "snap-to-marks", BOOLEAN, SNAP_TO_MARKS )
74 DALI_PROPERTY_REGISTRATION( Toolkit, Slider, "mark-tolerance", FLOAT, MARK_TOLERANCE )
76 DALI_SIGNAL_REGISTRATION( Toolkit, Slider, "value-changed", SIGNAL_VALUE_CHANGED )
77 DALI_SIGNAL_REGISTRATION( Toolkit, Slider, "mark", SIGNAL_MARK )
79 DALI_TYPE_REGISTRATION_END()
81 const float BACKING_Z = -0.1f;
82 const float PROGRESS_Z = 0.1f;
83 const float HANDLE_Z = 1.0f;
84 const float VALUE_TEXT_INCREMENT = 0.01f;
85 const float HANDLE_VALUE_DISPLAY_TEXT_Z = HANDLE_Z + VALUE_TEXT_INCREMENT;
86 const float VALUE_DISPLAY_TEXT_Z = VALUE_TEXT_INCREMENT + VALUE_TEXT_INCREMENT; // Put above HANDLE_VALUE_DISPLAY_TEXT_Z (parented to handle)
88 const float MARK_SNAP_TOLERANCE = 0.05f; // 5% of slider width
90 const int VALUE_VIEW_SHOW_DURATION = 1000; // millisec
91 const int VALUE_VIEW_SHOW_DURATION_LONG = 2000; // millisec
93 const float VALUE_VERTICAL_OFFSET = 48.0f;
95 const float DEFAULT_WIDTH = 0.0f;
96 const float DEFAULT_HEIGHT = 27.0f;
97 const float DEFAULT_HIT_HEIGHT = 72.0f;
98 const float DEFAULT_HANDLE_HEIGHT = DEFAULT_HIT_HEIGHT;
99 const float POPUP_TEXT_PADDING = 10.0f;
101 const char* SKINNED_BACKING_IMAGE_NAME = DALI_IMAGE_DIR "slider-skin.9.png";
102 const char* SKINNED_HANDLE_IMAGE_NAME = DALI_IMAGE_DIR "slider-skin-handle.png";;
103 const char* SKINNED_PROGRESS_IMAGE_NAME = DALI_IMAGE_DIR "slider-skin-progress.9.png";
104 const char* SKINNED_POPUP_IMAGE_NAME = DALI_IMAGE_DIR "slider-popup.9.png";
105 const char* SKINNED_POPUP_ARROW_IMAGE_NAME = DALI_IMAGE_DIR "slider-popup-arrow.png";
107 const Vector2 DEFAULT_HIT_REGION( DEFAULT_WIDTH, DEFAULT_HIT_HEIGHT );
108 const Vector2 DEFAULT_BACKING_REGION( DEFAULT_WIDTH, DEFAULT_HEIGHT );
109 const Vector2 DEFAULT_HANDLE_REGION( DEFAULT_HANDLE_HEIGHT, DEFAULT_HANDLE_HEIGHT );
111 const Vector4 DEFAULT_DISABLE_COLOR( 0.5f, 0.5f, 0.5f, 1.0f );
112 const Vector4 DEFAULT_POPUP_TEXT_COLOR( 0.5f, 0.5f, 0.5f, 1.0f );
114 const float VALUE_POPUP_MARGIN = 10.0f;
115 const float VALUE_POPUP_HEIGHT = 81.0f;
116 const float VALUE_POPUP_MIN_WIDTH = 54.0f;
117 const Vector2 VALUE_POPUP_ARROW_SIZE( 18.0f, 18.0f );
119 const float DEFAULT_LOWER_BOUND = 0.0f;
120 const float DEFAULT_UPPER_BOUND = 1.0f;
121 const float DEFAULT_VALUE = 0.0f;
122 const int DEFAULT_VALUE_PRECISION = 0;
123 const bool DEFAULT_SHOW_POPUP = false;
124 const bool DEFAULT_SHOW_VALUE = true;
125 const bool DEFAULT_ENABLED = true;
126 const bool DEFAULT_SNAP_TO_MARKS = false;
128 } // Unnamed namespace
130 ///////////////////////////////////////////////////////////////////////////////////////////////////
132 ///////////////////////////////////////////////////////////////////////////////////////////////////
134 Dali::Toolkit::Slider Slider::New()
136 // Create the implementation
137 SliderPtr slider( new Slider() );
139 // Pass ownership to CustomActor via derived handle
140 Dali::Toolkit::Slider handle( *slider );
142 // Second-phase init of the implementation
143 // This can only be done after the CustomActor connection has been made...
144 slider->Initialize();
150 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ),
152 mDisableColor( 0.0f, 0.0f, 0.0f, 0.0f ),
153 mPopupTextColor( 0.0f, 0.0f, 0.0f, 0.0f ),
154 mHitRegion( 0.0f, 0.0f ),
155 mBackingRegion( 0.0f, 0.0f ),
156 mHandleRegionSize( 0.0f, 0.0f ),
160 mMarkTolerance( 0.0f ),
161 mValuePrecision( 0 ),
164 mSnapToMarks( false )
172 void Slider::OnInitialize()
180 SetHitRegion( DEFAULT_HIT_REGION );
181 SetBackingRegion( DEFAULT_BACKING_REGION );
182 SetHandleRegion( DEFAULT_HANDLE_REGION );
184 SetBackingImageName( SKINNED_BACKING_IMAGE_NAME );
185 SetHandleImageName( SKINNED_HANDLE_IMAGE_NAME );
186 SetProgressImageName( SKINNED_PROGRESS_IMAGE_NAME );
187 SetPopupImageName( SKINNED_POPUP_IMAGE_NAME );
188 SetPopupArrowImageName( SKINNED_POPUP_ARROW_IMAGE_NAME );
190 SetPopupTextColor( DEFAULT_POPUP_TEXT_COLOR );
192 SetShowPopup( DEFAULT_SHOW_POPUP );
193 SetShowValue( DEFAULT_SHOW_VALUE );
195 SetEnabled( DEFAULT_ENABLED );
196 SetDisableColor( DEFAULT_DISABLE_COLOR );
198 SetSnapToMarks( DEFAULT_SNAP_TO_MARKS );
199 SetMarkTolerance( MARK_SNAP_TOLERANCE );
201 SetLowerBound( DEFAULT_LOWER_BOUND );
202 SetUpperBound( DEFAULT_UPPER_BOUND );
204 SetValuePrecision( DEFAULT_VALUE_PRECISION );
205 mValue = DEFAULT_VALUE;
206 DisplayValue( mValue, false ); // Run this last to display the correct value
208 // Size the Slider actor to a default
209 self.SetSize( DEFAULT_HIT_REGION.x, DEFAULT_HIT_REGION.y );
212 void Slider::OnSizeSet( const Vector3& size )
214 // Factor in handle overshoot into size of backing
215 SetHitRegion( Vector2( size.x, GetHitRegion().y ) );
216 SetBackingRegion( Vector2( size.x - GetHandleRegion().x, GetBackingRegion().y ) );
219 bool Slider::OnTouchEvent(Actor actor, const TouchEvent& event)
221 if( mState != DISABLED )
223 TouchPoint::State touchState = event.GetPoint(0).state;
225 if( touchState == TouchPoint::Down )
229 float percentage = MapPercentage( event.GetPoint(0).local );
230 float value = MapBounds( ( GetSnapToMarks() ) ? SnapToMark( percentage ) : MarkFilter( percentage ), GetLowerBound(), GetUpperBound() );
232 DisplayPopup( value );
234 else if( touchState == TouchPoint::Up)
236 if( mState == PRESSED )
239 mSlidingFinishedSignal.Emit( Toolkit::Slider::DownCast( Self() ), GetValue() );
247 void Slider::OnPan( Actor actor, const PanGesture& gesture )
249 // gesture.position is in local actor coordinates
250 if( mState != DISABLED )
252 switch( gesture.state )
254 case Gesture::Continuing:
256 if( mState == PRESSED )
258 float value = MapBounds( MarkFilter ( MapPercentage( gesture.position ) ), GetLowerBound(), GetUpperBound() );
260 DisplayPopup( value );
264 case Gesture::Finished:
266 if( mState == PRESSED )
268 if( GetSnapToMarks() )
270 float value = MapBounds( SnapToMark( MapPercentage( gesture.position ) ), GetLowerBound(), GetUpperBound() );
272 DisplayPopup( value );
274 mSlidingFinishedSignal.Emit( Toolkit::Slider::DownCast( Self() ), GetValue() );
288 float Slider::HitSpaceToDomain( float x )
290 float halfRegionWidth = GetHitRegion().x * 0.5f;
291 float halfDomainWidth = ( mDomain.to.x - mDomain.from.x ) * 0.5f;
292 float endDiff = halfRegionWidth - halfDomainWidth;
297 float Slider::MapPercentage( const Vector2& point )
299 return Clamp( ( HitSpaceToDomain( point.x ) - mDomain.from.x ) / ( mDomain.to.x - mDomain.from.x ), 0.0f, 1.0f );
302 float Slider::MapValuePercentage( float value )
304 return ( value - GetLowerBound() ) / ( GetUpperBound() - GetLowerBound() );
307 float Slider::MapBounds( float percent, float lowerBound, float upperBound )
309 return lowerBound + percent * ( upperBound - lowerBound );
312 Slider::Domain Slider::CalcDomain( const Vector2& currentSize )
314 return Domain( Vector2( 0.0f, 0.0f ), currentSize );
317 void Slider::DisplayValue( float value, bool raiseSignals )
319 float clampledValue = Clamp( value, GetLowerBound(), GetUpperBound() );
321 float percent = MapValuePercentage( clampledValue );
323 float x = mDomain.from.x + percent * ( mDomain.to.x - mDomain.from.x );
325 mHandle.SetPosition( x, 0.0f, HANDLE_Z );
330 mProgress.SetSize( x, GetBackingRegion().y );
336 Toolkit::Slider self = Toolkit::Slider::DownCast( Self() );
337 mValueChangedSignal.Emit( self, clampledValue );
340 if( MarkReached( percent, markIndex ) )
342 mMarkSignal.Emit( self, markIndex );
346 if( mHandleValueTextLabel )
348 std::stringstream ss;
349 ss.precision( GetValuePrecision() );
350 ss << std::fixed << clampledValue;
352 mHandleValueTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, ss.str() );
356 void Slider::SetMarks( const MarkList& marks )
361 const Slider::MarkList& Slider::GetMarks() const
366 void Slider::SetSnapToMarks( bool snap )
371 bool Slider::GetSnapToMarks() const
376 Actor Slider::CreateHitRegion()
378 Actor hitRegion = Actor::New();
379 hitRegion.SetParentOrigin( ParentOrigin::CENTER );
380 hitRegion.SetAnchorPoint( AnchorPoint::CENTER );
381 hitRegion.TouchedSignal().Connect( this, &Slider::OnTouchEvent );
386 ImageActor Slider::CreateBacking()
388 ImageActor backing = ImageActor::New();
389 backing.SetParentOrigin( ParentOrigin::CENTER );
390 backing.SetAnchorPoint( AnchorPoint::CENTER );
391 backing.SetZ( BACKING_Z );
396 void Slider::SetBackingImageName( const std::string& imageName )
398 if( mBacking && ( imageName.size() > 0 ) )
400 Image image = ResourceImage::New( imageName );
401 mBacking.SetImage( image );
405 std::string Slider::GetBackingImageName()
409 return ResourceImage::DownCast( mBacking.GetImage() ).GetUrl();
412 return std::string( "" );
415 ImageActor Slider::CreateProgress()
417 ImageActor progress = ImageActor::New();
418 progress.SetParentOrigin( ParentOrigin::CENTER_LEFT );
419 progress.SetAnchorPoint( AnchorPoint::CENTER_LEFT );
420 progress.SetZ( PROGRESS_Z );
425 void Slider::SetProgressImageName( const std::string& imageName )
427 if( mProgress && ( imageName.size() > 0 ) )
429 Image image = ResourceImage::New( imageName );
430 mProgress.SetImage( image );
434 std::string Slider::GetProgressImageName()
438 return ResourceImage::DownCast( mProgress.GetImage()).GetUrl();
441 return std::string( "" );
444 void Slider::SetPopupImageName( const std::string& imageName )
446 mPopupImageName = imageName;
449 std::string Slider::GetPopupImageName()
451 return mPopupImageName;
454 void Slider::CreatePopupImage( const std::string& imageName )
456 if( mPopup && ( imageName.size() > 0 ) )
458 Image image = ResourceImage::New( imageName );
459 mPopup.SetImage( image );
463 void Slider::SetPopupArrowImageName( const std::string& imageName )
465 mPopupArrowImageName = imageName;
468 std::string Slider::GetPopupArrowImageName()
470 return mPopupArrowImageName;
473 void Slider::CreatePopupArrowImage( const std::string& imageName )
475 if( mPopupArrow && ( imageName.size() > 0 ) )
477 Image image = ResourceImage::New( imageName );
478 mPopupArrow.SetImage( image );
482 void Slider::ResizeProgressRegion( const Vector2& region )
486 mProgress.SetSize( region );
490 ImageActor Slider::CreateHandle()
492 ImageActor handle = ImageActor::New();
493 handle.SetParentOrigin( ParentOrigin::CENTER_LEFT );
494 handle.SetAnchorPoint( AnchorPoint::CENTER );
495 handle.SetZ( HANDLE_Z );
500 ImageActor Slider::CreatePopupArrow()
502 ImageActor arrow = ImageActor::New();
503 arrow.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
504 arrow.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
505 arrow.SetZ( HANDLE_Z );
510 Toolkit::TextLabel Slider::CreatePopupText()
512 Toolkit::TextLabel textLabel = Toolkit::TextLabel::New();
513 textLabel.SetParentOrigin( ParentOrigin::CENTER );
514 textLabel.SetAnchorPoint( AnchorPoint::CENTER );
515 textLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
516 textLabel.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
517 textLabel.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
518 textLabel.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, DEFAULT_POPUP_TEXT_COLOR );
519 textLabel.SetZ( VALUE_DISPLAY_TEXT_Z );
520 textLabel.SetPadding( Padding( POPUP_TEXT_PADDING, POPUP_TEXT_PADDING, 0.0f, 0.0f ) );
524 ImageActor Slider::CreatePopup()
526 ImageActor popup = ImageActor::New();
527 popup.SetParentOrigin( ParentOrigin::TOP_CENTER );
528 popup.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
529 popup.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::WIDTH );
531 mValueTextLabel = CreatePopupText();
532 popup.Add( mValueTextLabel );
537 void Slider::SetHandleImageName( const std::string& imageName )
539 if( mHandle && ( imageName.size() > 0 ) )
541 Image image = ResourceImage::New( imageName );
542 mHandle.SetImage( image );
546 std::string Slider::GetHandleImageName()
550 return ResourceImage::DownCast( mHandle.GetImage() ).GetUrl();
553 return std::string( "" );
556 void Slider::ResizeHandleRegion( const Vector2& region )
560 mHandle.SetSize( region );
564 void Slider::CreateHandleValueDisplay()
566 if( mHandle && !mHandleValueTextLabel )
568 mHandleValueTextLabel = Toolkit::TextLabel::New();
569 mHandleValueTextLabel.SetParentOrigin( ParentOrigin::CENTER );
570 mHandleValueTextLabel.SetAnchorPoint( AnchorPoint::CENTER );
571 mHandleValueTextLabel.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
572 mHandleValueTextLabel.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
573 mHandleValueTextLabel.SetDrawMode( DrawMode::OVERLAY );
574 mHandle.Add( mHandleValueTextLabel );
578 void Slider::DestroyHandleValueDisplay()
580 UnparentAndReset(mHandleValueTextLabel);
583 void Slider::SetPopupTextColor( const Vector4& color )
585 mPopupTextColor = color;
588 Actor Slider::CreateValueDisplay()
590 Actor popup = Actor::New();
591 popup.SetParentOrigin( ParentOrigin::TOP_CENTER );
592 popup.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
594 mPopupArrow = CreatePopupArrow();
595 popup.Add( mPopupArrow );
597 mPopup = CreatePopup();
598 mPopup.SetSize( 0.0f, VALUE_POPUP_HEIGHT );
599 mPopupArrow.Add( mPopup );
604 Toolkit::Slider::ValueChangedSignalType& Slider::ValueChangedSignal()
606 return mValueChangedSignal;
609 Toolkit::Slider::ValueChangedSignalType& Slider::SlidingFinishedSignal()
611 return mSlidingFinishedSignal;
614 Toolkit::Slider::MarkSignalType& Slider::MarkSignal()
619 void Slider::UpdateSkin()
625 mBacking.SetColor( Color::WHITE );
626 mHandle.SetColor( Color::WHITE );
627 mProgress.SetColor( Color::WHITE );
632 Vector4 disableColor = GetDisableColor();
633 mBacking.SetColor( disableColor );
634 mHandle.SetColor( disableColor );
635 mProgress.SetColor( disableColor );
649 void Slider::CreateChildren()
654 mHitArea = CreateHitRegion();
655 mPanDetector = PanGestureDetector::New();
656 mPanDetector.Attach( mHitArea );
657 mPanDetector.DetectedSignal().Connect( this, &Slider::OnPan );
658 self.Add( mHitArea );
661 mBacking = CreateBacking();
662 self.Add( mBacking );
665 mProgress = CreateProgress();
666 mBacking.Add( mProgress );
669 mHandle = CreateHandle();
670 mBacking.Add( mHandle );
673 void Slider::SetHitRegion( const Vector2& size )
679 mHitArea.SetSize( mHitRegion );
683 const Vector2& Slider::GetHitRegion() const
688 void Slider::AddPopup()
692 mValueDisplay = CreateValueDisplay();
693 mValueDisplay.SetVisible( false );
694 mHandle.Add( mValueDisplay );
696 CreatePopupImage( GetPopupImageName() );
697 CreatePopupArrowImage( GetPopupArrowImageName() );
699 mValueTimer = Timer::New( VALUE_VIEW_SHOW_DURATION );
700 mValueTimer.TickSignal().Connect( this, &Slider::HideValueView );
704 void Slider::RemovePopup()
711 mPopupArrow.Unparent();
714 mValueDisplay.Unparent();
715 mValueDisplay.Reset();
717 mValueTimer.TickSignal().Disconnect( this, &Slider::HideValueView );
723 float Slider::MarkFilter( float value )
725 const float MARK_TOLERANCE = GetMarkTolerance();
728 for( MarkList::SizeType i = 0; i < mMarks.Count(); ++i)
730 const Property::Value& propertyValue = mMarks[i];
731 propertyValue.Get( mark );
732 mark = MapValuePercentage( mark );
734 // If close to a mark, return the mark
735 if( fabsf( mark - value ) < MARK_TOLERANCE )
744 float Slider::SnapToMark( float value )
746 float closestMark = value;
747 float closestDist = std::numeric_limits<float>::max();
750 for( MarkList::SizeType i = 0; i < mMarks.Count(); ++i)
752 const Property::Value& propertyValue = mMarks[i];
753 propertyValue.Get( mark );
754 mark = MapValuePercentage( mark );
756 float dist = fabsf( mark - value );
757 if( dist < closestDist )
767 bool Slider::MarkReached( float value, int& outIndex )
769 const float MARK_TOLERANCE = GetMarkTolerance();
773 tail = mMarks.Size() - 1;
777 while( head <= tail )
779 current = head + ( tail - head ) / 2;
781 const Property::Value& propertyValue = mMarks[ current ];
782 propertyValue.Get( mark );
783 mark = MapValuePercentage( mark );
785 if( fabsf( mark - value ) < MARK_TOLERANCE )
804 bool Slider::HideValueView()
808 mValueDisplay.SetVisible( false );
814 void Slider::SetLowerBound( float bound )
817 DisplayValue( GetValue(), false );
820 float Slider::GetLowerBound() const
825 void Slider::SetUpperBound( float bound )
828 DisplayValue( GetValue(), false );
831 float Slider::GetUpperBound() const
836 void Slider::SetValue( float value )
839 DisplayValue( mValue, true );
842 float Slider::GetValue() const
847 void Slider::SetBackingRegion( const Vector2& region )
849 mBackingRegion = region;
853 mBacking.SetSize( mBackingRegion );
856 ResizeProgressRegion( Vector2( 0.0f, mBackingRegion.y ) );
858 mDomain = CalcDomain( mBackingRegion );
860 DisplayValue( GetValue(), false ); // Set the progress bar to correct width
863 const Vector2& Slider::GetBackingRegion() const
865 return mBackingRegion;
868 void Slider::SetHandleRegion( const Vector2& region )
870 mHandleRegionSize = region;
872 ResizeHandleRegion( mHandleRegionSize );
874 Vector2 hitRegion = GetHitRegion();
875 hitRegion.x += mHandleRegionSize.x;
876 SetHitRegion( hitRegion );
879 const Vector2& Slider::GetHandleRegion() const
881 return mHandleRegionSize;
884 void Slider::SetDisableColor( const Vector4& color )
886 mDisableColor = color;
891 Vector4 Slider::GetDisableColor() const
893 return mDisableColor;
896 Vector4 Slider::GetPopupTextColor() const
898 return mPopupTextColor;
901 void Slider::SetValuePrecision( int precision )
903 mValuePrecision = precision;
906 int Slider::GetValuePrecision() const
908 return mValuePrecision;
911 void Slider::SetShowPopup( bool showPopup )
913 mShowPopup = showPopup;
926 bool Slider::GetShowPopup() const
931 void Slider::SetShowValue( bool showValue )
933 mShowValue = showValue;
937 CreateHandleValueDisplay();
941 DestroyHandleValueDisplay();
945 bool Slider::GetShowValue() const
950 void Slider::SetEnabled( bool enabled )
964 bool Slider::IsEnabled() const
966 return mState != DISABLED;
969 void Slider::SetMarkTolerance( float tolerance )
971 mMarkTolerance = tolerance;
974 float Slider::GetMarkTolerance() const
976 return mMarkTolerance;
979 // Static class method to support script connecting signals
980 bool Slider::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
982 Dali::BaseHandle handle( object );
984 bool connected = true;
985 Toolkit::Slider slider = Toolkit::Slider::DownCast( handle );
987 if( 0 == strcmp( signalName.c_str(), SIGNAL_VALUE_CHANGED ) )
989 slider.ValueChangedSignal().Connect( tracker, functor );
991 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MARK ) )
993 slider.MarkSignal().Connect( tracker, functor );
997 // signalName does not match any signal
1004 void Slider::DisplayPopup( float value )
1006 // Value displayDoConnectSignal
1007 if( mValueTextLabel )
1009 std::stringstream ss;
1010 ss.precision( GetValuePrecision() );
1011 ss << std::fixed << value;
1012 mValueTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, ss.str() );
1016 mValueDisplay.SetVisible( true );
1018 mValueTimer.SetInterval( VALUE_VIEW_SHOW_DURATION );
1023 void Slider::SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value )
1025 Toolkit::Slider slider = Toolkit::Slider::DownCast( Dali::BaseHandle( object ) );
1029 Slider& sliderImpl( GetImpl( slider ) );
1031 switch ( propertyIndex )
1033 case Toolkit::Slider::Property::LOWER_BOUND:
1035 sliderImpl.SetLowerBound( value.Get< float >() );
1039 case Toolkit::Slider::Property::UPPER_BOUND:
1041 sliderImpl.SetUpperBound( value.Get< float >() );
1045 case Toolkit::Slider::Property::VALUE:
1047 sliderImpl.SetValue( value.Get< float >() );
1051 case Toolkit::Slider::Property::HIT_REGION:
1053 sliderImpl.SetHitRegion( value.Get< Vector2 >() );
1057 case Toolkit::Slider::Property::BACKING_REGION:
1059 sliderImpl.SetBackingRegion( value.Get< Vector2 >() );
1063 case Toolkit::Slider::Property::HANDLE_REGION:
1065 sliderImpl.SetHandleRegion( value.Get< Vector2 >() );
1069 case Toolkit::Slider::Property::BACKING_IMAGE_NAME:
1071 sliderImpl.SetBackingImageName( value.Get< std::string >() );
1075 case Toolkit::Slider::Property::HANDLE_IMAGE_NAME:
1077 sliderImpl.SetHandleImageName( value.Get< std::string >() );
1081 case Toolkit::Slider::Property::PROGRESS_IMAGE_NAME:
1083 sliderImpl.SetProgressImageName( value.Get< std::string >() );
1087 case Toolkit::Slider::Property::POPUP_IMAGE_NAME:
1089 sliderImpl.SetPopupImageName( value.Get< std::string >() );
1093 case Toolkit::Slider::Property::POPUP_ARROW_IMAGE_NAME:
1095 sliderImpl.SetPopupArrowImageName( value.Get< std::string >() );
1099 case Toolkit::Slider::Property::DISABLE_COLOR:
1101 sliderImpl.SetDisableColor( value.Get< Vector4 >() );
1105 case Toolkit::Slider::Property::POPUP_TEXT_COLOR:
1107 sliderImpl.SetPopupTextColor( value.Get< Vector4 >() );
1111 case Toolkit::Slider::Property::VALUE_PRECISION:
1113 sliderImpl.SetValuePrecision( value.Get< int >() );
1117 case Toolkit::Slider::Property::SHOW_POPUP:
1119 sliderImpl.SetShowPopup( value.Get< bool >() );
1123 case Toolkit::Slider::Property::SHOW_VALUE:
1125 sliderImpl.SetShowValue( value.Get< bool >() );
1129 case Toolkit::Slider::Property::ENABLED:
1131 sliderImpl.SetEnabled( value.Get< bool >() );
1135 case Toolkit::Slider::Property::MARKS:
1137 sliderImpl.SetMarks( value.Get< Property::Array >() );
1141 case Toolkit::Slider::Property::SNAP_TO_MARKS:
1143 sliderImpl.SetSnapToMarks( value.Get< bool >() );
1147 case Toolkit::Slider::Property::MARK_TOLERANCE:
1149 sliderImpl.SetMarkTolerance( value.Get< float >() );
1156 Property::Value Slider::GetProperty( BaseObject* object, Property::Index propertyIndex )
1158 Property::Value value;
1160 Toolkit::Slider slider = Toolkit::Slider::DownCast( Dali::BaseHandle( object ) );
1164 Slider& sliderImpl( GetImpl( slider ) );
1166 switch ( propertyIndex )
1168 case Toolkit::Slider::Property::LOWER_BOUND:
1170 value = sliderImpl.GetLowerBound();
1174 case Toolkit::Slider::Property::UPPER_BOUND:
1176 value = sliderImpl.GetUpperBound();
1180 case Toolkit::Slider::Property::VALUE:
1182 value = sliderImpl.GetValue();
1186 case Toolkit::Slider::Property::HIT_REGION:
1188 value = sliderImpl.GetHitRegion();
1192 case Toolkit::Slider::Property::BACKING_REGION:
1194 value = sliderImpl.GetBackingRegion();
1198 case Toolkit::Slider::Property::HANDLE_REGION:
1200 value = sliderImpl.GetHandleRegion();
1204 case Toolkit::Slider::Property::BACKING_IMAGE_NAME:
1206 value = sliderImpl.GetBackingImageName();
1210 case Toolkit::Slider::Property::HANDLE_IMAGE_NAME:
1212 value = sliderImpl.GetHandleImageName();
1216 case Toolkit::Slider::Property::PROGRESS_IMAGE_NAME:
1218 value = sliderImpl.GetProgressImageName();
1222 case Toolkit::Slider::Property::POPUP_IMAGE_NAME:
1224 value = sliderImpl.GetPopupImageName();
1228 case Toolkit::Slider::Property::POPUP_ARROW_IMAGE_NAME:
1230 value = sliderImpl.GetPopupArrowImageName();
1234 case Toolkit::Slider::Property::DISABLE_COLOR:
1236 value = sliderImpl.GetDisableColor();
1240 case Toolkit::Slider::Property::POPUP_TEXT_COLOR:
1242 value = sliderImpl.GetPopupTextColor();
1246 case Toolkit::Slider::Property::VALUE_PRECISION:
1248 value = sliderImpl.GetValuePrecision();
1252 case Toolkit::Slider::Property::SHOW_POPUP:
1254 value = sliderImpl.GetShowPopup();
1258 case Toolkit::Slider::Property::SHOW_VALUE:
1260 value = sliderImpl.GetShowValue();
1264 case Toolkit::Slider::Property::ENABLED:
1266 value = sliderImpl.IsEnabled();
1270 case Toolkit::Slider::Property::MARKS:
1272 // TODO: Need to be able to return a PropertyArray
1273 // value = sliderImpl.GetMarks();
1277 case Toolkit::Slider::Property::SNAP_TO_MARKS:
1279 value = sliderImpl.GetSnapToMarks();
1283 case Toolkit::Slider::Property::MARK_TOLERANCE:
1285 value = sliderImpl.GetMarkTolerance();
1294 } // namespace Internal
1296 } // namespace Toolkit