mirror of
https://github.com/TomHarte/CLK.git
synced 2025-01-11 08:30:55 +00:00
Switch to std::clamp
.
This commit is contained in:
parent
8b38c567d2
commit
f8e8f18be5
@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
#include "Mouse.hpp"
|
#include "Mouse.hpp"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
using namespace Apple::ADB;
|
using namespace Apple::ADB;
|
||||||
|
|
||||||
Mouse::Mouse(Bus &bus) : ReactiveDevice(bus, 3) {}
|
Mouse::Mouse(Bus &bus) : ReactiveDevice(bus, 3) {}
|
||||||
@ -20,8 +22,8 @@ void Mouse::perform_command(const Command &command) {
|
|||||||
const int buttons = button_flags_;
|
const int buttons = button_flags_;
|
||||||
|
|
||||||
// Clamp deltas.
|
// Clamp deltas.
|
||||||
delta_x = std::max(std::min(delta_x, int16_t(127)), int16_t(-128));
|
delta_x = std::clamp(delta_x, int16_t(-128), int16_t(127));
|
||||||
delta_y = std::max(std::min(delta_y, int16_t(127)), int16_t(-128));
|
delta_y = std::clamp(delta_y, int16_t(-128), int16_t(127));
|
||||||
|
|
||||||
// Figure out what that would look like, and don't respond if there's
|
// Figure out what that would look like, and don't respond if there's
|
||||||
// no change to report.
|
// no change to report.
|
||||||
|
@ -68,8 +68,8 @@ void IntelligentKeyboard::run_for(HalfCycles duration) {
|
|||||||
mouse_position_[1] += mouse_y_multiplier_ * scaled_movement[1];
|
mouse_position_[1] += mouse_y_multiplier_ * scaled_movement[1];
|
||||||
|
|
||||||
// Clamp to range.
|
// Clamp to range.
|
||||||
mouse_position_[0] = std::min(std::max(mouse_position_[0], 0), mouse_range_[0]);
|
mouse_position_[0] = std::clamp(mouse_position_[0], 0, mouse_range_[0]);
|
||||||
mouse_position_[1] = std::min(std::max(mouse_position_[1], 0), mouse_range_[1]);
|
mouse_position_[1] = std::clamp(mouse_position_[1], 0, mouse_range_[1]);
|
||||||
|
|
||||||
mouse_movement_[0] -= scaled_movement[0] * mouse_scale_[0];
|
mouse_movement_[0] -= scaled_movement[0] * mouse_scale_[0];
|
||||||
mouse_movement_[1] -= scaled_movement[1] * mouse_scale_[1];
|
mouse_movement_[1] -= scaled_movement[1] * mouse_scale_[1];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user