summaryrefslogtreecommitdiffstats
path: root/tests/manual/html/pointer-events.html
blob: c6e7286628b1f89f59d58e663b0d9e0b59b62533 (plain)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Pointer event test</title>
  </head>
  <body>

<p>
    <canvas id="listener" width="500" height="500" style="border: silver 1px dotted;"></canvas>
</p>
<p>
    Touch this circle with a stylus. Its size indicates your pressure; its position is the angle between your stylus and your tablet device; and the radius is the rotation - if your tablet supports it.
</p>

  </body>
  <script>

var canvas = document.getElementById("listener");
var context = canvas.getContext('2d');

var eventName = [
    "pointerover",
    "pointerenter",
    "pointerdown",
    "pointermove",
    "pointerup",
    "pointercancel",
    "pointerout",
    "pointerleave",
    "gotpointercapture",
    "lostpointercapture"
];

for (var i = 0; i < eventName.length; i++) {
    canvas.addEventListener(eventName[i], function(ev) {
        drawCircle(ev.pressure, ev.tiltX, ev.tiltY, ev.twist);
    }, false);
}

drawCircle(0, 0, 0, 0);

function drawCircle(pressure, tiltX, tiltY, twist) {
    var centerX = canvas.width / 2 + tiltX;
    var centerY = canvas.height / 2 + tiltY;
    var radius = 100 + 100 * pressure;

    context.clearRect(0, 0, canvas.width, canvas.height);
    context.beginPath();
    context.arc(centerX,
                centerY,
                radius,
                0,
                2 * Math.PI,
                false);
    context.fillStyle = 'lightblue';
    context.fill();
    context.lineWidth = 3;
    context.strokeStyle = '#008B8B';
    context.stroke();

    context.beginPath();
    context.moveTo(centerX, centerY);
    context.lineTo(centerX + radius * Math.cos(twist), centerY + radius * Math.sin(twist));
    context.stroke();
}

</script>
</html>