summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCode WvS <code-wvs@quantentunnel.de>2015-03-22 11:34:27 +0100
committerCode WvS <code-wvs@quantentunnel.de>2015-03-22 11:34:27 +0100
commit2443eb0143310599669d3de61e9826e819137fb1 (patch)
tree2b0b54cf4a101466b4205f49a28a15b75fd6a5c9
parente5fba1af530c86c0be3ffe265b35e6a60251b10f (diff)
downloadsnap-yow-2443eb0143310599669d3de61e9826e819137fb1.tar.gz
snap-yow-2443eb0143310599669d3de61e9826e819137fb1.zip
move the decision whether to draw a line or a shape to pen up
-rw-r--r--blocks.js6
-rw-r--r--lang-de.js8
-rw-r--r--objects.js68
3 files changed, 41 insertions, 41 deletions
diff --git a/blocks.js b/blocks.js
index dd67695..0437ff2 100644
--- a/blocks.js
+++ b/blocks.js
@@ -1270,12 +1270,12 @@ SyntaxElementMorph.prototype.labelPart = function (spec) {
null, // text
false, // numeric?
{
- 'line' : ['line'],
- 'shape': ['shape']
+ 'a line' : ['a line'],
+ 'a shape': ['a shape']
},
true // read-only
);
- part.setContents(['line']);
+ part.setContents(['a line']);
break;
// symbols:
diff --git a/lang-de.js b/lang-de.js
index d07021b..8e24beb 100644
--- a/lang-de.js
+++ b/lang-de.js
@@ -405,8 +405,12 @@ SnapTranslator.dict.de = {
'wische',
'pen down':
'Stift runter',
- 'pen up':
- 'Stift hoch',
+ 'pen up and finish as %drawmode':
+ 'Stift hoch und beende als %drawmode',
+ 'a line': // workaround: line is already translated in whitespace
+ 'Linie',
+ 'a shape':
+ 'Fl\u00e4che',
'set pen color to %clr':
'setze Stiftfarbe auf %clr',
'change pen color by %n':
diff --git a/objects.js b/objects.js
index 227c105..2ed36e1 100644
--- a/objects.js
+++ b/objects.js
@@ -541,14 +541,14 @@ SpriteMorph.prototype.initBlocks = function () {
only: SpriteMorph,
type: 'command',
category: 'pen',
- spec: 'pen down and draw a %drawmode',
- defalts: ['line']
+ spec: 'pen down'
},
up: {
only: SpriteMorph,
type: 'command',
category: 'pen',
- spec: 'pen up'
+ spec: 'pen up and finish as %drawmode',
+ defaults: ['a line']
},
setColor: {
only: SpriteMorph,
@@ -2921,14 +2921,25 @@ SpriteMorph.prototype.show = function () {
// SpriteMorph pen color
-SpriteMorph.prototype.down = function (mode) {
+SpriteMorph.prototype.down = function () {
// overrides PenMorph.down
- this.isDown = true;
- this.penMode = mode[0] || 'line'; // default to line
- if (this.penMode == 'shape') {
- this.myPolygonIndex = window.polygonIndex++;
- } else { // 'line'
- this.myPolylineIndex = window.polylineIndex++;
+ this.isDown = true;
+ this.myPolylineIndex = window.polylineIndex++;
+};
+
+SpriteMorph.prototype.up = function (mode) {
+ // overrides PenMorph.up
+ this.isDown = false;
+ this.penMode = mode[0]; // default to line
+ if (this.penMode == 'a shape') {
+ // transform the line that has just been finished into a polygon
+ window.polygons[window.polygonIndex++] = L.polygon(
+ window.polylines[this.myPolylineIndex].getLatLngs(),
+ {color: this.color.toString(), weight: this.size})
+ .addTo(window.penShapes);
+ // remove the line that is now a filled shape
+ window.penLines.removeLayer(window.polylines[this.myPolylineIndex]);
+ delete window.polylines[this.myPolyIndex];
}
};
@@ -3381,32 +3392,17 @@ SpriteMorph.prototype.drawLine = function (start, dest) {
var destLatLng =
[stage.dimensions.y / 2 - to.y, to.x - stage.dimensions.x / 2];
- if (this.penMode == 'shape') {
- if (!window.polygons[this.myPolygonIndex]) {
- // add a new polygon with start and end points
- window.polygons[this.myPolygonIndex] = L.polygon([
- [stage.dimensions.y / 2 - from.y,
- from.x - stage.dimensions.x / 2],
- destLatLng,
- ],
- {color: this.color.toString(), weight: this.size})
- .addTo(window.penShapes);
- } else {
- window.polygons[this.myPolygonIndex].addLatLng(destLatLng);
- }
- } else { // 'line'
- if (!window.polylines[this.myPolylineIndex]) {
- // add a new line with start and end points
- window.polylines[this.myPolylineIndex] = L.polyline([
- [stage.dimensions.y / 2 - from.y,
- from.x - stage.dimensions.x / 2],
- destLatLng,
- ],
- {color: this.color.toString(), weight: this.size})
- .addTo(window.penLines);
- } else {
- window.polylines[this.myPolylineIndex].addLatLng(destLatLng);
- }
+ if (!window.polylines[this.myPolylineIndex]) {
+ // add a new line with start and end points
+ window.polylines[this.myPolylineIndex] = L.polyline([
+ [stage.dimensions.y / 2 - from.y,
+ from.x - stage.dimensions.x / 2],
+ destLatLng,
+ ],
+ {color: this.color.toString(), weight: this.size})
+ .addTo(window.penLines);
+ } else {
+ window.polylines[this.myPolylineIndex].addLatLng(destLatLng);
}
context.lineWidth = this.size;