| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2011 The Native Client SDK Authors. |
| 2 // Use of this source code is governed by a BSD-style license that can |
| 3 // be found in the LICENSE file. |
| 4 |
| 5 /** |
| 6 * @fileoverview The life Application object. This object instantiates a |
| 7 * Trackball object and connects it to the element named |tumbler_content|. |
| 8 * It also conditionally embeds a debuggable module or a release module into |
| 9 * the |tumbler_content| element. |
| 10 */ |
| 11 |
| 12 // Requires life |
| 13 // Requires uikit.Dragger |
| 14 |
| 15 // The life namespace |
| 16 var life = life || {}; |
| 17 |
| 18 /** |
| 19 * Constructor for the Application class. Use the run() method to populate |
| 20 * the object with controllers and wire up the events. |
| 21 * @constructor |
| 22 */ |
| 23 life.Application = function() { |
| 24 } |
| 25 |
| 26 /** |
| 27 * The native module for the application. This refers to the module loaded via |
| 28 * the <embed> tag. |
| 29 * @type {Element} |
| 30 * @private |
| 31 */ |
| 32 life.Application.prototype.module_ = null; |
| 33 |
| 34 /** |
| 35 * The mouse-drag event object. |
| 36 * @type {tumbler.Dragger} |
| 37 * @private |
| 38 */ |
| 39 life.Application.prototype.dragger_ = null; |
| 40 |
| 41 /** |
| 42 * The timer update interval object. |
| 43 * @type {tumbler.Dragger} |
| 44 * @private |
| 45 */ |
| 46 life.Application.prototype.updateInterval_ = null; |
| 47 |
| 48 /** |
| 49 * Called by the module loading function once the module has been loaded. Wire |
| 50 * up a Dragger object to |this|. |
| 51 * @param {!Element} nativeModule The instance of the native module. |
| 52 * @param {?String} opt_contentDivName The id of a DOM element which captures |
| 53 * the UI events. If unspecified, defaults to DEFAULT_DIV_NAME. The DOM |
| 54 * element must exist. |
| 55 */ |
| 56 life.Application.prototype.moduleDidLoad = |
| 57 function(nativeModule, opt_contentDivName) { |
| 58 contentDivId = opt_contentDivName || life.Application.DEFAULT_DIV_NAME; |
| 59 var contentDiv = document.getElementById(contentDivId); |
| 60 this.module_ = nativeModule; |
| 61 this.dragger_ = new uikit.Dragger(contentDiv); |
| 62 this.dragger_.addDragListener(this); |
| 63 if (this.module_) { |
| 64 // Use a 10ms update interval to drive frame rate |
| 65 this.updateInterval_ = setInterval("life.application.update()", 10); |
| 66 } |
| 67 } |
| 68 |
| 69 /** |
| 70 * Called when the page is unloaded. |
| 71 */ |
| 72 life.Application.prototype.moduleDidUnload = function() { |
| 73 clearInterval(this.updateInterval_); |
| 74 } |
| 75 |
| 76 /** |
| 77 * Called from the interval timer. This is a simple wrapper to call the |
| 78 * "update" method on the Life NaCl module. |
| 79 */ |
| 80 life.Application.prototype.update = function() { |
| 81 if (this.module_) |
| 82 this.module_.update(); |
| 83 } |
| 84 |
| 85 /** |
| 86 * Add a simulation cell at a 2D point. |
| 87 * @param {!number} point_x The x-coordinate, relative to the origin of the |
| 88 * enclosing element. |
| 89 * @param {!number} point_y The y-coordinate, relative to the origin of the |
| 90 * enclosing element, y increases downwards. |
| 91 */ |
| 92 life.Application.prototype.AddCellAtPoint = function(point_x, point_y) { |
| 93 if (this.module_) |
| 94 this.module_.addCellAtPoint(point_x, point_y); |
| 95 } |
| 96 |
| 97 /** |
| 98 * Handle the drag START event: Drop a new life cell at the mouse location. |
| 99 * @param {!life.Application} view The view controller that called |
| 100 * this method. |
| 101 * @param {!uikit.DragEvent} dragStartEvent The DRAG_START event that |
| 102 * triggered this handler. |
| 103 */ |
| 104 life.Application.prototype.handleStartDrag = |
| 105 function(controller, dragStartEvent) { |
| 106 this.AddCellAtPoint(dragStartEvent.clientX, dragStartEvent.clientY); |
| 107 } |
| 108 |
| 109 /** |
| 110 * Handle the drag DRAG event: Drop a new life cell at the mouse location. |
| 111 * @param {!life.Application} view The view controller that called |
| 112 * this method. |
| 113 * @param {!uikit.DragEvent} dragEvent The DRAG event that triggered |
| 114 * this handler. |
| 115 */ |
| 116 life.Application.prototype.handleDrag = function(controller, dragEvent) { |
| 117 this.AddCellAtPoint(dragEvent.clientX, dragEvent.clientY); |
| 118 } |
| 119 |
| 120 /** |
| 121 * Handle the drag END event: This is a no-op. |
| 122 * @param {!life.Application} view The view controller that called |
| 123 * this method. |
| 124 * @param {!uikit.DragEvent} dragEndEvent The DRAG_END event that |
| 125 * triggered this handler. |
| 126 */ |
| 127 life.Application.prototype.handleEndDrag = function(controller, dragEndEvent) { |
| 128 } |
| 129 |
| 130 /** |
| 131 * The default name for the 3D content div element. |
| 132 * @type {string} |
| 133 */ |
| 134 life.Application.DEFAULT_DIV_NAME = 'tumbler_content'; |
| OLD | NEW |