-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTextAreaTouchZone.pde
47 lines (39 loc) · 1.5 KB
/
TextAreaTouchZone.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
static class TextAreaTouchZone extends Zone {
protected final TextArea textArea;
protected boolean isTap;
protected long tapStartTimeMillis;
public TextAreaTouchZone(final String name, final TextArea textArea) {
super(name, textArea.x, textArea.y, textArea.width, textArea.height);
this.textArea = textArea;
}
@Override public void touchDown(final Touch touch) {
isTap = getNumTouches() == 1;
if (isTap) {
tapStartTimeMillis = System.currentTimeMillis();
}
}
@Override public void touchUp(final Touch touch) {
if (getNumTouches() == 0) {
if (isTap) {
if (abs(System.currentTimeMillis() - tapStartTimeMillis) < 500 && textArea.hasSelection()) {
textArea.setSelection(0, 0);
textArea.notifyObservers(new TextSelectionEvent(0, 0, 0, 0, false, false));
} else if (!textArea.hasSelection()) {
final TextPosition tp = textArea.getTextPositionByInnerPoint(textArea.getInnerPointByPoint(touch.x, touch.y));
textArea.setSelection(tp.offset, tp.offset + tp.toward);
textArea.notifyObservers(new TextSelectionEvent(textArea.getSelectionStart(), tp.row, textArea.getSelectionEnd(), tp.row, true, false));
}
}
}
isTap = false;
}
@Override public void touchMoved(final Touch touch) {
final Point lp = touch.getLastPoint();
isTap = isTap && (lp == null || lp.x == touch.x && lp.y == touch.y);
}
@Override public void touch() {
}
@Override public void draw() {
textArea.draw();
}
}