forked from pieeebot/Cafeberry-4JLibs
374 lines
9.1 KiB
C++
374 lines
9.1 KiB
C++
/*
|
|
MIT License
|
|
|
|
Copyright (c) 2026 Patoke
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
in the Software without restriction, including without limitation the rights
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
SOFTWARE.
|
|
*/
|
|
|
|
#include "4J_Input.h"
|
|
#include "INP_Keyboard.h"
|
|
#include "INP_Main.h"
|
|
|
|
C_4JInput InputManager;
|
|
CKeyboard InternalKeyboard;
|
|
|
|
void C_4JInput::Initialise(int iInputStateC, unsigned char ucMapC, unsigned char ucActionC, unsigned char ucMenuActionC)
|
|
{
|
|
InternalInputManager.Initialise(iInputStateC, ucMapC, ucActionC, ucMenuActionC);
|
|
InternalKeyboard.Init();
|
|
}
|
|
|
|
void C_4JInput::Tick(void)
|
|
{
|
|
InternalInputManager.Tick();
|
|
}
|
|
|
|
void C_4JInput::TickKBM(void)
|
|
{
|
|
InternalKeyboard.Tick();
|
|
}
|
|
void C_4JInput::SetDeadzoneAndMovementRange(unsigned int uiDeadzone, unsigned int uiMovementRangeMax)
|
|
{
|
|
InternalInputManager.SetDeadzoneAndMovementRange(uiDeadzone, uiMovementRangeMax);
|
|
}
|
|
|
|
void C_4JInput::SetGameJoypadMaps(unsigned char ucMap, unsigned char ucAction, unsigned int uiActionVal)
|
|
{
|
|
InternalInputManager.SetGameJoypadMaps(ucMap, ucAction, uiActionVal);
|
|
}
|
|
|
|
unsigned int C_4JInput::GetGameJoypadMaps(unsigned char ucMap, unsigned char ucAction)
|
|
{
|
|
return InternalInputManager.GetGameJoypadMaps(ucMap, ucAction);
|
|
}
|
|
|
|
void C_4JInput::SetJoypadMapVal(int iPad, unsigned char ucMap)
|
|
{
|
|
InternalInputManager.SetJoypadMapVal(iPad, ucMap);
|
|
}
|
|
|
|
unsigned char C_4JInput::GetJoypadMapVal(int iPad)
|
|
{
|
|
return InternalInputManager.GetJoypadMapVal(iPad);
|
|
}
|
|
|
|
void C_4JInput::SetJoypadSensitivity(int iPad, float fSensitivity)
|
|
{
|
|
InternalInputManager.SetJoypadSensitivity(iPad, fSensitivity);
|
|
}
|
|
|
|
unsigned int C_4JInput::GetValue(int iPad, unsigned char ucAction, bool bRepeat)
|
|
{
|
|
return InternalInputManager.GetValue(iPad, ucAction, bRepeat);
|
|
}
|
|
|
|
void C_4JInput::MapTouchInput(int iPad, int button)
|
|
{
|
|
InternalInputManager.MapTouchInput(iPad, button);
|
|
}
|
|
|
|
bool C_4JInput::ButtonPressed(int iPad, unsigned char ucAction)
|
|
{
|
|
return InternalInputManager.ButtonPressed(iPad, ucAction);
|
|
}
|
|
|
|
bool C_4JInput::ButtonReleased(int iPad, unsigned char ucAction)
|
|
{
|
|
return InternalInputManager.ButtonReleased(iPad, ucAction);
|
|
}
|
|
|
|
bool C_4JInput::ButtonDown(int iPad, unsigned char ucAction)
|
|
{
|
|
return InternalInputManager.ButtonDown(iPad, ucAction);
|
|
}
|
|
|
|
void C_4JInput::SetJoypadStickAxisMap(int iPad, unsigned int uiFrom, unsigned int uiTo)
|
|
{
|
|
InternalInputManager.SetJoypadStickAxisMap(iPad, uiFrom, uiTo);
|
|
}
|
|
|
|
void C_4JInput::SetJoypadStickTriggerMap(int iPad, unsigned int uiFrom, unsigned int uiTo)
|
|
{
|
|
InternalInputManager.SetJoypadStickTriggerMap(iPad, uiFrom, uiTo);
|
|
}
|
|
|
|
void C_4JInput::SetKeyRepeatRate(float fRepeatDelaySecs, float fRepeatRateSecs)
|
|
{
|
|
InternalInputManager.SetKeyRepeatRate(fRepeatDelaySecs, fRepeatRateSecs);
|
|
}
|
|
|
|
void C_4JInput::SetDebugSequence(const char *chSequenceA, int (*Func)(LPVOID), LPVOID lpParam)
|
|
{
|
|
InternalInputManager.SetDebugSequence(chSequenceA, Func, lpParam);
|
|
}
|
|
|
|
FLOAT C_4JInput::GetIdleSeconds(int iPad)
|
|
{
|
|
return InternalInputManager.GetIdleSeconds(iPad);
|
|
}
|
|
|
|
bool C_4JInput::IsPadConnected(int iPad)
|
|
{
|
|
return InternalInputManager.IsPadConnected(iPad);
|
|
}
|
|
|
|
bool C_4JInput::IsPadActive(int iPad)
|
|
{
|
|
return InternalInputManager.IsPadActive(iPad);
|
|
}
|
|
|
|
float C_4JInput::GetJoypadStick_LX(int iPad, bool bCheckMenuDisplay)
|
|
{
|
|
return InternalInputManager.GetJoypadStick_LX(iPad, bCheckMenuDisplay);
|
|
}
|
|
|
|
float C_4JInput::GetJoypadStick_LY(int iPad, bool bCheckMenuDisplay)
|
|
{
|
|
return InternalInputManager.GetJoypadStick_LY(iPad, bCheckMenuDisplay);
|
|
}
|
|
|
|
float C_4JInput::GetJoypadStick_RX(int iPad, bool bCheckMenuDisplay)
|
|
{
|
|
return InternalInputManager.GetJoypadStick_RX(iPad, bCheckMenuDisplay);
|
|
}
|
|
|
|
float C_4JInput::GetJoypadStick_RY(int iPad, bool bCheckMenuDisplay)
|
|
{
|
|
return InternalInputManager.GetJoypadStick_RY(iPad, bCheckMenuDisplay);
|
|
}
|
|
|
|
unsigned char C_4JInput::GetJoypadLTrigger(int iPad, bool bCheckMenuDisplay)
|
|
{
|
|
return InternalInputManager.GetJoypadLTrigger(iPad, bCheckMenuDisplay);
|
|
}
|
|
|
|
unsigned char C_4JInput::GetJoypadRTrigger(int iPad, bool bCheckMenuDisplay)
|
|
{
|
|
return InternalInputManager.GetJoypadRTrigger(iPad, bCheckMenuDisplay);
|
|
}
|
|
|
|
void C_4JInput::SetMenuDisplayed(int iPad, bool bVal)
|
|
{
|
|
InternalInputManager.SetMenuDisplayed(iPad, bVal);
|
|
}
|
|
|
|
void C_4JInput::OnKeyDown(int vkCode)
|
|
{
|
|
InternalKeyboard.OnKeyDown(vkCode);
|
|
}
|
|
|
|
void C_4JInput::OnKeyUp(int vkCode)
|
|
{
|
|
InternalKeyboard.OnKeyUp(vkCode);
|
|
}
|
|
|
|
void C_4JInput::OnChar(wchar_t ch)
|
|
{
|
|
InternalKeyboard.OnChar(ch);
|
|
}
|
|
|
|
bool C_4JInput::IsKeyDown(int vkCode) const
|
|
{
|
|
return InternalKeyboard.IsKeyDown(vkCode);
|
|
}
|
|
|
|
bool C_4JInput::IsKeyPressed(int vkCode) const
|
|
{
|
|
return InternalKeyboard.IsKeyPressed(vkCode);
|
|
}
|
|
|
|
bool C_4JInput::IsKeyReleased(int vkCode) const
|
|
{
|
|
return InternalKeyboard.IsKeyReleased(vkCode);
|
|
}
|
|
|
|
int C_4JInput::GetMouseX() const
|
|
{
|
|
return InternalKeyboard.GetMouseX();
|
|
}
|
|
|
|
int C_4JInput::GetMouseY() const
|
|
{
|
|
return InternalKeyboard.GetMouseY();
|
|
}
|
|
|
|
bool C_4JInput::IsMouseLDown() const
|
|
{
|
|
return InternalKeyboard.IsLButtonDown();
|
|
}
|
|
|
|
bool C_4JInput::IsLButtonPressed() const
|
|
{
|
|
return InternalKeyboard.IsLButtonPressed();
|
|
}
|
|
|
|
bool C_4JInput::IsLButtonReleased() const
|
|
{
|
|
return InternalKeyboard.IsLButtonReleased();
|
|
}
|
|
|
|
bool C_4JInput::IsMouseRDown() const
|
|
{
|
|
return InternalKeyboard.IsRButtonDown();
|
|
}
|
|
|
|
bool C_4JInput::IsRButtonPressed() const
|
|
{
|
|
return InternalKeyboard.IsRButtonPressed();
|
|
}
|
|
|
|
bool C_4JInput::IsRButtonReleased() const
|
|
{
|
|
return InternalKeyboard.IsRButtonReleased();
|
|
}
|
|
|
|
int C_4JInput::GetMouseWheelDelta() const
|
|
{
|
|
return InternalKeyboard.GetMouseWheelDelta();
|
|
}
|
|
|
|
wchar_t C_4JInput::GetLastChar() const
|
|
{
|
|
return InternalKeyboard.GetLastChar();
|
|
}
|
|
|
|
bool C_4JInput::HasChar() const
|
|
{
|
|
return InternalKeyboard.HasChar();
|
|
}
|
|
|
|
wchar_t C_4JInput::GetChar(int index) const
|
|
{
|
|
return InternalKeyboard.GetChar(index);
|
|
}
|
|
|
|
void C_4JInput::OnMouseMove(int x, int y)
|
|
{
|
|
InternalKeyboard.OnMouseMove(x, y);
|
|
}
|
|
|
|
void C_4JInput::OnRawMouseDelta(int dx, int dy)
|
|
{
|
|
InternalKeyboard.OnRawMouseDelta(dx, dy);
|
|
}
|
|
|
|
void C_4JInput::OnLButtonDown(int x, int y)
|
|
{
|
|
InternalKeyboard.OnLButtonDown(x, y);
|
|
}
|
|
|
|
void C_4JInput::OnLButtonUp(int x, int y)
|
|
{
|
|
InternalKeyboard.OnLButtonUp(x, y);
|
|
}
|
|
|
|
void C_4JInput::OnRButtonDown(int x, int y)
|
|
{
|
|
InternalKeyboard.OnRButtonDown(x, y);
|
|
}
|
|
|
|
void C_4JInput::OnRButtonUp(int x, int y)
|
|
{
|
|
InternalKeyboard.OnRButtonUp(x, y);
|
|
}
|
|
|
|
void C_4JInput::OnMButtonDown(int x, int y)
|
|
{
|
|
InternalKeyboard.OnMButtonDown(x, y);
|
|
}
|
|
|
|
void C_4JInput::OnMButtonUp(int x, int y)
|
|
{
|
|
InternalKeyboard.OnMButtonUp(x, y);
|
|
}
|
|
|
|
void C_4JInput::OnMouseWheel(int delta, int x, int y)
|
|
{
|
|
InternalKeyboard.OnMouseWheel(delta, x, y);
|
|
}
|
|
|
|
void C_4JInput::SetMouseCaptured(bool captured)
|
|
{
|
|
InternalKeyboard.SetMouseCaptured(captured);
|
|
}
|
|
|
|
void C_4JInput::SetWindowFocused(bool focused)
|
|
{
|
|
InternalKeyboard.SetWindowFocused(focused);
|
|
}
|
|
|
|
bool C_4JInput::IsMouseCaptured() const
|
|
{
|
|
return InternalKeyboard.IsMouseCaptured();
|
|
}
|
|
|
|
void C_4JInput::SetMousePos(int x, int y)
|
|
{
|
|
InternalKeyboard.SetMousePos(x, y);
|
|
}
|
|
|
|
int C_4JInput::GetRawMouseX() const
|
|
{
|
|
return InternalKeyboard.GetRawMouseX();
|
|
}
|
|
|
|
int C_4JInput::GetRawMouseY() const
|
|
{
|
|
return InternalKeyboard.GetRawMouseY();
|
|
}
|
|
|
|
EKeyboardResult C_4JInput::RequestKeyboard(LPCWSTR Title, LPCWSTR Text, DWORD dwPad, UINT uiMaxChars, int (*Func)(LPVOID, const bool), LPVOID lpParam,
|
|
C_4JInput::EKeyboardMode eMode)
|
|
{
|
|
return InternalKeyboard.RequestKeyboard(Title, Text, dwPad, uiMaxChars, Func, lpParam, eMode);
|
|
}
|
|
|
|
void C_4JInput::GetText(uint16_t *UTF16String)
|
|
{
|
|
InternalKeyboard.GetText(UTF16String);
|
|
}
|
|
|
|
const char* C_4JInput::PollControllerType(int ipad) {
|
|
const char* GamepadType = InternalInputManager.GetGamepadType(ipad);
|
|
|
|
if (!GamepadType)
|
|
return "UNKNOWN";
|
|
|
|
if (strcmp(GamepadType, "SWITCH_PRO") == 0 ||
|
|
strcmp(GamepadType, "JOYCON_PAIR") == 0 ||
|
|
strcmp(GamepadType, "JOYCON_L") == 0 ||
|
|
strcmp(GamepadType, "JOYCON_R") == 0)
|
|
{
|
|
return "SWITCH";
|
|
}
|
|
|
|
return GamepadType; // str1k3r - if not one of the switch types, return the type itself
|
|
}
|
|
|
|
bool C_4JInput::VerifyStrings(WCHAR **pwStringA, int iStringC, int (*Func)(LPVOID, STRING_VERIFY_RESPONSE *), LPVOID lpParam)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
void C_4JInput::CancelQueuedVerifyStrings(int (*Func)(LPVOID, STRING_VERIFY_RESPONSE *), LPVOID lpParam) {}
|
|
|
|
void C_4JInput::CancelAllVerifyInProgress(void) {}
|
|
|
|
// bool C_4JInput::InputDetected(DWORD dwUserIndex,WCHAR *pwchInput) {}
|