Exemplo n.º 1
0
 public void AddElements(DrawableContainerList elementsToAdd)
 {
     foreach (DrawableContainer element in elementsToAdd)
     {
         AddElement(element, true);
     }
 }
 public void SelectElements(DrawableContainerList elements)
 {
     foreach (DrawableContainer element in elements)
     {
         SelectElement(element);
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Make a following bounds change on this containerlist undoable!
 /// </summary>
 /// <param name="allowMerge">true means allow the moves to be merged</param>
 public void MakeBoundsChangeUndoable(bool allowMerge)
 {
     if (Count > 0 && Parent != null)
     {
         var clone = new DrawableContainerList();
         clone.AddRange(this);
         Parent.MakeUndoable(new DrawableContainerBoundsChangeMemento(clone), allowMerge);
     }
 }
Exemplo n.º 4
0
        public void PasteElementFromClipboard()
        {
            List <string> formats = ClipboardHelper.GetFormats();

            if (formats == null || formats.Count == 0)
            {
                return;
            }
            if (LOG.IsDebugEnabled)
            {
                LOG.Debug("List of clipboard formats available for pasting:");
                foreach (string format in formats)
                {
                    LOG.Debug("\tgot format: " + format);
                }
            }

            if (formats.Contains(typeof(DrawableContainerList).FullName))
            {
                DrawableContainerList dcs = (DrawableContainerList)ClipboardHelper.GetClipboardData(typeof(DrawableContainerList));
                if (dcs != null)
                {
                    dcs.Parent = this;
                    dcs.MoveBy(10, 10);
                    AddElements(dcs);
                    FieldAggregator.BindElements(dcs);
                    DeselectAllElements();
                    SelectElements(dcs);
                }
            }
            else if (ClipboardHelper.ContainsImage())
            {
                using (Image image = ClipboardHelper.GetImage()) {
                    if (image != null)
                    {
                        DeselectAllElements();
                        IBitmapContainer bitmapContainer = AddBitmapContainer(image as Bitmap, 0, 0);
                        SelectElement(bitmapContainer);
                    }
                }
            }
            else if (ClipboardHelper.ContainsText())
            {
                string text = ClipboardHelper.GetText();
                if (text != null)
                {
                    DeselectAllElements();
                    ITextContainer textContainer = AddTextContainer(text, HorizontalAlignment.Center, VerticalAlignment.CENTER,
                                                                    FontFamily.GenericSansSerif, 12f, false, false, false, 2, Color.Black, Color.Transparent);
                    SelectElement(textContainer);
                }
            }
        }
Exemplo n.º 5
0
        public static Bitmap GetImageForExport(Image img)
        {
            Bitmap   ret = new Bitmap(img.Width, img.Height);
            Graphics g   = Graphics.FromImage(ret);

            g.DrawImageUnscaled(img, new Point(0, 0));
            DrawableContainerList elements = new DrawableContainerList();

            elements.Draw(g, DrawableContainer.RenderMode.EXPORT);
            g.DrawImage(ret, 0, 0);
            return(ret);
        }
 /// <summary>
 /// Pulls one or several elements up to the topmost level(s) in hierarchy (z-index).
 /// </summary>
 /// <param name="elements">of elements to pull to top</param>
 public void PullElementsToTop(DrawableContainerList elements)
 {
     DrawableContainer[] dcs = this.ToArray();
     for (int i = 0; i < dcs.Length; i++)
     {
         DrawableContainer dc = dcs[i];
         if (elements.Contains(dc))
         {
             this.Remove(dc);
             this.Add(dc);
         }
     }
 }
 /// <summary>
 /// Pushes one or several elements down to the bottommost level(s) in hierarchy (z-index).
 /// </summary>
 /// <param name="elements">of elements to push to bottom</param>
 public void PushElementsToBottom(DrawableContainerList elements)
 {
     DrawableContainer[] dcs = this.ToArray();
     for (int i = dcs.Length - 1; i >= 0; i--)
     {
         DrawableContainer dc = dcs[i];
         if (elements.Contains(dc))
         {
             this.Remove(dc);
             this.Insert(0, dc);
         }
     }
 }
 /// <summary>
 /// Pulls one or several elements up to the topmost level(s) in hierarchy (z-index).
 /// </summary>
 /// <param name="elements">of elements to pull to top</param>
 public void PullElementsToTop(DrawableContainerList elements)
 {
     IDrawableContainer[] dcs = ToArray();
     for (int i = 0; i < dcs.Length; i++)
     {
         IDrawableContainer dc = dcs[i];
         if (elements.Contains(dc))
         {
             Remove(dc);
             Add(dc);
             Parent.Modified = true;
         }
     }
 }
Exemplo n.º 9
0
 /// <summary>
 /// Pushes one or several elements down one level in hierarchy (z-index).
 /// </summary>
 /// <param name="elements">list of elements to push down</param>
 public void PushElementsDown(DrawableContainerList elements)
 {
     for (int i = 0; i < Count; i++)
     {
         DrawableContainer dc = this[i];
         if (elements.Contains(dc))
         {
             if ((i > 0) && !elements.Contains(this[i - 1]))
             {
                 SwapElements(i, i - 1);
             }
         }
     }
 }
Exemplo n.º 10
0
 /// <summary>
 /// Pulls one or several elements up one level in hierarchy (z-index).
 /// </summary>
 /// <param name="elements">list of elements to pull up</param>
 public void PullElementsUp(DrawableContainerList elements)
 {
     for (int i = this.Count - 1; i >= 0; i--)
     {
         DrawableContainer dc = this[i];
         if (elements.Contains(dc))
         {
             if (Count > (i + 1) && !elements.Contains(this[i + 1]))
             {
                 SwapElements(i, i + 1);
             }
         }
     }
 }
 /// <summary>
 /// Pushes one or several elements down to the bottommost level(s) in hierarchy (z-index).
 /// </summary>
 /// <param name="elements">of elements to push to bottom</param>
 public void PushElementsToBottom(DrawableContainerList elements)
 {
     IDrawableContainer[] dcs = ToArray();
     for (int i = dcs.Length - 1; i >= 0; i--)
     {
         IDrawableContainer dc = dcs[i];
         if (elements.Contains(dc))
         {
             Remove(dc);
             Insert(0, dc);
             Parent.Modified = true;
         }
     }
 }
Exemplo n.º 12
0
        public void DuplicateSelectedElements()
        {
            if (LOG.IsDebugEnabled)
            {
                LOG.Debug("Duplicating " + selectedElements.Count + " selected elements");
            }
            DrawableContainerList dcs = selectedElements.Clone();

            dcs.Parent = this;
            dcs.MoveBy(10, 10);
            AddElements(dcs);
            DeselectAllElements();
            SelectElements(dcs);
        }
        public void DuplicateSelectedElements()
        {
            MemoryStream    ms = new MemoryStream();
            BinaryFormatter bf = new BinaryFormatter();

            bf.Serialize(ms, selectedElements);
            ms.Seek(0, 0);
            DrawableContainerList dc = (DrawableContainerList)bf.Deserialize(ms);

            dc.Parent = this;
            dc.MoveBy(10, 10);
            AddElements(dc);
            DeselectAllElements();
            SelectElements(dc);
        }
Exemplo n.º 14
0
 /// <summary>
 /// Indicates whether the given list of elements can be pushed down,
 /// i.e. whether there is at least one unselected element lower in hierarchy
 /// </summary>
 /// <param name="elements">list of elements to push down</param>
 /// <returns>true if the elements could be pushed down</returns>
 public bool CanPushDown(DrawableContainerList elements)
 {
     if (elements.Count == 0 || elements.Count == this.Count)
     {
         return(false);
     }
     foreach (DrawableContainer element in elements)
     {
         if (this.IndexOf(element) >= elements.Count)
         {
             return(true);
         }
     }
     return(false);
 }
 /// <summary>
 /// Indicates whether the given list of elements can be pulled up,
 /// i.e. whether there is at least one unselected element higher in hierarchy
 /// </summary>
 /// <param name="elements">list of elements to pull up</param>
 /// <returns>true if the elements could be pulled up</returns>
 public bool CanPullUp(DrawableContainerList elements)
 {
     if (elements.Count == 0 || elements.Count == Count)
     {
         return(false);
     }
     foreach (var element in elements)
     {
         if (IndexOf(element) < Count - elements.Count)
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 16
0
 /// <summary>
 /// Pulls one or several elements up one level in hierarchy (z-index).
 /// </summary>
 /// <param name="elements">list of elements to pull up</param>
 public void PullElementsUp(DrawableContainerList elements)
 {
     for (int i = Count - 1; i >= 0; i--)
     {
         var dc = this[i];
         if (!elements.Contains(dc))
         {
             continue;
         }
         if (Count > i + 1 && !elements.Contains(this[i + 1]))
         {
             SwapElements(i, i + 1);
         }
     }
 }
Exemplo n.º 17
0
 public void LoadElementsFromStream(Stream streamRead)
 {
     try {
         BinaryFormatter       binaryRead     = new BinaryFormatter();
         DrawableContainerList loadedElements = (DrawableContainerList)binaryRead.Deserialize(streamRead);
         if (loadedElements != null)
         {
             loadedElements.Parent = this;
             DeselectAllElements();
             AddElements(loadedElements);
             SelectElements(loadedElements);
             FieldAggregator.BindElements(loadedElements);
         }
     } catch (Exception e) {
         LOG.Error("Error serializing elements from stream.", e);
     }
 }
        public void PasteElementFromClipboard()
        {
            IDataObject           ido = Clipboard.GetDataObject();
            DrawableContainerList dc  = null;

            if (ido.GetDataPresent(typeof(DrawableContainerList)))
            {
                dc = (DrawableContainerList)ido.GetData(typeof(DrawableContainerList));
            }
            if (dc != null)
            {
                dc.Parent = this;
                dc.MoveBy(10, 10);
                AddElements(dc);
                DeselectAllElements();
                SelectElements(dc);
            }
        }
 public void AddElements(DrawableContainerList elems)
 {
     elements.AddRange(elems);
     Invalidate();
 }
Exemplo n.º 20
0
        /// <summary>
        /// Add items to a context menu for the selected item
        /// </summary>
        /// <param name="menu"></param>
        public virtual void AddContextMenuItems(ContextMenuStrip menu, Surface surface)
        {
            bool push = surface.Elements.CanPushDown(this);
            bool pull = surface.Elements.CanPullUp(this);

            ToolStripMenuItem item;

            // Pull "up"
            if (pull)
            {
                item        = new ToolStripMenuItem(Language.GetString(LangKey.editor_uptotop));
                item.Click += delegate {
                    surface.Elements.PullElementsToTop(this);
                    surface.Elements.Invalidate();
                };
                menu.Items.Add(item);
                item        = new ToolStripMenuItem(Language.GetString(LangKey.editor_uponelevel));
                item.Click += delegate {
                    surface.Elements.PullElementsUp(this);
                    surface.Elements.Invalidate();
                };
                menu.Items.Add(item);
            }
            // Push "down"
            if (push)
            {
                item        = new ToolStripMenuItem(Language.GetString(LangKey.editor_downtobottom));
                item.Click += delegate {
                    surface.Elements.PushElementsToBottom(this);
                    surface.Elements.Invalidate();
                };
                menu.Items.Add(item);
                item        = new ToolStripMenuItem(Language.GetString(LangKey.editor_downonelevel));
                item.Click += delegate {
                    surface.Elements.PushElementsDown(this);
                    surface.Elements.Invalidate();
                };
                menu.Items.Add(item);
            }

            // Duplicate
            item        = new ToolStripMenuItem(Language.GetString(LangKey.editor_duplicate));
            item.Click += delegate {
                DrawableContainerList dcs = this.Clone();
                dcs.Parent = surface;
                dcs.MoveBy(10, 10);
                surface.AddElements(dcs);
                surface.DeselectAllElements();
                surface.SelectElements(dcs);
            };
            menu.Items.Add(item);

            // Copy
            item        = new ToolStripMenuItem(Language.GetString(LangKey.editor_copytoclipboard));
            item.Image  = ((System.Drawing.Image)(editorFormResources.GetObject("copyToolStripMenuItem.Image")));
            item.Click += delegate {
                ClipboardHelper.SetClipboardData(typeof(DrawableContainerList), this);
            };
            menu.Items.Add(item);

            // Cut
            item        = new ToolStripMenuItem(Language.GetString(LangKey.editor_cuttoclipboard));
            item.Image  = ((System.Drawing.Image)(editorFormResources.GetObject("btnCut.Image")));
            item.Click += delegate {
                ClipboardHelper.SetClipboardData(typeof(DrawableContainerList), this);
                foreach (DrawableContainer container in this)
                {
                    surface.RemoveElement(container, true);
                }
            };
            menu.Items.Add(item);

            // Delete
            item        = new ToolStripMenuItem(Language.GetString(LangKey.editor_deleteelement));
            item.Image  = ((System.Drawing.Image)(editorFormResources.GetObject("removeObjectToolStripMenuItem.Image")));
            item.Click += delegate {
                foreach (DrawableContainer container in this)
                {
                    surface.RemoveElement(container, true);
                }
            };
            menu.Items.Add(item);

            // Reset
            bool canReset = false;

            foreach (DrawableContainer container in this)
            {
                if (container.hasDefaultSize)
                {
                    canReset = true;
                }
            }
            if (canReset)
            {
                item = new ToolStripMenuItem("Reset size");
                //item.Image = ((System.Drawing.Image)(editorFormResources.GetObject("removeObjectToolStripMenuItem.Image")));
                item.Click += delegate {
                    foreach (DrawableContainer container in this)
                    {
                        if (container.hasDefaultSize)
                        {
                            Size defaultSize = container.DefaultSize;
                            container.Invalidate();
                            container.MakeBoundsChangeUndoable(false);
                            container.Width  = defaultSize.Width;
                            container.Height = defaultSize.Height;
                            container.Invalidate();
                        }
                    }
                };
                menu.Items.Add(item);
            }
        }