refactored script pic for fading blocks

pull/95/head
jmoenig 2020-08-04 14:55:10 +02:00
rodzic ac8220bdaf
commit 40274d04f9
1 zmienionych plików z 18 dodań i 30 usunięć

Wyświetl plik

@ -4043,14 +4043,11 @@ BlockMorph.prototype.thumbnail = function (scale, clipWidth) {
BlockMorph.prototype.scriptPic = function () { BlockMorph.prototype.scriptPic = function () {
// answer a canvas image that also includes comments // answer a canvas image that also includes comments
if (this.alpha < 1) { var scr = this.fullScriptImage(),
return this.scriptPicOnBackground();
}
var scr = this.fullImage(),
fb = this.stackFullBounds(), fb = this.stackFullBounds(),
pic = newCanvas(fb.extent()), pic = newCanvas(fb.extent()),
ctx = pic.getContext('2d'); ctx = pic.getContext('2d');
this.allComments().forEach(comment => this.allComments().forEach(comment =>
ctx.drawImage( ctx.drawImage(
comment.fullImage(), comment.fullImage(),
@ -4062,33 +4059,24 @@ BlockMorph.prototype.scriptPic = function () {
return pic; return pic;
}; };
BlockMorph.prototype.scriptPicOnBackground = function () { BlockMorph.prototype.fullScriptImage = function () {
// answer a canvas image that also includes comments // answer a canvas image meant for (semi-) transparent blocks
// note: this version is meant for (semi-) transparent blocks // that lets the background shine through
// and lets the background shine through
var scr = this.fullImage(), var scr = this.fullImage(),
solid = this.doWithAlpha(1, () => this.fullImage()), solid,
bg = newCanvas(this.fullBounds().extent()), pic,
bgCtx = bg.getContext('2d'), ctx;
fb = this.stackFullBounds(),
pic = newCanvas(fb.extent()),
ctx = pic.getContext('2d');
bgCtx.fillColor = this.parent.getRenderColor().toString(); if (this.alpha === 1) {return scr; }
bgCtx.fillRect(0, 0, bg.width, bg.height); solid = this.doWithAlpha(1, () => this.fullImage());
bgCtx.globalCompositeOperation = 'destination-in'; pic = newCanvas(this.fullBounds().extent());
bgCtx.drawImage(solid, 0, 0); ctx = pic.getContext('2d');
bgCtx.globalCompositeOperation = 'source-over'; ctx.fillStyle = this.parent.getRenderColor().toString();
bgCtx.drawImage(scr, 0, 0); ctx.fillRect(0, 0, pic.width, pic.height);
ctx.globalCompositeOperation = 'destination-in';
this.allComments().forEach(comment => ctx.drawImage(solid, 0, 0);
ctx.drawImage( ctx.globalCompositeOperation = 'source-over';
comment.fullImage(), ctx.drawImage(scr, 0, 0);
comment.fullBounds().left() - fb.left(),
comment.top() - fb.top()
)
);
ctx.drawImage(bg, 0, 0);
return pic; return pic;
}; };