/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
#include <dali-toolkit/internal/controls/magnifier/magnifier-impl.h>
// EXTERNAL INCLUDES
-#include <dali/public-api/animation/active-constraint.h>
+#include <dali/devel-api/common/stage.h>
#include <dali/public-api/animation/constraint.h>
#include <dali/public-api/animation/constraints.h>
-#include <dali/public-api/common/stage.h>
+#include <dali/public-api/object/property-map.h>
+#include <dali/public-api/object/type-registry-helper.h>
+#include <dali/public-api/object/type-registry.h>
#include <dali/public-api/render-tasks/render-task-list.h>
-#include <dali/public-api/images/resource-image.h>
-using namespace Dali;
+// INTERNAL INCLUDES
+#include <dali-toolkit/devel-api/controls/control-devel.h>
+#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
+#include <dali-toolkit/internal/controls/control/control-data-impl.h>
+#include <dali-toolkit/internal/visuals/visual-factory-impl.h>
+#include <dali-toolkit/public-api/visuals/border-visual-properties.h>
+#include <dali-toolkit/public-api/visuals/visual-properties.h>
+namespace Dali
+{
+namespace Toolkit
+{
+namespace Internal
+{
namespace // unnamed namespace
{
+Dali::BaseHandle Create()
+{
+ return Toolkit::Magnifier::New();
+}
-const char* DEFAULT_FRAME_IMAGE_PATH = DALI_IMAGE_DIR "magnifier-image-frame.png";
-
-const float IMAGE_BORDER_INDENT = 14.0f; ///< Indent of border in pixels.
+// clang-format off
+DALI_TYPE_REGISTRATION_BEGIN(Toolkit::Magnifier, Toolkit::Control, Create)
-/**
- * ImageBorderSizeConstraint
- */
-struct ImageBorderSizeConstraint
-{
- ImageBorderSizeConstraint()
- : mSizeOffset(Vector3(IMAGE_BORDER_INDENT - 1, IMAGE_BORDER_INDENT - 1, 0.0f) * 2.0f)
- {
- }
+DALI_PROPERTY_REGISTRATION(Toolkit, Magnifier, "frameVisibility", BOOLEAN, FRAME_VISIBILITY )
+DALI_PROPERTY_REGISTRATION(Toolkit, Magnifier, "magnificationFactor", FLOAT, MAGNIFICATION_FACTOR)
- Vector3 operator()(const Vector3& current,
- const PropertyInput& referenceSizeProperty)
- {
- const Vector3& referenceSize = referenceSizeProperty.GetVector3();
+DALI_ANIMATABLE_PROPERTY_REGISTRATION(Toolkit, Magnifier, "sourcePosition", VECTOR3, SOURCE_POSITION)
- return referenceSize + mSizeOffset;
- }
+DALI_TYPE_REGISTRATION_END()
+// clang-format on
- Vector3 mSizeOffset; ///< The amount to offset the size from referenceSize
-};
+const float IMAGE_BORDER_INDENT = 5.0f; ///< Indent of border in pixels.
struct CameraActorPositionConstraint
{
{
}
- Vector3 operator()(const Vector3& current,
- const PropertyInput& sourcePositionProperty)
+ void operator()(Vector3& current, const PropertyInputContainer& inputs)
{
- const Vector3& sourcePosition = sourcePositionProperty.GetVector3();
+ const Vector3& sourcePosition = inputs[0]->GetVector3();
- return Vector3( sourcePosition.x + mStageSize.x * 0.5f,
- sourcePosition.y + mStageSize.y * 0.5f,
- sourcePosition.z + mDefaultCameraDistance);
+ current.x = sourcePosition.x + mStageSize.x * 0.5f;
+ current.y = sourcePosition.y + mStageSize.y * 0.5f;
+ current.z = sourcePosition.z + mDefaultCameraDistance;
}
Vector2 mStageSize;
- float mDefaultCameraDistance;
-
+ float mDefaultCameraDistance;
};
struct RenderTaskViewportPositionConstraint
{
}
- Vector2 operator()(const Vector2& current,
- const PropertyInput& positionProperty,
- const PropertyInput& magnifierSizeProperty,
- const PropertyInput& magnifierScaleProperty)
+ void operator()(Vector2& current, const PropertyInputContainer& inputs)
{
- Vector2 position(positionProperty.GetVector3()); // World position?
-
- //position -= mStageSize * 0.5f;
+ current = inputs[0]->GetVector3(); // World position?
// should be updated when:
// Magnifier's world position/size/scale/parentorigin/anchorpoint changes.
// or Magnifier camera's world position changes.
- Vector3 size = magnifierSizeProperty.GetVector3() * magnifierScaleProperty.GetVector3();
+ Vector3 size = inputs[1]->GetVector3() * inputs[2]->GetVector3(); /* magnifier-size * magnifier-scale */
// Reposition, and resize viewport to reflect the world bounds of this Magnifier actor.
- position.x += (mStageSize.width - size.width) * 0.5f;
- position.y += (mStageSize.height - size.height) * 0.5f;
-
- return position;
+ current.x += (mStageSize.width - size.width) * 0.5f;
+ current.y += (mStageSize.height - size.height) * 0.5f;
}
Vector2 mStageSize;
{
}
- Vector2 operator()(const Vector2& current,
- const PropertyInput& magnifierSizeProperty,
- const PropertyInput& magnifierScaleProperty)
+ void operator()(Vector2& current, const PropertyInputContainer& inputs)
{
- return Vector2(magnifierSizeProperty.GetVector3() * magnifierScaleProperty.GetVector3());
+ current = inputs[0]->GetVector3() * inputs[1]->GetVector3(); /* magnifier-size * magnifier-scale */
}
};
-}
-
-namespace Dali
-{
-
-namespace Toolkit
-{
-
-namespace Internal
-{
+} // unnamed namespace
///////////////////////////////////////////////////////////////////////////////////////////////////
// Magnifier
}
Magnifier::Magnifier()
-: Control( REQUIRES_TOUCH_EVENTS ),
- mPropertySourcePosition(Property::INVALID_INDEX),
+: Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
mDefaultCameraDistance(1000.f),
mActorSize(Vector3::ZERO),
mMagnificationFactor(1.0f)
void Magnifier::SetSourceActor(Actor actor)
{
- mTask.SetSourceActor( actor );
-}
-
-void Magnifier::SetSourcePosition(const Vector3& position)
-{
- Self().SetProperty(mPropertySourcePosition, position);
+ mTask.SetSourceActor(actor);
}
void Magnifier::Initialize()
{
- Actor self = Self();
- mPropertySourcePosition = self.RegisterProperty( Toolkit::Magnifier::SOURCE_POSITION_PROPERTY_NAME, Vector3::ZERO );
+ Actor self = Self();
Vector2 stageSize(Stage::GetCurrent().GetSize());
// NOTE:
// and what is not.
mSourceActor = Actor::New();
Stage().GetCurrent().Add(mSourceActor);
- mSourceActor.SetParentOrigin(ParentOrigin::CENTER);
- Constraint constraint = Constraint::New<Vector3>( Actor::Property::POSITION,
- Source( self, mPropertySourcePosition ),
- EqualToConstraint() );
- mSourceActor.ApplyConstraint(constraint);
+ mSourceActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
+ Constraint constraint = Constraint::New<Vector3>(mSourceActor, Actor::Property::POSITION, EqualToConstraint());
+ constraint.AddSource(Source(self, Toolkit::Magnifier::Property::SOURCE_POSITION));
+ constraint.Apply();
// create the render task this will render content on top of everything
// based on camera source position.
// But we can determine the initial position using the same formula:
// distance = stage.height * 0.5 / tan(FOV * 0.5)
- RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
- RenderTask renderTask = taskList.GetTask(0u);
- float fov = renderTask.GetCameraActor().GetFieldOfView();
- mDefaultCameraDistance = (stageSize.height * 0.5f) / tanf(fov * 0.5f);
+ RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
+ RenderTask renderTask = taskList.GetTask(0u);
+ float fov = renderTask.GetCameraActor().GetFieldOfView();
+ mDefaultCameraDistance = (stageSize.height * 0.5f) / tanf(fov * 0.5f);
// Use a 1 frame delayed source position to determine the camera actor's position.
// This is necessary as the viewport is determined by the Magnifier's Actor's World position (which is computed
// at the end of the update cycle i.e. after constraints have been applied.)
- //Property::Index propertySourcePositionDelayed = mCameraActor.RegisterProperty("delayed-source-position", Vector3::ZERO);
+ //Property::Index propertySourcePositionDelayed = mCameraActor.RegisterProperty("delayedSourcePosition", Vector3::ZERO);
- constraint = Constraint::New<Vector3>( Actor::Property::POSITION,
- Source( mSourceActor, Actor::Property::WORLD_POSITION ),
- CameraActorPositionConstraint(stageSize, mDefaultCameraDistance) );
- mCameraActor.ApplyConstraint(constraint);
+ constraint = Constraint::New<Vector3>(mCameraActor, Actor::Property::POSITION, CameraActorPositionConstraint(stageSize, mDefaultCameraDistance));
+ constraint.AddSource(Source(mSourceActor, Actor::Property::WORLD_POSITION));
+ constraint.Apply();
// Apply constraint to render-task viewport position
- constraint = Constraint::New<Vector2>( RenderTask::Property::VIEWPORT_POSITION,
- Source( self, Actor::Property::WORLD_POSITION ),//mPropertySourcePosition ),
- Source( self, Actor::Property::SIZE ),
- Source( self, Actor::Property::WORLD_SCALE ),
- RenderTaskViewportPositionConstraint(stageSize) );
- mTask.ApplyConstraint(constraint);
+ constraint = Constraint::New<Vector2>(mTask, RenderTask::Property::VIEWPORT_POSITION, RenderTaskViewportPositionConstraint(stageSize));
+ constraint.AddSource(Source(self, Actor::Property::WORLD_POSITION));
+ constraint.AddSource(Source(self, Actor::Property::SIZE));
+ constraint.AddSource(Source(self, Actor::Property::WORLD_SCALE));
+ constraint.Apply();
// Apply constraint to render-task viewport position
- constraint = Constraint::New<Vector2>( RenderTask::Property::VIEWPORT_SIZE,
- Source( self, Actor::Property::SIZE ),
- Source( self, Actor::Property::WORLD_SCALE ),
- RenderTaskViewportSizeConstraint() );
- mTask.ApplyConstraint(constraint);
+ constraint = Constraint::New<Vector2>(mTask, RenderTask::Property::VIEWPORT_SIZE, RenderTaskViewportSizeConstraint());
+ constraint.AddSource(Source(self, Actor::Property::SIZE));
+ constraint.AddSource(Source(self, Actor::Property::WORLD_SCALE));
+ constraint.Apply();
+
+ self.SetProperty(DevelControl::Property::ACCESSIBILITY_ROLE, Dali::Accessibility::Role::FILLER);
}
Magnifier::~Magnifier()
{
-
}
void Magnifier::InitializeRenderTask()
mCameraActor.SetType(Camera::FREE_LOOK);
stage.Add(mCameraActor);
- mTask.SetCameraActor( mCameraActor );
+ mTask.SetCameraActor(mCameraActor);
SetFrameVisibility(true);
}
bool Magnifier::GetFrameVisibility() const
{
- return mFrame;
+ return static_cast<bool>(mFrame);
}
void Magnifier::SetFrameVisibility(bool visible)
{
Actor self(Self());
- Image image = ResourceImage::New( DEFAULT_FRAME_IMAGE_PATH );
- mFrame = ImageActor::New( image );
- mFrame.SetDrawMode(DrawMode::OVERLAY);
- mFrame.SetStyle( ImageActor::STYLE_NINE_PATCH );
- mFrame.SetPositionInheritanceMode(DONT_INHERIT_POSITION);
- mFrame.SetInheritScale(true);
+ mFrame = Actor::New();
+ mFrame.SetProperty(Actor::Property::INHERIT_POSITION, false);
+ mFrame.SetProperty(Actor::Property::INHERIT_SCALE, true);
+ mFrame.SetResizePolicy(ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS);
+ Vector3 sizeOffset(IMAGE_BORDER_INDENT * 2.f - 2.f, IMAGE_BORDER_INDENT * 2.f - 2.f, 0.0f);
+ mFrame.SetProperty(Actor::Property::SIZE_MODE_FACTOR, sizeOffset);
- Constraint constraint = Constraint::New<Vector3>( Actor::Property::POSITION,
- ParentSource( Actor::Property::WORLD_POSITION ),
- EqualToConstraint() );
- mFrame.ApplyConstraint( constraint );
+ Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get();
- mFrame.SetNinePatchBorder( Vector4::ONE * IMAGE_BORDER_INDENT );
- self.Add(mFrame);
+ Property::Map map;
+ map[Toolkit::Visual::Property::TYPE] = Toolkit::Visual::BORDER;
+ map[Toolkit::BorderVisual::Property::COLOR] = Color::WHITE;
+ map[Toolkit::BorderVisual::Property::SIZE] = IMAGE_BORDER_INDENT;
+ Toolkit::Visual::Base borderVisual = visualFactory.CreateVisual(map);
+ Toolkit::GetImplementation(borderVisual).SetOnScene(mFrame);
- Vector3 sizeOffset(IMAGE_BORDER_INDENT*2.f - 2.f, IMAGE_BORDER_INDENT*2.f - 2.f, 0.0f);
- mFrame.SetSize(mActorSize + sizeOffset);
+ Constraint constraint = Constraint::New<Vector3>(mFrame, Actor::Property::POSITION, EqualToConstraint());
+ constraint.AddSource(ParentSource(Actor::Property::WORLD_POSITION));
+ constraint.Apply();
+
+ self.Add(mFrame);
}
else if(!visible && mFrame)
{
}
}
-void Magnifier::OnControlSizeSet(const Vector3& targetSize)
+void Magnifier::OnSizeSet(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
// a constraint yet as Camera/CameraActor properties are not animatable/constrainable.
mActorSize = targetSize;
Update();
+
+ Control::OnSizeSet(targetSize);
}
float Magnifier::GetMagnificationFactor() const
// should be updated when:
// Magnifier's world size/scale changes.
- Actor self(Self());
- Vector3 worldSize = mActorSize * self.GetCurrentWorldScale();
+ Actor self(Self());
+ Vector3 worldSize = mActorSize * self.GetCurrentProperty<Vector3>(Actor::Property::WORLD_SCALE);
// Adjust field of view to scale content
// |./
// |/ <--- fov/2 radians.
//
- const float fov = atanf( 0.5f * worldSize.height / mDefaultCameraDistance / mMagnificationFactor) * 2.0f;
- mCameraActor.SetFieldOfView( fov );
+ const float fov = atanf(0.5f * worldSize.height / mDefaultCameraDistance / mMagnificationFactor) * 2.0f;
+ mCameraActor.SetFieldOfView(fov);
// Adjust aspect ratio to compensate for rectangular viewports.
- mCameraActor.SetAspectRatio( worldSize.width / worldSize.height );
+ mCameraActor.SetAspectRatio(worldSize.width / worldSize.height);
+}
+
+void Magnifier::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
+{
+ Toolkit::Magnifier magnifier = Toolkit::Magnifier::DownCast(Dali::BaseHandle(object));
+
+ if(magnifier)
+ {
+ Magnifier& magnifierImpl(GetImpl(magnifier));
+ switch(index)
+ {
+ case Toolkit::Magnifier::Property::FRAME_VISIBILITY:
+ {
+ magnifierImpl.SetFrameVisibility(value.Get<bool>());
+ break;
+ }
+ case Toolkit::Magnifier::Property::MAGNIFICATION_FACTOR:
+ {
+ magnifierImpl.SetMagnificationFactor(value.Get<float>());
+ break;
+ }
+ }
+ }
+}
+
+Property::Value Magnifier::GetProperty(BaseObject* object, Property::Index index)
+{
+ Property::Value value;
+
+ Toolkit::Magnifier magnifier = Toolkit::Magnifier::DownCast(Dali::BaseHandle(object));
+
+ if(magnifier)
+ {
+ Magnifier& magnifierImpl(GetImpl(magnifier));
+ switch(index)
+ {
+ case Toolkit::Magnifier::Property::FRAME_VISIBILITY:
+ {
+ value = magnifierImpl.GetFrameVisibility();
+ break;
+ }
+ case Toolkit::Magnifier::Property::MAGNIFICATION_FACTOR:
+ {
+ value = magnifierImpl.GetMagnificationFactor();
+ break;
+ }
+ }
+ }
+
+ return value;
}
} // namespace Internal