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/dali.h>
23 #include <dali-toolkit/public-api/controls/control-impl.h>
24 #include <dali-toolkit/public-api/controls/slider/slider.h>
25 #include <dali-toolkit/public-api/controls/text-view/text-view.h>
40 typedef Dali::IntrusivePtr< Slider > SliderPtr;
43 * @copydoc Toolkit::Slider
45 class Slider : public ControlImpl
49 typedef Property::Array MarkList;
52 * Create a new Slider.
54 * @return A public handle to the newly allocated Slider.
56 static Dali::Toolkit::Slider New();
63 * Set marks from a list
65 * @param[in] marks The list of marks to set
67 void SetMarks( const MarkList& marks );
70 * Get the list of marks
72 * @return The marks list
74 const MarkList& GetMarks() const;
77 * Set if should snap to marks or not
79 * @param[in] snap Flag to snap to marks or not
81 void SetSnapToMarks( bool snap );
84 * Return if snap to marks is set or not
86 * @return If snap to marks is set
88 bool GetSnapToMarks() const;
91 * Set the value of the slider
93 * @param[in] value The value to set. Will be clamped to [lowerBound .. upperBound]
95 void SetValue( float value );
98 * Get the value of the slider
100 * @return The current value of the slider
102 float GetValue() const;
107 * @param[in] region The hit region
109 void SetHitRegion( const Vector2& region );
114 * @return The hit region
116 const Vector2& GetHitRegion() const;
121 * @param[in] region The backing region
123 void SetBackingRegion( const Vector2& region );
128 * @return The backing region
130 const Vector2& GetBackingRegion() const;
133 * @brief Set the disable color.
135 * @param[in] color The disable color.
137 void SetDisableColor( const Vector4& color );
140 * @brief Get disable color
142 * @return The disable color
144 Vector4 GetDisableColor() const;
147 * Get popup text color
149 * @return The popup text color
151 Vector4 GetPopupTextColor() const;
154 * Set the value precision to be used for numbers in the slider
156 * @param[in] precision The number of decimal places to use for printing numbers
158 void SetValuePrecision( int precision );
161 * Get value precision
163 * @return The value precision
165 int GetValuePrecision() const;
170 * @param[in] showPopup The show popup flag
172 void SetShowPopup( bool showPopup );
175 * Get show value in popup
177 * @return The show value flag
179 bool GetShowPopup() const;
182 * Set show value on handle
184 * @param[in] showValue The show value flag
186 void SetShowValue( bool showValue );
189 * Get show value on handle
191 * @return The show value flag
193 bool GetShowValue() const;
198 * param[in] enabled Set the enabled flag
200 void SetEnabled( bool enabled );
203 * Return if enabled or not
207 bool IsEnabled() const;
210 * @brief Set the mark tolerance
212 * The tolerance is the percentage of the slider width for which snapping to
215 * @param[in] tolerance The percentage of width for which to snap
217 void SetMarkTolerance( float tolerance );
220 * Return the mark tolerance
222 * @return The tolerance set for snapping to marks
224 float GetMarkTolerance() const;
230 * @copydoc Toolkit::Slider::ValueChangedSignal()
232 Toolkit::Slider::ValueChangedSignalType& ValueChangedSignal();
235 * copydoc Toolkit::Slider::SlidingFinishedSignal()
237 Toolkit::Slider::ValueChangedSignalType& SlidingFinishedSignal();
240 * @copydoc Toolkit::Slider::MarkSignal()
242 Toolkit::Slider::MarkSignalType& MarkSignal();
245 * Connects a callback function with the object's signals.
246 * @param[in] object The object providing the signal.
247 * @param[in] tracker Used to disconnect the signal.
248 * @param[in] signalName The signal to connect to.
249 * @param[in] functor A newly allocated FunctorDelegate.
250 * @return True if the signal was connected.
251 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
253 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName,
254 FunctorDelegate* functor );
259 * Called when a property of an object of this type is set.
260 * @param[in] object The object whose property is set.
261 * @param[in] index The property index.
262 * @param[in] value The new property value.
264 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
267 * Called to retrieve a property of an object of this type.
268 * @param[in] object The object whose property is to be retrieved.
269 * @param[in] index The property index.
270 * @return The current value of the property.
272 static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
277 * Construct a new Slider.
282 * A reference counted object may only be deleted by calling Unreference()
287 * @copydoc Toolkit::ControlImpl::OnControlSizeSet( const Vector3& size )
289 virtual void OnControlSizeSet( const Vector3& size );
294 * Domain is a from/to pair
304 Domain( Vector2 fromVal, Vector2 toVal )
305 : from( fromVal ), to( toVal )
324 * @copydoc Toolkit::Control::OnInitialize()
326 virtual void OnInitialize();
329 * Hit region touch event
331 * @param[in] actor The actor the event is raised for
332 * @param[in] event The touch event info
333 * @return If the event is handled or not
335 bool OnTouchEvent( Actor actor, const TouchEvent& event );
340 * @param[in] actor The actor the event is raised for
341 * @param[in] gesture The pan event info
343 void OnPan( Actor actor, PanGesture gestur );
346 * Map a position onto a domain and return the result as a percentage
348 * @param[in] point The point to map onto the domain
349 * @return The result as a percentage [0..1]
351 float MapPercentage( const Vector2& point );
354 * Map a value in the range to a percentage
356 * @param[in] point The value in range [lowerBound..upperBound]
357 * @return The result as a percentage [0..1]
359 float MapValuePercentage( float value );
362 * Convert a point in local hit space into domain space
364 * @param[in] x The x position to convert
365 * @return The x position in domain space
367 float HitSpaceToDomain( float x );
370 * Map a percentage onto the slider's bounds
372 * @param[in] percent The current value of slider in percent
373 * @param[in] lowerBound The lower bound to map onto
374 * @param[in] upperBound The upper bound to map onto
375 * @return The value of percent mapped from lowerBound to upperBound
377 float MapBounds( float percent, float lowerBound, float upperBound );
380 * Get the range of the valid values the slider handle can move between
382 * @param[in] currentSize The current size of the slider
383 * @return The range as a domain pair
385 Domain CalcDomain( const Vector2& currentSize );
388 * Create the hit region
390 * @return The hit region actor
392 Actor CreateHitRegion();
395 * Create the backing for the slider
397 * @return The backing actor
399 ImageActor CreateBacking();
402 * Create the progress backing for the slider
404 * @return The backing actor
406 ImageActor CreateProgress();
409 * Create the handle for the slider
411 * @return The created image handle
413 ImageActor CreateHandle();
416 * Create the popup arrow
418 * @return The created image handle
420 ImageActor CreatePopupArrow();
425 * @return The created image handle
427 ImageActor CreatePopup();
430 * Create the textview for the popup
432 * @return The textview created for the popup
434 Toolkit::TextView CreatePopupText();
437 * Create the value display for the slider
439 * @return The created root actor of the display
441 Actor CreateValueDisplay();
444 * Set the skin based on the current state
449 * Create all the children
451 void CreateChildren();
464 * Display the popup for a set duration with the given value
466 * @param[in] value The value to display in the popup
468 void DisplayPopup( float value );
471 * If there are marks present, filter the incoming percent based on snapping to any nearby marks
473 * @param[in] value The incoming value on the slider to filter
474 * @return The filtered percentage snapped to any nearby marks
476 float MarkFilter( float value );
479 * If there are marks present, snap the incoming percent to the nearest mark
481 * @param[in] value The incoming value on the slider to snap
482 * @return The filtered percentage snapped to the nearest mark
484 float SnapToMark( float value );
487 * Search for if a mark has been reached
489 * @param[in] value The value to search against
490 * @param[out] outIndex The index of the mark if found
491 * @return If a mark has been found to match percent
493 bool MarkReached( float value, int& outIndex );
496 * Handler for when the value view needs to be hidden
498 * @return If handled or not
500 bool HideValueView();
503 * Set value choosing whether to fire signals or not
505 * @paramp[in] value The value to set
506 * @param[in] raiseSignals Configure signals to be raised or not.
508 void DisplayValue( float value, bool raiseSignals );
511 * Create the image for the backing
513 * @param[in] imageName The name of the image to load and set
515 void SetBackingImageName( const std::string& imageName );
518 * @brief Return the backing image file name.
520 * @return The backing image file name.
522 std::string GetBackingImageName();
525 * Create the image for the progress bar
527 * @param[in] imageName The name of the image to load and set
529 void SetProgressImageName( const std::string& imageName );
532 * @brief Return the progress image name.
534 * @return The progress image name if it exists.
536 std::string GetProgressImageName();
539 * @brief Create the image for the popup
541 * @param[in] imageName The name of the image to load and set
543 void CreatePopupImage( const std::string& imageName );
546 * @brief Set the popup name
548 * @param[in] imageName The name of the image to set
550 void SetPopupImageName( const std::string& imageName );
553 * @brief Return the popup image name.
555 * @return The name of the popup image if it exists.
557 std::string GetPopupImageName();
560 * @brief Set the popup arrow image name
562 * @param[in] imageName The name of the image to set
564 void SetPopupArrowImageName( const std::string& imageName );
567 * @brief Return the popup arrow image name.
569 * @return The name of the popup image if it exists.
571 std::string GetPopupArrowImageName();
574 * Create the image for the popup arrow
576 * @param[in] imageName The name of the image to load and set
578 void CreatePopupArrowImage( const std::string& imageName );
581 * Set the size of the progress bar region
583 * @param[in] region The size of the region to set
585 void ResizeProgressRegion( const Vector2& region );
588 * Create the image for the handle
590 * @param[in] imageName The name of the image to load and set
592 void SetHandleImageName( const std::string& imageName );
595 * @brief Return the handle image name.
597 * @return The name of the image handle if it exists.
599 std::string GetHandleImageName();
602 * Set the size of the handle region
604 * @param[in] region The size of the region to set
606 void ResizeHandleRegion( const Vector2& region );
609 * Create and display the value on the handle
611 void CreateHandleValueDisplay();
614 * Remove and destroy the handle value display
616 void DestroyHandleValueDisplay();
619 * Update the color of the popup text
621 * @param[in] color The new color
623 void SetPopupTextColor( const Vector4& color );
628 * @param[in] region The handle region
630 void SetHandleRegion( const Vector2& region );
635 * @return The handle region
637 const Vector2& GetHandleRegion() const;
640 * Set the lower bound of the slider's value
642 * @param[in] bound The value to set for the lower bound
644 void SetLowerBound( float bound );
647 * Get the lower bound of the slider's value
649 * @return The lower bound value
651 float GetLowerBound() const;
654 * Set the upper bound of the slider's value
656 * @param[in] bound The value to set for the upper bound
658 void SetUpperBound( float bound );
661 * Get the upper bound of the slider's value
663 * @return The upper bound value
665 float GetUpperBound() const;
670 Slider( const Slider& );
673 Slider& operator=( const Slider& rhs );
677 Domain mDomain; ///< Current domain of the handle
679 Actor mHitArea; ///< The input handler
680 ImageActor mBacking; ///< Backing image
681 ImageActor mHandle; ///< Slider handle
682 ImageActor mProgress; ///< Progress backing
683 Actor mValueDisplay; ///< Display of the value
684 ImageActor mPopup; ///< Popup backing
685 ImageActor mPopupArrow; ///< Popup arrow backing
687 Toolkit::TextView mValueTextView; //< The text value in popup
688 Toolkit::TextView mHandleValueTextView; ///< The text value on handle
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__