5
#include <emscripten.h>
7
#define MULTILINE(...) #__VA_ARGS__
14
void mouseCB(int button, int state, int x, int y)
16
if(button == GLUT_LEFT_BUTTON)
18
if(state == GLUT_DOWN)
22
else if(state == GLUT_UP)
29
int main(int argc, char *argv[])
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.
40
var touches = [ touch ];
41
touches.item = function(i) { return this[i]; };
43
var event = document.createEvent('UIEvent');
44
event.target = Module['canvas'];
46
event.touches = touches;
47
event.initUIEvent(eventType, true, true, window, 1);
48
Module['canvas'].dispatchEvent(event);
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);
56
glutMouseFunc(&mouseCB);
58
emscripten_run_script("Module.injectEvent('touchend', 100, 100)");
59
emscripten_run_script("Module.injectEvent('touchstart', 100, 100)");
60
result = touch_started && touch_ended;