/*--------------------------------------------------------------------------
  Project:  Manual 2D Library - m2d
  File:     textBox.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: 1.31 $
 *-------------------------------------------------------------------------*/

#ifndef NTMV_M2D_TEXTBOX_H_
#define NTMV_M2D_TEXTBOX_H_

#if defined(__CWCC__)
#pragma once
#endif

#include <ntmv/m2d/pane.h>
#include <ntmv/m2d/Color.h>

namespace ntmv
{
namespace m2d
{

class DrawInfo;
struct ResBlockSet;

class TextBox : public Pane
{
    typedef Pane Base;

public:
    NTMV_RNT_RUNTIME_TYPEINFO;

                        TextBox(
                            const res::TextBox* pBlock,
                            const ResBlockSet&  resBlockSet);

    const wchar_t*      GetString() const                       { return mTextBuf; }

    const Color         GetTextColor() const                    { return mTextColor; }
    const Size&         GetFontSize() const                     { return mFontSize; }
    s16                 GetLineSpace() const                    { return mLineSpace; }
    s16                 GetCharSpace() const                    { return mCharSpace; }
    u8                  GetTextPositionH() const                { return detail::GetHorizontalPosition(mTextPosition); }
    u8                  GetTextPositionV() const                { return detail::GetVerticalPosition(mTextPosition); }
    u8                  GetTextAlignment() const                { return mBits.textAlignment; }

protected:
    virtual void        CalcSelf(
                            const DrawInfo& drawInfo,
                            Point           parentPosition);

    virtual void        DrawSelf(const DrawInfo& drawInfo);

    void                SetupG2dTextCanvas(
                            NNSG2dTextCanvas*   pTextCanvas,
                            NNSG2dCharCanvas*   pCharCanvas,
                            const DrawInfo&     drawInfo);


    s16                 GetTextMagH() const;
    s16                 GetTextMagV() const;
    s16                 GetTextAlignMag() const;

private:
    void                Init(
                            Page*       pPage,
                            u16         allocStrLen);

    u16                 SetString(
                            const wchar_t*  str,
                            u16             dstIdx,
                            u32             strLen);

protected:
    const wchar_t*      mTextBuf;
    Size                mTextSize;
    GXRgb               mTextColor;
    Size                mFontSize;

    s16                 mLineSpace;
    s16                 mCharSpace;

    const TextLine*     mTextLines;
    u16                 mLineNum;
    u8                  mTextPosition;

    Margin              mMargin;

    struct
    {
        u8                  textAlignment:  2;
    }                   mBits;
};

}   // namespace m2d
}   // namespace ntmv

/* NTMV_M2D_TEXTBOX_H_ */
#endif

