Remove constaints from BloomView, GaussianBlurView & Magnifier 54/34854/3 accepted/tizen/common/20150209.121015 accepted/tizen/mobile/20150211.014648 accepted/tizen/tv/20150210.012936 accepted/tizen/wearable/20150210.014752 submit/tizen/20150206.044231
authorXiangyin Ma <x1.ma@samsung.com>
Tue, 3 Feb 2015 13:20:56 +0000 (13:20 +0000)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Thu, 5 Feb 2015 16:13:11 +0000 (08:13 -0800)
Change-Id: Ie4dbec178de2c6644fddd459e5d6acd21f26ae7a

optional/dali-toolkit/internal/controls/bloom-view/bloom-view-impl.cpp
optional/dali-toolkit/internal/controls/gaussian-blur-view/gaussian-blur-view-impl.cpp
optional/dali-toolkit/internal/controls/magnifier/magnifier-impl.cpp
optional/dali-toolkit/internal/controls/magnifier/magnifier-impl.h

index df4f828..097097f 100644 (file)
@@ -224,8 +224,6 @@ void BloomView::OnInitialize()
 {
   // root actor to parent all user added actors, needed to allow us to set that subtree as exclusive for our child render task
   mChildrenRoot.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION );
-  mChildrenRoot.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); // same size as BloomView object
-
 
   //////////////////////////////////////////////////////
   // Create shaders
@@ -249,14 +247,12 @@ void BloomView::OnInitialize()
   // Create an ImageActor for compositing the result (scene and bloom textures) to output
   mCompositeImageActor = ImageActor::New();
   mCompositeImageActor.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION );
-  mCompositeImageActor.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); // same size as BloomView object
   mCompositeImageActor.SetShaderEffect( mCompositeShader );
   mCompositeImageActor.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) ); // FIXME
 
   // Create an ImageActor for holding final result, i.e. the blurred image. This will get rendered to screen later, via default / user render task
   mTargetImageActor = ImageActor::New();
   mTargetImageActor.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION );
-  mTargetImageActor.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); // same size as BloomView object
   mTargetImageActor.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) ); // FIXME
 
 
@@ -291,35 +287,22 @@ void BloomView::OnInitialize()
   SetupProperties();
 }
 
-/**
- * ZrelativeToYconstraint
- *
- * f(current, property, scale) = Vector3(current.x, current.y, property.y * scale)
- */
-struct ZrelativeToYconstraint
-{
-  ZrelativeToYconstraint( float scale )
-    : mScale( scale )
-  {}
-
-  Vector3 operator()(const Vector3&    current,
-                     const PropertyInput& property)
-  {
-    Vector3 v;
-
-    v.x = current.x;
-    v.y = current.y;
-    v.z = property.GetVector3().y * mScale;
-
-    return v;
-  }
-
-  float mScale;
-};
-
 void BloomView::OnControlSizeSet(const Vector3& targetSize)
 {
   mTargetSize = Vector2(targetSize);
+  mChildrenRoot.SetSize(targetSize);
+  mCompositeImageActor.SetSize(targetSize);
+  mTargetImageActor.SetSize(targetSize);
+
+  // Children render camera must move when GaussianBlurView 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 GaussianBlurView object changes size,
+  // this is the trade off for not being able to modify render target size
+  // Change camera z position based on GaussianBlurView actor height
+  float cameraPosConstraintScale = 0.5f / tanf(ARBITRARY_FIELD_OF_VIEW * 0.5f);
+  mRenderFullSizeCamera.SetZ( mTargetSize.height * cameraPosConstraintScale);
 
   // if we are already on stage, need to update render target sizes now to reflect the new size of this actor
   if(Self().OnStage())
@@ -364,19 +347,6 @@ void BloomView::AllocateResources()
     float cameraPosConstraintScale = 0.5f / tanf(ARBITRARY_FIELD_OF_VIEW * 0.5f);
     mRenderFullSizeCamera.SetPosition(0.0f, 0.0f, mTargetSize.height * cameraPosConstraintScale);
 
-
-    // Children render camera must move when GaussianBlurView 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 GaussianBlurView object changes size,
-    // this is the trade off for not being able to modify render target size
-    // Change camera z position based on GaussianBlurView actor height
-
-    mRenderFullSizeCamera.RemoveConstraints();
-    mRenderFullSizeCamera.ApplyConstraint( Constraint::New<Vector3>( Actor::POSITION, ParentSource( Actor::SIZE ), ZrelativeToYconstraint(cameraPosConstraintScale) ) );
-
-
     //////////////////////////////////////////////////////
     // Pass size change onto GaussianBlurView, so it matches
     mGaussianBlurView.SetSize(mTargetSize);
index 0aed88f..2b993e9 100644 (file)
@@ -256,8 +256,6 @@ void GaussianBlurView::OnInitialize()
 {
   // root actor to parent all user added actors, needed to allow us to set that subtree as exclusive for our child render task
   mChildrenRoot.SetParentOrigin(ParentOrigin::CENTER);
-  mChildrenRoot.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); // same size as GaussianBlurView object
-
 
   //////////////////////////////////////////////////////
   // Create shaders
@@ -297,7 +295,6 @@ void GaussianBlurView::OnInitialize()
   {
     mImageActorComposite = ImageActor::New();
     mImageActorComposite.SetParentOrigin(ParentOrigin::CENTER);
-    mImageActorComposite.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); // same size as GaussianBlurView object
     mImageActorComposite.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) ); // FIXME
     mImageActorComposite.SetOpacity(GAUSSIAN_BLUR_VIEW_DEFAULT_BLUR_STRENGTH); // ensure alpha is enabled for this object and set default value
 
@@ -307,7 +304,6 @@ void GaussianBlurView::OnInitialize()
     // Create an ImageActor for holding final result, i.e. the blurred image. This will get rendered to screen later, via default / user render task
     mTargetActor = ImageActor::New();
     mTargetActor.SetParentOrigin(ParentOrigin::CENTER);
-    mTargetActor.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); // same size as GaussianBlurView object
     mTargetActor.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) ); // FIXME
 
 
@@ -370,6 +366,22 @@ void GaussianBlurView::OnControlSizeSet(const Vector3& targetSize)
 {
   mTargetSize = Vector2(targetSize);
 
+  mChildrenRoot.SetSize(targetSize);
+
+  if( !mBlurUserImage )
+  {
+    mImageActorComposite.SetSize(targetSize);
+    mTargetActor.SetSize(targetSize);
+
+    // Children render camera must move when GaussianBlurView 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 GaussianBlurView object changes
+    // size, this is the trade off for not being able to modify render target size
+    // Change camera z position based on GaussianBlurView actor height
+    float cameraPosConstraintScale = 0.5f / tanf(ARBITRARY_FIELD_OF_VIEW * 0.5f);
+    mRenderFullSizeCamera.SetZ(mTargetSize.height * cameraPosConstraintScale);
+  }
+
+
   // if we are already on stage, need to update render target sizes now to reflect the new size of this actor
   if(Self().OnStage())
   {
@@ -414,13 +426,6 @@ void GaussianBlurView::AllocateResources()
       float cameraPosConstraintScale = 0.5f / tanf(ARBITRARY_FIELD_OF_VIEW * 0.5f);
       mRenderFullSizeCamera.SetPosition(0.0f, 0.0f, mTargetSize.height * cameraPosConstraintScale);
 
-      // Children render camera must move when GaussianBlurView 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 GaussianBlurView object changes
-      // size, this is the trade off for not being able to modify render target size
-      // Change camera z position based on GaussianBlurView actor height
-      mRenderFullSizeCamera.RemoveConstraints();
-      mRenderFullSizeCamera.ApplyConstraint( Constraint::New<Vector3>( Actor::POSITION, ParentSource( Actor::SIZE ), ZrelativeToYconstraint(cameraPosConstraintScale) ) );
-
       // create offscreen buffer of new size to render our child actors to
       mRenderTargetForRenderingChildren = FrameBufferImage::New( mTargetSize.width, mTargetSize.height, mPixelFormat, Dali::Image::Unused );
 
index 0cf34a0..5f9139c 100644 (file)
@@ -19,7 +19,6 @@
 #include <dali-toolkit/internal/controls/magnifier/magnifier-impl.h>
 
 // EXTERNAL INCLUDES
-#include <dali/public-api/actors/image-actor.h>
 #include <dali/public-api/animation/constraints.h>
 #include <dali/public-api/common/stage.h>
 #include <dali/public-api/render-tasks/render-task-list.h>
@@ -177,10 +176,6 @@ void Magnifier::Initialize()
   mPropertySourcePosition = self.RegisterProperty( Toolkit::Magnifier::SOURCE_POSITION_PROPERTY_NAME, Vector3::ZERO );
   Vector2 stageSize(Stage::GetCurrent().GetSize());
 
-  Layer dummyLayer = Layer::New();
-  Stage().GetCurrent().Add(dummyLayer);
-  dummyLayer.SetParentOrigin(ParentOrigin::CENTER);
-
   // NOTE:
   // sourceActor is a dummy delegate actor that takes the source property position,
   // and generates a WORLD_POSITION, which is 1 frame behind the source property.
@@ -192,7 +187,7 @@ void Magnifier::Initialize()
   // Perhaps this is a bug in the way the constraint system factors into what is dirty
   // and what is not.
   mSourceActor = Actor::New();
-  dummyLayer.Add(mSourceActor);
+  Stage().GetCurrent().Add(mSourceActor);
   mSourceActor.SetParentOrigin(ParentOrigin::CENTER);
   Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
                                                     Source( self, mPropertySourcePosition ),
@@ -275,56 +270,42 @@ void Magnifier::InitializeRenderTask()
 
 bool Magnifier::GetFrameVisibility() const
 {
-  return mFrameLayer;
+  return mFrame;
 }
 
 void Magnifier::SetFrameVisibility(bool visible)
 {
-  if(visible && !mFrameLayer)
+  if(visible && !mFrame)
   {
     Actor self(Self());
 
-    Layer mFrameLayer = Layer::New();
-    mFrameLayer.SetParentOrigin( ParentOrigin::CENTER );
-    Stage::GetCurrent().Add(mFrameLayer);
-
     Image image = Image::New( DEFAULT_FRAME_IMAGE_PATH );
-    ImageActor frame = ImageActor::New( image );
-    frame.SetDrawMode(DrawMode::OVERLAY);
-    frame.SetStyle( ImageActor::STYLE_NINE_PATCH );
-
-    frame.SetNinePatchBorder( Vector4::ONE * IMAGE_BORDER_INDENT );
-    mFrameLayer.Add(frame);
-
-    // Apply position constraint to the frame
-    Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
-                                                      Source( self, Actor::WORLD_POSITION ),
-                                                      EqualToConstraint() );
-    frame.ApplyConstraint(constraint);
-
-    // Apply scale constraint to the frame
-    constraint = Constraint::New<Vector3>( Actor::SCALE,
-                                           Source( self, Actor::SCALE ),
-                                           EqualToConstraint() );
-    frame.ApplyConstraint(constraint);
-
-    Source(self, Actor::SCALE),
-
-    // Apply size constraint to the the frame
-    constraint = Constraint::New<Vector3>(Actor::SIZE,
-                                          Source(self, Actor::SIZE),
-                                          ImageBorderSizeConstraint());
-    frame.ApplyConstraint(constraint);
+    mFrame = ImageActor::New( image );
+    mFrame.SetDrawMode(DrawMode::OVERLAY);
+    mFrame.SetStyle( ImageActor::STYLE_NINE_PATCH );
+    mFrame.SetPositionInheritanceMode(USE_PARENT_POSITION);
+    mFrame.SetInheritScale(true);
+
+    mFrame.SetNinePatchBorder( Vector4::ONE * IMAGE_BORDER_INDENT );
+    self.Add(mFrame);
+
+    Vector3 sizeOffset(IMAGE_BORDER_INDENT*2.f - 2.f, IMAGE_BORDER_INDENT*2.f - 2.f, 0.0f);
+    mFrame.SetSize(mActorSize + sizeOffset);
   }
-  else if(!visible && mFrameLayer)
+  else if(!visible && mFrame)
   {
-    Stage::GetCurrent().Remove(mFrameLayer);
-    mFrameLayer.Reset();
+    UnparentAndReset(mFrame);
   }
 }
 
 void Magnifier::OnControlSizeSet(const Vector3& targetSize)
 {
+  if( mFrame )
+  {
+    Vector3 sizeOffset(IMAGE_BORDER_INDENT*2.f - 2.f, IMAGE_BORDER_INDENT*2.f - 2.f, 0.0f);
+    mFrame.SetSize(targetSize + sizeOffset);
+  }
+
   // TODO: Once Camera/CameraActor properties function as proper animatable properties
   // this code can disappear.
   // whenever the size of the magnifier changes, the field of view needs to change
index f0c9133..4def324 100644 (file)
@@ -22,6 +22,7 @@
 #include <dali/public-api/actors/camera-actor.h>
 #include <dali/public-api/actors/layer.h>
 #include <dali/public-api/render-tasks/render-task.h>
+#include <dali/public-api/actors/image-actor.h>
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/public-api/controls/control-impl.h>
@@ -130,7 +131,7 @@ private:
 
   RenderTask mTask;                             ///< Render Task to render the source actor contents.
   CameraActor mCameraActor;                     ///< CameraActor attached to RenderTask
-  Layer mFrameLayer;                            ///< Frame is placed on separate layer added to stage.
+  ImageActor mFrame;                            ///< The Magnifier Frame
   Property::Index mPropertySourcePosition;      ///< Source Position ("source-position")
   Actor mSourceActor;                           ///< Source Delegate Actor represents the source position to read.
   float mDefaultCameraDistance;                 ///< Default RenderTask's camera distance from target.