1 /*---------------------------------------------------------------------------*
2 Project: WiiConnect24 API demos
3 File: MsgViewerRender.c
4
5 Copyright 2006 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 $Log: MsgViewerRender.c,v $
14 Revision 1.3 2008/05/01 08:50:26 hirose_kazuki
15 Added "Close library" mode.
16
17 Revision 1.2 2008/04/28 11:20:23 hirose_kazuki
18 Updated framework.
19
20 Revision 1.1 2006/09/27 08:58:01 torigoe_nobutaka
21 Renamed from render.c
22 Moved from nwc24demo/src.
23
24 Revision 1.2 2006/09/27 07:34:49 torigoe_nobutaka
25 Improved performance.
26 Changed display layout a bit.
27
28 Revision 1.1 2006/08/28 08:51:50 torigoe_nobutaka
29 Initial check in.
30
31
32 $NoKeywords: $
33 *---------------------------------------------------------------------------*/
34
35 #include <revolution.h>
36 #include <revolution/mem.h>
37 #include <revolution/nwc24.h>
38 #include <demo.h>
39
40 #include "MsgViewerRender.h"
41 #include "MsgViewer.h"
42
43 /*---------------------------------------------------------------------------*
44 Static constants
45 *---------------------------------------------------------------------------*/
46 static const s16 FONT_LEADING = FONT_SIZE + 2;
47 static const s16 MENU_BOX_TL_X = 4 * FONT_SIZE;
48 static const s16 MENU_BOX_TL_Y = 4 * FONT_LEADING;
49 static const s16 LIST_BOX_TL_X = 16 * FONT_SIZE;
50 static const s16 LIST_BOX_TL_Y = 3 * FONT_LEADING;
51 static const s16 HEADER_BOX_TL_X = MENU_BOX_TL_X + FONT_SIZE;
52 static const s16 HEADER_BOX_TL_Y = (LIST_BOX_ROWS + 2) * FONT_LEADING + LIST_BOX_TL_Y;
53 static const s16 TEXT_BOX_TL_X = HEADER_BOX_TL_X;
54 static const s16 TEXT_BOX_TL_Y = 4 * FONT_LEADING + HEADER_BOX_TL_Y;
55 static const s16 TEXT_BOX_WIDTH = 29 * FONT_SIZE;
56 static const s16 HOWTO_BOX_TL_X = MENU_BOX_TL_X;
57 static const s16 HOWTO_BOX_TL_Y = (TEXT_BOX_ROWS + 3) * FONT_LEADING + TEXT_BOX_TL_Y;
58 static const char* STR_CURSOR = ">";
59 static const char* STR_UPARROW = "^";
60 static const char* STR_DOWNARROW = "v";
61 static const char* STR_CANNOT_SCROLL = "x";
62
63 static const GXColor CLR_GREEN = { 0, 224, 64, 255 };
64 static const GXColor CLR_ORANGE = { 255, 128, 64, 255 };
65 static const GXColor CLR_YELLOW = { 255, 255, 0, 255 };
66
67 /* Menu Items */
68 static const char* STR_MSG_BOX_MENU[] =
69 {
70 "RECEIVE BOX",
71 "SEND BOX",
72 "RECEIVE MESSAGE",
73 "POST MESSAGE"
74 };
75
76 /*---------------------------------------------------------------------------*
77 Local functions
78 *---------------------------------------------------------------------------*/
79 static void RenderMenu ( void );
80 static void RenderMsgList ( NWC24MsgBoxId mBoxId );
81 static void RenderMsgContent ( void );
82 static void RenderTextDeleteMsg ( void );
83 static void RenderTextBeforeRecvMsg( void );
84 static void RenderTextBeforePostMsg( void );
85 static void RenderTextDoneRecvMsg ( void );
86 static void RenderTextDonePostMsg ( void );
87 static void RenderTextLibClosed ( void );
88 static void RenderTextWaitOpen ( void );
89 static void RenderError ( void );
90 static void RenderHowToUse ( void );
91 static void PrintFrom ( s16 x, s16 y, MsgData* msgData );
92 static void PrintTo ( s16 x, s16 y, MsgData* msgData );
93 static void PrintSubject ( s16 x, s16 y, MsgData* msgData );
94 static void PrintBodyText ( s16 x, s16 y, MsgData* msgData );
95
96 /*---------------------------------------------------------------------------*
97 Name : Render
98 Description : Renders the scene.
99 Arguments : None.
100 Returns : None.
101 *---------------------------------------------------------------------------*/
Render()102 void Render()
103 {
104 /* Menu */
105 RenderMenu();
106
107 /* Message list and their content */
108 if ( g_selectedMenu == MB_MENU_RECV_BOX || g_selectedMenu == MB_MENU_SEND_BOX )
109 {
110 NWC24MsgBoxId mBoxId = (g_selectedMenu == MB_MENU_RECV_BOX) ? NWC24_RECV_BOX : NWC24_SEND_BOX;
111 MsgBoxType mbType = (g_selectedMenu == MB_MENU_RECV_BOX) ? MB_TYPE_RECV : MB_TYPE_SEND;
112
113 RenderMsgList( mBoxId );
114 if ( g_state == MB_STATE_MSG_CONTENT && g_numMsgs[mbType] != 0 )
115 {
116 RenderMsgContent();
117 }
118 }
119
120 /* Other text: */
121 switch ( g_state )
122 {
123 case MB_STATE_DELETE_MSG: RenderTextDeleteMsg(); break;
124 case MB_STATE_BEFORE_RECV_MSG: RenderTextBeforeRecvMsg(); break;
125 case MB_STATE_BEFORE_POST_MSG: RenderTextBeforePostMsg(); break;
126 case MB_STATE_DONE_RECV_MSG: RenderTextDoneRecvMsg(); break;
127 case MB_STATE_DONE_POST_MSG: RenderTextDonePostMsg(); break;
128 case MB_STATE_LIB_CLOSED: RenderTextLibClosed(); break;
129 case MB_STATE_WAIT_OPEN: RenderTextWaitOpen(); break;
130 case MB_STATE_ERROR_CONT:
131 case MB_STATE_ERROR_STOP: RenderError(); break;
132 }
133
134 RenderHowToUse();
135
136 return;
137 }
138
139 /*---------------------------------------------------------------------------*
140 Name : RenderMenu
141 Description : Displays the menu.
142 Arguments : None.
143 Returns : None.
144 *---------------------------------------------------------------------------*/
RenderMenu(void)145 static void RenderMenu( void )
146 {
147 s16 printX = MENU_BOX_TL_X;
148 s16 printY = MENU_BOX_TL_Y;
149 s16 iMenu;
150
151 /* Menu */
152 for ( iMenu = 0; iMenu < NUM_MSG_BOX_MENUS; ++iMenu, printY += FONT_LEADING )
153 {
154 printX = MENU_BOX_TL_X;
155
156 if ( iMenu == g_selectedMenu )
157 {
158 if ( g_state == MB_STATE_MENU )
159 {
160 (void)DEMORFPrintf( (s16)(printX - FONT_SIZE), printY, 0, "%s", STR_CURSOR );
161 }
162 GXSetTevColor( GX_TEVREG0, CLR_YELLOW );
163 }
164
165 printX += DEMORFPrintf( printX, printY, 0, "[%s]", STR_MSG_BOX_MENU[iMenu] );
166 GXSetTevColor( GX_TEVREG0, CLR_WHITE );
167
168 if ( iMenu == MB_MENU_RECV_BOX )
169 {
170 (void)DEMORFPrintf( printX, printY, 0, "(%u)", g_numMsgs[MB_TYPE_RECV] );
171 }
172
173 if ( iMenu == MB_MENU_SEND_BOX )
174 {
175 (void)DEMORFPrintf( printX, printY, 0, "(%u)", g_numMsgs[MB_TYPE_SEND] );
176 }
177 }
178 }
179
180 /*---------------------------------------------------------------------------*
181 Name : RenderMsgList
182 Description : Lists the content of the specified message box.
183 Arguments : mBoxId - Message box type.
184 Returns : None.
185 *---------------------------------------------------------------------------*/
RenderMsgList(NWC24MsgBoxId mBoxId)186 static void RenderMsgList( NWC24MsgBoxId mBoxId )
187 {
188 s16 printX = LIST_BOX_TL_X;
189 s16 printY = LIST_BOX_TL_Y;
190 u32 i;
191 MsgBoxType mbType = (mBoxId == NWC24_RECV_BOX) ? MB_TYPE_RECV : MB_TYPE_SEND;
192
193 if ( g_numMsgs[mbType] == 0 )
194 {
195 /* If the specified message box is empty... */
196 printY += FONT_LEADING;
197
198 (void)DEMORFPrintf( printX, printY, 0, "(%s box has no message.)",
199 (mBoxId == NWC24_RECV_BOX) ? "Receive" : "Send" );
200 return;
201 }
202
203 (void)DEMORFPrintf( printX, printY, 0, "ID:" );
204 printX += DEMOGetRFTextWidth( "[00000000] " );
205 (void)DEMORFPrintf( printX, printY, 0, "Subject:" );
206
207 for ( i = 0; i < LIST_BOX_ROWS && (u32)(g_idxIdTopOfList[mbType] + i) < g_numMsgs[mbType]; ++i )
208 {
209 u32 idxSubjectBuf = (u32)((g_idxSubjectBufStart[mbType] + i) % LIST_BOX_ROWS);
210 u32 idxMsgId = (u32)(g_idxIdTopOfList[mbType] + i);
211
212 printX = LIST_BOX_TL_X;
213 printY += FONT_LEADING;
214
215 if ( idxMsgId == g_idxSelectedId[mbType] )
216 {
217 if ( g_state == MB_STATE_RECV_BOX || g_state == MB_STATE_SEND_BOX )
218 {
219 (void)DEMORFPrintf( (s16)(printX - FONT_SIZE), printY, 0, "%s", STR_CURSOR );
220 }
221 GXSetTevColor( GX_TEVREG0, CLR_YELLOW );
222 }
223
224 (void)DEMORFPrintf( printX, printY, 0, "[%08d] ", g_idListBuf[mbType][idxMsgId] );
225 printX += DEMOGetRFTextWidth( "[00000000] " );
226 (void)DEMORFPrintf( printX, printY, 0, "%s", g_subjectBuf[mbType][idxSubjectBuf] );
227
228 GXSetTevColor( GX_TEVREG0, CLR_WHITE );
229 }
230
231 return;
232 }
233
234 /*---------------------------------------------------------------------------*
235 Name : RenderMsgContent
236 Description : Displays the message content.
237 Arguments : None.
238 Returns : None.
239 *---------------------------------------------------------------------------*/
RenderMsgContent(void)240 static void RenderMsgContent( void )
241 {
242 s16 printX;
243 s16 printY;
244 s16 indent;
245
246 /* Simple header information */
247 printX = HEADER_BOX_TL_X;
248 printY = HEADER_BOX_TL_Y;
249 indent = (s16)DEMOGetRFTextWidth( "[Subject] " );
250
251 (void)DEMORFPrintf( printX, printY, 0, "[From]" );
252 PrintFrom( (s16)(printX + indent), printY, &g_msgData );
253
254 printY += FONT_LEADING;
255 (void)DEMORFPrintf( printX, printY, 0, "[To]" );
256 PrintTo( (s16)(printX + indent), printY, &g_msgData );
257
258 printY += FONT_LEADING;
259 (void)DEMORFPrintf( printX, printY, 0, "[Subject]" );
260 PrintSubject( (s16)(printX + indent), printY, &g_msgData );
261
262 /* This text */
263 printX = TEXT_BOX_TL_X;
264 printY = TEXT_BOX_TL_Y;
265 PrintBodyText( printX, printY, &g_msgData );
266
267 if ( g_state == MB_STATE_MSG_CONTENT )
268 {
269 /* scrollbar */
270 printX += TEXT_BOX_WIDTH + FONT_SIZE;
271 printY -= FONT_SIZE;
272 if ( g_lineTopOfBodyText != 0 )
273 {
274 (void)DEMORFPrintf( printX, printY, 0, "%s", STR_UPARROW );
275 }
276 else
277 {
278 (void)DEMORFPrintf( printX, printY, 0, "%s", STR_CANNOT_SCROLL );
279 }
280
281 printY += TEXT_BOX_ROWS * FONT_LEADING + FONT_SIZE;
282 if ( (s32)g_lineTopOfBodyText < (s32)(g_numLinesBodyText - TEXT_BOX_ROWS) )
283 {
284 (void)DEMORFPrintf( printX, printY, 0, "%s", STR_DOWNARROW );
285 }
286 else
287 {
288 (void)DEMORFPrintf( printX, printY, 0, "%s", STR_CANNOT_SCROLL );
289 }
290
291 /* Message delete text. */
292 printX = HOWTO_BOX_TL_X;
293 printY = (s16)(HOWTO_BOX_TL_Y - (2 * FONT_LEADING));
294 printX += DEMORFPrintf( printX, printY, 0, "(Push " );
295
296 DEMOSetFontType( DM_FT_RVS );
297 printX += DEMORFPrintf( printX, printY, 0, "<A>" );
298
299 DEMOSetFontType( DM_FT_XLU );
300 (void)DEMORFPrintf( printX, printY, 0, " to DELETE this message.)" );
301 }
302
303 return;
304 }
305
306 /*---------------------------------------------------------------------------*
307 Name : RenderTextDeleteMsg
308 Description : Displays message delete text.
309 Arguments : None.
310 Returns : None.
311 *---------------------------------------------------------------------------*/
RenderTextDeleteMsg(void)312 static void RenderTextDeleteMsg( void )
313 {
314 s16 printX = TEXT_BOX_TL_X;
315 s16 printY = TEXT_BOX_TL_Y;
316
317 DEMOSetFontType( DM_FT_RVS );
318 (void)DEMORFPrintf( printX, printY, 0, "Are you sure you want to delete this message?" );
319
320 printY += 2 * FONT_LEADING;
321 DEMOSetFontType( DM_FT_XLU );
322 printX += DEMORFPrintf( printX, printY, 0, "Push " );
323 DEMOSetFontType( DM_FT_RVS );
324 printX += DEMORFPrintf( printX, printY, 0, "<A>" );
325 DEMOSetFontType( DM_FT_XLU );
326 (void)DEMORFPrintf( printX, printY, 0, " to DELETE this message." );
327
328 printX = TEXT_BOX_TL_X;
329 printY += FONT_LEADING;
330 printX += DEMORFPrintf( printX, printY, 0, "Push " );
331 DEMOSetFontType( DM_FT_RVS );
332 printX += DEMORFPrintf( printX, printY, 0, "<B>" );
333 DEMOSetFontType( DM_FT_XLU );
334 (void)DEMORFPrintf( printX, printY, 0, " to CANCEL." );
335
336 return;
337 }
338
339 /*---------------------------------------------------------------------------*
340 Name : RenderTextBeforeRecvMsg
341 Description : Displays message receive text.
342 Arguments : None.
343 Returns : None.
344 *---------------------------------------------------------------------------*/
RenderTextBeforeRecvMsg(void)345 static void RenderTextBeforeRecvMsg( void )
346 {
347 s16 printX = TEXT_BOX_TL_X;
348 s16 printY = TEXT_BOX_TL_Y;
349
350 printX += DEMORFPrintf( printX, printY, 0, "Push " );
351 DEMOSetFontType( DM_FT_RVS );
352 printX += DEMORFPrintf( printX, printY, 0, "<A>" );
353 DEMOSetFontType( DM_FT_XLU );
354 (void)DEMORFPrintf( printX, printY, 0, " to RECEIVE a test message." );
355
356 printX = TEXT_BOX_TL_X;
357 printY += FONT_LEADING;
358 printX += DEMORFPrintf( printX, printY, 0, "Push " );
359 DEMOSetFontType( DM_FT_RVS );
360 printX += DEMORFPrintf( printX, printY, 0, "<B>" );
361 DEMOSetFontType( DM_FT_XLU );
362 (void)DEMORFPrintf( printX, printY, 0, " to CANCEL." );
363
364 return;
365 }
366
367 /*---------------------------------------------------------------------------*
368 Name : RenderTextBeforePostMsg
369 Description : Displays message send text.
370 Arguments : None.
371 Returns : None.
372 *---------------------------------------------------------------------------*/
RenderTextBeforePostMsg(void)373 static void RenderTextBeforePostMsg( void )
374 {
375 s16 printX = TEXT_BOX_TL_X;
376 s16 printY = TEXT_BOX_TL_Y;
377
378 printX += DEMORFPrintf( printX, printY, 0, "Push " );
379 DEMOSetFontType( DM_FT_RVS );
380 printX += DEMORFPrintf( printX, printY, 0, "<A>" );
381 DEMOSetFontType( DM_FT_XLU );
382 (void)DEMORFPrintf( printX, printY, 0, " to POST a test message." );
383
384 printX = TEXT_BOX_TL_X;
385 printY += FONT_LEADING;
386 printX += DEMORFPrintf( printX, printY, 0, "Push " );
387 DEMOSetFontType( DM_FT_RVS );
388 printX += DEMORFPrintf( printX, printY, 0, "<B>" );
389 DEMOSetFontType( DM_FT_XLU );
390 (void)DEMORFPrintf( printX, printY, 0, " to CANCEL." );
391
392 return;
393 }
394
395 /*---------------------------------------------------------------------------*
396 Name : RenderTextDoneRecvMsg
397 Description : Displays message receive complete text.
398 Arguments : None.
399 Returns : None.
400 *---------------------------------------------------------------------------*/
RenderTextDoneRecvMsg(void)401 static void RenderTextDoneRecvMsg( void )
402 {
403 s16 printX = TEXT_BOX_TL_X;
404 s16 printY = TEXT_BOX_TL_Y;
405
406 (void)DEMORFPrintf( printX, printY, 0, "Received a test message successfully." );
407
408 printY += 2 * FONT_LEADING;
409 printX += DEMORFPrintf( printX, printY, 0, "Push " );
410 DEMOSetFontType( DM_FT_RVS );
411 printX += DEMORFPrintf( printX, printY, 0, "<A>" );
412 DEMOSetFontType( DM_FT_XLU );
413 (void)DEMORFPrintf( printX, printY, 0, " to return to MENU." );
414
415 return;
416 }
417
418 /*---------------------------------------------------------------------------*
419 Name : RenderTextDonePostMsg
420 Description : Displays message send complete text.
421 Arguments : None.
422 Returns : None.
423 *---------------------------------------------------------------------------*/
RenderTextDonePostMsg(void)424 static void RenderTextDonePostMsg( void )
425 {
426 s16 printX = TEXT_BOX_TL_X;
427 s16 printY = TEXT_BOX_TL_Y;
428
429 (void)DEMORFPrintf( printX, printY, 0, "Posted a test message successfully." );
430
431 printY += 2 * FONT_LEADING;
432 printX += DEMORFPrintf( printX, printY, 0, "Push " );
433 DEMOSetFontType( DM_FT_RVS );
434 printX += DEMORFPrintf( printX, printY, 0, "<A>" );
435 DEMOSetFontType( DM_FT_XLU );
436 (void)DEMORFPrintf( printX, printY, 0, " to return to MENU." );
437
438 return;
439 }
440
441 /*---------------------------------------------------------------------------*
442 Name : RenderTextLibClosed
443 Description : Displays text for the closed library state.
444 Arguments : None.
445 Returns : None.
446 *---------------------------------------------------------------------------*/
RenderTextLibClosed(void)447 static void RenderTextLibClosed( void )
448 {
449 s16 printX = TEXT_BOX_TL_X;
450 s16 printY = TEXT_BOX_TL_Y;
451
452 GXSetTevColor( GX_TEVREG0, CLR_GREEN );
453
454 DEMOSetFontType( DM_FT_XLU );
455 (void)DEMORFPrintf( printX, printY, 0, "NWC24 LIBRARY CLOSED." );
456 printY += 2 * FONT_LEADING;
457 printX += DEMORFPrintf( printX, printY, 0, "Scheduler is working now. Press " );
458 DEMOSetFontType( DM_FT_RVS );
459 printX += DEMORFPrintf( printX, printY, 0, "<A>" );
460 DEMOSetFontType( DM_FT_XLU );
461 (void)DEMORFPrintf( printX, printY, 0, " to open again." );
462
463 GXSetTevColor( GX_TEVREG0, CLR_WHITE );
464
465 return;
466 }
467
468 /*---------------------------------------------------------------------------*
469 Name : RenderTextWaitOpen
470 Description : Displays text when waiting for the library to open.
471 Arguments : None.
472 Returns : None.
473 *---------------------------------------------------------------------------*/
RenderTextWaitOpen(void)474 static void RenderTextWaitOpen( void )
475 {
476 s16 printX = TEXT_BOX_TL_X;
477 s16 printY = TEXT_BOX_TL_Y;
478 s32 errorCode;
479
480 GXSetTevColor( GX_TEVREG0, CLR_GREEN );
481
482 DEMOSetFontType( DM_FT_XLU );
483 errorCode = - g_errorCode;
484 printX += DEMORFPrintf( printX, printY, 0, "Please wait ..." );
485
486 if ( errorCode != 0 )
487 {
488 (void)DEMORFPrintf( printX, printY, 0, " (CODE:%d)", errorCode );
489 }
490
491 GXSetTevColor( GX_TEVREG0, CLR_WHITE );
492
493 return;
494 }
495
496 /*---------------------------------------------------------------------------*
497 Name : RenderError
498 Description : Displays errors.
499 Arguments : None.
500 Returns : None.
501 *---------------------------------------------------------------------------*/
RenderError(void)502 static void RenderError( void )
503 {
504 s16 printX = TEXT_BOX_TL_X;
505 s16 printY = TEXT_BOX_TL_Y;
506 s32 errorCode;
507
508 GXSetTevColor( GX_TEVREG0, CLR_ORANGE );
509
510 DEMOSetFontType( DM_FT_XLU );
511 errorCode = - g_errorCode;
512 (void)DEMORFPrintf( printX, printY, 0, "ERROR OCCURED. (CODE:%d)", errorCode );
513
514 GXSetTevColor( GX_TEVREG0, CLR_WHITE );
515
516 return;
517 }
518
519 /*---------------------------------------------------------------------------*
520 Name : RenderHowToUse
521 Description : Displays how to use.
522 Arguments : None.
523 Returns : None.
524 *---------------------------------------------------------------------------*/
RenderHowToUse(void)525 static void RenderHowToUse( void )
526 {
527 static u8 frame = 0;
528 s16 printX = HOWTO_BOX_TL_X;
529 s16 printY = HOWTO_BOX_TL_Y;
530
531 DEMOSetFontType( DM_FT_RVS );
532 printX += DEMORFPrintf( printX, printY, 0, "<UP/DOWN>" );
533 DEMOSetFontType( DM_FT_XLU );
534 printX += DEMORFPrintf( printX, printY, 0, " Select or Scroll " );
535 DEMOSetFontType( DM_FT_RVS );
536 printX += DEMORFPrintf( printX, printY, 0, "<A>" );
537 DEMOSetFontType( DM_FT_XLU );
538 printX += DEMORFPrintf( printX, printY, 0, " Enter " );
539 DEMOSetFontType( DM_FT_RVS );
540 printX += DEMORFPrintf( printX, printY, 0, "<B>" );
541 DEMOSetFontType( DM_FT_XLU );
542 if ( g_state == MB_STATE_MENU )
543 {
544 printX += DEMORFPrintf( printX, printY, 0, " Close " );
545 }
546 else
547 {
548 printX += DEMORFPrintf( printX, printY, 0, " Cancel " );
549 }
550
551 // Frame count
552 frame = (u8)((frame + 1) % 60);
553 (void)DEMORFPrintf( printX, printY, 0, "%d", frame );
554
555 return;
556 }
557
558 /*---------------------------------------------------------------------------*
559 Name : PrintFrom
560 Description : Displays the sender of the specified message.
561 Arguments : x - x value of the display position.
562 y - y value of the display position.
563 msgData - Pointer to the MsgData type message data.
564 Returns : None.
565 *---------------------------------------------------------------------------*/
PrintFrom(s16 x,s16 y,MsgData * msgData)566 static void PrintFrom( s16 x, s16 y, MsgData* msgData )
567 {
568 (void)DEMORFPrintf( x, y, 0, "%s", msgData->from );
569 return;
570 }
571
572 /*---------------------------------------------------------------------------*
573 Name : PrintTo
574 Description : Displays the receiver of the specified message.
575 Arguments : x - x value of the display position.
576 y - y value of the display position.
577 msgData - Pointer to the MsgData type message data.
578 Returns : None.
579 *---------------------------------------------------------------------------*/
PrintTo(s16 x,s16 y,MsgData * msgData)580 static void PrintTo( s16 x, s16 y, MsgData* msgData )
581 {
582 u32 i;
583
584 for ( i = 0; i < msgData->numTo; ++i )
585 {
586 x += DEMORFPrintf( x, y, 0, "%s", msgData->to[i] );
587 if ( i < msgData->numTo - 1 )
588 {
589 x += DEMORFPrintf( x, y, 0, ", " );
590 }
591 }
592
593 return;
594 }
595
596 /*---------------------------------------------------------------------------*
597 Name : PrintSubject
598 Description : Displays the subject of the specified message.
599 Arguments : x - x value of the display position.
600 y - y value of the display position.
601 msgData - Pointer to the MsgData type message data.
602 Returns : None.
603 *---------------------------------------------------------------------------*/
PrintSubject(s16 x,s16 y,MsgData * msgData)604 static void PrintSubject( s16 x, s16 y, MsgData* msgData )
605 {
606 char* pt = msgData->subject;
607
608 while ( *pt != '\0' )
609 {
610 if ( *pt != '\r' && *pt != '\n' )
611 {
612 x += DEMORFPrintf( x, y, 0, "%c", *pt );
613 }
614
615 ++pt;
616 }
617
618 return;
619 }
620
621 /*---------------------------------------------------------------------------*
622 Name : PrintBodyText
623 Description : Displays the body text of the specified message.
624 Arguments : x - x value of the display position.
625 y - y value of the display position.
626 msgData - Pointer to the MsgData type message data.
627 Returns : None.
628 *---------------------------------------------------------------------------*/
PrintBodyText(s16 x,s16 y,MsgData * msgData)629 static void PrintBodyText( s16 x, s16 y, MsgData* msgData )
630 {
631 char* pt = msgData->text;
632 s16 width = 0;
633 u32 rowCount = 0;
634 s32 texWidth;
635 s32 pxWidth;
636 char* next = NULL;
637 s16 printX;
638 s16 printY;
639
640 while ( *pt != '\0' )
641 {
642 if ( *pt == '\r' )
643 {
644 ++pt;
645 continue;
646 }
647
648 // Line break
649 if ( *pt == '\n' )
650 {
651 width = 0;
652 ++rowCount;
653 ++pt;
654 continue;
655 }
656
657 next = OSGetFontWidth( pt, &texWidth );
658 pxWidth = (s16)(texWidth * FONT_SIZE / g_fontData->cellWidth);
659
660 // Line break
661 if ( TEXT_BOX_WIDTH < (s16)(width + pxWidth) )
662 {
663 width = 0;
664 ++rowCount;
665 }
666
667 if ( g_lineTopOfBodyText <= rowCount && rowCount < g_lineTopOfBodyText + TEXT_BOX_ROWS )
668 {
669 printX = (s16)(x + width);
670 printY = (s16)(y + ((rowCount - g_lineTopOfBodyText) * FONT_LEADING));
671 (void)DEMORFPutsEx( printX, printY, 0, pt, (s16)(pxWidth + 1), next - pt );
672 }
673
674 width += pxWidth;
675 pt = next;
676 }
677
678 g_numLinesBodyText = rowCount + 1;
679 return;
680 }
681
682 /*======== End of MsgViewerRender.c ========*/
683