/*--------------------------------------------------------------------------
  Project:  Manual 2D Library - m2d
  File:     m2d_textCanvasContext.cpp

  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 $
 *-------------------------------------------------------------------------*/

#include <ntmv/m2d/textCanvasContext.h>

#include <ntmv/m2d/graphicDefines.h>

namespace ntmv
{
namespace m2d
{

namespace
{

const int   TEXT_VSPACE         = 0;    // Line spacing when rendering strings (in pixels)

}   // namespace

/*---------------------------------------------------------------------------*
  Name:         TextCanvasContext::TextCanvasContext

  Description:  Constructor.

  Arguments:    bSubLCD:       TRUE when drawing to the sub-LCD.
                position:      The canvas position (in characters).
                size:          The canvas size (in characters).
                mpFont:        The font.
                bCanvasClear:  TRUE when clearing the canvas.
                hSpace:        Character spacing. 0 when omitted.

  Returns:      None.
 *---------------------------------------------------------------------------*/
TextCanvasContext::TextCanvasContext(
    bool                bSubLCD,
    Point               position,
    Size                size,
    const NNSG2dFont*   mpFont,
    s16                 hSpace
)
{
    NNS_G2dCharCanvasInitForOBJ1D(
        &mCharCanvas,
        static_cast<u8*>(bSubLCD ? G2S_GetOBJCharPtr(): G2_GetOBJCharPtr())
            + position.y * CHARACTER_LINE_BYTES
            + position.x * CHARACTER_BYTES,
        size.width,
        size.height,
        NNS_G2D_CHARA_COLORMODE_16
    );

    // TextCanvas initialization
    NNS_G2dTextCanvasInit(
        &mTextCanvas,
        &mCharCanvas,
        mpFont,
        hSpace,
        TEXT_VSPACE
    );

    // Clear the canvas
    NNS_G2dCharCanvasClear(&mCharCanvas, TEXT_COLOR_BG);
}

}   // namespace m2d
}   // namespace ntmv
