@@ -12,7 +12,7 @@ import scalafx.scene.control.Alert.AlertType
12
12
/**
13
13
* Created by Chris on 8/4/2015. This class actually handles the trackball emulation
14
14
*/
15
- class Engine (pollingRate : Option [ Double ], startupThreshold : Option [ Double ], giveupThreshold : Option [ Double ], drag : Option [ Double ] ) extends Runnable {
15
+ class Engine (config : Config ) extends Runnable {
16
16
17
17
// Setting up engine
18
18
val robot = new Robot
@@ -61,15 +61,15 @@ class Engine(pollingRate: Option[Double], startupThreshold: Option[Double], give
61
61
// Reset click tracking
62
62
clicked = false
63
63
// Poll for mouse movement and give time to detect clicks
64
- Thread .sleep(pollingRate.getOrElse(10.00 ).toInt)
64
+ Thread .sleep(config. pollingRate.getOrElse(10.00 ).toInt)
65
65
val startPos = new Point2D (mouseX, mouseY)
66
- Thread .sleep(pollingRate.getOrElse(10.00 ).toInt)
66
+ Thread .sleep(config. pollingRate.getOrElse(10.00 ).toInt)
67
67
val endPos = new Point2D (mouseX, mouseY)
68
68
69
69
// If this movement was significant
70
- if (! startPos.almostEquals(endPos, giveupThreshold.getOrElse(1 )) || clicked){
70
+ if (! startPos.almostEquals(endPos, config. giveupThreshold.getOrElse(1 )) || clicked){
71
71
// If this movement was violent
72
- if (! startPos.almostEquals(endPos, startupThreshold.getOrElse(5 ))) {
72
+ if (! startPos.almostEquals(endPos, config. startupThreshold.getOrElse(5 ))) {
73
73
// Use the last polled movement as the new trackball speed
74
74
lastVector = new Vector2D (startPos, endPos)
75
75
}else {
@@ -83,7 +83,7 @@ class Engine(pollingRate: Option[Double], startupThreshold: Option[Double], give
83
83
// Move the mouse according to the last trackball speed
84
84
robot.mouseMove((endPos.x + lastVector.x).toInt, (endPos.y + lastVector.y).toInt)
85
85
// Apply friction to trackball
86
- lastVector = new Vector2D (lastVector.x * drag.getOrElse(.95 ), lastVector.y * drag.getOrElse(.95 ))
86
+ lastVector = new Vector2D (lastVector.x * config. drag.getOrElse(.95 ), lastVector.y * config. drag.getOrElse(.95 ))
87
87
// If the trackball is almost stopped, stop it
88
88
if (lastVector.almostEquals(noVector, 2 )){
89
89
lastVector = noVector
0 commit comments