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

« back to all changes in this revision

Viewing changes to src/library_glut.js

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-06-11 15:45:24 UTC
  • mfrom: (1.2.1) (2.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20130611154524-rppb3w6tixlegv4n
Tags: 1.4.7~20130611~a1eb425-1
* New snapshot release
* Upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
    motionFunc: null,
13
13
    passiveMotionFunc: null,
14
14
    mouseFunc: null,
15
 
    lastX: 0,
16
 
    lastY: 0,
17
15
    buttons: 0,
18
16
    modifiers: 0,
19
17
    initWindowWidth: 256,
24
22
    windowWidth: 0,
25
23
    windowHeight: 0,
26
24
 
27
 
    savePosition: function(event) {
28
 
      /* TODO maybe loop here ala http://www.quirksmode.org/js/findpos.html */
29
 
      GLUT.lastX = event['clientX'] - Module['canvas'].offsetLeft;
30
 
      GLUT.lastY = event['clientY'] - Module['canvas'].offsetTop;
31
 
    },
32
 
 
33
25
    saveModifiers: function(event) {
34
26
      GLUT.modifiers = 0;
35
27
      if (event['shiftKey'])
45
37
       * spamming our app with uncessary callback call. It does happen in
46
38
       * Chrome on Windows.
47
39
       */
48
 
      var newX = event['clientX'] - Module['canvas'].offsetLeft;
49
 
      var newY = event['clientY'] - Module['canvas'].offsetTop;
50
 
      if (newX == GLUT.lastX && newY == GLUT.lastY)
51
 
        return;
 
40
      var lastX = Browser.mouseX;
 
41
      var lastY = Browser.mouseY;
 
42
      Browser.calculateMouseEvent(event);
 
43
      var newX = Browser.mouseX;
 
44
      var newY = Browser.mouseY;
 
45
      if (newX == lastX && newY == lastY) return;
52
46
 
53
 
      GLUT.savePosition(event);
54
47
      if (GLUT.buttons == 0 && event.target == Module["canvas"] && GLUT.passiveMotionFunc) {
55
48
        event.preventDefault();
56
49
        GLUT.saveModifiers(event);
57
 
        Runtime.dynCall('vii', GLUT.passiveMotionFunc, [GLUT.lastX, GLUT.lastY]);
 
50
        Runtime.dynCall('vii', GLUT.passiveMotionFunc, [lastX, lastY]);
58
51
      } else if (GLUT.buttons != 0 && GLUT.motionFunc) {
59
52
        event.preventDefault();
60
53
        GLUT.saveModifiers(event);
61
 
        Runtime.dynCall('vii', GLUT.motionFunc, [GLUT.lastX, GLUT.lastY]);
 
54
        Runtime.dynCall('vii', GLUT.motionFunc, [lastX, lastY]);
62
55
      }
63
56
    },
64
57
 
159
152
          if( GLUT.specialFunc ) {
160
153
            event.preventDefault();
161
154
            GLUT.saveModifiers(event);
162
 
            Runtime.dynCall('viii', GLUT.specialFunc, [key, GLUT.lastX, GLUT.lastY]);
 
155
            Runtime.dynCall('viii', GLUT.specialFunc, [key, Browser.mouseX, Browser.mouseY]);
163
156
          }
164
157
        }
165
158
        else
168
161
          if( key !== null && GLUT.keyboardFunc ) {
169
162
            event.preventDefault();
170
163
            GLUT.saveModifiers(event);
171
 
            Runtime.dynCall('viii', GLUT.keyboardFunc, [key, GLUT.lastX, GLUT.lastY]);
 
164
            Runtime.dynCall('viii', GLUT.keyboardFunc, [key, Browser.mouseX, Browser.mouseY]);
172
165
          }
173
166
        }
174
167
      }
181
174
          if(GLUT.specialUpFunc) {
182
175
            event.preventDefault ();
183
176
            GLUT.saveModifiers(event);
184
 
            Runtime.dynCall('viii', GLUT.specialUpFunc, [key, GLUT.lastX, GLUT.lastY]);
 
177
            Runtime.dynCall('viii', GLUT.specialUpFunc, [key, Browser.mouseX, Browser.mouseY]);
185
178
          }
186
179
        }
187
180
        else
190
183
          if( key !== null && GLUT.keyboardUpFunc ) {
191
184
            event.preventDefault ();
192
185
            GLUT.saveModifiers(event);
193
 
            Runtime.dynCall('viii', GLUT.keyboardUpFunc, [key, GLUT.lastX, GLUT.lastY]);
 
186
            Runtime.dynCall('viii', GLUT.keyboardUpFunc, [key, Browser.mouseX, Browser.mouseY]);
194
187
          }
195
188
        }
196
189
      }
197
190
    },
198
191
 
199
192
    onMouseButtonDown: function(event){
200
 
      GLUT.savePosition(event);
 
193
      Browser.calculateMouseEvent(event);
 
194
 
201
195
      GLUT.buttons |= (1 << event['button']);
202
196
 
203
197
      if(event.target == Module["canvas"] && GLUT.mouseFunc){
206
200
        } catch (e) {}
207
201
        event.preventDefault();
208
202
        GLUT.saveModifiers(event);
209
 
        Runtime.dynCall('viiii', GLUT.mouseFunc, [event['button'], 0/*GLUT_DOWN*/, GLUT.lastX, GLUT.lastY]);
 
203
        Runtime.dynCall('viiii', GLUT.mouseFunc, [event['button'], 0/*GLUT_DOWN*/, Browser.mouseX, Browser.mouseY]);
210
204
      }
211
205
    },
212
206
 
213
207
    onMouseButtonUp: function(event){
214
 
      GLUT.savePosition(event);
 
208
      Browser.calculateMouseEvent(event);
 
209
 
215
210
      GLUT.buttons &= ~(1 << event['button']);
216
211
 
217
212
      if(GLUT.mouseFunc) {
218
213
        event.preventDefault();
219
214
        GLUT.saveModifiers(event);
220
 
        Runtime.dynCall('viiii', GLUT.mouseFunc, [event['button'], 1/*GLUT_UP*/, GLUT.lastX, GLUT.lastY]);
 
215
        Runtime.dynCall('viiii', GLUT.mouseFunc, [event['button'], 1/*GLUT_UP*/, Browser.mouseX, Browser.mouseY]);
221
216
      }
222
217
    },
223
218
 
327
322
    var callback = function() {
328
323
      if (GLUT.idleFunc) {
329
324
        Runtime.dynCall('v', GLUT.idleFunc);
330
 
        window.setTimeout(callback, 0);
 
325
        Browser.safeSetTimeout(callback, 0);
331
326
      }
332
327
    }
333
 
    if (!GLUT.idleFunc)
334
 
      window.setTimeout(callback, 0);
 
328
    if (!GLUT.idleFunc) {
 
329
      Browser.safeSetTimeout(callback, 0);
 
330
    }
335
331
    GLUT.idleFunc = func;
336
332
  },
337
333
 
338
334
  glutTimerFunc: function(msec, func, value) {
339
 
    window.setTimeout(function() { Runtime.dynCall('vi', func, [value]); }, msec);
 
335
    Browser.safeSetTimeout(function() { Runtime.dynCall('vi', func, [value]); }, msec);
340
336
  },
341
337
 
342
338
  glutDisplayFunc: function(func) {
424
420
  glutPostRedisplay: function() {
425
421
    if (GLUT.displayFunc) {
426
422
      Browser.requestAnimationFrame(function() {
 
423
        if (ABORT) return;
427
424
        Runtime.dynCall('v', GLUT.displayFunc);
428
425
      });
429
426
    }