fusuma 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 46afda55ad48083da6e0d94a17a9ec3b1a009b4b
4
- data.tar.gz: 475fabc77f03056b25f9b718c26875bc75871380
3
+ metadata.gz: 216f8562a1a8273c5067e09b85d558669ad8b929
4
+ data.tar.gz: 19dd9a739ae9e3050dc5ac121d66499b3c084000
5
5
  SHA512:
6
- metadata.gz: 87b72d664ca8e7891f02265030fe261f7576b7de85ef55aad28f81809d06eaf29a4d016359375b1dae05847f4c13d86a752254fe65b7da9492e09b0b7ed9fa4e
7
- data.tar.gz: fa163ef797185c55af24204466f8bb48f80d01fcbf1571973b3e7e51c495982186df767b7114280cdba4b7cadb8061b1c7259e8d79b64213eaccddd6dfbb971b
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.
@@ -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? && enough_time_passed?
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 elapsed_time
28
- return 0 if length.zero?
29
- last.time - first.time
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 detect_direction(action_type)
35
+ def generate_vector(action_type)
33
36
  case action_type
34
37
  when 'swipe'
35
- detect_swipe
38
+ avg_swipe
36
39
  when 'pinch'
37
- detect_pinch
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
- (length > 1) && (elapsed_time > 0.05)
80
+ length > 2
90
81
  end
91
82
 
92
- def enough_time_passed?
93
- (last.time - last_triggerd_time) > 0.5
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 last_triggerd_time
88
+ def last_triggered_time
97
89
  @last_triggered_time ||= 0
98
90
  end
99
91
 
@@ -21,7 +21,7 @@ pinch:
21
21
  in:
22
22
  shortcut: 'ctrl+plus'
23
23
  out:
24
- shortcut: 'ctrl+minus'
24
+ shortcut: 'ctrl+minus'
25
25
 
26
26
  threshold:
27
27
  swipe: 1
data/lib/fusuma/pinch.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  module Fusuma
2
- # manage actions
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 enough_diameter?
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
- # manage actions
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 enough_distance?
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
@@ -1,3 +1,3 @@
1
1
  module Fusuma
2
- VERSION = '0.2.2'.freeze
2
+ VERSION = '0.2.3'.freeze
3
3
  end
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.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: 2016-12-31 00:00:00.000000000 Z
11
+ date: 2017-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler