OLD | NEW |
(Empty) | |
| 1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 * Use of this source code is governed by a BSD-style license that can be |
| 3 * found in the LICENSE file. |
| 4 */ |
| 5 'use strict'; |
| 6 |
| 7 base.require('ui'); |
| 8 base.require('color_mappings'); |
| 9 base.require('quad_view'); |
| 10 |
| 11 base.exportTo('ccfv', function() { |
| 12 |
| 13 /** |
| 14 * @constructor |
| 15 */ |
| 16 function TreeQuadViewSelection(view, tiles) { |
| 17 this.view = view; |
| 18 this.tiles = tiles; |
| 19 } |
| 20 |
| 21 TreeQuadViewSelection.prototype = { |
| 22 activate: function() { |
| 23 this.tiles.forEach(function(tile) { |
| 24 tile.selected = true; |
| 25 }); |
| 26 this.view.updateQuads_(); |
| 27 }, |
| 28 |
| 29 deactivate: function() { |
| 30 this.tiles.forEach(function(tile) { |
| 31 tile.selected = false; |
| 32 }); |
| 33 this.view.updateQuads_(); |
| 34 } |
| 35 }; |
| 36 |
| 37 /** |
| 38 * @constructor |
| 39 */ |
| 40 var TreeQuadView = ui.define(ccfv.QuadView); |
| 41 |
| 42 TreeQuadView.prototype = { |
| 43 __proto__: ccfv.QuadView.prototype, |
| 44 |
| 45 decorate: function() { |
| 46 this.which_tree_ = undefined; |
| 47 this.tiles_ = undefined; |
| 48 this.colorMap_ = ccfv.ALL_TILE_COLOR_MAPS[0]; |
| 49 }, |
| 50 |
| 51 get tiles() { |
| 52 return this.tiles_; |
| 53 }, |
| 54 |
| 55 set tiles(tiles) { |
| 56 this.tiles_ = tiles; |
| 57 this.updateQuads_(); |
| 58 }, |
| 59 |
| 60 get which_tree() { |
| 61 return this.which_tree_; |
| 62 }, |
| 63 |
| 64 set which_tree(which_tree) { |
| 65 this.which_tree_ = which_tree; |
| 66 this.updateQuads_(); |
| 67 }, |
| 68 |
| 69 get colorMap() { |
| 70 return this.colorMap_; |
| 71 }, |
| 72 |
| 73 set colorMap(map) { |
| 74 this.colorMap_ = map; |
| 75 this.updateQuads_(); |
| 76 }, |
| 77 |
| 78 updateQuads_: function() { |
| 79 if (this.which_tree_ === undefined || |
| 80 !this.tiles_) { |
| 81 this.quads = undefined; |
| 82 return; |
| 83 } |
| 84 |
| 85 var tiles = this.tiles_; |
| 86 var which_tree = this.which_tree_; |
| 87 |
| 88 var quads = []; |
| 89 for (var i = 0; i < tiles.length; i++) { |
| 90 var tile = tiles[i]; |
| 91 var priority = tile.priority[which_tree]; |
| 92 if (!priority.is_live) |
| 93 continue; |
| 94 |
| 95 var value = this.colorMap_.getValueForTile(tile, priority); |
| 96 var backgroundColor = value !== undefined ? |
| 97 this.colorMap_.getBackgroundColorForValue(value) : undefined; |
| 98 |
| 99 var quad = priority.current_screen_quad; |
| 100 quads.push({ |
| 101 backgroundColor: backgroundColor, |
| 102 selected: tile.selected, |
| 103 p1: quad.p1, |
| 104 p2: quad.p2, |
| 105 p3: quad.p3, |
| 106 p4: quad.p4 |
| 107 }); |
| 108 } |
| 109 this.quads = quads; |
| 110 }, |
| 111 |
| 112 createSelection_: function(quadIndices) { |
| 113 var tiles = []; |
| 114 for (var i = 0; i < quadIndices.length; i++) |
| 115 tiles.push(this.tiles_[quadIndices[i]]); |
| 116 return new TreeQuadViewSelection(this, tiles); |
| 117 } |
| 118 } |
| 119 |
| 120 return { |
| 121 TreeQuadView: TreeQuadView, |
| 122 TreeQuadViewSelection: TreeQuadViewSelection, |
| 123 } |
| 124 }); |
| 125 |
OLD | NEW |