samples: Add swkbd sample.

This commit is contained in:
James Benton 2018-06-13 12:12:51 +01:00
parent 75784dbb52
commit c2a993a4dd
4 changed files with 155 additions and 2 deletions

View File

@ -3,7 +3,6 @@
#include <nn/swkbd.h>
/**
* \defgroup swkbd SYSAPP Launch
* \ingroup swkbd
* @{
*/

View File

@ -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")

View File

@ -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}")

127
samples/swkbd/main.cpp Normal file
View File

@ -0,0 +1,127 @@
#include <coreinit/filesystem.h>
#include <coreinit/memdefaultheap.h>
#include <nn/swkbd.h>
#include <vpad/input.h>
#include <whb/proc.h>
#include <whb/gfx.h>
#include <whb/log.h>
#include <whb/log_udp.h>
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;
}