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 const Vector2& GetHitRegion() const;
120 * @param[in] region The backing region
122 void SetBackingRegion( const Vector2& region );
127 * @return The backing region
129 const Vector2& GetBackingRegion() const;
132 * @brief Set the disable color.
134 * @param[in] color The disable color.
136 void SetDisableColor( const Vector4& color );
139 * @brief Get disable color
141 * @return The disable color
143 Vector4 GetDisableColor() const;
146 * Get popup text color
148 * @return The popup text color
150 Vector4 GetPopupTextColor() const;
153 * Set the value precision to be used for numbers in the slider
155 * @param[in] precision The number of decimal places to use for printing numbers
157 void SetValuePrecision( int precision );
160 * Get value precision
162 * @return The value precision
164 int GetValuePrecision() const;
169 * @param[in] showPopup The show popup flag
171 void SetShowPopup( 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 SetShowValue( 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 * @brief Set the mark tolerance
211 * The tolerance is the percentage of the slider width for which snapping to
214 * @param[in] tolerance The percentage of width for which to snap
216 void SetMarkTolerance( float tolerance );
219 * Return the mark tolerance
221 * @return The tolerance set for snapping to marks
223 float GetMarkTolerance() const;
229 * @copydoc Toolkit::Slider::ValueChangedSignal()
231 Toolkit::Slider::ValueChangedSignalType& ValueChangedSignal();
234 * copydoc Toolkit::Slider::SlidingFinishedSignal()
236 Toolkit::Slider::ValueChangedSignalType& SlidingFinishedSignal();
239 * @copydoc Toolkit::Slider::MarkSignal()
241 Toolkit::Slider::MarkSignalType& MarkSignal();
244 * Connects a callback function with the object's signals.
245 * @param[in] object The object providing the signal.
246 * @param[in] tracker Used to disconnect the signal.
247 * @param[in] signalName The signal to connect to.
248 * @param[in] functor A newly allocated FunctorDelegate.
249 * @return True if the signal was connected.
250 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
252 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName,
253 FunctorDelegate* functor );
258 * Called when a property of an object of this type is set.
259 * @param[in] object The object whose property is set.
260 * @param[in] index The property index.
261 * @param[in] value The new property value.
263 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
266 * Called to retrieve a property of an object of this type.
267 * @param[in] object The object whose property is to be retrieved.
268 * @param[in] index The property index.
269 * @return The current value of the property.
271 static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
276 * Construct a new Slider.
281 * A reference counted object may only be deleted by calling Unreference()
286 * @copydoc Toolkit::ControlImpl::OnControlSizeSet( const Vector3& size )
288 virtual void OnControlSizeSet( const Vector3& size );
293 * Domain is a from/to pair
303 Domain( Vector2 fromVal, Vector2 toVal )
304 : from( fromVal ), to( toVal )
323 * @copydoc Toolkit::Control::OnInitialize()
325 virtual void OnInitialize();
328 * Hit region touch event
330 * @param[in] actor The actor the event is raised for
331 * @param[in] event The touch event info
332 * @return If the event is handled or not
334 bool OnTouchEvent( Actor actor, const TouchEvent& event );
339 * @param[in] actor The actor the event is raised for
340 * @param[in] gesture The pan event info
342 void OnPan( Actor actor, PanGesture gestur );
345 * Map a position onto a domain and return the result as a percentage
347 * @param[in] point The point to map onto the domain
348 * @return The result as a percentage [0..1]
350 float MapPercentage( const Vector2& point );
353 * Map a value in the range to a percentage
355 * @param[in] point The value in range [lowerBound..upperBound]
356 * @return The result as a percentage [0..1]
358 float MapValuePercentage( float value );
361 * Convert a point in local hit space into domain space
363 * @param[in] x The x position to convert
364 * @return The x position in domain space
366 float HitSpaceToDomain( float x );
369 * Map a percentage onto the slider's bounds
371 * @param[in] percent The current value of slider in percent
372 * @param[in] lowerBound The lower bound to map onto
373 * @param[in] upperBound The upper bound to map onto
374 * @return The value of percent mapped from lowerBound to upperBound
376 float MapBounds( float percent, float lowerBound, float upperBound );
379 * Get the range of the valid values the slider handle can move between
381 * @param[in] currentSize The current size of the slider
382 * @return The range as a domain pair
384 Domain CalcDomain( const Vector2& currentSize );
387 * Create the hit region
389 * @return The hit region actor
391 Actor CreateHitRegion();
394 * Create the backing for the slider
396 * @return The backing actor
398 ImageActor CreateBacking();
401 * Create the progress backing for the slider
403 * @return The backing actor
405 ImageActor CreateProgress();
408 * Create the handle for the slider
410 * @return The created image handle
412 ImageActor CreateHandle();
415 * Create the popup arrow
417 * @return The created image handle
419 ImageActor CreatePopupArrow();
424 * @return The created image handle
426 ImageActor CreatePopup();
429 * Create the textview for the popup
431 * @return The textview created for the popup
433 Toolkit::TextView CreatePopupText();
436 * Create the value display for the slider
438 * @return The created root actor of the display
440 Actor CreateValueDisplay();
443 * Set the skin based on the current state
448 * Create all the children
450 void CreateChildren();
463 * Display the popup for a set duration with the given value
465 * @param[in] value The value to display in the popup
467 void DisplayPopup( float value );
470 * If there are marks present, filter the incoming percent based on snapping to any nearby marks
472 * @param[in] value The incoming value on the slider to filter
473 * @return The filtered percentage snapped to any nearby marks
475 float MarkFilter( float value );
478 * If there are marks present, snap the incoming percent to the nearest mark
480 * @param[in] value The incoming value on the slider to snap
481 * @return The filtered percentage snapped to the nearest mark
483 float SnapToMark( float value );
486 * Search for if a mark has been reached
488 * @param[in] value The value to search against
489 * @param[out] outIndex The index of the mark if found
490 * @return If a mark has been found to match percent
492 bool MarkReached( float value, int& outIndex );
495 * Handler for when the value view needs to be hidden
497 * @return If handled or not
499 bool HideValueView();
502 * Set value choosing whether to fire signals or not
504 * @paramp[in] value The value to set
505 * @param[in] raiseSignals Configure signals to be raised or not.
507 void DisplayValue( float value, bool raiseSignals );
510 * Create the image for the backing
512 * @param[in] imageName The name of the image to load and set
514 void SetBackingImageName( const std::string& imageName );
517 * @brief Return the backing image file name.
519 * @return The backing image file name.
521 std::string GetBackingImageName();
524 * Create the image for the progress bar
526 * @param[in] imageName The name of the image to load and set
528 void SetProgressImageName( const std::string& imageName );
531 * @brief Return the progress image name.
533 * @return The progress image name if it exists.
535 std::string GetProgressImageName();
538 * @brief Create the image for the popup
540 * @param[in] imageName The name of the image to load and set
542 void CreatePopupImage( const std::string& imageName );
545 * @brief Set the popup name
547 * @param[in] imageName The name of the image to set
549 void SetPopupImageName( const std::string& imageName );
552 * @brief Return the popup image name.
554 * @return The name of the popup image if it exists.
556 std::string GetPopupImageName();
559 * @brief Set the popup arrow image name
561 * @param[in] imageName The name of the image to set
563 void SetPopupArrowImageName( const std::string& imageName );
566 * @brief Return the popup arrow image name.
568 * @return The name of the popup image if it exists.
570 std::string GetPopupArrowImageName();
573 * Create the image for the popup arrow
575 * @param[in] imageName The name of the image to load and set
577 void CreatePopupArrowImage( const std::string& imageName );
580 * Set the size of the progress bar region
582 * @param[in] region The size of the region to set
584 void ResizeProgressRegion( const Vector2& region );
587 * Create the image for the handle
589 * @param[in] imageName The name of the image to load and set
591 void SetHandleImageName( const std::string& imageName );
594 * @brief Return the handle image name.
596 * @return The name of the image handle if it exists.
598 std::string GetHandleImageName();
601 * Set the size of the handle region
603 * @param[in] region The size of the region to set
605 void ResizeHandleRegion( const Vector2& region );
608 * Create and display the value on the handle
610 void CreateHandleValueDisplay();
613 * Remove and destroy the handle value display
615 void DestroyHandleValueDisplay();
618 * Update the color of the popup text
620 * @param[in] color The new color
622 void SetPopupTextColor( const Vector4& color );
627 * @param[in] region The handle region
629 void SetHandleRegion( const Vector2& region );
634 * @return The handle region
636 const Vector2& GetHandleRegion() const;
639 * Set the lower bound of the slider's value
641 * @param[in] bound The value to set for the lower bound
643 void SetLowerBound( float bound );
646 * Get the lower bound of the slider's value
648 * @return The lower bound value
650 float GetLowerBound() const;
653 * Set the upper bound of the slider's value
655 * @param[in] bound The value to set for the upper bound
657 void SetUpperBound( float bound );
660 * Get the upper bound of the slider's value
662 * @return The upper bound value
664 float GetUpperBound() const;
669 Slider( const Slider& );
672 Slider& operator=( const Slider& rhs );
676 Domain mDomain; ///< Current domain of the handle
678 Actor mHitArea; ///< The input handler
679 ImageActor mBacking; ///< Backing image
680 ImageActor mHandle; ///< Slider handle
681 ImageActor mProgress; ///< Progress backing
682 Actor mValueDisplay; ///< Display of the value
683 ImageActor mPopup; ///< Popup backing
684 ImageActor mPopupArrow; ///< Popup arrow backing
686 Toolkit::TextView mValueTextView; //< The text value in popup
687 Toolkit::TextView mHandleValueTextView; ///< The text value on handle
688 Vector2 mHandleLastTouchPoint; ///< The last touch point for the handle
689 Timer mValueTimer; ///< Timer used to hide value view
691 Toolkit::Slider::ValueChangedSignalType mValueChangedSignal; ///< Signal emitted when the value is changed
692 Toolkit::Slider::ValueChangedSignalType mSlidingFinishedSignal; ///< Signal emitted when a sliding is finished
693 Toolkit::Slider::MarkSignalType mMarkSignal; ///< Signal emitted when a mark is reached
695 SliderState mState; ///< The state of the slider
697 PanGestureDetector mPanDetector; ///< Hit region pan detector
699 MarkList mMarks; ///< List of discreet marks
701 std::string mPopupImageName; ///< Image name for popup image
702 std::string mPopupArrowImageName; ///< Image name for popup arrow
704 Vector4 mDisableColor; ///< The color to tint the slider when disabled
705 Vector4 mPopupTextColor; ///< The color of the popup text
707 Vector2 mHitRegion; ///< Size of hit region
708 Vector2 mBackingRegion; ///< Size of backing region
709 Vector2 mHandleRegionSize; ///< Size of the handle region
711 float mLowerBound; ///< Lower bound on value
712 float mUpperBound; ///< Upper bound on value
713 float mValue; ///< Current value of slider
715 float mMarkTolerance; ///< Tolerance in percentage of slider width for which to snap to marks
717 int mValuePrecision; ///< The precision to use for outputting the value
719 bool mShowPopup : 1, ///< Show the popup or not
720 mShowValue : 1, ///< Whether to display the value number or not on the handle
721 mSnapToMarks : 1; ///< Turn on or off snapping to marks
724 } // namespace Internal
726 // Helpers for public-api forwarding methods
728 inline Toolkit::Internal::Slider& GetImpl( Toolkit::Slider& pub )
730 DALI_ASSERT_ALWAYS( pub );
732 Dali::RefObject& handle = pub.GetImplementation();
734 return static_cast< Toolkit::Internal::Slider& >( handle );
737 inline const Toolkit::Internal::Slider& GetImpl( const Toolkit::Slider& pub )
739 DALI_ASSERT_ALWAYS( pub );
741 const Dali::RefObject& handle = pub.GetImplementation();
743 return static_cast< const Toolkit::Internal::Slider& >( handle );
746 } // namespace Toolkit
750 #endif // __DALI_TOOLKIT_INTERNAL_SLIDER_H__