fusuma 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +7 -0
- data/lib/fusuma/action_stack.rb +15 -23
- data/lib/fusuma/config.yml +1 -1
- data/lib/fusuma/pinch.rb +27 -2
- data/lib/fusuma/swipe.rb +27 -2
- data/lib/fusuma/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 216f8562a1a8273c5067e09b85d558669ad8b929
|
4
|
+
data.tar.gz: 19dd9a739ae9e3050dc5ac121d66499b3c084000
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0c05bba807ab4569b2de22142713cc1a45c66b783e90785c7195bf58e39249a4d6b31a7a1ad72cb16b7275e62ad896a579c1fb214de4187f1b0df7cdb93ddc3
|
7
|
+
data.tar.gz: 07d4d793259309e26b5809cd5d8d7005ccb36b2de07dc6595e3a28ac17b45572e24ef77871549198085e3d90804a1f52c76bcbe103abfeea7537400589fdab82
|
data/README.md
CHANGED
@@ -61,10 +61,17 @@ pinch:
|
|
61
61
|
shortcut: 'ctrl+plus'
|
62
62
|
out:
|
63
63
|
shortcut: 'ctrl+minus'
|
64
|
+
|
65
|
+
threshold:
|
66
|
+
swipe: 1
|
67
|
+
pinch: 1
|
64
68
|
```
|
65
69
|
|
66
70
|
if `shortcut: ` is blank, the swipe/pinch doesn't trigger a keyevent.
|
67
71
|
|
72
|
+
`threshold:` is sensitivity to swipe/pinch. Default value is 1.
|
73
|
+
if the swipe's threshold change to `0.5`, shorten swipe-length by half
|
74
|
+
|
68
75
|
## Options
|
69
76
|
|
70
77
|
* `-v` : Enable debug mode.
|
data/lib/fusuma/action_stack.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
module Fusuma
|
2
2
|
# manage actions
|
3
3
|
class ActionStack < Array
|
4
|
+
ELAPSED_TIME = 0.01
|
5
|
+
|
4
6
|
def initialize(*args)
|
5
7
|
super(*args)
|
6
8
|
end
|
7
9
|
|
8
10
|
def gesture_info
|
9
|
-
return unless enough_actions?
|
11
|
+
return unless enough_actions?
|
10
12
|
action_type = detect_action_type
|
11
13
|
direction = detect_direction(action_type)
|
12
14
|
return if direction.nil?
|
@@ -24,32 +26,21 @@ module Fusuma
|
|
24
26
|
|
25
27
|
private
|
26
28
|
|
27
|
-
def
|
28
|
-
|
29
|
-
|
29
|
+
def detect_direction(action_type)
|
30
|
+
vector = generate_vector(action_type)
|
31
|
+
return if vector && !vector.enough?
|
32
|
+
vector.direction
|
30
33
|
end
|
31
34
|
|
32
|
-
def
|
35
|
+
def generate_vector(action_type)
|
33
36
|
case action_type
|
34
37
|
when 'swipe'
|
35
|
-
|
38
|
+
avg_swipe
|
36
39
|
when 'pinch'
|
37
|
-
|
40
|
+
avg_pinch
|
38
41
|
end
|
39
42
|
end
|
40
43
|
|
41
|
-
def detect_swipe
|
42
|
-
swipe = avg_swipe
|
43
|
-
return unless swipe.enough_distance?
|
44
|
-
swipe.direction
|
45
|
-
end
|
46
|
-
|
47
|
-
def detect_pinch
|
48
|
-
pinch = avg_pinch
|
49
|
-
return unless pinch.enough_diameter?
|
50
|
-
pinch.direction
|
51
|
-
end
|
52
|
-
|
53
44
|
def detect_finger
|
54
45
|
last.finger
|
55
46
|
end
|
@@ -86,14 +77,15 @@ module Fusuma
|
|
86
77
|
end
|
87
78
|
|
88
79
|
def enough_actions?
|
89
|
-
|
80
|
+
length > 2
|
90
81
|
end
|
91
82
|
|
92
|
-
def
|
93
|
-
|
83
|
+
def enough_elapsed_time?
|
84
|
+
return false if length.zero?
|
85
|
+
(last.time - first.time) > ELAPSED_TIME
|
94
86
|
end
|
95
87
|
|
96
|
-
def
|
88
|
+
def last_triggered_time
|
97
89
|
@last_triggered_time ||= 0
|
98
90
|
end
|
99
91
|
|
data/lib/fusuma/config.yml
CHANGED
data/lib/fusuma/pinch.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
module Fusuma
|
2
|
-
#
|
2
|
+
# vector data
|
3
3
|
class Pinch
|
4
4
|
BASE_THERESHOLD = 0.3
|
5
|
+
INTERVAL_TIME = 0.05
|
5
6
|
|
6
7
|
def initialize(diameter)
|
7
8
|
@diameter = diameter.to_f
|
@@ -14,13 +15,37 @@ module Fusuma
|
|
14
15
|
'out'
|
15
16
|
end
|
16
17
|
|
17
|
-
def
|
18
|
+
def enough?
|
18
19
|
MultiLogger.debug(diameter: diameter)
|
20
|
+
enough_diameter? && enough_interval? && self.class.touch_last_time
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def enough_diameter?
|
19
26
|
diameter.abs > threshold
|
20
27
|
end
|
21
28
|
|
29
|
+
def enough_interval?
|
30
|
+
return true if first_time?
|
31
|
+
return true if (Time.now - self.class.last_time) > INTERVAL_TIME
|
32
|
+
false
|
33
|
+
end
|
34
|
+
|
35
|
+
def first_time?
|
36
|
+
self.class.last_time.nil?
|
37
|
+
end
|
38
|
+
|
22
39
|
def threshold
|
23
40
|
@threshold ||= BASE_THERESHOLD * Config.threshold('pinch')
|
24
41
|
end
|
42
|
+
|
43
|
+
class << self
|
44
|
+
attr_reader :last_time
|
45
|
+
|
46
|
+
def touch_last_time
|
47
|
+
@last_time = Time.now
|
48
|
+
end
|
49
|
+
end
|
25
50
|
end
|
26
51
|
end
|
data/lib/fusuma/swipe.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
module Fusuma
|
2
|
-
#
|
2
|
+
# vector data
|
3
3
|
class Swipe
|
4
4
|
BASE_THERESHOLD = 20
|
5
|
+
INTERVAL_TIME = 0.5
|
5
6
|
|
6
7
|
def initialize(x, y)
|
7
8
|
@x = x
|
@@ -14,13 +15,37 @@ module Fusuma
|
|
14
15
|
y > 0 ? 'down' : 'up'
|
15
16
|
end
|
16
17
|
|
17
|
-
def
|
18
|
+
def enough?
|
18
19
|
MultiLogger.debug(x: x, y: y)
|
20
|
+
enough_distance? && enough_interval? && self.class.touch_last_time
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def enough_distance?
|
19
26
|
(x.abs > threshold) || (y.abs > threshold)
|
20
27
|
end
|
21
28
|
|
29
|
+
def enough_interval?
|
30
|
+
return true if first_time?
|
31
|
+
return true if (Time.now - self.class.last_time) > INTERVAL_TIME
|
32
|
+
false
|
33
|
+
end
|
34
|
+
|
35
|
+
def first_time?
|
36
|
+
self.class.last_time.nil?
|
37
|
+
end
|
38
|
+
|
22
39
|
def threshold
|
23
40
|
@threshold ||= BASE_THERESHOLD * Config.threshold('swipe')
|
24
41
|
end
|
42
|
+
|
43
|
+
class << self
|
44
|
+
attr_reader :last_time
|
45
|
+
|
46
|
+
def touch_last_time
|
47
|
+
@last_time = Time.now
|
48
|
+
end
|
49
|
+
end
|
25
50
|
end
|
26
51
|
end
|
data/lib/fusuma/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fusuma
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- iberianpig
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|