mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-11-22 18:53:28 +01:00
overlays: make auto-repeat buttons configurable
and properly reset the auto-repeat timer whenever a new button was pressed
This commit is contained in:
parent
bdc5ed094b
commit
20c69a0e3e
@ -10,6 +10,15 @@ namespace rsx
|
||||
{
|
||||
namespace overlays
|
||||
{
|
||||
osk_dialog::osk_dialog()
|
||||
{
|
||||
auto_repeat_buttons.insert(pad_button::L1);
|
||||
auto_repeat_buttons.insert(pad_button::R1);
|
||||
auto_repeat_buttons.insert(pad_button::cross);
|
||||
auto_repeat_buttons.insert(pad_button::triangle);
|
||||
auto_repeat_buttons.insert(pad_button::square);
|
||||
}
|
||||
|
||||
void osk_dialog::Close(bool ok)
|
||||
{
|
||||
fade_animation.current = color4f(1.f);
|
||||
|
@ -78,7 +78,7 @@ namespace rsx
|
||||
std::vector<osk_panel> m_panels;
|
||||
usz m_panel_index = 0;
|
||||
|
||||
osk_dialog() = default;
|
||||
osk_dialog();
|
||||
~osk_dialog() override = default;
|
||||
|
||||
void Create(const std::string& title, const std::u16string& message, char16_t* init_text, u32 charlimit, u32 prohibit_flags, u32 panel_flag, u32 first_view_panel) override;
|
||||
|
@ -51,10 +51,13 @@ namespace rsx
|
||||
std::array<steady_clock::time_point, CELL_PAD_MAX_PORT_NUM> initial_timestamp;
|
||||
initial_timestamp.fill(steady_clock::now());
|
||||
|
||||
std::array<std::array<bool, pad_button::pad_button_max_enum>, CELL_PAD_MAX_PORT_NUM> button_state;
|
||||
for (auto& state : button_state)
|
||||
std::array<u8, CELL_PAD_MAX_PORT_NUM> last_auto_repeat_button;
|
||||
last_auto_repeat_button.fill(pad_button::pad_button_max_enum);
|
||||
|
||||
std::array<std::array<bool, pad_button::pad_button_max_enum>, CELL_PAD_MAX_PORT_NUM> last_button_state;
|
||||
for (auto& state : last_button_state)
|
||||
{
|
||||
state.fill(true);
|
||||
state.fill(false);
|
||||
}
|
||||
|
||||
input_timer.Start();
|
||||
@ -90,7 +93,7 @@ namespace rsx
|
||||
|
||||
for (auto &button : pad->m_buttons)
|
||||
{
|
||||
u8 button_id = 255;
|
||||
u8 button_id = pad_button::pad_button_max_enum;
|
||||
if (button.m_offset == CELL_PAD_BTN_OFFSET_DIGITAL1)
|
||||
{
|
||||
switch (button.m_outKeyCode)
|
||||
@ -148,34 +151,44 @@ namespace rsx
|
||||
}
|
||||
}
|
||||
|
||||
if (button_id < 255)
|
||||
if (button_id < pad_button::pad_button_max_enum)
|
||||
{
|
||||
if (button.m_pressed)
|
||||
{
|
||||
if (button_id < 4) // d-pad button
|
||||
const bool is_auto_repeat_button = auto_repeat_buttons.contains(button_id);
|
||||
|
||||
if (!last_button_state[pad_index][button_id])
|
||||
{
|
||||
if (!button_state[pad_index][button_id])
|
||||
{
|
||||
// the d-pad button was not pressed before, so this is a new button press
|
||||
// The button was not pressed before, so this is a new button press. Reset auto-repeat.
|
||||
timestamp[pad_index] = steady_clock::now();
|
||||
initial_timestamp[pad_index] = timestamp[pad_index];
|
||||
last_auto_repeat_button[pad_index] = is_auto_repeat_button ? button_id : pad_button::pad_button_max_enum;
|
||||
on_button_pressed(static_cast<pad_button>(button_id));
|
||||
}
|
||||
else if (input_timer.GetMsSince(initial_timestamp[pad_index]) > ms_threshold && input_timer.GetMsSince(timestamp[pad_index]) > ms_interval)
|
||||
else if (is_auto_repeat_button)
|
||||
{
|
||||
// the d-pad button was pressed for at least the given threshold in ms and will trigger at an interval
|
||||
if (last_auto_repeat_button[pad_index] == button_id
|
||||
&& input_timer.GetMsSince(initial_timestamp[pad_index]) > ms_threshold
|
||||
&& input_timer.GetMsSince(timestamp[pad_index]) > ms_interval)
|
||||
{
|
||||
// The auto-repeat button was pressed for at least the given threshold in ms and will trigger at an interval.
|
||||
timestamp[pad_index] = steady_clock::now();
|
||||
on_button_pressed(static_cast<pad_button>(button_id));
|
||||
}
|
||||
}
|
||||
else if (!button_state[pad_index][button_id])
|
||||
else if (last_auto_repeat_button[pad_index] == pad_button::pad_button_max_enum)
|
||||
{
|
||||
// the button was not pressed before, so this is a new button press
|
||||
on_button_pressed(static_cast<pad_button>(button_id));
|
||||
// An auto-repeat button was already pressed before and will now start triggering again after the next threshold.
|
||||
last_auto_repeat_button[pad_index] = button_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (last_button_state[pad_index][button_id] && last_auto_repeat_button[pad_index] == button_id)
|
||||
{
|
||||
// We stopped pressing an auto-repeat button, so re-enable auto-repeat for other buttons.
|
||||
last_auto_repeat_button[pad_index] = pad_button::pad_button_max_enum;
|
||||
}
|
||||
|
||||
button_state[pad_index][button_id] = button.m_pressed;
|
||||
last_button_state[pad_index][button_id] = button.m_pressed;
|
||||
}
|
||||
|
||||
if (exit)
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "Utilities/Timer.h"
|
||||
|
||||
#include <mutex>
|
||||
#include <set>
|
||||
|
||||
|
||||
// Definition of user interface implementations
|
||||
@ -69,6 +70,7 @@ namespace rsx
|
||||
|
||||
protected:
|
||||
Timer input_timer;
|
||||
std::set<u8> auto_repeat_buttons = { pad_button::dpad_up, pad_button::dpad_down, pad_button::dpad_left, pad_button::dpad_right };
|
||||
atomic_t<bool> exit = false;
|
||||
atomic_t<u64> thread_bits = 0;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user