Browse Source

Auto white-out with a finger when using apple stylus (#167)

When using an iPad with an apple stylus, finger touches now trigger the whiteout tool.
This behavior can be disabled by setting the environment variable AUTO_FINGER_WHITEOUT=disabled

* Auto white-out with a finger when using stylus

* Add AUTO_FINGER_WHITEOUT config variable

* Use local variable to remember if stylus was used and make behavior configurable

* Delete "stylus" property

* Make AUTO_FINGER_WHITEOUT on by default

Co-authored-by: Ophir LOJKINE <pere.jobs@gmail.com>

* Delete parseBool, add note about iPad/Pencil

Co-authored-by: ishabalin <ishabalin@apple.com>
Co-authored-by: Ophir LOJKINE <pere.jobs@gmail.com>
dev_h
Ilya Shabalin 4 years ago
parent
commit
edf31cd6c2
No account linked to committer's email address
3 changed files with 31 additions and 0 deletions
  1. 26
    0
      client-data/tools/pencil/pencil.js
  2. 1
    0
      server/client_configuration.js
  3. 4
    0
      server/configuration.js

+ 26
- 0
client-data/tools/pencil/pencil.js View File

34
 	// than this?
34
 	// than this?
35
 	var MIN_PENCIL_INTERVAL_MS = Tools.server_config.MAX_EMIT_COUNT_PERIOD / Tools.server_config.MAX_EMIT_COUNT;
35
 	var MIN_PENCIL_INTERVAL_MS = Tools.server_config.MAX_EMIT_COUNT_PERIOD / Tools.server_config.MAX_EMIT_COUNT;
36
 
36
 
37
+	var AUTO_FINGER_WHITEOUT = Tools.server_config.AUTO_FINGER_WHITEOUT;
38
+	var hasUsedStylus = false;
39
+
37
 	//Indicates the id of the line the user is currently drawing or an empty string while the user is not drawing
40
 	//Indicates the id of the line the user is currently drawing or an empty string while the user is not drawing
38
 	var curLineId = "",
41
 	var curLineId = "",
39
 		lastTime = performance.now(); //The time at which the last point was drawn
42
 		lastTime = performance.now(); //The time at which the last point was drawn
46
 		this.y = y;
49
 		this.y = y;
47
 	}
50
 	}
48
 
51
 
52
+	function handleAutoWhiteOut(evt) {
53
+		if (evt.touches && evt.touches[0] && evt.touches[0].touchType == "stylus") {
54
+			//When using stylus, switch back to the primary
55
+			if (hasUsedStylus && Tools.curTool.secondary.active) {
56
+				Tools.change("Pencil");
57
+			}
58
+			//Remember if starting a line with a stylus
59
+			hasUsedStylus = true;
60
+		}
61
+		if (evt.touches && evt.touches[0] && evt.touches[0].touchType == "direct") {
62
+			//When used stylus and touched with a finger, switch to secondary
63
+			if (hasUsedStylus && !Tools.curTool.secondary.active) {
64
+				Tools.change("Pencil");
65
+			}
66
+		}
67
+	}
68
+
49
 	function startLine(x, y, evt) {
69
 	function startLine(x, y, evt) {
50
 
70
 
51
 		//Prevent the press from being interpreted by the browser
71
 		//Prevent the press from being interpreted by the browser
52
 		evt.preventDefault();
72
 		evt.preventDefault();
53
 
73
 
74
+		if (AUTO_FINGER_WHITEOUT) handleAutoWhiteOut(evt);
75
+
54
 		curLineId = Tools.generateUID("l"); //"l" for line
76
 		curLineId = Tools.generateUID("l"); //"l" for line
55
 
77
 
56
 		Tools.drawAndSend({
78
 		Tools.drawAndSend({
149
 			"release": stopLineAt,
171
 			"release": stopLineAt,
150
 		},
172
 		},
151
 		"draw": draw,
173
 		"draw": draw,
174
+		"onstart": function(oldTool) {
175
+			//Reset stylus
176
+			hasUsedStylus = false;
177
+		},
152
 		"secondary": {
178
 		"secondary": {
153
 			"name": "White-out",
179
 			"name": "White-out",
154
 			"icon": "tools/pencil/whiteout_tape.svg",
180
 			"icon": "tools/pencil/whiteout_tape.svg",

+ 1
- 0
server/client_configuration.js View File

6
   MAX_EMIT_COUNT: config.MAX_EMIT_COUNT,
6
   MAX_EMIT_COUNT: config.MAX_EMIT_COUNT,
7
   MAX_EMIT_COUNT_PERIOD: config.MAX_EMIT_COUNT_PERIOD,
7
   MAX_EMIT_COUNT_PERIOD: config.MAX_EMIT_COUNT_PERIOD,
8
   BLOCKED_TOOLS: config.BLOCKED_TOOLS,
8
   BLOCKED_TOOLS: config.BLOCKED_TOOLS,
9
+  AUTO_FINGER_WHITEOUT: config.AUTO_FINGER_WHITEOUT,
9
 };
10
 };

+ 4
- 0
server/configuration.js View File

41
 
41
 
42
   /** Blocked Tools. A comma-separated list of tools that should not appear on boards. */
42
   /** Blocked Tools. A comma-separated list of tools that should not appear on boards. */
43
   BLOCKED_TOOLS: (process.env["WBO_BLOCKED_TOOLS"] || "").split(","),
43
   BLOCKED_TOOLS: (process.env["WBO_BLOCKED_TOOLS"] || "").split(","),
44
+
45
+  /** Automatically switch to White-out on finger touch after drawing
46
+      with Pencil using a stylus. Only supported on iPad with Apple Pencil. */
47
+  AUTO_FINGER_WHITEOUT: process.env['AUTO_FINGER_WHITEOUT'] !== "disabled",
44
 };
48
 };

Loading…
Cancel
Save