public override Moveable DeepCopy() { Statement copy = new Statement(behaviour.DeepCopy()); List <BlockSlot> slots = GetSlots(); List <BlockSlot> copySlots = copy.GetSlots(); if (slots.Count != copySlots.Count) { throw new ApplicationException(String.Format("Statement.DeepCopy() returned a copy with the wrong number of slots (expected {0} but found {1}.", slots.Count, copySlots.Count)); } for (int i = 0; i < slots.Count; i++) { Moveable contents = slots[i].Contents; if (contents != null) { copySlots[i].Contents = contents.DeepCopy(); } else { copySlots[i].Contents = null; } } return(copy); }
/// <summary> /// Accepts dropped Moveable objects, if they fit this slot. /// </summary> protected virtual void AcceptDrop(object sender, DragEventArgs e) { if (!e.Handled) { if (e.Data.GetDataPresent(typeof(Moveable))) { Moveable moveable = e.Data.GetData(typeof(Moveable)) as Moveable; if (moveable != null && moveable != Contents && Fits(moveable)) { if (e.AllowedEffects == DragDropEffects.Copy) { Contents = moveable.DeepCopy(); } else if (e.AllowedEffects == DragDropEffects.Move) { moveable.Remove(); Contents = moveable; } //ActivityLog.Write(new Activity("PlacedBlock","Block",Contents.GetLogText(),"PlacedOn",this.GetLogText())); Log.WriteAction(LogAction.placed, "block", Contents.GetLogText() + " on " + this.GetLogText()); } e.Handled = true; } } SetDefaultAppearance(); }
public Spine DeepCopy() { Spine copy = new Spine(fitter, (uint)Pegs.Count, Extends); copy.Margin = Margin; for (int i = 0; i < Pegs.Count; i++) { Peg origPeg = (Peg)Pegs[i]; Peg copyPeg = (Peg)copy.Pegs[i]; Moveable moveable = origPeg.Slot.Contents; if (moveable != null) { copyPeg.Slot.Contents = moveable.DeepCopy(); } } return(copy); }
public MoveableAdorner(Moveable moveable, AdornerLayer layer, Point position) : base(moveable) { this.layer = layer; this.position = position; visuals = new VisualCollection(this); contentPresenter = new ContentPresenter(); visuals.Add(contentPresenter); Moveable clone = moveable.DeepCopy(); clone.Opacity = 0.7; Content = clone; layer.Add(this); IsHitTestVisible = false; AllowDrop = true; AdornedElement.IsHitTestVisible = false; }
private void DroppedOnSlotPanel(object sender, DragEventArgs e) { if (!e.Handled) { if (e.Data.GetDataPresent(typeof(Moveable))) { Moveable moveable = e.Data.GetData(typeof(Moveable)) as Moveable; if (moveable != null && Fits(moveable)) { if (e.AllowedEffects == DragDropEffects.Copy) { Attached = (Moveable)moveable.DeepCopy(); } else if (e.AllowedEffects == DragDropEffects.Move) { Attached = moveable; } } e.Handled = true; } } SetToStandardAppearance(); }
/// <summary> /// Attach a Moveable to the spine, either onto a free adjacent peg, /// or onto a newly-created peg. /// </summary> protected void AttachToSpine(object sender, DragEventArgs e) { if (e.Handled) { return; } if (!e.Data.GetDataPresent(typeof(Moveable))) { return; } if (!(e.AllowedEffects == DragDropEffects.Copy || e.AllowedEffects == DragDropEffects.Move)) { return; } Moveable moveable = e.Data.GetData(typeof(Moveable)) as Moveable; if (fitter.Fits(moveable)) { DropZone dropZone = sender as DropZone; if (dropZone == null) { return; } Peg above = UIHelper.TryFindParent <Peg>(dropZone); if (above == null) { return; } int index = Pegs.IndexOf(above); if (index == -1) { throw new InvalidOperationException("Peg not found on spine."); } index++; Peg below; if (index < Pegs.Count) { below = (Peg)Pegs[index]; } else { below = null; } Peg target = null; // If a moveable has been dropped just above or below // itself, do nothing. Otherwise, try to use an empty // peg, or create a new peg if there isn't one: bool pointlessMove = e.AllowedEffects == DragDropEffects.Move && ((above != null && above.Slot.Contents == moveable) || (below != null && below.Slot.Contents == moveable)); if (pointlessMove) { e.Handled = true; return; } else if (below != null && below.Slot.Contents == null) { target = below; } else if (above != null && above.Slot.Contents == null) { target = above; } else { target = AddPeg(false, index); } if (e.AllowedEffects == DragDropEffects.Copy) { target.Slot.Contents = moveable.DeepCopy(); } else if (e.AllowedEffects == DragDropEffects.Move) { moveable.Remove(); target.Slot.Contents = moveable; } try { Log.WriteAction(LogAction.placed, "block", target.Slot.Contents.GetLogText() + " on " + target.Slot.GetLogText()); //ActivityLog.Write(new Activity("PlacedBlock","Block",target.Slot.Contents.GetLogText(),"PlacedOn",target.Slot.GetLogText())); } catch (Exception) {} OnChanged(new EventArgs()); } e.Handled = true; }
protected void DroppedOnCanvas(object sender, DragEventArgs e) { try { if (!e.Handled) { Moveable moveable = null; Size size = new Size(); if (e.Data.GetDataPresent(typeof(Moveable))) { moveable = (Moveable)e.Data.GetData(typeof(Moveable)); size = moveable.RenderSize; // use the original's size as the clone has not been drawn yet if (e.AllowedEffects == DragDropEffects.Copy) { moveable = moveable.DeepCopy(); } } // // HACK: // else if (e.Data.GetDataPresent(typeof(NWN2InstanceCollection))) { // NWN2InstanceCollection instances = (NWN2InstanceCollection)e.Data.GetData(typeof(NWN2InstanceCollection)); // if (instances.Count > 0) { // moveable = factory.CreateInstanceBlock(instances[0]); // size = ObjectBlock.DefaultSize; // } // } // else if (e.Data.GetDataPresent(typeof(NWN2BlueprintCollection))) { // try { // NWN2BlueprintCollection blueprints = (NWN2BlueprintCollection)e.Data.GetData(typeof(NWN2BlueprintCollection)); // if (blueprints.Count > 0) { // moveable = factory.CreateBlueprintBlock(blueprints[0]); // size = ObjectBlock.DefaultSize; // } // } // catch (System.Runtime.InteropServices.COMException x) { // // MessageBox.Show(x.ToString()); // /* // * Weird error occurs here - even though GetDataPresent() returns true, // * actually trying to retrieve the data raises this nasty exception. // * TODO: // * Look for the blueprints directly in the toolset instead. // */ // } // } if (moveable != null) { bool movingWithinCanvas = moveable.Parent == mainCanvas; PlaceInWorkspace(moveable); Point position = e.GetPosition(mainCanvas); position.X -= (size.Width / 2); position.Y -= (size.Height / 2); moveable.MoveTo(position); if (movingWithinCanvas) { //ActivityLog.Write(new Activity("MovedWithinCanvas","Block",moveable.GetLogText())); Log.WriteAction(LogAction.moved, "block", moveable.GetLogText() + " to different spot on canvas"); } else { //ActivityLog.Write(new Activity("PlacedBlock","Block",moveable.GetLogText(),"PlacedOn","Canvas")); Log.WriteAction(LogAction.placed, "block", moveable.GetLogText() + " on canvas"); } } } } catch (Exception x) { MessageBox.Show("Something went wrong when handling a drop on the canvas.\n\n" + x); } }