From c2a993a4dd7c6e7cacf8cf46ee99d4a006690611 Mon Sep 17 00:00:00 2001 From: James Benton Date: Wed, 13 Jun 2018 12:12:51 +0100 Subject: [PATCH] samples: Add swkbd sample. --- include/swkbd/rpl_interface.h | 1 - samples/CMakeLists.txt | 3 +- samples/swkbd/CMakeLists.txt | 26 +++++++ samples/swkbd/main.cpp | 127 ++++++++++++++++++++++++++++++++++ 4 files changed, 155 insertions(+), 2 deletions(-) create mode 100644 samples/swkbd/CMakeLists.txt create mode 100644 samples/swkbd/main.cpp diff --git a/include/swkbd/rpl_interface.h b/include/swkbd/rpl_interface.h index 779f891a..65ed7f66 100644 --- a/include/swkbd/rpl_interface.h +++ b/include/swkbd/rpl_interface.h @@ -3,7 +3,6 @@ #include /** - * \defgroup swkbd SYSAPP Launch * \ingroup swkbd * @{ */ diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index e948c765..822518f9 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -3,10 +3,11 @@ project(samples) include("${WUT_ROOT}/share/wut.cmake" REQUIRED) add_subdirectory(custom_default_heap) +add_subdirectory(gx2_triangle) add_subdirectory(helloworld) add_subdirectory(helloworld_std_thread) -add_subdirectory(gx2_triangle) add_subdirectory(my_first_rpl) +add_subdirectory(swkbd) install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/content/" DESTINATION "${CMAKE_INSTALL_PREFIX}/content") diff --git a/samples/swkbd/CMakeLists.txt b/samples/swkbd/CMakeLists.txt new file mode 100644 index 00000000..81c13fb7 --- /dev/null +++ b/samples/swkbd/CMakeLists.txt @@ -0,0 +1,26 @@ +cmake_minimum_required(VERSION 3.2) +project(swkbd CXX) +include("${WUT_ROOT}/share/wut.cmake" REQUIRED) + +add_executable(swkbd + main.cpp) + +target_link_libraries(swkbd + whb + gx2 + coreinit + proc_ui + sysapp + nsysnet + nn_ac + nn_swkbd + vpad) + +wut_enable_newlib(swkbd) +wut_enable_stdcpp(swkbd) + +wut_create_rpx(swkbd.rpx + swkbd) + +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/swkbd.rpx" + DESTINATION "${CMAKE_INSTALL_PREFIX}") diff --git a/samples/swkbd/main.cpp b/samples/swkbd/main.cpp new file mode 100644 index 00000000..ac8eb1d9 --- /dev/null +++ b/samples/swkbd/main.cpp @@ -0,0 +1,127 @@ +#include +#include +#include +#include + +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + WHBLogUdpInit(); + WHBProcInit(); + WHBGfxInit(); + FSInit(); + VPADInit(); + + // Create FSClient for swkbd + FSClient *fsClient = (FSClient *)MEMAllocFromDefaultHeap(sizeof(FSClient)); + FSAddClient(fsClient, 0); + + // Create swkbd + nn::swkbd::CreateArg createArg; + createArg.regionType = nn::swkbd::RegionType::Europe; + createArg.workMemory = MEMAllocFromDefaultHeap(nn::swkbd::GetWorkMemorySize(0)); + createArg.fsClient = fsClient; + if (!nn::swkbd::Create(createArg)) { + WHBLogPrintf("nn::swkbd::Create failed"); + WHBProcShutdown(); + return -1; + } + + // Show the keyboard + nn::swkbd::AppearArg appearArg; + appearArg.keyboardArg.configArg.languageType = nn::swkbd::LanguageType::English; + if (!nn::swkbd::AppearInputForm(appearArg)) { + WHBLogPrintf("nn::swkbd::AppearInputForm failed"); + WHBProcShutdown(); + return -1; + } + + WHBLogPrintf("Begin rendering..."); + while (WHBProcIsRunning()) { + // Read vpad for swkbd::Calc + VPADStatus vpadStatus; + VPADRead(0, &vpadStatus, 1, nullptr); + VPADGetTPCalibratedPoint(0, &vpadStatus.tpNormal, &vpadStatus.tpNormal); + + // Update keyboard + nn::swkbd::ControllerInfo controllerInfo; + controllerInfo.vpad = &vpadStatus; + controllerInfo.kpad[0] = nullptr; + controllerInfo.kpad[1] = nullptr; + controllerInfo.kpad[2] = nullptr; + controllerInfo.kpad[3] = nullptr; + nn::swkbd::Calc(controllerInfo); + + if (nn::swkbd::IsNeedCalcSubThreadFont()) { + nn::swkbd::CalcSubThreadFont(); + } + + if (nn::swkbd::IsNeedCalcSubThreadPredict()) { + nn::swkbd::CalcSubThreadPredict(); + } + + if (nn::swkbd::IsDecideOkButton(nullptr)) { + nn::swkbd::DisappearInputForm(); + break; + } + + WHBGfxBeginRender(); + + WHBGfxBeginRenderTV(); + WHBGfxClearColor(0.0f, 0.0f, 1.0f, 1.0f); + nn::swkbd::DrawTV(); + WHBGfxFinishRenderTV(); + + WHBGfxBeginRenderDRC(); + WHBGfxClearColor(1.0f, 0.0f, 1.0f, 1.0f); + nn::swkbd::DrawDRC(); + WHBGfxFinishRenderDRC(); + + WHBGfxFinishRender(); + } + + const char16_t *str = nn::swkbd::GetInputFormString(); + + if (!str) { + WHBLogPrint("nn::swkbd::GetInputFormString returned NULL"); + } else { + // Quick hack to get from a char16_t str to char for our log function + char logStr[128]; + logStr[0] = 0; + + for (int i = 0; i < 128; ++i) { + if (!str[i]) { + logStr[i] = 0; + break; + } + + if (str[i] > 0x7F) { + logStr[i] = '?'; + } else { + logStr[i] = str[i]; + } + } + + WHBLogPrintf("Input string: %s", logStr); + } + + // Cleanup + WHBLogPrintf("Exiting..."); + nn::swkbd::Destroy(); + MEMFreeToDefaultHeap(createArg.workMemory); + + FSDelClient(fsClient, 0); + MEMFreeToDefaultHeap(fsClient); + + FSShutdown(); + VPADShutdown(); + + WHBGfxShutdown(); + WHBProcShutdown(); + WHBLogUdpDeinit(); + return 0; +}