/*--------------------------------------------------------------------------*
 Project:
 File: sys_WindowManager.h
 

*--------------------------------------------------------------------------*/
#ifndef _UJI_SYS_WINDOW_MANAGER_H_
#define _UJI_SYS_WINDOW_MANAGER_H_

#include <nn/gx.h>
#include "sys_Window.h"


namespace uji {
namespace sys {
    
class WindowManager
{
public:
    WindowManager();
    ~WindowManager();
    
    // ウインドウの生成・破棄
    bool CreateWindow(Window* window, s32 display, int x, int y);
    bool CreateWindow(Window* window, s32 display, int x, int y, int width, int height)
    {
        window->SetSize(Size(width, height));
        return this->CreateWindow(window, display, x, y); 
    }
    void DestroyWindow( Window* window );

    // ウインドウの更新
    void Update();

    // パッドの更新
    void UpdatePad(const Pad& pad);

    // ウインドウの描画
    void Draw(s32 display);
    void DrawDisplay0() { this->Draw(NN_GX_DISPLAY0); }
    void DrawDisplay1() { this->Draw(NN_GX_DISPLAY1); }
#if 0    
    // TODO: アクティブウインドウの変更等に利用予定
    void SetWindowControlFlag(bool enable) { m_EnableWindowControl = enable; }
    bool GetWindowControlFlag() const { return m_EnableWindowControl; }
    bool IsPressWindowControlKey( const Pad& pad ) const;    
#endif
    // ウインドウクライアント領域のアルファ値
    void SetAlpha(int alpha) { m_MasterAlpha = alpha; }
    float GetAlpha() const { return m_MasterAlpha; }
    
    // ウインドウ描画フラグの設定・取得
    void SetWindowVisibleFlag(bool flag) { m_VisibleFlag = flag; }
    bool GetWindowVisibleFlag() { return m_VisibleFlag; }
    
    // アクティブウインドウの設定・取得
    void SetActiveWindow(Window* window);    
    Window* GetActiveWindow() { return m_ActiveWindow; }

    // ウインドウリストの取得
    WindowList& GetWindowList() { return m_WindowList; }
    const WindowList& GetWindowList() const { return m_WindowList; }
    
    // ウインドウオーダー関連
    WindowZOrderList& detail_GetWindowZOrderList() { return m_WindowDrawList; }
    const WindowZOrderList& detail_GetWindowZOrderList() const { return m_WindowDrawList; }
    void detail_SortWindowList();
    void detail_SortWindowZOrderList();
    
    // マスターアルファ値に対して加減
    void ChangeMasterAlpha(int add);
    
    // ウインドウマネージャのパッド処理の有効/無効を設定・取得
    void SetManagerPadControlFlag(bool enable) { m_EnableManagerPadControl = enable; }
    bool GetManagerPadControlFlag() const { return m_EnableManagerPadControl; }    
    
private:    
    void UpdateActiveWindow();
    void UpdateOrder();

    Window* GetWindowByIndex(int index);
    int GetWindowIndex(Window* window);

    void OnUpdatePad(const Pad& pad);

#if 0    
    bool    m_EnableWindowControl;
#endif
    bool    m_EnableManagerPadControl;
    
    bool    m_WindowMenuMode;
    bool    m_VisibleFlag;

    Window* m_ActiveWindow;
    bool    m_ActiveWindowToTop;
    
    int     m_MasterAlpha;
    
    WindowList          m_WindowList;
    WindowZOrderList    m_WindowDrawList;  
};

}   // usingnamespace sys
}   // usingnamespace uji
  

/* _UJI_SYS_WINDOW_MANAGER_H_ */
#endif

