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>
24 #include <dali/public-api/object/property-array.h>
27 #include <dali-toolkit/public-api/controls/control-impl.h>
28 #include <dali-toolkit/devel-api/controls/slider/slider.h>
29 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
44 typedef Dali::IntrusivePtr< Slider > SliderPtr;
47 * @copydoc Toolkit::Slider
49 class Slider : public Control
53 typedef Property::Array MarkList;
56 * Create a new Slider.
58 * @return A public handle to the newly allocated Slider.
60 static Dali::Toolkit::Slider New();
67 * Set marks from a list
69 * @param[in] marks The list of marks to set
71 void SetMarks( const MarkList& marks );
74 * Get the list of marks
76 * @return The marks list
78 const MarkList& GetMarks() const;
81 * Set if should snap to marks or not
83 * @param[in] snap Flag to snap to marks or not
85 void SetSnapToMarks( bool snap );
88 * Return if snap to marks is set or not
90 * @return If snap to marks is set
92 bool GetSnapToMarks() const;
95 * Set the value of the slider
97 * @param[in] value The value to set. Will be clamped to [lowerBound .. upperBound]
99 void SetValue( float value );
102 * Get the value of the slider
104 * @return The current value of the slider
106 float GetValue() const;
111 * @param[in] region The hit region
113 void SetHitRegion( const Vector2& region );
118 * @return The hit region
120 const Vector2& GetHitRegion() const;
125 * @param[in] region The backing region
127 void SetBackingRegion( const Vector2& region );
132 * @return The backing region
134 const Vector2& GetBackingRegion() const;
137 * @brief Set the disable color.
139 * @param[in] color The disable color.
141 void SetDisableColor( const Vector4& color );
144 * @brief Get disable color
146 * @return The disable color
148 Vector4 GetDisableColor() const;
151 * Get popup text color
153 * @return The popup text color
155 Vector4 GetPopupTextColor() const;
158 * Set the value precision to be used for numbers in the slider
160 * @param[in] precision The number of decimal places to use for printing numbers
162 void SetValuePrecision( int precision );
165 * Get value precision
167 * @return The value precision
169 int GetValuePrecision() const;
174 * @param[in] showPopup The show popup flag
176 void SetShowPopup( bool showPopup );
179 * Get show value in popup
181 * @return The show value flag
183 bool GetShowPopup() const;
186 * Set show value on handle
188 * @param[in] showValue The show value flag
190 void SetShowValue( bool showValue );
193 * Get show value on handle
195 * @return The show value flag
197 bool GetShowValue() const;
202 * param[in] enabled Set the enabled flag
204 void SetEnabled( bool enabled );
207 * Return if enabled or not
211 bool IsEnabled() const;
214 * @brief Set the mark tolerance
216 * The tolerance is the percentage of the slider width for which snapping to
219 * @param[in] tolerance The percentage of width for which to snap
221 void SetMarkTolerance( float tolerance );
224 * Return the mark tolerance
226 * @return The tolerance set for snapping to marks
228 float GetMarkTolerance() const;
234 * @copydoc Toolkit::Slider::ValueChangedSignal()
236 Toolkit::Slider::ValueChangedSignalType& ValueChangedSignal();
239 * copydoc Toolkit::Slider::SlidingFinishedSignal()
241 Toolkit::Slider::ValueChangedSignalType& SlidingFinishedSignal();
244 * @copydoc Toolkit::Slider::MarkSignal()
246 Toolkit::Slider::MarkSignalType& MarkSignal();
249 * Connects a callback function with the object's signals.
250 * @param[in] object The object providing the signal.
251 * @param[in] tracker Used to disconnect the signal.
252 * @param[in] signalName The signal to connect to.
253 * @param[in] functor A newly allocated FunctorDelegate.
254 * @return True if the signal was connected.
255 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
257 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName,
258 FunctorDelegate* functor );
263 * Called when a property of an object of this type is set.
264 * @param[in] object The object whose property is set.
265 * @param[in] index The property index.
266 * @param[in] value The new property value.
268 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
271 * Called to retrieve a property of an object of this type.
272 * @param[in] object The object whose property is to be retrieved.
273 * @param[in] index The property index.
274 * @return The current value of the property.
276 static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
281 * Construct a new Slider.
286 * A reference counted object may only be deleted by calling Unreference()
291 * @copydoc CustomActorImpl::OnSizeSet( const Vector3& size )
293 virtual void OnSizeSet( const Vector3& size );
298 * Domain is a from/to pair
308 Domain( Vector2 fromVal, Vector2 toVal )
309 : from( fromVal ), to( toVal )
328 * @copydoc Toolkit::Control::OnInitialize()
330 virtual void OnInitialize();
333 * Hit region touch event
335 * @param[in] actor The actor the event is raised for
336 * @param[in] event The touch event info
337 * @return If the event is handled or not
339 bool OnTouchEvent( Actor actor, const TouchEvent& event );
344 * @param[in] actor The actor the event is raised for
345 * @param[in] gesture The pan event info
347 void OnPan( Actor actor, const PanGesture& gesture );
350 * Map a position onto a domain and return the result as a percentage
352 * @param[in] point The point to map onto the domain
353 * @return The result as a percentage [0..1]
355 float MapPercentage( const Vector2& point );
358 * Map a value in the range to a percentage
360 * @param[in] point The value in range [lowerBound..upperBound]
361 * @return The result as a percentage [0..1]
363 float MapValuePercentage( float value );
366 * Convert a point in local hit space into domain space
368 * @param[in] x The x position to convert
369 * @return The x position in domain space
371 float HitSpaceToDomain( float x );
374 * Map a percentage onto the slider's bounds
376 * @param[in] percent The current value of slider in percent
377 * @param[in] lowerBound The lower bound to map onto
378 * @param[in] upperBound The upper bound to map onto
379 * @return The value of percent mapped from lowerBound to upperBound
381 float MapBounds( float percent, float lowerBound, float upperBound );
384 * Get the range of the valid values the slider handle can move between
386 * @param[in] currentSize The current size of the slider
387 * @return The range as a domain pair
389 Domain CalcDomain( const Vector2& currentSize );
392 * Create the hit region
394 * @return The hit region actor
396 Actor CreateHitRegion();
399 * Create the backing for the slider
401 * @return The backing actor
403 ImageActor CreateBacking();
406 * Create the progress backing for the slider
408 * @return The backing actor
410 ImageActor CreateProgress();
413 * Create the handle for the slider
415 * @return The created image handle
417 ImageActor CreateHandle();
420 * Create the popup arrow
422 * @return The created image handle
424 ImageActor CreatePopupArrow();
429 * @return The created image handle
431 ImageActor CreatePopup();
434 * Create the textview for the popup
436 * @return The textview created for the popup
438 Toolkit::TextLabel CreatePopupText();
441 * Create the value display for the slider
443 * @return The created root actor of the display
445 Actor CreateValueDisplay();
448 * Set the skin based on the current state
453 * Create all the children
455 void CreateChildren();
468 * Display the popup for a set duration with the given value
470 * @param[in] value The value to display in the popup
472 void DisplayPopup( float value );
475 * If there are marks present, filter the incoming percent based on snapping to any nearby marks
477 * @param[in] value The incoming value on the slider to filter
478 * @return The filtered percentage snapped to any nearby marks
480 float MarkFilter( float value );
483 * If there are marks present, snap the incoming percent to the nearest mark
485 * @param[in] value The incoming value on the slider to snap
486 * @return The filtered percentage snapped to the nearest mark
488 float SnapToMark( float value );
491 * Search for if a mark has been reached
493 * @param[in] value The value to search against
494 * @param[out] outIndex The index of the mark if found
495 * @return If a mark has been found to match percent
497 bool MarkReached( float value, int& outIndex );
500 * Handler for when the value view needs to be hidden
502 * @return If handled or not
504 bool HideValueView();
507 * Set value choosing whether to fire signals or not
509 * @paramp[in] value The value to set
510 * @param[in] raiseSignals Configure signals to be raised or not.
512 void DisplayValue( float value, bool raiseSignals );
515 * Create the image for the backing
517 * @param[in] imageName The name of the image to load and set
519 void SetBackingImageName( const std::string& imageName );
522 * @brief Return the backing image file name.
524 * @return The backing image file name.
526 std::string GetBackingImageName();
529 * Create the image for the progress bar
531 * @param[in] imageName The name of the image to load and set
533 void SetProgressImageName( const std::string& imageName );
536 * @brief Return the progress image name.
538 * @return The progress image name if it exists.
540 std::string GetProgressImageName();
543 * @brief Create the image for the popup
545 * @param[in] imageName The name of the image to load and set
547 void CreatePopupImage( const std::string& imageName );
550 * @brief Set the popup name
552 * @param[in] imageName The name of the image to set
554 void SetPopupImageName( const std::string& imageName );
557 * @brief Return the popup image name.
559 * @return The name of the popup image if it exists.
561 std::string GetPopupImageName();
564 * @brief Set the popup arrow image name
566 * @param[in] imageName The name of the image to set
568 void SetPopupArrowImageName( const std::string& imageName );
571 * @brief Return the popup arrow image name.
573 * @return The name of the popup image if it exists.
575 std::string GetPopupArrowImageName();
578 * Create the image for the popup arrow
580 * @param[in] imageName The name of the image to load and set
582 void CreatePopupArrowImage( const std::string& imageName );
585 * Set the size of the progress bar region
587 * @param[in] region The size of the region to set
589 void ResizeProgressRegion( const Vector2& region );
592 * Create the image for the handle
594 * @param[in] imageName The name of the image to load and set
596 void SetHandleImageName( const std::string& imageName );
599 * @brief Return the handle image name.
601 * @return The name of the image handle if it exists.
603 std::string GetHandleImageName();
606 * Set the size of the handle region
608 * @param[in] region The size of the region to set
610 void ResizeHandleRegion( const Vector2& region );
613 * Create and display the value on the handle
615 void CreateHandleValueDisplay();
618 * Remove and destroy the handle value display
620 void DestroyHandleValueDisplay();
623 * Update the color of the popup text
625 * @param[in] color The new color
627 void SetPopupTextColor( const Vector4& color );
632 * @param[in] region The handle region
634 void SetHandleRegion( const Vector2& region );
639 * @return The handle region
641 const Vector2& GetHandleRegion() const;
644 * Set the lower bound of the slider's value
646 * @param[in] bound The value to set for the lower bound
648 void SetLowerBound( float bound );
651 * Get the lower bound of the slider's value
653 * @return The lower bound value
655 float GetLowerBound() const;
658 * Set the upper bound of the slider's value
660 * @param[in] bound The value to set for the upper bound
662 void SetUpperBound( float bound );
665 * Get the upper bound of the slider's value
667 * @return The upper bound value
669 float GetUpperBound() const;
674 Slider( const Slider& );
677 Slider& operator=( const Slider& rhs );
681 Domain mDomain; ///< Current domain of the handle
683 Actor mHitArea; ///< The input handler
684 ImageActor mBacking; ///< Backing image
685 ImageActor mHandle; ///< Slider handle
686 ImageActor mProgress; ///< Progress backing
687 Actor mValueDisplay; ///< Display of the value
688 ImageActor mPopup; ///< Popup backing
689 ImageActor mPopupArrow; ///< Popup arrow backing
691 Toolkit::TextLabel mValueTextLabel; //< The text value in popup
692 Toolkit::TextLabel mHandleValueTextLabel; ///< The text value on handle
693 Vector2 mHandleLastTouchPoint; ///< The last touch point for the handle
694 Timer mValueTimer; ///< Timer used to hide value view
696 Toolkit::Slider::ValueChangedSignalType mValueChangedSignal; ///< Signal emitted when the value is changed
697 Toolkit::Slider::ValueChangedSignalType mSlidingFinishedSignal; ///< Signal emitted when a sliding is finished
698 Toolkit::Slider::MarkSignalType mMarkSignal; ///< Signal emitted when a mark is reached
700 SliderState mState; ///< The state of the slider
702 PanGestureDetector mPanDetector; ///< Hit region pan detector
704 MarkList mMarks; ///< List of discreet marks
706 std::string mPopupImageName; ///< Image name for popup image
707 std::string mPopupArrowImageName; ///< Image name for popup arrow
709 Vector4 mDisableColor; ///< The color to tint the slider when disabled
710 Vector4 mPopupTextColor; ///< The color of the popup text
712 Vector2 mHitRegion; ///< Size of hit region
713 Vector2 mBackingRegion; ///< Size of backing region
714 Vector2 mHandleRegionSize; ///< Size of the handle region
716 float mLowerBound; ///< Lower bound on value
717 float mUpperBound; ///< Upper bound on value
718 float mValue; ///< Current value of slider
720 float mMarkTolerance; ///< Tolerance in percentage of slider width for which to snap to marks
722 int mValuePrecision; ///< The precision to use for outputting the value
724 bool mShowPopup : 1, ///< Show the popup or not
725 mShowValue : 1, ///< Whether to display the value number or not on the handle
726 mSnapToMarks : 1; ///< Turn on or off snapping to marks
729 } // namespace Internal
731 // Helpers for public-api forwarding methods
733 inline Toolkit::Internal::Slider& GetImpl( Toolkit::Slider& pub )
735 DALI_ASSERT_ALWAYS( pub );
737 Dali::RefObject& handle = pub.GetImplementation();
739 return static_cast< Toolkit::Internal::Slider& >( handle );
742 inline const Toolkit::Internal::Slider& GetImpl( const Toolkit::Slider& pub )
744 DALI_ASSERT_ALWAYS( pub );
746 const Dali::RefObject& handle = pub.GetImplementation();
748 return static_cast< const Toolkit::Internal::Slider& >( handle );
751 } // namespace Toolkit
755 #endif // __DALI_TOOLKIT_INTERNAL_SLIDER_H__