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>
28 #include <dali-toolkit/public-api/controls/text-view/text-view.h>
43 typedef Dali::IntrusivePtr< Slider > SliderPtr;
46 * @copydoc Toolkit::Slider
48 class Slider : public Control
55 SLIDER_PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
56 SLIDER_PROPERTY_END_INDEX = SLIDER_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices
59 typedef Property::Array MarkList;
62 * Create a new Slider.
64 * @return A public handle to the newly allocated Slider.
66 static Dali::Toolkit::Slider New();
73 * Set marks from a list
75 * @param[in] marks The list of marks to set
77 void SetMarks( const MarkList& marks );
80 * Get the list of marks
82 * @return The marks list
84 const MarkList& GetMarks() const;
87 * Set if should snap to marks or not
89 * @param[in] snap Flag to snap to marks or not
91 void SetSnapToMarks( bool snap );
94 * Return if snap to marks is set or not
96 * @return If snap to marks is set
98 bool GetSnapToMarks() const;
101 * Set the value of the slider
103 * @param[in] value The value to set. Will be clamped to [lowerBound .. upperBound]
105 void SetValue( float value );
108 * Get the value of the slider
110 * @return The current value of the slider
112 float GetValue() const;
117 * @param[in] region The hit region
119 void SetHitRegion( const Vector2& region );
124 * @return The hit region
126 const Vector2& GetHitRegion() const;
131 * @param[in] region The backing region
133 void SetBackingRegion( const Vector2& region );
138 * @return The backing region
140 const Vector2& GetBackingRegion() const;
143 * @brief Set the disable color.
145 * @param[in] color The disable color.
147 void SetDisableColor( const Vector4& color );
150 * @brief Get disable color
152 * @return The disable color
154 Vector4 GetDisableColor() const;
157 * Get popup text color
159 * @return The popup text color
161 Vector4 GetPopupTextColor() const;
164 * Set the value precision to be used for numbers in the slider
166 * @param[in] precision The number of decimal places to use for printing numbers
168 void SetValuePrecision( int precision );
171 * Get value precision
173 * @return The value precision
175 int GetValuePrecision() const;
180 * @param[in] showPopup The show popup flag
182 void SetShowPopup( bool showPopup );
185 * Get show value in popup
187 * @return The show value flag
189 bool GetShowPopup() const;
192 * Set show value on handle
194 * @param[in] showValue The show value flag
196 void SetShowValue( bool showValue );
199 * Get show value on handle
201 * @return The show value flag
203 bool GetShowValue() const;
208 * param[in] enabled Set the enabled flag
210 void SetEnabled( bool enabled );
213 * Return if enabled or not
217 bool IsEnabled() const;
220 * @brief Set the mark tolerance
222 * The tolerance is the percentage of the slider width for which snapping to
225 * @param[in] tolerance The percentage of width for which to snap
227 void SetMarkTolerance( float tolerance );
230 * Return the mark tolerance
232 * @return The tolerance set for snapping to marks
234 float GetMarkTolerance() const;
240 * @copydoc Toolkit::Slider::ValueChangedSignal()
242 Toolkit::Slider::ValueChangedSignalType& ValueChangedSignal();
245 * copydoc Toolkit::Slider::SlidingFinishedSignal()
247 Toolkit::Slider::ValueChangedSignalType& SlidingFinishedSignal();
250 * @copydoc Toolkit::Slider::MarkSignal()
252 Toolkit::Slider::MarkSignalType& MarkSignal();
255 * Connects a callback function with the object's signals.
256 * @param[in] object The object providing the signal.
257 * @param[in] tracker Used to disconnect the signal.
258 * @param[in] signalName The signal to connect to.
259 * @param[in] functor A newly allocated FunctorDelegate.
260 * @return True if the signal was connected.
261 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
263 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName,
264 FunctorDelegate* functor );
269 * Called when a property of an object of this type is set.
270 * @param[in] object The object whose property is set.
271 * @param[in] index The property index.
272 * @param[in] value The new property value.
274 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
277 * Called to retrieve a property of an object of this type.
278 * @param[in] object The object whose property is to be retrieved.
279 * @param[in] index The property index.
280 * @return The current value of the property.
282 static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
287 * Construct a new Slider.
292 * A reference counted object may only be deleted by calling Unreference()
297 * @copydoc Control::OnControlSizeSet( const Vector3& size )
299 virtual void OnControlSizeSet( const Vector3& size );
304 * Domain is a from/to pair
314 Domain( Vector2 fromVal, Vector2 toVal )
315 : from( fromVal ), to( toVal )
334 * @copydoc Toolkit::Control::OnInitialize()
336 virtual void OnInitialize();
339 * Hit region touch event
341 * @param[in] actor The actor the event is raised for
342 * @param[in] event The touch event info
343 * @return If the event is handled or not
345 bool OnTouchEvent( Actor actor, const TouchEvent& event );
350 * @param[in] actor The actor the event is raised for
351 * @param[in] gesture The pan event info
353 void OnPan( Actor actor, const PanGesture& gesture );
356 * Map a position onto a domain and return the result as a percentage
358 * @param[in] point The point to map onto the domain
359 * @return The result as a percentage [0..1]
361 float MapPercentage( const Vector2& point );
364 * Map a value in the range to a percentage
366 * @param[in] point The value in range [lowerBound..upperBound]
367 * @return The result as a percentage [0..1]
369 float MapValuePercentage( float value );
372 * Convert a point in local hit space into domain space
374 * @param[in] x The x position to convert
375 * @return The x position in domain space
377 float HitSpaceToDomain( float x );
380 * Map a percentage onto the slider's bounds
382 * @param[in] percent The current value of slider in percent
383 * @param[in] lowerBound The lower bound to map onto
384 * @param[in] upperBound The upper bound to map onto
385 * @return The value of percent mapped from lowerBound to upperBound
387 float MapBounds( float percent, float lowerBound, float upperBound );
390 * Get the range of the valid values the slider handle can move between
392 * @param[in] currentSize The current size of the slider
393 * @return The range as a domain pair
395 Domain CalcDomain( const Vector2& currentSize );
398 * Create the hit region
400 * @return The hit region actor
402 Actor CreateHitRegion();
405 * Create the backing for the slider
407 * @return The backing actor
409 ImageActor CreateBacking();
412 * Create the progress backing for the slider
414 * @return The backing actor
416 ImageActor CreateProgress();
419 * Create the handle for the slider
421 * @return The created image handle
423 ImageActor CreateHandle();
426 * Create the popup arrow
428 * @return The created image handle
430 ImageActor CreatePopupArrow();
435 * @return The created image handle
437 ImageActor CreatePopup();
440 * Create the textview for the popup
442 * @return The textview created for the popup
444 Toolkit::TextView CreatePopupText();
447 * Create the value display for the slider
449 * @return The created root actor of the display
451 Actor CreateValueDisplay();
454 * Set the skin based on the current state
459 * Create all the children
461 void CreateChildren();
474 * Display the popup for a set duration with the given value
476 * @param[in] value The value to display in the popup
478 void DisplayPopup( float value );
481 * If there are marks present, filter the incoming percent based on snapping to any nearby marks
483 * @param[in] value The incoming value on the slider to filter
484 * @return The filtered percentage snapped to any nearby marks
486 float MarkFilter( float value );
489 * If there are marks present, snap the incoming percent to the nearest mark
491 * @param[in] value The incoming value on the slider to snap
492 * @return The filtered percentage snapped to the nearest mark
494 float SnapToMark( float value );
497 * Search for if a mark has been reached
499 * @param[in] value The value to search against
500 * @param[out] outIndex The index of the mark if found
501 * @return If a mark has been found to match percent
503 bool MarkReached( float value, int& outIndex );
506 * Handler for when the value view needs to be hidden
508 * @return If handled or not
510 bool HideValueView();
513 * Set value choosing whether to fire signals or not
515 * @paramp[in] value The value to set
516 * @param[in] raiseSignals Configure signals to be raised or not.
518 void DisplayValue( float value, bool raiseSignals );
521 * Create the image for the backing
523 * @param[in] imageName The name of the image to load and set
525 void SetBackingImageName( const std::string& imageName );
528 * @brief Return the backing image file name.
530 * @return The backing image file name.
532 std::string GetBackingImageName();
535 * Create the image for the progress bar
537 * @param[in] imageName The name of the image to load and set
539 void SetProgressImageName( const std::string& imageName );
542 * @brief Return the progress image name.
544 * @return The progress image name if it exists.
546 std::string GetProgressImageName();
549 * @brief Create the image for the popup
551 * @param[in] imageName The name of the image to load and set
553 void CreatePopupImage( const std::string& imageName );
556 * @brief Set the popup name
558 * @param[in] imageName The name of the image to set
560 void SetPopupImageName( const std::string& imageName );
563 * @brief Return the popup image name.
565 * @return The name of the popup image if it exists.
567 std::string GetPopupImageName();
570 * @brief Set the popup arrow image name
572 * @param[in] imageName The name of the image to set
574 void SetPopupArrowImageName( const std::string& imageName );
577 * @brief Return the popup arrow image name.
579 * @return The name of the popup image if it exists.
581 std::string GetPopupArrowImageName();
584 * Create the image for the popup arrow
586 * @param[in] imageName The name of the image to load and set
588 void CreatePopupArrowImage( const std::string& imageName );
591 * Set the size of the progress bar region
593 * @param[in] region The size of the region to set
595 void ResizeProgressRegion( const Vector2& region );
598 * Create the image for the handle
600 * @param[in] imageName The name of the image to load and set
602 void SetHandleImageName( const std::string& imageName );
605 * @brief Return the handle image name.
607 * @return The name of the image handle if it exists.
609 std::string GetHandleImageName();
612 * Set the size of the handle region
614 * @param[in] region The size of the region to set
616 void ResizeHandleRegion( const Vector2& region );
619 * Create and display the value on the handle
621 void CreateHandleValueDisplay();
624 * Remove and destroy the handle value display
626 void DestroyHandleValueDisplay();
629 * Update the color of the popup text
631 * @param[in] color The new color
633 void SetPopupTextColor( const Vector4& color );
638 * @param[in] region The handle region
640 void SetHandleRegion( const Vector2& region );
645 * @return The handle region
647 const Vector2& GetHandleRegion() const;
650 * Set the lower bound of the slider's value
652 * @param[in] bound The value to set for the lower bound
654 void SetLowerBound( float bound );
657 * Get the lower bound of the slider's value
659 * @return The lower bound value
661 float GetLowerBound() const;
664 * Set the upper bound of the slider's value
666 * @param[in] bound The value to set for the upper bound
668 void SetUpperBound( float bound );
671 * Get the upper bound of the slider's value
673 * @return The upper bound value
675 float GetUpperBound() const;
680 Slider( const Slider& );
683 Slider& operator=( const Slider& rhs );
687 Domain mDomain; ///< Current domain of the handle
689 Actor mHitArea; ///< The input handler
690 ImageActor mBacking; ///< Backing image
691 ImageActor mHandle; ///< Slider handle
692 ImageActor mProgress; ///< Progress backing
693 Actor mValueDisplay; ///< Display of the value
694 ImageActor mPopup; ///< Popup backing
695 ImageActor mPopupArrow; ///< Popup arrow backing
697 Toolkit::TextView mValueTextView; //< The text value in popup
698 Toolkit::TextView mHandleValueTextView; ///< The text value on handle
699 Vector2 mHandleLastTouchPoint; ///< The last touch point for the handle
700 Timer mValueTimer; ///< Timer used to hide value view
702 Toolkit::Slider::ValueChangedSignalType mValueChangedSignal; ///< Signal emitted when the value is changed
703 Toolkit::Slider::ValueChangedSignalType mSlidingFinishedSignal; ///< Signal emitted when a sliding is finished
704 Toolkit::Slider::MarkSignalType mMarkSignal; ///< Signal emitted when a mark is reached
706 SliderState mState; ///< The state of the slider
708 PanGestureDetector mPanDetector; ///< Hit region pan detector
710 MarkList mMarks; ///< List of discreet marks
712 std::string mPopupImageName; ///< Image name for popup image
713 std::string mPopupArrowImageName; ///< Image name for popup arrow
715 Vector4 mDisableColor; ///< The color to tint the slider when disabled
716 Vector4 mPopupTextColor; ///< The color of the popup text
718 Vector2 mHitRegion; ///< Size of hit region
719 Vector2 mBackingRegion; ///< Size of backing region
720 Vector2 mHandleRegionSize; ///< Size of the handle region
722 float mLowerBound; ///< Lower bound on value
723 float mUpperBound; ///< Upper bound on value
724 float mValue; ///< Current value of slider
726 float mMarkTolerance; ///< Tolerance in percentage of slider width for which to snap to marks
728 int mValuePrecision; ///< The precision to use for outputting the value
730 bool mShowPopup : 1, ///< Show the popup or not
731 mShowValue : 1, ///< Whether to display the value number or not on the handle
732 mSnapToMarks : 1; ///< Turn on or off snapping to marks
735 } // namespace Internal
737 // Helpers for public-api forwarding methods
739 inline Toolkit::Internal::Slider& GetImpl( Toolkit::Slider& pub )
741 DALI_ASSERT_ALWAYS( pub );
743 Dali::RefObject& handle = pub.GetImplementation();
745 return static_cast< Toolkit::Internal::Slider& >( handle );
748 inline const Toolkit::Internal::Slider& GetImpl( const Toolkit::Slider& pub )
750 DALI_ASSERT_ALWAYS( pub );
752 const Dali::RefObject& handle = pub.GetImplementation();
754 return static_cast< const Toolkit::Internal::Slider& >( handle );
757 } // namespace Toolkit
761 #endif // __DALI_TOOLKIT_INTERNAL_SLIDER_H__