companion-module-utils
Version:
Utility tools for use in Bitfocus Companion modules
134 lines (133 loc) • 5.59 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.meter1 = exports.boxes = void 0;
const graphics_1 = require("./graphics");
const util_1 = require("./util");
const boxes = (options) => {
const boxOptions = [...options.boxes].slice(0, 6);
const boxArray = [];
boxOptions.forEach((boxOption, index) => {
let offsetX = 0;
let offsetY = 0;
if (options.position === 'top' || options.position === 'bottom') {
offsetY = options.position === 'top' ? 2 : options.height - 10;
offsetX = (options.width - boxOptions.length * 10) / 2 + index * 10;
}
if (options.position === 'left' || options.position === 'right') {
offsetX = options.position === 'left' ? 2 : 62;
offsetY = (options.height - boxOptions.length * 10) / 2 + index * 10;
}
const box = (0, graphics_1.rect)({
width: options.width,
height: options.height,
offsetX,
offsetY,
color: boxOption.borderColor,
opacity: boxOption.borderOpacity,
fillColor: boxOption.fillColor,
fillOpacity: boxOption.fillOpacity,
rectHeight: 8,
rectWidth: 8,
strokeWidth: 1,
});
boxArray.push(box);
});
return (0, graphics_1.stackImage)(boxArray);
};
exports.boxes = boxes;
const meter1 = (options) => {
const muted = options.muted !== undefined ? options.muted : false;
const bars2 = options.meter2 !== undefined;
const bar1 = (0, graphics_1.bar)({
width: options.width,
height: options.height,
colors: [
{
size: 35,
color: muted ? (0, util_1.combineRGB)(0, 128, 128) : (0, util_1.combineRGB)(0, 128, 0),
background: muted ? (0, util_1.combineRGB)(0, 128, 128) : (0, util_1.combineRGB)(0, 128, 0),
backgroundOpacity: 64,
},
{
size: 25,
color: muted ? (0, util_1.combineRGB)(0, 192, 192) : (0, util_1.combineRGB)(0, 192, 0),
background: muted ? (0, util_1.combineRGB)(0, 192, 192) : (0, util_1.combineRGB)(0, 192, 0),
backgroundOpacity: 64,
},
{
size: 25,
color: muted ? (0, util_1.combineRGB)(0, 255, 255) : (0, util_1.combineRGB)(0, 255, 0),
background: muted ? (0, util_1.combineRGB)(0, 255, 255) : (0, util_1.combineRGB)(0, 255, 0),
backgroundOpacity: 64,
},
{
size: 10,
color: muted ? (0, util_1.combineRGB)(255, 255, 116) : (0, util_1.combineRGB)(255, 255, 0),
background: muted ? (0, util_1.combineRGB)(255, 255, 116) : (0, util_1.combineRGB)(225, 225, 0),
backgroundOpacity: 64,
},
{
size: 5,
color: muted ? (0, util_1.combineRGB)(255, 0, 0) : (0, util_1.combineRGB)(255, 0, 0),
background: muted ? (0, util_1.combineRGB)(255, 0, 0) : (0, util_1.combineRGB)(255, 0, 0),
backgroundOpacity: 64,
},
],
opacity: 255,
offsetX: bars2 ? 54 : 62,
offsetY: 5,
barLength: options.height - 10,
barWidth: 6,
value: options.meter1,
type: 'vertical',
});
let bar2;
if (bars2) {
bar2 = (0, graphics_1.bar)({
width: options.width,
height: options.height,
colors: [
{
size: 35,
color: muted ? (0, util_1.combineRGB)(0, 128, 128) : (0, util_1.combineRGB)(0, 128, 0),
background: muted ? (0, util_1.combineRGB)(0, 128, 128) : (0, util_1.combineRGB)(0, 128, 0),
backgroundOpacity: 64,
},
{
size: 25,
color: muted ? (0, util_1.combineRGB)(0, 192, 192) : (0, util_1.combineRGB)(0, 192, 0),
background: muted ? (0, util_1.combineRGB)(0, 192, 192) : (0, util_1.combineRGB)(0, 192, 0),
backgroundOpacity: 64,
},
{
size: 25,
color: muted ? (0, util_1.combineRGB)(0, 255, 255) : (0, util_1.combineRGB)(0, 255, 0),
background: muted ? (0, util_1.combineRGB)(0, 255, 255) : (0, util_1.combineRGB)(0, 255, 0),
backgroundOpacity: 64,
},
{
size: 10,
color: muted ? (0, util_1.combineRGB)(255, 255, 116) : (0, util_1.combineRGB)(255, 255, 0),
background: muted ? (0, util_1.combineRGB)(255, 255, 116) : (0, util_1.combineRGB)(225, 225, 0),
backgroundOpacity: 64,
},
{
size: 5,
color: muted ? (0, util_1.combineRGB)(255, 0, 0) : (0, util_1.combineRGB)(255, 0, 0),
background: muted ? (0, util_1.combineRGB)(255, 0, 0) : (0, util_1.combineRGB)(255, 0, 0),
backgroundOpacity: 64,
},
],
opacity: 255,
offsetX: 62,
offsetY: 5,
barLength: options.height - 10,
barWidth: 6,
value: options.meter2,
type: 'vertical',
});
return (0, graphics_1.stackImage)([bar1, bar2]);
}
return bar1;
};
exports.meter1 = meter1;