/* * Here, newSubView is set to false when adding sub views from the constructor (so the * view's data type is already added to ArgTypes. From outside the class the public * AddSubView defined above is called, always for new subviews */ private void AddSubView(IBlockView v, DataType argType, int i, bool newSubView) { if (!(v is LabelView || v is EditableLabelView)) { argIndexes.Add(i); trueArgs.Add(true); if (newSubView) { ArgTypes.Add(argType); } } else { trueArgs.Add(false); } if (v.Parent != null) { ((ContentView)v.Parent).Detach(v); } Attach(v); argViews.Add(v); parts.Add(v.Assemble()); Reassemble(); Changed(this); }
public void ShouldMoveBlockViewsWhenDropBlocks() { IBlockView blockViewOne = Substitute.For <IBlockView>(); IBlockView blockViewTwo = Substitute.For <IBlockView>(); IBlockView blockViewThree = Substitute.For <IBlockView>(); IBlockView blockViewFour = Substitute.For <IBlockView>(); group.Children[0].AttachView(blockViewOne); group.Children[1].AttachView(blockViewTwo); group.Children[2].AttachView(blockViewThree); group.Children[3].AttachView(blockViewFour); Assert.IsTrue(grid.AddGroup(group)); Assert.IsTrue(group.Location.Equals(setting.BlockSpawnPoint)); grid.SetState(GridStates.OnFix); grid.OnUpdate(); Assert.IsTrue(grid.CurrenteStateName == GridStates.Dropping); blockViewOne.Received().MoveTo(group.Children[0].Location.ToVector2()); blockViewTwo.Received().MoveTo(group.Children[1].Location.ToVector2()); blockViewThree.Received().MoveTo(group.Children[2].Location.ToVector2()); blockViewFour.Received().MoveTo(group.Children[3].Location.ToVector2()); grid.OnUpdate(); Assert.IsTrue(grid.CurrenteStateName == GridStates.Dropped); blockViewOne.Received().OnUpdate(); blockViewTwo.Received().OnUpdate(); blockViewThree.Received().OnUpdate(); blockViewFour.Received().OnUpdate(); }
private void BodyBlockSlotOnTryToDisconnect(BlockPlug plug) { plug.BlockViewGameObject.transform.SetParent(null); _connectedView = null; Block.Next = null; SizeChanged?.Invoke(FullSize); }
void ProcDefBlock_FormalParamChanged(object sender, int index, IProcDefBit newBit) { IBlockView v = ViewFromBlock((VarDefBlock)newBit); ProcDefView parent = (ProcDefView)ViewFromBlock((IBlock)sender); parent.SetFormalBit(index, v); }
public IBlockView ChildHasPoint(Point p, Point origin) { for (int i = 0; i < Contents.Count; ++i) { IBlockView v = Contents[i]; Point rp = new Point(0, layoutOffsets[i * 2]); // notice that contentOffsets also holds the offset if (v.HasPoint(p, origin.Offseted(rp.X, rp.Y))) // of the "side" graphics, not just the content views { IBlockView chp = v.ChildHasPoint(p, origin.Offseted(rp.X, rp.Y)); if (chp == v) { return(this); } else { return(chp); } } } for (int i = 0; i < Scripts.Count; ++i) { IBlockView v = Scripts[i]; Point rp = scriptOffsets[i]; if (v.HasPoint(p, origin.Offseted(rp.X, rp.Y))) { return(v.ChildHasPoint(p, origin.Offseted(rp.X, rp.Y))); } } return(this); }
public IBlockView ChildHasPoint(Point p, Point origin) { int y = 0; for (int i = 0; i < elements.Count; ++i) { IBlockView v = elements[i]; Point rp = new Point(0, y); if (v.HasPoint(p, origin.Offseted(rp.X, rp.Y))) { IBlockView c = v.ChildHasPoint(p, origin.Offseted(rp.X, rp.Y)); if (i == 0 && c == v) { // selecting the first block-> select whole stack // but selecting a proper child of the first block should // go normally return(this); } else { return(c); } } y += elementBitmaps[i].Height - BlockStackView.NotchHeight; } return(this); }
void Update() { if (Input.GetMouseButtonDown(0)) { var ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { currentBlockView = hit.collider.gameObject.GetComponent <IBlockView>(); } } if (Input.GetMouseButtonUp(0)) { currentBlockView?.TryToConnect(); currentBlockView = null; } if (currentBlockView != null) { var plane = new Plane(Vector3.forward, Vector3.zero); float distance; var ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (plane.Raycast(ray, out distance)) { currentBlockView.Position = ray.GetPoint(distance); } } }
private void GenerateShape(bool[,] shape, ShapeView shapeView, Color shapeColor) { var height = shape.GetLength(0); var width = shape.GetLength(1); var blockViews = new IBlockView[height, width]; shapeView.Shape = shape; for (var i = 0; i < height; i++) { for (var j = 0; j < width; j++) { if (shape[i, j]) { var blockView = BlockPool.Pop(); blockView.SetParent(shapeView.BlockContainer); blockView.SetLocalPosition(new Vector3(j - width / 2f + 0.5f, height / 2f - i - 0.5f)); blockViews[i, j] = blockView; blockView.SetColor(shapeColor); } } } shapeView.BlockViews = blockViews; shapeView.MininimazeScale(); }
void blockstack_OnInsert(object sender, int i, IBlock b) { IBlockView v = ViewFromBlock(b); BlockStackView parent = (BlockStackView)ViewFromBlock((IBlock)sender); parent.InsertView(i, v); modified(); }
void InvokationBlock_ArgChanged(object sender, int arg, IBlock _old, IBlock _new) { IBlockView v = ViewFromBlock(_new); IInvokationBlockView parent = (IInvokationBlockView)ViewFromBlock((IBlock)sender); parent.SetArgView(arg, v); modified(); }
void ProcDefBlock_FormalParamRemoved(object sender, IProcDefBit bit) { ProcDefBlock b = (ProcDefBlock)sender; ProcDefView v = (ProcDefView)ViewFromBlock(b); IBlockView bitView = ViewFromBlock((IBlock)bit); v.RemoveFormalBit(bitView); }
private Rectangle ViewBounds(IBlockView v) { if (!allViews.ContainsKey(v)) { return(Rectangle.Empty); } return(new Rectangle(allViews[v], v.Assemble().Size)); }
public void ViewReceivesDeleteWhenDeleteBlock() { IBlockView blockView = Substitute.For <IBlockView>(); block.AttachView(blockView); block.StartDeleting(); blockView.Received().Delete(); }
public static IBlockView AbsoluteAncestor(this IBlockView v) { while (v.Parent != null) { v = v.Parent; } return(v); }
private void Detach(IBlockView v) { if (!(v.Parent == this)) { throw new InvalidOperationException("How did the parent of my arg not be me??"); } v.Parent = null; v.Changed -= ArgView_Changed; }
private void BodyBlockSlotOnTryToConnect(BlockPlug plug) { plug.BlockViewGameObject.transform.SetParent(ChildSlot.transform); plug.BlockViewGameObject.transform.localPosition = Vector3.zero; _connectedView = plug.BlockView; SizeChanged?.Invoke(FullSize); plug.BlockView.SizeChanged += BlockViewOnSizeChanged; Block.Next = plug.BlockView.Block; }
private void OnBlockRemoved(IBlockModel block) { _rotationAnimator.StopAnimation(_ghostBlockView); _movementAnimator.StopAnimation(_ghostBlockView); _ghostBlockView?.Dispose(); _ghostBlockView = null; block.OnPositionChanged -= UpdateGhostPositionRotation; block.OnRotationChanged -= UpdateGhostPositionRotation; }
void blockSpace_OnTopLevelDeleted(object sender, TopLevelScript tl) { IBlockView v = blockViews[tl.Block]; Rectangle bounds = ViewBounds(v); allViews.Remove(v); Modified(this); Update(bounds); }
public void StopAnimation(IBlockView view) { for (var i = _animations.Count - 1; i >= 0; i--) { if (view == _animations[i].View) { _animations.RemoveAt(i); } } }
internal void RemoveSubView(IBlockView v) { int index = argViews.IndexOf(v); if (index == -1) { throw new ArgumentException("ContentView.RemoveSubView: view doesn't exist"); } RemoveSubView(index); }
public static Point AbsolutePos(this IBlockView v) { Point p = v.RelativePos; while (v.Parent != null) { p = p.Offseted(v.Parent.RelativePos); v = v.Parent; } return(p); }
public void ShouldReturnTrueWhenBlockViewIsOnMove() { Assert.IsFalse(block.IsOnMove); IBlockView blockView = Substitute.For <IBlockView>(); blockView.IsOnMove.Returns(true); block.AttachView(blockView); Assert.IsTrue(block.IsOnMove); }
public void RemoveSubView(int index) { IBlockView v = argViews[index]; Detach(v); argViews.RemoveAt(index); parts.RemoveAt(index); Reassemble(); Changed(this); }
void blockSpace_OnTopLevelAdded(object sender, TopLevelScript tl) { IBlockView v = viewFactory.ViewFromBlock(tl.Block); allViews[v] = tl.Location; v.RelativePos = tl.Location; v.Parent = null; Update(ViewBounds(v)); Modified(this); }
public void ViewShouldReceiveMoveTo() { IBlockView blockView = Substitute.For <IBlockView>(); block.AttachView(blockView); Coord coord = new Coord(2, 2); block.Move(coord); blockView.Received().MoveTo(Arg.Any <Vector2>()); }
private IBlockView HitTest(Point p) { IBlockView hit = null; Point location = view.RelativePos; if (view.HasPoint(p, location)) { hit = view.ChildHasPoint(p, location); } return(hit); }
void blockSpace_OnTopLevelMoved(object sender, TopLevelScript tl) { IBlockView v = blockViews[tl.Block]; Rectangle r1 = ViewBounds(v); v.RelativePos = tl.Location; allViews[v] = tl.Location; Rectangle r2 = ViewBounds(v); Modified(this); Update(Rectangle.Union(r1, r2)); }
public void ShouldReturnIsToDeleteTrueWhenViewReturnsTrue() { IBlockView blockView = Substitute.For <IBlockView>(); blockView.IsDeleting.Returns(true); block.AttachView(blockView); block.IsToDelete.Returns(true); blockView.IsToDelete.Returns(false); block.IsToDelete.Returns(false); }
public DropRegion(DropType DropType, Rectangle Rectangle, IBlockView destination, object extraInfo, DataType argType) { this.DropType = DropType; this.Rectangle = Rectangle; this.Destination = destination; this.ExtraInfo = extraInfo; this.ArgType = argType; if (argType == DataType.Invalid && DropType == DropType.AsArgument) { throw new ArgumentException("DropRegion constructor: if DropType is argument, you must supply a valid argument type", "argType"); } }
internal void InsertView(int i, IBlockView v) { if (v.Parent != null) { // We don't want to deal here with deataching v from its parent // it should be already detached throw new InvalidOperationException(); } Attach(v); elements.Insert(i, v); Reassemble(); Changed(this); }
private void Attach(IBlockView v) { v.Parent = this; v.Changed += new ViewChangedEvent(subView_Changed); }
public void AddFormalBit(IBlockView bit, DataType type) { invokationContent.AddSubView(bit, type); }
public void SetFormalBit(int index, IBlockView v) { invokationContent.SetSubView(index, v); }
public void RemoveFormalBit(IBlockView bit) { invokationContent.RemoveSubView(bit); }
private Rectangle ViewBounds(IBlockView v) { if (!allViews.ContainsKey(v)) return Rectangle.Empty; return new Rectangle(allViews[v], v.Assemble().Size); }
internal void MouseDown(Point p) { if (state == CanvasState.TextEditing) { // Since the mousedown registered, we've clicked outside the textbox ResetTextEditState(); } else if (state == CanvasState.Ready) { if (canvasView.PaletteRect.Contains(p)) { int x = canvasView.PaletteRect.Left; int y = canvasView.PaletteRect.Top; IBlock[] defaultArgs; string funcName = palette.HitTest(p.Offseted(-x, -y), out defaultArgs); if (funcName != "") { IBlock b = blockSpace.makeNewBlock(funcName,defaultArgs); TopLevelScript s = AddTopLevel(b, p.Offseted(-5, -5)); dragged = blockViews[b]; draggingOrigin = p; draggedModel = s; state = CanvasState.Dragging; PrepareDropRegions(b); Update(ViewBounds(dragged)); return; } } IBlockView hit = HitTest(p); if (hit == null) return; if (!allViews.ContainsKey(hit)) { if (hit.Model.ParentRelationship.Type == ParentRelationshipType.Stack) { int i = hit.Model.ParentRelationship.Index; Point np = hit.AbsolutePos(); Rectangle bounds = ViewBounds(hit.AbsoluteAncestor()); BlockStack parent = (BlockStack)hit.Model.ParentRelationship.Parent; TopLevelScript splitted = SplitBlockStack(parent, i, np); Update(bounds); draggedModel = splitted; hit = blockViews[splitted.Block]; } else if (hit.Model.ParentRelationship.Type == ParentRelationshipType.Arg) { if (hit is ITextualView) { // We shouldn't detach e.g a number argument from its block // but we should enable the user to edit it SetEditState((ITextualView) hit); return; } int i = hit.Model.ParentRelationship.Index; Point np = hit.AbsolutePos(); Rectangle bounds = ViewBounds(hit.AbsoluteAncestor()); InvokationBlock parent = (InvokationBlock)hit.Model.ParentRelationship.Parent; TopLevelScript splitted = TakeoutBlockArgument(parent, i, np); Update(bounds); draggedModel = splitted; hit = blockViews[splitted.Block]; } else if (hit.Model.ParentRelationship.Type == ParentRelationshipType.FormalParameter) { ProcDefBlock pd = (ProcDefBlock ) hit.Model.ParentRelationship.Parent; VarAccessBlock va = new VarAccessBlock((VarDefBlock)pd.Bits[hit.Model.ParentRelationship.Index]); TopLevelScript tls = AddTopLevel(va, p); hit = ViewFromBlock(va); draggedModel = tls; } else if (hit.Model.ParentRelationship.Type == ParentRelationshipType.None) { hit = null; draggedModel = null; } } else { draggedModel = blockSpace.FindScript(hit.Model); } if (hit != null) { dragged = hit; draggingOrigin = p; state = CanvasState.Dragging; PrepareDropRegions(hit.Model); } Update(); } }
public void Mark(IBlockView v) { canvasView.Marked = v; }
public DropRegion(DropType DropType, Rectangle Rectangle, IBlockView destination, object extraInfo) : this(DropType, Rectangle, destination, extraInfo, DataType.Invalid) { }
public Block() { _view = new NullBlockView(); }
public void AttachView(IBlockView view) { _view = view; }
public void SetArgView(int i, IBlockView v) { int iContent = 0, iScript = 0; ArgViewType resultViewType = ArgViewType.Unknown; for (int j = 0; j < ArgPartitions.Count; ++j) { ArgumentPartition p = ArgPartitions[j]; if (p.Type == ArgViewType.Content) { if (i < p.N) { resultViewType = ArgViewType.Content; break; } else { i -= p.N; iContent++; } } else if (p.Type == ArgViewType.Script) { if (i < p.N) { resultViewType = ArgViewType.Script; break; } else { i -= p.N; iScript++; } } } // Now we can use resultViewType and i to determine the arg if (resultViewType == ArgViewType.Content) { Contents[iContent].SetArgView(i, v); } else if (resultViewType == ArgViewType.Script) { SetScriptView(iScript, (IStackableBlockView) v); } else { throw new InvalidOperationException("Error in view search algorithm in CBlockView.SetArgView(...)"); } }
public void SetArgView(int i, IBlockView v) { content.SetArgView(i, v); }
internal void AddArgView(IBlockView v, DataType type) { content.AddSubView(v, type); }
private void ShowEraseButton(IBlockView hit) { eraseButton.Location = new Point(hit.AbsolutePos().X, 2); eraseButton.Show(); }
public DropRegion(DropType DropType, Rectangle Rectangle, IBlockView destination) : this(DropType, Rectangle, destination, null) { }