| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 var ui = new Object(); | 5 var scene = {}; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * The scene class assists in managing element and animations in the scene. | 8 * The scene class assists in managing element and animations in the UI. It |
| 9 * It allows scene update commands to be queued in batches, and manages | 9 * allows UI update API commands to be queued in batches, and manages allocation |
| 10 * allocation of element and animation IDs. | 10 * of element and animation IDs. |
| 11 * | 11 * |
| 12 * Examples: | 12 * Examples: |
| 13 * | 13 * |
| 14 * var scene = new ui.Scene(); | 14 * var ui = new scene.Scene(); |
| 15 * | 15 * |
| 16 * // Add an element. | 16 * // Add an element. |
| 17 * var el = new api.UiElement(100, 200, 50, 50); | 17 * var el = new api.UiElement(100, 200, 50, 50); |
| 18 * el.setSize(buttonWidth, buttonHeight); | 18 * el.setSize(buttonWidth, buttonHeight); |
| 19 * | 19 * |
| 20 * // Anchor it to the bottom of the content quad. | 20 * // Anchor it to the bottom of the content quad. |
| 21 * el.setParentId(contentQuadId); | 21 * el.setParentId(contentQuadId); |
| 22 * el.setAnchoring(api.XAnchoring.XNONE, api.YAnchoring.YBOTTOM); | 22 * el.setAnchoring(api.XAnchoring.XNONE, api.YAnchoring.YBOTTOM); |
| 23 * | 23 * |
| 24 * // Place it just below the content quad edge. | 24 * // Place it just below the content quad edge. |
| 25 * el.setTranslation(0, -0.2, 0.0); | 25 * el.setTranslation(0, -0.2, 0.0); |
| 26 * | 26 * |
| 27 * // Add it to the scene. | 27 * // Add it to the ui. |
| 28 * var buttonId = scene.addElement(el); | 28 * var buttonId = ui.addElement(el); |
| 29 * scene.flush(); | 29 * ui.flush(); |
| 30 * | 30 * |
| 31 * // Make the button twice as big. | 31 * // Make the button twice as big. |
| 32 * var update = new api.UiElementUpdate(); | 32 * var update = new api.UiElementUpdate(); |
| 33 * update.setSize(bunttonWidth * 2, buttonHeight * 2); | 33 * update.setSize(bunttonWidth * 2, buttonHeight * 2); |
| 34 * scene.updateElement(buttonId, update); | 34 * ui.updateElement(buttonId, update); |
| 35 * scene.flush(); | 35 * ui.flush(); |
| 36 * | 36 * |
| 37 * // Animate the button size back to its original size, over 250 ms. | 37 * // Animate the button size back to its original size, over 250 ms. |
| 38 * var resize = new api.Animation(buttonId, 250); | 38 * var resize = new api.Animation(buttonId, 250); |
| 39 * resize.setSize(buttonWidth, buttonHeight); | 39 * resize.setSize(buttonWidth, buttonHeight); |
| 40 * scene.addAnimation(resize); | 40 * ui.addAnimation(resize); |
| 41 * scene.flush(); | 41 * ui.flush(); |
| 42 * | 42 * |
| 43 * @struct | 43 * @struct |
| 44 */ | 44 */ |
| 45 ui.Scene = class { | 45 scene.Scene = class { |
| 46 constructor() { | 46 constructor() { |
| 47 /** @private {number} */ | 47 /** @private {number} */ |
| 48 this.idIndex = 1; | 48 this.idIndex = 1; |
| 49 /** @private {Array<Object>} */ | 49 /** @private {Array<Object>} */ |
| 50 this.commands = []; | 50 this.commands = []; |
| 51 /** @private {!Set<number>} */ | 51 /** @private {!Set<number>} */ |
| 52 this.elements = new Set(); | 52 this.elements = new Set(); |
| 53 /** @private {!Object} */ | 53 /** @private {!Object} */ |
| 54 this.animations = []; | 54 this.animations = []; |
| 55 } | 55 } |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 var id = parseInt(id_key, 10); | 138 var id = parseInt(id_key, 10); |
| 139 this.removeAnimation(id); | 139 this.removeAnimation(id); |
| 140 } | 140 } |
| 141 var ids = this.elements.values(); | 141 var ids = this.elements.values(); |
| 142 for (let id of ids) { | 142 for (let id of ids) { |
| 143 this.removeElement(id); | 143 this.removeElement(id); |
| 144 } | 144 } |
| 145 this.flush(); | 145 this.flush(); |
| 146 } | 146 } |
| 147 }; | 147 }; |
| OLD | NEW |