X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=optional%2Fdali-toolkit%2Finternal%2Fcontrols%2Fmagnifier%2Fmagnifier-impl.cpp;h=2bfd96ae7f8626a76969976530a833443c9f0e80;hb=e6bf46a6c76b0000dd5174ae406cc62ca8f5d9c2;hp=978324025aa562723d470e142f7aea6b2fe7848e;hpb=d5e3ed5f5b1c8fdba3ae97ead8729620f54b3836;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/optional/dali-toolkit/internal/controls/magnifier/magnifier-impl.cpp b/optional/dali-toolkit/internal/controls/magnifier/magnifier-impl.cpp index 9783240..2bfd96a 100644 --- a/optional/dali-toolkit/internal/controls/magnifier/magnifier-impl.cpp +++ b/optional/dali-toolkit/internal/controls/magnifier/magnifier-impl.cpp @@ -15,8 +15,14 @@ * */ +// CLASS HEADER #include +// EXTERNAL INCLUDES +#include +#include +#include + using namespace Dali; namespace // unnamed namespace @@ -115,22 +121,6 @@ struct RenderTaskViewportSizeConstraint } }; -/** - * Returns relative border (0.0f...1.0f x 0.0f...1.0f) - * from an absolute pixel specified border. - * @param[in] absolute A border using absolute pixel coordinates - * @param[in] width The width of the texture - * @param[in] height The height of the texture. - * @return A border relative to the size of the Image texture dimensions. - */ -Vector4 GetRelativeBorder(Vector4 absolute, float width, float height) -{ - return Vector4( absolute.x / width, - absolute.y / height, - absolute.z / width, - absolute.w / height); -} - } namespace Dali @@ -164,6 +154,7 @@ Dali::Toolkit::Magnifier Magnifier::New() Magnifier::Magnifier() : Control( REQUIRES_TOUCH_EVENTS ), mPropertySourcePosition(Property::INVALID_INDEX), + mDefaultCameraDistance(1000.f), mActorSize(Vector3::ZERO), mMagnificationFactor(1.0f) { @@ -185,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. @@ -200,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( Actor::POSITION, Source( self, mPropertySourcePosition ), @@ -235,8 +222,8 @@ void Magnifier::Initialize() //Property::Index propertySourcePositionDelayed = mCameraActor.RegisterProperty("delayed-source-position", Vector3::ZERO); constraint = Constraint::New( Actor::POSITION, - Source( mSourceActor, Actor::WORLD_POSITION ), - CameraActorPositionConstraint(stageSize, mDefaultCameraDistance) ); + Source( mSourceActor, Actor::WORLD_POSITION ), + CameraActorPositionConstraint(stageSize, mDefaultCameraDistance) ); mCameraActor.ApplyConstraint(constraint); // Apply constraint to render-task viewport position @@ -283,56 +270,47 @@ 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); + mFrame = ImageActor::New( image ); + mFrame.SetDrawMode(DrawMode::OVERLAY); + mFrame.SetStyle( ImageActor::STYLE_NINE_PATCH ); + mFrame.SetPositionInheritanceMode(DONT_INHERIT_POSITION); + mFrame.SetInheritScale(true); - // Apply position constraint to the frame Constraint constraint = Constraint::New( Actor::POSITION, - Source( self, Actor::WORLD_POSITION ), - EqualToConstraint() ); - frame.ApplyConstraint(constraint); - - // Apply scale constraint to the frame - constraint = Constraint::New( Actor::SCALE, - Source( self, Actor::SCALE ), - EqualToConstraint() ); - frame.ApplyConstraint(constraint); - - Source(self, Actor::SCALE), - - // Apply size constraint to the the frame - constraint = Constraint::New(Actor::SIZE, - Source(self, Actor::SIZE), - ImageBorderSizeConstraint()); - frame.ApplyConstraint(constraint); + ParentSource(Actor::WORLD_POSITION), + EqualToConstraint()); + mFrame.ApplyConstraint( constraint ); + + 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