X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Feffects-view%2Feffects-view-impl.cpp;h=8d1a3b378d5a93c40ca848cd6a5503f0f7751c66;hp=a513c55fba1d1f4404746266755e261d6a6cc792;hb=0dd2826b16facb7e8f21ffb86853bd1b0afb97b4;hpb=e2eda444afbe82e9591fe198eef339227f90a616 diff --git a/dali-toolkit/internal/controls/effects-view/effects-view-impl.cpp b/dali-toolkit/internal/controls/effects-view/effects-view-impl.cpp index a513c55..8d1a3b3 100644 --- a/dali-toolkit/internal/controls/effects-view/effects-view-impl.cpp +++ b/dali-toolkit/internal/controls/effects-view/effects-view-impl.cpp @@ -1,22 +1,31 @@ -// -// Copyright (c) 2014 Samsung Electronics Co., Ltd. -// -// Licensed under the Flora License, Version 1.0 (the License); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://floralicense.org/license/ -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an AS IS BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// +/* + * Copyright (c) 2014 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ // CLASS HEADER #include "effects-view-impl.h" +// EXTERNAL INCLUDES +#include +#include +#include +#include +#include +#include + // INTERNAL INCLUDES #include "../../filters/blur-two-pass-filter.h" #include "../../filters/emboss-filter.h" @@ -39,21 +48,24 @@ Dali::BaseHandle Create() return Toolkit::EffectsView::New(); } -Dali::TypeRegistration mType( typeid(Dali::Toolkit::EffectsView), typeid(Dali::Toolkit::Control), Create ); +DALI_TYPE_REGISTRATION_BEGIN( Toolkit::EffectsView, Toolkit::Control, Create ) +DALI_TYPE_REGISTRATION_END() const Pixel::Format EFFECTS_VIEW_DEFAULT_PIXEL_FORMAT = Pixel::RGBA8888; const float ARBITRARY_FIELD_OF_VIEW = Math::PI / 4.0f; const Vector4 EFFECTS_VIEW_DEFAULT_BACKGROUND_COLOR( 1.0f, 1.0f, 1.0f, 0.0 ); const bool EFFECTS_VIEW_REFRESH_ON_DEMAND(false); -// custom properties + +// Custom properties +const char* const EFFECT_SIZE_PROPERTY_NAME = "EffectSize"; +const char* const EFFECT_STRENGTH_PROPERTY_NAME = "EffectStrength"; +const char* const EFFECT_OFFSET_PROPERTY_NAME = "EffectOffset"; +const char* const EFFECT_COLOR_PROPERTY_NAME = "EffectColor"; + const float EFFECT_SIZE_DEFAULT( 1.0f ); -const std::string EFFECT_SIZE_PROPERTY_NAME( "EffectSize" ); const float EFFECT_STRENGTH_DEFAULT( 0.5f ); -const std::string EFFECT_STRENGTH_PROPERTY_NAME( "EffectStrength" ); const Vector3 EFFECT_OFFSET_DEFAULT( 0.0f, 0.0f, 0.0f ); -const std::string EFFECT_OFFSET_PROPERTY_NAME( "EffectOffset" ); const Vector4 EFFECT_COLOR_DEFAULT( Color::WHITE ); -const std::string EFFECT_COLOR_PROPERTY_NAME( "EffectColor" ); const char* const EFFECTS_VIEW_FRAGMENT_SOURCE = "void main()\n" @@ -100,7 +112,7 @@ Toolkit::EffectsView EffectsView::New() } EffectsView::EffectsView() -: ControlImpl( false ), +: Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ), mEffectType( Toolkit::EffectsView::INVALID_TYPE ), mPixelFormat( EFFECTS_VIEW_DEFAULT_PIXEL_FORMAT ), mSpread(0.0f), @@ -213,7 +225,7 @@ void EffectsView::SetOutputImage( FrameBufferImage image ) } mActorForResult = Actor::New(); mActorForResult.SetParentOrigin( ParentOrigin::CENTER ); - mActorForResult.ApplyConstraint( Constraint::New( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); + mActorForResult.SetSize( mTargetSize ); mActorForResult.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) ); Self().Add( mActorForResult ); @@ -258,9 +270,14 @@ void EffectsView::SetupProperties() mEffectStrengthPropertyIndex = self.RegisterProperty(EFFECT_STRENGTH_PROPERTY_NAME, EFFECT_STRENGTH_DEFAULT, Property::READ_WRITE); mEffectOffsetPropertyIndex = self.RegisterProperty(EFFECT_OFFSET_PROPERTY_NAME, EFFECT_OFFSET_DEFAULT); mEffectColorPropertyIndex = self.RegisterProperty(EFFECT_COLOR_PROPERTY_NAME, EFFECT_COLOR_DEFAULT); - mActorPostFilter.ApplyConstraint( Constraint::New( Actor::POSITION, Source( self, mEffectOffsetPropertyIndex ), EqualToConstraint() ) ); - mActorPostFilter.ApplyConstraint( Constraint::New( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); - mActorPostFilter.ApplyConstraint( Constraint::New( Actor::COLOR, Source( self, mEffectColorPropertyIndex ), EqualToConstraint() ) ); + + Constraint positionConstraint = Constraint::New( mActorPostFilter, Actor::Property::POSITION, EqualToConstraint() ); + positionConstraint.AddSource( Source( self, mEffectOffsetPropertyIndex ) ); + positionConstraint.Apply(); + + Constraint colorConstraint = Constraint::New( mActorPostFilter, Actor::Property::COLOR, EqualToConstraint() ); + colorConstraint.AddSource( Source( self, mEffectColorPropertyIndex ) ); + colorConstraint.Apply(); } void EffectsView::SetBackgroundColor( const Vector4& color ) @@ -273,7 +290,7 @@ Vector4 EffectsView::GetBackgroundColor() const return mBackgroundColor; } -// From ControlImpl +// From Control void EffectsView::OnInitialize() { ////////////////////////////////////////////////////// @@ -282,13 +299,11 @@ void EffectsView::OnInitialize() mCameraForChildren.SetParentOrigin(ParentOrigin::CENTER); mActorForChildren = ImageActor::New(); - mActorForChildren.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION ); - mActorForChildren.ApplyConstraint( Constraint::New( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); // same size as EffectsView object + mActorForChildren.SetParentOrigin( ParentOrigin::CENTER ); mActorForChildren.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) ); mActorPostFilter = ImageActor::New(); mActorPostFilter.SetParentOrigin( ParentOrigin::CENTER ); - mActorPostFilter.ApplyConstraint( Constraint::New( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); // same size as EffectsView object mActorPostFilter.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) ); mActorPostFilter.SetShaderEffect( ShaderEffect::New( "", EFFECTS_VIEW_FRAGMENT_SOURCE ) ); @@ -300,7 +315,7 @@ void EffectsView::OnInitialize() SetupProperties(); } -void EffectsView::OnControlSizeSet(const Vector3& targetSize) +void EffectsView::OnSizeSet(const Vector3& targetSize) { mTargetSize = Vector2(targetSize); @@ -309,6 +324,38 @@ void EffectsView::OnControlSizeSet(const Vector3& targetSize) { AllocateResources(); } + + if( mActorForResult ) + { + mActorForResult.SetSize( targetSize ); + } + if( mActorForChildren ) + { + mActorForChildren.SetSize( targetSize ); + } + if( mActorPostFilter ) + { + mActorPostFilter.SetSize( targetSize ); + } + + // Children render camera must move when EffectsView object is resized. + // This is since we cannot change render target size - so we need to remap the child actors' rendering + // accordingly so they still exactly fill the render target. + // Note that this means the effective resolution of the child render changes as the EffectsView object + // changes size, this is the trade off for not being able to modify render target size + // Change camera z position based on EffectsView actor height + if( mCameraForChildren ) + { + const float cameraPosScale( 0.5f / tanf(ARBITRARY_FIELD_OF_VIEW * 0.5f) ); + mCameraForChildren.SetZ( targetSize.height * cameraPosScale ); + } + + const size_t numFilters( mFilters.size() ); + for( size_t i = 0; i < numFilters; ++i ) + { + mFilters[i]->SetSize( mTargetSize ); + } + } void EffectsView::OnStageDisconnection() @@ -402,10 +449,10 @@ void EffectsView::AllocateResources() SetupCameras(); - mImageForChildren = FrameBufferImage::New( mTargetSize.width, mTargetSize.height, mPixelFormat, Dali::Image::Unused ); + mImageForChildren = FrameBufferImage::New( mTargetSize.width, mTargetSize.height, mPixelFormat, Dali::Image::UNUSED ); mActorForChildren.SetImage(mImageForChildren); - mImagePostFilter = FrameBufferImage::New( mTargetSize.width, mTargetSize.height, mPixelFormat, Dali::Image::Unused ); + mImagePostFilter = FrameBufferImage::New( mTargetSize.width, mTargetSize.height, mPixelFormat, Dali::Image::UNUSED ); mActorPostFilter.SetImage(mImagePostFilter); SetupFilters(); @@ -414,7 +461,7 @@ void EffectsView::AllocateResources() void EffectsView::SetupCameras() { - const float cameraPosConstraintScale( 0.5f / tanf(ARBITRARY_FIELD_OF_VIEW * 0.5f) ); + const float cameraPosScale( 0.5f / tanf(ARBITRARY_FIELD_OF_VIEW * 0.5f) ); // Create and place a camera for the children render, corresponding to its render target size mCameraForChildren.SetFieldOfView(ARBITRARY_FIELD_OF_VIEW); @@ -422,17 +469,8 @@ void EffectsView::SetupCameras() mCameraForChildren.SetNearClippingPlane(1.0f); mCameraForChildren.SetAspectRatio(mTargetSize.width / mTargetSize.height); mCameraForChildren.SetType(Dali::Camera::FREE_LOOK); // camera orientation based solely on actor - mCameraForChildren.SetPosition(0.0f, 0.0f, mTargetSize.height * cameraPosConstraintScale); - mCameraForChildren.SetRotation(Quaternion(M_PI, Vector3::YAXIS)); - - // Children render camera must move when EffectsView object is resized. - // This is since we cannot change render target size - so we need to remap the child actors' rendering - // accordingly so they still exactly fill the render target. - // Note that this means the effective resolution of the child render changes as the EffectsView object - // changes size, this is the trade off for not being able to modify render target size - // Change camera z position based on EffectsView actor height - mCameraForChildren.RemoveConstraints(); - mCameraForChildren.ApplyConstraint( Constraint::New( Actor::POSITION_Z, ParentSource( Actor::SIZE_HEIGHT ), RelativeToConstraintFloat(cameraPosConstraintScale) ) ); + mCameraForChildren.SetPosition(0.0f, 0.0f, mTargetSize.height * cameraPosScale); + mCameraForChildren.SetZ( mTargetSize.height * cameraPosScale ); } void EffectsView::CreateRenderTasks()