Adding Visual namespace and Visual becomes Visual::Base
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / magnifier / magnifier-impl.cpp
index 29e5bec..b69313c 100644 (file)
 #include <dali/public-api/common/stage.h>
 #include <dali/public-api/render-tasks/render-task-list.h>
 #include <dali/public-api/images/resource-image.h>
+#include <dali/public-api/object/type-registry.h>
+#include <dali/public-api/object/type-registry-helper.h>
+#include <dali/public-api/object/property-map.h>
 
-using namespace Dali;
+// INTERNAL INCLUDES
+#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
+#include <dali-toolkit/internal/visuals/visual-string-constants.h>
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+namespace Internal
+{
 
 namespace // unnamed namespace
 {
 
-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.
+Dali::BaseHandle Create()
+{
+  return Toolkit::Magnifier::New();
+}
+
+DALI_TYPE_REGISTRATION_BEGIN( Toolkit::Magnifier, Toolkit::Control, Create )
+
+DALI_PROPERTY_REGISTRATION( Toolkit, Magnifier, "frameVisibility",      BOOLEAN, FRAME_VISIBILITY     )
+DALI_PROPERTY_REGISTRATION( Toolkit, Magnifier, "magnificationFactor",  FLOAT,   MAGNIFICATION_FACTOR )
+
+DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, Magnifier, "sourcePosition",  VECTOR3, SOURCE_POSITION )
+
+DALI_TYPE_REGISTRATION_END()
+
+const float IMAGE_BORDER_INDENT = 5.0f;            ///< Indent of border in pixels.
 
 struct CameraActorPositionConstraint
 {
@@ -92,16 +119,7 @@ struct RenderTaskViewportSizeConstraint
   }
 };
 
-}
-
-namespace Dali
-{
-
-namespace Toolkit
-{
-
-namespace Internal
-{
+} // unnamed namespace
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // Magnifier
@@ -123,8 +141,7 @@ Dali::Toolkit::Magnifier Magnifier::New()
 }
 
 Magnifier::Magnifier()
-: Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS ) ),
-  mPropertySourcePosition(Property::INVALID_INDEX),
+: Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ),
   mDefaultCameraDistance(1000.f),
   mActorSize(Vector3::ZERO),
   mMagnificationFactor(1.0f)
@@ -136,15 +153,9 @@ void Magnifier::SetSourceActor(Actor actor)
   mTask.SetSourceActor( actor );
 }
 
-void Magnifier::SetSourcePosition(const Vector3& position)
-{
-  Self().SetProperty(mPropertySourcePosition, position);
-}
-
 void Magnifier::Initialize()
 {
   Actor self = Self();
-  mPropertySourcePosition = self.RegisterProperty( Toolkit::Magnifier::SOURCE_POSITION_PROPERTY_NAME, Vector3::ZERO );
   Vector2 stageSize(Stage::GetCurrent().GetSize());
 
   // NOTE:
@@ -161,7 +172,7 @@ void Magnifier::Initialize()
   Stage().GetCurrent().Add(mSourceActor);
   mSourceActor.SetParentOrigin(ParentOrigin::CENTER);
   Constraint constraint = Constraint::New<Vector3>( mSourceActor, Actor::Property::POSITION, EqualToConstraint() );
-  constraint.AddSource( Source( self, mPropertySourcePosition ) );
+  constraint.AddSource( Source( self, Toolkit::Magnifier::Property::SOURCE_POSITION ) );
   constraint.Apply();
 
   // create the render task this will render content on top of everything
@@ -189,7 +200,7 @@ void Magnifier::Initialize()
   // 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>( mCameraActor, Actor::Property::POSITION, CameraActorPositionConstraint(stageSize, mDefaultCameraDistance) );
   constraint.AddSource( Source( mSourceActor, Actor::Property::WORLD_POSITION ) );
@@ -245,21 +256,26 @@ 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 = Actor::New( );
+    mFrame.SetInheritPosition(false);
     mFrame.SetInheritScale(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.SetSizeModeFactor( sizeOffset );
 
+    Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get();
+
+    Property::Map map;
+    map[ RENDERER_TYPE ] = BORDER_RENDERER;
+    map[ "borderColor"  ] = Color::WHITE;
+    map[ "borderSize"   ] = IMAGE_BORDER_INDENT;
+    Toolkit::Visual::Base borderVisual = visualFactory.CreateVisual( map );
+    borderVisual.SetOnStage( mFrame );
+
     Constraint constraint = Constraint::New<Vector3>( mFrame, Actor::Property::POSITION, EqualToConstraint() );
     constraint.AddSource( ParentSource( Actor::Property::WORLD_POSITION ) );
     constraint.Apply();
 
-    mFrame.SetNinePatchBorder( Vector4::ONE * IMAGE_BORDER_INDENT );
     self.Add(mFrame);
   }
   else if(!visible && mFrame)
@@ -268,8 +284,10 @@ void Magnifier::SetFrameVisibility(bool visible)
   }
 }
 
-void Magnifier::OnControlSizeSet(const Vector3& targetSize)
+void Magnifier::OnSizeSet(const Vector3& targetSize)
 {
+  Control::OnSizeSet( targetSize );
+
   // 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
@@ -317,6 +335,56 @@ void Magnifier::Update()
   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
 
 } // namespace Toolkit