// Copyright (C) 2013 Massachusetts Institute of Technology
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License version 2,
// as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
'use strict';
var Reporter = function(data) {
this.cmd = data.cmd;
this.color = data.color;
this.isDiscrete = data.isDiscrete;
this.label = data.label;
this.mode = data.mode;
this.param = data.param;
this.sliderMin = data.sliderMin;
this.sliderMax = data.sliderMax;
this.target = data.target;
this.visible = data.visible;
this.x = data.x;
this.y = data.y;
this.z = io.getCount();
this.el = null; // jQuery Element for the outer box
this.valueEl = null; // jQ element containing the reporter value
this.slider = null; // slider jQ element
};
Reporter.prototype.attach = function(scene) {
switch (this.mode) {
case 1: // Normal
case 3: // Slider
this.el = $('
' + this.label + '
');
this.valueEl = $('
null
');
this.el.append(this.valueEl);
if (this.mode == 3) {
// Slider-specific
// Temporarily, set the value to sliderMin until an update
this.slider = $('');
this.slider.change(this.changeSlider);
this.el.append(' ');
this.el.append(this.slider);
}
break;
case 2: // Large
this.el = $('
'+(this.target==='Stage'?'':this.target+' ')+this.listName);
var c = this.containerEl = $('
').appendTo(this.el).width(this.width-13).height(this.height-34);
var s = this.scrollbar = $('
').appendTo(this.el);
var sb = s.children('.list-scrollbar');
sb.mousedown(function(e){
if (e.which===1) $(this).data({scrolling:true,startY:e.pageY}); // left button
});
$('body').mousemove(function(e){
if (sb.data('scrolling')) {
var offset = parseInt(sb.css('top'))+e.pageY-sb.data('startY');
if (offset < 0) {
offset = 0;
}
if (offset > c.height()-sb.height()) {
offset = c.height()-sb.height();
}
sb.css('top',offset);
c.scrollTop(c.height()/sb.height()*offset);
}
}).mouseup(function(){
if ($.hasData(sb[0],'scrolling')) sb.removeData(['scrolling','startY']);
});
// this.el.append('
+'); // disabled because it doesn't do anything even in the original
this.el.append('
length: '+this.contents.length);
scene.append(this.el);
this.update();
this.el.css('left', this.x);
this.el.css('top', this.y);
this.el.width(this.width);
this.el.height(this.height);
this.el.css('z-index', this.z);
this.el.css('display', this.visible ? 'inline-block' : 'none');
};
List.prototype.update = function(){
this.contents = findList(runtime.spriteNamed(this.target),this.listName);
this.el.css('display', this.visible ? 'inline-block' : 'none');
if (!this.visible) return;
var c = this.containerEl.html(''); // so that it can be used inside the forEach
this.contents.forEach(function(val,i){
$('