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( Slider, "lower-bound", FLOAT, LOWER_BOUND )
56 DALI_PROPERTY_REGISTRATION( Slider, "upper-bound", FLOAT, UPPER_BOUND )
57 DALI_PROPERTY_REGISTRATION( Slider, "value", FLOAT, VALUE )
58 DALI_PROPERTY_REGISTRATION( Slider, "hit-region", VECTOR2, HIT_REGION )
59 DALI_PROPERTY_REGISTRATION( Slider, "backing-region", VECTOR2, BACKING_REGION )
60 DALI_PROPERTY_REGISTRATION( Slider, "handle-region", VECTOR2, HANDLE_REGION )
61 DALI_PROPERTY_REGISTRATION( Slider, "backing-image-name", STRING, BACKING_IMAGE_NAME )
62 DALI_PROPERTY_REGISTRATION( Slider, "handle-image-name", STRING, HANDLE_IMAGE_NAME )
63 DALI_PROPERTY_REGISTRATION( Slider, "progress-image-name", STRING, PROGRESS_IMAGE_NAME )
64 DALI_PROPERTY_REGISTRATION( Slider, "popup-image-name", STRING, POPUP_IMAGE_NAME )
65 DALI_PROPERTY_REGISTRATION( Slider, "popup-arrow-image-name", STRING, POPUP_ARROW_IMAGE_NAME )
66 DALI_PROPERTY_REGISTRATION( Slider, "disable-color", VECTOR4, DISABLE_COLOR )
67 DALI_PROPERTY_REGISTRATION( Slider, "popup-text-color", VECTOR4, POPUP_TEXT_COLOR )
68 DALI_PROPERTY_REGISTRATION( Slider, "value-precision", INTEGER, VALUE_PRECISION )
69 DALI_PROPERTY_REGISTRATION( Slider, "show-popup", BOOLEAN, SHOW_POPUP )
70 DALI_PROPERTY_REGISTRATION( Slider, "show-value", BOOLEAN, SHOW_VALUE )
71 DALI_PROPERTY_REGISTRATION( Slider, "enabled", BOOLEAN, ENABLED )
72 DALI_PROPERTY_REGISTRATION( Slider, "marks", ARRAY, MARKS )
73 DALI_PROPERTY_REGISTRATION( Slider, "snap-to-marks", BOOLEAN, SNAP_TO_MARKS )
74 DALI_PROPERTY_REGISTRATION( Slider, "mark-tolerance", FLOAT, MARK_TOLERANCE )
76 DALI_SIGNAL_REGISTRATION( Slider, "value-changed", SIGNAL_VALUE_CHANGED )
77 DALI_SIGNAL_REGISTRATION( 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;
100 const char* SKINNED_BACKING_IMAGE_NAME = DALI_IMAGE_DIR "slider-skin.9.png";
101 const char* SKINNED_HANDLE_IMAGE_NAME = DALI_IMAGE_DIR "slider-skin-handle.png";;
102 const char* SKINNED_PROGRESS_IMAGE_NAME = DALI_IMAGE_DIR "slider-skin-progress.9.png";
103 const char* SKINNED_POPUP_IMAGE_NAME = DALI_IMAGE_DIR "slider-popup.9.png";
104 const char* SKINNED_POPUP_ARROW_IMAGE_NAME = DALI_IMAGE_DIR "slider-popup-arrow.png";
106 const Vector2 DEFAULT_HIT_REGION( DEFAULT_WIDTH, DEFAULT_HIT_HEIGHT );
107 const Vector2 DEFAULT_BACKING_REGION( DEFAULT_WIDTH, DEFAULT_HEIGHT );
108 const Vector2 DEFAULT_HANDLE_REGION( DEFAULT_HANDLE_HEIGHT, DEFAULT_HANDLE_HEIGHT );
110 const Vector4 DEFAULT_DISABLE_COLOR( 0.5f, 0.5f, 0.5f, 1.0f );
111 const Vector4 DEFAULT_POPUP_TEXT_COLOR( 0.5f, 0.5f, 0.5f, 1.0f );
113 const float VALUE_POPUP_MARGIN = 10.0f;
114 const float VALUE_POPUP_HEIGHT = 81.0f;
115 const float VALUE_POPUP_MIN_WIDTH = 54.0f;
116 const Vector2 VALUE_POPUP_ARROW_SIZE( 18.0f, 18.0f );
118 const float DEFAULT_LOWER_BOUND = 0.0f;
119 const float DEFAULT_UPPER_BOUND = 1.0f;
120 const float DEFAULT_VALUE = 0.0f;
121 const int DEFAULT_VALUE_PRECISION = 0;
122 const bool DEFAULT_SHOW_POPUP = false;
123 const bool DEFAULT_SHOW_VALUE = true;
124 const bool DEFAULT_ENABLED = true;
125 const bool DEFAULT_SNAP_TO_MARKS = false;
127 } // Unnamed namespace
129 ///////////////////////////////////////////////////////////////////////////////////////////////////
131 ///////////////////////////////////////////////////////////////////////////////////////////////////
133 Dali::Toolkit::Slider Slider::New()
135 // Create the implementation
136 SliderPtr slider( new Slider() );
138 // Pass ownership to CustomActor via derived handle
139 Dali::Toolkit::Slider handle( *slider );
141 // Second-phase init of the implementation
142 // This can only be done after the CustomActor connection has been made...
143 slider->Initialize();
149 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ),
151 mDisableColor( 0.0f, 0.0f, 0.0f, 0.0f ),
152 mPopupTextColor( 0.0f, 0.0f, 0.0f, 0.0f ),
153 mHitRegion( 0.0f, 0.0f ),
154 mBackingRegion( 0.0f, 0.0f ),
155 mHandleRegionSize( 0.0f, 0.0f ),
159 mMarkTolerance( 0.0f ),
160 mValuePrecision( 0 ),
163 mSnapToMarks( false )
171 void Slider::OnInitialize()
179 SetHitRegion( DEFAULT_HIT_REGION );
180 SetBackingRegion( DEFAULT_BACKING_REGION );
181 SetHandleRegion( DEFAULT_HANDLE_REGION );
183 SetBackingImageName( SKINNED_BACKING_IMAGE_NAME );
184 SetHandleImageName( SKINNED_HANDLE_IMAGE_NAME );
185 SetProgressImageName( SKINNED_PROGRESS_IMAGE_NAME );
186 SetPopupImageName( SKINNED_POPUP_IMAGE_NAME );
187 SetPopupArrowImageName( SKINNED_POPUP_ARROW_IMAGE_NAME );
189 SetPopupTextColor( DEFAULT_POPUP_TEXT_COLOR );
191 SetShowPopup( DEFAULT_SHOW_POPUP );
192 SetShowValue( DEFAULT_SHOW_VALUE );
194 SetEnabled( DEFAULT_ENABLED );
195 SetDisableColor( DEFAULT_DISABLE_COLOR );
197 SetSnapToMarks( DEFAULT_SNAP_TO_MARKS );
198 SetMarkTolerance( MARK_SNAP_TOLERANCE );
200 SetLowerBound( DEFAULT_LOWER_BOUND );
201 SetUpperBound( DEFAULT_UPPER_BOUND );
203 SetValuePrecision( DEFAULT_VALUE_PRECISION );
204 mValue = DEFAULT_VALUE;
205 DisplayValue( mValue, false ); // Run this last to display the correct value
207 // Size the Slider actor to a default
208 self.SetSize( DEFAULT_HIT_REGION.x, DEFAULT_HIT_REGION.y );
211 void Slider::OnControlSizeSet( const Vector3& size )
213 // Factor in handle overshoot into size of backing
214 SetHitRegion( Vector2( size.x, GetHitRegion().y ) );
215 SetBackingRegion( Vector2( size.x - GetHandleRegion().x, GetBackingRegion().y ) );
218 bool Slider::OnTouchEvent(Actor actor, const TouchEvent& event)
220 if( mState != DISABLED )
222 TouchPoint::State touchState = event.GetPoint(0).state;
224 if( touchState == TouchPoint::Down )
228 float percentage = MapPercentage( event.GetPoint(0).local );
229 float value = MapBounds( ( GetSnapToMarks() ) ? SnapToMark( percentage ) : MarkFilter( percentage ), GetLowerBound(), GetUpperBound() );
231 DisplayPopup( value );
233 else if( touchState == TouchPoint::Up)
235 if( mState == PRESSED )
238 mSlidingFinishedSignal.Emit( Toolkit::Slider::DownCast( Self() ), GetValue() );
246 void Slider::OnPan( Actor actor, const PanGesture& gesture )
248 // gesture.position is in local actor coordinates
249 if( mState != DISABLED )
251 switch( gesture.state )
253 case Gesture::Continuing:
255 if( mState == PRESSED )
257 float value = MapBounds( MarkFilter ( MapPercentage( gesture.position ) ), GetLowerBound(), GetUpperBound() );
259 DisplayPopup( value );
263 case Gesture::Finished:
265 if( mState == PRESSED )
267 if( GetSnapToMarks() )
269 float value = MapBounds( SnapToMark( MapPercentage( gesture.position ) ), GetLowerBound(), GetUpperBound() );
271 DisplayPopup( value );
273 mSlidingFinishedSignal.Emit( Toolkit::Slider::DownCast( Self() ), GetValue() );
287 float Slider::HitSpaceToDomain( float x )
289 float halfRegionWidth = GetHitRegion().x * 0.5f;
290 float halfDomainWidth = ( mDomain.to.x - mDomain.from.x ) * 0.5f;
291 float endDiff = halfRegionWidth - halfDomainWidth;
296 float Slider::MapPercentage( const Vector2& point )
298 return Clamp( ( HitSpaceToDomain( point.x ) - mDomain.from.x ) / ( mDomain.to.x - mDomain.from.x ), 0.0f, 1.0f );
301 float Slider::MapValuePercentage( float value )
303 return ( value - GetLowerBound() ) / ( GetUpperBound() - GetLowerBound() );
306 float Slider::MapBounds( float percent, float lowerBound, float upperBound )
308 return lowerBound + percent * ( upperBound - lowerBound );
311 Slider::Domain Slider::CalcDomain( const Vector2& currentSize )
313 return Domain( Vector2( 0.0f, 0.0f ), currentSize );
316 void Slider::DisplayValue( float value, bool raiseSignals )
318 float clampledValue = Clamp( value, GetLowerBound(), GetUpperBound() );
320 float percent = MapValuePercentage( clampledValue );
322 float x = mDomain.from.x + percent * ( mDomain.to.x - mDomain.from.x );
324 mHandle.SetPosition( x, 0.0f, HANDLE_Z );
329 if( clampledValue > 0.0f )
331 mProgress.SetVisible( true ); // Deliberately set this in case multiple SetValues are fired at once
332 mProgress.SetSize( x, GetBackingRegion().y );
336 mProgress.SetVisible( false );
343 Toolkit::Slider self = Toolkit::Slider::DownCast( Self() );
344 mValueChangedSignal.Emit( self, clampledValue );
347 if( MarkReached( percent, markIndex ) )
349 mMarkSignal.Emit( self, markIndex );
353 if( mHandleValueTextLabel )
355 std::stringstream ss;
356 ss.precision( GetValuePrecision() );
357 ss << std::fixed << clampledValue;
359 mHandleValueTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, ss.str() );
363 void Slider::SetMarks( const MarkList& marks )
366 for( MarkList::const_iterator it = marks.begin(), itEnd = marks.end(); it != itEnd; ++it )
368 const Property::Value& propertyValue = *it;
369 propertyValue.Get( value );
371 mMarks.push_back( value );
375 const Slider::MarkList& Slider::GetMarks() const
380 void Slider::SetSnapToMarks( bool snap )
385 bool Slider::GetSnapToMarks() const
390 Actor Slider::CreateHitRegion()
392 Actor hitRegion = Actor::New();
393 hitRegion.SetParentOrigin( ParentOrigin::CENTER );
394 hitRegion.SetAnchorPoint( AnchorPoint::CENTER );
395 hitRegion.TouchedSignal().Connect( this, &Slider::OnTouchEvent );
400 ImageActor Slider::CreateBacking()
402 ImageActor backing = ImageActor::New();
403 backing.SetRelayoutEnabled( false );
404 backing.SetParentOrigin( ParentOrigin::CENTER );
405 backing.SetAnchorPoint( AnchorPoint::CENTER );
406 backing.SetZ( BACKING_Z );
411 void Slider::SetBackingImageName( const std::string& imageName )
413 if( mBacking && ( imageName.size() > 0 ) )
415 Image image = ResourceImage::New( imageName );
416 mBacking.SetImage( image );
420 std::string Slider::GetBackingImageName()
424 return ResourceImage::DownCast( mBacking.GetImage() ).GetUrl();
427 return std::string( "" );
430 ImageActor Slider::CreateProgress()
432 ImageActor progress = ImageActor::New();
433 progress.SetRelayoutEnabled( false );
434 progress.SetParentOrigin( ParentOrigin::CENTER_LEFT );
435 progress.SetAnchorPoint( AnchorPoint::CENTER_LEFT );
436 progress.SetZ( PROGRESS_Z );
441 void Slider::SetProgressImageName( const std::string& imageName )
443 if( mProgress && ( imageName.size() > 0 ) )
445 Image image = ResourceImage::New( imageName );
446 mProgress.SetImage( image );
450 std::string Slider::GetProgressImageName()
454 return ResourceImage::DownCast( mProgress.GetImage()).GetUrl();
457 return std::string( "" );
460 void Slider::SetPopupImageName( const std::string& imageName )
462 mPopupImageName = imageName;
465 std::string Slider::GetPopupImageName()
467 return mPopupImageName;
470 void Slider::CreatePopupImage( const std::string& imageName )
472 if( mPopup && ( imageName.size() > 0 ) )
474 Image image = ResourceImage::New( imageName );
475 mPopup.SetImage( image );
479 void Slider::SetPopupArrowImageName( const std::string& imageName )
481 mPopupArrowImageName = imageName;
484 std::string Slider::GetPopupArrowImageName()
486 return mPopupArrowImageName;
489 void Slider::CreatePopupArrowImage( const std::string& imageName )
491 if( mPopupArrow && ( imageName.size() > 0 ) )
493 Image image = ResourceImage::New( imageName );
494 mPopupArrow.SetImage( image );
498 void Slider::ResizeProgressRegion( const Vector2& region )
502 mProgress.SetSize( region );
506 ImageActor Slider::CreateHandle()
508 ImageActor handle = ImageActor::New();
509 handle.SetRelayoutEnabled( false );
510 handle.SetParentOrigin( ParentOrigin::CENTER_LEFT );
511 handle.SetAnchorPoint( AnchorPoint::CENTER );
512 handle.SetZ( HANDLE_Z );
517 ImageActor Slider::CreatePopupArrow()
519 ImageActor arrow = ImageActor::New();
520 arrow.SetRelayoutEnabled( false );
521 arrow.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
522 arrow.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
523 arrow.SetZ( HANDLE_Z );
528 Toolkit::TextLabel Slider::CreatePopupText()
530 Toolkit::TextLabel textLabel = Toolkit::TextLabel::New();
531 textLabel.SetParentOrigin( ParentOrigin::CENTER );
532 textLabel.SetAnchorPoint( AnchorPoint::CENTER );
533 textLabel.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
534 textLabel.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
535 textLabel.SetZ( VALUE_DISPLAY_TEXT_Z );
539 ImageActor Slider::CreatePopup()
541 ImageActor popup = ImageActor::New();
542 popup.SetRelayoutEnabled( false );
543 popup.SetParentOrigin( ParentOrigin::TOP_CENTER );
544 popup.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
546 mValueTextLabel = CreatePopupText();
547 popup.Add( mValueTextLabel );
552 void Slider::SetHandleImageName( const std::string& imageName )
554 if( mHandle && ( imageName.size() > 0 ) )
556 Image image = ResourceImage::New( imageName );
557 mHandle.SetImage( image );
561 std::string Slider::GetHandleImageName()
565 return ResourceImage::DownCast( mHandle.GetImage() ).GetUrl();
568 return std::string( "" );
571 void Slider::ResizeHandleRegion( const Vector2& region )
575 mHandle.SetSize( region );
579 void Slider::CreateHandleValueDisplay()
581 if( mHandle && !mHandleValueTextLabel )
583 mHandleValueTextLabel = Toolkit::TextLabel::New();
584 mHandleValueTextLabel.SetParentOrigin( ParentOrigin::CENTER );
585 mHandleValueTextLabel.SetAnchorPoint( AnchorPoint::CENTER );
586 mHandleValueTextLabel.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
587 mHandleValueTextLabel.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
588 mHandleValueTextLabel.SetDrawMode( DrawMode::OVERLAY );
589 mHandle.Add( mHandleValueTextLabel );
593 void Slider::DestroyHandleValueDisplay()
595 UnparentAndReset(mHandleValueTextLabel);
598 void Slider::SetPopupTextColor( const Vector4& color )
600 mPopupTextColor = color;
603 Actor Slider::CreateValueDisplay()
605 Actor popup = Actor::New();
606 popup.SetParentOrigin( ParentOrigin::TOP_CENTER );
607 popup.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
609 mPopupArrow = CreatePopupArrow();
610 popup.Add( mPopupArrow );
612 mPopup = CreatePopup();
613 mPopup.SetSize( 0.0f, VALUE_POPUP_HEIGHT );
614 mPopupArrow.Add( mPopup );
619 Toolkit::Slider::ValueChangedSignalType& Slider::ValueChangedSignal()
621 return mValueChangedSignal;
624 Toolkit::Slider::ValueChangedSignalType& Slider::SlidingFinishedSignal()
626 return mSlidingFinishedSignal;
629 Toolkit::Slider::MarkSignalType& Slider::MarkSignal()
634 void Slider::UpdateSkin()
640 mBacking.SetColor( Color::WHITE );
641 mHandle.SetColor( Color::WHITE );
642 mProgress.SetColor( Color::WHITE );
647 Vector4 disableColor = GetDisableColor();
648 mBacking.SetColor( disableColor );
649 mHandle.SetColor( disableColor );
650 mProgress.SetColor( disableColor );
664 void Slider::CreateChildren()
669 mHitArea = CreateHitRegion();
670 mPanDetector = PanGestureDetector::New();
671 mPanDetector.Attach( mHitArea );
672 mPanDetector.DetectedSignal().Connect( this, &Slider::OnPan );
673 self.Add( mHitArea );
676 mBacking = CreateBacking();
677 self.Add( mBacking );
680 mProgress = CreateProgress();
681 mBacking.Add( mProgress );
684 mHandle = CreateHandle();
685 mBacking.Add( mHandle );
688 void Slider::SetHitRegion( const Vector2& size )
694 mHitArea.SetSize( mHitRegion );
698 const Vector2& Slider::GetHitRegion() const
703 void Slider::AddPopup()
707 mValueDisplay = CreateValueDisplay();
708 mValueDisplay.SetVisible( false );
709 mHandle.Add( mValueDisplay );
711 CreatePopupImage( GetPopupImageName() );
712 CreatePopupArrowImage( GetPopupArrowImageName() );
714 mValueTimer = Timer::New( VALUE_VIEW_SHOW_DURATION );
715 mValueTimer.TickSignal().Connect( this, &Slider::HideValueView );
719 void Slider::RemovePopup()
726 mPopupArrow.Unparent();
729 mValueDisplay.Unparent();
730 mValueDisplay.Reset();
732 mValueTimer.TickSignal().Disconnect( this, &Slider::HideValueView );
738 float Slider::MarkFilter( float value )
740 const float MARK_TOLERANCE = GetMarkTolerance();
743 for( MarkList::iterator it = mMarks.begin(), itEnd = mMarks.end(); it != itEnd; ++it )
745 const Property::Value& propertyValue = *it;
746 propertyValue.Get( mark );
747 mark = MapValuePercentage( mark );
749 // If close to a mark, return the mark
750 if( fabsf( mark - value ) < MARK_TOLERANCE )
759 float Slider::SnapToMark( float value )
761 float closestMark = value;
762 float closestDist = std::numeric_limits<float>::max();
765 for( MarkList::iterator it = mMarks.begin(), itEnd = mMarks.end(); it != itEnd; ++it )
767 const Property::Value& propertyValue = *it;
768 propertyValue.Get( mark );
769 mark = MapValuePercentage( mark );
771 float dist = fabsf( mark - value );
772 if( dist < closestDist )
782 bool Slider::MarkReached( float value, int& outIndex )
784 const float MARK_TOLERANCE = GetMarkTolerance();
788 tail = mMarks.size() - 1;
792 while( head <= tail )
794 current = head + ( tail - head ) / 2;
796 const Property::Value& propertyValue = mMarks[ current ];
797 propertyValue.Get( mark );
798 mark = MapValuePercentage( mark );
800 if( fabsf( mark - value ) < MARK_TOLERANCE )
819 bool Slider::HideValueView()
823 mValueDisplay.SetVisible( false );
829 void Slider::SetLowerBound( float bound )
832 DisplayValue( GetValue(), false );
835 float Slider::GetLowerBound() const
840 void Slider::SetUpperBound( float bound )
843 DisplayValue( GetValue(), false );
846 float Slider::GetUpperBound() const
851 void Slider::SetValue( float value )
854 DisplayValue( mValue, true );
857 float Slider::GetValue() const
862 void Slider::SetBackingRegion( const Vector2& region )
864 mBackingRegion = region;
868 mBacking.SetSize( mBackingRegion );
871 ResizeProgressRegion( Vector2( 0.0f, mBackingRegion.y ) );
873 mDomain = CalcDomain( mBackingRegion );
875 DisplayValue( GetValue(), false ); // Set the progress bar to correct width
878 const Vector2& Slider::GetBackingRegion() const
880 return mBackingRegion;
883 void Slider::SetHandleRegion( const Vector2& region )
885 mHandleRegionSize = region;
887 ResizeHandleRegion( mHandleRegionSize );
889 Vector2 hitRegion = GetHitRegion();
890 hitRegion.x += mHandleRegionSize.x;
891 SetHitRegion( hitRegion );
894 const Vector2& Slider::GetHandleRegion() const
896 return mHandleRegionSize;
899 void Slider::SetDisableColor( const Vector4& color )
901 mDisableColor = color;
906 Vector4 Slider::GetDisableColor() const
908 return mDisableColor;
911 Vector4 Slider::GetPopupTextColor() const
913 return mPopupTextColor;
916 void Slider::SetValuePrecision( int precision )
918 mValuePrecision = precision;
921 int Slider::GetValuePrecision() const
923 return mValuePrecision;
926 void Slider::SetShowPopup( bool showPopup )
928 mShowPopup = showPopup;
941 bool Slider::GetShowPopup() const
946 void Slider::SetShowValue( bool showValue )
948 mShowValue = showValue;
952 CreateHandleValueDisplay();
956 DestroyHandleValueDisplay();
960 bool Slider::GetShowValue() const
965 void Slider::SetEnabled( bool enabled )
979 bool Slider::IsEnabled() const
981 return mState != DISABLED;
984 void Slider::SetMarkTolerance( float tolerance )
986 mMarkTolerance = tolerance;
989 float Slider::GetMarkTolerance() const
991 return mMarkTolerance;
994 // Static class method to support script connecting signals
995 bool Slider::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
997 Dali::BaseHandle handle( object );
999 bool connected = true;
1000 Toolkit::Slider slider = Toolkit::Slider::DownCast( handle );
1002 if( 0 == strcmp( signalName.c_str(), SIGNAL_VALUE_CHANGED ) )
1004 slider.ValueChangedSignal().Connect( tracker, functor );
1006 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MARK ) )
1008 slider.MarkSignal().Connect( tracker, functor );
1012 // signalName does not match any signal
1019 void Slider::DisplayPopup( float value )
1021 // Value displayDoConnectSignal
1022 if( mValueTextLabel )
1024 std::stringstream ss;
1025 ss.precision( GetValuePrecision() );
1026 ss << std::fixed << value;
1027 mValueTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, ss.str() );
1031 mValueDisplay.SetVisible( true );
1033 mValueTimer.SetInterval( VALUE_VIEW_SHOW_DURATION );
1038 void Slider::SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value )
1040 Toolkit::Slider slider = Toolkit::Slider::DownCast( Dali::BaseHandle( object ) );
1044 Slider& sliderImpl( GetImpl( slider ) );
1046 switch ( propertyIndex )
1048 case Toolkit::Slider::Property::LOWER_BOUND:
1050 sliderImpl.SetLowerBound( value.Get< float >() );
1054 case Toolkit::Slider::Property::UPPER_BOUND:
1056 sliderImpl.SetUpperBound( value.Get< float >() );
1060 case Toolkit::Slider::Property::VALUE:
1062 sliderImpl.SetValue( value.Get< float >() );
1066 case Toolkit::Slider::Property::HIT_REGION:
1068 sliderImpl.SetHitRegion( value.Get< Vector2 >() );
1072 case Toolkit::Slider::Property::BACKING_REGION:
1074 sliderImpl.SetBackingRegion( value.Get< Vector2 >() );
1078 case Toolkit::Slider::Property::HANDLE_REGION:
1080 sliderImpl.SetHandleRegion( value.Get< Vector2 >() );
1084 case Toolkit::Slider::Property::BACKING_IMAGE_NAME:
1086 sliderImpl.SetBackingImageName( value.Get< std::string >() );
1090 case Toolkit::Slider::Property::HANDLE_IMAGE_NAME:
1092 sliderImpl.SetHandleImageName( value.Get< std::string >() );
1096 case Toolkit::Slider::Property::PROGRESS_IMAGE_NAME:
1098 sliderImpl.SetProgressImageName( value.Get< std::string >() );
1102 case Toolkit::Slider::Property::POPUP_IMAGE_NAME:
1104 sliderImpl.SetPopupImageName( value.Get< std::string >() );
1108 case Toolkit::Slider::Property::POPUP_ARROW_IMAGE_NAME:
1110 sliderImpl.SetPopupArrowImageName( value.Get< std::string >() );
1114 case Toolkit::Slider::Property::DISABLE_COLOR:
1116 sliderImpl.SetDisableColor( value.Get< Vector4 >() );
1120 case Toolkit::Slider::Property::POPUP_TEXT_COLOR:
1122 sliderImpl.SetPopupTextColor( value.Get< Vector4 >() );
1126 case Toolkit::Slider::Property::VALUE_PRECISION:
1128 sliderImpl.SetValuePrecision( value.Get< int >() );
1132 case Toolkit::Slider::Property::SHOW_POPUP:
1134 sliderImpl.SetShowPopup( value.Get< bool >() );
1138 case Toolkit::Slider::Property::SHOW_VALUE:
1140 sliderImpl.SetShowValue( value.Get< bool >() );
1144 case Toolkit::Slider::Property::ENABLED:
1146 sliderImpl.SetEnabled( value.Get< bool >() );
1150 case Toolkit::Slider::Property::MARKS:
1152 sliderImpl.SetMarks( value.Get< Property::Array >() );
1156 case Toolkit::Slider::Property::SNAP_TO_MARKS:
1158 sliderImpl.SetSnapToMarks( value.Get< bool >() );
1162 case Toolkit::Slider::Property::MARK_TOLERANCE:
1164 sliderImpl.SetMarkTolerance( value.Get< float >() );
1171 Property::Value Slider::GetProperty( BaseObject* object, Property::Index propertyIndex )
1173 Property::Value value;
1175 Toolkit::Slider slider = Toolkit::Slider::DownCast( Dali::BaseHandle( object ) );
1179 Slider& sliderImpl( GetImpl( slider ) );
1181 switch ( propertyIndex )
1183 case Toolkit::Slider::Property::LOWER_BOUND:
1185 value = sliderImpl.GetLowerBound();
1189 case Toolkit::Slider::Property::UPPER_BOUND:
1191 value = sliderImpl.GetUpperBound();
1195 case Toolkit::Slider::Property::VALUE:
1197 value = sliderImpl.GetValue();
1201 case Toolkit::Slider::Property::HIT_REGION:
1203 value = sliderImpl.GetHitRegion();
1207 case Toolkit::Slider::Property::BACKING_REGION:
1209 value = sliderImpl.GetBackingRegion();
1213 case Toolkit::Slider::Property::HANDLE_REGION:
1215 value = sliderImpl.GetHandleRegion();
1219 case Toolkit::Slider::Property::BACKING_IMAGE_NAME:
1221 value = sliderImpl.GetBackingImageName();
1225 case Toolkit::Slider::Property::HANDLE_IMAGE_NAME:
1227 value = sliderImpl.GetHandleImageName();
1231 case Toolkit::Slider::Property::PROGRESS_IMAGE_NAME:
1233 value = sliderImpl.GetProgressImageName();
1237 case Toolkit::Slider::Property::POPUP_IMAGE_NAME:
1239 value = sliderImpl.GetPopupImageName();
1243 case Toolkit::Slider::Property::POPUP_ARROW_IMAGE_NAME:
1245 value = sliderImpl.GetPopupArrowImageName();
1249 case Toolkit::Slider::Property::DISABLE_COLOR:
1251 value = sliderImpl.GetDisableColor();
1255 case Toolkit::Slider::Property::POPUP_TEXT_COLOR:
1257 value = sliderImpl.GetPopupTextColor();
1261 case Toolkit::Slider::Property::VALUE_PRECISION:
1263 value = sliderImpl.GetValuePrecision();
1267 case Toolkit::Slider::Property::SHOW_POPUP:
1269 value = sliderImpl.GetShowPopup();
1273 case Toolkit::Slider::Property::SHOW_VALUE:
1275 value = sliderImpl.GetShowValue();
1279 case Toolkit::Slider::Property::ENABLED:
1281 value = sliderImpl.IsEnabled();
1285 case Toolkit::Slider::Property::MARKS:
1287 // TODO: Need to be able to return a PropertyArray
1288 // value = sliderImpl.GetMarks();
1292 case Toolkit::Slider::Property::SNAP_TO_MARKS:
1294 value = sliderImpl.GetSnapToMarks();
1298 case Toolkit::Slider::Property::MARK_TOLERANCE:
1300 value = sliderImpl.GetMarkTolerance();
1309 } // namespace Internal
1311 } // namespace Toolkit