X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fshadow-view%2Fshadow-view-impl.cpp;h=f2fe0b9d8c26942c9bcaeec89f158926fbbaa812;hp=098e9ae4bdbfb0fcf84b26c7baf2b550bbd97059;hb=6275c8953b7908321d408a470b78c07383614b45;hpb=306d2f61a1b64179e801fa8a0bb2bd7b4e9dd682 diff --git a/dali-toolkit/internal/controls/shadow-view/shadow-view-impl.cpp b/dali-toolkit/internal/controls/shadow-view/shadow-view-impl.cpp index 098e9ae..f2fe0b9 100644 --- a/dali-toolkit/internal/controls/shadow-view/shadow-view-impl.cpp +++ b/dali-toolkit/internal/controls/shadow-view/shadow-view-impl.cpp @@ -21,8 +21,10 @@ // EXTERNAL INCLUDES #include #include +#include #include #include +#include #include #include @@ -67,8 +69,8 @@ BaseHandle Create() return Toolkit::ShadowView::New(); } -TypeRegistration mType( typeid(Toolkit::ShadowView), typeid(Toolkit::Control), Create ); - +DALI_TYPE_REGISTRATION_BEGIN( Toolkit::ShadowView, Toolkit::Control, Create ) +DALI_TYPE_REGISTRATION_END() const float BLUR_STRENGTH_DEFAULT = 1.0f; @@ -77,12 +79,11 @@ const float DEFAULT_FIELD_OF_VIEW_RADIANS = Math::PI / 4.0f; // 45 degrees const Vector4 DEFAULT_SHADOW_COLOR = Vector4(0.2f, 0.2f, 0.2f, 0.8f); -const std::string SHADER_LIGHT_CAMERA_PROJECTION_MATRIX_PROPERTY_NAME( "uLightCameraProjectionMatrix" ); -const std::string SHADER_LIGHT_CAMERA_VIEW_MATRIX_PROPERTY_NAME( "uLightCameraViewMatrix" ); -const std::string SHADER_SHADOW_COLOR_PROPERTY_NAME( "uShadowColor" ); - -const std::string BLUR_STRENGTH_PROPERTY_NAME( "BlurStrengthProperty" ); -const std::string SHADOW_COLOR_PROPERTY_NAME( "ShadowColorProperty" ); +const char* const SHADER_LIGHT_CAMERA_PROJECTION_MATRIX_PROPERTY_NAME = "uLightCameraProjectionMatrix"; +const char* const SHADER_LIGHT_CAMERA_VIEW_MATRIX_PROPERTY_NAME = "uLightCameraViewMatrix"; +const char* const SHADER_SHADOW_COLOR_PROPERTY_NAME = "uShadowColor"; +const char* const BLUR_STRENGTH_PROPERTY_NAME = "BlurStrengthProperty"; +const char* const SHADOW_COLOR_PROPERTY_NAME = "ShadowColorProperty"; const char* const RENDER_SHADOW_VERTEX_SOURCE = " uniform mediump mat4 uLightCameraProjectionMatrix;\n" @@ -104,23 +105,10 @@ const char* const RENDER_SHADOW_FRAGMENT_SOURCE = " gl_FragColor = vec4(uShadowColor.rgb, uShadowColor.a * alpha);\n" "}\n"; -// TODO: Add this to dali-core constraints.h -/** - * EqualToConstraintMatrix - * - * f(current, property) = property - */ -struct EqualToConstraintMatrix -{ - EqualToConstraintMatrix(){} - - Dali::Matrix operator()(const Dali::Matrix& current, const PropertyInput& property) {return property.GetMatrix();} -}; - } // namespace ShadowView::ShadowView( float downsampleWidthScale, float downsampleHeightScale ) -: Control( CONTROL_BEHAVIOUR_NONE ), +: Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ), mChildrenRoot(Actor::New()), mCachedShadowColor(DEFAULT_SHADOW_COLOR), mCachedBackgroundColor(DEFAULT_SHADOW_COLOR.r, DEFAULT_SHADOW_COLOR.g, DEFAULT_SHADOW_COLOR.b, 0.0f), @@ -166,6 +154,7 @@ void ShadowView::SetShadowPlane(Actor shadowPlane) mShadowPlaneBg = shadowPlane; mShadowPlane = ImageActor::New(); + mShadowPlane.SetName( "SHADOW_PLANE" ); mShadowPlane.SetParentOrigin(ParentOrigin::CENTER); mShadowPlane.SetAnchorPoint(AnchorPoint::CENTER); @@ -180,9 +169,9 @@ void ShadowView::SetShadowPlane(Actor shadowPlane) ConstrainCamera(); - mShadowPlane.ApplyConstraint( Constraint::New( Actor::SIZE, Source( mShadowPlaneBg, Actor::SIZE ), EqualToConstraint() ) ); + mShadowPlane.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mBlurRootActor.ApplyConstraint( Constraint::New( Actor::SIZE, Source( mShadowPlane, Actor::SIZE ), EqualToConstraint() ) ); + mBlurRootActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); } void ShadowView::SetPointLight(Actor pointLight) @@ -237,7 +226,7 @@ void ShadowView::OnInitialize() { // root actor to parent all user added actors. Used as source actor for shadow render task. mChildrenRoot.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION ); - mChildrenRoot.ApplyConstraint(Constraint::New( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() )); + mChildrenRoot.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); Vector2 stageSize = Stage::GetCurrent().GetSize(); mCameraActor = CameraActor::New(stageSize); @@ -247,7 +236,7 @@ void ShadowView::OnInitialize() // Target is constrained to point at the shadow plane origin mCameraActor.SetNearClippingPlane( 1.0f ); mCameraActor.SetType( Dali::Camera::FREE_LOOK ); // Camera orientation constrained to point at shadow plane world position - mCameraActor.SetRotation(Radian(Degree(180)), Vector3::YAXIS); + mCameraActor.SetOrientation(Radian(Degree(180)), Vector3::YAXIS); mCameraActor.SetPosition(DEFAULT_LIGHT_POSITION); mShadowRenderShader = ShaderEffect::New( RENDER_SHADOW_VERTEX_SOURCE, RENDER_SHADOW_FRAGMENT_SOURCE, @@ -272,10 +261,11 @@ void ShadowView::OnInitialize() mBlurFilter.SetPixelFormat(Pixel::RGBA8888); mBlurRootActor = Actor::New(); + mBlurRootActor.SetName( "BLUR_ROOT_ACTOR" ); // Turn off inheritance to ensure filter renders properly mBlurRootActor.SetPositionInheritanceMode(USE_PARENT_POSITION); - mBlurRootActor.SetInheritRotation(false); + mBlurRootActor.SetInheritOrientation(false); mBlurRootActor.SetInheritScale(false); mBlurRootActor.SetColorMode(USE_OWN_COLOR); @@ -291,20 +281,6 @@ void ShadowView::OnSizeSet(const Vector3& targetSize) { } -void ShadowView::OnStageConnection() -{ - // TODO: can't call this here, since SetImage() calls fail to connect images to stage, since parent chain not fully on stage yet - // Need to fix the stage connection so this callback can be used arbitrarily. At that point we can simplify the API by removing the need for Activate() / Deactivate() - //Activate(); -} - -void ShadowView::OnStageDisconnection() -{ - // TODO: can't call this here, since SetImage() calls fails similarly to above - // Need to fix the stage connection so this callback can be used arbitrarily. At that point we can simplify the API by removing the need for Activate() / Deactivate() - //Deactivate(); -} - void ShadowView::ConstrainCamera() { if( mPointLight && mShadowPlane ) @@ -312,18 +288,15 @@ void ShadowView::ConstrainCamera() // Constrain camera to look directly at center of shadow plane. (mPointLight position // is under control of application, can't use transform inheritance) - Constraint cameraOrientationConstraint = - Constraint::New ( Actor::ROTATION, - Source( mShadowPlane, Actor::WORLD_POSITION ), - Source( mPointLight, Actor::WORLD_POSITION ), - Source( mShadowPlane, Actor::WORLD_ROTATION ), - &LookAt ); + Constraint cameraOrientationConstraint = Constraint::New ( mCameraActor, Actor::Property::ORIENTATION, &LookAt ); + cameraOrientationConstraint.AddSource( Source( mShadowPlane, Actor::Property::WORLD_POSITION ) ); + cameraOrientationConstraint.AddSource( Source( mPointLight, Actor::Property::WORLD_POSITION ) ); + cameraOrientationConstraint.AddSource( Source( mShadowPlane, Actor::Property::WORLD_ORIENTATION ) ); + cameraOrientationConstraint.Apply(); - mCameraActor.ApplyConstraint( cameraOrientationConstraint ); - - Constraint pointLightPositionConstraint = Constraint::New( Actor::POSITION, Source( mPointLight, Actor::WORLD_POSITION ), EqualToConstraint() ); - - mCameraActor.ApplyConstraint( pointLightPositionConstraint ); + Constraint pointLightPositionConstraint = Constraint::New( mCameraActor, Actor::Property::POSITION, EqualToConstraint() ); + pointLightPositionConstraint.AddSource( Source( mPointLight, Actor::Property::WORLD_POSITION ) ); + pointLightPositionConstraint.Apply(); } } @@ -369,23 +342,29 @@ void ShadowView::SetShaderConstants() Property::Index lightCameraProjectionMatrixPropertyIndex = mShadowRenderShader.GetPropertyIndex(SHADER_LIGHT_CAMERA_PROJECTION_MATRIX_PROPERTY_NAME); Property::Index lightCameraViewMatrixPropertyIndex = mShadowRenderShader.GetPropertyIndex(SHADER_LIGHT_CAMERA_VIEW_MATRIX_PROPERTY_NAME); - Constraint projectionMatrixConstraint = Constraint::New( lightCameraProjectionMatrixPropertyIndex, Source( mCameraActor, CameraActor::PROJECTION_MATRIX ), EqualToConstraintMatrix()); - Constraint viewMatrixConstraint = Constraint::New( lightCameraViewMatrixPropertyIndex, Source( mCameraActor, CameraActor::VIEW_MATRIX ), EqualToConstraintMatrix()); + Constraint projectionMatrixConstraint = Constraint::New( mShadowRenderShader, lightCameraProjectionMatrixPropertyIndex, EqualToConstraint() ); + projectionMatrixConstraint.AddSource( Source( mCameraActor, CameraActor::Property::PROJECTION_MATRIX ) ); - mShadowRenderShader.ApplyConstraint(projectionMatrixConstraint); - mShadowRenderShader.ApplyConstraint(viewMatrixConstraint); + Constraint viewMatrixConstraint = Constraint::New( mShadowRenderShader, lightCameraViewMatrixPropertyIndex, EqualToConstraint() ); + viewMatrixConstraint.AddSource( Source( mCameraActor, CameraActor::Property::VIEW_MATRIX ) ); + + projectionMatrixConstraint.Apply(); + viewMatrixConstraint.Apply(); // Register a property that the user can use to control the blur in the internal object mBlurStrengthPropertyIndex = self.RegisterProperty(BLUR_STRENGTH_PROPERTY_NAME, BLUR_STRENGTH_DEFAULT); - mBlurFilter.GetHandleForAnimateBlurStrength().ApplyConstraint( Constraint::New( mBlurFilter.GetBlurStrengthPropertyIndex() , - Source( self, mBlurStrengthPropertyIndex), - EqualToConstraint()) ); + + Constraint blurStrengthConstraint = Constraint::New( mBlurFilter.GetHandleForAnimateBlurStrength(), mBlurFilter.GetBlurStrengthPropertyIndex(), EqualToConstraint() ); + blurStrengthConstraint.AddSource( Source( self, mBlurStrengthPropertyIndex) ); + blurStrengthConstraint.Apply(); // Register a property that the user can use to control the color of the shadow. Property::Index index = mShadowRenderShader.GetPropertyIndex(SHADER_SHADOW_COLOR_PROPERTY_NAME); mShadowColorPropertyIndex = self.RegisterProperty(SHADOW_COLOR_PROPERTY_NAME, mCachedShadowColor); - mShadowRenderShader.ApplyConstraint(Constraint::New( index, Source( self, mShadowColorPropertyIndex ), EqualToConstraint()) ); + Constraint shadowRenderShaderConstraint = Constraint::New( mShadowRenderShader, index, EqualToConstraint() ); + shadowRenderShaderConstraint.AddSource( Source( self, mShadowColorPropertyIndex ) ); + shadowRenderShaderConstraint.Apply(); } } // namespace Internal