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,27 +12,26 @@ 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)
MouseWrapper.move(0, 1); MouseWrapper.move(0, 1);
if (mouseMoveIntent & KEY_MOUSE_LEFT) if (mouseMoveIntent & KEY_MOUSE_LEFT)
MouseWrapper.move(-1, 0); MouseWrapper.move(-1, 0);
else if (mouseMoveIntent & KEY_MOUSE_RIGHT) else if (mouseMoveIntent & KEY_MOUSE_RIGHT)
MouseWrapper.move(1, 0); MouseWrapper.move(1, 0);
} }
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();
Mouse.move(moveX, moveY, 0);
end_warping();
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