summaryrefslogtreecommitdiff
path: root/objects.js
diff options
context:
space:
mode:
authorCode WvS <code-wvs@quantentunnel.de>2015-03-01 17:48:36 +0100
committerCode WvS <code-wvs@quantentunnel.de>2015-03-01 17:48:36 +0100
commit2a6993efae6e961660ecd2aa1f999f10aadf94f4 (patch)
tree0e17ff542086f2d83c00a1bb63bdb577ece4bd97 /objects.js
parent5b615ebf5cfc4f6aa6c5930dcc7ec7e211e883df (diff)
downloadsnap-yow-2a6993efae6e961660ecd2aa1f999f10aadf94f4.tar.gz
snap-yow-2a6993efae6e961660ecd2aa1f999f10aadf94f4.zip
draw pen trails; expand to polygons automatically
Diffstat (limited to 'objects.js')
-rw-r--r--objects.js35
1 files changed, 34 insertions, 1 deletions
diff --git a/objects.js b/objects.js
index 209a45f..b8b0ccd 100644
--- a/objects.js
+++ b/objects.js
@@ -1393,6 +1393,8 @@ SpriteMorph.prototype.init = function (globals) {
this.isDraggable = true;
this.isDown = false;
+ this.myPolylineIndex = window.polylineIndex++;
+
this.heading = 90;
this.changed();
this.drawNew();
@@ -3308,6 +3310,33 @@ SpriteMorph.prototype.drawLine = function (start, dest) {
).intersect(this.parent.visibleBounds()).spread();
if (this.isDown) {
+ var stage = this.parent;
+ var destLatLng =
+ [stage.dimensions.y / 2 - to.y, to.x - stage.dimensions.x / 2];
+
+ 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.penTrails);
+ } else {
+ var latlngs = window.polylines[this.myPolylineIndex].getLatLngs();
+ for (var j = 0; j < latlngs.length; j++) {
+ if (latlngs[j].distanceTo(destLatLng) < 0.1) {
+ var polyLL = window.polylines[this.myPolylineIndex].spliceLatLngs(j, latlngs.length)
+ .concat([destLatLng]);
+ L.polygon(polyLL, {color: this.color.toString(), weight: this.size})
+ .addTo(window.penTrails);
+ break;
+ }
+ }
+
+ window.polylines[this.myPolylineIndex].addLatLng(destLatLng);
+ }
+
context.lineWidth = this.size;
context.strokeStyle = this.color.toString();
if (this.useFlatLineEnds) {
@@ -3343,6 +3372,9 @@ SpriteMorph.prototype.moveBy = function (delta, justMe) {
part.moveBy(delta);
});
}
+ if (!this.isDown) {
+ this.myPolylineIndex = window.polylineIndex++;
+ }
};
SpriteMorph.prototype.slideBackTo = function (situation, inSteps) {
@@ -3403,7 +3435,6 @@ SpriteMorph.prototype.forward = function (meters) {
diffLon = Math.sin(radians(this.heading))
* (1 / (111.32 * Math.cos(radians(this.yPosition()))) * kilometers);
- // TODO: "0 - ..." – why does this work? The formula above looks wrong ;-)
var diffPoint = new Point(diffLon, 0 - diffLat);
this.setPosition(this.position().add(diffPoint));
this.updateMarker();
@@ -4563,6 +4594,8 @@ StageMorph.prototype.drawOn = function (aCanvas, aRect) {
};
StageMorph.prototype.clearPenTrails = function () {
+ window.map.removeLayer(window.penTrails);
+ window.penTrails = L.layerGroup().addTo(window.map);
this.trailsCanvas = newCanvas(this.dimensions);
this.changed();
};