author | rougeronj |
Thu, 16 Apr 2015 12:15:33 +0200 | |
changeset 153 | 60bd2b36b9dc |
parent 131 | 0bb70072a56f |
permissions | -rw-r--r-- |
101 | 1 |
/** |
2 |
* scripts/stageview.js |
|
3 |
* |
|
4 |
* This is the starting point for your application. |
|
5 |
* Take a look at http://browserify.org/ for more info |
|
6 |
*/ |
|
7 |
||
8 |
/* global document: false */ |
|
9 |
||
10 |
'use strict'; |
|
11 |
||
12 |
||
13 |
var PIXI = require('pixi'); |
|
14 |
var _ = require('lodash'); |
|
15 |
||
16 |
var defaultConfig = { |
|
17 |
externalRefresh: false, |
|
18 |
logger: undefined, |
|
104 | 19 |
sceneWidth: 1024, |
20 |
sceneHeight: 768, |
|
101 | 21 |
framerate: 25, |
22 |
sceneBgColor: 0xFFFFFF, |
|
23 |
canvasContainer: 'canvasContainer', |
|
24 |
}; |
|
25 |
||
26 |
function StageView(options) { |
|
27 |
||
28 |
var _this = this; |
|
29 |
var opts = _(options).defaults(defaultConfig).value(); |
|
30 |
||
31 |
var externalRefresh = opts.externalRefresh; |
|
32 |
||
33 |
this.logger = opts.logger; |
|
34 |
this.framerate = opts.framerate; |
|
35 |
var sceneBgColor = opts.sceneBgColor; |
|
36 |
var sceneWidth = opts.sceneWidth; |
|
37 |
var sceneHeight = opts.sceneHeight; |
|
38 |
var canvasContainer = opts.canvasContainer; |
|
105
25ac8802c189
Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents:
104
diff
changeset
|
39 |
var timeContainer = []; |
131 | 40 |
var components = []; |
41 |
||
101 | 42 |
//create an new instance of a pixi stage |
43 |
this.stage = new PIXI.Stage(sceneBgColor); |
|
44 |
//create a renderer instance. |
|
45 |
var renderer = PIXI.autoDetectRenderer(sceneWidth, sceneHeight); |
|
131 | 46 |
|
101 | 47 |
this.init = function() { |
48 |
||
49 |
if(typeof(canvasContainer) === 'string') { |
|
50 |
canvasContainer = document.getElementById(canvasContainer); |
|
51 |
} |
|
52 |
if(typeof(timeContainer) === 'string') { |
|
53 |
timeContainer = document.getElementById(timeContainer); |
|
54 |
} |
|
55 |
||
56 |
canvasContainer.appendChild(renderer.view); |
|
131 | 57 |
|
101 | 58 |
components.forEach(function(c){ |
59 |
c.init(); |
|
60 |
}); |
|
61 |
}; |
|
131 | 62 |
|
105
25ac8802c189
Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents:
104
diff
changeset
|
63 |
this.registerTimeContainer = function(container) { |
25ac8802c189
Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents:
104
diff
changeset
|
64 |
timeContainer.push(container); |
25ac8802c189
Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents:
104
diff
changeset
|
65 |
}; |
131 | 66 |
|
101 | 67 |
this.registerComponent = function(component) { |
68 |
components.push(component); |
|
69 |
this.stage.addChild(component.container); |
|
70 |
}; |
|
71 |
||
72 |
this.refresh = function() { |
|
73 |
components.forEach(function(c){ |
|
74 |
c.refresh(); |
|
75 |
}); |
|
76 |
renderer.render(this.stage); |
|
77 |
}; |
|
78 |
||
79 |
// Init page and intervals |
|
80 |
var refreshInterval; |
|
81 |
||
82 |
this.start = function() { |
|
83 |
||
84 |
if(!externalRefresh) { |
|
85 |
refreshInterval = setInterval(function() {_this.refresh();}, 1000/this.framerate); |
|
86 |
} |
|
131 | 87 |
|
101 | 88 |
components.forEach(function(c){ |
89 |
c.start(); |
|
90 |
}); |
|
91 |
}; |
|
92 |
||
93 |
this.stop = function() { |
|
94 |
if(!externalRefresh) { |
|
95 |
clearInterval(refreshInterval); |
|
96 |
} |
|
97 |
|
|
98 |
components.forEach(function(c){ |
|
99 |
c.stop(); |
|
100 |
}); |
|
101 |
}; |
|
102 |
||
103 |
||
104 |
this.log = function(m) { |
|
105 |
if(this.logger) { |
|
106 |
this.logger.log(m); |
|
107 |
} |
|
108 |
}; |
|
109 |
||
110 |
||
111 |
return this; |
|
112 |
} |
|
113 |
||
114 |
module.exports = { |
|
115 |
StageView: StageView |
|
116 |
}; |