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-controls/text-label.h>
43 typedef Dali::IntrusivePtr< Slider > SliderPtr;
46 * @copydoc Toolkit::Slider
48 class Slider : public Control
52 typedef Property::Array MarkList;
55 * Create a new Slider.
57 * @return A public handle to the newly allocated Slider.
59 static Dali::Toolkit::Slider New();
66 * Set marks from a list
68 * @param[in] marks The list of marks to set
70 void SetMarks( const MarkList& marks );
73 * Get the list of marks
75 * @return The marks list
77 const MarkList& GetMarks() const;
80 * Set if should snap to marks or not
82 * @param[in] snap Flag to snap to marks or not
84 void SetSnapToMarks( bool snap );
87 * Return if snap to marks is set or not
89 * @return If snap to marks is set
91 bool GetSnapToMarks() const;
94 * Set the value of the slider
96 * @param[in] value The value to set. Will be clamped to [lowerBound .. upperBound]
98 void SetValue( float value );
101 * Get the value of the slider
103 * @return The current value of the slider
105 float GetValue() const;
110 * @param[in] region The hit region
112 void SetHitRegion( const Vector2& region );
117 * @return The hit region
119 const Vector2& GetHitRegion() const;
124 * @param[in] region The backing region
126 void SetBackingRegion( const Vector2& region );
131 * @return The backing region
133 const Vector2& GetBackingRegion() const;
136 * @brief Set the disable color.
138 * @param[in] color The disable color.
140 void SetDisableColor( const Vector4& color );
143 * @brief Get disable color
145 * @return The disable color
147 Vector4 GetDisableColor() const;
150 * Get popup text color
152 * @return The popup text color
154 Vector4 GetPopupTextColor() const;
157 * Set the value precision to be used for numbers in the slider
159 * @param[in] precision The number of decimal places to use for printing numbers
161 void SetValuePrecision( int precision );
164 * Get value precision
166 * @return The value precision
168 int GetValuePrecision() const;
173 * @param[in] showPopup The show popup flag
175 void SetShowPopup( bool showPopup );
178 * Get show value in popup
180 * @return The show value flag
182 bool GetShowPopup() const;
185 * Set show value on handle
187 * @param[in] showValue The show value flag
189 void SetShowValue( bool showValue );
192 * Get show value on handle
194 * @return The show value flag
196 bool GetShowValue() const;
201 * param[in] enabled Set the enabled flag
203 void SetEnabled( bool enabled );
206 * Return if enabled or not
210 bool IsEnabled() const;
213 * @brief Set the mark tolerance
215 * The tolerance is the percentage of the slider width for which snapping to
218 * @param[in] tolerance The percentage of width for which to snap
220 void SetMarkTolerance( float tolerance );
223 * Return the mark tolerance
225 * @return The tolerance set for snapping to marks
227 float GetMarkTolerance() const;
233 * @copydoc Toolkit::Slider::ValueChangedSignal()
235 Toolkit::Slider::ValueChangedSignalType& ValueChangedSignal();
238 * copydoc Toolkit::Slider::SlidingFinishedSignal()
240 Toolkit::Slider::ValueChangedSignalType& SlidingFinishedSignal();
243 * @copydoc Toolkit::Slider::MarkSignal()
245 Toolkit::Slider::MarkSignalType& MarkSignal();
248 * Connects a callback function with the object's signals.
249 * @param[in] object The object providing the signal.
250 * @param[in] tracker Used to disconnect the signal.
251 * @param[in] signalName The signal to connect to.
252 * @param[in] functor A newly allocated FunctorDelegate.
253 * @return True if the signal was connected.
254 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
256 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName,
257 FunctorDelegate* functor );
262 * Called when a property of an object of this type is set.
263 * @param[in] object The object whose property is set.
264 * @param[in] index The property index.
265 * @param[in] value The new property value.
267 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
270 * Called to retrieve a property of an object of this type.
271 * @param[in] object The object whose property is to be retrieved.
272 * @param[in] index The property index.
273 * @return The current value of the property.
275 static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
280 * Construct a new Slider.
285 * A reference counted object may only be deleted by calling Unreference()
290 * @copydoc Control::OnControlSizeSet( const Vector3& size )
292 virtual void OnControlSizeSet( const Vector3& size );
297 * Domain is a from/to pair
307 Domain( Vector2 fromVal, Vector2 toVal )
308 : from( fromVal ), to( toVal )
327 * @copydoc Toolkit::Control::OnInitialize()
329 virtual void OnInitialize();
332 * Hit region touch event
334 * @param[in] actor The actor the event is raised for
335 * @param[in] event The touch event info
336 * @return If the event is handled or not
338 bool OnTouchEvent( Actor actor, const TouchEvent& event );
343 * @param[in] actor The actor the event is raised for
344 * @param[in] gesture The pan event info
346 void OnPan( Actor actor, const PanGesture& gesture );
349 * Map a position onto a domain and return the result as a percentage
351 * @param[in] point The point to map onto the domain
352 * @return The result as a percentage [0..1]
354 float MapPercentage( const Vector2& point );
357 * Map a value in the range to a percentage
359 * @param[in] point The value in range [lowerBound..upperBound]
360 * @return The result as a percentage [0..1]
362 float MapValuePercentage( float value );
365 * Convert a point in local hit space into domain space
367 * @param[in] x The x position to convert
368 * @return The x position in domain space
370 float HitSpaceToDomain( float x );
373 * Map a percentage onto the slider's bounds
375 * @param[in] percent The current value of slider in percent
376 * @param[in] lowerBound The lower bound to map onto
377 * @param[in] upperBound The upper bound to map onto
378 * @return The value of percent mapped from lowerBound to upperBound
380 float MapBounds( float percent, float lowerBound, float upperBound );
383 * Get the range of the valid values the slider handle can move between
385 * @param[in] currentSize The current size of the slider
386 * @return The range as a domain pair
388 Domain CalcDomain( const Vector2& currentSize );
391 * Create the hit region
393 * @return The hit region actor
395 Actor CreateHitRegion();
398 * Create the backing for the slider
400 * @return The backing actor
402 ImageActor CreateBacking();
405 * Create the progress backing for the slider
407 * @return The backing actor
409 ImageActor CreateProgress();
412 * Create the handle for the slider
414 * @return The created image handle
416 ImageActor CreateHandle();
419 * Create the popup arrow
421 * @return The created image handle
423 ImageActor CreatePopupArrow();
428 * @return The created image handle
430 ImageActor CreatePopup();
433 * Create the textview for the popup
435 * @return The textview created for the popup
437 Toolkit::TextLabel CreatePopupText();
440 * Create the value display for the slider
442 * @return The created root actor of the display
444 Actor CreateValueDisplay();
447 * Set the skin based on the current state
452 * Create all the children
454 void CreateChildren();
467 * Display the popup for a set duration with the given value
469 * @param[in] value The value to display in the popup
471 void DisplayPopup( float value );
474 * If there are marks present, filter the incoming percent based on snapping to any nearby marks
476 * @param[in] value The incoming value on the slider to filter
477 * @return The filtered percentage snapped to any nearby marks
479 float MarkFilter( float value );
482 * If there are marks present, snap the incoming percent to the nearest mark
484 * @param[in] value The incoming value on the slider to snap
485 * @return The filtered percentage snapped to the nearest mark
487 float SnapToMark( float value );
490 * Search for if a mark has been reached
492 * @param[in] value The value to search against
493 * @param[out] outIndex The index of the mark if found
494 * @return If a mark has been found to match percent
496 bool MarkReached( float value, int& outIndex );
499 * Handler for when the value view needs to be hidden
501 * @return If handled or not
503 bool HideValueView();
506 * Set value choosing whether to fire signals or not
508 * @paramp[in] value The value to set
509 * @param[in] raiseSignals Configure signals to be raised or not.
511 void DisplayValue( float value, bool raiseSignals );
514 * Create the image for the backing
516 * @param[in] imageName The name of the image to load and set
518 void SetBackingImageName( const std::string& imageName );
521 * @brief Return the backing image file name.
523 * @return The backing image file name.
525 std::string GetBackingImageName();
528 * Create the image for the progress bar
530 * @param[in] imageName The name of the image to load and set
532 void SetProgressImageName( const std::string& imageName );
535 * @brief Return the progress image name.
537 * @return The progress image name if it exists.
539 std::string GetProgressImageName();
542 * @brief Create the image for the popup
544 * @param[in] imageName The name of the image to load and set
546 void CreatePopupImage( const std::string& imageName );
549 * @brief Set the popup name
551 * @param[in] imageName The name of the image to set
553 void SetPopupImageName( const std::string& imageName );
556 * @brief Return the popup image name.
558 * @return The name of the popup image if it exists.
560 std::string GetPopupImageName();
563 * @brief Set the popup arrow image name
565 * @param[in] imageName The name of the image to set
567 void SetPopupArrowImageName( const std::string& imageName );
570 * @brief Return the popup arrow image name.
572 * @return The name of the popup image if it exists.
574 std::string GetPopupArrowImageName();
577 * Create the image for the popup arrow
579 * @param[in] imageName The name of the image to load and set
581 void CreatePopupArrowImage( const std::string& imageName );
584 * Set the size of the progress bar region
586 * @param[in] region The size of the region to set
588 void ResizeProgressRegion( const Vector2& region );
591 * Create the image for the handle
593 * @param[in] imageName The name of the image to load and set
595 void SetHandleImageName( const std::string& imageName );
598 * @brief Return the handle image name.
600 * @return The name of the image handle if it exists.
602 std::string GetHandleImageName();
605 * Set the size of the handle region
607 * @param[in] region The size of the region to set
609 void ResizeHandleRegion( const Vector2& region );
612 * Create and display the value on the handle
614 void CreateHandleValueDisplay();
617 * Remove and destroy the handle value display
619 void DestroyHandleValueDisplay();
622 * Update the color of the popup text
624 * @param[in] color The new color
626 void SetPopupTextColor( const Vector4& color );
631 * @param[in] region The handle region
633 void SetHandleRegion( const Vector2& region );
638 * @return The handle region
640 const Vector2& GetHandleRegion() const;
643 * Set the lower bound of the slider's value
645 * @param[in] bound The value to set for the lower bound
647 void SetLowerBound( float bound );
650 * Get the lower bound of the slider's value
652 * @return The lower bound value
654 float GetLowerBound() const;
657 * Set the upper bound of the slider's value
659 * @param[in] bound The value to set for the upper bound
661 void SetUpperBound( float bound );
664 * Get the upper bound of the slider's value
666 * @return The upper bound value
668 float GetUpperBound() const;
673 Slider( const Slider& );
676 Slider& operator=( const Slider& rhs );
680 Domain mDomain; ///< Current domain of the handle
682 Actor mHitArea; ///< The input handler
683 ImageActor mBacking; ///< Backing image
684 ImageActor mHandle; ///< Slider handle
685 ImageActor mProgress; ///< Progress backing
686 Actor mValueDisplay; ///< Display of the value
687 ImageActor mPopup; ///< Popup backing
688 ImageActor mPopupArrow; ///< Popup arrow backing
690 Toolkit::TextLabel mValueTextLabel; //< The text value in popup
691 Toolkit::TextLabel mHandleValueTextLabel; ///< The text value on handle
692 Vector2 mHandleLastTouchPoint; ///< The last touch point for the handle
693 Timer mValueTimer; ///< Timer used to hide value view
695 Toolkit::Slider::ValueChangedSignalType mValueChangedSignal; ///< Signal emitted when the value is changed
696 Toolkit::Slider::ValueChangedSignalType mSlidingFinishedSignal; ///< Signal emitted when a sliding is finished
697 Toolkit::Slider::MarkSignalType mMarkSignal; ///< Signal emitted when a mark is reached
699 SliderState mState; ///< The state of the slider
701 PanGestureDetector mPanDetector; ///< Hit region pan detector
703 MarkList mMarks; ///< List of discreet marks
705 std::string mPopupImageName; ///< Image name for popup image
706 std::string mPopupArrowImageName; ///< Image name for popup arrow
708 Vector4 mDisableColor; ///< The color to tint the slider when disabled
709 Vector4 mPopupTextColor; ///< The color of the popup text
711 Vector2 mHitRegion; ///< Size of hit region
712 Vector2 mBackingRegion; ///< Size of backing region
713 Vector2 mHandleRegionSize; ///< Size of the handle region
715 float mLowerBound; ///< Lower bound on value
716 float mUpperBound; ///< Upper bound on value
717 float mValue; ///< Current value of slider
719 float mMarkTolerance; ///< Tolerance in percentage of slider width for which to snap to marks
721 int mValuePrecision; ///< The precision to use for outputting the value
723 bool mShowPopup : 1, ///< Show the popup or not
724 mShowValue : 1, ///< Whether to display the value number or not on the handle
725 mSnapToMarks : 1; ///< Turn on or off snapping to marks
728 } // namespace Internal
730 // Helpers for public-api forwarding methods
732 inline Toolkit::Internal::Slider& GetImpl( Toolkit::Slider& pub )
734 DALI_ASSERT_ALWAYS( pub );
736 Dali::RefObject& handle = pub.GetImplementation();
738 return static_cast< Toolkit::Internal::Slider& >( handle );
741 inline const Toolkit::Internal::Slider& GetImpl( const Toolkit::Slider& pub )
743 DALI_ASSERT_ALWAYS( pub );
745 const Dali::RefObject& handle = pub.GetImplementation();
747 return static_cast< const Toolkit::Internal::Slider& >( handle );
750 } // namespace Toolkit
754 #endif // __DALI_TOOLKIT_INTERNAL_SLIDER_H__