1 #ifndef __DALI_TOOLKIT_INTERNAL_SLIDER_H__
2 #define __DALI_TOOLKIT_INTERNAL_SLIDER_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 // Licensed under the Flora License, Version 1.0 (the License);
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://floralicense.org/license/
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an AS IS BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
21 #include <dali/dali.h>
22 #include <dali-toolkit/public-api/controls/control-impl.h>
23 #include <dali-toolkit/public-api/controls/slider/slider.h>
24 #include <dali-toolkit/public-api/controls/text-view/text-view.h>
39 typedef Dali::IntrusivePtr< Slider > SliderPtr;
42 * @copydoc Toolkit::Slider
44 class Slider : public ControlImpl
48 typedef Property::Array MarkList;
51 * Create a new Slider.
53 * @return A public handle to the newly allocated Slider.
55 static Dali::Toolkit::Slider New();
62 * Set marks from a list
64 * @param[in] marks The list of marks to set
66 void SetMarks( const MarkList& marks );
69 * Get the list of marks
71 * @return The marks list
73 const MarkList& GetMarks() const;
76 * Set if should snap to marks or not
78 * @param[in] snap Flag to snap to marks or not
80 void SetSnapToMarks( bool snap );
83 * Return if snap to marks is set or not
85 * @return If snap to marks is set
87 bool GetSnapToMarks() const;
90 * Set the value of the slider
92 * @param[in] value The value to set. Will be clamped to [lowerBound .. upperBound]
94 void SetValue( float value );
97 * Get the value of the slider
99 * @return The current value of the slider
101 float GetValue() const;
106 * @param[in] region The hit region
108 void SetHitRegion( const Vector2& region );
113 * @return The hit region
115 Vector2 GetHitRegion() const;
120 * @param[in] region The backing region
122 void SetBackingRegion( const Vector2& region );
127 * @return The backing region
129 Vector2 GetBackingRegion() const;
132 * Get backing scale9 border
134 * @return The backing scale9 border
136 Vector4 GetBackingScale9Border() const;
139 * Get popup scale9 border
141 * @return The popup scale9 border
143 Vector4 GetPopupScale9Border() const;
148 * @return The disable color
150 Vector4 GetDisableColor() const;
153 * Get popup text color
155 * @return The popup text color
157 Vector4 GetPopupTextColor() const;
160 * Get value precision
162 * @return The value precision
164 int GetValuePrecision() const;
169 * @param[in] showPopup The show popup flag
171 void ShowPopup( bool showPopup );
174 * Get show value in popup
176 * @return The show value flag
178 bool GetShowPopup() const;
181 * Set show value on handle
183 * @param[in] showValue The show value flag
185 void ShowValue( bool showValue );
188 * Get show value on handle
190 * @return The show value flag
192 bool GetShowValue() const;
197 * param[in] enabled Set the enabled flag
199 void SetEnabled( bool enabled );
202 * Return if enabled or not
206 bool IsEnabled() const;
209 * Return the mark tolerance
211 * @return The tolerance set for snapping to marks
213 float GetMarkTolerance() const;
219 * @copydoc Toolkit::Slider::ValueChangedSignal()
221 Toolkit::Slider::ValueChangedSignalType& ValueChangedSignal();
224 * copydoc Toolkit::Slider::SlidingFinishedSignal()
226 Toolkit::Slider::ValueChangedSignalType& SlidingFinishedSignal();
229 * @copydoc Toolkit::Slider::MarkSignal()
231 Toolkit::Slider::MarkSignalType& MarkSignal();
234 * Connects a callback function with the object's signals.
235 * @param[in] object The object providing the signal.
236 * @param[in] tracker Used to disconnect the signal.
237 * @param[in] signalName The signal to connect to.
238 * @param[in] functor A newly allocated FunctorDelegate.
239 * @return True if the signal was connected.
240 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
242 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName,
243 FunctorDelegate* functor );
248 * Construct a new Slider.
253 * A reference counted object may only be deleted by calling Unreference()
258 * @copydoc Toolkit::ControlImpl::OnControlSizeSet( const Vector3& size )
260 virtual void OnControlSizeSet( const Vector3& size );
265 * Domain is a from/to pair
275 Domain( Vector2 fromVal, Vector2 toVal )
276 : from( fromVal ), to( toVal )
295 * @copydoc Toolkit::Control::OnInitialize()
297 virtual void OnInitialize();
300 * Hit region touch event
302 * @param[in] actor The actor the event is raised for
303 * @param[in] event The touch event info
304 * @return If the event is handled or not
306 bool OnTouchEvent( Actor actor, const TouchEvent& event );
311 * @param[in] actor The actor the event is raised for
312 * @param[in] gesture The pan event info
314 void OnPan( Actor actor, PanGesture gestur );
317 * Map a position onto a domain and return the result as a percentage
319 * @param[in] point The point to map onto the domain
320 * @return The result as a percentage [0..1]
322 float MapPercentage( const Vector2& point );
325 * Map a value in the range to a percentage
327 * @param[in] point The value in range [lowerBound..upperBound]
328 * @return The result as a percentage [0..1]
330 float MapValuePercentage( float value );
333 * Convert a point in local hit space into domain space
335 * @param[in] x The x position to convert
336 * @return The x position in domain space
338 float HitSpaceToDomain( float x );
341 * Map a percentage onto the slider's bounds
343 * @param[in] percent The current value of slider in percent
344 * @param[in] lowerBound The lower bound to map onto
345 * @param[in] upperBound The upper bound to map onto
346 * @return The value of percent mapped from lowerBound to upperBound
348 float MapBounds( float percent, float lowerBound, float upperBound );
351 * Get the range of the valid values the slider handle can move between
353 * @param[in] currentSize The current size of the slider
354 * @return The range as a domain pair
356 Domain CalcDomain( const Vector2& currentSize );
359 * Create the hit region
361 * @return The hit region actor
363 Actor CreateHitRegion();
366 * Create the backing for the slider
368 * @return The backing actor
370 ImageActor CreateBacking();
373 * Create the progress backing for the slider
375 * @return The backing actor
377 ImageActor CreateProgress();
380 * Create the handle for the slider
382 * @return The created image handle
384 ImageActor CreateHandle();
387 * Create the popup arrow
389 * @return The created image handle
391 ImageActor CreatePopupArrow();
396 * @return The created image handle
398 ImageActor CreatePopup();
401 * Create the textview for the popup
403 * @return The textview created for the popup
405 Toolkit::TextView CreatePopupText();
408 * Create the value display for the slider
410 * @return The created root actor of the display
412 Actor CreateValueDisplay();
415 * Set the skin based on the current state
420 * Create all the children
422 void CreateChildren();
425 * Resize the hit area
427 * @param[in] size The new size of the hit area
429 void ResizeHitRegion( const Vector2& size );
442 * Display the popup for a set duration with the given value
444 * @param[in] value The value to display in the popup
446 void DisplayPopup( float value );
449 * If there are marks present, filter the incoming percent based on snapping to any nearby marks
451 * @param[in] value The incoming value on the slider to filter
452 * @return The filtered percentage snapped to any nearby marks
454 float MarkFilter( float value );
457 * If there are marks present, snap the incoming percent to the nearest mark
459 * @param[in] value The incoming value on the slider to snap
460 * @return The filtered percentage snapped to the nearest mark
462 float SnapToMark( float value );
465 * Search for if a mark has been reached
467 * @param[in] value The value to search against
468 * @param[out] outIndex The index of the mark if found
469 * @return If a mark has been found to match percent
471 bool MarkReached( float value, int& outIndex );
474 * Handler for when the value view needs to be hidden
476 * @return If handled or not
478 bool HideValueView();
481 * Set value choosing whether to fire signals or not
483 * @paramp[in] value The value to set
484 * @param[in] raiseSignals Configure signals to be raised or not.
486 void DisplayValue( float value, bool raiseSignals );
489 * Create the image for the backing
491 * @param[in] imageName The name of the image to load and set
493 void CreateBackingImage( const std::string& imageName );
496 * Set the backing image to be a scale-9 image
498 * @param[in] border The scale-9 border to use
500 void SetBackingScale9( const Vector4& border );
503 * Resize the backing region
505 * @param[in] region The size of the region to set
507 void ResizeBackingRegion( const Vector2& region );
510 * Size the backing region
512 * @param[in] region The size of the region to set
514 void SetBackingRegionSize( const Vector2& region );
517 * Create the image for the progress bar
519 * @param[in] imageName The name of the image to load and set
521 void CreateProgressImage( const std::string& imageName );
524 * Create the image for the popup
526 * @param[in] imageName The name of the image to load and set
528 void CreatePopupImage( const std::string& imageName );
531 * Create the image for the popup arrow
533 * @param[in] imageName The name of the image to load and set
535 void CreatePopupArrowImage( const std::string& imageName );
538 * Set the progress image to be a scale-9 image
540 * @param[in] border The scale-9 border to use
542 void SetProgressScale9( const Vector4& border );
545 * Set the popup image to be a scale-9 image
547 * @param[in] border The scale-9 border to use
549 void SetPopupScale9( const Vector4& border );
552 * Set the size of the progress bar region
554 * @param[in] region The size of the region to set
556 void ResizeProgressRegion( const Vector2& region );
559 * Create the image for the handle
561 * @param[in] imageName The name of the image to load and set
563 void CreateHandleImage( const std::string& imageName );
566 * Set the size of the handle region
568 * @param[in] region The size of the region to set
570 void ResizeHandleRegion( const Vector2& region );
573 * Create and display the value on the handle
575 void CreateHandleValueDisplay();
578 * Remove and destroy the handle value display
580 void DestroyHandleValueDisplay();
583 * Update the color of the popup text
585 * @param[in] color The new color
587 void UpdatePopupTextColor( const Vector4& color );
592 * @param[in] region The handle region
594 void UpdateHandleRegion( const Vector2& region );
599 * @return The handle region
601 Vector2 GetHandleRegion() const;
604 * Set the lower bound of the slider's value
606 * @param[in] bound The value to set for the lower bound
608 void UpdateLowerBound( float bound );
611 * Get the lower bound of the slider's value
613 * @return The lower bound value
615 float GetLowerBound() const;
618 * Set the upper bound of the slider's value
620 * @param[in] bound The value to set for the upper bound
622 void UpdateUpperBound( float bound );
625 * Get the upper bound of the slider's value
627 * @return The upper bound value
629 float GetUpperBound() const;
635 * @copydoc Dali::CustomActorImpl::OnPropertySet()
637 virtual void OnPropertySet( Property::Index index, Property::Value propertyValue );
642 Slider( const Slider& );
645 Slider& operator=( const Slider& rhs );
649 Domain mDomain; ///< Current domain of the handle
651 Actor mHitArea; ///< The input handler
652 ImageActor mBacking; ///< Backing image
653 ImageActor mHandle; ///< Slider handle
654 ImageActor mProgress; ///< Progress backing
655 Actor mValueDisplay; ///< Display of the value
656 ImageActor mPopup; ///< Popup backing
657 ImageActor mPopupArrow; ///< Popup arrow backing
659 Toolkit::TextView mValueTextView; //< The text value in popup
660 Toolkit::TextView mHandleValueTextView; ///< The text value on handle
661 Vector2 mHandleLastTouchPoint; ///< The last touch point for the handle
662 Timer mValueTimer; ///< Timer used to hide value view
664 Toolkit::Slider::ValueChangedSignalType mValueChangedSignal; ///< Signal emitted when the value is changed
665 Toolkit::Slider::ValueChangedSignalType mSlidingFinishedSignal; ///< Signal emitted when a sliding is finished
666 Toolkit::Slider::MarkSignalType mMarkSignal; ///< Signal emitted when a mark is reached
668 SliderState mState; ///< The state of the slider
670 PanGestureDetector mPanDetector; ///< Hit region pan detector
672 MarkList mMarks; ///< List of discreet marks
675 Property::Index mPropertyLowerBound;
676 Property::Index mPropertyUpperBound;
677 Property::Index mPropertyValue;
678 Property::Index mPropertyHitRegion;
679 Property::Index mPropertyBackingRegion;
680 Property::Index mPropertyHandleRegion;
682 Property::Index mPropertyBackingImageName;
683 Property::Index mPropertyHandleImageName;
684 Property::Index mPropertyProgressImageName;
685 Property::Index mPropertyPopupImageName;
686 Property::Index mPropertyPopupArrowImageName;
688 Property::Index mPropertyBackingScale9Border;
689 Property::Index mPropertyProgressScale9Border;
690 Property::Index mPropertyPopupScale9Border;
692 Property::Index mPropertyDisableColor;
693 Property::Index mPropertyPopupTextColor;
695 Property::Index mPropertyValuePrecision;
697 Property::Index mPropertyShowPopup;
698 Property::Index mPropertyShowValue;
700 Property::Index mPropertyEnabled;
702 Property::Index mPropertyMarks;
703 Property::Index mPropertySnapToMarks;
704 Property::Index mPropertyMarkTolerance;
708 } // namespace Internal
710 // Helpers for public-api forwarding methods
712 inline Toolkit::Internal::Slider& GetImpl( Toolkit::Slider& pub )
714 DALI_ASSERT_ALWAYS( pub );
716 Dali::RefObject& handle = pub.GetImplementation();
718 return static_cast< Toolkit::Internal::Slider& >( handle );
721 inline const Toolkit::Internal::Slider& GetImpl( const Toolkit::Slider& pub )
723 DALI_ASSERT_ALWAYS( pub );
725 const Dali::RefObject& handle = pub.GetImplementation();
727 return static_cast< const Toolkit::Internal::Slider& >( handle );
730 } // namespace Toolkit
734 #endif // __DALI_TOOLKIT_INTERNAL_SLIDER_H__