X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Fstyling%2Fimage-channel-control-impl.cpp;h=c7dde4f2a55c3ebe0ac5d8392925219fbcdee781;hb=aa68f1034c216719641d32849168fa31f6680576;hp=dc133d1b306f1b45bb51e2705446f321eba0f8ac;hpb=11f7a3260303d7e609694abc4d51513979c613ed;p=platform%2Fcore%2Fuifw%2Fdali-demo.git diff --git a/examples/styling/image-channel-control-impl.cpp b/examples/styling/image-channel-control-impl.cpp index dc133d1..c7dde4f 100644 --- a/examples/styling/image-channel-control-impl.cpp +++ b/examples/styling/image-channel-control-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 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. @@ -16,9 +16,12 @@ #include "image-channel-control-impl.h" #include -#include +#include #include +#include + + using namespace Dali; // Needed for macros namespace Demo @@ -33,11 +36,12 @@ const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( varying mediump vec2 vTexCoord;\n uniform sampler2D sTexture;\n uniform mediump vec4 uColor;\n + uniform mediump vec3 mixColor;\n uniform mediump vec3 uChannels;\n \n void main()\n {\n - gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor * vec4(uChannels, 1.0) ;\n + gl_FragColor = texture2D( sTexture, vTexCoord ) * vec4(mixColor,1.0) * uColor * vec4(uChannels, 1.0) ;\n }\n ); @@ -53,6 +57,11 @@ DALI_PROPERTY_REGISTRATION( Demo, ImageChannelControl, "redChannel", FLOAT, RED_ DALI_PROPERTY_REGISTRATION( Demo, ImageChannelControl, "greenChannel", FLOAT, GREEN_CHANNEL ); DALI_PROPERTY_REGISTRATION( Demo, ImageChannelControl, "blueChannel", FLOAT, BLUE_CHANNEL ); +DALI_PROPERTY_REGISTRATION( Demo, ImageChannelControl, "visibility", BOOLEAN, VISIBILITY ); +DALI_PROPERTY_REGISTRATION( Demo, ImageChannelControl, "enableVisibilityTransition", ARRAY, ENABLE_VISIBILITY_TRANSITION ); +DALI_PROPERTY_REGISTRATION( Demo, ImageChannelControl, "disableVisibilityTransition", ARRAY, DISABLE_VISIBILITY_TRANSITION ); + +DALI_PROPERTY_REGISTRATION( Demo, ImageChannelControl, "imageVisual", MAP, IMAGE_VISUAL ); DALI_TYPE_REGISTRATION_END(); } // anonymous namespace @@ -60,7 +69,10 @@ DALI_TYPE_REGISTRATION_END(); Internal::ImageChannelControl::ImageChannelControl() : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ), - mChannels( 1.0f, 1.0f, 1.0f ) + mChannels( 1.0f, 1.0f, 1.0f ), + mChannelIndex( Property::INVALID_INDEX ), + mVisibility(true), + mTargetVisibility(true) { } @@ -89,11 +101,59 @@ void ImageChannelControl::SetImage( const std::string& url ) properties[Dali::Toolkit::Visual::Property::SHADER]=shader; properties[Dali::Toolkit::ImageVisual::Property::URL] = url; - Dali::Toolkit::InitializeVisual( self, mVisual, properties ); + mVisual = Toolkit::VisualFactory::Get().CreateVisual( properties ); + Toolkit::DevelControl::RegisterVisual( *this, Demo::ImageChannelControl::Property::IMAGE_VISUAL, mVisual ); + mVisual.SetName("imageVisual"); RelayoutRequest(); } +void ImageChannelControl::SetVisibility( bool visibility ) +{ + printf("ImageChannelControl %s: SetVisibility( %s )\n", Self().GetName().c_str(), visibility?"T":"F" ); + + if( mAnimation ) + { + mAnimation.Stop(); + mAnimation.FinishedSignal().Disconnect( this, &ImageChannelControl::OnStateChangeAnimationFinished ); + OnStateChangeAnimationFinished(mAnimation); + } + + if( mVisibility != visibility ) + { + if( mVisibility ) + { + if( mDisableVisibilityTransition.Count() > 0 ) + { + mAnimation = Toolkit::DevelControl::CreateTransition( *this, mDisableVisibilityTransition ); + } + } + else + { + if( mEnableVisibilityTransition.Count() > 0 ) + { + mAnimation = Toolkit::DevelControl::CreateTransition( *this, mEnableVisibilityTransition ); + } + } + } + + if( mAnimation ) + { + mAnimation.FinishedSignal().Connect( this, &ImageChannelControl::OnStateChangeAnimationFinished ); + mAnimation.Play(); + mTargetVisibility = visibility; + } + else + { + mVisibility = visibility; + } +} + +void ImageChannelControl::OnStateChangeAnimationFinished( Animation& src ) +{ + mVisibility = mTargetVisibility; +} + void ImageChannelControl::OnInitialize() { Actor self = Self(); @@ -103,22 +163,10 @@ void ImageChannelControl::OnInitialize() void ImageChannelControl::OnStageConnection( int depth ) { Control::OnStageConnection( depth ); - - if( mVisual ) - { - CustomActor self = Self(); - mVisual.SetOnStage( self ); - } } void ImageChannelControl::OnStageDisconnection() { - if( mVisual ) - { - CustomActor self = Self(); - mVisual.SetOffStage( self ); - } - Control::OnStageDisconnection(); } @@ -129,7 +177,16 @@ void ImageChannelControl::OnSizeSet( const Vector3& targetSize ) if( mVisual ) { Vector2 size( targetSize ); - mVisual.SetSize( size ); + Property::Map transformMap; + transformMap + .Add( Toolkit::Visual::Transform::Property::OFFSET, Vector2(0.0f, 0.0f) ) + .Add( Toolkit::Visual::Transform::Property::SIZE, Vector2(1.0f, 1.0f) ) + .Add( Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::CENTER ) + .Add( Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::CENTER ) + .Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::Visual::Transform::Policy::RELATIVE, Toolkit::Visual::Transform::Policy::RELATIVE ) ) + .Add( Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::Visual::Transform::Policy::RELATIVE, Toolkit::Visual::Transform::Policy::RELATIVE ) ); + + mVisual.SetTransformAndSize( transformMap, size ); } } @@ -144,6 +201,12 @@ Vector3 ImageChannelControl::GetNaturalSize() return Vector3::ZERO; } +void ImageChannelControl::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change ) +{ + // Chain up. + Control::OnStyleChange( styleManager, change ); +} + /////////////////////////////////////////////////////////// // @@ -154,12 +217,56 @@ void ImageChannelControl::SetProperty( BaseObject* object, Property::Index index { Demo::ImageChannelControl imageChannelControl = Demo::ImageChannelControl::DownCast( Dali::BaseHandle( object ) ); - if ( imageChannelControl ) + if( imageChannelControl ) { ImageChannelControl& impl = GetImpl( imageChannelControl ); Actor self = impl.Self(); switch ( index ) { + case Demo::ImageChannelControl::Property::RESOURCE_URL: + { + impl.SetImage( value.Get() ); + break; + } + case Demo::ImageChannelControl::Property::IMAGE_VISUAL: + { + Property::Map* map = value.GetMap(); + if( map ) + { + impl.mVisual = Toolkit::VisualFactory::Get().CreateVisual( *map ); + Toolkit::DevelControl::RegisterVisual( impl, Demo::ImageChannelControl::Property::IMAGE_VISUAL, impl.mVisual ); + } + break; + } + case Demo::ImageChannelControl::Property::VISIBILITY: + { + impl.SetVisibility( value.Get() ); + break; + } + case Demo::ImageChannelControl::Property::ENABLE_VISIBILITY_TRANSITION: + { + if( value.GetType() == Property::ARRAY ) + { + impl.mEnableVisibilityTransition = Toolkit::TransitionData::New( *value.GetArray()); + } + else if( value.GetType() == Property::MAP ) + { + impl.mEnableVisibilityTransition = Toolkit::TransitionData::New( *value.GetMap() ); + } + break; + } + case Demo::ImageChannelControl::Property::DISABLE_VISIBILITY_TRANSITION: + { + if( value.GetType() == Property::ARRAY ) + { + impl.mDisableVisibilityTransition = Toolkit::TransitionData::New( *value.GetArray()); + } + else if( value.GetType() == Property::MAP ) + { + impl.mDisableVisibilityTransition = Toolkit::TransitionData::New( *value.GetMap() ); + } + break; + } case Demo::ImageChannelControl::Property::RED_CHANNEL: { impl.mChannels[0] = value.Get(); @@ -208,6 +315,13 @@ Property::Value ImageChannelControl::GetProperty( BaseObject* object, Property:: value = impl.mChannels[2]; break; } + case Demo::ImageChannelControl::Property::VISIBILITY: + { + value = impl.mVisibility; + break; + } + default: + break; } }