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

« back to all changes in this revision

Viewing changes to src/library_glut.js

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2014-01-19 14:12:40 UTC
  • mfrom: (4.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20140119141240-nfiw0p8033oitpfz
Tags: 1.9.0~20140119~7dc8c2f-1
* New snapshot release (Closes: #733714)
* Provide sources for javascript and flash. Done in orig-tar.sh
  Available in third_party/websockify/include/web-socket-js/src/
  (Closes: #735903)

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
    modifiers: 0,
17
17
    initWindowWidth: 256,
18
18
    initWindowHeight: 256,
 
19
    initDisplayMode: 0x0000 /*GLUT_RGBA*/ | 0x0002 /*GLUT_DOUBLE*/ | 0x0010 /*GLUT_DEPTH*/,
19
20
    // Set when going fullscreen
20
21
    windowX: 0,
21
22
    windowY: 0,
58
59
    getSpecialKey: function(keycode) {
59
60
        var key = null;
60
61
        switch (keycode) {
 
62
          case 8:  key = 120 /* backspace */; break;
 
63
          case 46: key = 111 /* delete */; break;
 
64
 
61
65
          case 0x70 /*DOM_VK_F1*/: key = 1 /* GLUT_KEY_F1 */; break;
62
66
          case 0x71 /*DOM_VK_F2*/: key = 2 /* GLUT_KEY_F2 */; break;
63
67
          case 0x72 /*DOM_VK_F3*/: key = 3 /* GLUT_KEY_F3 */; break;
118
122
        return keycode; // numeric  TODO handle shift?
119
123
      if (65 <= keycode && keycode <= 90)
120
124
        return event['shiftKey'] ? keycode : keycode + 32;
 
125
      if (96 <= keycode && keycode <= 105)
 
126
        return keycode - 48; // numpad numbers    
121
127
      if (106 <= keycode && keycode <= 111)
122
128
        return keycode - 106 + 42; // *,+-./  TODO handle shift?
123
129
 
124
130
      switch (keycode) {
 
131
        case 9:  // tab key
 
132
        case 13: // return key
125
133
        case 27: // escape
126
134
        case 32: // space
127
135
        case 61: // equal
189
197
      }
190
198
    },
191
199
 
192
 
    onMouseButtonDown: function(event){
 
200
    onMouseButtonDown: function(event) {
193
201
      Browser.calculateMouseEvent(event);
194
202
 
195
203
      GLUT.buttons |= (1 << event['button']);
196
204
 
197
 
      if(event.target == Module["canvas"] && GLUT.mouseFunc){
 
205
      if (event.target == Module["canvas"] && GLUT.mouseFunc) {
198
206
        try {
199
207
          event.target.setCapture();
200
208
        } catch (e) {}
204
212
      }
205
213
    },
206
214
 
207
 
    onMouseButtonUp: function(event){
 
215
    onMouseButtonUp: function(event) {
208
216
      Browser.calculateMouseEvent(event);
209
217
 
210
218
      GLUT.buttons &= ~(1 << event['button']);
211
219
 
212
 
      if(GLUT.mouseFunc) {
 
220
      if (GLUT.mouseFunc) {
213
221
        event.preventDefault();
214
222
        GLUT.saveModifiers(event);
215
223
        Runtime.dynCall('viiii', GLUT.mouseFunc, [event['button'], 1/*GLUT_UP*/, Browser.mouseX, Browser.mouseY]);
216
224
      }
217
225
    },
218
226
 
 
227
    onMouseWheel: function(event) {
 
228
      Browser.calculateMouseEvent(event);
 
229
 
 
230
      // cross-browser wheel delta
 
231
      var e = window.event || event; // old IE support
 
232
      var delta = Math.max(-1, Math.min(1, (e.wheelDelta || -e.detail)));
 
233
 
 
234
      var button = 3; // wheel up
 
235
      if (delta < 0) {
 
236
        button = 4; // wheel down
 
237
      }
 
238
 
 
239
      if (GLUT.mouseFunc) {
 
240
        event.preventDefault();
 
241
        GLUT.saveModifiers(event);
 
242
        Runtime.dynCall('viiii', GLUT.mouseFunc, [button, 0/*GLUT_DOWN*/, Browser.mouseX, Browser.mouseY]);
 
243
      }
 
244
    },
 
245
 
219
246
    // TODO add fullscreen API ala:
220
247
    // http://johndyer.name/native-fullscreen-javascript-api-plus-jquery-plugin/
221
 
    onFullScreenEventChange: function(event){
 
248
    onFullScreenEventChange: function(event) {
222
249
      var width;
223
250
      var height;
224
251
      if (document["fullScreen"] || document["mozFullScreen"] || document["webkitIsFullScreen"]) {
279
306
      window.addEventListener("mousemove", GLUT.onMousemove, true);
280
307
      window.addEventListener("mousedown", GLUT.onMouseButtonDown, true);
281
308
      window.addEventListener("mouseup", GLUT.onMouseButtonUp, true);
 
309
      // IE9, Chrome, Safari, Opera
 
310
      window.addEventListener("mousewheel", GLUT.onMouseWheel, true);
 
311
      // Firefox
 
312
      window.addEventListener("DOMMouseScroll", GLUT.onMouseWheel, true);
282
313
    }
283
 
    
 
314
 
284
315
    Browser.resizeListeners.push(function(width, height) {
285
316
      if (GLUT.reshapeFunc) {
286
317
        Runtime.dynCall('vii', GLUT.reshapeFunc, [width, height]);
298
329
        window.removeEventListener("mousemove", GLUT.onMousemove, true);
299
330
        window.removeEventListener("mousedown", GLUT.onMouseButtonDown, true);
300
331
        window.removeEventListener("mouseup", GLUT.onMouseButtonUp, true);
 
332
        // IE9, Chrome, Safari, Opera
 
333
        window.removeEventListener("mousewheel", GLUT.onMouseWheel, true);
 
334
        // Firefox
 
335
        window.removeEventListener("DOMMouseScroll", GLUT.onMouseWheel, true);
301
336
      }
302
337
      Module["canvas"].width = Module["canvas"].height = 1;
303
338
    } });
344
379
  },
345
380
 
346
381
  glutIdleFunc: function(func) {
347
 
    var callback = function() {
 
382
    function callback() {
348
383
      if (GLUT.idleFunc) {
349
384
        Runtime.dynCall('v', GLUT.idleFunc);
350
385
        Browser.safeSetTimeout(callback, 0);
398
433
 
399
434
  glutCreateWindow__deps: ['$Browser'],
400
435
  glutCreateWindow: function(name) {
401
 
    Module.ctx = Browser.createContext(Module['canvas'], true, true);
 
436
    var contextAttributes = {
 
437
      antialias: ((GLUT.initDisplayMode & 0x0080 /*GLUT_MULTISAMPLE*/) != 0),
 
438
      depth: ((GLUT.initDisplayMode & 0x0010 /*GLUT_DEPTH*/) != 0),
 
439
      stencil: ((GLUT.initDisplayMode & 0x0020 /*GLUT_STENCIL*/) != 0)
 
440
    };
 
441
    Module.ctx = Browser.createContext(Module['canvas'], true, true, contextAttributes);
402
442
    return Module.ctx ? 1 /* a new GLUT window ID for the created context */ : 0 /* failure */;
403
443
  },
404
444
 
437
477
    GLUT.requestFullScreen();
438
478
  },
439
479
 
440
 
  glutInitDisplayMode: function(mode) {},
 
480
  glutInitDisplayMode: function(mode) {
 
481
    GLUT.initDisplayMode = mode;
 
482
  },
 
483
 
441
484
  glutSwapBuffers: function() {},
442
485
 
443
486
  glutPostRedisplay: function() {