~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/glut_touchevents.c

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-09-20 22:44:35 UTC
  • mfrom: (4.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20130920224435-apuwj4fsl3fqv1a6
Tags: 1.5.6~20130920~6010666-1
* New snapshot release
* Update the list of supported architectures to the same as libv8
  (Closes: #723129)
* emlibtool has been removed from upstream.
* Fix warning syntax-error-in-dep5-copyright
* Refresh of the patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <stdlib.h>
 
3
#include <GL/glut.h>
 
4
#include <EGL/egl.h>
 
5
#include <emscripten.h>
 
6
 
 
7
#define MULTILINE(...) #__VA_ARGS__
 
8
 
 
9
int touch_started = 0;
 
10
int touch_ended = 0;
 
11
 
 
12
int result = 0;
 
13
 
 
14
void mouseCB(int button, int state, int x, int y)
 
15
{
 
16
    if(button == GLUT_LEFT_BUTTON)
 
17
    {
 
18
        if(state == GLUT_DOWN)
 
19
        {
 
20
            touch_started = 1;
 
21
        }
 
22
        else if(state == GLUT_UP)
 
23
        {
 
24
            touch_ended = 1;
 
25
        }
 
26
    }
 
27
}
 
28
 
 
29
int main(int argc, char *argv[])
 
30
{
 
31
    emscripten_run_script(MULTILINE(
 
32
        Module.injectEvent = function(eventType, x, y) {
 
33
            // Desktop browsers do not have the event types for touch events,
 
34
            // so we fake them by creating a plain-vanilla UIEvent and then
 
35
            // filling in the fields that we look for with appropriate values.
 
36
            var touch = {
 
37
                pageX: x,
 
38
                pageY: y
 
39
            };
 
40
            var touches = [ touch ];
 
41
            touches.item = function(i) { return this[i]; };
 
42
 
 
43
            var event = document.createEvent('UIEvent');
 
44
            event.target = Module['canvas'];
 
45
            event.button = 0;
 
46
            event.touches = touches;
 
47
            event.initUIEvent(eventType, true, true, window, 1);
 
48
            Module['canvas'].dispatchEvent(event);
 
49
        }
 
50
    ));
 
51
 
 
52
    // Fake a touch device so that glut sets up the appropriate event handlers.
 
53
    emscripten_run_script("document.documentElement['ontouchstart'] = 1");
 
54
    glutInit(&argc, argv);
 
55
 
 
56
    glutMouseFunc(&mouseCB);
 
57
 
 
58
    emscripten_run_script("Module.injectEvent('touchend', 100, 100)");
 
59
    emscripten_run_script("Module.injectEvent('touchstart', 100, 100)");
 
60
    result = touch_started && touch_ended;
 
61
 
 
62
    REPORT_RESULT();
 
63
    return 0;
 
64
}