Merge pull request #243 from nathan/wrap-c-in-stack

Allow wrapping C blocks in the middle of a stack
This commit is contained in:
Shane M. Clements 2014-06-12 16:04:26 -06:00
commit 5132c96eb2
2 changed files with 41 additions and 4 deletions

View file

@ -454,6 +454,13 @@ public class Block extends Sprite {
}
}
public function previewSubstack1Height(h:int):void {
base.setSubstack1Height(h);
base.redraw();
fixElseLabel();
if (nextBlock) nextBlock.y = base.nextBlockY();
}
public function duplicate(forClone:Boolean, forStage:Boolean = false):Block {
var newSpec:String = spec;
if (forStage && op == 'whenClicked') newSpec = 'when Stage clicked';
@ -627,9 +634,13 @@ public class Block extends Sprite {
}
private function appendBlock(b:Block):void {
var bottom:Block = bottomBlock();
bottom.addChild(b);
bottom.nextBlock = b;
if (base.canHaveSubstack1() && !subStack1) {
insertBlockSub1(b);
} else {
var bottom:Block = bottomBlock();
bottom.addChild(b);
bottom.nextBlock = b;
}
}
private function owningBlock():Block {

View file

@ -135,6 +135,32 @@ public class ScriptsPane extends ScrollFrameContents {
public function updateFeedbackFor(b:Block):void {
nearestTarget = nearestTargetForBlockIn(b, possibleTargets);
if (b.base.canHaveSubstack1() && !b.subStack1) {
var o:Block = null;
if (nearestTarget) {
t = nearestTarget[1];
switch (nearestTarget[2]) {
case INSERT_NORMAL:
o = t.nextBlock;
break;
case INSERT_WRAP:
o = t;
break;
case INSERT_SUB1:
o = t.subStack1;
break;
case INSERT_SUB2:
o = t.subStack2;
break;
}
}
var h:int = BlockShape.EmptySubstackH;
if (o) {
h = o.height;
if (!o.bottomBlock().isTerminal) h -= BlockShape.NotchDepth;
}
b.previewSubstack1Height(h);
}
if (nearestTarget != null) {
var localP:Point = globalToLocal(nearestTarget[0]);
var t:* = nearestTarget[1];
@ -221,7 +247,7 @@ public class ScriptsPane extends ScrollFrameContents {
p = target.localToGlobal(new Point(-BlockShape.SubstackInset, -(b.base.substack1y() - BlockShape.NotchDepth)));
possibleTargets.push([p, target, INSERT_WRAP]);
}
if (!b.isHat) findCommandTargetsIn(target, bEndWithTerminal);
if (!b.isHat) findCommandTargetsIn(target, bEndWithTerminal && !bCanWrap);
}
}
}