mirror of
https://github.com/devkitPro/wut.git
synced 2026-05-09 04:12:30 -05:00
All this commit does is make the swkbd and erreula samples roughly equivalent in function For example when closing the error viewer, `SYSLaunchMenu()` will be called to cause ProcUI to exit, just like how it is in swkbd. Also this adds sound effects for the erreula sample, much like what swkbd has already had for some time now.
135 lines
3.4 KiB
C++
135 lines
3.4 KiB
C++
#include <coreinit/filesystem.h>
|
|
#include <coreinit/memdefaultheap.h>
|
|
#include <gx2/surface.h>
|
|
#include <nn/swkbd.h>
|
|
#include <sndcore2/core.h>
|
|
#include <sysapp/launch.h>
|
|
#include <vpad/input.h>
|
|
|
|
#include <whb/gfx.h>
|
|
#include <whb/log.h>
|
|
#include <whb/log_udp.h>
|
|
#include <whb/proc.h>
|
|
|
|
int
|
|
main(int argc, char **argv)
|
|
{
|
|
WHBLogUdpInit();
|
|
WHBProcInit();
|
|
WHBGfxInit();
|
|
FSInit();
|
|
AXInit();
|
|
|
|
// Create FSClient for swkbd
|
|
FSClient *fsClient = (FSClient *)MEMAllocFromDefaultHeap(sizeof(FSClient));
|
|
FSAddClient(fsClient, FS_ERROR_FLAG_NONE);
|
|
|
|
// 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;
|
|
appearArg.inputFormArg.hintText = u"I'm a hint.";
|
|
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(VPAD_CHAN_0, &vpadStatus, 1, nullptr);
|
|
VPADGetTPCalibratedPoint(VPAD_CHAN_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();
|
|
// Cause ProcUI to exit.
|
|
SYSLaunchMenu();
|
|
}
|
|
|
|
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, FS_ERROR_FLAG_NONE);
|
|
MEMFreeToDefaultHeap(fsClient);
|
|
|
|
FSShutdown();
|
|
VPADShutdown();
|
|
AXQuit();
|
|
|
|
WHBGfxShutdown();
|
|
WHBProcShutdown();
|
|
WHBLogUdpDeinit();
|
|
return 0;
|
|
}
|