[mousetrap/gnome3-wip: 96/240] Tweak the joystick a little
- From: Heidi Ellis <heidiellis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mousetrap/gnome3-wip: 96/240] Tweak the joystick a little
- Date: Mon, 8 Sep 2014 15:20:38 +0000 (UTC)
commit 9f72283be8180296aee7c840a60192959247eed7
Author: Kevin Brown <kbrown rediker com>
Date: Fri Jun 13 20:40:24 2014 -0400
Tweak the joystick a little
When the camera loses the location of the nose, it previously
stopped moving the cursor. Considering this is a joystick, and we
calculate the direction of the cursor constantly, we can assume the
user is still planning on moving in the last calculated direction.
This also moves the cursor relative to its position on the screen
instead of relative to the last calculated location. This allows
the cursor to be manually moved if needed, and it will still work
as expected without jumping the cursor to the last location.
src/mousetrap/gui.py | 1 +
src/mousetrap/pointers/nose_joystick.py | 37 ++++++++++++++++++++-----------
2 files changed, 25 insertions(+), 13 deletions(-)
---
diff --git a/src/mousetrap/gui.py b/src/mousetrap/gui.py
index 2dbe0e7..04c3e86 100644
--- a/src/mousetrap/gui.py
+++ b/src/mousetrap/gui.py
@@ -61,6 +61,7 @@ class ScreenPointer(object):
x_index = 1
y_index = 2
position = self._pointer.get_position()
+
return (position[x_index], position[y_index])
def set_position(self, position=None):
diff --git a/src/mousetrap/pointers/nose_joystick.py b/src/mousetrap/pointers/nose_joystick.py
index 7a3b4d4..202fa83 100644
--- a/src/mousetrap/pointers/nose_joystick.py
+++ b/src/mousetrap/pointers/nose_joystick.py
@@ -12,12 +12,12 @@ class Pointer(interface.Pointer):
self._nose_locator = NoseLocator()
self._image = None
- pointer = ScreenPointer()
+ self._pointer = ScreenPointer()
- self._last_pointer_location = pointer.get_position()
self._initial_image_location = (0, 0)
+ self._last_delta = (0, 0)
- self._location = self._last_pointer_location
+ self._location = self._pointer.get_position()
def update_image(self, image):
self._image = image
@@ -25,9 +25,25 @@ class Pointer(interface.Pointer):
try:
point_image = self._nose_locator.locate(image)
point_screen = self._convert_image_to_screen_point(*point_image)
+
self._location = point_screen
except FeatureNotFoundException:
- self._location = None
+ location = self._pointer.get_position()
+
+ self._location = self._apply_delta_to_point(location,
+ self._last_delta)
+
+ def _apply_delta_to_point(self, point, delta):
+ delta_x, delta_y = delta
+ point_x, point_y = point
+
+ if delta_x == 0 and delta_y == 0:
+ return None
+
+ point_x += delta_x
+ point_y += delta_y
+
+ return (point_x, point_y)
def _convert_image_to_screen_point(self, image_x, image_y):
initial_x, initial_y = self._initial_image_location
@@ -46,18 +62,13 @@ class Pointer(interface.Pointer):
if abs(delta_y) < self.THRESHOLD:
delta_y = 0
- if delta_x == 0 and delta_y == 0:
- return None
+ delta = (delta_x, delta_y)
- pointer_x, pointer_y = self._last_pointer_location
+ self._last_delta = delta
- pointer_x += delta_x
- pointer_y += delta_y
+ location = self._pointer.get_position()
- return (pointer_x, pointer_y)
+ return self._apply_delta_to_point(location, delta)
def get_new_position(self):
- if self._location:
- self._last_pointer_location = self._location
-
return self._location
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]