diff options
Diffstat (limited to '')
| -rw-r--r-- | src/yuzu/configuration/configure_input_player_widget.cpp | 51 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input_player_widget.h | 1 |
2 files changed, 37 insertions, 15 deletions
diff --git a/src/yuzu/configuration/configure_input_player_widget.cpp b/src/yuzu/configuration/configure_input_player_widget.cpp index 1b0665805..1e3251547 100644 --- a/src/yuzu/configuration/configure_input_player_widget.cpp +++ b/src/yuzu/configuration/configure_input_player_widget.cpp | |||
| @@ -11,10 +11,10 @@ | |||
| 11 | PlayerControlPreview::PlayerControlPreview(QWidget* parent) : QFrame(parent) { | 11 | PlayerControlPreview::PlayerControlPreview(QWidget* parent) : QFrame(parent) { |
| 12 | UpdateColors(); | 12 | UpdateColors(); |
| 13 | QTimer* timer = new QTimer(this); | 13 | QTimer* timer = new QTimer(this); |
| 14 | connect(timer, &QTimer::timeout, this, QOverload<>::of(&PlayerControlPreview::update)); | 14 | connect(timer, &QTimer::timeout, this, QOverload<>::of(&PlayerControlPreview::UpdateInput)); |
| 15 | 15 | ||
| 16 | // refresh at 40hz | 16 | // refresh at 60hz |
| 17 | timer->start(25); | 17 | timer->start(16); |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | PlayerControlPreview::~PlayerControlPreview() = default; | 20 | PlayerControlPreview::~PlayerControlPreview() = default; |
| @@ -155,12 +155,8 @@ void PlayerControlPreview::UpdateColors() { | |||
| 155 | // colors.right = QColor(Settings::values.players.GetValue()[player_index].body_color_right); | 155 | // colors.right = QColor(Settings::values.players.GetValue()[player_index].body_color_right); |
| 156 | } | 156 | } |
| 157 | 157 | ||
| 158 | void PlayerControlPreview::paintEvent(QPaintEvent* event) { | 158 | void PlayerControlPreview::UpdateInput() { |
| 159 | QFrame::paintEvent(event); | 159 | bool input_changed = false; |
| 160 | QPainter p(this); | ||
| 161 | p.setRenderHint(QPainter::Antialiasing); | ||
| 162 | const QPointF center = rect().center(); | ||
| 163 | |||
| 164 | const auto& button_state = buttons; | 160 | const auto& button_state = buttons; |
| 165 | for (std::size_t index = 0; index < button_values.size(); ++index) { | 161 | for (std::size_t index = 0; index < button_values.size(); ++index) { |
| 166 | bool value = false; | 162 | bool value = false; |
| @@ -169,7 +165,10 @@ void PlayerControlPreview::paintEvent(QPaintEvent* event) { | |||
| 169 | } | 165 | } |
| 170 | bool blink = mapping_active && index == button_mapping_index; | 166 | bool blink = mapping_active && index == button_mapping_index; |
| 171 | if (analog_mapping_index == Settings::NativeAnalog::NUM_STICKS_HID) { | 167 | if (analog_mapping_index == Settings::NativeAnalog::NUM_STICKS_HID) { |
| 172 | blink &= blink_counter > 12; | 168 | blink &= blink_counter > 25; |
| 169 | } | ||
| 170 | if (button_values[index] != value || blink) { | ||
| 171 | input_changed = true; | ||
| 173 | } | 172 | } |
| 174 | button_values[index] = value || blink; | 173 | button_values[index] = value || blink; |
| 175 | } | 174 | } |
| @@ -178,17 +177,42 @@ void PlayerControlPreview::paintEvent(QPaintEvent* event) { | |||
| 178 | for (std::size_t index = 0; index < axis_values.size(); ++index) { | 177 | for (std::size_t index = 0; index < axis_values.size(); ++index) { |
| 179 | const auto [stick_x_f, stick_y_f] = analog_state[index]->GetStatus(); | 178 | const auto [stick_x_f, stick_y_f] = analog_state[index]->GetStatus(); |
| 180 | const auto [stick_x_rf, stick_y_rf] = analog_state[index]->GetRawStatus(); | 179 | const auto [stick_x_rf, stick_y_rf] = analog_state[index]->GetRawStatus(); |
| 180 | |||
| 181 | if (static_cast<int>(stick_x_rf * 45) != | ||
| 182 | static_cast<int>(axis_values[index].raw_value.x() * 45) || | ||
| 183 | static_cast<int>(-stick_y_rf * 45) != | ||
| 184 | static_cast<int>(axis_values[index].raw_value.y() * 45)) { | ||
| 185 | input_changed = true; | ||
| 186 | } | ||
| 187 | |||
| 181 | axis_values[index].properties = analog_state[index]->GetAnalogProperties(); | 188 | axis_values[index].properties = analog_state[index]->GetAnalogProperties(); |
| 182 | axis_values[index].value = QPointF(stick_x_f, -stick_y_f); | 189 | axis_values[index].value = QPointF(stick_x_f, -stick_y_f); |
| 183 | axis_values[index].raw_value = QPointF(stick_x_rf, -stick_y_rf); | 190 | axis_values[index].raw_value = QPointF(stick_x_rf, -stick_y_rf); |
| 184 | 191 | ||
| 185 | const bool blink_analog = mapping_active && index == analog_mapping_index; | 192 | const bool blink_analog = mapping_active && index == analog_mapping_index; |
| 186 | if (blink_analog) { | 193 | if (blink_analog) { |
| 194 | input_changed = true; | ||
| 187 | axis_values[index].value = | 195 | axis_values[index].value = |
| 188 | QPointF(blink_counter < 12 ? -blink_counter / 12.0f : 0, | 196 | QPointF(blink_counter < 25 ? -blink_counter / 25.0f : 0, |
| 189 | blink_counter > 12 ? -(blink_counter - 12) / 12.0f : 0); | 197 | blink_counter > 25 ? -(blink_counter - 25) / 25.0f : 0); |
| 190 | } | 198 | } |
| 191 | } | 199 | } |
| 200 | |||
| 201 | if (input_changed) { | ||
| 202 | update(); | ||
| 203 | } | ||
| 204 | |||
| 205 | if (mapping_active) { | ||
| 206 | blink_counter = (blink_counter + 1) % 50; | ||
| 207 | } | ||
| 208 | } | ||
| 209 | |||
| 210 | void PlayerControlPreview::paintEvent(QPaintEvent* event) { | ||
| 211 | QFrame::paintEvent(event); | ||
| 212 | QPainter p(this); | ||
| 213 | p.setRenderHint(QPainter::Antialiasing); | ||
| 214 | const QPointF center = rect().center(); | ||
| 215 | |||
| 192 | switch (controller_type) { | 216 | switch (controller_type) { |
| 193 | case Settings::ControllerType::Handheld: | 217 | case Settings::ControllerType::Handheld: |
| 194 | DrawHandheldController(p, center); | 218 | DrawHandheldController(p, center); |
| @@ -207,9 +231,6 @@ void PlayerControlPreview::paintEvent(QPaintEvent* event) { | |||
| 207 | DrawProController(p, center); | 231 | DrawProController(p, center); |
| 208 | break; | 232 | break; |
| 209 | } | 233 | } |
| 210 | if (mapping_active) { | ||
| 211 | blink_counter = (blink_counter + 1) % 24; | ||
| 212 | } | ||
| 213 | } | 234 | } |
| 214 | 235 | ||
| 215 | void PlayerControlPreview::DrawLeftController(QPainter& p, const QPointF center) { | 236 | void PlayerControlPreview::DrawLeftController(QPainter& p, const QPointF center) { |
diff --git a/src/yuzu/configuration/configure_input_player_widget.h b/src/yuzu/configuration/configure_input_player_widget.h index 7d0653faa..33a5482ba 100644 --- a/src/yuzu/configuration/configure_input_player_widget.h +++ b/src/yuzu/configuration/configure_input_player_widget.h | |||
| @@ -32,6 +32,7 @@ public: | |||
| 32 | void BeginMappingButton(std::size_t button_id); | 32 | void BeginMappingButton(std::size_t button_id); |
| 33 | void BeginMappingAnalog(std::size_t button_id); | 33 | void BeginMappingAnalog(std::size_t button_id); |
| 34 | void EndMapping(); | 34 | void EndMapping(); |
| 35 | void UpdateInput(); | ||
| 35 | 36 | ||
| 36 | protected: | 37 | protected: |
| 37 | void paintEvent(QPaintEvent* event) override; | 38 | void paintEvent(QPaintEvent* event) override; |