Add projector communication between renderer and main

This commit is contained in:
Matt 2016-04-17 22:22:18 -04:00
parent c72eed3d5d
commit 24aebc4c31
4 changed files with 1186 additions and 699 deletions

View File

@ -2463,6 +2463,7 @@ var remote = require('remote'),
ipcRenderer = require('electron').ipcRenderer,
mcopy = {},
light = {},
proj = {},
nav = {},
seq = {},
gui = {},
@ -2719,6 +2720,564 @@ seq.clear = function () {
mcopy.state.sequence.arr = [];
};
/*
mcopy.cmd = {};
mcopy.cmd.cam_forward = function (callback) {
var res = function (ms) {
mcopy.state.camera.pos++;
//gui action
mcopy.gui.updateState();
mcopy.log('Camera moved +1 frame to ' + mcopy.state.camera.pos);
if (callback) { callback(); }
};
if (!mcopy.state.camera.direction) {
mcopy.log('Advancing camera...');
mcopy.arduino.send(mcopy.cfg.arduino.cmd.cam_forward, function (ms) {
mcopy.state.camera.direction = true;
mcopy.gui.trad.updateDir({value:'cam_forward'});
setTimeout(function () {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.camera, res);
}, mcopy.cfg.arduino.serialDelay);
});
} else {
setTimeout(function () {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.camera, res);
}, mcopy.cfg.arduino.serialDelay);
}
};
mcopy.cmd.cam_backward = function (callback) {
var res = function (ms) {
mcopy.state.camera.pos--;
//gui action
mcopy.gui.updateState();
mcopy.log('Camera moved -1 frame to ' + mcopy.state.camera.pos);
if (callback) { callback(); }
};
if (mcopy.state.camera.direction) {
mcopy.log('Rewinding camera...');
mcopy.arduino.send(mcopy.cfg.arduino.cmd.cam_backward, function (ms) {
mcopy.state.camera.direction = false;
mcopy.gui.trad.updateDir({value:'cam_backward'});
setTimeout(function () {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.camera, res);
}, mcopy.cfg.arduino.serialDelay);
});
} else {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.camera, res);
}
};
mcopy.cmd.proj_forward = function (callback) {
var res = function (ms) {
mcopy.state.projector.pos++;
mcopy.gui.updateState();
mcopy.log('Projector moved +1 frame to ' + mcopy.state.projector.pos);
//gui action
if (callback) { callback(); }
};
if (!mcopy.state.projector.direction) {
mcopy.log('Advancing projector...');
mcopy.arduino.send(mcopy.cfg.arduino.cmd.proj_forward, function (ms) {
mcopy.state.projector.direction = true;
mcopy.gui.trad.updateDir({value:'proj_forward'});
setTimeout(function () {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.projector, res);
}, mcopy.cfg.arduino.serialDelay);
});
} else {
setTimeout(function () {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.projector, res);
}, mcopy.cfg.arduino.serialDelay);
}
};
mcopy.cmd.proj_backward = function (callback) {
var res = function (ms) {
mcopy.state.projector.pos--;
mcopy.gui.updateState();
//gui action
mcopy.log('Projector moved -1 frame to ' + mcopy.state.projector.pos);
if (callback) { callback(); }
};
if (mcopy.state.projector.direction) {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.proj_backward, function (ms) {
mcopy.state.projector.direction = false;
mcopy.gui.trad.updateDir({value:'proj_backward'});
setTimeout(function () {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.projector, res);
}, mcopy.cfg.arduino.serialDelay);
});
} else {
setTimeout(function () {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.projector, res);
}, mcopy.cfg.arduino.serialDelay);
}
};
mcopy.cmd.black_forward = function (callback) {
var res = function (ms) {
mcopy.state.camera.pos++;
mcopy.gui.updateState();
//gui action
mcopy.log('Camera moved +1 BLACK frame to ' + mcopy.state.camera.pos);
if (callback) { callback(); }
};
if (!mcopy.state.camera.direction) {
mcopy.log('Advancing camera...');
mcopy.arduino.send(mcopy.cfg.arduino.cmd.cam_forward, function (ms) {
mcopy.state.camera.direction = true;
setTimeout(function () {
//black
mcopy.arduino.send(mcopy.cfg.arduino.cmd.black, res);
}, mcopy.cfg.arduino.serialDelay);
});
} else {
setTimeout(function () {
//black
mcopy.arduino.send(mcopy.cfg.arduino.cmd.black, res);
}, mcopy.cfg.arduino.serialDelay);
}
};
mcopy.cmd.black_backward = function (callback) {
var res = function (ms) {
mcopy.state.camera.pos--;
mcopy.gui.updateState();
//gui action
mcopy.log('Camera moved -1 BLACK frame to ' + mcopy.state.camera.pos);
if (callback) { callback(); }
};
if (mcopy.state.camera.direction) {
mcopy.log('Rewinding camera...');
mcopy.arduino.send(mcopy.cfg.arduino.cmd.cam_backward, function (ms) {
mcopy.state.camera.direction = false;
setTimeout(function () {
//black
mcopy.arduino.send(mcopy.cfg.arduino.cmd.black, res);
}, mcopy.cfg.arduino.serialDelay);
});
} else {
//black
mcopy.arduino.send(mcopy.cfg.arduino.cmd.black, res);
}
};*/
proj.queue = {};
proj.lock = false;
proj.init = function () {
'use strict';
proj.listen();
};
proj.set = function (dir, callback) {
'use strict';
var obj;
if (proj.lock) {
return false;
}
obj = {
dir : dir,
id : uuid.v4()
};
ipcRenderer.sendSync('proj', obj);
if (typeof callback !== 'undefined') {
obj.callback = callback;
}
proj.queue[obj.id] = obj;
proj.lock = true;
};
proj.move = function (callback) {
'use strict';
var obj;
if (proj.lock) {
return false;
}
obj = {
frame : true,
id : uuid.v4()
};
ipcRenderer.sendSync('proj', obj);
if (typeof callback !== 'undefined') {
obj.callback = callback;
}
proj.queue[obj.id] = obj;
proj.lock = true;
};
proj.end = function (cmd, id) {
'use strict';
if (cmd === mcopy.cfg.arduino.cmd.proj_forward) {
mcopy.state.projector.direction = true;
} else if (cmd === mcopy.cfg.arduino.cmd.proj_backward) {
mcopy.state.projector.direction = false;
} else if (cmd === mcopy.cfg.arduino.cmd.projector) {
if (mcopy.state.projector.direction) {
mcopy.state.projector.pos += 1;
} else {
mcopy.state.projector.pos -= 1;
}
}
if (typeof proj.queue[id] !== 'undefined') {
if (typeof proj.queue[id].callback !== 'undefined') {
proj.queue[id].callback();
}
delete proj.queue[id];
proj.lock = false;
}
};
proj.listen = function () {
'use strict';
ipcRenderer.on('proj', function (event, arg) {
proj.end(arg.cmd, arg.id);
return event.returnValue = true;
});
};
//LIGHT
light.preview_state = false; //light is on/off for preview viewing
light.color = [255, 255, 255]; //default color
light.current = [0, 0, 0]; //last sent
light.icon = {};
light.swatches = [
{
rgb : [0, 0, 0],
name : 'off'
},
{
rgb : [255, 255, 255],
name : 'white (LED)'
},
{
rgb : chroma.kelvin(2500).rgb(),
name : '2500 kelvin'
},
{
rgb : chroma.kelvin(5600).rgb(),
name : '5600 kelvin'
},
{
rgb : chroma.kelvin(6500).rgb(),
name : '6500 kelvin'
},
{
rgb : light.color,
set : true,
default : true
}
];
light.queue = {};
light.lock = false;
light.init = function () {
'use strict';
//create dynamic style for displaying light across screens
light.icon = document.createElement('style');
light.icon.innerHTML = 'span.mcopy-light{background-color: #000;}';
document.body.appendChild(light.icon);
light.colorPickers();
light.swatch.init();
light.listen();
light.display(light.current);
$('#preview').on('change', function () {
light.preview_state = $(this).prop('checked');
if (light.preview_state) {
light.display(light.color);
light.set(light.color);
} else {
light.display([0,0,0]);
light.set([0,0,0]);
}
});
};
light.colorPickers = function () {
'use strict';
$('#colors-tabs').w2tabs({
name: 'colors',
active: 'kelvin',
tabs: [
{ id: 'kelvin', caption: 'Kelvin'},
{ id: 'cmy', caption: 'CMY'},
{ id: 'rgb', caption: 'RGB' }
],
onClick: function (event) {
$('.colors-page').hide();
$('#' + event.target + '-page').show();
if (event.target === 'rgb') {
light.rgb.page();
}
}
});
light.rgb.init();
light.kelvin.init();
};
light.set = function (rgb, callback) { //rgb = [0,0,0]
'use strict';
var obj;
if (light.lock) {
//potential for logging overlapping commands
return false;
}
obj = {
rgb : rgb,
id : uuid.v4()
};
ipcRenderer.sendSync('light', obj);
if (typeof callback !== 'undefined') {
obj.callback = callback;
}
light.queue[obj.id] = obj;
light.current = rgb;
light.lock = true;
};
light.end = function (id) {
'use strict';
if (typeof light.queue[id] !== 'undefined') {
if (typeof light.queue[id].callback !== 'undefined') {
light.queue[id].callback();
}
delete light.queue[id];
light.lock = false;
}
}
light.listen = function () {
'use strict';
ipcRenderer.on('light', function (event, arg) {
light.end(arg.id);
return event.returnValue = true;
});
};
light.preview = function (rgb, name) {
'use strict';
var rgbStr;
rgb = light.rgb.floor(rgb);
rgbStr = 'rgb(' + rgb.join(',') + ')';
light.color = rgb;
if (typeof name === 'undefined') {
name = rgbStr;
}
$('#light-swatches .swatch.set').css('background', rgbStr)
.attr('color', rgb.join(','))
.prop('title', name);
if (light.preview_state) {
light.display(rgb);
light.set(rgb);
}
};
light.display = function (rgb) { //display light active state
'use strict';
var str,
i;
rgb = light.rgb.floor(rgb);
for (i = 0; i < 3; i++) {
$('#light-status form input').eq(i).val(rgb[i]);
}
str = 'rgb(' + rgb.join(',') + ')';
$('#color').css('background-color', str);
light.icon = document.styleSheets[document.styleSheets.length - 1];
light.icon.deleteRule(0);
light.icon.insertRule('span.mcopy-light{background-color: ' + str + ';}', 0)
};
//KELVIN GUI
light.kelvin = {};
light.kelvin.steps = 348;
light.kelvin.min = light.kelvin.steps * 4;
light.kelvin.max = 20000;
light.kelvin.moving = false;
light.kelvin.init = function () {
'use strict';
$('#kelvin').on('change', light.kelvin.change);
$('#kelvin').on('keypup', function (e) {
var code = e.keyCode || e.which;
if (code === 13) {
light.kelvin.change();
}
});
$('#kelvin-slider').on('mousemove', function (event) {
if (light.kelvin.moving) {
light.kelvin.click(this, event);
}
});
$('#kelvin-slider').on('mousedown', function (event) {
light.kelvin.moving = true;
light.kelvin.click(this, event);
});
$(document).on('mouseup', function () {
light.kelvin.moving = false;
});
light.kelvin.scale();
light.kelvin.set(5600); //default value
};
light.kelvin.change = function () {
'use strict';
var val = $('#kelvin').val(),
rgb = chroma.kelvin(val).rgb();
light.kelvin.pos(val);
light.preview(rgb, val + ' kelvin');
};
light.kelvin.scale = function () {
'use strict';
var i,
min = light.kelvin.min,
max = light.kelvin.max,
steps = light.kelvin.steps,
rgb,
elem,
elemStr = '<span style="background: rgb(XXXX);"></span>'
for (i = 0; i < steps; i++) {
rgb = chroma.kelvin((i * ((max - min) / steps)) + min).rgb();
rgb = light.rgb.floor(rgb).join(',');
elem = $(elemStr.replace('XXXX', rgb));
$('#kelvin-scale').append(elem);
}
};
light.kelvin.pos = function (kelvin) {
'use strict';
var min = light.kelvin.min,
max = light.kelvin.max,
steps = light.kelvin.steps,
start = -1,
pos = Math.round((kelvin - min) / ( (max - min) / steps)) + start;
if (pos < start) {
pos = start;
}
if (pos > steps) {
pos = steps;
}
$('#kelvin-pos').css('left', pos + 'px');
};
light.kelvin.set = function (kelvin) {
'use strict';
$('#kelvin').val(kelvin);
light.kelvin.change();
};
light.kelvin.click = function (t, e) {
'use strict';
var parentOffset = $(t).parent().offset(),
relX = e.pageX - parentOffset.left - 31, //?
min = light.kelvin.min,
max = light.kelvin.max,
steps = light.kelvin.steps,
kelvin = Math.round((relX * ((max - min) / steps)) + min);
light.kelvin.set(kelvin);
};
//CMY GUI
light.cmy = {};
light.cmy.init = function () {
'use strict';
};
//RGB GUI
light.rgb = {};
light.rgb.elem;
light.rgb.lock = true;
light.rgb.init = function () {
'use strict';
light.rgb.elem = jsColorPicker('#rgb', {
customBG: '#222',
readOnly: true,
size: 3,
appendTo : document.getElementById('rgb-page'),
// patch: false,
init: function(elm, colors) { // colors is a different instance (not connected to colorPicker)
elm.style.backgroundColor = elm.value;
elm.style.color = colors.rgbaMixCustom.luminance > 0.22 ? '#222' : '#ddd';
},
convertCallback: light.rgb.change
});
};
light.rgb.page = function () {
'use strict';
if (light.rgb.lock) {
$('#rgb').focus();
light.rgb.lock = false;
}
light.rgb.set(light.color);
};
light.rgb.change = function (colors, type) {
'use strict';
var a = colors.RND.rgb,
rgb = [a.r, a.g, a.b];
if (!light.rgb.lock) {
light.preview(rgb);
}
};
light.rgb.floor = function (rgb) {
'use strict';
return [
Math.floor(rgb[0]),
Math.floor(rgb[1]),
Math.floor(rgb[2])
];
};
light.rgb.set = function (rgb) {
'use strict';
var hex = chroma.rgb(rgb).hex();
light.rgb.elem.current.startRender();
light.rgb.elem.current.setColor(hex);
light.rgb.elem.current.stopRender();
};
//SWATCH GUI
light.swatch = {};
light.swatch.init = function () {
'use strict';
var number = 12,
add,
elem,
rgb,
i,
x;
for (i = 0; i < light.swatches.length; i++) {
light.swatches[i].rgb = light.rgb.floor(light.swatches[i].rgb);
rgb = 'rgb(' + light.swatches[i].rgb.join(',') + ')';
elem = $('<div class="swatch"></div>');
elem.css('background', rgb);
elem.attr('color', light.swatches[i].rgb.join(','));
if (typeof light.swatches[i].name !== 'undefined') {
elem.prop('title', light.swatches[i].name);
} else {
elem.prop('title', rgb);
}
if (light.swatches[i].default) {
elem.addClass('default');
}
if (light.swatches[i].set) {
elem.addClass('set');
}
$('#new-swatch').before(elem);
}
$('#new-swatch').on('click', light.swatch.add);
$(document.body).on('click', '#light-swatches .swatch', function () {
var rgb = $(this).attr('color');
if (typeof color !== 'undefined') {
rgb = rgb.split(',');
$('#light-swatches .swatch').removeClass('default set');
$(this).addClass('default set');
if (w2ui['colors'].active === 'rgb') {
light.rgb.set(light.color);
}
light.preview(rgb);
}
});
$(document.body).on('dblclick', '.swatch', function () {
});
};
light.swatch.add = function () {
'use strict';
var swatch = $('<div class="swatch default set"></div>');
$('#light-swatches .swatch').removeClass('default set');
$('#new-swatch').before(swatch);
light.preview(light.color);
};
//GUI
gui.fmtZero = function (val, len) {
var raw = val,
@ -3068,353 +3627,7 @@ gui.grid.events = function () {
});
};
//LIGHT
light.preview_state = false; //light is on/off for preview viewing
light.color = [255, 255, 255]; //default color
light.current = [0, 0, 0]; //last sent
light.icon = {};
light.swatches = [
{
rgb : [0, 0, 0],
name : 'off'
},
{
rgb : [255, 255, 255],
name : 'white (LED)'
},
{
rgb : chroma.kelvin(2500).rgb(),
name : '2500 kelvin'
},
{
rgb : chroma.kelvin(5600).rgb(),
name : '5600 kelvin'
},
{
rgb : chroma.kelvin(6500).rgb(),
name : '6500 kelvin'
},
{
rgb : light.color,
set : true,
default : true
}
];
light.queue = {};
light.lock = false;
light.init = function () {
'use strict';
//create dynamic style for displaying light across screens
light.icon = document.createElement('style');
light.icon.innerHTML = 'span.mcopy-light{background-color: #000;}';
document.body.appendChild(light.icon);
light.colorPickers();
light.swatch.init();
light.listen();
light.display(light.current);
$('#preview').on('change', function () {
light.preview_state = $(this).prop('checked');
if (light.preview_state) {
light.display(light.color);
light.set(light.color);
} else {
light.display([0,0,0]);
light.set([0,0,0]);
}
});
};
light.colorPickers = function () {
'use strict';
$('#colors-tabs').w2tabs({
name: 'colors',
active: 'kelvin',
tabs: [
{ id: 'kelvin', caption: 'Kelvin'},
{ id: 'cmy', caption: 'CMY'},
{ id: 'rgb', caption: 'RGB' }
],
onClick: function (event) {
$('.colors-page').hide();
$('#' + event.target + '-page').show();
if (event.target === 'rgb') {
light.rgb.page();
}
}
});
light.rgb.init();
light.kelvin.init();
};
light.set = function (rgb, callback) { //rgb = [0,0,0]
'use strict';
var obj;
if (light.lock) {
//potential for logging overlapping commands
return false;
}
obj = {
rgb : rgb,
id : uuid.v4()
};
ipcRenderer.sendSync('light', obj);
if (typeof callback !== 'undefined') {
obj.callback = callback;
}
light.queue[obj.id] = obj;
light.current = rgb;
light.lock = true;
};
light.end = function (id) {
'use strict';
if (typeof light.queue[id] !== 'undefined') {
if (typeof light.queue[id].callback !== 'undefined') {
light.queue[id].callback();
}
delete light.queue[id];
light.lock = false;
}
}
light.listen = function () {
'use strict';
ipcRenderer.on('light', function (event, arg) {
light.end(arg.id);
return event.returnValue = true;
});
};
light.preview = function (rgb, name) {
'use strict';
var rgbStr;
rgb = light.rgb.floor(rgb);
rgbStr = 'rgb(' + rgb.join(',') + ')';
light.color = rgb;
if (typeof name === 'undefined') {
name = rgbStr;
}
$('#light-swatches .swatch.set').css('background', rgbStr)
.attr('color', rgb.join(','))
.prop('title', name);
if (light.preview_state) {
light.display(rgb);
light.set(rgb);
}
};
light.display = function (rgb) { //display light active state
'use strict';
var str,
i;
rgb = light.rgb.floor(rgb);
for (i = 0; i < 3; i++) {
$('#light-status form input').eq(i).val(rgb[i]);
}
str = 'rgb(' + rgb.join(',') + ')';
$('#color').css('background-color', str);
light.icon = document.styleSheets[document.styleSheets.length - 1];
light.icon.deleteRule(0);
light.icon.insertRule('span.mcopy-light{background-color: ' + str + ';}', 0)
};
//KELVIN GUI
light.kelvin = {};
light.kelvin.steps = 348;
light.kelvin.min = light.kelvin.steps * 4;
light.kelvin.max = 20000;
light.kelvin.moving = false;
light.kelvin.init = function () {
'use strict';
$('#kelvin').on('change', light.kelvin.change);
$('#kelvin').on('keypup', function (e) {
var code = e.keyCode || e.which;
if (code === 13) {
light.kelvin.change();
}
});
$('#kelvin-slider').on('mousemove', function (event) {
if (light.kelvin.moving) {
light.kelvin.click(this, event);
}
});
$('#kelvin-slider').on('mousedown', function (event) {
light.kelvin.moving = true;
light.kelvin.click(this, event);
});
$(document).on('mouseup', function () {
light.kelvin.moving = false;
});
light.kelvin.scale();
light.kelvin.set(5600); //default value
};
light.kelvin.change = function () {
'use strict';
var val = $('#kelvin').val(),
rgb = chroma.kelvin(val).rgb();
light.kelvin.pos(val);
light.preview(rgb, val + ' kelvin');
};
light.kelvin.scale = function () {
'use strict';
var i,
min = light.kelvin.min,
max = light.kelvin.max,
steps = light.kelvin.steps,
rgb,
elem,
elemStr = '<span style="background: rgb(XXXX);"></span>'
for (i = 0; i < steps; i++) {
rgb = chroma.kelvin((i * ((max - min) / steps)) + min).rgb();
rgb = light.rgb.floor(rgb).join(',');
elem = $(elemStr.replace('XXXX', rgb));
$('#kelvin-scale').append(elem);
}
};
light.kelvin.pos = function (kelvin) {
'use strict';
var min = light.kelvin.min,
max = light.kelvin.max,
steps = light.kelvin.steps,
start = -1,
pos = Math.round((kelvin - min) / ( (max - min) / steps)) + start;
if (pos < start) {
pos = start;
}
if (pos > steps) {
pos = steps;
}
$('#kelvin-pos').css('left', pos + 'px');
};
light.kelvin.set = function (kelvin) {
'use strict';
$('#kelvin').val(kelvin);
light.kelvin.change();
};
light.kelvin.click = function (t, e) {
'use strict';
var parentOffset = $(t).parent().offset(),
relX = e.pageX - parentOffset.left - 31, //?
min = light.kelvin.min,
max = light.kelvin.max,
steps = light.kelvin.steps,
kelvin = Math.round((relX * ((max - min) / steps)) + min);
light.kelvin.set(kelvin);
};
//CMY GUI
light.cmy = {};
light.cmy.init = function () {
'use strict';
};
//RGB GUI
light.rgb = {};
light.rgb.elem;
light.rgb.lock = true;
light.rgb.init = function () {
'use strict';
light.rgb.elem = jsColorPicker('#rgb', {
customBG: '#222',
readOnly: true,
size: 3,
appendTo : document.getElementById('rgb-page'),
// patch: false,
init: function(elm, colors) { // colors is a different instance (not connected to colorPicker)
elm.style.backgroundColor = elm.value;
elm.style.color = colors.rgbaMixCustom.luminance > 0.22 ? '#222' : '#ddd';
},
convertCallback: light.rgb.change
});
};
light.rgb.page = function () {
'use strict';
if (light.rgb.lock) {
$('#rgb').focus();
light.rgb.lock = false;
}
light.rgb.set(light.color);
};
light.rgb.change = function (colors, type) {
'use strict';
var a = colors.RND.rgb,
rgb = [a.r, a.g, a.b];
if (!light.rgb.lock) {
light.preview(rgb);
}
};
light.rgb.floor = function (rgb) {
'use strict';
return [
Math.floor(rgb[0]),
Math.floor(rgb[1]),
Math.floor(rgb[2])
];
};
light.rgb.set = function (rgb) {
'use strict';
var hex = chroma.rgb(rgb).hex();
light.rgb.elem.current.startRender();
light.rgb.elem.current.setColor(hex);
light.rgb.elem.current.stopRender();
};
light.swatch = {};
light.swatch.init = function () {
'use strict';
var number = 12,
add,
elem,
rgb,
i,
x;
for (i = 0; i < light.swatches.length; i++) {
light.swatches[i].rgb = light.rgb.floor(light.swatches[i].rgb);
rgb = 'rgb(' + light.swatches[i].rgb.join(',') + ')';
elem = $('<div class="swatch"></div>');
elem.css('background', rgb);
elem.attr('color', light.swatches[i].rgb.join(','));
if (typeof light.swatches[i].name !== 'undefined') {
elem.prop('title', light.swatches[i].name);
} else {
elem.prop('title', rgb);
}
if (light.swatches[i].default) {
elem.addClass('default');
}
if (light.swatches[i].set) {
elem.addClass('set');
}
$('#new-swatch').before(elem);
}
$('#new-swatch').on('click', light.swatch.add);
$(document.body).on('click', '#light-swatches .swatch', function () {
var rgb = $(this).attr('color');
if (typeof color !== 'undefined') {
rgb = rgb.split(',');
$('#light-swatches .swatch').removeClass('default set');
$(this).addClass('default set');
if (w2ui['colors'].active === 'rgb') {
light.rgb.set(light.color);
}
light.preview(rgb);
}
});
$(document.body).on('dblclick', '.swatch', function () {
});
};
light.swatch.add = function () {
'use strict';
var swatch = $('<div class="swatch default set"></div>');
$('#light-swatches .swatch').removeClass('default set');
$('#new-swatch').before(swatch);
light.preview(light.color);
};
//NAV GUI
nav.init = function () {
'use strict';
$('#toolbar').w2toolbar({
@ -3448,7 +3661,8 @@ nav.change = function (id) {
var init = function () {
'use strict';
nav.init();
log.init();
gui.grid.init();
gui.grid.init();
log.init();
light.init();
proj.init();
};

View File

@ -124,7 +124,7 @@ mcopy.arduino.fakeConnect = function (callback) {
p : mcopy.cfg.arduino.proj.time + mcopy.cfg.arduino.proj.delay
},
timeout = t[cmd];
if (typeof timeout === 'undefined') timeout = 500;
if (typeof timeout === 'undefined') timeout = 10;
mcopy.arduino.timer = +new Date();
setTimeout(function () {
mcopy.arduino.end(cmd);

View File

@ -37,6 +37,8 @@ var init = function () {
//createMenu();
log.init();
light.init();
proj.init();
arduino = require('./lib/mcopy-arduino.js')(mcopy.cfg);
setTimeout(function () {
arduino.init(function (err, device) {
@ -239,6 +241,63 @@ light.end = function (rgb, id) {
mainWindow.webContents.send('light', {rgb: rgb, id : id});
};
var proj = {};
proj.state = {
dir : true //default dir
};
proj.init = function () {
'use strict';
proj.listen();
};
proj.set = function (dir, id) {
'use strict';
var cmd;
if (dir) {
cmd = mcopy.cfg.arduino.cmd.proj_forward;
} else {
cmd = mcopy.cfg.arduino.cmd.proj_backward;
}
proj.state.dir = dir;
arduino.send(cmd, function () {
proj.end(cmd, id);
});
};
proj.move = function (frame, id) {
'use strict';
arduino.send(mcopy.cfg.arduino.cmd.projector, function () {
proj.end(mcopy.cfg.arduino.cmd.projector, id);
});
};
proj.listen = function () {
'use strict';
ipcMain.on('proj', function (event, arg) {
if (typeof arg.dir !== 'undefined') {
proj.set(arg.dir, arg.id);
} else if (typeof arg.frame !== 'undefined') {
proj.move(arg.frame, arg.id);
}
event.returnValue = true;
});
};
proj.end = function (cmd, id) {
var message = '';
if (cmd === mcopy.cfg.arduino.cmd.proj_forward) {
message = 'Projector set to FORWARD';
} else if (cmd === mcopy.cfg.arduino.cmd.proj_backward) {
message = 'Projector set to BACKWARD';
} else if (cmd === mcopy.cfg.arduino.cmd.projector) {
message = 'Projector ';
if (proj.state.dir) {
message += 'ADVANCED';
} else {
message += 'REWOUND'
}
message += ' 1 frame';
}
log.info(message, 'PROJ', true, true);
mainWindow.webContents.send('proj', {cmd: cmd, id : id});
};
var log = {};
log.time = 'MM/DD/YY-HH:mm:ss';
log.transport = new (winston.Logger)({

View File

@ -7,6 +7,7 @@ var remote = require('remote'),
ipcRenderer = require('electron').ipcRenderer,
mcopy = {},
light = {},
proj = {},
nav = {},
seq = {},
gui = {},
@ -263,6 +264,564 @@ seq.clear = function () {
mcopy.state.sequence.arr = [];
};
/*
mcopy.cmd = {};
mcopy.cmd.cam_forward = function (callback) {
var res = function (ms) {
mcopy.state.camera.pos++;
//gui action
mcopy.gui.updateState();
mcopy.log('Camera moved +1 frame to ' + mcopy.state.camera.pos);
if (callback) { callback(); }
};
if (!mcopy.state.camera.direction) {
mcopy.log('Advancing camera...');
mcopy.arduino.send(mcopy.cfg.arduino.cmd.cam_forward, function (ms) {
mcopy.state.camera.direction = true;
mcopy.gui.trad.updateDir({value:'cam_forward'});
setTimeout(function () {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.camera, res);
}, mcopy.cfg.arduino.serialDelay);
});
} else {
setTimeout(function () {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.camera, res);
}, mcopy.cfg.arduino.serialDelay);
}
};
mcopy.cmd.cam_backward = function (callback) {
var res = function (ms) {
mcopy.state.camera.pos--;
//gui action
mcopy.gui.updateState();
mcopy.log('Camera moved -1 frame to ' + mcopy.state.camera.pos);
if (callback) { callback(); }
};
if (mcopy.state.camera.direction) {
mcopy.log('Rewinding camera...');
mcopy.arduino.send(mcopy.cfg.arduino.cmd.cam_backward, function (ms) {
mcopy.state.camera.direction = false;
mcopy.gui.trad.updateDir({value:'cam_backward'});
setTimeout(function () {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.camera, res);
}, mcopy.cfg.arduino.serialDelay);
});
} else {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.camera, res);
}
};
mcopy.cmd.proj_forward = function (callback) {
var res = function (ms) {
mcopy.state.projector.pos++;
mcopy.gui.updateState();
mcopy.log('Projector moved +1 frame to ' + mcopy.state.projector.pos);
//gui action
if (callback) { callback(); }
};
if (!mcopy.state.projector.direction) {
mcopy.log('Advancing projector...');
mcopy.arduino.send(mcopy.cfg.arduino.cmd.proj_forward, function (ms) {
mcopy.state.projector.direction = true;
mcopy.gui.trad.updateDir({value:'proj_forward'});
setTimeout(function () {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.projector, res);
}, mcopy.cfg.arduino.serialDelay);
});
} else {
setTimeout(function () {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.projector, res);
}, mcopy.cfg.arduino.serialDelay);
}
};
mcopy.cmd.proj_backward = function (callback) {
var res = function (ms) {
mcopy.state.projector.pos--;
mcopy.gui.updateState();
//gui action
mcopy.log('Projector moved -1 frame to ' + mcopy.state.projector.pos);
if (callback) { callback(); }
};
if (mcopy.state.projector.direction) {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.proj_backward, function (ms) {
mcopy.state.projector.direction = false;
mcopy.gui.trad.updateDir({value:'proj_backward'});
setTimeout(function () {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.projector, res);
}, mcopy.cfg.arduino.serialDelay);
});
} else {
setTimeout(function () {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.projector, res);
}, mcopy.cfg.arduino.serialDelay);
}
};
mcopy.cmd.black_forward = function (callback) {
var res = function (ms) {
mcopy.state.camera.pos++;
mcopy.gui.updateState();
//gui action
mcopy.log('Camera moved +1 BLACK frame to ' + mcopy.state.camera.pos);
if (callback) { callback(); }
};
if (!mcopy.state.camera.direction) {
mcopy.log('Advancing camera...');
mcopy.arduino.send(mcopy.cfg.arduino.cmd.cam_forward, function (ms) {
mcopy.state.camera.direction = true;
setTimeout(function () {
//black
mcopy.arduino.send(mcopy.cfg.arduino.cmd.black, res);
}, mcopy.cfg.arduino.serialDelay);
});
} else {
setTimeout(function () {
//black
mcopy.arduino.send(mcopy.cfg.arduino.cmd.black, res);
}, mcopy.cfg.arduino.serialDelay);
}
};
mcopy.cmd.black_backward = function (callback) {
var res = function (ms) {
mcopy.state.camera.pos--;
mcopy.gui.updateState();
//gui action
mcopy.log('Camera moved -1 BLACK frame to ' + mcopy.state.camera.pos);
if (callback) { callback(); }
};
if (mcopy.state.camera.direction) {
mcopy.log('Rewinding camera...');
mcopy.arduino.send(mcopy.cfg.arduino.cmd.cam_backward, function (ms) {
mcopy.state.camera.direction = false;
setTimeout(function () {
//black
mcopy.arduino.send(mcopy.cfg.arduino.cmd.black, res);
}, mcopy.cfg.arduino.serialDelay);
});
} else {
//black
mcopy.arduino.send(mcopy.cfg.arduino.cmd.black, res);
}
};*/
proj.queue = {};
proj.lock = false;
proj.init = function () {
'use strict';
proj.listen();
};
proj.set = function (dir, callback) {
'use strict';
var obj;
if (proj.lock) {
return false;
}
obj = {
dir : dir,
id : uuid.v4()
};
ipcRenderer.sendSync('proj', obj);
if (typeof callback !== 'undefined') {
obj.callback = callback;
}
proj.queue[obj.id] = obj;
proj.lock = true;
};
proj.move = function (callback) {
'use strict';
var obj;
if (proj.lock) {
return false;
}
obj = {
frame : true,
id : uuid.v4()
};
ipcRenderer.sendSync('proj', obj);
if (typeof callback !== 'undefined') {
obj.callback = callback;
}
proj.queue[obj.id] = obj;
proj.lock = true;
};
proj.end = function (cmd, id) {
'use strict';
if (cmd === mcopy.cfg.arduino.cmd.proj_forward) {
mcopy.state.projector.direction = true;
} else if (cmd === mcopy.cfg.arduino.cmd.proj_backward) {
mcopy.state.projector.direction = false;
} else if (cmd === mcopy.cfg.arduino.cmd.projector) {
if (mcopy.state.projector.direction) {
mcopy.state.projector.pos += 1;
} else {
mcopy.state.projector.pos -= 1;
}
}
if (typeof proj.queue[id] !== 'undefined') {
if (typeof proj.queue[id].callback !== 'undefined') {
proj.queue[id].callback();
}
delete proj.queue[id];
proj.lock = false;
}
};
proj.listen = function () {
'use strict';
ipcRenderer.on('proj', function (event, arg) {
proj.end(arg.cmd, arg.id);
return event.returnValue = true;
});
};
//LIGHT
light.preview_state = false; //light is on/off for preview viewing
light.color = [255, 255, 255]; //default color
light.current = [0, 0, 0]; //last sent
light.icon = {};
light.swatches = [
{
rgb : [0, 0, 0],
name : 'off'
},
{
rgb : [255, 255, 255],
name : 'white (LED)'
},
{
rgb : chroma.kelvin(2500).rgb(),
name : '2500 kelvin'
},
{
rgb : chroma.kelvin(5600).rgb(),
name : '5600 kelvin'
},
{
rgb : chroma.kelvin(6500).rgb(),
name : '6500 kelvin'
},
{
rgb : light.color,
set : true,
default : true
}
];
light.queue = {};
light.lock = false;
light.init = function () {
'use strict';
//create dynamic style for displaying light across screens
light.icon = document.createElement('style');
light.icon.innerHTML = 'span.mcopy-light{background-color: #000;}';
document.body.appendChild(light.icon);
light.colorPickers();
light.swatch.init();
light.listen();
light.display(light.current);
$('#preview').on('change', function () {
light.preview_state = $(this).prop('checked');
if (light.preview_state) {
light.display(light.color);
light.set(light.color);
} else {
light.display([0,0,0]);
light.set([0,0,0]);
}
});
};
light.colorPickers = function () {
'use strict';
$('#colors-tabs').w2tabs({
name: 'colors',
active: 'kelvin',
tabs: [
{ id: 'kelvin', caption: 'Kelvin'},
{ id: 'cmy', caption: 'CMY'},
{ id: 'rgb', caption: 'RGB' }
],
onClick: function (event) {
$('.colors-page').hide();
$('#' + event.target + '-page').show();
if (event.target === 'rgb') {
light.rgb.page();
}
}
});
light.rgb.init();
light.kelvin.init();
};
light.set = function (rgb, callback) { //rgb = [0,0,0]
'use strict';
var obj;
if (light.lock) {
//potential for logging overlapping commands
return false;
}
obj = {
rgb : rgb,
id : uuid.v4()
};
ipcRenderer.sendSync('light', obj);
if (typeof callback !== 'undefined') {
obj.callback = callback;
}
light.queue[obj.id] = obj;
light.current = rgb;
light.lock = true;
};
light.end = function (id) {
'use strict';
if (typeof light.queue[id] !== 'undefined') {
if (typeof light.queue[id].callback !== 'undefined') {
light.queue[id].callback();
}
delete light.queue[id];
light.lock = false;
}
}
light.listen = function () {
'use strict';
ipcRenderer.on('light', function (event, arg) {
light.end(arg.id);
return event.returnValue = true;
});
};
light.preview = function (rgb, name) {
'use strict';
var rgbStr;
rgb = light.rgb.floor(rgb);
rgbStr = 'rgb(' + rgb.join(',') + ')';
light.color = rgb;
if (typeof name === 'undefined') {
name = rgbStr;
}
$('#light-swatches .swatch.set').css('background', rgbStr)
.attr('color', rgb.join(','))
.prop('title', name);
if (light.preview_state) {
light.display(rgb);
light.set(rgb);
}
};
light.display = function (rgb) { //display light active state
'use strict';
var str,
i;
rgb = light.rgb.floor(rgb);
for (i = 0; i < 3; i++) {
$('#light-status form input').eq(i).val(rgb[i]);
}
str = 'rgb(' + rgb.join(',') + ')';
$('#color').css('background-color', str);
light.icon = document.styleSheets[document.styleSheets.length - 1];
light.icon.deleteRule(0);
light.icon.insertRule('span.mcopy-light{background-color: ' + str + ';}', 0)
};
//KELVIN GUI
light.kelvin = {};
light.kelvin.steps = 348;
light.kelvin.min = light.kelvin.steps * 4;
light.kelvin.max = 20000;
light.kelvin.moving = false;
light.kelvin.init = function () {
'use strict';
$('#kelvin').on('change', light.kelvin.change);
$('#kelvin').on('keypup', function (e) {
var code = e.keyCode || e.which;
if (code === 13) {
light.kelvin.change();
}
});
$('#kelvin-slider').on('mousemove', function (event) {
if (light.kelvin.moving) {
light.kelvin.click(this, event);
}
});
$('#kelvin-slider').on('mousedown', function (event) {
light.kelvin.moving = true;
light.kelvin.click(this, event);
});
$(document).on('mouseup', function () {
light.kelvin.moving = false;
});
light.kelvin.scale();
light.kelvin.set(5600); //default value
};
light.kelvin.change = function () {
'use strict';
var val = $('#kelvin').val(),
rgb = chroma.kelvin(val).rgb();
light.kelvin.pos(val);
light.preview(rgb, val + ' kelvin');
};
light.kelvin.scale = function () {
'use strict';
var i,
min = light.kelvin.min,
max = light.kelvin.max,
steps = light.kelvin.steps,
rgb,
elem,
elemStr = '<span style="background: rgb(XXXX);"></span>'
for (i = 0; i < steps; i++) {
rgb = chroma.kelvin((i * ((max - min) / steps)) + min).rgb();
rgb = light.rgb.floor(rgb).join(',');
elem = $(elemStr.replace('XXXX', rgb));
$('#kelvin-scale').append(elem);
}
};
light.kelvin.pos = function (kelvin) {
'use strict';
var min = light.kelvin.min,
max = light.kelvin.max,
steps = light.kelvin.steps,
start = -1,
pos = Math.round((kelvin - min) / ( (max - min) / steps)) + start;
if (pos < start) {
pos = start;
}
if (pos > steps) {
pos = steps;
}
$('#kelvin-pos').css('left', pos + 'px');
};
light.kelvin.set = function (kelvin) {
'use strict';
$('#kelvin').val(kelvin);
light.kelvin.change();
};
light.kelvin.click = function (t, e) {
'use strict';
var parentOffset = $(t).parent().offset(),
relX = e.pageX - parentOffset.left - 31, //?
min = light.kelvin.min,
max = light.kelvin.max,
steps = light.kelvin.steps,
kelvin = Math.round((relX * ((max - min) / steps)) + min);
light.kelvin.set(kelvin);
};
//CMY GUI
light.cmy = {};
light.cmy.init = function () {
'use strict';
};
//RGB GUI
light.rgb = {};
light.rgb.elem;
light.rgb.lock = true;
light.rgb.init = function () {
'use strict';
light.rgb.elem = jsColorPicker('#rgb', {
customBG: '#222',
readOnly: true,
size: 3,
appendTo : document.getElementById('rgb-page'),
// patch: false,
init: function(elm, colors) { // colors is a different instance (not connected to colorPicker)
elm.style.backgroundColor = elm.value;
elm.style.color = colors.rgbaMixCustom.luminance > 0.22 ? '#222' : '#ddd';
},
convertCallback: light.rgb.change
});
};
light.rgb.page = function () {
'use strict';
if (light.rgb.lock) {
$('#rgb').focus();
light.rgb.lock = false;
}
light.rgb.set(light.color);
};
light.rgb.change = function (colors, type) {
'use strict';
var a = colors.RND.rgb,
rgb = [a.r, a.g, a.b];
if (!light.rgb.lock) {
light.preview(rgb);
}
};
light.rgb.floor = function (rgb) {
'use strict';
return [
Math.floor(rgb[0]),
Math.floor(rgb[1]),
Math.floor(rgb[2])
];
};
light.rgb.set = function (rgb) {
'use strict';
var hex = chroma.rgb(rgb).hex();
light.rgb.elem.current.startRender();
light.rgb.elem.current.setColor(hex);
light.rgb.elem.current.stopRender();
};
//SWATCH GUI
light.swatch = {};
light.swatch.init = function () {
'use strict';
var number = 12,
add,
elem,
rgb,
i,
x;
for (i = 0; i < light.swatches.length; i++) {
light.swatches[i].rgb = light.rgb.floor(light.swatches[i].rgb);
rgb = 'rgb(' + light.swatches[i].rgb.join(',') + ')';
elem = $('<div class="swatch"></div>');
elem.css('background', rgb);
elem.attr('color', light.swatches[i].rgb.join(','));
if (typeof light.swatches[i].name !== 'undefined') {
elem.prop('title', light.swatches[i].name);
} else {
elem.prop('title', rgb);
}
if (light.swatches[i].default) {
elem.addClass('default');
}
if (light.swatches[i].set) {
elem.addClass('set');
}
$('#new-swatch').before(elem);
}
$('#new-swatch').on('click', light.swatch.add);
$(document.body).on('click', '#light-swatches .swatch', function () {
var rgb = $(this).attr('color');
if (typeof color !== 'undefined') {
rgb = rgb.split(',');
$('#light-swatches .swatch').removeClass('default set');
$(this).addClass('default set');
if (w2ui['colors'].active === 'rgb') {
light.rgb.set(light.color);
}
light.preview(rgb);
}
});
$(document.body).on('dblclick', '.swatch', function () {
});
};
light.swatch.add = function () {
'use strict';
var swatch = $('<div class="swatch default set"></div>');
$('#light-swatches .swatch').removeClass('default set');
$('#new-swatch').before(swatch);
light.preview(light.color);
};
//GUI
gui.fmtZero = function (val, len) {
var raw = val,
@ -612,353 +1171,7 @@ gui.grid.events = function () {
});
};
//LIGHT
light.preview_state = false; //light is on/off for preview viewing
light.color = [255, 255, 255]; //default color
light.current = [0, 0, 0]; //last sent
light.icon = {};
light.swatches = [
{
rgb : [0, 0, 0],
name : 'off'
},
{
rgb : [255, 255, 255],
name : 'white (LED)'
},
{
rgb : chroma.kelvin(2500).rgb(),
name : '2500 kelvin'
},
{
rgb : chroma.kelvin(5600).rgb(),
name : '5600 kelvin'
},
{
rgb : chroma.kelvin(6500).rgb(),
name : '6500 kelvin'
},
{
rgb : light.color,
set : true,
default : true
}
];
light.queue = {};
light.lock = false;
light.init = function () {
'use strict';
//create dynamic style for displaying light across screens
light.icon = document.createElement('style');
light.icon.innerHTML = 'span.mcopy-light{background-color: #000;}';
document.body.appendChild(light.icon);
light.colorPickers();
light.swatch.init();
light.listen();
light.display(light.current);
$('#preview').on('change', function () {
light.preview_state = $(this).prop('checked');
if (light.preview_state) {
light.display(light.color);
light.set(light.color);
} else {
light.display([0,0,0]);
light.set([0,0,0]);
}
});
};
light.colorPickers = function () {
'use strict';
$('#colors-tabs').w2tabs({
name: 'colors',
active: 'kelvin',
tabs: [
{ id: 'kelvin', caption: 'Kelvin'},
{ id: 'cmy', caption: 'CMY'},
{ id: 'rgb', caption: 'RGB' }
],
onClick: function (event) {
$('.colors-page').hide();
$('#' + event.target + '-page').show();
if (event.target === 'rgb') {
light.rgb.page();
}
}
});
light.rgb.init();
light.kelvin.init();
};
light.set = function (rgb, callback) { //rgb = [0,0,0]
'use strict';
var obj;
if (light.lock) {
//potential for logging overlapping commands
return false;
}
obj = {
rgb : rgb,
id : uuid.v4()
};
ipcRenderer.sendSync('light', obj);
if (typeof callback !== 'undefined') {
obj.callback = callback;
}
light.queue[obj.id] = obj;
light.current = rgb;
light.lock = true;
};
light.end = function (id) {
'use strict';
if (typeof light.queue[id] !== 'undefined') {
if (typeof light.queue[id].callback !== 'undefined') {
light.queue[id].callback();
}
delete light.queue[id];
light.lock = false;
}
}
light.listen = function () {
'use strict';
ipcRenderer.on('light', function (event, arg) {
light.end(arg.id);
return event.returnValue = true;
});
};
light.preview = function (rgb, name) {
'use strict';
var rgbStr;
rgb = light.rgb.floor(rgb);
rgbStr = 'rgb(' + rgb.join(',') + ')';
light.color = rgb;
if (typeof name === 'undefined') {
name = rgbStr;
}
$('#light-swatches .swatch.set').css('background', rgbStr)
.attr('color', rgb.join(','))
.prop('title', name);
if (light.preview_state) {
light.display(rgb);
light.set(rgb);
}
};
light.display = function (rgb) { //display light active state
'use strict';
var str,
i;
rgb = light.rgb.floor(rgb);
for (i = 0; i < 3; i++) {
$('#light-status form input').eq(i).val(rgb[i]);
}
str = 'rgb(' + rgb.join(',') + ')';
$('#color').css('background-color', str);
light.icon = document.styleSheets[document.styleSheets.length - 1];
light.icon.deleteRule(0);
light.icon.insertRule('span.mcopy-light{background-color: ' + str + ';}', 0)
};
//KELVIN GUI
light.kelvin = {};
light.kelvin.steps = 348;
light.kelvin.min = light.kelvin.steps * 4;
light.kelvin.max = 20000;
light.kelvin.moving = false;
light.kelvin.init = function () {
'use strict';
$('#kelvin').on('change', light.kelvin.change);
$('#kelvin').on('keypup', function (e) {
var code = e.keyCode || e.which;
if (code === 13) {
light.kelvin.change();
}
});
$('#kelvin-slider').on('mousemove', function (event) {
if (light.kelvin.moving) {
light.kelvin.click(this, event);
}
});
$('#kelvin-slider').on('mousedown', function (event) {
light.kelvin.moving = true;
light.kelvin.click(this, event);
});
$(document).on('mouseup', function () {
light.kelvin.moving = false;
});
light.kelvin.scale();
light.kelvin.set(5600); //default value
};
light.kelvin.change = function () {
'use strict';
var val = $('#kelvin').val(),
rgb = chroma.kelvin(val).rgb();
light.kelvin.pos(val);
light.preview(rgb, val + ' kelvin');
};
light.kelvin.scale = function () {
'use strict';
var i,
min = light.kelvin.min,
max = light.kelvin.max,
steps = light.kelvin.steps,
rgb,
elem,
elemStr = '<span style="background: rgb(XXXX);"></span>'
for (i = 0; i < steps; i++) {
rgb = chroma.kelvin((i * ((max - min) / steps)) + min).rgb();
rgb = light.rgb.floor(rgb).join(',');
elem = $(elemStr.replace('XXXX', rgb));
$('#kelvin-scale').append(elem);
}
};
light.kelvin.pos = function (kelvin) {
'use strict';
var min = light.kelvin.min,
max = light.kelvin.max,
steps = light.kelvin.steps,
start = -1,
pos = Math.round((kelvin - min) / ( (max - min) / steps)) + start;
if (pos < start) {
pos = start;
}
if (pos > steps) {
pos = steps;
}
$('#kelvin-pos').css('left', pos + 'px');
};
light.kelvin.set = function (kelvin) {
'use strict';
$('#kelvin').val(kelvin);
light.kelvin.change();
};
light.kelvin.click = function (t, e) {
'use strict';
var parentOffset = $(t).parent().offset(),
relX = e.pageX - parentOffset.left - 31, //?
min = light.kelvin.min,
max = light.kelvin.max,
steps = light.kelvin.steps,
kelvin = Math.round((relX * ((max - min) / steps)) + min);
light.kelvin.set(kelvin);
};
//CMY GUI
light.cmy = {};
light.cmy.init = function () {
'use strict';
};
//RGB GUI
light.rgb = {};
light.rgb.elem;
light.rgb.lock = true;
light.rgb.init = function () {
'use strict';
light.rgb.elem = jsColorPicker('#rgb', {
customBG: '#222',
readOnly: true,
size: 3,
appendTo : document.getElementById('rgb-page'),
// patch: false,
init: function(elm, colors) { // colors is a different instance (not connected to colorPicker)
elm.style.backgroundColor = elm.value;
elm.style.color = colors.rgbaMixCustom.luminance > 0.22 ? '#222' : '#ddd';
},
convertCallback: light.rgb.change
});
};
light.rgb.page = function () {
'use strict';
if (light.rgb.lock) {
$('#rgb').focus();
light.rgb.lock = false;
}
light.rgb.set(light.color);
};
light.rgb.change = function (colors, type) {
'use strict';
var a = colors.RND.rgb,
rgb = [a.r, a.g, a.b];
if (!light.rgb.lock) {
light.preview(rgb);
}
};
light.rgb.floor = function (rgb) {
'use strict';
return [
Math.floor(rgb[0]),
Math.floor(rgb[1]),
Math.floor(rgb[2])
];
};
light.rgb.set = function (rgb) {
'use strict';
var hex = chroma.rgb(rgb).hex();
light.rgb.elem.current.startRender();
light.rgb.elem.current.setColor(hex);
light.rgb.elem.current.stopRender();
};
light.swatch = {};
light.swatch.init = function () {
'use strict';
var number = 12,
add,
elem,
rgb,
i,
x;
for (i = 0; i < light.swatches.length; i++) {
light.swatches[i].rgb = light.rgb.floor(light.swatches[i].rgb);
rgb = 'rgb(' + light.swatches[i].rgb.join(',') + ')';
elem = $('<div class="swatch"></div>');
elem.css('background', rgb);
elem.attr('color', light.swatches[i].rgb.join(','));
if (typeof light.swatches[i].name !== 'undefined') {
elem.prop('title', light.swatches[i].name);
} else {
elem.prop('title', rgb);
}
if (light.swatches[i].default) {
elem.addClass('default');
}
if (light.swatches[i].set) {
elem.addClass('set');
}
$('#new-swatch').before(elem);
}
$('#new-swatch').on('click', light.swatch.add);
$(document.body).on('click', '#light-swatches .swatch', function () {
var rgb = $(this).attr('color');
if (typeof color !== 'undefined') {
rgb = rgb.split(',');
$('#light-swatches .swatch').removeClass('default set');
$(this).addClass('default set');
if (w2ui['colors'].active === 'rgb') {
light.rgb.set(light.color);
}
light.preview(rgb);
}
});
$(document.body).on('dblclick', '.swatch', function () {
});
};
light.swatch.add = function () {
'use strict';
var swatch = $('<div class="swatch default set"></div>');
$('#light-swatches .swatch').removeClass('default set');
$('#new-swatch').before(swatch);
light.preview(light.color);
};
//NAV GUI
nav.init = function () {
'use strict';
$('#toolbar').w2toolbar({
@ -992,7 +1205,8 @@ nav.change = function (id) {
var init = function () {
'use strict';
nav.init();
log.init();
gui.grid.init();
gui.grid.init();
log.init();
light.init();
proj.init();
};