/*---------------------------------------------------------------------------* Project: Horizon File: phtsel_demo.cpp Copyright (C)2009-2012 Nintendo Co., Ltd. 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. $Rev:$ *---------------------------------------------------------------------------*/ #include #include "demo.h" #include "PadEx.h" #include "Menu.h" #include "PhtselMenu.h" #include #include #include //---------------------------------------------------------------- namespace { nn::phtsel::Parameter psel_param; // Photo selection settings structure //============================== Menu menu; // data for menu namespace { using namespace nn::phtsel; //============================== // items //============================== // parameter names const char* const cFalseTrueName[] = { "FALSE", "TRUE", }; const char* const cOnOffAllName[] = { "ON", "OFF", "ALL", }; const char* const cImageKindName[] = { "JPEG", "MP", "Picture", }; const char* const cMessageName[] = { "\"\"", "\"TEST MESSAGE\"", }; // value table const bool cFalseTrueTable[] = { false, true, }; const PhtselInput::ImageKindBit cImageKindTable[] = { PhtselInput::IMAGE_KIND_BIT_JPEG , PhtselInput::IMAGE_KIND_BIT_MP , PhtselInput::IMAGE_KIND_BIT_PICTURE , }; const PhtselInput::ScreenShotType cScreenShotTypeTable[] = { PhtselInput::SCREEN_SHOT_TYPE_FLAG_ON , PhtselInput::SCREEN_SHOT_TYPE_FLAG_OFF, PhtselInput::SCREEN_SHOT_TYPE_ALL , }; const PhtselInput::FaceType cFaceTypeTable[] = { PhtselInput::FACE_TYPE_FLAG_ON , PhtselInput::FACE_TYPE_FLAG_OFF, PhtselInput::FACE_TYPE_ALL , }; const PhtselInput::DistributeType cDistributeTypeTable[] = { PhtselInput::DISTRIBUTE_TYPE_FLAG_ON , PhtselInput::DISTRIBUTE_TYPE_FLAG_OFF, PhtselInput::DISTRIBUTE_TYPE_ALL , }; const wchar_t* const cMessageTable[] = { L"", L"TEST MESSAGE", }; //============================== // Variables //============================== // items ArrayItem itemEnableSoftReset ( "ENABLE SOFT RESET", cFalseTrueTable, cFalseTrueName ); ArrayItem itemEnableHomeButton( "ENABLE HOME BUTTON", cFalseTrueTable, cFalseTrueName ); DateTimeItem itemSecStart( "SEC START" ); DateTimeItem itemSecEnd ( "SEC END" ); ArrayItem itemImageKind ( "IMAGE KIND BIT", cImageKindTable , cImageKindName ); ArrayItem itemScreenShotType( "SCREEN SHOT TYPE", cScreenShotTypeTable, cOnOffAllName ); ArrayItem itemFaceType ( "FACE TYPE", cFaceTypeTable , cOnOffAllName ); RangeItem<0, PhtselInput::MAX_FACE_INFO_NUM> itemMinFaceNum( "MIN FACE NUM" ); RangeItem<0, PhtselInput::MAX_FACE_INFO_NUM> itemMaxFaceNum( "MAX FACE NUM" ); TitleIdItem itemTitleId( "TITLE UNIQUE ID" ); ArrayItem itemDistributeType( "DISTRIBUTE TYPE", cDistributeTypeTable, cOnOffAllName ); ArrayItem itemSoundEnable ( "SOUND ENABLE", cFalseTrueTable , cFalseTrueName); ArrayItem itemMessage ( "MESSAGE", cMessageTable , cMessageName ); } //============================== // Functions //============================== // read default parameter void ReadDefaultParameter() { nn::phtsel::Parameter param; nn::phtsel::InitializeParameter( param ); nn::phtsel::Config& rConfig = param.config; nn::phtsel::PhtselInput& rInput = param.input; itemEnableSoftReset .SetSelectValue( rConfig.enableSoftReset ); itemEnableHomeButton.SetSelectValue( rConfig.enableHomeButton ); itemSecStart .SetSelectValue( rInput.GetSecStart() ); itemSecEnd .SetSelectValue( rInput.GetSecEnd() ); itemImageKind .SetSelectValue( rInput.GetImgKindBit() ); itemScreenShotType.SetSelectValue( rInput.GetScreenShotType() ); itemFaceType .SetSelectValue( rInput.GetFaceType() ); itemMinFaceNum .SetSelectValue( rInput.GetMinFaceNum() ); itemMaxFaceNum .SetSelectValue( rInput.GetMaxFaceNum() ); itemTitleId .ResetValueAll(); itemDistributeType.SetSelectValue( rInput.GetDistributeType() ); itemSoundEnable .SetSelectValue( rInput.GetSoundEnable() ); itemMessage .SetSelectIndex( 0 ); } // reflect parameter void ReflectParameter() { nn::phtsel::Config& rConfig = psel_param.config; nn::phtsel::PhtselInput& rInput = psel_param.input; rInput.InitAll(); rConfig.enableSoftReset = itemEnableSoftReset.GetSelectValue(); rConfig.enableHomeButton = itemEnableHomeButton.GetSelectValue(); rInput.SetSecStart ( itemSecStart .GetSelectValue() ); rInput.SetSecEnd ( itemSecEnd .GetSelectValue() ); rInput.SetImgKindBit ( itemImageKind .GetSelectValue() ); rInput.SetScreenShotType( itemScreenShotType.GetSelectValue() ); rInput.SetFaceType ( itemFaceType .GetSelectValue() ); rInput.SetMinFaceNum ( itemMinFaceNum .GetSelectValue() ); rInput.SetMaxFaceNum ( itemMaxFaceNum .GetSelectValue() ); for( s32 i=0; iDraw( df, 4, y, menu.GetSelectItemIndex()==i ); } } df.SwapBuffers(); } void DrawDisplay() { DrawText(); } void RestoreGraphics() { // Recover the GPU register settings nngxUpdateState(NN_GX_STATE_ALL); nngxValidateState(NN_GX_STATE_ALL,GL_TRUE); } } //---------------------------------------------------------------- AppletQueryReply myReceiveSleepQueryNotification( uptr arg ) { NN_UNUSED_VAR( arg ); NN_LOG("*** Application-1 sleepQuery \n"); return /*applet::IsActive()? applet::REPLY_LATER:*/ nn::applet::REPLY_ACCEPT; } //---------------------------------------------------------------- void myReceiveAwakeNotification( uptr arg ) { NN_UNUSED_VAR( arg ); NN_LOG("*** Application-1 awake \n"); if ( nn::applet::IsActive() ) { nngxStartLcdDisplay(); } } //---------------------------------------------------------------- extern "C" void nnMain() { NN_TLOG_("----Application start\n"); nn::Result result; // applet declarations nn::applet::SetSleepQueryCallback( myReceiveSleepQueryNotification, 0 ); nn::applet::SetAwakeCallback( myReceiveAwakeNotification, 0 ); nn::applet::Enable(); if(nn::applet::IsExpectedToCloseApplication()) { // Quickly end the application nn::applet::PrepareToCloseApplication(); nn::applet::CloseApplication(); // Never reached return; } // hid result = nn::hid::Initialize(); NN_UTIL_PANIC_IF_FAILED(result); // Render class initialization SetupRenderSystem(); nn::hid::PadReader padReader; nn::hid::PadStatus ps; PadEx padEx(ps); // Initialize photo selection settings structure nn::phtsel::InitializeParameter( psel_param ); InitMenu(); while(1) { loopCnt++; padReader.ReadLatest(&ps); padEx.Tick(); // Render DrawDisplay(); bool bDetailEdit = menu.GetSelectItemPtr()->IsDetailEditMode(); // Start library applet if ( ps.trigger & nn::hid::BUTTON_X ) { ReflectParameter(); // Get memory address of work buffer void* pWorkBuffer = std::malloc(nn::phtsel::GetWorkBufferSize()); NN_NULL_ASSERT(pWorkBuffer); nn::phtsel::StartPhtsel( &psel_param, pWorkBuffer ); std::free(pWorkBuffer); if(nn::applet::IsExpectedToCloseApplication()) { break; } // Recover the GPU register settings RestoreGraphics(); NN_LOG("return code = %d\n",psel_param.output.GetReturnCode()); // Show information for selected file path NN_LOG("file path = [%ls]\n",psel_param.output.GetValue()); NN_LOG("file path length = %2d\n--\n",psel_param.output.GetValueLen()); padEx.Reset(); } // Initialize settings if ( (ps.trigger & (nn::hid::BUTTON_START)) && !bDetailEdit ) { ReadDefaultParameter(); } // Switch to detailed edit mode if( menu.GetSelectItemPtr()->IsEnableDetailEditMode() ) { if ( ( !bDetailEdit && (ps.trigger & (nn::hid::BUTTON_A)) ) || ( bDetailEdit && (ps.trigger & (nn::hid::BUTTON_B)) ) ) { bDetailEdit = !bDetailEdit; menu.GetSelectItemPtr()->SetDetailEditMode(bDetailEdit); } } // Item selection if( !bDetailEdit ) { if ( (padEx.GetRepeat() & (nn::hid::BUTTON_UP)) ) { menu.AddSelectItemIndex( -1 ); } else if ( (padEx.GetRepeat() & (nn::hid::BUTTON_DOWN)) ) { menu.AddSelectItemIndex( 1 ); } } // Item setting menu.GetSelectItemPtr()->Proc( padEx ); // Process HOME Button if ( nn::applet::IsExpectedToProcessHomeButton() ) { NN_LOG("HomeBtn.\n"); nn::applet::ProcessHomeButtonAndWait(); if(nn::applet::IsExpectedToCloseApplication()) { break; } RestoreGraphics(); } // POWER button process if ( nn::applet::IsExpectedToProcessPowerButton() ) { NN_LOG("PowerBtn.\n"); nn::applet::ProcessPowerButtonAndWait(); if(nn::applet::IsExpectedToCloseApplication()) { break; } RestoreGraphics(); } } NN_TLOG_("----Application is to be end\n"); // Free the render class ReleaseRenderSystem(); // Finalize hid nn::hid::Finalize(); // Exit application nn::applet::PrepareToCloseApplication(); nn::applet::CloseApplication(); // No need to call Finalize on applet // Execution will probably not reach here. NN_TLOG_("----Application end\n"); }