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 Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/actors/image-actor.h>
23 #include <dali/public-api/adaptor-framework/timer.h>
26 #include <dali-toolkit/public-api/controls/control-impl.h>
27 #include <dali-toolkit/public-api/controls/slider/slider.h>
42 typedef Dali::IntrusivePtr< Slider > SliderPtr;
45 * @copydoc Toolkit::Slider
47 class Slider : public Control
51 typedef Property::Array MarkList;
54 * Create a new Slider.
56 * @return A public handle to the newly allocated Slider.
58 static Dali::Toolkit::Slider New();
65 * Set marks from a list
67 * @param[in] marks The list of marks to set
69 void SetMarks( const MarkList& marks );
72 * Get the list of marks
74 * @return The marks list
76 const MarkList& GetMarks() const;
79 * Set if should snap to marks or not
81 * @param[in] snap Flag to snap to marks or not
83 void SetSnapToMarks( bool snap );
86 * Return if snap to marks is set or not
88 * @return If snap to marks is set
90 bool GetSnapToMarks() const;
93 * Set the value of the slider
95 * @param[in] value The value to set. Will be clamped to [lowerBound .. upperBound]
97 void SetValue( float value );
100 * Get the value of the slider
102 * @return The current value of the slider
104 float GetValue() const;
109 * @param[in] region The hit region
111 void SetHitRegion( const Vector2& region );
116 * @return The hit region
118 const Vector2& GetHitRegion() const;
123 * @param[in] region The backing region
125 void SetBackingRegion( const Vector2& region );
130 * @return The backing region
132 const Vector2& GetBackingRegion() const;
135 * @brief Set the disable color.
137 * @param[in] color The disable color.
139 void SetDisableColor( const Vector4& color );
142 * @brief Get disable color
144 * @return The disable color
146 Vector4 GetDisableColor() const;
149 * Get popup text color
151 * @return The popup text color
153 Vector4 GetPopupTextColor() const;
156 * Set the value precision to be used for numbers in the slider
158 * @param[in] precision The number of decimal places to use for printing numbers
160 void SetValuePrecision( int precision );
163 * Get value precision
165 * @return The value precision
167 int GetValuePrecision() const;
172 * @param[in] showPopup The show popup flag
174 void SetShowPopup( bool showPopup );
177 * Get show value in popup
179 * @return The show value flag
181 bool GetShowPopup() const;
184 * Set show value on handle
186 * @param[in] showValue The show value flag
188 void SetShowValue( bool showValue );
191 * Get show value on handle
193 * @return The show value flag
195 bool GetShowValue() const;
200 * param[in] enabled Set the enabled flag
202 void SetEnabled( bool enabled );
205 * Return if enabled or not
209 bool IsEnabled() const;
212 * @brief Set the mark tolerance
214 * The tolerance is the percentage of the slider width for which snapping to
217 * @param[in] tolerance The percentage of width for which to snap
219 void SetMarkTolerance( float tolerance );
222 * Return the mark tolerance
224 * @return The tolerance set for snapping to marks
226 float GetMarkTolerance() const;
232 * @copydoc Toolkit::Slider::ValueChangedSignal()
234 Toolkit::Slider::ValueChangedSignalType& ValueChangedSignal();
237 * copydoc Toolkit::Slider::SlidingFinishedSignal()
239 Toolkit::Slider::ValueChangedSignalType& SlidingFinishedSignal();
242 * @copydoc Toolkit::Slider::MarkSignal()
244 Toolkit::Slider::MarkSignalType& MarkSignal();
247 * Connects a callback function with the object's signals.
248 * @param[in] object The object providing the signal.
249 * @param[in] tracker Used to disconnect the signal.
250 * @param[in] signalName The signal to connect to.
251 * @param[in] functor A newly allocated FunctorDelegate.
252 * @return True if the signal was connected.
253 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
255 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName,
256 FunctorDelegate* functor );
261 * Called when a property of an object of this type is set.
262 * @param[in] object The object whose property is set.
263 * @param[in] index The property index.
264 * @param[in] value The new property value.
266 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
269 * Called to retrieve a property of an object of this type.
270 * @param[in] object The object whose property is to be retrieved.
271 * @param[in] index The property index.
272 * @return The current value of the property.
274 static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
279 * Construct a new Slider.
284 * A reference counted object may only be deleted by calling Unreference()
289 * @copydoc Control::OnControlSizeSet( const Vector3& size )
291 virtual void OnControlSizeSet( const Vector3& size );
296 * Domain is a from/to pair
306 Domain( Vector2 fromVal, Vector2 toVal )
307 : from( fromVal ), to( toVal )
326 * @copydoc Toolkit::Control::OnInitialize()
328 virtual void OnInitialize();
331 * Hit region touch event
333 * @param[in] actor The actor the event is raised for
334 * @param[in] event The touch event info
335 * @return If the event is handled or not
337 bool OnTouchEvent( Actor actor, const TouchEvent& event );
342 * @param[in] actor The actor the event is raised for
343 * @param[in] gesture The pan event info
345 void OnPan( Actor actor, const PanGesture& gesture );
348 * Map a position onto a domain and return the result as a percentage
350 * @param[in] point The point to map onto the domain
351 * @return The result as a percentage [0..1]
353 float MapPercentage( const Vector2& point );
356 * Map a value in the range to a percentage
358 * @param[in] point The value in range [lowerBound..upperBound]
359 * @return The result as a percentage [0..1]
361 float MapValuePercentage( float value );
364 * Convert a point in local hit space into domain space
366 * @param[in] x The x position to convert
367 * @return The x position in domain space
369 float HitSpaceToDomain( float x );
372 * Map a percentage onto the slider's bounds
374 * @param[in] percent The current value of slider in percent
375 * @param[in] lowerBound The lower bound to map onto
376 * @param[in] upperBound The upper bound to map onto
377 * @return The value of percent mapped from lowerBound to upperBound
379 float MapBounds( float percent, float lowerBound, float upperBound );
382 * Get the range of the valid values the slider handle can move between
384 * @param[in] currentSize The current size of the slider
385 * @return The range as a domain pair
387 Domain CalcDomain( const Vector2& currentSize );
390 * Create the hit region
392 * @return The hit region actor
394 Actor CreateHitRegion();
397 * Create the backing for the slider
399 * @return The backing actor
401 ImageActor CreateBacking();
404 * Create the progress backing for the slider
406 * @return The backing actor
408 ImageActor CreateProgress();
411 * Create the handle for the slider
413 * @return The created image handle
415 ImageActor CreateHandle();
418 * Create the popup arrow
420 * @return The created image handle
422 ImageActor CreatePopupArrow();
427 * @return The created image handle
429 ImageActor CreatePopup();
432 * Create the textview for the popup
434 * @return The textview created for the popup
436 //Toolkit::TextView CreatePopupText();
439 * Create the value display for the slider
441 * @return The created root actor of the display
443 Actor CreateValueDisplay();
446 * Set the skin based on the current state
451 * Create all the children
453 void CreateChildren();
466 * Display the popup for a set duration with the given value
468 * @param[in] value The value to display in the popup
470 void DisplayPopup( float value );
473 * If there are marks present, filter the incoming percent based on snapping to any nearby marks
475 * @param[in] value The incoming value on the slider to filter
476 * @return The filtered percentage snapped to any nearby marks
478 float MarkFilter( float value );
481 * If there are marks present, snap the incoming percent to the nearest mark
483 * @param[in] value The incoming value on the slider to snap
484 * @return The filtered percentage snapped to the nearest mark
486 float SnapToMark( float value );
489 * Search for if a mark has been reached
491 * @param[in] value The value to search against
492 * @param[out] outIndex The index of the mark if found
493 * @return If a mark has been found to match percent
495 bool MarkReached( float value, int& outIndex );
498 * Handler for when the value view needs to be hidden
500 * @return If handled or not
502 bool HideValueView();
505 * Set value choosing whether to fire signals or not
507 * @paramp[in] value The value to set
508 * @param[in] raiseSignals Configure signals to be raised or not.
510 void DisplayValue( float value, bool raiseSignals );
513 * Create the image for the backing
515 * @param[in] imageName The name of the image to load and set
517 void SetBackingImageName( const std::string& imageName );
520 * @brief Return the backing image file name.
522 * @return The backing image file name.
524 std::string GetBackingImageName();
527 * Create the image for the progress bar
529 * @param[in] imageName The name of the image to load and set
531 void SetProgressImageName( const std::string& imageName );
534 * @brief Return the progress image name.
536 * @return The progress image name if it exists.
538 std::string GetProgressImageName();
541 * @brief Create the image for the popup
543 * @param[in] imageName The name of the image to load and set
545 void CreatePopupImage( const std::string& imageName );
548 * @brief Set the popup name
550 * @param[in] imageName The name of the image to set
552 void SetPopupImageName( const std::string& imageName );
555 * @brief Return the popup image name.
557 * @return The name of the popup image if it exists.
559 std::string GetPopupImageName();
562 * @brief Set the popup arrow image name
564 * @param[in] imageName The name of the image to set
566 void SetPopupArrowImageName( const std::string& imageName );
569 * @brief Return the popup arrow image name.
571 * @return The name of the popup image if it exists.
573 std::string GetPopupArrowImageName();
576 * Create the image for the popup arrow
578 * @param[in] imageName The name of the image to load and set
580 void CreatePopupArrowImage( const std::string& imageName );
583 * Set the size of the progress bar region
585 * @param[in] region The size of the region to set
587 void ResizeProgressRegion( const Vector2& region );
590 * Create the image for the handle
592 * @param[in] imageName The name of the image to load and set
594 void SetHandleImageName( const std::string& imageName );
597 * @brief Return the handle image name.
599 * @return The name of the image handle if it exists.
601 std::string GetHandleImageName();
604 * Set the size of the handle region
606 * @param[in] region The size of the region to set
608 void ResizeHandleRegion( const Vector2& region );
611 * Create and display the value on the handle
613 void CreateHandleValueDisplay();
616 * Remove and destroy the handle value display
618 void DestroyHandleValueDisplay();
621 * Update the color of the popup text
623 * @param[in] color The new color
625 void SetPopupTextColor( const Vector4& color );
630 * @param[in] region The handle region
632 void SetHandleRegion( const Vector2& region );
637 * @return The handle region
639 const Vector2& GetHandleRegion() const;
642 * Set the lower bound of the slider's value
644 * @param[in] bound The value to set for the lower bound
646 void SetLowerBound( float bound );
649 * Get the lower bound of the slider's value
651 * @return The lower bound value
653 float GetLowerBound() const;
656 * Set the upper bound of the slider's value
658 * @param[in] bound The value to set for the upper bound
660 void SetUpperBound( float bound );
663 * Get the upper bound of the slider's value
665 * @return The upper bound value
667 float GetUpperBound() const;
672 Slider( const Slider& );
675 Slider& operator=( const Slider& rhs );
679 Domain mDomain; ///< Current domain of the handle
681 Actor mHitArea; ///< The input handler
682 ImageActor mBacking; ///< Backing image
683 ImageActor mHandle; ///< Slider handle
684 ImageActor mProgress; ///< Progress backing
685 Actor mValueDisplay; ///< Display of the value
686 ImageActor mPopup; ///< Popup backing
687 ImageActor mPopupArrow; ///< Popup arrow backing
689 Vector2 mHandleLastTouchPoint; ///< The last touch point for the handle
690 Timer mValueTimer; ///< Timer used to hide value view
692 Toolkit::Slider::ValueChangedSignalType mValueChangedSignal; ///< Signal emitted when the value is changed
693 Toolkit::Slider::ValueChangedSignalType mSlidingFinishedSignal; ///< Signal emitted when a sliding is finished
694 Toolkit::Slider::MarkSignalType mMarkSignal; ///< Signal emitted when a mark is reached
696 SliderState mState; ///< The state of the slider
698 PanGestureDetector mPanDetector; ///< Hit region pan detector
700 MarkList mMarks; ///< List of discreet marks
702 std::string mPopupImageName; ///< Image name for popup image
703 std::string mPopupArrowImageName; ///< Image name for popup arrow
705 Vector4 mDisableColor; ///< The color to tint the slider when disabled
706 Vector4 mPopupTextColor; ///< The color of the popup text
708 Vector2 mHitRegion; ///< Size of hit region
709 Vector2 mBackingRegion; ///< Size of backing region
710 Vector2 mHandleRegionSize; ///< Size of the handle region
712 float mLowerBound; ///< Lower bound on value
713 float mUpperBound; ///< Upper bound on value
714 float mValue; ///< Current value of slider
716 float mMarkTolerance; ///< Tolerance in percentage of slider width for which to snap to marks
718 int mValuePrecision; ///< The precision to use for outputting the value
720 bool mShowPopup : 1, ///< Show the popup or not
721 mShowValue : 1, ///< Whether to display the value number or not on the handle
722 mSnapToMarks : 1; ///< Turn on or off snapping to marks
725 } // namespace Internal
727 // Helpers for public-api forwarding methods
729 inline Toolkit::Internal::Slider& GetImpl( Toolkit::Slider& pub )
731 DALI_ASSERT_ALWAYS( pub );
733 Dali::RefObject& handle = pub.GetImplementation();
735 return static_cast< Toolkit::Internal::Slider& >( handle );
738 inline const Toolkit::Internal::Slider& GetImpl( const Toolkit::Slider& pub )
740 DALI_ASSERT_ALWAYS( pub );
742 const Dali::RefObject& handle = pub.GetImplementation();
744 return static_cast< const Toolkit::Internal::Slider& >( handle );
747 } // namespace Toolkit
751 #endif // __DALI_TOOLKIT_INTERNAL_SLIDER_H__