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 mHandle.Add( mHandleValueTextLabel );
577 void Slider::DestroyHandleValueDisplay()
579 UnparentAndReset(mHandleValueTextLabel);
582 void Slider::SetPopupTextColor( const Vector4& color )
584 mPopupTextColor = color;
587 Actor Slider::CreateValueDisplay()
589 Actor popup = Actor::New();
590 popup.SetParentOrigin( ParentOrigin::TOP_CENTER );
591 popup.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
593 mPopupArrow = CreatePopupArrow();
594 popup.Add( mPopupArrow );
596 mPopup = CreatePopup();
597 mPopup.SetSize( 0.0f, VALUE_POPUP_HEIGHT );
598 mPopupArrow.Add( mPopup );
603 Toolkit::Slider::ValueChangedSignalType& Slider::ValueChangedSignal()
605 return mValueChangedSignal;
608 Toolkit::Slider::ValueChangedSignalType& Slider::SlidingFinishedSignal()
610 return mSlidingFinishedSignal;
613 Toolkit::Slider::MarkSignalType& Slider::MarkSignal()
618 void Slider::UpdateSkin()
624 mBacking.SetColor( Color::WHITE );
625 mHandle.SetColor( Color::WHITE );
626 mProgress.SetColor( Color::WHITE );
631 Vector4 disableColor = GetDisableColor();
632 mBacking.SetColor( disableColor );
633 mHandle.SetColor( disableColor );
634 mProgress.SetColor( disableColor );
648 void Slider::CreateChildren()
653 mHitArea = CreateHitRegion();
654 mPanDetector = PanGestureDetector::New();
655 mPanDetector.Attach( mHitArea );
656 mPanDetector.DetectedSignal().Connect( this, &Slider::OnPan );
657 self.Add( mHitArea );
660 mBacking = CreateBacking();
661 self.Add( mBacking );
664 mProgress = CreateProgress();
665 mBacking.Add( mProgress );
668 mHandle = CreateHandle();
669 mBacking.Add( mHandle );
672 void Slider::SetHitRegion( const Vector2& size )
678 mHitArea.SetSize( mHitRegion );
682 const Vector2& Slider::GetHitRegion() const
687 void Slider::AddPopup()
691 mValueDisplay = CreateValueDisplay();
692 mValueDisplay.SetVisible( false );
693 mHandle.Add( mValueDisplay );
695 CreatePopupImage( GetPopupImageName() );
696 CreatePopupArrowImage( GetPopupArrowImageName() );
698 mValueTimer = Timer::New( VALUE_VIEW_SHOW_DURATION );
699 mValueTimer.TickSignal().Connect( this, &Slider::HideValueView );
703 void Slider::RemovePopup()
710 mPopupArrow.Unparent();
713 mValueDisplay.Unparent();
714 mValueDisplay.Reset();
716 mValueTimer.TickSignal().Disconnect( this, &Slider::HideValueView );
722 float Slider::MarkFilter( float value )
724 const float MARK_TOLERANCE = GetMarkTolerance();
727 for( MarkList::SizeType i = 0; i < mMarks.Count(); ++i)
729 const Property::Value& propertyValue = mMarks[i];
730 propertyValue.Get( mark );
731 mark = MapValuePercentage( mark );
733 // If close to a mark, return the mark
734 if( fabsf( mark - value ) < MARK_TOLERANCE )
743 float Slider::SnapToMark( float value )
745 float closestMark = value;
746 float closestDist = std::numeric_limits<float>::max();
749 for( MarkList::SizeType i = 0; i < mMarks.Count(); ++i)
751 const Property::Value& propertyValue = mMarks[i];
752 propertyValue.Get( mark );
753 mark = MapValuePercentage( mark );
755 float dist = fabsf( mark - value );
756 if( dist < closestDist )
766 bool Slider::MarkReached( float value, int& outIndex )
768 const float MARK_TOLERANCE = GetMarkTolerance();
772 tail = mMarks.Size() - 1;
776 while( head <= tail )
778 current = head + ( tail - head ) / 2;
780 const Property::Value& propertyValue = mMarks[ current ];
781 propertyValue.Get( mark );
782 mark = MapValuePercentage( mark );
784 if( fabsf( mark - value ) < MARK_TOLERANCE )
803 bool Slider::HideValueView()
807 mValueDisplay.SetVisible( false );
813 void Slider::SetLowerBound( float bound )
816 DisplayValue( GetValue(), false );
819 float Slider::GetLowerBound() const
824 void Slider::SetUpperBound( float bound )
827 DisplayValue( GetValue(), false );
830 float Slider::GetUpperBound() const
835 void Slider::SetValue( float value )
838 DisplayValue( mValue, true );
841 float Slider::GetValue() const
846 void Slider::SetBackingRegion( const Vector2& region )
848 mBackingRegion = region;
852 mBacking.SetSize( mBackingRegion );
855 ResizeProgressRegion( Vector2( 0.0f, mBackingRegion.y ) );
857 mDomain = CalcDomain( mBackingRegion );
859 DisplayValue( GetValue(), false ); // Set the progress bar to correct width
862 const Vector2& Slider::GetBackingRegion() const
864 return mBackingRegion;
867 void Slider::SetHandleRegion( const Vector2& region )
869 mHandleRegionSize = region;
871 ResizeHandleRegion( mHandleRegionSize );
873 Vector2 hitRegion = GetHitRegion();
874 hitRegion.x += mHandleRegionSize.x;
875 SetHitRegion( hitRegion );
878 const Vector2& Slider::GetHandleRegion() const
880 return mHandleRegionSize;
883 void Slider::SetDisableColor( const Vector4& color )
885 mDisableColor = color;
890 Vector4 Slider::GetDisableColor() const
892 return mDisableColor;
895 Vector4 Slider::GetPopupTextColor() const
897 return mPopupTextColor;
900 void Slider::SetValuePrecision( int precision )
902 mValuePrecision = precision;
905 int Slider::GetValuePrecision() const
907 return mValuePrecision;
910 void Slider::SetShowPopup( bool showPopup )
912 mShowPopup = showPopup;
925 bool Slider::GetShowPopup() const
930 void Slider::SetShowValue( bool showValue )
932 mShowValue = showValue;
936 CreateHandleValueDisplay();
940 DestroyHandleValueDisplay();
944 bool Slider::GetShowValue() const
949 void Slider::SetEnabled( bool enabled )
963 bool Slider::IsEnabled() const
965 return mState != DISABLED;
968 void Slider::SetMarkTolerance( float tolerance )
970 mMarkTolerance = tolerance;
973 float Slider::GetMarkTolerance() const
975 return mMarkTolerance;
978 // Static class method to support script connecting signals
979 bool Slider::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
981 Dali::BaseHandle handle( object );
983 bool connected = true;
984 Toolkit::Slider slider = Toolkit::Slider::DownCast( handle );
986 if( 0 == strcmp( signalName.c_str(), SIGNAL_VALUE_CHANGED ) )
988 slider.ValueChangedSignal().Connect( tracker, functor );
990 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MARK ) )
992 slider.MarkSignal().Connect( tracker, functor );
996 // signalName does not match any signal
1003 void Slider::DisplayPopup( float value )
1005 // Value displayDoConnectSignal
1006 if( mValueTextLabel )
1008 std::stringstream ss;
1009 ss.precision( GetValuePrecision() );
1010 ss << std::fixed << value;
1011 mValueTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, ss.str() );
1015 mValueDisplay.SetVisible( true );
1017 mValueTimer.SetInterval( VALUE_VIEW_SHOW_DURATION );
1022 void Slider::SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value )
1024 Toolkit::Slider slider = Toolkit::Slider::DownCast( Dali::BaseHandle( object ) );
1028 Slider& sliderImpl( GetImpl( slider ) );
1030 switch ( propertyIndex )
1032 case Toolkit::Slider::Property::LOWER_BOUND:
1034 sliderImpl.SetLowerBound( value.Get< float >() );
1038 case Toolkit::Slider::Property::UPPER_BOUND:
1040 sliderImpl.SetUpperBound( value.Get< float >() );
1044 case Toolkit::Slider::Property::VALUE:
1046 sliderImpl.SetValue( value.Get< float >() );
1050 case Toolkit::Slider::Property::HIT_REGION:
1052 sliderImpl.SetHitRegion( value.Get< Vector2 >() );
1056 case Toolkit::Slider::Property::BACKING_REGION:
1058 sliderImpl.SetBackingRegion( value.Get< Vector2 >() );
1062 case Toolkit::Slider::Property::HANDLE_REGION:
1064 sliderImpl.SetHandleRegion( value.Get< Vector2 >() );
1068 case Toolkit::Slider::Property::BACKING_IMAGE_NAME:
1070 sliderImpl.SetBackingImageName( value.Get< std::string >() );
1074 case Toolkit::Slider::Property::HANDLE_IMAGE_NAME:
1076 sliderImpl.SetHandleImageName( value.Get< std::string >() );
1080 case Toolkit::Slider::Property::PROGRESS_IMAGE_NAME:
1082 sliderImpl.SetProgressImageName( value.Get< std::string >() );
1086 case Toolkit::Slider::Property::POPUP_IMAGE_NAME:
1088 sliderImpl.SetPopupImageName( value.Get< std::string >() );
1092 case Toolkit::Slider::Property::POPUP_ARROW_IMAGE_NAME:
1094 sliderImpl.SetPopupArrowImageName( value.Get< std::string >() );
1098 case Toolkit::Slider::Property::DISABLE_COLOR:
1100 sliderImpl.SetDisableColor( value.Get< Vector4 >() );
1104 case Toolkit::Slider::Property::POPUP_TEXT_COLOR:
1106 sliderImpl.SetPopupTextColor( value.Get< Vector4 >() );
1110 case Toolkit::Slider::Property::VALUE_PRECISION:
1112 sliderImpl.SetValuePrecision( value.Get< int >() );
1116 case Toolkit::Slider::Property::SHOW_POPUP:
1118 sliderImpl.SetShowPopup( value.Get< bool >() );
1122 case Toolkit::Slider::Property::SHOW_VALUE:
1124 sliderImpl.SetShowValue( value.Get< bool >() );
1128 case Toolkit::Slider::Property::ENABLED:
1130 sliderImpl.SetEnabled( value.Get< bool >() );
1134 case Toolkit::Slider::Property::MARKS:
1136 sliderImpl.SetMarks( value.Get< Property::Array >() );
1140 case Toolkit::Slider::Property::SNAP_TO_MARKS:
1142 sliderImpl.SetSnapToMarks( value.Get< bool >() );
1146 case Toolkit::Slider::Property::MARK_TOLERANCE:
1148 sliderImpl.SetMarkTolerance( value.Get< float >() );
1155 Property::Value Slider::GetProperty( BaseObject* object, Property::Index propertyIndex )
1157 Property::Value value;
1159 Toolkit::Slider slider = Toolkit::Slider::DownCast( Dali::BaseHandle( object ) );
1163 Slider& sliderImpl( GetImpl( slider ) );
1165 switch ( propertyIndex )
1167 case Toolkit::Slider::Property::LOWER_BOUND:
1169 value = sliderImpl.GetLowerBound();
1173 case Toolkit::Slider::Property::UPPER_BOUND:
1175 value = sliderImpl.GetUpperBound();
1179 case Toolkit::Slider::Property::VALUE:
1181 value = sliderImpl.GetValue();
1185 case Toolkit::Slider::Property::HIT_REGION:
1187 value = sliderImpl.GetHitRegion();
1191 case Toolkit::Slider::Property::BACKING_REGION:
1193 value = sliderImpl.GetBackingRegion();
1197 case Toolkit::Slider::Property::HANDLE_REGION:
1199 value = sliderImpl.GetHandleRegion();
1203 case Toolkit::Slider::Property::BACKING_IMAGE_NAME:
1205 value = sliderImpl.GetBackingImageName();
1209 case Toolkit::Slider::Property::HANDLE_IMAGE_NAME:
1211 value = sliderImpl.GetHandleImageName();
1215 case Toolkit::Slider::Property::PROGRESS_IMAGE_NAME:
1217 value = sliderImpl.GetProgressImageName();
1221 case Toolkit::Slider::Property::POPUP_IMAGE_NAME:
1223 value = sliderImpl.GetPopupImageName();
1227 case Toolkit::Slider::Property::POPUP_ARROW_IMAGE_NAME:
1229 value = sliderImpl.GetPopupArrowImageName();
1233 case Toolkit::Slider::Property::DISABLE_COLOR:
1235 value = sliderImpl.GetDisableColor();
1239 case Toolkit::Slider::Property::POPUP_TEXT_COLOR:
1241 value = sliderImpl.GetPopupTextColor();
1245 case Toolkit::Slider::Property::VALUE_PRECISION:
1247 value = sliderImpl.GetValuePrecision();
1251 case Toolkit::Slider::Property::SHOW_POPUP:
1253 value = sliderImpl.GetShowPopup();
1257 case Toolkit::Slider::Property::SHOW_VALUE:
1259 value = sliderImpl.GetShowValue();
1263 case Toolkit::Slider::Property::ENABLED:
1265 value = sliderImpl.IsEnabled();
1269 case Toolkit::Slider::Property::MARKS:
1271 // TODO: Need to be able to return a PropertyArray
1272 // value = sliderImpl.GetMarks();
1276 case Toolkit::Slider::Property::SNAP_TO_MARKS:
1278 value = sliderImpl.GetSnapToMarks();
1282 case Toolkit::Slider::Property::MARK_TOLERANCE:
1284 value = sliderImpl.GetMarkTolerance();
1293 } // namespace Internal
1295 } // namespace Toolkit