X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fslider%2Fslider-impl.cpp;h=275995d38b05b52f0728c760e3f18201994aabec;hb=3a23cbcd64ab5780928e4a141e497242c9989110;hp=9c9965cccdd206b94d9861704ea060b30b31677b;hpb=f4f74e774495b9c798c86e5697fe84db6decc327;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/controls/slider/slider-impl.cpp b/dali-toolkit/internal/controls/slider/slider-impl.cpp index 9c9965c..275995d 100755 --- a/dali-toolkit/internal/controls/slider/slider-impl.cpp +++ b/dali-toolkit/internal/controls/slider/slider-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,10 +22,10 @@ #include // for strcmp #include #include -#include +#include #include #include -#include +#include // INTERNAL INCLUDES #include @@ -102,7 +102,6 @@ const Vector4 DEFAULT_DISABLED_COLOR( 0.5f, 0.5f, 0.5f, 1.0f ); const float VALUE_POPUP_MARGIN = 10.0f; const float VALUE_POPUP_HEIGHT = 81.0f; const float VALUE_POPUP_MIN_WIDTH = 54.0f; -const Vector2 VALUE_POPUP_ARROW_SIZE( 18.0f, 18.0f ); const float DEFAULT_LOWER_BOUND = 0.0f; const float DEFAULT_UPPER_BOUND = 1.0f; @@ -135,7 +134,7 @@ Dali::Toolkit::Slider Slider::New() } Slider::Slider() -: Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ), +: Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ), mState( NORMAL ), mPopupVisual(""), mPopupArrowVisual(""), @@ -201,31 +200,35 @@ void Slider::OnInitialize() // Size the Slider actor to a default self.SetSize( DEFAULT_HIT_REGION.x, DEFAULT_HIT_REGION.y ); + + // Connect to the touch signal + self.TouchSignal().Connect( this, &Slider::OnTouch ); } -void Slider::OnSizeSet( const Vector3& size ) +void Slider::OnRelayout( const Vector2& size, RelayoutContainer& container ) { - // Factor in handle overshoot into size of track SetHitRegion( Vector2( size.x, GetHitRegion().y ) ); + // Factor in handle overshoot into size of backing SetTrackRegion( Vector2( size.x - GetHandleSize().x, GetTrackRegion().y ) ); + Control::OnRelayout( size, container ); } -bool Slider::OnTouchEvent(Actor actor, const TouchEvent& event) +bool Slider::OnTouch(Actor actor, const TouchData& touch) { if( mState != DISABLED ) { - TouchPoint::State touchState = event.GetPoint(0).state; + const PointState::Type touchState = touch.GetState(0); - if( touchState == TouchPoint::Down ) + if( touchState == PointState::DOWN ) { mState = PRESSED; - float percentage = MapPercentage( event.GetPoint(0).local ); + float percentage = MapPercentage( touch.GetLocalPosition( 0 ) ); float value = MapBounds( ( GetSnapToMarks() ) ? SnapToMark( percentage ) : MarkFilter( percentage ), GetLowerBound(), GetUpperBound() ); SetValue( value ); DisplayPopup( value ); } - else if( touchState == TouchPoint::Up) + else if( touchState == PointState::UP ) { if( mState == PRESSED ) { @@ -310,9 +313,9 @@ Slider::Domain Slider::CalcDomain( const Vector2& currentSize ) void Slider::DisplayValue( float value, bool raiseSignals ) { - float clampledValue = Clamp( value, GetLowerBound(), GetUpperBound() ); + float clampedValue = Clamp( value, GetLowerBound(), GetUpperBound() ); - float percent = MapValuePercentage( clampledValue ); + float percent = MapValuePercentage( clampedValue ); float x = mDomain.from.x + percent * ( mDomain.to.x - mDomain.from.x ); @@ -328,7 +331,7 @@ void Slider::DisplayValue( float value, bool raiseSignals ) if( raiseSignals ) { Toolkit::Slider self = Toolkit::Slider::DownCast( Self() ); - mValueChangedSignal.Emit( self, clampledValue ); + mValueChangedSignal.Emit( self, clampedValue ); int markIndex; if( MarkReached( percent, markIndex ) ) @@ -341,9 +344,13 @@ void Slider::DisplayValue( float value, bool raiseSignals ) { std::stringstream ss; ss.precision( GetValuePrecision() ); - ss << std::fixed << clampledValue; + ss << std::fixed << clampedValue; - mHandleValueTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, ss.str() ); + std::string label = mHandleValueTextLabel.GetProperty( Toolkit::TextLabel::Property::TEXT ); + if( label.compare(ss.str()) ) + { + mHandleValueTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, ss.str() ); + } } } @@ -372,7 +379,7 @@ Actor Slider::CreateHitRegion() Actor hitRegion = Actor::New(); hitRegion.SetParentOrigin( ParentOrigin::CENTER ); hitRegion.SetAnchorPoint( AnchorPoint::CENTER ); - hitRegion.TouchedSignal().Connect( this, &Slider::OnTouchEvent ); + hitRegion.TouchSignal().Connect( this, &Slider::OnTouch ); return hitRegion; } @@ -380,9 +387,9 @@ Actor Slider::CreateHitRegion() Toolkit::ImageView Slider::CreateTrack() { Toolkit::ImageView track = Toolkit::ImageView::New(); + track.SetName("SliderTrack"); track.SetParentOrigin( ParentOrigin::CENTER ); track.SetAnchorPoint( AnchorPoint::CENTER ); - return track; } @@ -442,6 +449,7 @@ std::string Slider::GetTrackVisual() Toolkit::ImageView Slider::CreateProgress() { Toolkit::ImageView progress = Toolkit::ImageView::New(); + progress.SetName("SliderProgress"); progress.SetParentOrigin( ParentOrigin::CENTER_LEFT ); progress.SetAnchorPoint( AnchorPoint::CENTER_LEFT ); @@ -512,8 +520,9 @@ void Slider::CreatePopupImage( const std::string& filename ) { if( mPopup && ( filename.size() > 0 ) ) { - Image image = ResourceImage::New( filename ); - mPopup.SetImage( image ); + Property::Map map; + map[Toolkit::ImageVisual::Property::URL] = filename; + mPopup.SetProperty( Toolkit::ImageView::Property::IMAGE, map ); } } @@ -549,8 +558,9 @@ void Slider::CreatePopupArrowImage( const std::string& filename ) { if( mPopupArrow && ( filename.size() > 0 ) ) { - Image image = ResourceImage::New( filename ); - mPopupArrow.SetImage( image ); + Property::Map map; + map[Toolkit::ImageVisual::Property::URL] = filename; + mPopupArrow.SetProperty( Toolkit::ImageView::Property::IMAGE, map ); } } @@ -565,6 +575,7 @@ void Slider::ResizeProgressRegion( const Vector2& region ) Toolkit::ImageView Slider::CreateHandle() { Toolkit::ImageView handle = Toolkit::ImageView::New(); + handle.SetName("SliderHandle"); handle.SetParentOrigin( ParentOrigin::CENTER_LEFT ); handle.SetAnchorPoint( AnchorPoint::CENTER ); @@ -574,6 +585,8 @@ Toolkit::ImageView Slider::CreateHandle() Toolkit::ImageView Slider::CreatePopupArrow() { Toolkit::ImageView arrow = Toolkit::ImageView::New(); + arrow.SetStyleName("SliderPopupArrow"); + arrow.SetName("SliderPopupArrow"); arrow.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); arrow.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); @@ -583,6 +596,8 @@ Toolkit::ImageView Slider::CreatePopupArrow() Toolkit::TextLabel Slider::CreatePopupText() { Toolkit::TextLabel textLabel = Toolkit::TextLabel::New(); + textLabel.SetName( "SliderPopupTextLabel" ); + textLabel.SetStyleName( "SliderPopupTextLabel" ); textLabel.SetParentOrigin( ParentOrigin::CENTER ); textLabel.SetAnchorPoint( AnchorPoint::CENTER ); textLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); @@ -595,6 +610,7 @@ Toolkit::TextLabel Slider::CreatePopupText() Toolkit::ImageView Slider::CreatePopup() { Toolkit::ImageView popup = Toolkit::ImageView::New(); + popup.SetName( "SliderPopup" ); popup.SetParentOrigin( ParentOrigin::TOP_CENTER ); popup.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); popup.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::WIDTH ); @@ -665,6 +681,8 @@ void Slider::CreateHandleValueDisplay() if( mHandle && !mHandleValueTextLabel ) { mHandleValueTextLabel = Toolkit::TextLabel::New(); + mHandleValueTextLabel.SetName("SliderHandleTextLabel"); + mHandleValueTextLabel.SetStyleName("SliderHandleTextLabel"); mHandleValueTextLabel.SetParentOrigin( ParentOrigin::CENTER ); mHandleValueTextLabel.SetAnchorPoint( AnchorPoint::CENTER ); mHandleValueTextLabel.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); @@ -1360,8 +1378,15 @@ Property::Value Slider::GetProperty( BaseObject* object, Property::Index propert case Toolkit::Slider::Property::MARKS: { - // TODO: Need to be able to return a PropertyArray - // value = sliderImpl.GetMarks(); + Property::Value value1( Property::ARRAY ); + Property::Array* markArray = value1.GetArray(); + + if( markArray ) + { + *markArray = sliderImpl.GetMarks(); + } + + value = value1; break; }