private static void GenerateLayoutLevel(IShapeContainer container, GridLayout layout, Transaction transaction) { foreach (var sub in layout.Contents) { var item = new Item { ItemType = sub.Type, StyleType = Item.DefaultItemDisplayTypeForType(sub.Type), LineStyle = { Colour = Color.Black }, FillStyle = { Colour = Color.LightGray }, LabelText = "" }; item.SetBounds(sub.Bounds); var scriptable = new Scriptable(item); container.Contents.Add(scriptable); scriptable.Parent = container; transaction.Create(item); transaction.Create(scriptable); scriptable.SelectScript = new Script(); if (sub.Contents != null) { scriptable.SelectScript.Visit.VisitType = Script.VisitTarget.VisitTypes.Down; GenerateLayoutLevel(item, sub, transaction); } else { scriptable.SelectScript.Visit.VisitType = Script.VisitTarget.VisitTypes.Up; } } container.FinishedModifyingContents(transaction); }
public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction) { IShapeContainer container = CurrentPage.SelectionContainer(); if (container == null) { MessageBox.Show(Strings.Item("Container_Mismatch")); return; } transaction.Edit((Datum)container); List <Shape> created = new List <Shape>(); int nextID = (from p in Globals.Root.CurrentDocument.Pages select p.FindHighestUsedID()).Max() + 1; foreach (Shape s in CurrentPage.SelectedShapes) { transaction.Edit(s); Scriptable scriptable = new Scriptable(s); transaction.Create(scriptable); scriptable.Parent = container; scriptable.SAWID = nextID++; container.Contents.Remove(s); container.Contents.Add(scriptable); // note this makes no attempt to maintain Z order. Edited items will be brought to the front (but are likely to maintain relative order) created.Add(scriptable); } container.FinishedModifyingContents(transaction); // it should still be the contained elements which are listed as selected I think CurrentPage.SelectOnly(created); }
public OpenCommand(IFileShapeParser shapeParser, IShapeContainer shapeContainer, IWriter writer) { _shapeParser = shapeParser; _shapeContainer = shapeContainer; _writer = writer; }
public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction) { IShapeContainer container = CurrentPage.SelectionContainer(); if (container == null) { MessageBox.Show(Strings.Item("Container_Mismatch")); return; } transaction.Edit((Datum)container); Lined mask = FindSourceShape(); ImportedImage image = FindSourceImage(); transaction.Edit(mask); transaction.Edit(image); (mask as Pencil).ForceClosure(transaction); if (mask is Curve curve && !curve.Closed()) { throw new UserException("[Mask_Not_Closed]"); } MaskedImage result = new MaskedImage(image, mask); transaction.Create(result); int index = Math.Max(mask.Z, image.Z); // this will be the Z-order of the new group result.Parent = container; container.Contents.Insert(index + 1, result); // This index will be valid as the individual shapes are still in the list container.Contents.Remove(mask); container.Contents.Remove(image); container.FinishedModifyingContents(transaction, null); CurrentPage.SelectOnly(result); }
private void FillTreeNode(IShapeContainer container, TreeNodeCollection nodes) { foreach (Shape shape in container.Contents) { AddTreeNode(shape, nodes); } }
public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction) { if (CurrentPage.SelectedCount != 1) { return; } Shape shape = CurrentPage.SelectedShapes.First(); GraphicsPath path = shape.ConvertToPath(); if (path == null) { Utilities.LogSubError("ConvertToPath returned null from: " + shape.ShapeCode); MessageBox.Show(Strings.Item("ConvertPath_Null")); return; } GenericPath create = new GenericPath(path); create.DeriveStyles(new[] { shape }); // {} because it takes a list of shapes transaction.Edit((Datum)shape.Parent); transaction.Create(create); IShapeContainer container = (IShapeContainer)shape.Parent; container.Contents.Remove(shape); container.Contents.Add(create); container.FinishedModifyingContents(transaction); create.Parent = shape.Parent; transaction.Delete(shape); CurrentPage.SelectOnly(create); }
public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction) { Shape moving = CurrentPage.SelectedShapes.First(); IShapeContainer oldContainer = moving.Container; int targetIndex = oldContainer.Contents.IndexOf(moving) - 1; // index of new container if (targetIndex < 0) { return; } IShapeContainer newContainer = oldContainer.Contents[targetIndex].AsContainer; if (newContainer == null) { return; // item cannot accept contents } transaction.Edit((Datum)oldContainer); transaction.Edit((Datum)newContainer); transaction.Edit(moving); oldContainer.Contents.Remove(moving); newContainer.Contents.Add(moving); moving.Parent = newContainer; // move child physically within (newContainer as Container)?.BringChildWithinBounds(moving, transaction); oldContainer.FinishedModifyingContents(transaction); newContainer.FinishedModifyingContents(transaction); moving.Parent.NotifyIndirectChange(moving, ChangeAffects.GrabSpots); }
public static void Display(IShapeContainer container, Document doc) { var frm = new frmGridWizard(); Transaction transaction = new Transaction(); if (frm.ShowDialog() == DialogResult.OK) { if (container is Scriptable) { container = (IShapeContainer)(container as Scriptable).Element; // buttons go in the item not the scriptable! } transaction.Edit((Datum)container); RectangleF bounds; if (container is Page) { bounds = (container as Page).Bounds; } else { bounds = (container as Shape).Bounds; } container.Contents.Clear(); var layout = GridLayout.CalculateAreas(bounds, (int)frm.nudRows.Value, (int)frm.nudColumns.Value, (int)frm.nudSpacing.Value, frm.SelectedOrder, (GridLayout.Escapes)frm.cmbEscapes.SelectedIndex, frm.SelectedEscapeRatio); GenerateLayoutLevel(container, layout, transaction); Globals.Root.StoreNewTransaction(transaction, true); } }
public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction) { IShapeContainer container = CurrentPage.SelectionContainer(); if (container == null) { MessageBox.Show(Strings.Item("Container_Mismatch")); return; } transaction.Edit((Datum)container); List <Shape> moved = new List <Shape>(); foreach (Scriptable scriptable in CurrentPage.SelectedShapes) { transaction.Delete(scriptable); Shape shape = scriptable.Element; transaction.Edit(shape); shape.Parent = container; container.Contents.Remove(scriptable); container.Contents.Add(shape); moved.Add(shape); } container.FinishedModifyingContents(transaction); CurrentPage.SelectOnly(moved); }
public WithinCommand( IWriter writer, IShapeContainer shapeContainer, IShapeFactory shapeFactory) { _writer = writer; _shapeContainer = shapeContainer; _shapeFactory = shapeFactory; }
public CreateCommand( IFileShapeParser shapeParser, IShapeContainer shapeContainer, IWriter writer, IShapeFactory shapeFactory) { _shapeParser = shapeParser; _shapeContainer = shapeContainer; _writer = writer; _shapeFactory = shapeFactory; }
public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction) { Shape moving = CurrentPage.SelectedShapes.First(); IShapeContainer oldContainer = moving.Container; IShapeContainer newContainer = (oldContainer as Shape).Container.AsParentContainer; transaction.Edit((Datum)oldContainer); transaction.Edit((Datum)newContainer); transaction.Edit(moving); oldContainer.Contents.Remove(moving); newContainer.Contents.Add(moving); moving.Parent = newContainer; oldContainer.FinishedModifyingContents(transaction); newContainer.FinishedModifyingContents(transaction); }
private void tvOutline_NodeMoved(object sender, TreeViewWithMove.MoveEventArgs e) { Transaction transaction = new Transaction(); Shape moved = (Shape)e.Moved.Tag; IShapeContainer parent = (IShapeContainer)moved.Parent; transaction.Edit(moved); transaction.Edit(moved.Parent as Datum); //int currentIndex = parent.Contents.IndexOf(moved); parent.Contents.Remove(moved); int newIndex = e.NewIndex; //if (currentIndex < e.NewIndex) // newIndex--; parent.Contents.Insert(newIndex, moved); parent.FinishedModifyingContents(transaction); Globals.Root.StoreNewTransaction(transaction, true); }
public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction) { MaskedImage masked = (MaskedImage)CurrentPage.SelectedShapes.First(); IShapeContainer container = (IShapeContainer)masked.Parent; transaction.Edit((Datum)container); transaction.Edit(masked.MaskShape); transaction.Edit(masked.Image); transaction.Delete(masked); masked.Image.Parent = container; masked.MaskShape.Parent = container; container.Contents.Insert(masked.Z + 1, masked.Image); // This index will be valid as the individual shapes are still in the list container.Contents.Insert(masked.Z + 2, masked.MaskShape); container.Contents.Remove(masked); container.FinishedModifyingContents(transaction, null); CurrentPage.SelectOnly(masked.MaskShape); // arbitrarily seemd better to leave the shape selected }
public bool AssignAbility(GameObject abilityPrefab) { if (remainingAbilities == 0) { return(false); } GameObject go = Instantiate(abilityPrefab, transform); go.transform.position = abilitySlot.transform.position; remainingAbilities--; IShapeContainer shapeContainer = transform.parent.GetComponent <IShapeContainer>(); shapeContainer.PrepareStart(); AudioSource snapSound = gameObject.AddComponent <AudioSource>(); snapSound.clip = Resources.Load("SoundEffects/Snap/SnapSound") as AudioClip; snapSound.Play(); return(true); }
public override bool IsApplicable(EditableView pnlView) { if (CurrentPage.SelectedCount != 1) { return(false); } Shape moving = CurrentPage.SelectedShapes.First(); IShapeContainer oldContainer = moving.Container; int targetIndex = oldContainer.Contents.IndexOf(moving) - 1; // index of new container // can't do it if it's listed first: if (targetIndex < 0) { return(false); } IShapeContainer newContainer = oldContainer.Contents[targetIndex].AsContainer; if (newContainer == null) { return(false); // item cannot accept contents } return(true); }
public TranslateCommand(IWriter writer, IShapeContainer shapeContainer) { _writer = writer; _shapeContainer = shapeContainer; }
private void Engine_TransactionStored(object sender, Globals.TransactionEventArgs e) { if (m_Stale) { if (Visible) { FillTree(); } return; } if (!Visible) { m_Stale = true; tvOutline.Nodes.Clear(); NodeList.Clear(); return; } bool wipeout = false; foreach (Change change in e.Transaction) { if (change.Key is IShapeContainer && !change.IsCreate && !change.IsDelete) { IShapeContainer current = (IShapeContainer)change.Current; IShapeContainer previous = (IShapeContainer)change.Previous; if (current.Contents.Count != previous.Contents.Count) { wipeout = true; } else { wipeout = Enumerable.Range(0, current.Contents.Count).Any(i => current.Contents[i] != previous.Contents[i]); } } if (change.Key is Page) { if (change.IsCreate || change.IsDelete) { wipeout = true; } } else if (change.Key is Document) { wipeout = true; } else if (change.Key is Shape) { if (NodeList.ContainsKey(change.Key)) { if (change.IsDelete) { NodeList[change.Key].Remove(); // removes the node from the tree NodeList.Remove(change.Key); // And update our list } else if (!change.IsCreate) { Shape currentShape = change.Current as Shape; Shape previousShape = (Shape)change.Previous; if (currentShape.Parent != previousShape.Parent || currentShape.Z != previousShape.Z) { wipeout = true; // A shape has been moved from one container to another; just update the entire tree } else if (currentShape.LabelText != previousShape.LabelText) { NodeList[change.Current].Text = currentShape.Description; } StyleNode(NodeList[change.Current], currentShape); } } else if (change.IsCreate) { Shape shp = change.Current as Shape; if (NodeList.ContainsKey((Datum)shp.Parent)) { AddTreeNode(shp, NodeList[(Datum)shp.Parent].Nodes); } else { wipeout = true; // can't find parent of new shape. Just give up and start again } } } if (wipeout) { break; } } if (wipeout) { FillTree(); } UpdateInfo(); }
public void btnAdd_Click(object sender, EventArgs e) { Transaction transaction = new Transaction(); List <ButtonShape> buttons = m_Page.OfType <ButtonShape>().ToList(); PointF pt; SizeF sz; // Button is positioned to the bottom right of the existing ones; position will actually be ignored if there is a flow buttons.Sort((X, Y) => { // Sorts into an effectively reading order, but backwards. First entry will be bottom right float result = -(X.Bounds.Bottom - Y.Bounds.Bottom); if (Math.Abs(result) < Geometry.NEGLIGIBLE) { result = -(X.Bounds.Right - Y.Bounds.Right); } return(Math.Sign(result)); }); if (buttons.Any()) { sz = new SizeF(buttons.Average(x => x.Bounds.Width), buttons.Average(x => x.Bounds.Height)); pt = buttons.First().Bounds.TopRight() + new SizeF(1, 0); if (pt.X + sz.Width > m_Page.Bounds.Width) // Has gone off the end of the line, start a new line { pt = new PointF(0, pt.Y + sz.Height + 1); } if (pt.Y + sz.Height * 0.6 > m_Page.Size.Height) // off the bottom - Just resets to the top left in this case { pt = new PointF(0, -m_Page.Size.Height); } } else { sz = new SizeF(9, 9); pt = new PointF(0, -m_Page.Size.Height); } ButtonShape create = new ButtonShape(); transaction.Create(create); EditableView.ClickPosition dummyPosition = new EditableView.ClickPosition(pt, m_Page, 1, Shape.SnapModes.Off, Shape.SnapModes.Off, null, EditableView.ClickPosition.Sources.Irrelevant); create.Start(dummyPosition); create.SetStyleObject(frmButton.GetStyleForNewButton(m_Page)); dummyPosition.Exact = dummyPosition.Exact + sz; dummyPosition.Snapped = dummyPosition.Exact; create.Complete(dummyPosition); create.Action = ctrActions.SelectedAction; switch (create.Action.Change) { case Parameters.Action_Character: create.Action = new CharAction(m_Key.ToString()); break; case Parameters.Action_Key: create.Action = new KeyAction(m_eKey); break; case Parameters.Action_Text: if (string.IsNullOrEmpty((create.Action as TextAction)?.Text)) // might already be specified by list { create.Action = new TextAction(txtText.Text); } break; } SharedImage image; string temp; ButtonShape.GetDisplayFromAction(create.Action, out temp, out image, transaction); create.LabelText = temp; if (image != null) { create.SetImage(image); } if (m_Page.IsSingleAutoSize) { IShapeContainer container = (IShapeContainer)m_Page.Shapes.First(); transaction.Edit((Datum)container); container.Contents.Add(create); create.Parent = (IShapeParent)container; container.FinishedModifyingContents(transaction, null); if (create.Bounds.Bottom > m_Page.Bounds.Bottom) // Is off the bottom { transaction.Edit(m_Page); m_Page.SetSizeExcludingMargin(new SizeF(m_Page.Size.Width, pt.Y + sz.Height - m_Page.Bounds.Top)); ((IAutoSize)container).SetBounds(m_Page.Bounds, null); Globals.OnCurrentPageSizeChanged(); } } else { m_Page.AddNew(create, transaction); if (pt.Y > m_Page.Bounds.Bottom - 1) // Is off the bottom { transaction.Edit(m_Page); float height = pt.Y + sz.Height + m_Page.Margin * 2 - m_Page.Bounds.Top; TransformMove delta = new TransformMove(0, -(height - m_Page.PhysicalSize.Height)); // All existing shapes will need to be moved up by this much because the top coordinate of the page will change m_Page.SetSize(new SizeF(m_Page.PhysicalSize.Width, height), m_Page.Margin); foreach (Shape shp in m_Page) { transaction.Edit(shp); shp.ApplyTransformation(delta); } Globals.OnCurrentPageSizeChanged(); } } Globals.Root.StoreNewTransaction(transaction, true); }
public EraseCommand(IShapeContainer shapeContainer, IWriter writer) { _shapeContainer = shapeContainer; _writer = writer; }
private void PasteSplashData(Transaction transaction, EditableView pnlView) { DataObject data = (DataObject)Clipboard.GetDataObject(); byte[] buffer = (byte[])data.GetData("Splash data", false); // will be nothing if deserialisation failed if (buffer == null) { Debug.Fail("Deserialisation failed"); return; } using (MemoryStream stream = new MemoryStream(buffer, false)) using (DataReader reader = new DataReader(stream, FileMarkers.ShapeList)) { List <Datum> list = reader.ReadDataList(); // cannot insert objects directly as that would mean pasting twice inserted 2 objects with same ID Mapping hashIDChanges = new Mapping(); DatumList newList = new DatumList(); RectangleF bounds = RectangleF.Empty; // work out existing bounds of list bool includesShapes = false; foreach (Datum datum in list) { if (datum is Shape) { // assumed that all shapes need to be created into page Shape create = (Shape)datum.Clone(hashIDChanges); transaction.Create(create); newList.Add(create); Geometry.Extend(ref bounds, create.MinimalBounds); // minimal makes, for example, the snapping of axes better includesShapes = true; } else if (datum is SharedBase resource) { // no need to clone these as they are effectively invariant if (CurrentDocument.FindExistingSharedResource <Datum>(resource.ID) == null) { transaction.Edit(CurrentDocument); CurrentDocument.AddSharedResource(resource); // if ID exists in this document it is assumed to be same object } } else if (datum is ButtonStyle buttonStyle) { // as Shape, but don't add to page // if IsShared it is not cloned. Means styles in multi docs will share ID, which is good as further pasting in will reuse existing style // does need to be added to document share ButtonStyle create; if (buttonStyle.IsShared) { create = buttonStyle; if (CurrentDocument.GetButtonStyle(create.ID) == null) { CurrentDocument.AddButtonStyle(create); // is new to this doc - either by cloning, or transaction.Create(create); } } else { create = (ButtonStyle)buttonStyle.Clone(hashIDChanges); transaction.Create(create); } newList.Add(create); } else { Debug.Fail("Datum not processed by by Paste: " + datum.TypeByte); } } // want to centre shapes within current area, rather than pasting at original position (which leaves them on top of each other and largely invisible) IShapeContainer container = CurrentPage; if (includesShapes) { if (CurrentPage.SelectedCount == 1 && CurrentPage.SelectedShapes.First().AsContainer != null) { container = CurrentPage.SelectedShapes.First().AsContainer; // but in SAW don't paste automatically into an empty container - chances are it's the item which was just copied! // instead paste into that container's parent if (!container.Any()) { container = (container as Shape).Container.AsParentContainer; } } PointF target = pnlView.ViewableArea().Centre(); // Or use cursor position if better PointF cursor = pnlView.CursorPositionLocal; // Automatically selects the drawing cursor if split cursors are used // or the container if (((Datum)container).TypeByte == (byte)Shape.Shapes.Container) { target = ((Shape)container).Bounds.Centre(); } else if (cursor.X > 0 && cursor.Y > 0 && cursor.X < pnlView.Width && cursor.Y < pnlView.Height) { cursor = pnlView.MouseToData(cursor.ToPoint()); // And also need to check the cursor is within the page. the above just checked it was within the control (there may be some dead area displayed) if (cursor.X < pnlView.ViewableArea().Width&& cursor.Y < pnlView.ViewableArea().Height) { target = cursor; } } target.X -= bounds.Width / 2; target.Y -= bounds.Height / 2; // where we want the top left to be if (pnlView.SnapMode == Shape.SnapModes.Grid) { target = CurrentPage.Paper.SnapPoint2(target); } var transform = new TransformMove(target.X - bounds.X, target.Y - bounds.Y); transaction.Edit((Datum)container); foreach (Shape shape in newList.Values.OfType <Shape>()) // of type needed in case other stuff was mixed in with it { container.Contents.Add(shape); shape.Parent = container; shape.ApplyTransformation(transform); } container.FinishedModifyingContents(transaction); } foreach (Datum shape in newList.Values) { try { // order changed shape.UpdateReferencesObjectsCreated(CurrentDocument, reader); shape.UpdateReferencesIDsChanged(hashIDChanges, Globals.Root.CurrentDocument); } catch (Exception ex) { Utilities.LogSubError(ex); } } List <Shape> newShapes = newList.Values.OfType <Shape>().ToList(); if (newShapes.Count > 0 && container == CurrentPage) // don't select the shapes when pasting into a container - leaves the container selected, which allows for more pastes { CurrentPage.SelectOnly(newShapes); } pnlView.InvalidateData(CurrentPage.SelectedRefreshBoundary(), StaticView.InvalidationBuffer.All); } }
public SaveCommand(IFileShapeParser fileShapeParser, IShapeContainer shapeContainer) { _fileShapeParser = fileShapeParser; _shapeContainer = shapeContainer; }
public PrintCommand(IShapeContainer shapeContainer) { _shapeContainer = shapeContainer; }
protected void OnEnable() { ValidateData(); shapeContainer = target as IShapeContainer; }