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
54 SLIDER_PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
55 SLIDER_PROPERTY_END_INDEX = SLIDER_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices
58 typedef Property::Array MarkList;
61 * Create a new Slider.
63 * @return A public handle to the newly allocated Slider.
65 static Dali::Toolkit::Slider New();
72 * Set marks from a list
74 * @param[in] marks The list of marks to set
76 void SetMarks( const MarkList& marks );
79 * Get the list of marks
81 * @return The marks list
83 const MarkList& GetMarks() const;
86 * Set if should snap to marks or not
88 * @param[in] snap Flag to snap to marks or not
90 void SetSnapToMarks( bool snap );
93 * Return if snap to marks is set or not
95 * @return If snap to marks is set
97 bool GetSnapToMarks() const;
100 * Set the value of the slider
102 * @param[in] value The value to set. Will be clamped to [lowerBound .. upperBound]
104 void SetValue( float value );
107 * Get the value of the slider
109 * @return The current value of the slider
111 float GetValue() const;
116 * @param[in] region The hit region
118 void SetHitRegion( const Vector2& region );
123 * @return The hit region
125 const Vector2& GetHitRegion() const;
130 * @param[in] region The backing region
132 void SetBackingRegion( const Vector2& region );
137 * @return The backing region
139 const Vector2& GetBackingRegion() const;
142 * @brief Set the disable color.
144 * @param[in] color The disable color.
146 void SetDisableColor( const Vector4& color );
149 * @brief Get disable color
151 * @return The disable color
153 Vector4 GetDisableColor() const;
156 * Get popup text color
158 * @return The popup text color
160 Vector4 GetPopupTextColor() const;
163 * Set the value precision to be used for numbers in the slider
165 * @param[in] precision The number of decimal places to use for printing numbers
167 void SetValuePrecision( int precision );
170 * Get value precision
172 * @return The value precision
174 int GetValuePrecision() const;
179 * @param[in] showPopup The show popup flag
181 void SetShowPopup( bool showPopup );
184 * Get show value in popup
186 * @return The show value flag
188 bool GetShowPopup() const;
191 * Set show value on handle
193 * @param[in] showValue The show value flag
195 void SetShowValue( bool showValue );
198 * Get show value on handle
200 * @return The show value flag
202 bool GetShowValue() const;
207 * param[in] enabled Set the enabled flag
209 void SetEnabled( bool enabled );
212 * Return if enabled or not
216 bool IsEnabled() const;
219 * @brief Set the mark tolerance
221 * The tolerance is the percentage of the slider width for which snapping to
224 * @param[in] tolerance The percentage of width for which to snap
226 void SetMarkTolerance( float tolerance );
229 * Return the mark tolerance
231 * @return The tolerance set for snapping to marks
233 float GetMarkTolerance() const;
239 * @copydoc Toolkit::Slider::ValueChangedSignal()
241 Toolkit::Slider::ValueChangedSignalType& ValueChangedSignal();
244 * copydoc Toolkit::Slider::SlidingFinishedSignal()
246 Toolkit::Slider::ValueChangedSignalType& SlidingFinishedSignal();
249 * @copydoc Toolkit::Slider::MarkSignal()
251 Toolkit::Slider::MarkSignalType& MarkSignal();
254 * Connects a callback function with the object's signals.
255 * @param[in] object The object providing the signal.
256 * @param[in] tracker Used to disconnect the signal.
257 * @param[in] signalName The signal to connect to.
258 * @param[in] functor A newly allocated FunctorDelegate.
259 * @return True if the signal was connected.
260 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
262 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName,
263 FunctorDelegate* functor );
268 * Called when a property of an object of this type is set.
269 * @param[in] object The object whose property is set.
270 * @param[in] index The property index.
271 * @param[in] value The new property value.
273 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
276 * Called to retrieve a property of an object of this type.
277 * @param[in] object The object whose property is to be retrieved.
278 * @param[in] index The property index.
279 * @return The current value of the property.
281 static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
286 * Construct a new Slider.
291 * A reference counted object may only be deleted by calling Unreference()
296 * @copydoc Control::OnControlSizeSet( const Vector3& size )
298 virtual void OnControlSizeSet( const Vector3& size );
303 * Domain is a from/to pair
313 Domain( Vector2 fromVal, Vector2 toVal )
314 : from( fromVal ), to( toVal )
333 * @copydoc Toolkit::Control::OnInitialize()
335 virtual void OnInitialize();
338 * Hit region touch event
340 * @param[in] actor The actor the event is raised for
341 * @param[in] event The touch event info
342 * @return If the event is handled or not
344 bool OnTouchEvent( Actor actor, const TouchEvent& event );
349 * @param[in] actor The actor the event is raised for
350 * @param[in] gesture The pan event info
352 void OnPan( Actor actor, const PanGesture& gesture );
355 * Map a position onto a domain and return the result as a percentage
357 * @param[in] point The point to map onto the domain
358 * @return The result as a percentage [0..1]
360 float MapPercentage( const Vector2& point );
363 * Map a value in the range to a percentage
365 * @param[in] point The value in range [lowerBound..upperBound]
366 * @return The result as a percentage [0..1]
368 float MapValuePercentage( float value );
371 * Convert a point in local hit space into domain space
373 * @param[in] x The x position to convert
374 * @return The x position in domain space
376 float HitSpaceToDomain( float x );
379 * Map a percentage onto the slider's bounds
381 * @param[in] percent The current value of slider in percent
382 * @param[in] lowerBound The lower bound to map onto
383 * @param[in] upperBound The upper bound to map onto
384 * @return The value of percent mapped from lowerBound to upperBound
386 float MapBounds( float percent, float lowerBound, float upperBound );
389 * Get the range of the valid values the slider handle can move between
391 * @param[in] currentSize The current size of the slider
392 * @return The range as a domain pair
394 Domain CalcDomain( const Vector2& currentSize );
397 * Create the hit region
399 * @return The hit region actor
401 Actor CreateHitRegion();
404 * Create the backing for the slider
406 * @return The backing actor
408 ImageActor CreateBacking();
411 * Create the progress backing for the slider
413 * @return The backing actor
415 ImageActor CreateProgress();
418 * Create the handle for the slider
420 * @return The created image handle
422 ImageActor CreateHandle();
425 * Create the popup arrow
427 * @return The created image handle
429 ImageActor CreatePopupArrow();
434 * @return The created image handle
436 ImageActor CreatePopup();
439 * Create the textview for the popup
441 * @return The textview created for the popup
443 //Toolkit::TextView CreatePopupText();
446 * Create the value display for the slider
448 * @return The created root actor of the display
450 Actor CreateValueDisplay();
453 * Set the skin based on the current state
458 * Create all the children
460 void CreateChildren();
473 * Display the popup for a set duration with the given value
475 * @param[in] value The value to display in the popup
477 void DisplayPopup( float value );
480 * If there are marks present, filter the incoming percent based on snapping to any nearby marks
482 * @param[in] value The incoming value on the slider to filter
483 * @return The filtered percentage snapped to any nearby marks
485 float MarkFilter( float value );
488 * If there are marks present, snap the incoming percent to the nearest mark
490 * @param[in] value The incoming value on the slider to snap
491 * @return The filtered percentage snapped to the nearest mark
493 float SnapToMark( float value );
496 * Search for if a mark has been reached
498 * @param[in] value The value to search against
499 * @param[out] outIndex The index of the mark if found
500 * @return If a mark has been found to match percent
502 bool MarkReached( float value, int& outIndex );
505 * Handler for when the value view needs to be hidden
507 * @return If handled or not
509 bool HideValueView();
512 * Set value choosing whether to fire signals or not
514 * @paramp[in] value The value to set
515 * @param[in] raiseSignals Configure signals to be raised or not.
517 void DisplayValue( float value, bool raiseSignals );
520 * Create the image for the backing
522 * @param[in] imageName The name of the image to load and set
524 void SetBackingImageName( const std::string& imageName );
527 * @brief Return the backing image file name.
529 * @return The backing image file name.
531 std::string GetBackingImageName();
534 * Create the image for the progress bar
536 * @param[in] imageName The name of the image to load and set
538 void SetProgressImageName( const std::string& imageName );
541 * @brief Return the progress image name.
543 * @return The progress image name if it exists.
545 std::string GetProgressImageName();
548 * @brief Create the image for the popup
550 * @param[in] imageName The name of the image to load and set
552 void CreatePopupImage( const std::string& imageName );
555 * @brief Set the popup name
557 * @param[in] imageName The name of the image to set
559 void SetPopupImageName( const std::string& imageName );
562 * @brief Return the popup image name.
564 * @return The name of the popup image if it exists.
566 std::string GetPopupImageName();
569 * @brief Set the popup arrow image name
571 * @param[in] imageName The name of the image to set
573 void SetPopupArrowImageName( const std::string& imageName );
576 * @brief Return the popup arrow image name.
578 * @return The name of the popup image if it exists.
580 std::string GetPopupArrowImageName();
583 * Create the image for the popup arrow
585 * @param[in] imageName The name of the image to load and set
587 void CreatePopupArrowImage( const std::string& imageName );
590 * Set the size of the progress bar region
592 * @param[in] region The size of the region to set
594 void ResizeProgressRegion( const Vector2& region );
597 * Create the image for the handle
599 * @param[in] imageName The name of the image to load and set
601 void SetHandleImageName( const std::string& imageName );
604 * @brief Return the handle image name.
606 * @return The name of the image handle if it exists.
608 std::string GetHandleImageName();
611 * Set the size of the handle region
613 * @param[in] region The size of the region to set
615 void ResizeHandleRegion( const Vector2& region );
618 * Create and display the value on the handle
620 void CreateHandleValueDisplay();
623 * Remove and destroy the handle value display
625 void DestroyHandleValueDisplay();
628 * Update the color of the popup text
630 * @param[in] color The new color
632 void SetPopupTextColor( const Vector4& color );
637 * @param[in] region The handle region
639 void SetHandleRegion( const Vector2& region );
644 * @return The handle region
646 const Vector2& GetHandleRegion() const;
649 * Set the lower bound of the slider's value
651 * @param[in] bound The value to set for the lower bound
653 void SetLowerBound( float bound );
656 * Get the lower bound of the slider's value
658 * @return The lower bound value
660 float GetLowerBound() const;
663 * Set the upper bound of the slider's value
665 * @param[in] bound The value to set for the upper bound
667 void SetUpperBound( float bound );
670 * Get the upper bound of the slider's value
672 * @return The upper bound value
674 float GetUpperBound() const;
679 Slider( const Slider& );
682 Slider& operator=( const Slider& rhs );
686 Domain mDomain; ///< Current domain of the handle
688 Actor mHitArea; ///< The input handler
689 ImageActor mBacking; ///< Backing image
690 ImageActor mHandle; ///< Slider handle
691 ImageActor mProgress; ///< Progress backing
692 Actor mValueDisplay; ///< Display of the value
693 ImageActor mPopup; ///< Popup backing
694 ImageActor mPopupArrow; ///< Popup arrow backing
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__