1 /** |
|
2 * js/annotsRoll.js |
|
3 * |
|
4 * annotsRoll basic component |
|
5 * |
|
6 */ |
|
7 |
|
8 'use strict'; |
|
9 |
|
10 var PIXI = require('pixi'); |
|
11 var randomColor = require('randomColor'); |
|
12 |
|
13 function AnnotsRoll(parentContainer, xInit, yInit, width, height, widthRoll, pixelsPerSecond, annotColors, lineInterval){ |
|
14 var _this = this; |
|
15 this.container = new PIXI.DisplayObjectContainer(); |
|
16 this.container.position.x = xInit; |
|
17 this.container.position.y = yInit; |
|
18 this.container.width = width; |
|
19 parentContainer.addChild(this.container); |
|
20 |
|
21 this.height = height; |
|
22 this.width = width; |
|
23 this.widthRoll = widthRoll; |
|
24 this.pixelsPerSecond = pixelsPerSecond; |
|
25 this.lineInterval = lineInterval; |
|
26 |
|
27 this.addAnnot = function(category, user, color){ |
|
28 var graphics = new PIXI.Graphics(); |
|
29 var x = 0; |
|
30 var y = -this.container.y; |
|
31 graphics.beginFill(color); |
|
32 graphics.drawRect(x, y, 10, 3); |
|
33 graphics.endFill(); |
|
34 |
|
35 this.container.addChild(graphics); |
|
36 |
|
37 var catText = new PIXI.Text(category, { font: '16pt Arial', fill: color.replace("0x", "#") }); |
|
38 catText.x = x + 20; |
|
39 catText.y = y - 23; |
|
40 this.container.addChild(catText); |
|
41 |
|
42 var userText = new PIXI.Text(user, { font: '10pt Arial', fill: '#444444' }); |
|
43 userText.x = x + 20; |
|
44 userText.y = y + 2; |
|
45 this.container.addChild(userText); |
|
46 |
|
47 this.addAnnotLine(color); |
|
48 }; |
|
49 |
|
50 this.addAnnotLine = function(color){ |
|
51 var x = this.widthRoll; |
|
52 var y = -this.container.y; |
|
53 |
|
54 var graphics = new PIXI.Graphics(); |
|
55 |
|
56 graphics.beginFill(color); |
|
57 graphics.drawRect(x, y, this.width - x, 3); |
|
58 graphics.endFill(); |
|
59 |
|
60 this.container.addChild(graphics); |
|
61 }; |
|
62 |
|
63 this.moveTo = function(diffTime){ |
|
64 this.container.y = Math.floor(diffTime*this.pixelsPerSecond); |
|
65 }; |
|
66 |
|
67 this.removePassedObjets = function(){ |
|
68 var nbChilds = _this.container.children.length; |
|
69 var i = 0, childIsNowDisplayed = false, childrenToRemove = []; |
|
70 while(i<nbChilds && !childIsNowDisplayed){ |
|
71 var child = _this.container.children[i++]; |
|
72 |
|
73 if(typeof(child) == 'undefined') { |
|
74 continue; |
|
75 } |
|
76 if((child.y + child.height) < (Math.abs(_this.container.y) - _this.height)){ |
|
77 childrenToRemove.push(child); |
|
78 } |
|
79 else { |
|
80 childIsNowDisplayed = true; |
|
81 } |
|
82 } |
|
83 childrenToRemove.forEach(function(child) { |
|
84 _this.container.removeChild(child); |
|
85 }); |
|
86 }; |
|
87 |
|
88 window.setInterval(this.removePassedObjets, 1000 * this.height / this.pixelsPerSecond ); |
|
89 |
|
90 } |
|
91 |
|
92 module.exports = AnnotsRoll; |
|