/*---------------------------------------------------------------------------* Project: WiiConnect24 API demos File: FLViewerRender.c Copyright 2006 Nintendo. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Log: FLViewerRender.c,v $ Revision 1.1 2006/09/27 08:56:17 torigoe_nobutaka Moved from nwc24demo/src. Revision 1.1 2006/09/13 10:07:05 torigoe_nobutaka Initial check in. $NoKeywords: $ *---------------------------------------------------------------------------*/ #include #include #include #define DEMO_USE_MEMLIB 1 #include #include "FLViewer.h" #include "FLViewerRender.h" /*---------------------------------------------------------------------------* Static constants *---------------------------------------------------------------------------*/ static const s16 LARGE_FONT_SIZE = 32; static const s16 FONT_LEADING = (s16)(FONT_SIZE + 2); static const s16 LIST_BOX_TL_X = 2 * FONT_SIZE; static const s16 LIST_BOX_TL_Y = 3 * FONT_LEADING; static const s16 LIST_BOX_WIDTH = 15 * FONT_SIZE; static const s16 INFO_BOX_TL_X = 17 * FONT_SIZE; static const s16 INFO_BOX_TL_Y = 3 * FONT_LEADING; static const s16 HELP_BOX_TL_X = 17 * FONT_SIZE; static const s16 HELP_BOX_TL_Y = 16 * FONT_LEADING; static const s16 HEX_BOX_TL_X = 30 * FONT_SIZE; static const s16 HEX_BOX_TL_Y = 2 * FONT_LEADING; static const char* STR_EDIT_ITEM[] = { "Type", "Status", "FDID", "Name", "Address" }; /*---------------------------------------------------------------------------* Forward declarations of function *---------------------------------------------------------------------------*/ static void SetFontColor ( GXColor color ); static void SetFontSize ( s16 size ); static void RenderFriendList( void ); static void RenderFriendInfo( void ); static void PrintType ( s16 x, s16 y, NWC24FriendInfo* info ); static void PrintTypeCore ( s16 x, s16 y, u32 type, BOOL bEditMode ); static void PrintStatus ( s16 x, s16 y, NWC24FriendInfo* info ); static void PrintStatusCore ( s16 x, s16 y, u32 status, BOOL bEditMode ); static void PrintFdId ( s16 x, s16 y, NWC24FriendInfo* info ); static void PrintFdIdCore ( s16 x, s16 y, const char* strFdId, BOOL bEditMode ); static void PrintName ( s16 x, s16 y, NWC24FriendInfo* info ); static void PrintNameCore ( s16 x, s16 y, const char* name, BOOL bEditMode ); static void PrintAddress ( s16 x, s16 y, NWC24FriendInfo* info ); static void PrintWiiId ( s16 x, s16 y, const char* strWiiId, BOOL bEditMode ); static void PrintMailAddr ( s16 x, s16 y, const char* mailAddr, BOOL bEditMode ); /*---------------------------------------------------------------------------* Render scene *---------------------------------------------------------------------------*/ void Render( void ) { s16 printX; s16 printY; /* Friend information list */ RenderFriendList(); /* Friend information */ if ( (g_state == STATE_SELECT_FRIEND && TRUE == NWC24IsFriendInfoThere( g_idxSelectedFriend )) || g_state != STATE_SELECT_FRIEND ) { RenderFriendInfo(); } /* Hexadecimal input mode*/ if ( g_hexBuf[0] != '\0' ) { printX = HEX_BOX_TL_X; printY = HEX_BOX_TL_Y; printX += DEMORFPrintf( printX, printY, 0, "(hex) 0x" ); SetFontColor( CLR_GREEN ); (void)DEMORFPrintf( printX, printY, 0, "%s", g_hexBuf ); SetFontColor( CLR_WHITE ); } /* Frame count */ { static u8 frames = 0; printX = LIST_BOX_TL_X; printY = (s16)(LIST_BOX_TL_Y + ((LIST_BOX_ROWS + 1) * FONT_LEADING)); /* Frame count */ frames = (u8)((frames + 1) % 60); (void)DEMORFPrintf( printX, printY, 0, "%d", frames ); } /* Friend information deletion verification */ if ( g_state == STATE_DELETE_FRIEND ) { printX = HELP_BOX_TL_X; printY = HELP_BOX_TL_Y - FONT_LEADING; SetFontColor( CLR_YELLOW ); (void)DEMORFPrintf( printX, printY, 0, "Delete this friend info? (A/B)" ); SetFontColor( CLR_WHITE ); } /* Controls */ { if ( !g_bHelp ) { printX = (s16)(g_screenWidth - (2 * FONT_SIZE) - DEMOGetRFTextWidth( "<1>: Show help" )); printY = (s16)(LIST_BOX_TL_Y + (LIST_BOX_ROWS * FONT_LEADING)); (void)DEMORFPrintf( printX, printY, 0, "<1>: Show help" ); } else { printX = HELP_BOX_TL_X; printY = HELP_BOX_TL_Y; (void)DEMORFPrintf( printX, printY, 0, ":\n" ":\n" ":\n" ":\n" "<+>:\n" "<->:\n" "<1>:" ); printX += DEMOGetRFTextWidth( "<00000/0000>: " ); (void)DEMORFPrintf( printX, printY, 0, "\n\n\n\n\n\nHide help" ); switch ( g_state ) { case STATE_SELECT_FRIEND: { (void)DEMORFPrintf( printX, printY, 0, "Select\n" "-\n" "Edit\n" "Delete\n" "-\n" "-" ); break; } case STATE_SELECT_EDIT_ITEM: { (void)DEMORFPrintf( printX, printY, 0, "Select\n" "-\n" "Edit\n" "Cancel\n" "Register\n" "-" ); break; } case STATE_EDIT_TYPE: case STATE_EDIT_STATUS: case STATE_EDIT_FD_ID: { (void)DEMORFPrintf( printX, printY, 0, "Select\n" "-\n" "Input\n" "Back space\n" "-\n" "-" ); break; } case STATE_EDIT_NAME: { (void)DEMORFPrintf( printX, printY, 0, "Select\n" "Change char-type\n" "Input\n" "Back space\n" "Decide\n" "Toggle hex-mode" ); break; } case STATE_EDIT_WII_ID: { (void)DEMORFPrintf( printX, printY, 0, "Select\n" "-\n" "Input\n" "Back space\n" "-\n" "-" ); break; } case STATE_EDIT_MAIL_ADDR: { (void)DEMORFPrintf( printX, printY, 0, "Select\n" "Change char-type\n" "Input\n" "Back space\n" "Decide\n" "-" ); break; } case STATE_DELETE_FRIEND: { (void)DEMORFPrintf( printX, printY, 0, "-\n" "-\n" "Yes\n" "No\n" "-\n" "-" ); break; } } // end switch } // end else } return; } /*---------------------------------------------------------------------------*/ static void SetFontColor( GXColor color ) { GXSetTevColor( GX_TEVREG0, color ); return; } /*---------------------------------------------------------------------------*/ static void SetFontSize( s16 size ) { DEMOSetROMFontSize( size, 0 ); return; } /*---------------------------------------------------------------------------* Display of friend information list *---------------------------------------------------------------------------*/ static void RenderFriendList( void ) { u32 i; s16 printX; s16 printY = LIST_BOX_TL_Y; for ( i = 0; i < LIST_BOX_ROWS; ++i ) { u32 idxFriend = g_idxTopOfFriendList + i; u32 idxBuf = (g_idxNameBufStart + i) % LIST_BOX_ROWS; if ( g_numFriendInfos <= idxFriend ) { break; } if ( idxFriend == g_idxSelectedFriend ) { SetFontColor( (g_state == STATE_SELECT_FRIEND) ? CLR_YELLOW : CLR_DARKYELLOW ); } printX = LIST_BOX_TL_X; (void)DEMORFPrintf( printX, printY, 0, "[%03u", idxFriend ); printX += DEMOGetRFTextWidth( "[000" ); printX += DEMORFPrintf( printX, printY, 0, "] " ); (void)DEMORFPrintf( printX, printY, 0, "%s", g_nameBuf[idxBuf] ); SetFontColor( CLR_WHITE ); printY += FONT_LEADING; } return; } /*---------------------------------------------------------------------------* Display of friend information *---------------------------------------------------------------------------*/ static void RenderFriendInfo( void ) { NWC24Err err; NWC24FriendInfo* info = NULL; BOOL bRegistered; u8 iItem; s16 printX = INFO_BOX_TL_X; s16 printY = INFO_BOX_TL_Y; bRegistered = (BOOL)(TRUE == NWC24IsFriendInfoThere( g_idxSelectedFriend )); if ( bRegistered ) { err = NWC24ReadFriendInfo( g_tempInfo, g_idxSelectedFriend ); CheckError( "NWC24GetNumFriendInfos()", err ); } /* Item name of friend information */ for ( iItem = 0; iItem < NUM_EDIT_ITEMS; ++iItem ) { if ( g_state != STATE_SELECT_FRIEND && g_state != STATE_DELETE_FRIEND ) { if ( bRegistered && !UPDATABLE_ITEM_TABLE[iItem] ) { SetFontColor( CLR_GRAY ); } else if ( iItem == g_selectedEditItem ) { SetFontColor( (g_state == STATE_SELECT_EDIT_ITEM) ? CLR_YELLOW : CLR_DARKYELLOW ); } } (void)DEMORFPrintf( printX, printY, 0, "%s:", STR_EDIT_ITEM[iItem] ); SetFontColor( CLR_WHITE ); printY += 2 * FONT_LEADING; } printX += (s16)DEMOGetRFTextWidth( "00000000: " ); printY = INFO_BOX_TL_Y; /* Friend information value */ if ( bRegistered && (g_state == STATE_SELECT_FRIEND || g_state == STATE_DELETE_FRIEND) ) { PrintType( printX, printY, g_tempInfo ); printY += 2 * FONT_LEADING; PrintStatus( printX, printY, g_tempInfo ); printY += 2 * FONT_LEADING; PrintFdId( printX, printY, g_tempInfo ); printY += 2 * FONT_LEADING; PrintName( printX, printY, g_tempInfo ); printY += 2 * FONT_LEADING; PrintAddress( printX, printY, g_tempInfo ); } else if ( g_state != STATE_SELECT_FRIEND ) { PrintTypeCore( printX, printY, g_editFriendInfo.type, g_state == STATE_EDIT_TYPE ); printY += 2 * FONT_LEADING; PrintStatusCore( printX, printY, g_editFriendInfo.status, g_state == STATE_EDIT_STATUS ); printY += 2 * FONT_LEADING; PrintFdIdCore( printX, printY, g_editFriendInfo.fdId, g_state == STATE_EDIT_FD_ID ); printY += 2 * FONT_LEADING; PrintNameCore( printX, printY, g_editFriendInfo.name, g_state == STATE_EDIT_NAME ); printY += 2 * FONT_LEADING; if ( g_editFriendInfo.type == NWC24_FI_TYPE_WII ) { PrintWiiId( printX, printY, g_editFriendInfo.wiiId, g_state == STATE_EDIT_WII_ID ); } else if ( g_editFriendInfo.type == NWC24_FI_TYPE_PUBLIC ) { PrintMailAddr( printX, printY, g_editFriendInfo.mailAddr, g_state == STATE_EDIT_MAIL_ADDR ); } } return; } /*---------------------------------------------------------------------------* Name: PrintType Description: Displays friend information address type Arguments : x - x-coordinate value of the display position. y - y-coordinate value of the display position. info - Pointer to the NWC24FriendInfo structure displaying the content. Returns: None. *---------------------------------------------------------------------------*/ static void PrintType( s16 x, s16 y, NWC24FriendInfo* info ) { ASSERT( info ); PrintTypeCore( x, y, info->attr.type, FALSE ); return; } /*---------------------------------------------------------------------------*/ static void PrintTypeCore( s16 x, s16 y, u32 type, BOOL bEditMode ) { if ( bEditMode ) { SetFontColor( CLR_YELLOW ); SetFontSize( LARGE_FONT_SIZE ); y += LARGE_FONT_SIZE - FONT_SIZE; } if ( type == NWC24_FI_TYPE_WII ) { (void)DEMORFPrintf( x, y, 0, "Wii" ); } else if ( type == NWC24_FI_TYPE_PUBLIC ) { (void)DEMORFPrintf( x, y, 0, "Public" ); } else { (void)DEMORFPrintf( x, y, 0, "Invalid type" ); } SetFontColor( CLR_WHITE ); SetFontSize( FONT_SIZE ); return; } /*---------------------------------------------------------------------------* Name: PrintStatus Description: Displays the friendship establishment state of friend information Arguments : x - x-coordinate value of the display position. y - y-coordinate value of the display position. info - Pointer to the NWC24FriendInfo structure displaying the content. Returns: None. *---------------------------------------------------------------------------*/ static void PrintStatus( s16 x, s16 y, NWC24FriendInfo* info ) { ASSERT( info ); PrintStatusCore( x, y, info->attr.status, FALSE ); return; } /*---------------------------------------------------------------------------*/ static void PrintStatusCore( s16 x, s16 y, u32 status, BOOL bEditMode ) { if ( bEditMode ) { SetFontColor( CLR_YELLOW ); SetFontSize( LARGE_FONT_SIZE ); y += LARGE_FONT_SIZE - FONT_SIZE; } if ( status == NWC24_FI_STAT_PENDING ) { (void)DEMORFPrintf( x, y, 0, "Pending" ); } else if ( status == NWC24_FI_STAT_ESTABLISHED ) { (void)DEMORFPrintf( x, y, 0, "Established" ); } else { (void)DEMORFPrintf( x, y, 0, "Invalid status" ); } SetFontColor( CLR_WHITE ); SetFontSize( FONT_SIZE ); return; } /*---------------------------------------------------------------------------* Name: PrintFdId Description: Displays fdId member value of friend information. Arguments : x - x-coordinate value of the display position. y - y-coordinate value of the display position. info - Pointer to the NWC24FriendInfo structure displaying the content. Returns: None. *---------------------------------------------------------------------------*/ static void PrintFdId( s16 x, s16 y, NWC24FriendInfo* info ) { char strFdId[FD_ID_BUF_SIZE]; (void)sprintf( strFdId, "%016llu", info->attr.fdId ); PrintFdIdCore( x, y, strFdId, FALSE ); return; } /*---------------------------------------------------------------------------*/ static void PrintFdIdCore( s16 x, s16 y, const char* strFdId, BOOL bEditMode ) { u32 i; for ( i = 0; i < WII_ID_BUF_SIZE - 1; ++i ) { if ( strFdId[i] == '\0' ) { break; } if ( bEditMode && strFdId[i + 1] == '\0' ) { SetFontColor( CLR_YELLOW ); SetFontSize( LARGE_FONT_SIZE ); y += LARGE_FONT_SIZE - FONT_SIZE; } x += DEMORFPrintf( x, y, 0, "%c", strFdId[i] ); if ( i % 4 == 3 ) { x += DEMORFPrintf( x, y, 0, " " ); } } SetFontColor( CLR_WHITE ); SetFontSize( FONT_SIZE ); return; } /*---------------------------------------------------------------------------* Name: PrintName Description: Displays the name (nickname) of friend information Arguments : x - x-coordinate value of the display position. y - y-coordinate value of the display position. info - Pointer to the NWC24FriendInfo structure displaying the content. Returns: None. *---------------------------------------------------------------------------*/ static void PrintName( s16 x, s16 y, NWC24FriendInfo* info ) { char name[NAME_BUF_SIZE]; ConvNameUtf16ToSjis( name, info->attr.name ); PrintNameCore( x, y, name, FALSE ); return; } /*---------------------------------------------------------------------------*/ static void PrintNameCore( s16 x, s16 y, const char* name, BOOL bEditMode ) { u32 i; s32 charSize; for ( i = 0; i < NAME_LEN; ++i ) { if ( *name == '\0' ) { break; } charSize = SjisIsMultibyte( name ) ? 2 : 1; if ( bEditMode && *(name + charSize) == '\0' ) { SetFontColor( CLR_YELLOW ); SetFontSize( LARGE_FONT_SIZE ); y += LARGE_FONT_SIZE - FONT_SIZE; } x += DEMORFPutsEx( x, y, 0, (char*)name, g_screenWidth, charSize ); name += charSize; } SetFontColor( CLR_WHITE ); SetFontSize( FONT_SIZE ); return; } /*---------------------------------------------------------------------------* Name: PrintAddress Description: Displays friend information address Arguments : x - x-coordinate value of the display position. y - y-coordinate value of the display position. info - Pointer to the NWC24FriendInfo structure displaying the content. Returns: None. *---------------------------------------------------------------------------*/ static void PrintAddress( s16 x, s16 y, NWC24FriendInfo* info ) { ASSERT( info ); if ( info->attr.type == NWC24_FI_TYPE_WII ) { char strWiiId[WII_ID_BUF_SIZE]; (void)sprintf( strWiiId, "%016llu", info->addr.wiiId ); PrintWiiId( x, y, strWiiId, FALSE ); } else if ( info->attr.type == NWC24_FI_TYPE_PUBLIC ) { PrintMailAddr( x, y, info->addr.mailAddr, FALSE ); } return; } /*---------------------------------------------------------------------------*/ static void PrintWiiId( s16 x, s16 y, const char* strWiiId, BOOL bEditMode ) { u32 i; if ( strWiiId[0] == '\0' ) { SetFontColor( CLR_GREEN ); (void)DEMORFPrintf( x, y, 0, "Bad Wii ID" ); SetFontColor( CLR_WHITE ); return; } for ( i = 0; i < WII_ID_BUF_SIZE - 1; ++i ) { if ( strWiiId[i] == '\0' ) { break; } if ( bEditMode && strWiiId[i + 1] == '\0' ) { SetFontColor( CLR_YELLOW ); SetFontSize( LARGE_FONT_SIZE ); y += LARGE_FONT_SIZE - FONT_SIZE; } x += DEMORFPrintf( x, y, 0, "%c", strWiiId[i] ); if ( i % 4 == 3 ) { x += DEMORFPrintf( x, y, 0, " " ); } } SetFontColor( CLR_WHITE ); SetFontSize( FONT_SIZE ); return; } /*---------------------------------------------------------------------------*/ static void PrintMailAddr( s16 x, s16 y, const char* mailAddr, BOOL bEditMode ) { u32 i; s32 width; s16 printX = x; s16 printY = y; for ( i = 0; i < MAIL_ADDR_BUF_SIZE - 1; ++i ) { if ( mailAddr[i] == '\0' ) { break; } if ( bEditMode && mailAddr[i + 1] == '\0' ) { SetFontColor( CLR_YELLOW ); SetFontSize( LARGE_FONT_SIZE ); printY += LARGE_FONT_SIZE - FONT_SIZE; } (void)OSGetFontWidth( &mailAddr[i], &width ); if ( g_screenWidth < (s16)(printX + width + (2 * FONT_SIZE)) ) { printX = x; printY += FONT_LEADING; } printX += DEMORFPrintf( printX, printY, 0, "%c", mailAddr[i] ); } SetFontColor( CLR_WHITE ); SetFontSize( FONT_SIZE ); return; } /*======== End of FLViewerRender.c ========*/