1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - GX - demos - UnitTours/DEMOLib
3   File:     DEMOBitmap.h
4 
5   Copyright 2007-2008 Nintendo. 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   $Date:: 2008-09-17 #$
14   $Rev: 8556 $
15   $Author: okubata_ryoma $
16  *---------------------------------------------------------------------------*/
17 #ifndef DEMO_BITMAP_H_
18 #define DEMO_BITMAP_H_
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 
25 /*---------------------------------------------------------------------------*/
26 /* Constants */
27 
28 #define DEMO_RGB_NONE   GX_RGBA(31, 31, 31, 0)
29 #define DEMO_RGB_CLEAR  GX_RGBA( 0,  0,  0, 0)
30 
31 extern const u32 DEMOAsciiChr[8 * 0x100];
32 
33 
34 /*---------------------------------------------------------------------------*/
35 /* Functions */
36 
37 // Simplified versions that have taken conditional operators into account
38 #define DEMOSetBitmapTextColor(color)       DEMOiSetBitmapTextColor(DEMOVerifyGXRgb(color))
39 #define DEMOSetBitmapGroundColor(color)     DEMOiSetBitmapGroundColor(DEMOVerifyGXRgb(color))
40 #define DEMOFillRect(x, y, wx, wy, color)   DEMOiFillRect(x, y, wx, wy, DEMOVerifyGXRgb(color))
41 #define DEMODrawLine(sx, sy, tx, ty, color) DEMOiDrawLine(sx, sy, tx, ty, DEMOVerifyGXRgb(color))
42 #define DEMODrawFrame(x, y, wx, wy, color)  DEMOiDrawFrame(x, y, wx, wy, DEMOVerifyGXRgb(color))
43 
44 
45 /*---------------------------------------------------------------------------*
46   Name:         DEMOInitDisplayBitmap
47 
48   Description:  Initializes DEMO in bitmap render mode.
49 
50   Arguments:    None.
51 
52   Returns:      None.
53  *---------------------------------------------------------------------------*/
54 void DEMOInitDisplayBitmap(void);
55 
56 /*---------------------------------------------------------------------------*
57   Name:         DEMO_DrawFlip
58 
59   Description:  Applies the current rendering content to VRAM.
60 
61   Arguments:    None.
62 
63   Returns:      None.
64  *---------------------------------------------------------------------------*/
65 void DEMO_DrawFlip();
66 
67 /*---------------------------------------------------------------------------*
68   Name:         DEMOHookConsole
69 
70   Description:  Configure output to be sent to the log, as well, using the OS_PutString hook function.
71 
72   Arguments:    None.
73 
74   Returns:      None.
75  *---------------------------------------------------------------------------*/
76 void DEMOHookConsole(void);
77 
78 /*---------------------------------------------------------------------------*
79   Name:         DEMOVerifyGXRgb
80 
81   Description:  Checks for a valid color value.
82 
83   Arguments:    color: Color value that is thought to be within the GXRgb range.
84 
85   Returns:      If color is a valid GXRgb value, it will be returned unchanged. If it is out of range, 0xFFFF will be returned.
86  *---------------------------------------------------------------------------*/
87 GXRgb DEMOVerifyGXRgb(int color);
88 
89 /*---------------------------------------------------------------------------*
90   Name:         DEMOSetBitmapTextColor
91 
92   Description:  Sets the text color for rendering bitmaps.
93 
94   Arguments:    color: Color to set
95 
96   Returns:      None.
97  *---------------------------------------------------------------------------*/
98 void DEMOiSetBitmapTextColor(GXRgb color);
99 
100 /*---------------------------------------------------------------------------*
101   Name:         DEMOSetBitmapGroundColor
102 
103   Description:  Sets the background color for rendering bitmaps.
104 
105   Arguments:    color: the color to set
106 
107   Returns:      None.
108  *---------------------------------------------------------------------------*/
109 void DEMOiSetBitmapGroundColor(GXRgb color);
110 
111 /*---------------------------------------------------------------------------*
112   Name:         DEMOFillRect
113 
114   Description:  Renders a rectangle to the bitmap.
115 
116   Arguments:    x: X-coordinate for rendering
117                 y: Y-coordinate for rendering
118                 wx: X width for rendering
119                 wy: Y width for rendering
120                 color: Color to set
121 
122   Returns:      None.
123  *---------------------------------------------------------------------------*/
124 void DEMOiFillRect(int x, int y, int wx, int wy, GXRgb color);
125 
126 /*---------------------------------------------------------------------------*
127   Name:         DEMOBlitRect
128 
129   Description:  Transfers a rectangle to the bitmap.
130 
131   Arguments:    x: X-coordinate for rendering
132                 y: Y-coordinate for rendering
133                 wx: X width for rendering
134                 wy: Y width for rendering
135                 image: Image to transfer
136                 stroke: Number of pixels per line to transfer.
137 
138   Returns:      None.
139  *---------------------------------------------------------------------------*/
140 void DEMOBlitRect(int x, int y, int wx, int wy, const GXRgb *image, int stroke);
141 
142 /*---------------------------------------------------------------------------*
143   Name:         DEMOBlitTex16
144 
145   Description:  Transfers a 16-color texture to the bitmap.
146 
147   Arguments:    x: X-coordinate for rendering
148                 y: Y-coordinate for rendering
149                 wx: Rendering width in the x-direction (must be an integer multiple of 8 pixels)
150                 wy: Rendering width in the y-direction (must be an integer multiple of 8 pixels)
151                 chr: Character image (4x8x8 1-D character format)
152                 plt: Palette image (index 0 will be considered transparent)
153 
154   Returns:      None.
155  *---------------------------------------------------------------------------*/
156 void DEMOBlitTex16(int x, int y, int wx, int wy, const void *chr, const GXRgb *plt);
157 
158 /*---------------------------------------------------------------------------*
159   Name:         DEMODrawLine
160 
161   Description:  Renders a line on the bitmap.
162 
163   Arguments:    sx: X-coordinate of the starting point
164                 sy: Y-coordinate of the starting point
165                 tx: Distance along the x-axis to the ending point
166                 ty: Distance along the y-axis to the ending point
167                 color: Color to set
168 
169   Returns:      None.
170  *---------------------------------------------------------------------------*/
171 void DEMOiDrawLine(int sx, int sy, int tx, int ty, GXRgb color);
172 
173 /*---------------------------------------------------------------------------*
174   Name:         DEMODrawFrame
175 
176   Description:  Renders a frame to the bitmap.
177 
178   Arguments:    x: X-coordinate for rendering
179                 y: Y-coordinate for rendering
180                 wx: X width for rendering
181                 wy: Y width for rendering
182                 color: Color to set
183 
184   Returns:      None.
185  *---------------------------------------------------------------------------*/
186 void DEMOiDrawFrame(int x, int y, int wx, int wy, GXRgb color);
187 
188 /*---------------------------------------------------------------------------*
189   Name:         DEMODrawText
190 
191   Description:  Renders a character string on the bitmap.
192 
193   Arguments:    x: X-coordinate for rendering
194                 y: Y-coordinate for rendering
195                 format: Formatted string
196 
197   Returns:      None.
198  *---------------------------------------------------------------------------*/
199 void DEMODrawText(int x, int y, const char *format, ...);
200 
201 /*---------------------------------------------------------------------------*
202   Name:         DEMOClearString
203 
204   Description:  Deletes all background text.
205 
206   Arguments:    None.
207 
208   Returns:      None.
209  *---------------------------------------------------------------------------*/
210 void DEMOClearString(void);
211 
212 /*---------------------------------------------------------------------------*
213   Name:         DEMOPutString
214 
215   Description:  Renders the background text.
216 
217   Arguments:    x: X-coordinate for rendering
218                 y: Y-coordinate for rendering
219                 format: Formatted character string.
220 
221   Returns:      None.
222  *---------------------------------------------------------------------------*/
223 void DEMOPutString(int x, int y, const char *format, ...);
224 
225 /*---------------------------------------------------------------------------*
226   Name:         DEMOPutLog
227 
228   Description:  Displays a log string on the lower screen.
229 
230   Arguments:    format: Formatted string
231 
232   Returns:      None.
233  *---------------------------------------------------------------------------*/
234 void DEMOPutLog(const char *format, ...);
235 
236 /*---------------------------------------------------------------------------*
237   Name:         DEMOSetViewPort
238 
239   Description:  Sets the viewport and projection.
240 
241   Arguments:    x: Upper-left x-coordinate
242                 y: Upper-left y-coordinate
243                 wx: Width of the viewport in the x direction
244                 wy: Width of the viewport in the y direction
245 
246   Returns:      None.
247  *---------------------------------------------------------------------------*/
248 void DEMOSetViewPort(int x, int y, int wx, int wy);
249 
250 
251 #ifdef __cplusplus
252 }/* extern "C" */
253 #endif
254 
255 /* DEMO_BITMAP_H_ */
256 #endif
257