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/public-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::OnControlSizeSet( 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 )
359 for( MarkList::const_iterator it = marks.begin(), itEnd = marks.end(); it != itEnd; ++it )
361 const Property::Value& propertyValue = *it;
362 propertyValue.Get( value );
364 mMarks.push_back( value );
368 const Slider::MarkList& Slider::GetMarks() const
373 void Slider::SetSnapToMarks( bool snap )
378 bool Slider::GetSnapToMarks() const
383 Actor Slider::CreateHitRegion()
385 Actor hitRegion = Actor::New();
386 hitRegion.SetParentOrigin( ParentOrigin::CENTER );
387 hitRegion.SetAnchorPoint( AnchorPoint::CENTER );
388 hitRegion.TouchedSignal().Connect( this, &Slider::OnTouchEvent );
393 ImageActor Slider::CreateBacking()
395 ImageActor backing = ImageActor::New();
396 backing.SetParentOrigin( ParentOrigin::CENTER );
397 backing.SetAnchorPoint( AnchorPoint::CENTER );
398 backing.SetZ( BACKING_Z );
403 void Slider::SetBackingImageName( const std::string& imageName )
405 if( mBacking && ( imageName.size() > 0 ) )
407 Image image = ResourceImage::New( imageName );
408 mBacking.SetImage( image );
412 std::string Slider::GetBackingImageName()
416 return ResourceImage::DownCast( mBacking.GetImage() ).GetUrl();
419 return std::string( "" );
422 ImageActor Slider::CreateProgress()
424 ImageActor progress = ImageActor::New();
425 progress.SetParentOrigin( ParentOrigin::CENTER_LEFT );
426 progress.SetAnchorPoint( AnchorPoint::CENTER_LEFT );
427 progress.SetZ( PROGRESS_Z );
432 void Slider::SetProgressImageName( const std::string& imageName )
434 if( mProgress && ( imageName.size() > 0 ) )
436 Image image = ResourceImage::New( imageName );
437 mProgress.SetImage( image );
441 std::string Slider::GetProgressImageName()
445 return ResourceImage::DownCast( mProgress.GetImage()).GetUrl();
448 return std::string( "" );
451 void Slider::SetPopupImageName( const std::string& imageName )
453 mPopupImageName = imageName;
456 std::string Slider::GetPopupImageName()
458 return mPopupImageName;
461 void Slider::CreatePopupImage( const std::string& imageName )
463 if( mPopup && ( imageName.size() > 0 ) )
465 Image image = ResourceImage::New( imageName );
466 mPopup.SetImage( image );
470 void Slider::SetPopupArrowImageName( const std::string& imageName )
472 mPopupArrowImageName = imageName;
475 std::string Slider::GetPopupArrowImageName()
477 return mPopupArrowImageName;
480 void Slider::CreatePopupArrowImage( const std::string& imageName )
482 if( mPopupArrow && ( imageName.size() > 0 ) )
484 Image image = ResourceImage::New( imageName );
485 mPopupArrow.SetImage( image );
489 void Slider::ResizeProgressRegion( const Vector2& region )
493 mProgress.SetSize( region );
497 ImageActor Slider::CreateHandle()
499 ImageActor handle = ImageActor::New();
500 handle.SetParentOrigin( ParentOrigin::CENTER_LEFT );
501 handle.SetAnchorPoint( AnchorPoint::CENTER );
502 handle.SetZ( HANDLE_Z );
507 ImageActor Slider::CreatePopupArrow()
509 ImageActor arrow = ImageActor::New();
510 arrow.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
511 arrow.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
512 arrow.SetZ( HANDLE_Z );
517 Toolkit::TextLabel Slider::CreatePopupText()
519 Toolkit::TextLabel textLabel = Toolkit::TextLabel::New();
520 textLabel.SetParentOrigin( ParentOrigin::CENTER );
521 textLabel.SetAnchorPoint( AnchorPoint::CENTER );
522 textLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
523 textLabel.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
524 textLabel.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
525 textLabel.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, DEFAULT_POPUP_TEXT_COLOR );
526 textLabel.SetZ( VALUE_DISPLAY_TEXT_Z );
527 textLabel.SetPadding( Padding( POPUP_TEXT_PADDING, POPUP_TEXT_PADDING, 0.0f, 0.0f ) );
531 ImageActor Slider::CreatePopup()
533 ImageActor popup = ImageActor::New();
534 popup.SetParentOrigin( ParentOrigin::TOP_CENTER );
535 popup.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
536 popup.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::WIDTH );
538 mValueTextLabel = CreatePopupText();
539 popup.Add( mValueTextLabel );
544 void Slider::SetHandleImageName( const std::string& imageName )
546 if( mHandle && ( imageName.size() > 0 ) )
548 Image image = ResourceImage::New( imageName );
549 mHandle.SetImage( image );
553 std::string Slider::GetHandleImageName()
557 return ResourceImage::DownCast( mHandle.GetImage() ).GetUrl();
560 return std::string( "" );
563 void Slider::ResizeHandleRegion( const Vector2& region )
567 mHandle.SetSize( region );
571 void Slider::CreateHandleValueDisplay()
573 if( mHandle && !mHandleValueTextLabel )
575 mHandleValueTextLabel = Toolkit::TextLabel::New();
576 mHandleValueTextLabel.SetParentOrigin( ParentOrigin::CENTER );
577 mHandleValueTextLabel.SetAnchorPoint( AnchorPoint::CENTER );
578 mHandleValueTextLabel.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
579 mHandleValueTextLabel.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
580 mHandleValueTextLabel.SetDrawMode( DrawMode::OVERLAY );
581 mHandle.Add( mHandleValueTextLabel );
585 void Slider::DestroyHandleValueDisplay()
587 UnparentAndReset(mHandleValueTextLabel);
590 void Slider::SetPopupTextColor( const Vector4& color )
592 mPopupTextColor = color;
595 Actor Slider::CreateValueDisplay()
597 Actor popup = Actor::New();
598 popup.SetParentOrigin( ParentOrigin::TOP_CENTER );
599 popup.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
601 mPopupArrow = CreatePopupArrow();
602 popup.Add( mPopupArrow );
604 mPopup = CreatePopup();
605 mPopup.SetSize( 0.0f, VALUE_POPUP_HEIGHT );
606 mPopupArrow.Add( mPopup );
611 Toolkit::Slider::ValueChangedSignalType& Slider::ValueChangedSignal()
613 return mValueChangedSignal;
616 Toolkit::Slider::ValueChangedSignalType& Slider::SlidingFinishedSignal()
618 return mSlidingFinishedSignal;
621 Toolkit::Slider::MarkSignalType& Slider::MarkSignal()
626 void Slider::UpdateSkin()
632 mBacking.SetColor( Color::WHITE );
633 mHandle.SetColor( Color::WHITE );
634 mProgress.SetColor( Color::WHITE );
639 Vector4 disableColor = GetDisableColor();
640 mBacking.SetColor( disableColor );
641 mHandle.SetColor( disableColor );
642 mProgress.SetColor( disableColor );
656 void Slider::CreateChildren()
661 mHitArea = CreateHitRegion();
662 mPanDetector = PanGestureDetector::New();
663 mPanDetector.Attach( mHitArea );
664 mPanDetector.DetectedSignal().Connect( this, &Slider::OnPan );
665 self.Add( mHitArea );
668 mBacking = CreateBacking();
669 self.Add( mBacking );
672 mProgress = CreateProgress();
673 mBacking.Add( mProgress );
676 mHandle = CreateHandle();
677 mBacking.Add( mHandle );
680 void Slider::SetHitRegion( const Vector2& size )
686 mHitArea.SetSize( mHitRegion );
690 const Vector2& Slider::GetHitRegion() const
695 void Slider::AddPopup()
699 mValueDisplay = CreateValueDisplay();
700 mValueDisplay.SetVisible( false );
701 mHandle.Add( mValueDisplay );
703 CreatePopupImage( GetPopupImageName() );
704 CreatePopupArrowImage( GetPopupArrowImageName() );
706 mValueTimer = Timer::New( VALUE_VIEW_SHOW_DURATION );
707 mValueTimer.TickSignal().Connect( this, &Slider::HideValueView );
711 void Slider::RemovePopup()
718 mPopupArrow.Unparent();
721 mValueDisplay.Unparent();
722 mValueDisplay.Reset();
724 mValueTimer.TickSignal().Disconnect( this, &Slider::HideValueView );
730 float Slider::MarkFilter( float value )
732 const float MARK_TOLERANCE = GetMarkTolerance();
735 for( MarkList::iterator it = mMarks.begin(), itEnd = mMarks.end(); it != itEnd; ++it )
737 const Property::Value& propertyValue = *it;
738 propertyValue.Get( mark );
739 mark = MapValuePercentage( mark );
741 // If close to a mark, return the mark
742 if( fabsf( mark - value ) < MARK_TOLERANCE )
751 float Slider::SnapToMark( float value )
753 float closestMark = value;
754 float closestDist = std::numeric_limits<float>::max();
757 for( MarkList::iterator it = mMarks.begin(), itEnd = mMarks.end(); it != itEnd; ++it )
759 const Property::Value& propertyValue = *it;
760 propertyValue.Get( mark );
761 mark = MapValuePercentage( mark );
763 float dist = fabsf( mark - value );
764 if( dist < closestDist )
774 bool Slider::MarkReached( float value, int& outIndex )
776 const float MARK_TOLERANCE = GetMarkTolerance();
780 tail = mMarks.size() - 1;
784 while( head <= tail )
786 current = head + ( tail - head ) / 2;
788 const Property::Value& propertyValue = mMarks[ current ];
789 propertyValue.Get( mark );
790 mark = MapValuePercentage( mark );
792 if( fabsf( mark - value ) < MARK_TOLERANCE )
811 bool Slider::HideValueView()
815 mValueDisplay.SetVisible( false );
821 void Slider::SetLowerBound( float bound )
824 DisplayValue( GetValue(), false );
827 float Slider::GetLowerBound() const
832 void Slider::SetUpperBound( float bound )
835 DisplayValue( GetValue(), false );
838 float Slider::GetUpperBound() const
843 void Slider::SetValue( float value )
846 DisplayValue( mValue, true );
849 float Slider::GetValue() const
854 void Slider::SetBackingRegion( const Vector2& region )
856 mBackingRegion = region;
860 mBacking.SetSize( mBackingRegion );
863 ResizeProgressRegion( Vector2( 0.0f, mBackingRegion.y ) );
865 mDomain = CalcDomain( mBackingRegion );
867 DisplayValue( GetValue(), false ); // Set the progress bar to correct width
870 const Vector2& Slider::GetBackingRegion() const
872 return mBackingRegion;
875 void Slider::SetHandleRegion( const Vector2& region )
877 mHandleRegionSize = region;
879 ResizeHandleRegion( mHandleRegionSize );
881 Vector2 hitRegion = GetHitRegion();
882 hitRegion.x += mHandleRegionSize.x;
883 SetHitRegion( hitRegion );
886 const Vector2& Slider::GetHandleRegion() const
888 return mHandleRegionSize;
891 void Slider::SetDisableColor( const Vector4& color )
893 mDisableColor = color;
898 Vector4 Slider::GetDisableColor() const
900 return mDisableColor;
903 Vector4 Slider::GetPopupTextColor() const
905 return mPopupTextColor;
908 void Slider::SetValuePrecision( int precision )
910 mValuePrecision = precision;
913 int Slider::GetValuePrecision() const
915 return mValuePrecision;
918 void Slider::SetShowPopup( bool showPopup )
920 mShowPopup = showPopup;
933 bool Slider::GetShowPopup() const
938 void Slider::SetShowValue( bool showValue )
940 mShowValue = showValue;
944 CreateHandleValueDisplay();
948 DestroyHandleValueDisplay();
952 bool Slider::GetShowValue() const
957 void Slider::SetEnabled( bool enabled )
971 bool Slider::IsEnabled() const
973 return mState != DISABLED;
976 void Slider::SetMarkTolerance( float tolerance )
978 mMarkTolerance = tolerance;
981 float Slider::GetMarkTolerance() const
983 return mMarkTolerance;
986 // Static class method to support script connecting signals
987 bool Slider::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
989 Dali::BaseHandle handle( object );
991 bool connected = true;
992 Toolkit::Slider slider = Toolkit::Slider::DownCast( handle );
994 if( 0 == strcmp( signalName.c_str(), SIGNAL_VALUE_CHANGED ) )
996 slider.ValueChangedSignal().Connect( tracker, functor );
998 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MARK ) )
1000 slider.MarkSignal().Connect( tracker, functor );
1004 // signalName does not match any signal
1011 void Slider::DisplayPopup( float value )
1013 // Value displayDoConnectSignal
1014 if( mValueTextLabel )
1016 std::stringstream ss;
1017 ss.precision( GetValuePrecision() );
1018 ss << std::fixed << value;
1019 mValueTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, ss.str() );
1023 mValueDisplay.SetVisible( true );
1025 mValueTimer.SetInterval( VALUE_VIEW_SHOW_DURATION );
1030 void Slider::SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value )
1032 Toolkit::Slider slider = Toolkit::Slider::DownCast( Dali::BaseHandle( object ) );
1036 Slider& sliderImpl( GetImpl( slider ) );
1038 switch ( propertyIndex )
1040 case Toolkit::Slider::Property::LOWER_BOUND:
1042 sliderImpl.SetLowerBound( value.Get< float >() );
1046 case Toolkit::Slider::Property::UPPER_BOUND:
1048 sliderImpl.SetUpperBound( value.Get< float >() );
1052 case Toolkit::Slider::Property::VALUE:
1054 sliderImpl.SetValue( value.Get< float >() );
1058 case Toolkit::Slider::Property::HIT_REGION:
1060 sliderImpl.SetHitRegion( value.Get< Vector2 >() );
1064 case Toolkit::Slider::Property::BACKING_REGION:
1066 sliderImpl.SetBackingRegion( value.Get< Vector2 >() );
1070 case Toolkit::Slider::Property::HANDLE_REGION:
1072 sliderImpl.SetHandleRegion( value.Get< Vector2 >() );
1076 case Toolkit::Slider::Property::BACKING_IMAGE_NAME:
1078 sliderImpl.SetBackingImageName( value.Get< std::string >() );
1082 case Toolkit::Slider::Property::HANDLE_IMAGE_NAME:
1084 sliderImpl.SetHandleImageName( value.Get< std::string >() );
1088 case Toolkit::Slider::Property::PROGRESS_IMAGE_NAME:
1090 sliderImpl.SetProgressImageName( value.Get< std::string >() );
1094 case Toolkit::Slider::Property::POPUP_IMAGE_NAME:
1096 sliderImpl.SetPopupImageName( value.Get< std::string >() );
1100 case Toolkit::Slider::Property::POPUP_ARROW_IMAGE_NAME:
1102 sliderImpl.SetPopupArrowImageName( value.Get< std::string >() );
1106 case Toolkit::Slider::Property::DISABLE_COLOR:
1108 sliderImpl.SetDisableColor( value.Get< Vector4 >() );
1112 case Toolkit::Slider::Property::POPUP_TEXT_COLOR:
1114 sliderImpl.SetPopupTextColor( value.Get< Vector4 >() );
1118 case Toolkit::Slider::Property::VALUE_PRECISION:
1120 sliderImpl.SetValuePrecision( value.Get< int >() );
1124 case Toolkit::Slider::Property::SHOW_POPUP:
1126 sliderImpl.SetShowPopup( value.Get< bool >() );
1130 case Toolkit::Slider::Property::SHOW_VALUE:
1132 sliderImpl.SetShowValue( value.Get< bool >() );
1136 case Toolkit::Slider::Property::ENABLED:
1138 sliderImpl.SetEnabled( value.Get< bool >() );
1142 case Toolkit::Slider::Property::MARKS:
1144 sliderImpl.SetMarks( value.Get< Property::Array >() );
1148 case Toolkit::Slider::Property::SNAP_TO_MARKS:
1150 sliderImpl.SetSnapToMarks( value.Get< bool >() );
1154 case Toolkit::Slider::Property::MARK_TOLERANCE:
1156 sliderImpl.SetMarkTolerance( value.Get< float >() );
1163 Property::Value Slider::GetProperty( BaseObject* object, Property::Index propertyIndex )
1165 Property::Value value;
1167 Toolkit::Slider slider = Toolkit::Slider::DownCast( Dali::BaseHandle( object ) );
1171 Slider& sliderImpl( GetImpl( slider ) );
1173 switch ( propertyIndex )
1175 case Toolkit::Slider::Property::LOWER_BOUND:
1177 value = sliderImpl.GetLowerBound();
1181 case Toolkit::Slider::Property::UPPER_BOUND:
1183 value = sliderImpl.GetUpperBound();
1187 case Toolkit::Slider::Property::VALUE:
1189 value = sliderImpl.GetValue();
1193 case Toolkit::Slider::Property::HIT_REGION:
1195 value = sliderImpl.GetHitRegion();
1199 case Toolkit::Slider::Property::BACKING_REGION:
1201 value = sliderImpl.GetBackingRegion();
1205 case Toolkit::Slider::Property::HANDLE_REGION:
1207 value = sliderImpl.GetHandleRegion();
1211 case Toolkit::Slider::Property::BACKING_IMAGE_NAME:
1213 value = sliderImpl.GetBackingImageName();
1217 case Toolkit::Slider::Property::HANDLE_IMAGE_NAME:
1219 value = sliderImpl.GetHandleImageName();
1223 case Toolkit::Slider::Property::PROGRESS_IMAGE_NAME:
1225 value = sliderImpl.GetProgressImageName();
1229 case Toolkit::Slider::Property::POPUP_IMAGE_NAME:
1231 value = sliderImpl.GetPopupImageName();
1235 case Toolkit::Slider::Property::POPUP_ARROW_IMAGE_NAME:
1237 value = sliderImpl.GetPopupArrowImageName();
1241 case Toolkit::Slider::Property::DISABLE_COLOR:
1243 value = sliderImpl.GetDisableColor();
1247 case Toolkit::Slider::Property::POPUP_TEXT_COLOR:
1249 value = sliderImpl.GetPopupTextColor();
1253 case Toolkit::Slider::Property::VALUE_PRECISION:
1255 value = sliderImpl.GetValuePrecision();
1259 case Toolkit::Slider::Property::SHOW_POPUP:
1261 value = sliderImpl.GetShowPopup();
1265 case Toolkit::Slider::Property::SHOW_VALUE:
1267 value = sliderImpl.GetShowValue();
1271 case Toolkit::Slider::Property::ENABLED:
1273 value = sliderImpl.IsEnabled();
1277 case Toolkit::Slider::Property::MARKS:
1279 // TODO: Need to be able to return a PropertyArray
1280 // value = sliderImpl.GetMarks();
1284 case Toolkit::Slider::Property::SNAP_TO_MARKS:
1286 value = sliderImpl.GetSnapToMarks();
1290 case Toolkit::Slider::Property::MARK_TOLERANCE:
1292 value = sliderImpl.GetMarkTolerance();
1301 } // namespace Internal
1303 } // namespace Toolkit