migrated pen trails and webcam layers

pull/95/head
jmoenig 2020-03-10 15:00:50 +01:00
rodzic 9ea3e8fcf1
commit a09fb2a015
1 zmienionych plików z 51 dodań i 88 usunięć

Wyświetl plik

@ -1978,7 +1978,7 @@ SpriteMorph.prototype.render = function (ctx) {
} }
} }
// apply graphics effects to image // apply graphics effects to image
this.cachedImage = this.applyGraphicsEffects(this.cachedImage); // ++++ this.cachedImage = this.applyGraphicsEffects(this.cachedImage);
this.version = Date.now(); this.version = Date.now();
}; };
@ -7595,8 +7595,6 @@ StageMorph.prototype.moveBy = function (delta) {
// StageMorph rendering // StageMorph rendering
StageMorph.prototype.render = function (ctx) { StageMorph.prototype.render = function (ctx) {
// +++ to do: make sure to also draw the additional layers either here
// +++ or in drawOn()
ctx.save(); ctx.save();
ctx.fillStyle = this.color.toString(); ctx.fillStyle = this.color.toString();
ctx.fillRect(0, 0, this.width(), this.height()); ctx.fillRect(0, 0, this.width(), this.height());
@ -7607,103 +7605,68 @@ StageMorph.prototype.render = function (ctx) {
(this.width() / this.scale - this.costume.width()) / 2, (this.width() / this.scale - this.costume.width()) / 2,
(this.height() / this.scale - this.costume.height()) / 2 (this.height() / this.scale - this.costume.height()) / 2
); );
this.cachedImage = this.applyGraphicsEffects(this.cachedImage); // ++++ this.cachedImage = this.applyGraphicsEffects(this.cachedImage);
} }
ctx.restore(); ctx.restore();
this.version = Date.now(); // for observer optimization this.version = Date.now(); // for observer optimization
}; };
/* +++ commented out for refactoring
StageMorph.prototype.drawOn = function (ctx, rect) { StageMorph.prototype.drawOn = function (ctx, rect) {
// make sure to draw the pen trails canvas as well // draw pen trails and webcam layers
var rectangle, area, delta, src, w, h, sl, st, ws, hs; var clipped = rect.intersect(this.bounds),
if (!this.isVisible) { pos, src, w, h, sl, st, ws, hs;
return null;
}
// +++ rectangle = rect || this.bounds; // +++ we don't need this, right?
area = rectangle.intersect(this.bounds); // okay, we need to review all of this
if (area.extent().gt(Zero)) {
delta = this.position().neg();
src = area.translateBy(delta);
ctx.globalAlpha = this.alpha;
if (!this.isVisible || !clipped.extent().gt(ZERO)) {
return;
}
// costume, if any, and background color
StageMorph.uber.drawOn.call(this, ctx, rect);
pos = this.position();
src = clipped.translateBy(pos.neg());
sl = src.left(); sl = src.left();
st = src.top(); st = src.top();
w = Math.min(src.width(), this.image.width - sl); w = src.width();
h = Math.min(src.height(), this.image.height - st); h = src.height();
if (w < 1 || h < 1) {
return null;
}
context.drawImage(
this.image,
sl,
st,
w,
h,
area.left(),
area.top(),
w,
h
);
// projection layer (webcam, maps, etc.)
if (this.projectionSource) {
ws = w / this.scale; ws = w / this.scale;
hs = h / this.scale; hs = h / this.scale;
context.save();
context.scale(this.scale, this.scale); ctx.save();
context.globalAlpha = 1 - (this.projectionTransparency / 100); ctx.scale(this.scale, this.scale);
context.drawImage(
// projection layer (e.g. webcam)
if (this.projectionSource) {
ctx.globalAlpha = 1 - (this.projectionTransparency / 100);
ctx.drawImage(
this.projectionLayer(), this.projectionLayer(),
sl / this.scale, sl / this.scale,
st / this.scale, st / this.scale,
ws, ws,
hs, hs,
area.left() / this.scale, clipped.left() / this.scale,
area.top() / this.scale, clipped.top() / this.scale,
ws, ws,
hs hs
); );
context.restore();
this.version = Date.now(); // update watcher icons this.version = Date.now(); // update watcher icons
} }
// pen trails // pen trails
ws = w / this.scale; ctx.drawImage(
hs = h / this.scale;
context.save();
context.scale(this.scale, this.scale);
try {
context.drawImage(
this.penTrails(), this.penTrails(),
sl / this.scale, sl / this.scale,
st / this.scale, st / this.scale,
ws, ws,
hs, hs,
area.left() / this.scale, clipped.left() / this.scale,
area.top() / this.scale, clipped.top() / this.scale,
ws, ws,
hs hs
); );
} catch (err) { // sometimes triggered only by Firefox
// console.log(err); ctx.restore();
context.restore();
context.drawImage(
this.penTrails(),
0,
0,
this.dimensions.x,
this.dimensions.y,
this.left(),
this.top(),
this.dimensions.x * this.scale,
this.dimensions.y * this.scale
);
}
context.restore();
}
}; };
*/
StageMorph.prototype.clearPenTrails = function () { StageMorph.prototype.clearPenTrails = function () {
this.cachedPenTrailsMorph = null; this.cachedPenTrailsMorph = null;