/// ****************************************************************************
/// @file   
/// @author Dr.Neeton
/// @date   200X/X/X - 2015/11/12
/// 
/// @brief  DirectX フレーム管理。
/// 
/// ****************************************************************************

#pragma once

#include "CPL_DX_Window.h"


namespace CPL {
namespace DX {
// namespace Graph {
// namespace GUI {



// _____________________________________________________________________________
/// @brief DirectXイベントフレーム
///
// *****************************************************************************
class FrameEvent
  : public WIN::FrameEvent
  , public DX::Window
{
public:
  FrameEvent
  ( _in<sdptr<Graphics_i_>> in_sp_graphics
  , _in<sdptr<Input      >> in_sp_input = nullptr
  ) : DX::Window( in_sp_graphics, in_sp_input )
  {}
  virtual ~FrameEvent() {}


private:
  // ↓ 警告がうざいので、明示的に呼び出し
  SDEF On_Paint() override { return false; }
  SDEF On_Size( _in<eSizeMode> ) override { return false; }
  SDEF On_EraseBkGnd( _in<HDC> ) override { return true; }

  CPL_WIN_COMPONENT_GET_CLASS_NAME_Base( WIN::MdiWindow )

protected:
  // DX側優先。
  SDEF On_Create() override
  {
    return DX::Window::On_Create();
  }

public:
  virtual SDEF Run() override { return WIN::FrameEvent::Run(); }
  virtual SDEF On_Destroy() override { return WIN::FrameEvent::On_Destroy(); }
  virtual SDEF
    DefaultProc_
      ( _in<UINT> in_message
      , _in<WPARAM> in_wparam
      , _in<LPARAM> in_lparam
      ) override
  {
    return Window::DefaultProc_( in_message, in_wparam, in_lparam );
  }

  // _____________________________________________________________________________
  /// @copydoc CPL::WIN::Component::Create
  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  bool
    Create
      ( _in<HWND     > in_hdl_win_parent
      , _in<td_Coord2> in_pos  = WIN::kPOS_DEFAULT
      , _in<td_Coord2> in_size = WIN::kSIZE_DEFAULT
      ) override
  {
    return
      DX::Window::Create
        ( in_hdl_win_parent
        , in_pos
        , in_size
        , false
        , WS_OVERLAPPEDWINDOW
        );
  }

  // _____________________________________________________________________________
  /// @copydoc CPL::WIN::Component::Create
  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  bool
    Create
      ( _in<HWND      > in_hdl_win_parent
      , _in<td_Coord2 > in_pos
      , _in<td_Coord2 > in_size
      , _in<bool      > in_flag_client_size
      , _in<WIN::STYLE> in_win_style = WS_OVERLAPPEDWINDOW
      )
  {
    return
      DX::Window::Create
        ( in_hdl_win_parent
        , in_pos
        , in_size
        , in_flag_client_size
        , in_win_style
        );
  }
};


// _____________________________________________________________________________
/// @brief DirectXループフレーム
///
// *****************************************************************************
class FrameLoop
  : public WIN::FrameLoop
  , public DX::Window
{
public:
  FrameLoop
  ( _in<sdptr<Graphics_i_>> in_sp_graphics
  , _in<sdptr<Input      >> in_sp_input = nullptr
  ) : DX::Window( in_sp_graphics, in_sp_input )
  {}
  virtual ~FrameLoop() {}
  

private:
  // ↓ 警告がうざいので明示的に呼び出し
  SDEF On_Paint() override { return false; }
  SDEF On_Size( _in<eSizeMode> ) override { return false; }
  SDEF On_EraseBkGnd( _in<HDC> ) override { return true; }
  CPL_WIN_COMPONENT_GET_CLASS_NAME_Base( WIN::MdiWindow )

protected:
  // DX側優先。
  SDEF On_Create() override
  {
    return DX::Window::On_Create();
  }

public:
  virtual SDEF Run() override { return WIN::FrameLoop::Run(); }
  virtual SDEF On_Destroy() override { return WIN::FrameLoop::On_Destroy(); }
  virtual SDEF
    DefaultProc_
      ( _in<UINT  > in_message
      , _in<WPARAM> in_wparam
      , _in<LPARAM> in_lparam
      ) override
  {
    return Window::DefaultProc_( in_message, in_wparam, in_lparam );
  }
  virtual SDEF On_Frame() override
  {
    On_FrameMove();
    return 0;
  }

  // _____________________________________________________________________________
  /// @copydoc CPL::WIN::Component::Create
  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  bool
    Create
      ( _in<HWND     > in_hdl_win_parent
      , _in<td_Coord2> in_pos  = WIN::kPOS_DEFAULT
      , _in<td_Coord2> in_size = WIN::kSIZE_DEFAULT
      ) override
  {
    return
      DX::Window::Create
        ( in_hdl_win_parent
        , in_pos
        , in_size
        , false
        , WS_OVERLAPPEDWINDOW
        );
  }
};


// } // namespace GUI
// } namespace Graph
} // namespace DX
} // namespace CPL
