1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     dev_DirectPrint.h
4 
5   Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain proprietary
8   information of Nintendo and/or its licensed developers and are protected by
9   national and international copyright laws. They may not be disclosed to third
10   parties or copied or duplicated in any form, in whole or in part, without the
11   prior written consent of Nintendo.
12 
13   The content herein is highly confidential and should be handled accordingly.
14 
15   $Revision: 31311 $
16  *---------------------------------------------------------------------------*/
17 
18 #ifndef NW_DEV_DIRECTPRINT_H_
19 #define NW_DEV_DIRECTPRINT_H_
20 
21 #include <nw/types.h>
22 #include <cstdarg>
23 #include <nw/sdk.h>
24 #include <nw/ut.h>
25 #include <gles2/gl2.h>
26 #include <gles2/gl2ext.h>
27 
28 namespace nw
29 {
30 namespace dev
31 {
32 
33 #ifdef NW_DEV_ENABLED
34 namespace internal
35 {
36 
37 //---------------------------------------------------------------------------
38 //! @brief フレームバッファの情報をあらわすクラスです。
39 //---------------------------------------------------------------------------
40 struct FrameBufferInfo
41 {
42     //! @brief コンストラクタです。
43     //!
44     //! @details
45     //! メンバーの初期化は行いません。
46     //!
FrameBufferInfoFrameBufferInfo47     FrameBufferInfo()
48     {
49     }
50 
51     //! @brief コンストラクタです。
FrameBufferInfoFrameBufferInfo52     FrameBufferInfo(
53         u8* address,
54         GLuint format,
55         u16 width,
56         u16 height)
57     : m_Address(address),
58       m_Format(format),
59       m_Width(width),
60       m_Height(height)
61     {
62     }
63 
64     //! バッファのメモリアドレスです。
65     u8* m_Address;
66 
67     //! バッファのフォーマットです。
68     GLuint m_Format;
69 
70     //! バッファの幅(ピクセル数)です。
71     u16 m_Width;
72 
73     //! バッファの高さ(ピクセル数)です。
74     u16 m_Height;
75 };
76 
77 } // namespace internal
78 
79 #endif // defined(NW_DEV_ENABLED)
80 
81 //---------------------------------------------------------------------------
82 //! @brief フレームバッファに直接描画するクラスです。
83 //---------------------------------------------------------------------------
84 class DirectPrint
85 {
86 public:
87     //! フォントの横幅です。
88     static const int FONT_WIDTH  = 6;
89     //! フォントの高さです。
90     static const int FONT_HEIGHT = 7;
91     //! 行の高さです。
92     static const int LINE_HEIGHT = FONT_HEIGHT + 4;
93     //! タブ幅(文字数)です。
94     static const int TAB_WIDTH   = 4;
95 
96     //! 描画の向きを表します。
97     enum Direction
98     {
99         //! 画面を横に広く使うモードです。
100         DIRECTION_HORIZONTAL,
101         //! 画面を縦に広く使うモードです。
102         DIRECTION_VERTICAL,
103         //! 列挙子の数です。
104         DIRECTION_MAX
105     };
106 
107 #if defined(NW_DEV_ENABLED)
108 
109     //----------------------------------------
110     //! @name コンストラクタ/デストラクタ
111     //  @{
112 
113     //! @brief コンストラクタです。
114     DirectPrint();
115 
116     //! @brief デストラクタです。
117     ~DirectPrint();
118 
119     //  @}
120 
121     //----------------------------------------
122     //! @name 初期化/終了処理
123     //  @{
124 
125     //! @brief ダイレクトプリント機能を初期化します。
126     void Initialize();
127 
128     //! @brief リソースを開放します。
129     //!
130     //! @details
131     //! デストラクタの呼び出し以前にリソースを開放したい場合に使用します。
132     //!
133     void Finalize();
134 
135     //! @brief ダイレクトプリント機能が使用可能な状態かを返します。
136     bool IsActive() const;
137 
138     //  @}
139 
140     //----------------------------------------
141     //! @name 設定
142     //  @{
143 
144     //! @brief 描画対象となるフレームバッファを設定します。
145     //!
146     //! @param buffer  フレームバッファへのポインタです。
147     //! @param format  フレームバッファのフォーマットです。
148     //! @param width  フレームバッファの幅です。(ピクセル, 8の倍数)
149     //! @param height  フレームバッファの高さです。(ピクセル, 8の倍数)
150     //!
151     void SetTargetBuffer(
152         void *buffer,
153         GLuint format,
154         u16 width,
155         u16 height);
156 
157     //! @brief 描画対象となるフレームバッファを設定します。
158     //!
159     //! @details
160     //! フレームバッファに関するその他のパラメータは以前の設定が
161     //! そのまま使われます。
162     //!
163     //! @param buffer  フレームバッファへのポインタです。
164     //!
165     void SetTargetBuffer(void *buffer);
166 
167     //! @brief 描画対象のフレームバッファに
168     //! 現在アクティブなディスプレイバッファを設定します。
169     //!
170     //! @remark
171     //! 実機のみ利用できます。
172     //!
173     void SetTargetActiveDisplayBuffer();
174 
175     //! @brief 現在設定されている描画対象のフレームバッファを取得します。
176     //!
177     //! @return フレームバッファのアドレスを返します。
178     //!
GetTargetBuffer()179     void* GetTargetBuffer() const
180     {
181         return m_Buffer.m_Address;
182     }
183 
184     //! @brief 現在設定されている描画対象の幅を取得します。
185     //!
186     //! @return フレームバッファの幅を返します。
187     //!
GetTargetWidth()188     u16 GetTargetWidth() const
189     {
190         return m_Buffer.m_Width;
191     }
192 
193     //! @brief 現在設定されている描画対象の高さを取得します。
194     //!
195     //! @return フレームバッファの高さを返します。
196     //!
GetTargetHeight()197     u16 GetTargetHeight() const
198     {
199         return m_Buffer.m_Height;
200     }
201 
202     //! @brief 描画色を設定します。
203     //!
204     //! @param color 描画色です。
205     //!
206     void SetColor(ut::Color8 color);
207 
208     //! @brief 描画色を設定します。
209     //!
210     //! @param r  文字描画色の赤成分です。
211     //! @param g  文字描画色の緑成分です。
212     //! @param b  文字描画色の青成分です。
213     //!
214     void SetColor(u8 r, u8 g, u8 b);
215 
216     //! @brief 現在の描画色を取得します。
217     //!
218     //! @return 描画色を返します。
219     //!
220     ut::Color8 GetColor() const;
221 
222     //! @brief 背景色を設定します。
223     //!
224     //! @param color 背景色です。
225     //!
226     void SetBackgroundColor(ut::Color8 color);
227 
228     //! @brief 背景色を設定します。
229     //!
230     //! @param r  背景色の赤成分です。
231     //! @param g  背景色の緑成分です。
232     //! @param b  背景色の青成分です。
233     //!
234     void SetBackgroundColor(u8 r, u8 g, u8 b);
235 
236     //! @brief 現在の背景を取得します。
237     //!
238     //! @return 背景を返します。
239     //!
240     ut::Color8 GetBackgroundColor() const;
241 
242     //! @brief 描画の方向を指定します。
243     //!
244     //! @details
245     //! 描画方向はDIRECTION_VERTICALに初期化されます。
246     //!
247     //! @param direction  描画の方向です。
248     //!
249     //! @sa GetDirection
250     //!
251     void SetDirection(Direction direction);
252 
253     //! @brief 描画の方向を取得します。
254     //!
255     //! @return 描画の方向を返します。
256     //!
257     //! @sa SetDirection
258     //!
259     Direction GetDirection() const;
260 
261     //  @}
262 
263     //----------------------------------------
264     //! @name 描画
265     //  @{
266 
267     //! @brief 矩形領域を背景色で塗りつぶします。
268     //!
269     //! @param x  矩形領域の位置(X方向成分)です。
270     //! @param y  矩形領域の位置(Y方向成分)です。
271     //! @param width  矩形領域の幅です。
272     //! @param height  矩形領域の高さです。
273     //!
274     void Erase(int x, int y, int width, int height);
275 
276     //! @brief 文字列を描画します。
277     //!
278     //! @details
279     //! 描画される文字列の後ろの矩形領域は背景色で塗りつぶされます。
280     //! 行右端で折り返します。
281     //!
282     //! @param x  描画開始位置(X方向成分)です。
283     //! @param y  描画開始位置(Y方向成分)です。
284     //! @param format  文字列のフォーマットです。
285     //!
286     void Printf(int x, int y, const char* format, ...);
287 
288     //! @brief 文字列を描画します。
289     //!
290     //! @details
291     //! 描画される文字列の後ろの矩形領域は背景色で塗りつぶされます。
292     //!
293     //! @param x  描画開始位置(X方向成分)です。
294     //! @param y  描画開始位置(Y方向成分)です。
295     //! @param turnOver  行右端で折り返す場合には true を指定します。
296     //! @param format  文字列のフォーマットです。
297     //!
298     void Printf(int x, int y, bool turnOver, const char* format, ...);
299 
300     //! @brief 文字列を描画します。
301     //!
302     //! @param x  描画開始位置(X方向成分)です。
303     //! @param y  描画開始位置(Y方向成分)です。
304     //! @param turnOver  行右端で折り返す場合には true を指定します。
305     //! @param backErase  背景を塗りつぶす場合は true を指定します。
306     //! @param format  文字列のフォーマットです。
307     //!
308     void Printf(
309         int x,
310         int y,
311         bool turnOver,
312         bool backErase,
313         const char* format,
314         ...);
315 
316     //! @brief 文字列を描画します。
317     //!
318     //! @param x  描画開始位置(X方向成分)です。
319     //! @param y  描画開始位置(Y方向成分)です。
320     //! @param format  文字列のフォーマットです。
321     //! @param vargs  可変長引数です。
322     //! @param turnOver  行右端で折り返す場合には true を指定します。
323     //! @param backErase  背景を塗りつぶす場合は true を指定します。
324     //!
325     void VPrintf(
326         int x,
327         int y,
328         const char* format,
329         std::va_list vargs,
330         bool turnOver = true,
331         bool backErase = true);
332 
333     //! @brief 文字列を描画します。
334     //!
335     //! @param x  描画開始位置(X方向成分)です。
336     //! @param y  描画開始位置(Y方向成分)です。
337     //! @param str  文字列です。
338     //! @param turnOver  行右端で折り返す場合には true を指定します。
339     //! @param backErase  背景を塗りつぶす場合は true を指定します。
340     //!
341     void DrawString(
342         int x,
343         int y,
344         const char* str,
345         bool turnOver = true,
346         bool backErase = false);
347 
348     //! @brief 描画された文字列をキャッシュからメモリへストアします。
349     void StoreCache();
350 
351     //  @}
352 
353 private:
354     //! フレームバッファ情報。
355     internal::FrameBufferInfo m_Buffer;
356 
357     //! 描画色。
358     ut::Color8 m_Color;
359 
360     //! 背景色。
361     ut::Color8 m_BackgroundColor;
362 
363     //! 描画方向
364     Direction m_Direction;
365 
366     //! 初期化が完了しているか。
367     bool m_Initialized;
368 
369 #else // !defined(NW_DEV_ENABLED)
370 
DirectPrint()371     DirectPrint(){}
372 
~DirectPrint()373     ~DirectPrint(){}
374 
Initialize()375     void Initialize(){}
376 
Finalize()377     void Finalize(){}
378 
IsActive()379     bool IsActive() const{ return false; }
380 
SetTargetBuffer(void *,GLuint,u16,u16)381     void SetTargetBuffer(
382         void *,
383         GLuint,
384         u16,
385         u16){}
386 
SetTargetBuffer(void *)387     void SetTargetBuffer(void *){}
388 
SetTargetActiveDisplayBuffer()389     void SetTargetActiveDisplayBuffer(){}
390 
GetTargetBuffer()391     void* GetTargetBuffer() const{ return NULL; }
392 
GetTargetWidth()393     u16 GetTargetWidth() const{ return 0; }
394 
GetTargetHeight()395     u16 GetTargetHeight() const{ return 0; }
396 
SetColor(ut::Color8)397     void SetColor(ut::Color8){}
398 
SetColor(u8,u8,u8)399     void SetColor(u8, u8, u8){}
400 
GetColor()401     ut::Color8 GetColor() const{ return ut::Color8(); }
402 
SetBackgroundColor(ut::Color8)403     void SetBackgroundColor(ut::Color8){}
404 
SetBackgroundColor(u8,u8,u8)405     void SetBackgroundColor(u8, u8, u8){}
406 
GetBackgroundColor()407     ut::Color8 GetBackgroundColor() const{ return ut::Color8(); }
408 
SetDirection(Direction)409     void SetDirection(Direction){}
410 
GetDirection()411     Direction GetDirection() const{ return Direction(); }
412 
Erase(int,int,int,int)413     void Erase(int, int, int, int){}
414 
Printf(int,int,const char *,...)415     void Printf(int, int, const char*, ...){}
416 
Printf(int,int,bool,const char *,...)417     void Printf(int, int, bool, const char*, ...){}
418 
Printf(int,int,bool,bool,const char *,...)419     void Printf(
420         int,
421         int,
422         bool,
423         bool,
424         const char*,
425         ...)
426     {}
427 
428     void VPrintf(
429         int,
430         int,
431         const char*,
432         std::va_list,
433         bool = true,
434         bool = true)
435     {}
436 
437     void DrawString(
438         int,
439         int,
440         const char*,
441         bool = true,
442         bool = false)
443     {}
444 
StoreCache()445     void StoreCache(){}
446 
447 #endif // defined(NW_DEV_ENABLED)
448 };
449 
450 } // namespace nw::dev
451 } // namespace nw
452 
453 #endif // NW_DEV_DIRECTPRINT_H_
454