/// ****************************************************************************
/// @file   
/// @author Dr.Neeton
/// @date   2016/02/04 - 2017/02/03
/// 
/// @brief  描画関連
/// 
/// ****************************************************************************

#include "CPL_GUC_MasterLayer.h"

namespace CPL {
namespace GUC {


// _____________________________________________________________________________
/// @brief 最上位描画レイヤー
// *****************************************************************************
class HighestDrawingOwner
  : public Owner
{
  using td_base = Owner;
  using td_self = HighestDrawingOwner;
  friend class td_self;
  friend Factory<td_self>;
  friend CallPrivateConstructor<td_self>;
public:
protected:
private:
  HighestDrawingOwner( _in<sdptr<Component>> in_sp_master_layer )
    : Owner
      ( in_sp_master_layer
      , float2{ 0, 0 }
      , float2{ WIN::GetWinFrame()->GetClientSize() }
      )
  {
    zzz_setFlagThrowMouse_( true );
  }
  HighestDrawingOwner( cref<td_self> in_HDOwner )
    : td_base( in_HDOwner )
  {
  }

  // _____________________________________________________________________________
  /// @copydoc CPL::GUC::Component::CreateClone
  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  sdptr<Component>
    CreateClone
      ( _in<sdptr<Component>> in_sp_component_for_parent       = nullptr
      , _in<float2          > in_offset_position_from_original = float2{0,0}
      ) const override
  {
    return
      zzz_CreateClone_Basic<td_self>
        ( in_sp_component_for_parent
        , in_offset_position_from_original
        );
  }
};


// _____________________________________________________________________________
/// @brief コンストラクタ
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
MasterLayer::MasterLayer( _in<sdptr<Component>> in_sp_component_for_root )
  : Layer( in_sp_component_for_root )
{
  m_sp_owner =
    Factory<HighestDrawingOwner>::Create( GetLinkMyself() );
  m_sp_owner->SetStateDrawFrame( false );
  m_sp_overlayer =
    Factory<Layer>::Create( GetLinkMyself() );
  m_sp_overlayer->SetStateVisible( true );

  // 親にマスターレイヤーを指定すると、自動的にその配下の描画オーナーに配置
  // されてしまうため、明示的に座標と位置の従属設定を行う。
  m_sp_overlayer->SetBelongComponent
    ( GetLinkMyself()
    , eParentType::All
    );
}


// _____________________________________________________________________________
/// @brief コピーコンストラクタ
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
MasterLayer::MasterLayer( cref<td_self> in_master_layer )
  : td_base( in_master_layer )
  , m_sp_owner
    { FindComponentT_by_UserID<Owner>( in_master_layer.m_sp_owner )
    }
  , m_sp_overlayer
    { FindComponentT_by_UserID<Layer>( in_master_layer.m_sp_overlayer )
    }
{
  m_sp_owner    ->SetAutoUserID();
  m_sp_overlayer->SetAutoUserID();
}


// _____________________________________________________________________________
/// @copydoc CPL::GUC::Component::CreateClone
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sdptr<Component>
  MasterLayer::CreateClone
    ( _in<sdptr<Component>> in_sp_component_for_parent
    , _in<float2          > in_offset_position_from_original
    ) const
{
  return
    zzz_CreateClone_Basic<td_self>
      ( in_sp_component_for_parent
      , in_offset_position_from_original
      );
}


} // namespace GUC
} // namespace CPL