private bool FindActiveDropRegion(Rectangle rect, out DropRegion ret) { foreach (DropRegion dr in DropRegions) { if (EffectiveDropRegion(rect, dr)) { canvasView.SetDropRegion(dr); ret = dr; return(true); } } canvasView.ResetDropRegion(); ret = new DropRegion(); return(false); }
private void ConnectBlocks(DropRegion dr, TopLevelScript block) { Point destinationLoc = new Point(); if (allViews.ContainsKey(dr.Destination)) { destinationLoc = allViews[dr.Destination]; } int sourceHeight = blockViews[block.Block].Assemble().Height; switch (dr.DropType) { case DropType.Above: IBlock finalStack = blockSpace.StackAbove(block, dr.Destination.Model); if (finalStack.ParentRelationship.Type == ParentRelationshipType.None) { // We've stacked A above B, we need to reposition the result so that // B's old location stays the same TopLevelScript ts = blockSpace.FindScript(finalStack); ts.Location = new Point(destinationLoc.X, destinationLoc.Y - sourceHeight + BlockStackView.NotchHeight); } break; case DropType.Below: blockSpace.StackBelow(block, dr.Destination.Model); break; case DropType.Between: blockSpace.RemoveScript(draggedModel); (dr.Destination.Model as BlockStack).Insert((int)dr.ExtraInfo, block.Block); break; case DropType.AsArgument: blockSpace.RemoveScript(draggedModel); (dr.Destination.Model as InvokationBlock).SetArg((int)dr.ExtraInfo, block.Block); break; } }
public void SetDropRegion(DropRegion dr) { CurrentDropRegion = dr; activeDropRegion = true; }
private bool FindActiveDropRegion(Rectangle rect, out DropRegion ret) { foreach (DropRegion dr in DropRegions) { if (EffectiveDropRegion(rect, dr)) { canvasView.SetDropRegion(dr); ret = dr; return true; } } canvasView.ResetDropRegion(); ret = new DropRegion(); return false; }
private void ConnectBlocks(DropRegion dr, TopLevelScript block) { Point destinationLoc = new Point(); if(allViews.ContainsKey(dr.Destination)) destinationLoc = allViews[dr.Destination]; int sourceHeight = blockViews[block.Block].Assemble().Height; switch (dr.DropType) { case DropType.Above: IBlock finalStack = blockSpace.StackAbove(block, dr.Destination.Model); if (finalStack.ParentRelationship.Type == ParentRelationshipType.None) { // We've stacked A above B, we need to reposition the result so that // B's old location stays the same TopLevelScript ts = blockSpace.FindScript(finalStack); ts.Location = new Point(destinationLoc.X, destinationLoc.Y - sourceHeight + BlockStackView.NotchHeight); } break; case DropType.Below: blockSpace.StackBelow(block, dr.Destination.Model); break; case DropType.Between: blockSpace.RemoveScript(draggedModel); (dr.Destination.Model as BlockStack).Insert((int)dr.ExtraInfo, block.Block); break; case DropType.AsArgument: blockSpace.RemoveScript(draggedModel); (dr.Destination.Model as InvokationBlock).SetArg((int)dr.ExtraInfo, block.Block); break; } }
private static bool EffectiveDropRegion(Rectangle rect, DropRegion dr) { switch (dr.DropType) { case DropType.Above: if (rect.BottomSlice(5).IntersectsWith(dr.Rectangle)) { return true; } break; case DropType.Below: case DropType.Between: if (rect.TopSlice(5).IntersectsWith(dr.Rectangle)) { return true; ; } break; case DropType.AsArgument: if (rect.IntersectsWith(dr.Rectangle)) { return true; ; } break; } return false; }