1 /*---------------------------------------------------------------------------*
2
3 Copyright (C) 2010-2012 Nintendo. All rights reserved.
4
5 These coded instructions, statements, and computer programs contain
6 proprietary information of Nintendo of America Inc. and/or Nintendo
7 Company Ltd., and are protected by Federal copyright law. They may
8 not be disclosed to third parties or copied or duplicated in any form,
9 in whole or in part, without the prior written consent of Nintendo.
10
11 *---------------------------------------------------------------------------*/
12 // -----------------------------------------------------------------------------
13 // demoFont.h
14 //
15 // -----------------------------------------------------------------------------
16
17 #ifndef __DEMO_FONT_H_
18 #define __DEMO_FONT_H_
19
20 #include <cafe/demo.h>
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25
26 /// @addtogroup demoFont
27 /// @{
28
29 /// \brief Structure used to define the font data for an instance of DEMOFont
30 typedef struct
31 {
32 /// \brief Mag Scale X,Y of characters
33 f32 *charMagScale;
34
35 /// \brief Mag Scale X,Y of characters (proportional)
36 f32 charMagScaleF[2]; // xxx should it be [4]?
37
38 /// \brief Mag Scale X,Y of characters (fixed)
39 f32 charMagScaleP[2]; // xxx should it be [4]?
40
41 /// \brief Depth value
42 f32 depth;
43
44 /// \brief Color
45 f32 color[4];
46
47 } DEMOFontFontData;
48
49 /// \brief Structure used to define an instance of DEMOFont
50 typedef struct
51 {
52 /// \brief Context state ptr for DEMOFont (instance)
53 GX2ContextState *contextState;
54
55 /// \brief The font data
56 DEMOFontFontData font;
57
58 /// \brief TRUE if the font is currently proportional
59 BOOL proportional;
60
61 /// \brief TRUE if fonts are currently enabled
62 BOOL enabled;
63
64 } DEMOFontInstance;
65
66 /// \brief Initializes the font data and font shader program
67 ///
68 /// Sets up demo font context state and font texture object.
69 /// Creates the font shader program, Sets up font initial values.
70 // Sets up initial grid = 60x24(proportional), 80x24(mono-spacing), color = (1.0f,1.0f,1.0f,1.0f), zValue=-1.0f, proportional=TRUE.
71 /// At default, DEMOFont uses DEMOColorBuffer and viewport which is created in DEMOGfxInit.
72 /// If you want to change the buffer, call DEMOFontSetTarget after init.
73 ///
74 /// \retval A pointer to the instance created by this function
75 DEMOFontInstance* DEMOFontInit(void);
76
77 /// \brief Deletes all the font data
78 void DEMOFontShutdown(void);
79
80 /// \brief Set demo font context to current
81 ///
82 /// Set demo font context to current.
83 /// Call this API before Drawing fonts with demo font context created in DEMOFontInit.
84 void DEMOFontSetContextState(void);
85
86 /// \brief Set view port for demo font.
87 ///
88 /// Set view port for demo font.
89 /// Call this API after calling DEMOFontSetContextState.
90 ///
91 /// \param xOrig orig x point of viewport
92 /// \param yOrig orig y point of viewport
93 /// \param width width of viewport
94 /// \param height height of viewport
DEMOFontSetViewport(f32 xOrig,f32 yOrig,f32 width,f32 height)95 inline void DEMOFontSetViewport(f32 xOrig, f32 yOrig, f32 width, f32 height)
96 {
97 GX2SetViewport(xOrig, yOrig, width, height, 0.0f, 1.0f);
98 GX2SetScissor(xOrig, yOrig, width, height);
99 }
100
101 /// \brief Set color buffer and viewport for demo font
102 ///
103 /// Set color buffer and view port for demo font.
104 /// Call this API after calling DEMOFontSetContextState.
105 ///
106 /// \param colorBuffer Ptr to color buffer structure to set.
DEMOFontSetTarget(GX2ColorBuffer * colorBuffer)107 inline void DEMOFontSetTarget(GX2ColorBuffer* colorBuffer)
108 {
109 DEMOFontSetViewport(0.0,
110 0.0,
111 colorBuffer->surface.width,
112 colorBuffer->surface.height);
113 GX2SetColorBuffer(colorBuffer, GX2_RENDER_TARGET_0);
114 }
115
116 /// \brief Enable/disable fonts from drawing
117 ///
118 /// \param enable If true, fonts will draw. If false, they will not draw.
119 void DEMOFontDrawEnable(BOOL enable);
120
121 /// \brief Output the string into Screen by character units step
122 ///
123 /// Call this API after DEMOFontSetContextState.
124 ///
125 /// \param column Column position of the string by character units step (0 is left side of Screen)
126 /// \param line Line position of the string by character units step (0 is the top of Screen)
127 /// \param pFmt Pointer to a null-terminated string including format specification (equivalent to C's standard output function)
128 void DEMOFontPrintf(f32 column, f32 line, const char* pFmt, ... );
129
130 /// \brief Output the pre-formatted string into Screen by character units step
131 ///
132 /// Call this API after DEMOFontSetContextState.
133 ///
134 /// \param column Column position of the string by character units step (0 is left side of Screen)
135 /// \param line Line position of the string by character units step (0 is the top of Screen)
136 /// \param pStr Pointer to a null-terminated string
137 void DEMOFontPuts(f32 column, f32 line, const char* pStr);
138
139 /// \brief Set the font color
140 ///
141 /// \param r The red color for the font
142 /// \param g The green color for the font
143 /// \param b The blue color for the font
144 /// \param a The alpha color for the font
145 void DEMOFontSetColor(f32 r, f32 g, f32 b, f32 a);
146
147 /// \brief Set the grid size
148 ///
149 /// \param xGrid The number of fixed-width columns
150 /// \param yGrid The number of fixed-width lines
151 void DEMOFontSetGridSize(f32 xGrid, f32 yGrid);
152
153 /// \brief Set the font spacing type
154 ///
155 /// \param proportional True means to use proportional spacing, false means mono spacing
156 void DEMOFontSetSpacing(BOOL proportional);
157
158 /// \brief Set the Z value
159 ///
160 /// \param zValue -1.0 = near plane, 1.0 = far plane
161 void DEMOFontSetZValue(f32 zValue);
162
163 /// \brief Get the maximum texel size of the character.
164 ///
165 /// \param pCharWidth Pointer to the width texel size of character cell
166 /// \param pCharHeight Pointer to the height texel size of character cell
167 void DEMOFontGetCharSize(f32 *pCharWidth, f32 *pCharHeight);
168
169 /// \brief Creates a new instance of DEMOFont
170 ///
171 /// This will create a new instance, in addition to setting the instance.
172 /// This is called by DEMOFontInit().
173 DEMOFontInstance* DEMOFontAddInstance(void);
174
175 /// \brief Deletes an instance of DEMOFont
176 ///
177 /// This is called by DEMOFontShutdown().
178 void DEMOFontDeleteInstance(DEMOFontInstance *instance);
179
180 /// \brief Sets the instance of DEMOFont
181 void DEMOFontSetInstance(DEMOFontInstance *instance);
182
183 /// \brief Gets the instance of DEMOFont
184 DEMOFontInstance* DEMOFontGetInstance(void);
185
186 /// @}
187
188 #ifdef __cplusplus
189 }
190 #endif
191
192 #endif // __DEMO_FONT_H_
193
194