This repository has been archived on 2025-05-04. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
scratch-html5/js/Stage.js
Chad Walker 41b68edd90 Add procedure support
- when a call block is executed, the block is copied, any parameters are
   evaluated and stored on the copy, then the copy is pushed on the stack
- when a getParam block is executed it finds the last call block on the
  stack, and then gets the already evaluated parameters from there.
- based on PR #21 by @bobbybee, passes all of @nathan's tests there
2014-09-13 11:07:11 -05:00

71 lines
2.5 KiB
JavaScript

// Copyright (C) 2013 Massachusetts Institute of Technology
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License version 2,
// as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// Scratch HTML5 Player
// Stage.js
// Tim Mickel, July 2011 - March 2012
// Provides the basic logic for the Stage, a special kind of Sprite.
'use strict';
var Stage = function(data) {
// Place the background layer in the very back.
// The pen layer is right above the stage background,
// and all sprites are above that.
this.z = -2;
// Pen layer and canvas cache.
this.penLayerLoaded = false;
this.lineCanvas = document.createElement('canvas');
this.lineCanvas.width = 480;
this.lineCanvas.height = 360;
this.lineCache = this.lineCanvas.getContext('2d');
this.isStage = true;
this.askAnswer = ""; //this is a private variable and should be blank
Sprite.call(this, data);
};
Stage.prototype = Object.create(Sprite.prototype);
Stage.prototype.constructor = Stage;
Stage.prototype.attachPenLayer = function(scene) {
if (this.penLayerLoaded) return;
this.penLayerLoaded = true;
$(this.lineCanvas).css('position', 'absolute');
$(this.lineCanvas).css('z-index', '-1');
scene.append(this.lineCanvas);
};
Stage.prototype.isLoaded = function() {
return this.penLayerLoaded && Sprite.prototype.isLoaded.call(this);
};
// Pen functions
Stage.prototype.clearPenStrokes = function() {
this.lineCache.clearRect(0, 0, 480, 360);
};
Stage.prototype.stroke = function(from, to, width, color) {
this.lineCache.lineWidth = width;
this.lineCache.lineCap = 'round';
this.lineCache.beginPath();
// Use .5 offsets for canvas rigid pixel drawing
this.lineCache.moveTo(from[0] + 240.5, 180.5 - from[1]);
this.lineCache.lineTo(to[0] + 240.5, 180.5 - to[1]);
this.lineCache.strokeStyle = 'rgb(' + (color >> 16) + ',' + (color >> 8 & 255) + ',' + (color & 255) + ')';
this.lineCache.stroke();
};