diff options
| author | jmoenig <jens@moenig.org> | 2015-01-21 10:23:02 +0100 |
|---|---|---|
| committer | jmoenig <jens@moenig.org> | 2015-01-21 10:23:02 +0100 |
| commit | f1fbb38b8715639e6025c130de70ef269cb0c0cd (patch) | |
| tree | e24c4b76c851bb4e1e87f20b967c1c298c30f127 | |
| parent | 4a3cf0aa3bc4778821801ec325fb2fd9dbbd038b (diff) | |
| download | snap-byow-f1fbb38b8715639e6025c130de70ef269cb0c0cd.tar.gz snap-byow-f1fbb38b8715639e6025c130de70ef269cb0c0cd.zip | |
Keep layering of nested sprites thru drag & drop
it used to be that dragging an anchor always brought it to the front,
altering the nested sprite’s internal layering order
| -rwxr-xr-x | history.txt | 4 | ||||
| -rw-r--r-- | objects.js | 27 |
2 files changed, 30 insertions, 1 deletions
diff --git a/history.txt b/history.txt index b621772..1880e45 100755 --- a/history.txt +++ b/history.txt @@ -2418,3 +2418,7 @@ ______ ------ * BYOB: fixed #702 * GUI: fixed #680 + +150121 +------ +* Objects: Keep layering of nested sprites thru drag & drop @@ -125,7 +125,7 @@ PrototypeHatBlockMorph*/ // Global stuff //////////////////////////////////////////////////////// -modules.objects = '2015-January-12'; +modules.objects = '2015-January-21'; var SpriteMorph; var StageMorph; @@ -1315,6 +1315,7 @@ SpriteMorph.prototype.init = function (globals) { this.anchor = null; this.nestingScale = 1; this.rotatesWithAnchor = true; + this.layers = null; // cache for dragging nested sprites, don't serialize this.blocksCache = {}; // not to be serialized (!) this.paletteCache = {}; // not to be serialized (!) @@ -3158,6 +3159,7 @@ SpriteMorph.prototype.positionTalkBubble = function () { SpriteMorph.prototype.prepareToBeGrabbed = function (hand) { var bubble = this.talkBubble(); + this.recordLayers(); if (!bubble) {return null; } this.removeShadow(); bubble.hide(); @@ -3168,6 +3170,7 @@ SpriteMorph.prototype.prepareToBeGrabbed = function (hand) { }; SpriteMorph.prototype.justDropped = function () { + this.restoreLayers(); this.positionTalkBubble(); }; @@ -4045,6 +4048,28 @@ SpriteMorph.prototype.allAnchors = function () { return result; }; +SpriteMorph.prototype.recordLayers = function () { + var stage = this.parentThatIsA(StageMorph); + if (!stage) { + this.layerCache = null; + return; + } + this.layers = this.allParts(); + this.layers.sort(function (x, y) { + return stage.children.indexOf(x) < stage.children.indexOf(y) ? + -1 : 1; + }); +}; + +SpriteMorph.prototype.restoreLayers = function () { + if (this.layers && this.layers.length > 1) { + this.layers.forEach(function (sprite) { + sprite.comeToFront(); + }); + } + this.layers = null; +}; + // SpriteMorph highlighting SpriteMorph.prototype.addHighlight = function (oldHighlight) { |
