/*--------------------------------------------------------------------------
  Project:  Manual 2D Library - m2d
  File:     pageView.h

  Copyright (C)2007-2009 Nintendo  All Rights Reserved.

  These coded instructions, statements, and computer programs contain
  proprietary information of Nintendo of America Inc. and/or Nintendo
  Company Ltd., and are protected by Federal copyright law.  They may
  not be disclosed to third parties or copied or duplicated in any form,
  in whole or in part, without the prior written consent of Nintendo.

  $Revision: 1758 $
 *-------------------------------------------------------------------------*/

#ifndef NTMV_M2D_PAGEVIEW_H_
#define NTMV_M2D_PAGEVIEW_H_

#if defined(__CWCC__)
#pragma once
#endif

#include <nnsys/fnd/allocator.h>
#include <ntmv/m2d/types.h>
#include <ntmv/m2d/Rect.h>
#include <ntmv/m2d/texture.h>

namespace ntmv
{
namespace m2d
{

class Page;
class Pane;
class DrawInfo;
class ArcResourceAccessor;

class PageView
{
public:
                        PageView();

                        ~PageView();

    void                Init(NNSFndAllocator* pAllocator);

    Size                GetViewSize() const             { return mViewSize; }

    void                SetViewSize(Size value)         { mViewSize = value; }

    void                SetFont(const NNSG2dFont *const fonts[])    { mFonts = fonts; }

    void                SetPage(Page* pPage);

    u16*                GetFrameBuf() const             { return mFrameBuf; }

    Size                GetFrameBufSize() const         { return mFrameBufSize; }

    void                SetFrameBuf(
                            u16*    frameBuf,
                            Size    size
                        )
    {
        mFrameBuf = frameBuf;
        mFrameBufSize = size;
    }

    void                PreserveOffset()    { mPreViewPosY = mViewPosY; mPreEndViewPosY = mEndViewPosY; }

    void                ResetPosition();

    bool                CheckScroll(
                            bool    bUp,
                            bool    bDown);

    bool                Scroll(s16     moveY);

    bool                DoScroll(bool* pScrollEvent);

    void                SetupDrawInfo(DrawInfo* pDrawInfo);

    void                Draw();

    void                InvalidateRect();

    const Rect          GetScreenRect(const Rect& layoutRect);

    s16                 GetScrollHeight() const;

    bool                IsScrollable() const;

    const wchar_t*      GetPageHeaderText() const;

    s16                 GetViewPosY() const             { return mViewPosY; }

    const VRegion       GetViewVRegion() const          { return VRegion(mViewPosY, mEndViewPosY); }

    const VRegion       GetPreViewVRegion() const       { return VRegion(mPreViewPosY, mPreEndViewPosY); }

    s16                 GetNextViewPosY() const         { return mNextViewPosY; }

    void                SetNextViewPosY(s16 value)      { mNextViewPosY = value; }

    Page*               GetPage() const                 { return mpPage; }

    bool                HasPage() const                 { return 0 != mpPage; }

    void                SetPageBottomImage(
                            const ImageHeader*  wallPaperImg);

    void                SetScrollStart(bool bEnable)    { mbScrollStart = bEnable; }

private:
    void                Calc();

    void                DrawPageBottom(const DrawInfo& drawInfo);

    NNSFndAllocator*    mpAllocator;
    Page*               mpPage;
    const NNSG2dFont *const *
                        mFonts;

    Size                mViewSize;
    u16*                mFrameBuf;
    Size                mFrameBufSize;

    Texture             mWallPaperTex;

    s16                 mViewPosY;
    s16                 mEndViewPosY;
    s16                 mPreViewPosY;
    s16                 mPreEndViewPosY;
    s16                 mNextViewPosY;
    s16                 mScrollSEPosY;
    bool                mbScrollStart;
};

}   // namespace m2d
}   // namespace ntmv

/* NTMV_M2D_PAGEVIEW_H_ */
#endif
