Merge pull request #7 from schanzer/master

Add optional color arg to empty-scene
This commit is contained in:
Jens Axel Søgaard 2015-02-02 15:09:16 +01:00
commit eb4dd0c7c1
2 changed files with 9 additions and 5 deletions

View File

@ -683,12 +683,14 @@ EXPORTS['above/align'] =
EXPORTS['empty-scene'] = EXPORTS['empty-scene'] =
makePrimitiveProcedure( makePrimitiveProcedure(
'empty-scene', 'empty-scene',
2, plt.baselib.lists.makeList(2, 3),
function(MACHINE) { function(MACHINE) {
var width = checkNonNegativeReal(MACHINE, 'empty-scene', 0); var width = checkNonNegativeReal(MACHINE, 'empty-scene', 0);
var height = checkNonNegativeReal(MACHINE, 'empty-scene', 1); var height = checkNonNegativeReal(MACHINE, 'empty-scene', 1);
return makeSceneImage(jsnums.toFixnum(width), var color = (MACHINE.a===3)? checkColor(MACHINE, 'empty-scene', 2) : null;
return makeSceneImage(jsnums.toFixnum(width),
jsnums.toFixnum(height), jsnums.toFixnum(height),
color,
[], [],
true); true);
}); });

View File

@ -288,13 +288,14 @@ var isScene = function(x) {
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// SceneImage: primitive-number primitive-number (listof image) -> Scene // SceneImage: primitive-number primitive-number color (listof image) -> Scene
var SceneImage = function(width, height, children, withBorder) { var SceneImage = function(width, height, color, children, withBorder) {
BaseImage.call(this); BaseImage.call(this);
this.width = width; this.width = width;
this.height = height; this.height = height;
this.children = children; // arrayof [image, number, number] this.children = children; // arrayof [image, number, number]
this.withBorder = withBorder; this.withBorder = withBorder;
this.color = color;
}; };
SceneImage.prototype = heir(BaseImage.prototype); SceneImage.prototype = heir(BaseImage.prototype);
@ -314,7 +315,8 @@ SceneImage.prototype.render = function(ctx, x, y) {
var childImage, childX, childY; var childImage, childX, childY;
// create a clipping region around the boundaries of the Scene // create a clipping region around the boundaries of the Scene
ctx.save(); ctx.save();
ctx.fillStyle = "rgba(0,0,0,0)"; // if no color is defined, default to transparent
ctx.fillStyle = this.color? colorString(this.color) : "rgba(0,0,0,0)";
ctx.fillRect(x, y, this.width, this.height); ctx.fillRect(x, y, this.width, this.height);
ctx.restore(); ctx.restore();
// save the context, reset the path, and clip to the path around the scene edge // save the context, reset the path, and clip to the path around the scene edge