Use a single accel counter

Instead of calculating separate acceleration for the x and y axes, use only a
single one, that applies to both axes. Thus, holding mouse up, and then pressing
and holding right will move the mouse cursor in a straight diagonal line,
instead of a curve.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/365/head
Gergely Nagy 8 years ago
parent c782eb7275
commit 41d57b598a

@ -12,6 +12,14 @@ static void loopHook(bool postClear) {
return; return;
} }
if (mouseMoveIntent == 0) {
MouseWrapper.mouseActiveForCycles = 0;
return;
}
if (MouseWrapper.mouseActiveForCycles < 255)
MouseWrapper.mouseActiveForCycles++;
if (mouseMoveIntent & KEY_MOUSE_UP) if (mouseMoveIntent & KEY_MOUSE_UP)
MouseWrapper.move(0, -1); MouseWrapper.move(0, -1);
else if (mouseMoveIntent & KEY_MOUSE_DOWN) else if (mouseMoveIntent & KEY_MOUSE_DOWN)
@ -24,15 +32,6 @@ static void loopHook(bool postClear) {
} }
static void handle_mouse_key_event(Key mappedKey, uint8_t keyState) { static void handle_mouse_key_event(Key mappedKey, uint8_t keyState) {
if (key_toggled_off(keyState)) {
if (mappedKey.keyCode & KEY_MOUSE_UP || mappedKey.keyCode & KEY_MOUSE_DOWN) {
MouseWrapper.mouseActiveForCyclesY=0;
}
if (mappedKey.keyCode & KEY_MOUSE_LEFT || mappedKey.keyCode & KEY_MOUSE_RIGHT) {
MouseWrapper.mouseActiveForCyclesX=0;
}
}
if (!key_is_pressed(keyState)) if (!key_is_pressed(keyState))
return; return;

@ -103,18 +103,14 @@ void MouseWrapper_::move( int8_t x, int8_t y) {
int16_t moveX =0; int16_t moveX =0;
int16_t moveY = 0; int16_t moveY = 0;
if (x != 0 ) { if (x != 0 ) {
if (mouseActiveForCyclesX < 255) { mouseActiveForCyclesX++;} moveX = (x * acceleration(mouseActiveForCycles));
moveX = (x * acceleration(mouseActiveForCyclesX));
} }
if (y != 0) { if (y != 0) {
if (mouseActiveForCyclesY < 255) { mouseActiveForCyclesY++;} moveY = (y * acceleration(mouseActiveForCycles));
moveY = (y * acceleration(mouseActiveForCyclesY));
} }
end_warping(); end_warping();
Mouse.move(moveX, moveY, 0); Mouse.move(moveX, moveY, 0);
} }
MouseWrapper_ MouseWrapper; MouseWrapper_ MouseWrapper;

@ -37,8 +37,7 @@ class MouseWrapper_ {
void warp(uint8_t warp_cmd); void warp(uint8_t warp_cmd);
void press_button(uint8_t button); void press_button(uint8_t button);
void release_button(uint8_t button); void release_button(uint8_t button);
uint8_t mouseActiveForCyclesX = 0; uint8_t mouseActiveForCycles = 0;
uint8_t mouseActiveForCyclesY = 0;
private: private:
uint16_t next_width = 0; uint16_t next_width = 0;
@ -53,4 +52,5 @@ class MouseWrapper_ {
void warp_jump(uint16_t left, uint16_t top, uint16_t height, uint16_t width); void warp_jump(uint16_t left, uint16_t top, uint16_t height, uint16_t width);
}; };
extern MouseWrapper_ MouseWrapper; extern MouseWrapper_ MouseWrapper;

Loading…
Cancel
Save