Skip to content
This repository has been archived by the owner on Jul 17, 2020. It is now read-only.

Commit

Permalink
fix(gallery): fixes draw loop to not draw gallery to output
Browse files Browse the repository at this point in the history
Adds a check for the gallery group and only draws to the defined drawTo property on the group

fix #92
  • Loading branch information
2xAA committed May 15, 2020
1 parent 9c87bec commit 62f984b
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions src/application/worker/loop.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import get from "lodash.get";
import store from "./store";
import map from "../utils/map";
import constants from "../constants";
import { applyWindow } from "meyda/src/utilities";

const meyda = { windowing: applyWindow };
Expand Down Expand Up @@ -91,6 +92,8 @@ function loop(delta, features) {
const groupsLength = groups.length;
for (let i = 0; i < groupsLength; ++i) {
const group = groups[i];
const isGalleryGroup = group.name === constants.GALLERY_GROUP_NAME;

const groupModulesLength = group.modules.length;
if (!group.enabled || group.alpha < 0.001) {
continue;
Expand All @@ -107,15 +110,10 @@ function loop(delta, features) {
}

if (clearing) {
groupContext.clearRect(
0,
0,
groupContext.canvas.width,
groupContext.canvas.height
);
drawTo.clearRect(0, 0, drawTo.canvas.width, drawTo.canvas.height);
}

if (pipeline && clearing) {
if (pipeline && clearing && !isGalleryGroup) {
bufferContext.clearRect(
0,
0,
Expand All @@ -125,15 +123,15 @@ function loop(delta, features) {
}

if (inherit) {
groupContext.drawImage(
drawTo.drawImage(
lastCanvas,
0,
0,
drawTo.canvas.width,
drawTo.canvas.height
);

if (pipeline) {
if (pipeline && !isGalleryGroup) {
bufferContext.drawImage(
lastCanvas,
0,
Expand All @@ -146,19 +144,21 @@ function loop(delta, features) {

let firstModuleDrawn = false;
for (let j = 0; j < groupModulesLength; ++j) {
let canvas = groupContext.canvas;
let canvas = drawTo.canvas;

const module = active[group.modules[j]];

if (!module.meta.enabled || module.meta.alpha < 0.001) {
continue;
}

if (pipeline && firstModuleDrawn) {
if (pipeline && firstModuleDrawn && !isGalleryGroup) {
canvas = bufferContext.canvas;
} else if (pipeline) {
canvas = groupContext.canvas;
} else if (pipeline && !isGalleryGroup) {
canvas = drawTo.canvas;
firstModuleDrawn = true;
} else if (isGalleryGroup) {
canvas = aux.canvas;
}

drawTo.save();
Expand Down Expand Up @@ -186,14 +186,14 @@ function loop(delta, features) {
});
}

if (pipeline) {
groupContext.clearRect(0, 0, canvas.width, canvas.height);
groupContext.drawImage(bufferCanvas, 0, 0, canvas.width, canvas.height);
if (pipeline && !isGalleryGroup) {
drawTo.clearRect(0, 0, canvas.width, canvas.height);
drawTo.drawImage(bufferCanvas, 0, 0, canvas.width, canvas.height);
}

renderers[module.meta.type].render({
canvas,
context: groupContext,
context: drawTo,
delta,
module: moduleDefinition,
features,
Expand All @@ -205,18 +205,18 @@ function loop(delta, features) {
});
drawTo.restore();

if (pipeline) {
if (pipeline && !isGalleryGroup) {
bufferContext.clearRect(0, 0, canvas.width, canvas.height);
bufferContext.drawImage(
groupContext.canvas,
drawTo.canvas,
0,
0,
canvas.width,
canvas.height
);

groupContext.clearRect(0, 0, canvas.width, canvas.height);
groupContext.drawImage(
drawTo.clearRect(0, 0, canvas.width, canvas.height);
drawTo.drawImage(
bufferCanvas,
0,
0,
Expand All @@ -227,7 +227,7 @@ function loop(delta, features) {
}

if (!group.hidden) {
lastCanvas = groupContext.canvas;
lastCanvas = drawTo.canvas;
}
}

Expand All @@ -237,6 +237,8 @@ function loop(delta, features) {
main.clearRect(0, 0, main.canvas.width, main.canvas.height);
for (let i = 0; i < groupsLength; ++i) {
const group = groups[i];
const isGalleryGroup = group.name === constants.GALLERY_GROUP_NAME;

const {
compositeOperation,
context: { context },
Expand All @@ -245,7 +247,7 @@ function loop(delta, features) {
modules
} = group;
const groupModulesLength = modules.length;
if (!enabled || groupModulesLength < 1 || !(alpha > 0)) {
if (!enabled || groupModulesLength < 1 || !(alpha > 0) || isGalleryGroup) {
continue;
}

Expand Down

0 comments on commit 62f984b

Please sign in to comment.