1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     lyt_FontContainer.h
4 
5   Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Revision: 23638 $
14  *---------------------------------------------------------------------------*/
15 
16 #ifndef NW_LYT_FONTCONTAINER_H_
17 #define NW_LYT_FONTCONTAINER_H_
18 
19 #include <nw/types.h>
20 
21 #include <nw/ut/ut_LinkList.h>
22 #include <nw/lyt/lyt_ResourceAccessor.h>
23 #include <cstddef>
24 
25 namespace nw
26 {
27 namespace lyt
28 {
29 
30 //---------------------------------------------------------------------------
31 //! :private
32 //!
33 //! @brief フォントオブジェクトを保持するクラスです。
34 //!
35 //! @sa FontContainer
36 //!
37 //! @since 2009/09/18 初版。
38 //---------------------------------------------------------------------------
39 class FontRefLink
40 {
41 public:
42     //! フォントリソース名の最大です。
43     static const int FONTNAMEBUF_MAX = 128;
44 
45     //----------------------------------------
46     //! @name コンストラクタ/デストラクタ
47     //@{
48 
49     //! @brief コンストラクタです。
50     //!
51     //! @since 2009/09/18 初版。
52     //!
53     FontRefLink();
54 
55     //! @brief デストラクタです。
56     //!
57     //! @details
58     //! 所有の指定されたフォントオブジェクトを破棄します。
59     //!
60     //! @since 2009/09/18 初版。
61     //! @date 2010/01/26 所有の指定されたフォントオブジェクトは破棄する仕様に変更しました。
62     //!
63     ~FontRefLink();
64 
65     //@}
66 
67     //----------------------------------------
68     //! @name 設定/取得
69     //@{
70 
71     //! @brief 情報を設定します。
72     //!
73     //! @param name  フォントリソースの名前です。
74     //! @param pFont  フォントオブジェクトへのポインタです。
75     //! @param own  コンテナがフォントオブジェクトを所有するか指定します。
76     //!             true を指定した場合にはコンテナがフォントオブジェクトを破棄します。
77     //!
78     //! @since 2009/09/18 初版。
79     //! @date 2010/01/26 own 引数を追加しました。
80     //!
81     void Set(
82         const char* name,
83         font::Font* pFont,
84         bool own
85     );
86 
87     //! @brief 関連付けられているフォント名を取得します。
88     //!
89     //! @return 関連付けられているフォント名を返します。
90     //!
91     //! @since 2009/09/18 初版。
92     //!
GetFontName()93     const char* GetFontName() const
94     {
95         return m_FontName;
96     }
97 
98     //! @brief 設定されているフォントオブジェクトを取得します。
99     //!
100     //! @return フォントオブジェクトへのポインタを返します。
101     //!
102     //! @since 2009/09/18 初版。
103     //!
GetFont()104     font::Font* GetFont() const
105     {
106         return m_pFont;
107     }
108 
109     //@}
110 
111     //! :private
112     //! リストのリンク情報です。
113     ut::LinkListNode m_Link;
114 
115 private:
116     char m_FontName[FONTNAMEBUF_MAX];
117     font::Font* m_pFont;
118     bool m_Own;
119 };
120 
121 //---------------------------------------------------------------------------
122 //! :category リソースアクセサ
123 //!
124 //! @brief フォントを保持するクラスです。
125 //!
126 //! @details
127 //! ResourceAccessor の実装でフォントを保持するのに利用されます。
128 //!
129 //! @sa ResourceAccessor
130 //!
131 //! @since 2010/01/26 初版。
132 //---------------------------------------------------------------------------
133 class FontContainer : public ut::LinkList<FontRefLink, offsetof(FontRefLink, m_Link)>
134 {
135 public:
136     //----------------------------------------
137     //! @name コンストラクタ/デストラクタ
138     //@{
139 
140     //! @brief デストラクタです。
141     //!
142     //! @details
143     //! 所有しているフォントオブジェクトも破棄します。
144     //!
145     //! @since 2010/01/26 初版。
146     //!
147     ~FontContainer();
148 
149     // @}
150 
151     //----------------------------------------
152     //! @name 登録/破棄
153     //@{
154 
155     //! @brief 登録を抹消します。
156     //!
157     //! @details
158     //! 所有しているフォントオブジェクトを破棄します。
159     //!
160     //! @since 2010/01/26 初版。
161     //!
162     void Finalize();
163 
164     //! @brief フォントを登録します。
165     //!
166     //! @param name フォントリソースの名前です。
167     //! @param pFont  フォントオブジェクトです。
168     //! @param own  フォントオブジェクトを所有するか指定します。
169     //!             true を指定した場合にはコンテナがフォントオブジェクトを破棄します。
170     //!
171     //! @return 登録キーを返します。キーは登録の抹消に使用します。
172     //!
173     //! @since 2010/01/26 初版。
174     //!
175     FontKey RegistFont(const char* name, font::Font* pFont, bool own);
176 
177     //! @brief フォントの登録を抹消します。
178     //!
179     //! @param key  登録時に取得した登録キーを指定します。
180     //!
181     //! @since 2010/01/26 初版。
182     //!
183     void UnregistFont(FontKey key);
184 
185     //@}
186 
187     //----------------------------------------
188     //! @name 検索
189     //@{
190 
191     //! @brief フォントを検索します。
192     //!
193     //! @param name  検索するフォントの名前です。
194     //!
195     //! @return 見つかったフォント、または NULL を返します。
196     //!
197     //! @since 2010/01/26 初版。
198     //!
199     nw::font::Font* FindFontByName(
200         const char* name
201     );
202 };
203 
204 }   // namespace lyt
205 }   // namespace nw
206 
207 /* NW_LYT_FONTCONTAINER_H_ */
208 #endif
209