/*---------------------------------------------------------------------------* Project: Horizon File: font_CharWriter.h Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. 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: 25674 $ *---------------------------------------------------------------------------*/ #ifndef NN_FONT_CTR_FONT_CHAR_WRITER_H_ #define NN_FONT_CTR_FONT_CHAR_WRITER_H_ // 左上原点 #define COORDINATE_LT 1 #include #include #include #include #include #include #include #include #include // 文字描画用シェーダバイナリファイル名 #define NW_FONT_SHADERBINARY L"nwfont_TextWriterShader.shbin" #define NW_FONT_RECTDRAWER_SHADERBINARY L"nwfont_RectDrawerShader.shbin" namespace nn { namespace font { namespace CTR { struct DispStringBuffer; //--------------------------------------------------------------------------- //! @brief Fontクラスを用いて文字の描画を行うためのクラスです。 //--------------------------------------------------------------------------- class CharWriter { public: /* ------------------------------------------------------------------------ 型 ------------------------------------------------------------------------ */ //! グラデーションの種類を表す enum です。 enum GradationMode { GRADMODE_NONE, //!< グラデーションなし GRADMODE_H, //!< 水平方向グラデーション GRADMODE_V, //!< 垂直方向グラデーション NUM_OF_GRADMODE }; /* ------------------------------------------------------------------------ 定数 ------------------------------------------------------------------------ */ static const u32 DEFAULT_COLOR_MAPPING_MIN = 0x00000000UL; static const u32 DEFAULT_COLOR_MAPPING_MAX = 0xFFFFFFFFUL; /* ------------------------------------------------------------------------ 関数 ------------------------------------------------------------------------ */ //! @name コンストラクタ/デストラクタ //@{ //! コンストラクタです。 CharWriter(); //! デストラクタです。 ~CharWriter(); //@} //! @name フォント //@{ //! @brief フォントを設定します。 //! //! @param[in] pFont 新しく設定するフォントへのポインタ。 //! void SetFont(const Font* pFont) { m_pFont = pFont; } //! @brief フォントを取得します。 //! //! @return フォントが設定されている場合にはフォントへのポインタを返します。 //! 設定されていない場合には NULL を返します。 //! const Font* GetFont() const { return m_pFont; } //@} //! @name 文字描画準備 //@{ //! 文字描画のための準備を行います。 void SetupGX(); //! 描画設定の後処理を行います。 static void FinalizeGX() { TextWriterResource::FinalizeGX(); } //@} //! @name グリフ色の線形変換 //@{ //! @brief 文字描画時のグリフカラーの線形変換を設定します。 //! //! @param[in] min 各成分についての 0 の変換後の値。 //! @param[in] max 各成分についての 255 の変換後の値。 //! void SetColorMapping( util::Color8 min, util::Color8 max ) { m_ColorMapping.min = min; m_ColorMapping.max = max; } //! @brief グリフカラーの線形変換における各成分の 0 の変換後の値を取得します。 //! //! @return グリフカラーの線形変換における各成分の 0 の変換後の値を返します。 //! const util::Color8 GetColorMappingMin() const { return m_ColorMapping.min; } //! @brief グリフカラーの線形変換における各成分の 255 の変換後の値を取得します。 //! //! @return グリフカラーの線形変換における各成分の 255 の変換後の値を返します。 //! const util::Color8 GetColorMappingMax() const { return m_ColorMapping.max; } //! 文字描画時のグリフカラーの線形変換を行わないように設定します。 void ResetColorMapping() { SetColorMapping(DEFAULT_COLOR_MAPPING_MIN, DEFAULT_COLOR_MAPPING_MAX); } //@} //! @name 文字色/グラデーション //@{ //! @brief 文字描画時の追加のアルファ値を設定します。 //! //! @param[in] alpha 新しく設定する追加のアルファ値。 //! void SetAlpha(u8 alpha) { m_Alpha = alpha; } //文字描画時の追加のアルファ値を取得します。 //! @brief 文字描画時の追加のアルファ値を取得します。 //! //! @return 追加のアルファ値を返します。 //! u8 GetAlpha() const { return m_Alpha; } //! @brief グラデーションモードを設定します。 //! //! @param[in] mode 新しく設定するグラデーションモード。 //! void SetGradationMode(GradationMode mode) { NN_FONT_MINMAX_ASSERT(mode, GRADMODE_NONE, NUM_OF_GRADMODE - 1); m_GradationMode = mode; UpdateVertexColor(); } //! @brief グラデーションモードを取得します。 //! //! @return グラデーションモードを返します。 //! GradationMode GetGradationMode() const { return m_GradationMode; } //! @brief 文字色またはグラデーション色を設定します。 //! //! @param[in] color 文字色。 //! void SetTextColor(util::Color8 color) { m_TextColors[internal::TEXTCOLOR_START] = color; UpdateVertexColor(); } //! @brief 文字色またはグラデーション色を設定します。 //! //! @param[in] start グラデーション開始色。 //! @param[in] end グラデーション終了色。 //! void SetTextColor( util::Color8 start, util::Color8 end ) { m_TextColors[internal::TEXTCOLOR_START] = start; m_TextColors[internal::TEXTCOLOR_END ] = end; UpdateVertexColor(); } //! @brief 文字色を取得します。 //! //! @return 文字色を返します。 //! const util::Color8 GetTextColor() const { return m_TextColors[internal::TEXTCOLOR_START]; } //! @brief グラデーション開始色を取得します。 //! //! @return グラデーション開始色を返します。 //! const util::Color8 GetGradationStartColor() const { return m_TextColors[internal::TEXTCOLOR_START]; } //! @brief グラデーション終了色を取得します。 //! //! @return グラデーション終了色を返します。 //! const util::Color8 GetGradationEndColor() const { return m_TextColors[internal::TEXTCOLOR_END]; } //@} //! @name 文字の拡大縮小 //@{ //! @brief 文字の拡大率を指定します。 //! //! @param[in] hScale 横方向拡大率。 //! @param[in] vScale 縦方向拡大率。 //! void SetScale( f32 hScale, f32 vScale ) { m_Scale.x = hScale; m_Scale.y = vScale; } //! @brief 文字の拡大率を指定します。 //! //! @param[in] hvScale 拡大率。 //! void SetScale(f32 hvScale) { m_Scale.x = hvScale; m_Scale.y = hvScale; } //! @brief 文字の横方向の拡大率を取得します。 //! //! @return 文字の横方向の拡大率を返します。 //! f32 GetScaleH() const { return m_Scale.x; } //! @brief 文字の縦方向の拡大率を取得します。 //! //! @return 文字の縦方向の拡大率を返します。 //! f32 GetScaleV() const { return m_Scale.y; } //! @brief 文字のサイズを指定します。 //! //! @param[in] width 拡大後のセルの幅。 //! @param[in] height 拡大後のセルの高さ。 //! void SetFontSize( f32 width, f32 height); //! @brief 文字のサイズを指定します。 //! //! @param[in] height 拡大後のセルの高さ。 //! void SetFontSize(f32 height); //! @brief 拡大適用後のセル幅を取得します。 //! //! @return フォントが設定されている場合は拡大適用後のセル幅をピクセル単位で取得します。 //! フォントが設定されていない場合の返り値は未定義です。 //! f32 GetFontWidth() const; //! @brief 拡大適用後のセル高さを取得します。 //! //! @return フォントが設定されている場合は拡大適用後のセル高さをピクセル単位で取得します。 //! フォントが設定されていない場合の返り値は未定義です。 //! f32 GetFontHeight() const; //! @brief 拡大適用後のアセントを取得します。 //! //! @return 拡大適用後のアセントを返します。 //! f32 GetFontAscent() const; //! @brief 拡大適用後のディセントを取得します。 //! //! @return 拡大適用後のディセントを返します。 //! f32 GetFontDescent() const; //@} //! @name 等幅描画 //@{ //! @brief 強制等幅描画を行うように設定します。 //! //! @param[in] isFixed 強制等幅描画を行うのであれば true を指定します。 //! void EnableFixedWidth(bool isFixed) { m_IsWidthFixed = isFixed; } //! @brief 強制等幅描画を行うかどうかを取得します。 //! //! @return 強制等幅描画を行う場合は true を、行わない場合は false を返します。 //! bool IsWidthFixed() const { return m_IsWidthFixed; } //! @brief 強制等幅描画の文字幅を指定します。 //! //! @param[in] width 新しい等幅描画幅。 //! void SetFixedWidth(f32 width) { m_FixedWidth = width; } //! @brief 強制等幅描画の文字幅を取得します。 //! //! @return 強制等幅描画の文字幅を返します。 //! f32 GetFixedWidth() const { return m_FixedWidth; } //@} //! @name 文字描画 //@{ //! @brief 文字を描画します。 //! //! @param[in] code 描画する文字の文字コード。 //! //! @return 描画した文字の文字幅を返します。 //! f32 Print(CharCode code); //! @brief グリフを描画します。 //! //! @param[in] glyph 描画する文字のグリフデータ。 //! void DrawGlyph(const Glyph& glyph); //@} //! @name カーソル //@{ //! @brief カーソル位置を指定した新しい座標に設定します。 //! //! @param[in] x カーソルの新しい X 座標。 //! @param[in] y カーソルの新しい Y 座標。 //! void SetCursor( f32 x, f32 y ) { m_CursorPos.x = x; m_CursorPos.y = y; } //! @brief カーソル位置を指定した新しい座標に設定します。 //! //! @param[in] x カーソルの新しい X 座標。 //! @param[in] y カーソルの新しい Y 座標。 //! @param[in] z カーソルの新しい Z 座標。 //! void SetCursor( f32 x, f32 y, f32 z ) { m_CursorPos.x = x; m_CursorPos.y = y; m_CursorPos.z = z; } //! @brief カーソルを現在位置から指定された差分だけ移動します。 //! //! @param[in] dx X 軸方向のカーソル移動量。 //! @param[in] dy Y 軸方向のカーソル移動量。 //! void MoveCursor( f32 dx, f32 dy ) { m_CursorPos.x += dx; m_CursorPos.y += dy; } //! @brief カーソルを現在位置から指定された差分だけ移動します。 //! //! @param[in] dx X 軸方向のカーソル移動量。 //! @param[in] dy Y 軸方向のカーソル移動量。 //! @param[in] dz Z 軸方向のカーソル移動量。 //! void MoveCursor( f32 dx, f32 dy, f32 dz ) { m_CursorPos.x += dx; m_CursorPos.y += dy; m_CursorPos.z += dz; } //! @brief カーソルの X 座標を設定します。 //! //! @param[in] x カーソルの新しい X 座標。 //! void SetCursorX(f32 x) { m_CursorPos.x = x; } //! @brief カーソルの Y 座標を設定します。 //! //! @param[in] y カーソルの新しい Y 座標。 //! void SetCursorY(f32 y) { m_CursorPos.y = y; } //! @brief カーソルの Z 座標を設定します。 //! //! @param[in] z カーソルの新しい Z 座標。 //! void SetCursorZ(f32 z) { m_CursorPos.z = z; } //! @brief カーソルを現在位置から指定された差分だけ移動します。 //! //! @param[in] dx X 軸方向のカーソル移動量。 //! void MoveCursorX(f32 dx) { m_CursorPos.x += dx; } //! @brief カーソルを現在位置から指定された差分だけ移動します。 //! //! @param[in] dy Y 軸方向のカーソル移動量。 //! void MoveCursorY(f32 dy) { m_CursorPos.y += dy; } //! @brief カーソルを現在位置から指定された差分だけ移動します。 //! //! @param[in] dz Z 軸方向のカーソル移動量。 //! void MoveCursorZ(f32 dz) { m_CursorPos.z += dz; } //! @brief カーソルのX座標を取得します。 //! //! @return カーソルのX座標を返します。 //! f32 GetCursorX() const { return m_CursorPos.x; } //! @brief カーソルのY座標を取得します。 //! //! @return カーソルのY座標を返します。 //! f32 GetCursorY() const { return m_CursorPos.y; } //! @brief カーソルのZ座標を取得します。 //! //! @return カーソルのZ座標を返します。 //! f32 GetCursorZ() const { return m_CursorPos.z; } //@} //! @name シェーダー関連の設定/取得 //@{ //! @brief TextWriterResourceインスタンスを取得します。 //! //! @return TextWriterResourceインスタンスへのポインタを返します。 //! TextWriterResource* GetTextWriterResource() const { return m_pTextWriterResource; } //! @brief TextWriterResourceインスタンスをセットします。 //! //! @param[in] pTextWriterResource TextWriterResourceインスタンスへのポインタ。 //! void SetTextWriterResource(TextWriterResource* pTextWriterResource) { m_pTextWriterResource = pTextWriterResource; } //@} //! @name 文字列表示用バッファ //@{ //! @brief 文字列表示用バッファのサイズを計算します。 //! //! @param[in] charNum 最大描画文字数 //! //! @return 文字列表示用バッファのサイズを返します。 //! static u32 GetDispStringBufferSize(u32 charNum); //! @brief 文字列表示用バッファを初期化します。 //! //! @param[in] drawBuffer 描画用バッファ。 //! @param[in] charNum 最大描画文字数。 //! //! @return 初期化した文字列表示用バッファを返します。 //! static DispStringBuffer* InitDispStringBuffer( void* drawBuffer, u32 charNum); //! @brief 文字列表示用バッファを取得します。 //! //! @return 文字列表示用バッファを返します。 //! DispStringBuffer* GetDispStringBuffer() const { return m_pDispStringBuffer; } //! @brief 文字列表示用バッファをセットします。 //! NULLを設定した場合は文字列表示用バッファを使用しなくなります。 //! //! @param[in] buffer 文字列表示用バッファ。 //! void SetDispStringBuffer(DispStringBuffer* buffer) { m_pDispStringBuffer = buffer; } //! @brief 文字列の描画を開始します。 //! 文字列表示用バッファが設定されている場合に使用します。 //! void StartPrint(); //! @brief 文字列の描画を終了します。 //! 文字列表示用バッファが設定されている場合に使用します。 //! void EndPrint(); //! @brief 文字列表示用のコマンドバッファをカレントのコマンドリストに追加します。 //! void UseCommandBuffer(); //@} #if defined(NN_FONT_PROFILE) void PrintProfile(); #endif protected: #if defined(NN_FONT_PROFILE) void CopyProfileData(const CharWriter& other) const; #endif private: /* ------------------------------------------------------------------------ 型 ------------------------------------------------------------------------ */ typedef math::VEC2 CharScale; typedef math::VEC3 CursorPos; struct ColorMapping { util::Color8 min; util::Color8 max; }; /* ------------------------------------------------------------------------ 関数 ------------------------------------------------------------------------ */ //---- 描画準備 //! @brief グラフィックスエンジンを文字描画用のデフォルト設定にします。 //! //! @param[in] bAlphaTex テクスチャがアルファのみのテクスチャの場合は真。 //! void SetupGXDefault(bool bAlphaTex = false); //! @brief グラフィックスエンジンをテクスチャカラーの線形変換ありの //! 文字描画用に設定します。 //! //! @param[in] bAlphaTex テクスチャがアルファのみのテクスチャの場合は真。 //! void SetupGXWithColorMapping(bool bAlphaTex = false); //! 頂点フォーマットを文字描画用に設定します。 void SetupVertexFormat(); //! グラフィックスエンジンに対して共通の設定を行います。 void SetupGXCommon(); //! @brief グリフを指定位置に描画します。 //! カーソル移動は行いません。 //! //! @param[in] x 描画位置のX座標。 //! @param[in] glyph 描画するグリフデータ。 //! void PrintGlyph( f32 x, const Glyph& glyph); //! テクスチャを張る四角形ポリゴンの頂点カラーを更新します。 void UpdateVertexColor(); //! @brief グリフデータの持つテクスチャをロードします。 //! //! @param[in] glyph ロードすべきテクスチャ情報を持つグリフデータ。 //! void LoadTexture(const Glyph& glyph); /* ------------------------------------------------------------------------ 変数 ------------------------------------------------------------------------ */ static const GLushort s_VertexIndexs[]; ColorMapping m_ColorMapping; //!< カラーマッピング NN_PADDING3; util::Color8 m_VertexColors[internal::TRIFAN_VTX_MAX]; //!< 頂点カラー util::Color8 m_TextColors[internal::TEXTCOLOR_MAX]; //!< 文字色 GradationMode m_GradationMode; CharScale m_Scale; //!< 文字拡大率 CursorPos m_CursorPos; //!< カーソル位置 f32 m_FixedWidth; //!< 等幅時の幅 const Font* m_pFont; //!< フォント //! TextWriterResourceインスタンスへのポインタ TextWriterResource* m_pTextWriterResource; //! 頂点バッファオブジェクト用構造体へのポインタ DispStringBuffer* m_pDispStringBuffer; bool m_IsWidthFixed; //!< 等幅描画するかどうか u8 m_Alpha; //!< 不透明度 NN_PADDING2; #if defined(NN_FONT_PROFILE) mutable Stopwatch m_LoadTextureSw; mutable Stopwatch m_PrintCharSw; mutable u32 m_LoadTextureCount; mutable u32 m_PrintCharCount; mutable Stopwatch m_DispCharSw; mutable u32 m_DispCharCount; #endif }; } // namespace CTR } // namespace font } // namespace nn #endif // NN_FONT_CTR_FONT_CHAR_WRITER_H_