Merge remote-tracking branch 'refs/remotes/LLK/develop' into develop

This commit is contained in:
griffpatch 2017-02-15 08:46:57 +00:00
commit be8bec23fa
7 changed files with 71 additions and 30 deletions

View File

@ -2,8 +2,7 @@
#### WebGL-based rendering engine for Scratch 3.0
[![Build Status](https://travis-ci.org/LLK/scratch-render.svg?branch=develop)](https://travis-ci.org/LLK/scratch-render)
[![Dependency Status](https://david-dm.org/LLK/scratch-render.svg)](https://david-dm.org/LLK/scratch-render)
[![devDependency Status](https://david-dm.org/LLK/scratch-render/dev-status.svg)](https://david-dm.org/LLK/scratch-render#info=devDependencies)
[![Greenkeeper badge](https://badges.greenkeeper.io/LLK/scratch-render.svg)](https://greenkeeper.io/)
## Installation
```bash

View File

@ -21,26 +21,26 @@
"watch": "./node_modules/.bin/webpack --progress --colors --watch --watch-poll"
},
"devDependencies": {
"babel-core": "6.9.1",
"babel-core": "6.22.1",
"babel-eslint": "7.1.1",
"babel-loader": "6.2.4",
"babel-polyfill": "6.9.1",
"babel-preset-es2015": "6.9.0",
"babel-loader": "6.3.0",
"babel-polyfill": "6.22.0",
"babel-preset-es2015": "6.22.0",
"base64-loader": "1.0.0",
"eslint": "3.12.0",
"eslint": "3.14.1",
"eslint-config-scratch": "3.1.0",
"gh-pages": "0.11.0",
"gh-pages": "0.12.0",
"hull.js": "0.2.10",
"json": "9.0.4",
"json-loader": "0.5.4",
"lodash.defaultsdeep": "4.6.0",
"raw-loader": "0.5.1",
"scratch-render-fonts": "git+https://github.com/LLK/scratch-render-fonts.git",
"tap": "5.7.1",
"tap": "10.1.1",
"travis-after-all": "1.4.4",
"twgl.js": "1.5.2",
"webpack": "1.13.0",
"webpack-dev-server": "1.14.1",
"xhr": "2.2.0"
"twgl.js": "2.8.2",
"webpack": "2.2.1",
"webpack-dev-server": "1.16.3",
"xhr": "2.3.3"
}
}

View File

@ -181,7 +181,7 @@ class PenSkin extends Skin {
const r = Math.round(color4f[0] * 255);
const g = Math.round(color4f[1] * 255);
const b = Math.round(color4f[2] * 255);
const a = Math.round(color4f[3]); // Alpha is 0 to 1 (not 0 to 255 like r,g,b)
const a = color4f[3]; // Alpha is 0 to 1 (not 0 to 255 like r,g,b)
context.strokeStyle = `rgba(${r},${g},${b},${a})`;
context.lineCap = 'round';

View File

@ -736,6 +736,46 @@ class RenderWebGL extends EventEmitter {
drawable.updateProperties(properties);
}
/**
* Update the position object's x & y members to keep the drawable fenced in view.
* @param {int} drawableID - The ID of the Drawable to update.
* @param {Array.<number, number>} position to be fenced - An array of type [x, y]
* @return {Array.<number, number>} The fenced position as an array [x, y]
*/
getFencedPositionOfDrawable (drawableID, position) {
let x = position[0];
let y = position[1];
const drawable = this._allDrawables[drawableID];
if (!drawable) {
// TODO: fix whatever's wrong in the VM which causes this, then add a warning or throw here.
// Right now this happens so much on some projects that a warning or exception here can hang the browser.
return [x, y];
}
const dx = x - drawable._position[0];
const dy = y - drawable._position[1];
const aabb = drawable.getFastBounds();
// This is my best guess at the fencing in Scratch 2,
// but I suspect it may need further work to be precisely the same?
const sx = this._xRight - Math.min(15, Math.floor((aabb.right - aabb.left) / 2));
if (aabb.right + dx < -sx) {
x = drawable._position[0] - (sx + aabb.right);
} else if (aabb.left + dx > sx) {
x = drawable._position[0] + (sx - aabb.left);
}
const sy = this._yTop - Math.min(15, Math.floor((aabb.top - aabb.bottom) / 2));
if (aabb.top + dy < -sy) {
y = drawable._position[1] - (sy + aabb.top);
} else if (aabb.bottom + dy > sy) {
y = drawable._position[1] + (sy - aabb.bottom);
}
return [x, y];
}
/**
* Clear a pen layer.
* @param {int} penSkinID - the unique ID of a Pen Skin.

View File

@ -34,10 +34,10 @@ class SVGSkin extends Skin {
}
/**
* @return {[number,number]} the "native" size, in texels, of this skin.
* @return {[number,number]} the natural size, in Scratch units, of this skin.
*/
get size () {
return [this._svgRenderer.canvas.width, this._svgRenderer.canvas.height];
return this._svgRenderer.size;
}
/**

View File

@ -2,11 +2,11 @@
// First, have Webpack load their data as Base 64 strings.
/* eslint-disable global-require */
const FONTS = {
Donegal: require('base64!scratch-render-fonts/DonegalOne-Regular.ttf'),
Gloria: require('base64!scratch-render-fonts/GloriaHallelujah.ttf'),
Mystery: require('base64!scratch-render-fonts/MysteryQuest-Regular.ttf'),
Marker: require('base64!scratch-render-fonts/PermanentMarker.ttf'),
Scratch: require('base64!scratch-render-fonts/Scratch.ttf')
Donegal: require('base64-loader!scratch-render-fonts/DonegalOne-Regular.ttf'),
Gloria: require('base64-loader!scratch-render-fonts/GloriaHallelujah.ttf'),
Mystery: require('base64-loader!scratch-render-fonts/MysteryQuest-Regular.ttf'),
Marker: require('base64-loader!scratch-render-fonts/PermanentMarker.ttf'),
Scratch: require('base64-loader!scratch-render-fonts/Scratch.ttf')
};
/* eslint-enable global-require */
@ -37,6 +37,7 @@ class SvgRenderer {
constructor (canvas) {
this._canvas = canvas || document.createElement('canvas');
this._context = this._canvas.getContext('2d');
this._measurements = {x: 0, y: 0, width: 0, height: 0};
}
/**
@ -72,6 +73,13 @@ class SvgRenderer {
this._draw();
}
/**
* @return {[number,number]} the natural size, in Scratch units, of this SVG.
*/
get size () {
return [this._measurements.width, this._measurements.height];
}
/**
* Transforms an SVG's text elements for Scratch 2.0 quirks.
* These quirks include:

View File

@ -15,21 +15,17 @@ const base = {
},
devtool: 'source-map',
module: {
loaders: [
rules: [
{
include: [
path.resolve(__dirname, 'src')
],
test: /\.js$/,
loader: 'babel-loader',
query: {
options: {
presets: ['es2015']
}
},
{
test: /\.json$/,
loader: 'json-loader'
},
{
test: /\.(glsl|vs|fs|frag|vert)$/,
loader: 'raw-loader'
@ -40,9 +36,7 @@ const base = {
new webpack.optimize.UglifyJsPlugin({
include: /\.min\.js$/,
minimize: true,
compress: {
warnings: false
}
sourceMap: true
})
]
};