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 Control
51 SLIDER_PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
52 SLIDER_PROPERTY_END_INDEX = SLIDER_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices
55 typedef Property::Array MarkList;
58 * Create a new Slider.
60 * @return A public handle to the newly allocated Slider.
62 static Dali::Toolkit::Slider New();
69 * Set marks from a list
71 * @param[in] marks The list of marks to set
73 void SetMarks( const MarkList& marks );
76 * Get the list of marks
78 * @return The marks list
80 const MarkList& GetMarks() const;
83 * Set if should snap to marks or not
85 * @param[in] snap Flag to snap to marks or not
87 void SetSnapToMarks( bool snap );
90 * Return if snap to marks is set or not
92 * @return If snap to marks is set
94 bool GetSnapToMarks() const;
97 * Set the value of the slider
99 * @param[in] value The value to set. Will be clamped to [lowerBound .. upperBound]
101 void SetValue( float value );
104 * Get the value of the slider
106 * @return The current value of the slider
108 float GetValue() const;
113 * @param[in] region The hit region
115 void SetHitRegion( const Vector2& region );
120 * @return The hit region
122 const Vector2& GetHitRegion() const;
127 * @param[in] region The backing region
129 void SetBackingRegion( const Vector2& region );
134 * @return The backing region
136 const Vector2& GetBackingRegion() const;
139 * @brief Set the disable color.
141 * @param[in] color The disable color.
143 void SetDisableColor( const Vector4& color );
146 * @brief Get disable color
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 * Set the value precision to be used for numbers in the slider
162 * @param[in] precision The number of decimal places to use for printing numbers
164 void SetValuePrecision( int precision );
167 * Get value precision
169 * @return The value precision
171 int GetValuePrecision() const;
176 * @param[in] showPopup The show popup flag
178 void SetShowPopup( bool showPopup );
181 * Get show value in popup
183 * @return The show value flag
185 bool GetShowPopup() const;
188 * Set show value on handle
190 * @param[in] showValue The show value flag
192 void SetShowValue( bool showValue );
195 * Get show value on handle
197 * @return The show value flag
199 bool GetShowValue() const;
204 * param[in] enabled Set the enabled flag
206 void SetEnabled( bool enabled );
209 * Return if enabled or not
213 bool IsEnabled() const;
216 * @brief Set the mark tolerance
218 * The tolerance is the percentage of the slider width for which snapping to
221 * @param[in] tolerance The percentage of width for which to snap
223 void SetMarkTolerance( float tolerance );
226 * Return the mark tolerance
228 * @return The tolerance set for snapping to marks
230 float GetMarkTolerance() const;
236 * @copydoc Toolkit::Slider::ValueChangedSignal()
238 Toolkit::Slider::ValueChangedSignalType& ValueChangedSignal();
241 * copydoc Toolkit::Slider::SlidingFinishedSignal()
243 Toolkit::Slider::ValueChangedSignalType& SlidingFinishedSignal();
246 * @copydoc Toolkit::Slider::MarkSignal()
248 Toolkit::Slider::MarkSignalType& MarkSignal();
251 * Connects a callback function with the object's signals.
252 * @param[in] object The object providing the signal.
253 * @param[in] tracker Used to disconnect the signal.
254 * @param[in] signalName The signal to connect to.
255 * @param[in] functor A newly allocated FunctorDelegate.
256 * @return True if the signal was connected.
257 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
259 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName,
260 FunctorDelegate* functor );
265 * Called when a property of an object of this type is set.
266 * @param[in] object The object whose property is set.
267 * @param[in] index The property index.
268 * @param[in] value The new property value.
270 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
273 * Called to retrieve a property of an object of this type.
274 * @param[in] object The object whose property is to be retrieved.
275 * @param[in] index The property index.
276 * @return The current value of the property.
278 static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
283 * Construct a new Slider.
288 * A reference counted object may only be deleted by calling Unreference()
293 * @copydoc Control::OnControlSizeSet( const Vector3& size )
295 virtual void OnControlSizeSet( const Vector3& size );
300 * Domain is a from/to pair
310 Domain( Vector2 fromVal, Vector2 toVal )
311 : from( fromVal ), to( toVal )
330 * @copydoc Toolkit::Control::OnInitialize()
332 virtual void OnInitialize();
335 * Hit region touch event
337 * @param[in] actor The actor the event is raised for
338 * @param[in] event The touch event info
339 * @return If the event is handled or not
341 bool OnTouchEvent( Actor actor, const TouchEvent& event );
346 * @param[in] actor The actor the event is raised for
347 * @param[in] gesture The pan event info
349 void OnPan( Actor actor, PanGesture gestur );
352 * Map a position onto a domain and return the result as a percentage
354 * @param[in] point The point to map onto the domain
355 * @return The result as a percentage [0..1]
357 float MapPercentage( const Vector2& point );
360 * Map a value in the range to a percentage
362 * @param[in] point The value in range [lowerBound..upperBound]
363 * @return The result as a percentage [0..1]
365 float MapValuePercentage( float value );
368 * Convert a point in local hit space into domain space
370 * @param[in] x The x position to convert
371 * @return The x position in domain space
373 float HitSpaceToDomain( float x );
376 * Map a percentage onto the slider's bounds
378 * @param[in] percent The current value of slider in percent
379 * @param[in] lowerBound The lower bound to map onto
380 * @param[in] upperBound The upper bound to map onto
381 * @return The value of percent mapped from lowerBound to upperBound
383 float MapBounds( float percent, float lowerBound, float upperBound );
386 * Get the range of the valid values the slider handle can move between
388 * @param[in] currentSize The current size of the slider
389 * @return The range as a domain pair
391 Domain CalcDomain( const Vector2& currentSize );
394 * Create the hit region
396 * @return The hit region actor
398 Actor CreateHitRegion();
401 * Create the backing for the slider
403 * @return The backing actor
405 ImageActor CreateBacking();
408 * Create the progress backing for the slider
410 * @return The backing actor
412 ImageActor CreateProgress();
415 * Create the handle for the slider
417 * @return The created image handle
419 ImageActor CreateHandle();
422 * Create the popup arrow
424 * @return The created image handle
426 ImageActor CreatePopupArrow();
431 * @return The created image handle
433 ImageActor CreatePopup();
436 * Create the textview for the popup
438 * @return The textview created for the popup
440 Toolkit::TextView CreatePopupText();
443 * Create the value display for the slider
445 * @return The created root actor of the display
447 Actor CreateValueDisplay();
450 * Set the skin based on the current state
455 * Create all the children
457 void CreateChildren();
470 * Display the popup for a set duration with the given value
472 * @param[in] value The value to display in the popup
474 void DisplayPopup( float value );
477 * If there are marks present, filter the incoming percent based on snapping to any nearby marks
479 * @param[in] value The incoming value on the slider to filter
480 * @return The filtered percentage snapped to any nearby marks
482 float MarkFilter( float value );
485 * If there are marks present, snap the incoming percent to the nearest mark
487 * @param[in] value The incoming value on the slider to snap
488 * @return The filtered percentage snapped to the nearest mark
490 float SnapToMark( float value );
493 * Search for if a mark has been reached
495 * @param[in] value The value to search against
496 * @param[out] outIndex The index of the mark if found
497 * @return If a mark has been found to match percent
499 bool MarkReached( float value, int& outIndex );
502 * Handler for when the value view needs to be hidden
504 * @return If handled or not
506 bool HideValueView();
509 * Set value choosing whether to fire signals or not
511 * @paramp[in] value The value to set
512 * @param[in] raiseSignals Configure signals to be raised or not.
514 void DisplayValue( float value, bool raiseSignals );
517 * Create the image for the backing
519 * @param[in] imageName The name of the image to load and set
521 void SetBackingImageName( const std::string& imageName );
524 * @brief Return the backing image file name.
526 * @return The backing image file name.
528 std::string GetBackingImageName();
531 * Create the image for the progress bar
533 * @param[in] imageName The name of the image to load and set
535 void SetProgressImageName( const std::string& imageName );
538 * @brief Return the progress image name.
540 * @return The progress image name if it exists.
542 std::string GetProgressImageName();
545 * @brief Create the image for the popup
547 * @param[in] imageName The name of the image to load and set
549 void CreatePopupImage( const std::string& imageName );
552 * @brief Set the popup name
554 * @param[in] imageName The name of the image to set
556 void SetPopupImageName( const std::string& imageName );
559 * @brief Return the popup image name.
561 * @return The name of the popup image if it exists.
563 std::string GetPopupImageName();
566 * @brief Set the popup arrow image name
568 * @param[in] imageName The name of the image to set
570 void SetPopupArrowImageName( const std::string& imageName );
573 * @brief Return the popup arrow image name.
575 * @return The name of the popup image if it exists.
577 std::string GetPopupArrowImageName();
580 * Create the image for the popup arrow
582 * @param[in] imageName The name of the image to load and set
584 void CreatePopupArrowImage( const std::string& imageName );
587 * Set the size of the progress bar region
589 * @param[in] region The size of the region to set
591 void ResizeProgressRegion( const Vector2& region );
594 * Create the image for the handle
596 * @param[in] imageName The name of the image to load and set
598 void SetHandleImageName( const std::string& imageName );
601 * @brief Return the handle image name.
603 * @return The name of the image handle if it exists.
605 std::string GetHandleImageName();
608 * Set the size of the handle region
610 * @param[in] region The size of the region to set
612 void ResizeHandleRegion( const Vector2& region );
615 * Create and display the value on the handle
617 void CreateHandleValueDisplay();
620 * Remove and destroy the handle value display
622 void DestroyHandleValueDisplay();
625 * Update the color of the popup text
627 * @param[in] color The new color
629 void SetPopupTextColor( const Vector4& color );
634 * @param[in] region The handle region
636 void SetHandleRegion( const Vector2& region );
641 * @return The handle region
643 const Vector2& GetHandleRegion() const;
646 * Set the lower bound of the slider's value
648 * @param[in] bound The value to set for the lower bound
650 void SetLowerBound( float bound );
653 * Get the lower bound of the slider's value
655 * @return The lower bound value
657 float GetLowerBound() const;
660 * Set the upper bound of the slider's value
662 * @param[in] bound The value to set for the upper bound
664 void SetUpperBound( float bound );
667 * Get the upper bound of the slider's value
669 * @return The upper bound value
671 float GetUpperBound() const;
676 Slider( const Slider& );
679 Slider& operator=( const Slider& rhs );
683 Domain mDomain; ///< Current domain of the handle
685 Actor mHitArea; ///< The input handler
686 ImageActor mBacking; ///< Backing image
687 ImageActor mHandle; ///< Slider handle
688 ImageActor mProgress; ///< Progress backing
689 Actor mValueDisplay; ///< Display of the value
690 ImageActor mPopup; ///< Popup backing
691 ImageActor mPopupArrow; ///< Popup arrow backing
693 Toolkit::TextView mValueTextView; //< The text value in popup
694 Toolkit::TextView mHandleValueTextView; ///< The text value on handle
695 Vector2 mHandleLastTouchPoint; ///< The last touch point for the handle
696 Timer mValueTimer; ///< Timer used to hide value view
698 Toolkit::Slider::ValueChangedSignalType mValueChangedSignal; ///< Signal emitted when the value is changed
699 Toolkit::Slider::ValueChangedSignalType mSlidingFinishedSignal; ///< Signal emitted when a sliding is finished
700 Toolkit::Slider::MarkSignalType mMarkSignal; ///< Signal emitted when a mark is reached
702 SliderState mState; ///< The state of the slider
704 PanGestureDetector mPanDetector; ///< Hit region pan detector
706 MarkList mMarks; ///< List of discreet marks
708 std::string mPopupImageName; ///< Image name for popup image
709 std::string mPopupArrowImageName; ///< Image name for popup arrow
711 Vector4 mDisableColor; ///< The color to tint the slider when disabled
712 Vector4 mPopupTextColor; ///< The color of the popup text
714 Vector2 mHitRegion; ///< Size of hit region
715 Vector2 mBackingRegion; ///< Size of backing region
716 Vector2 mHandleRegionSize; ///< Size of the handle region
718 float mLowerBound; ///< Lower bound on value
719 float mUpperBound; ///< Upper bound on value
720 float mValue; ///< Current value of slider
722 float mMarkTolerance; ///< Tolerance in percentage of slider width for which to snap to marks
724 int mValuePrecision; ///< The precision to use for outputting the value
726 bool mShowPopup : 1, ///< Show the popup or not
727 mShowValue : 1, ///< Whether to display the value number or not on the handle
728 mSnapToMarks : 1; ///< Turn on or off snapping to marks
731 } // namespace Internal
733 // Helpers for public-api forwarding methods
735 inline Toolkit::Internal::Slider& GetImpl( Toolkit::Slider& pub )
737 DALI_ASSERT_ALWAYS( pub );
739 Dali::RefObject& handle = pub.GetImplementation();
741 return static_cast< Toolkit::Internal::Slider& >( handle );
744 inline const Toolkit::Internal::Slider& GetImpl( const Toolkit::Slider& pub )
746 DALI_ASSERT_ALWAYS( pub );
748 const Dali::RefObject& handle = pub.GetImplementation();
750 return static_cast< const Toolkit::Internal::Slider& >( handle );
753 } // namespace Toolkit
757 #endif // __DALI_TOOLKIT_INTERNAL_SLIDER_H__