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::MarkSignal()
226 Toolkit::Slider::MarkSignalType& MarkSignal();
229 * Connects a callback function with the object's signals.
230 * @param[in] object The object providing the signal.
231 * @param[in] tracker Used to disconnect the signal.
232 * @param[in] signalName The signal to connect to.
233 * @param[in] functor A newly allocated FunctorDelegate.
234 * @return True if the signal was connected.
235 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
237 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName,
238 FunctorDelegate* functor );
243 * Construct a new Slider.
248 * A reference counted object may only be deleted by calling Unreference()
253 * @copydoc Toolkit::ControlImpl::OnControlSizeSet( const Vector3& size )
255 virtual void OnControlSizeSet( const Vector3& size );
260 * Domain is a from/to pair
270 Domain( Vector2 fromVal, Vector2 toVal )
271 : from( fromVal ), to( toVal )
290 * @copydoc Toolkit::Control::OnInitialize()
292 virtual void OnInitialize();
295 * Hit region touch event
297 * @param[in] actor The actor the event is raised for
298 * @param[in] event The touch event info
299 * @return If the event is handled or not
301 bool OnTouchEvent( Actor actor, const TouchEvent& event );
306 * @param[in] actor The actor the event is raised for
307 * @param[in] gesture The pan event info
309 void OnPan( Actor actor, PanGesture gestur );
312 * Map a position onto a domain and return the result as a percentage
314 * @param[in] point The point to map onto the domain
315 * @return The result as a percentage [0..1]
317 float MapPercentage( const Vector2& point );
320 * Map a value in the range to a percentage
322 * @param[in] point The value in range [lowerBound..upperBound]
323 * @return The result as a percentage [0..1]
325 float MapValuePercentage( float value );
328 * Convert a point in local hit space into domain space
330 * @param[in] x The x position to convert
331 * @return The x position in domain space
333 float HitSpaceToDomain( float x );
336 * Map a percentage onto the slider's bounds
338 * @param[in] percent The current value of slider in percent
339 * @param[in] lowerBound The lower bound to map onto
340 * @param[in] upperBound The upper bound to map onto
341 * @return The value of percent mapped from lowerBound to upperBound
343 float MapBounds( float percent, float lowerBound, float upperBound );
346 * Get the range of the valid values the slider handle can move between
348 * @param[in] currentSize The current size of the slider
349 * @return The range as a domain pair
351 Domain CalcDomain( const Vector2& currentSize );
354 * Create the hit region
356 * @return The hit region actor
358 Actor CreateHitRegion();
361 * Create the backing for the slider
363 * @return The backing actor
365 ImageActor CreateBacking();
368 * Create the progress backing for the slider
370 * @return The backing actor
372 ImageActor CreateProgress();
375 * Create the handle for the slider
377 * @return The created image handle
379 ImageActor CreateHandle();
382 * Create the popup arrow
384 * @return The created image handle
386 ImageActor CreatePopupArrow();
391 * @return The created image handle
393 ImageActor CreatePopup();
396 * Create the textview for the popup
398 * @return The textview created for the popup
400 Toolkit::TextView CreatePopupText();
403 * Create the value display for the slider
405 * @return The created root actor of the display
407 Actor CreateValueDisplay();
410 * Set the skin based on the current state
415 * Create all the children
417 void CreateChildren();
420 * Resize the hit area
422 * @param[in] size The new size of the hit area
424 void ResizeHitRegion( const Vector2& size );
437 * Display the popup for a set duration with the given value
439 * @param[in] value The value to display in the popup
441 void DisplayPopup( float value );
444 * If there are marks present, filter the incoming percent based on snapping to any nearby marks
446 * @param[in] value The incoming value on the slider to filter
447 * @return The filtered percentage snapped to any nearby marks
449 float MarkFilter( float value );
452 * If there are marks present, snap the incoming percent to the nearest mark
454 * @param[in] value The incoming value on the slider to snap
455 * @return The filtered percentage snapped to the nearest mark
457 float SnapToMark( float value );
460 * Search for if a mark has been reached
462 * @param[in] value The value to search against
463 * @param[out] outIndex The index of the mark if found
464 * @return If a mark has been found to match percent
466 bool MarkReached( float value, int& outIndex );
469 * Handler for when the value view needs to be hidden
471 * @return If handled or not
473 bool HideValueView();
476 * Set value choosing whether to fire signals or not
478 * @paramp[in] value The value to set
479 * @param[in] raiseSignals Configure signals to be raised or not.
481 void DisplayValue( float value, bool raiseSignals );
484 * Create the image for the backing
486 * @param[in] imageName The name of the image to load and set
488 void CreateBackingImage( const std::string& imageName );
491 * Set the backing image to be a scale-9 image
493 * @param[in] border The scale-9 border to use
495 void SetBackingScale9( const Vector4& border );
498 * Resize the backing region
500 * @param[in] region The size of the region to set
502 void ResizeBackingRegion( const Vector2& region );
505 * Size the backing region
507 * @param[in] region The size of the region to set
509 void SetBackingRegionSize( const Vector2& region );
512 * Create the image for the progress bar
514 * @param[in] imageName The name of the image to load and set
516 void CreateProgressImage( const std::string& imageName );
519 * Create the image for the popup
521 * @param[in] imageName The name of the image to load and set
523 void CreatePopupImage( const std::string& imageName );
526 * Create the image for the popup arrow
528 * @param[in] imageName The name of the image to load and set
530 void CreatePopupArrowImage( const std::string& imageName );
533 * Set the progress image to be a scale-9 image
535 * @param[in] border The scale-9 border to use
537 void SetProgressScale9( const Vector4& border );
540 * Set the popup image to be a scale-9 image
542 * @param[in] border The scale-9 border to use
544 void SetPopupScale9( const Vector4& border );
547 * Set the size of the progress bar region
549 * @param[in] region The size of the region to set
551 void ResizeProgressRegion( const Vector2& region );
554 * Create the image for the handle
556 * @param[in] imageName The name of the image to load and set
558 void CreateHandleImage( const std::string& imageName );
561 * Set the size of the handle region
563 * @param[in] region The size of the region to set
565 void ResizeHandleRegion( const Vector2& region );
568 * Create and display the value on the handle
570 void CreateHandleValueDisplay();
573 * Remove and destroy the handle value display
575 void DestroyHandleValueDisplay();
578 * Update the color of the popup text
580 * @param[in] color The new color
582 void UpdatePopupTextColor( const Vector4& color );
587 * @param[in] region The handle region
589 void UpdateHandleRegion( const Vector2& region );
594 * @return The handle region
596 Vector2 GetHandleRegion() const;
599 * Set the lower bound of the slider's value
601 * @param[in] bound The value to set for the lower bound
603 void UpdateLowerBound( float bound );
606 * Get the lower bound of the slider's value
608 * @return The lower bound value
610 float GetLowerBound() const;
613 * Set the upper bound of the slider's value
615 * @param[in] bound The value to set for the upper bound
617 void UpdateUpperBound( float bound );
620 * Get the upper bound of the slider's value
622 * @return The upper bound value
624 float GetUpperBound() const;
630 * @copydoc Dali::CustomActorImpl::OnPropertySet()
632 virtual void OnPropertySet( Property::Index index, Property::Value propertyValue );
637 Slider( const Slider& );
640 Slider& operator=( const Slider& rhs );
644 Domain mDomain; ///< Current domain of the handle
646 Actor mHitArea; ///< The input handler
647 ImageActor mBacking; ///< Backing image
648 ImageActor mHandle; ///< Slider handle
649 ImageActor mProgress; ///< Progress backing
650 Actor mValueDisplay; ///< Display of the value
651 ImageActor mPopup; ///< Popup backing
652 ImageActor mPopupArrow; ///< Popup arrow backing
654 Toolkit::TextView mValueTextView; //< The text value in popup
655 Toolkit::TextView mHandleValueTextView; ///< The text value on handle
656 Vector2 mHandleLastTouchPoint; ///< The last touch point for the handle
657 Timer mValueTimer; ///< Timer used to hide value view
659 Toolkit::Slider::ValueChangedSignalType mValueChangedSignal; ///< Signal emitted when the value is changed
660 Toolkit::Slider::MarkSignalType mMarkSignal; ///< Signal emitted when a mark is reached
662 SliderState mState; ///< The state of the slider
664 PanGestureDetector mPanDetector; ///< Hit region pan detector
666 MarkList mMarks; ///< List of discreet marks
669 Property::Index mPropertyLowerBound;
670 Property::Index mPropertyUpperBound;
671 Property::Index mPropertyValue;
672 Property::Index mPropertyHitRegion;
673 Property::Index mPropertyBackingRegion;
674 Property::Index mPropertyHandleRegion;
676 Property::Index mPropertyBackingImageName;
677 Property::Index mPropertyHandleImageName;
678 Property::Index mPropertyProgressImageName;
679 Property::Index mPropertyPopupImageName;
680 Property::Index mPropertyPopupArrowImageName;
682 Property::Index mPropertyBackingScale9Border;
683 Property::Index mPropertyProgressScale9Border;
684 Property::Index mPropertyPopupScale9Border;
686 Property::Index mPropertyDisableColor;
687 Property::Index mPropertyPopupTextColor;
689 Property::Index mPropertyValuePrecision;
691 Property::Index mPropertyShowPopup;
692 Property::Index mPropertyShowValue;
694 Property::Index mPropertyEnabled;
696 Property::Index mPropertyMarks;
697 Property::Index mPropertySnapToMarks;
698 Property::Index mPropertyMarkTolerance;
702 } // namespace Internal
704 // Helpers for public-api forwarding methods
706 inline Toolkit::Internal::Slider& GetImpl( Toolkit::Slider& pub )
708 DALI_ASSERT_ALWAYS( pub );
710 Dali::RefObject& handle = pub.GetImplementation();
712 return static_cast< Toolkit::Internal::Slider& >( handle );
715 inline const Toolkit::Internal::Slider& GetImpl( const Toolkit::Slider& pub )
717 DALI_ASSERT_ALWAYS( pub );
719 const Dali::RefObject& handle = pub.GetImplementation();
721 return static_cast< const Toolkit::Internal::Slider& >( handle );
724 } // namespace Toolkit
728 #endif // __DALI_TOOLKIT_INTERNAL_SLIDER_H__