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 Control
52 SLIDER_PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
53 SLIDER_PROPERTY_END_INDEX = SLIDER_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices
56 typedef Property::Array MarkList;
59 * Create a new Slider.
61 * @return A public handle to the newly allocated Slider.
63 static Dali::Toolkit::Slider New();
70 * Set marks from a list
72 * @param[in] marks The list of marks to set
74 void SetMarks( const MarkList& marks );
77 * Get the list of marks
79 * @return The marks list
81 const MarkList& GetMarks() const;
84 * Set if should snap to marks or not
86 * @param[in] snap Flag to snap to marks or not
88 void SetSnapToMarks( bool snap );
91 * Return if snap to marks is set or not
93 * @return If snap to marks is set
95 bool GetSnapToMarks() const;
98 * Set the value of the slider
100 * @param[in] value The value to set. Will be clamped to [lowerBound .. upperBound]
102 void SetValue( float value );
105 * Get the value of the slider
107 * @return The current value of the slider
109 float GetValue() const;
114 * @param[in] region The hit region
116 void SetHitRegion( const Vector2& region );
121 * @return The hit region
123 const Vector2& GetHitRegion() const;
128 * @param[in] region The backing region
130 void SetBackingRegion( const Vector2& region );
135 * @return The backing region
137 const Vector2& GetBackingRegion() const;
140 * @brief Set the disable color.
142 * @param[in] color The disable color.
144 void SetDisableColor( const Vector4& color );
147 * @brief Get disable color
149 * @return The disable color
151 Vector4 GetDisableColor() const;
154 * Get popup text color
156 * @return The popup text color
158 Vector4 GetPopupTextColor() const;
161 * Set the value precision to be used for numbers in the slider
163 * @param[in] precision The number of decimal places to use for printing numbers
165 void SetValuePrecision( int precision );
168 * Get value precision
170 * @return The value precision
172 int GetValuePrecision() const;
177 * @param[in] showPopup The show popup flag
179 void SetShowPopup( bool showPopup );
182 * Get show value in popup
184 * @return The show value flag
186 bool GetShowPopup() const;
189 * Set show value on handle
191 * @param[in] showValue The show value flag
193 void SetShowValue( bool showValue );
196 * Get show value on handle
198 * @return The show value flag
200 bool GetShowValue() const;
205 * param[in] enabled Set the enabled flag
207 void SetEnabled( bool enabled );
210 * Return if enabled or not
214 bool IsEnabled() const;
217 * @brief Set the mark tolerance
219 * The tolerance is the percentage of the slider width for which snapping to
222 * @param[in] tolerance The percentage of width for which to snap
224 void SetMarkTolerance( float tolerance );
227 * Return the mark tolerance
229 * @return The tolerance set for snapping to marks
231 float GetMarkTolerance() const;
237 * @copydoc Toolkit::Slider::ValueChangedSignal()
239 Toolkit::Slider::ValueChangedSignalType& ValueChangedSignal();
242 * copydoc Toolkit::Slider::SlidingFinishedSignal()
244 Toolkit::Slider::ValueChangedSignalType& SlidingFinishedSignal();
247 * @copydoc Toolkit::Slider::MarkSignal()
249 Toolkit::Slider::MarkSignalType& MarkSignal();
252 * Connects a callback function with the object's signals.
253 * @param[in] object The object providing the signal.
254 * @param[in] tracker Used to disconnect the signal.
255 * @param[in] signalName The signal to connect to.
256 * @param[in] functor A newly allocated FunctorDelegate.
257 * @return True if the signal was connected.
258 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
260 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName,
261 FunctorDelegate* functor );
266 * Called when a property of an object of this type is set.
267 * @param[in] object The object whose property is set.
268 * @param[in] index The property index.
269 * @param[in] value The new property value.
271 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
274 * Called to retrieve a property of an object of this type.
275 * @param[in] object The object whose property is to be retrieved.
276 * @param[in] index The property index.
277 * @return The current value of the property.
279 static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
284 * Construct a new Slider.
289 * A reference counted object may only be deleted by calling Unreference()
294 * @copydoc Control::OnControlSizeSet( const Vector3& size )
296 virtual void OnControlSizeSet( const Vector3& size );
301 * Domain is a from/to pair
311 Domain( Vector2 fromVal, Vector2 toVal )
312 : from( fromVal ), to( toVal )
331 * @copydoc Toolkit::Control::OnInitialize()
333 virtual void OnInitialize();
336 * Hit region touch event
338 * @param[in] actor The actor the event is raised for
339 * @param[in] event The touch event info
340 * @return If the event is handled or not
342 bool OnTouchEvent( Actor actor, const TouchEvent& event );
347 * @param[in] actor The actor the event is raised for
348 * @param[in] gesture The pan event info
350 void OnPan( Actor actor, PanGesture gestur );
353 * Map a position onto a domain and return the result as a percentage
355 * @param[in] point The point to map onto the domain
356 * @return The result as a percentage [0..1]
358 float MapPercentage( const Vector2& point );
361 * Map a value in the range to a percentage
363 * @param[in] point The value in range [lowerBound..upperBound]
364 * @return The result as a percentage [0..1]
366 float MapValuePercentage( float value );
369 * Convert a point in local hit space into domain space
371 * @param[in] x The x position to convert
372 * @return The x position in domain space
374 float HitSpaceToDomain( float x );
377 * Map a percentage onto the slider's bounds
379 * @param[in] percent The current value of slider in percent
380 * @param[in] lowerBound The lower bound to map onto
381 * @param[in] upperBound The upper bound to map onto
382 * @return The value of percent mapped from lowerBound to upperBound
384 float MapBounds( float percent, float lowerBound, float upperBound );
387 * Get the range of the valid values the slider handle can move between
389 * @param[in] currentSize The current size of the slider
390 * @return The range as a domain pair
392 Domain CalcDomain( const Vector2& currentSize );
395 * Create the hit region
397 * @return The hit region actor
399 Actor CreateHitRegion();
402 * Create the backing for the slider
404 * @return The backing actor
406 ImageActor CreateBacking();
409 * Create the progress backing for the slider
411 * @return The backing actor
413 ImageActor CreateProgress();
416 * Create the handle for the slider
418 * @return The created image handle
420 ImageActor CreateHandle();
423 * Create the popup arrow
425 * @return The created image handle
427 ImageActor CreatePopupArrow();
432 * @return The created image handle
434 ImageActor CreatePopup();
437 * Create the textview for the popup
439 * @return The textview created for the popup
441 Toolkit::TextView CreatePopupText();
444 * Create the value display for the slider
446 * @return The created root actor of the display
448 Actor CreateValueDisplay();
451 * Set the skin based on the current state
456 * Create all the children
458 void CreateChildren();
471 * Display the popup for a set duration with the given value
473 * @param[in] value The value to display in the popup
475 void DisplayPopup( float value );
478 * If there are marks present, filter the incoming percent based on snapping to any nearby marks
480 * @param[in] value The incoming value on the slider to filter
481 * @return The filtered percentage snapped to any nearby marks
483 float MarkFilter( float value );
486 * If there are marks present, snap the incoming percent to the nearest mark
488 * @param[in] value The incoming value on the slider to snap
489 * @return The filtered percentage snapped to the nearest mark
491 float SnapToMark( float value );
494 * Search for if a mark has been reached
496 * @param[in] value The value to search against
497 * @param[out] outIndex The index of the mark if found
498 * @return If a mark has been found to match percent
500 bool MarkReached( float value, int& outIndex );
503 * Handler for when the value view needs to be hidden
505 * @return If handled or not
507 bool HideValueView();
510 * Set value choosing whether to fire signals or not
512 * @paramp[in] value The value to set
513 * @param[in] raiseSignals Configure signals to be raised or not.
515 void DisplayValue( float value, bool raiseSignals );
518 * Create the image for the backing
520 * @param[in] imageName The name of the image to load and set
522 void SetBackingImageName( const std::string& imageName );
525 * @brief Return the backing image file name.
527 * @return The backing image file name.
529 std::string GetBackingImageName();
532 * Create the image for the progress bar
534 * @param[in] imageName The name of the image to load and set
536 void SetProgressImageName( const std::string& imageName );
539 * @brief Return the progress image name.
541 * @return The progress image name if it exists.
543 std::string GetProgressImageName();
546 * @brief Create the image for the popup
548 * @param[in] imageName The name of the image to load and set
550 void CreatePopupImage( const std::string& imageName );
553 * @brief Set the popup name
555 * @param[in] imageName The name of the image to set
557 void SetPopupImageName( const std::string& imageName );
560 * @brief Return the popup image name.
562 * @return The name of the popup image if it exists.
564 std::string GetPopupImageName();
567 * @brief Set the popup arrow image name
569 * @param[in] imageName The name of the image to set
571 void SetPopupArrowImageName( const std::string& imageName );
574 * @brief Return the popup arrow image name.
576 * @return The name of the popup image if it exists.
578 std::string GetPopupArrowImageName();
581 * Create the image for the popup arrow
583 * @param[in] imageName The name of the image to load and set
585 void CreatePopupArrowImage( const std::string& imageName );
588 * Set the size of the progress bar region
590 * @param[in] region The size of the region to set
592 void ResizeProgressRegion( const Vector2& region );
595 * Create the image for the handle
597 * @param[in] imageName The name of the image to load and set
599 void SetHandleImageName( const std::string& imageName );
602 * @brief Return the handle image name.
604 * @return The name of the image handle if it exists.
606 std::string GetHandleImageName();
609 * Set the size of the handle region
611 * @param[in] region The size of the region to set
613 void ResizeHandleRegion( const Vector2& region );
616 * Create and display the value on the handle
618 void CreateHandleValueDisplay();
621 * Remove and destroy the handle value display
623 void DestroyHandleValueDisplay();
626 * Update the color of the popup text
628 * @param[in] color The new color
630 void SetPopupTextColor( const Vector4& color );
635 * @param[in] region The handle region
637 void SetHandleRegion( const Vector2& region );
642 * @return The handle region
644 const Vector2& GetHandleRegion() const;
647 * Set the lower bound of the slider's value
649 * @param[in] bound The value to set for the lower bound
651 void SetLowerBound( float bound );
654 * Get the lower bound of the slider's value
656 * @return The lower bound value
658 float GetLowerBound() const;
661 * Set the upper bound of the slider's value
663 * @param[in] bound The value to set for the upper bound
665 void SetUpperBound( float bound );
668 * Get the upper bound of the slider's value
670 * @return The upper bound value
672 float GetUpperBound() const;
677 Slider( const Slider& );
680 Slider& operator=( const Slider& rhs );
684 Domain mDomain; ///< Current domain of the handle
686 Actor mHitArea; ///< The input handler
687 ImageActor mBacking; ///< Backing image
688 ImageActor mHandle; ///< Slider handle
689 ImageActor mProgress; ///< Progress backing
690 Actor mValueDisplay; ///< Display of the value
691 ImageActor mPopup; ///< Popup backing
692 ImageActor mPopupArrow; ///< Popup arrow backing
694 Toolkit::TextView mValueTextView; //< The text value in popup
695 Toolkit::TextView mHandleValueTextView; ///< The text value on handle
696 Vector2 mHandleLastTouchPoint; ///< The last touch point for the handle
697 Timer mValueTimer; ///< Timer used to hide value view
699 Toolkit::Slider::ValueChangedSignalType mValueChangedSignal; ///< Signal emitted when the value is changed
700 Toolkit::Slider::ValueChangedSignalType mSlidingFinishedSignal; ///< Signal emitted when a sliding is finished
701 Toolkit::Slider::MarkSignalType mMarkSignal; ///< Signal emitted when a mark is reached
703 SliderState mState; ///< The state of the slider
705 PanGestureDetector mPanDetector; ///< Hit region pan detector
707 MarkList mMarks; ///< List of discreet marks
709 std::string mPopupImageName; ///< Image name for popup image
710 std::string mPopupArrowImageName; ///< Image name for popup arrow
712 Vector4 mDisableColor; ///< The color to tint the slider when disabled
713 Vector4 mPopupTextColor; ///< The color of the popup text
715 Vector2 mHitRegion; ///< Size of hit region
716 Vector2 mBackingRegion; ///< Size of backing region
717 Vector2 mHandleRegionSize; ///< Size of the handle region
719 float mLowerBound; ///< Lower bound on value
720 float mUpperBound; ///< Upper bound on value
721 float mValue; ///< Current value of slider
723 float mMarkTolerance; ///< Tolerance in percentage of slider width for which to snap to marks
725 int mValuePrecision; ///< The precision to use for outputting the value
727 bool mShowPopup : 1, ///< Show the popup or not
728 mShowValue : 1, ///< Whether to display the value number or not on the handle
729 mSnapToMarks : 1; ///< Turn on or off snapping to marks
732 } // namespace Internal
734 // Helpers for public-api forwarding methods
736 inline Toolkit::Internal::Slider& GetImpl( Toolkit::Slider& pub )
738 DALI_ASSERT_ALWAYS( pub );
740 Dali::RefObject& handle = pub.GetImplementation();
742 return static_cast< Toolkit::Internal::Slider& >( handle );
745 inline const Toolkit::Internal::Slider& GetImpl( const Toolkit::Slider& pub )
747 DALI_ASSERT_ALWAYS( pub );
749 const Dali::RefObject& handle = pub.GetImplementation();
751 return static_cast< const Toolkit::Internal::Slider& >( handle );
754 } // namespace Toolkit
758 #endif // __DALI_TOOLKIT_INTERNAL_SLIDER_H__