void Magnifier::SetFrameVisibility(bool visible) { if(visible && !mFrameLayer) { 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); } else if(!visible && mFrameLayer) { Stage::GetCurrent().Remove(mFrameLayer); mFrameLayer.Reset(); } }
void View::SetBackground( ImageActor backgroundImage ) { // Create background layer if doesn't exist. if( !mBackgroundLayer ) { mBackgroundLayer = Layer::New(); mBackgroundLayer.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION ); mBackgroundLayer.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); // Add background layer to custom actor. Self().Add( mBackgroundLayer ); // Drop the background layer DALI_ASSERT_ALWAYS( mBackgroundLayer.OnStage() ); // We need to be on-stage to drop the layer mBackgroundLayer.LowerToBottom(); } else { // It removes the old background if( 0 < mBackgroundLayer.GetChildCount() ) { mBackgroundLayer.Remove( mBackgroundLayer.GetChildAt(0) ); } } backgroundImage.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION ); Constraint constraint = Constraint::New<Vector3>( Actor::SCALE, LocalSource( Actor::SIZE ), ParentSource( Actor::SIZE ), ScaleToFillXYKeepAspectRatioConstraint() ); backgroundImage.ApplyConstraint( constraint ); mBackgroundLayer.Add( backgroundImage ); }