mirror of
https://github.com/J-D-K/JKSV.git
synced 2026-03-22 01:34:13 -05:00
81 lines
2.0 KiB
C++
81 lines
2.0 KiB
C++
#include <vector>
|
|
#include <cstring>
|
|
|
|
#include "system/input.hpp"
|
|
|
|
#include "log.hpp"
|
|
|
|
namespace
|
|
{
|
|
PadState s_PadState;
|
|
}
|
|
|
|
void sys::input::init(void)
|
|
{
|
|
padInitializeDefault(&s_PadState);
|
|
padConfigureInput(1, HidNpadStyleSet_NpadStandard);
|
|
logger::log("input::init(): Succeeded.");
|
|
}
|
|
|
|
void sys::input::update(void)
|
|
{
|
|
padUpdate(&s_PadState);
|
|
}
|
|
|
|
bool sys::input::buttonDown(HidNpadButton button)
|
|
{
|
|
return padGetButtonsDown(&s_PadState) & button;
|
|
}
|
|
|
|
bool sys::input::buttonHeld(HidNpadButton button)
|
|
{
|
|
return padGetButtons(&s_PadState) & button;
|
|
}
|
|
|
|
bool sys::input::buttonReleased(HidNpadButton button)
|
|
{
|
|
return padGetButtonsUp(&s_PadState) & button;
|
|
}
|
|
|
|
uint64_t sys::input::buttonsDown(void)
|
|
{
|
|
return padGetButtonsDown(&s_PadState);
|
|
}
|
|
|
|
uint64_t sys::input::buttonsHeld(void)
|
|
{
|
|
return padGetButtons(&s_PadState);
|
|
}
|
|
|
|
uint64_t sys::input::buttonsReleased(void)
|
|
{
|
|
return padGetButtonsUp(&s_PadState);
|
|
}
|
|
|
|
std::string sys::input::getString(SwkbdType swkbdType, const std::string &defaultText, const std::string &headerText, size_t maximumLength)
|
|
{
|
|
// Keyboard config
|
|
SwkbdConfig config;
|
|
// Input buffer
|
|
std::vector<char> inputBuffer(maximumLength + 1);
|
|
|
|
// Setup soft keyboard
|
|
swkbdCreate(&config, 0);
|
|
swkbdConfigMakePresetDefault(&config);
|
|
swkbdConfigSetType(&config, swkbdType);
|
|
swkbdConfigSetInitialText(&config, defaultText.c_str());
|
|
swkbdConfigSetHeaderText(&config, headerText.c_str());
|
|
swkbdConfigSetGuideText(&config, headerText.c_str());
|
|
swkbdConfigSetStringLenMax(&config, maximumLength);
|
|
swkbdConfigSetKeySetDisableBitmask(&config, SwkbdKeyDisableBitmask_Backslash | SwkbdKeyDisableBitmask_Percent);
|
|
|
|
Result showKeyboard = swkbdShow(&config, inputBuffer.data(), maximumLength + 1);
|
|
if(R_FAILED(showKeyboard))
|
|
{
|
|
logger::log("Error showing keyboard: 0x%X: %s", showKeyboard, inputBuffer.data());
|
|
}
|
|
// Free keyboard
|
|
swkbdClose(&config);
|
|
|
|
return std::string(inputBuffer.data());
|
|
} |