From 2e32c1c93bbe40a2ddd57099a9f914418f96f926 Mon Sep 17 00:00:00 2001 From: Code WvS Date: Wed, 25 Mar 2015 10:36:30 +0100 Subject: move shape size calculation to core --- blocks.js | 1 + objects.js | 16 ++++++++++++++++ overpass.xml | 2 +- threads.js | 2 ++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/blocks.js b/blocks.js index 0437ff2..6f3ed28 100644 --- a/blocks.js +++ b/blocks.js @@ -6769,6 +6769,7 @@ InputSlotMorph.prototype.attributesMenu = function () { } if (obj instanceof SpriteMorph) { dict = { + 'shape size' : ['shape size'], 'longitude' : ['x position'], 'latitude' : ['y position'], 'direction' : ['direction'], diff --git a/objects.js b/objects.js index 771318e..d4f5cb0 100644 --- a/objects.js +++ b/objects.js @@ -598,6 +598,12 @@ SpriteMorph.prototype.initBlocks = function () { spec: 'set pen size to %n', defaults: [1] }, + shapeSize: { + only: SpriteMorph, + type: 'reporter', + category: 'pen', + spec: 'size of drawn shapes in m²' + }, doStamp: { only: SpriteMorph, type: 'command', @@ -1970,6 +1976,8 @@ SpriteMorph.prototype.blockTemplates = function (category) { blocks.push('-'); blocks.push(block('changeSize')); blocks.push(block('setSize')); + blocks.push('-'); + blocks.push(block('shapeSize')); //blocks.push('-'); //blocks.push(block('doStamp')); @@ -3111,6 +3119,14 @@ SpriteMorph.prototype.changeSize = function (delta) { this.setSize(this.size + (+delta || 0)); }; +SpriteMorph.prototype.shapeSize = function () { + var size = 0; + this.penShapes.eachLayer(function (layer) { + size += LGeo.area(layer); + }); + return size; +}; + // SpriteMorph scale SpriteMorph.prototype.getScale = function () { diff --git a/overpass.xml b/overpass.xml index ed3b2a8..f1c6485 100644 --- a/overpass.xml +++ b/overpass.xml @@ -1 +1 @@ -
Sprite
\ No newline at end of file +
\ No newline at end of file diff --git a/threads.js b/threads.js index 2817144..4aaf7b5 100644 --- a/threads.js +++ b/threads.js @@ -2535,6 +2535,8 @@ Process.prototype.reportAttributeOf = function (attribute, name) { return thatObj.variables.getVar(attribute); } switch (this.inputOption(attribute)) { + case 'shape size': + return thatObj.shapeSize(); case 'x position': return thatObj.xPosition ? thatObj.xPosition() : ''; case 'y position': -- cgit v1.3.1