Compare commits

...

16 Commits

Author SHA1 Message Date
greenkeeper[bot]
ac5146b0ba chore(package): update tap to version 14.10.2
Closes #289
2019-11-26 00:08:35 +00:00
DD Liu
58aa05c0a7 Merge pull request #480 from adroitwhiz/usenearest-fix-2
Fix useNearest() to take renderer scale into account, take two
2019-11-06 15:43:06 -05:00
DD Liu
c6b5824694 Merge pull request #514 from adroitwhiz/simplify-reskin
Remove setConvexHullDirty and setTransformDirty calls from _reskin
2019-11-06 11:36:38 -05:00
DD Liu
066b243f04 Merge pull request #521 from adroitwhiz/text-bubble-edge-fix
Call beginPath on TextBubbleSkin canvas after clearing it with clearRect
2019-11-06 11:29:58 -05:00
DD Liu
45482fecbd Merge pull request #517 from adroitwhiz/text-bubble-cleanups
Clean up TextBubbleSkin code
2019-11-06 11:22:47 -05:00
DD Liu
058fefbb12 Merge pull request #523 from LLK/greenkeeper/scratch-svg-renderer-0.2.0-prerelease.20191104164753
Update scratch-svg-renderer to the latest version 🚀
brings in https://github.com/LLK/scratch-svg-renderer/pull/99
2019-11-04 16:36:27 -05:00
greenkeeper[bot]
c7669b00cf fix(package): update scratch-svg-renderer to version 0.2.0-prerelease.20191104164753 2019-11-04 16:49:13 +00:00
DD Liu
89294a4583 Merge pull request #519 from LLK/greenkeeper/scratch-svg-renderer-0.2.0-prerelease.20191031221353
Update scratch-svg-renderer to the latest version 🚀
brings in https://github.com/LLK/scratch-svg-renderer/pull/84
2019-11-01 15:26:48 -04:00
adroitwhiz
e46c0ec3de Call beginPath after clearing text bubble canvas 2019-11-01 10:16:24 -04:00
greenkeeper[bot]
471c88b850 fix(package): update scratch-svg-renderer to version 0.2.0-prerelease.20191031221353 2019-10-31 22:15:21 +00:00
DD Liu
eccfb44a96 Merge pull request #412 from LLK/greenkeeper/scratch-vm-0.2.0-prerelease.20190213162739
Update scratch-vm to the latest version 🚀
2019-10-29 15:54:35 -04:00
adroitwhiz
861b9429c0 Clean up text bubble code 2019-10-26 10:49:07 -04:00
adroitwhiz
8dbd71470d Remove unnecessary "set dirty" calls from _reskin 2019-10-12 10:16:40 -04:00
adroitwhiz
ae23bb5e56 add jsdoc for useNearest 2019-07-11 10:23:15 -04:00
adroitwhiz
99d14f0e16 Take screen-space scale into account w/ useNearest 2019-07-11 10:07:33 -04:00
greenkeeper[bot]
13f7a1038d chore(package): update scratch-vm to version 0.2.0-prerelease.20190213162739 2019-02-13 16:42:45 +00:00
5 changed files with 22 additions and 33 deletions

View File

@@ -37,8 +37,8 @@
"gh-pages": "^1.0.0",
"jsdoc": "^3.5.5",
"json": "^9.0.4",
"scratch-vm": "0.2.0-prerelease.20190207224121",
"tap": "^11.0.0",
"scratch-vm": "0.2.0-prerelease.20190213162739",
"tap": "^14.10.2",
"travis-after-all": "^1.4.4",
"uglifyjs-webpack-plugin": "^1.2.5",
"webpack": "^4.8.0",
@@ -53,7 +53,7 @@
"minilog": "3.1.0",
"raw-loader": "^0.5.1",
"scratch-storage": "^1.0.0",
"scratch-svg-renderer": "0.2.0-prerelease.20190822202608",
"scratch-svg-renderer": "0.2.0-prerelease.20191104164753",
"twgl.js": "4.4.0"
}
}

View File

@@ -461,7 +461,9 @@ class Drawable {
const localPosition = getLocalPosition(this, vec);
if (this.useNearest) {
// We're not passing in a scale to useNearest, but that's okay because "touching" queries
// happen at the "native" size anyway.
if (this.useNearest()) {
return this.skin.isTouchingNearest(localPosition);
}
return this.skin.isTouchingLinear(localPosition);
@@ -469,8 +471,10 @@ class Drawable {
/**
* Should the drawable use NEAREST NEIGHBOR or LINEAR INTERPOLATION mode
* @param {?Array<Number>} scale Optionally, the screen-space scale of the drawable.
* @return {boolean} True if the drawable should use nearest-neighbor interpolation.
*/
get useNearest () {
useNearest (scale = this.scale) {
// Raster skins (bitmaps) should always prefer nearest neighbor
if (this.skin.isRaster) {
return true;
@@ -492,8 +496,8 @@ class Drawable {
}
// If the scale of the skin is very close to 100 (0.99999 variance is okay I guess)
if (Math.abs(this.scale[0]) > 99 && Math.abs(this.scale[0]) < 101 &&
Math.abs(this.scale[1]) > 99 && Math.abs(this.scale[1]) < 101) {
if (Math.abs(scale[0]) > 99 && Math.abs(scale[0]) < 101 &&
Math.abs(scale[1]) > 99 && Math.abs(scale[1]) < 101) {
return true;
}
return false;
@@ -685,7 +689,7 @@ class Drawable {
}
const textColor =
// commenting out to only use nearest for now
// drawable.useNearest ?
// drawable.useNearest() ?
drawable.skin._silhouette.colorAtNearest(localPosition, dst);
// : drawable.skin._silhouette.colorAtLinear(localPosition, dst);
return EffectTransform.transformColor(drawable, textColor, textColor);

View File

@@ -394,8 +394,6 @@ class RenderWebGL extends EventEmitter {
for (const drawable of this._allDrawables) {
if (drawable && drawable.skin === oldSkin) {
drawable.skin = newSkin;
drawable.setConvexHullDirty();
drawable.setTransformDirty();
}
}
oldSkin.dispose();
@@ -1735,7 +1733,7 @@ class RenderWebGL extends EventEmitter {
if (uniforms.u_skin) {
twgl.setTextureParameters(
gl, uniforms.u_skin, {minMag: drawable.useNearest ? gl.NEAREST : gl.LINEAR}
gl, uniforms.u_skin, {minMag: drawable.useNearest(drawableScale) ? gl.NEAREST : gl.LINEAR}
);
}

View File

@@ -54,7 +54,7 @@ class TextBubbleSkin extends Skin {
/** @type {Array<string>} */
this._lines = [];
this._textSize = {width: 0, height: 0};
/** @type {object} */
this._textAreaSize = {width: 0, height: 0};
/** @type {string} */
@@ -127,17 +127,14 @@ class TextBubbleSkin extends Skin {
this._lines = this.textWrapper.wrapText(BubbleStyle.MAX_LINE_WIDTH, this._text);
// Measure width of longest line to avoid extra-wide bubbles
let longestLine = 0;
let longestLineWidth = 0;
for (const line of this._lines) {
longestLine = Math.max(longestLine, this.measurementProvider.measureText(line));
longestLineWidth = Math.max(longestLineWidth, this.measurementProvider.measureText(line));
}
this._textSize.width = longestLine;
this._textSize.height = BubbleStyle.LINE_HEIGHT * this._lines.length;
// Calculate the canvas-space sizes of the padded text area and full text bubble
const paddedWidth = Math.max(this._textSize.width, BubbleStyle.MIN_WIDTH) + (BubbleStyle.PADDING * 2);
const paddedHeight = this._textSize.height + (BubbleStyle.PADDING * 2);
const paddedWidth = Math.max(longestLineWidth, BubbleStyle.MIN_WIDTH) + (BubbleStyle.PADDING * 2);
const paddedHeight = (BubbleStyle.LINE_HEIGHT * this._lines.length) + (BubbleStyle.PADDING * 2);
this._textAreaSize.width = paddedWidth;
this._textAreaSize.height = paddedHeight;
@@ -183,6 +180,7 @@ class TextBubbleSkin extends Skin {
}
// Draw the bubble's rounded borders
ctx.beginPath();
ctx.moveTo(BubbleStyle.CORNER_RADIUS, paddedHeight);
ctx.arcTo(0, paddedHeight, 0, paddedHeight - BubbleStyle.CORNER_RADIUS, BubbleStyle.CORNER_RADIUS);
ctx.arcTo(0, 0, paddedWidth, 0, BubbleStyle.CORNER_RADIUS);
@@ -267,14 +265,13 @@ class TextBubbleSkin extends Skin {
if (this._texture === null) {
const textureOptions = {
auto: true,
wrap: gl.CLAMP_TO_EDGE,
src: textureData
auto: false,
wrap: gl.CLAMP_TO_EDGE
};
this._texture = twgl.createTexture(gl, textureOptions);
}
gl.bindTexture(gl.TEXTURE_2D, this._texture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, textureData);
this._silhouette.update(textureData);

View File

@@ -1,10 +0,0 @@
/* IMPORTANT
* This snapshot file is auto-generated, but designed for humans.
* It should be checked into source control and tracked carefully.
* Re-generate by setting TAP_SNAPSHOT=1 and running tests.
* Make sure to inspect the output below. Do not ignore changes!
*/
'use strict'
exports[`test/integration/scratch-tests.js TAP bubble snapshot > bubble-text-snapshot 1`] = `
<text xmlns="http://www.w3.org/2000/svg" alignment-baseline="text-before-edge" font-size="14" fill="#575E75" font-family="Helvetica"><tspan x="0" dy="1.2em">&lt;e*&amp;%$&amp;^$&gt;&lt;/!abc'&gt;</tspan></text>
`