示例#1
0
        void SurfaceMouseMove(object sender, MouseEventArgs e)
        {
            Point currentMouse = MouseHelper.FixMouseCoordinates(e);

            if (DrawingMode != DrawingModes.None)
            {
                Cursor = Cursors.Cross;
            }
            else
            {
                Cursor = Cursors.Default;
            }

            if (mouseDown)
            {
                if (mouseDownElement != null)                  // an element is currently dragged
                {
                    mouseDownElement.Invalidate();
                    selectedElements.HideGrippers();
                    // Move the element
                    if (mouseDownElement.Selected)
                    {
                        if (!isSurfaceMoveMadeUndoable)
                        {
                            // Only allow one undoable per mouse-down/move/up "cycle"
                            isSurfaceMoveMadeUndoable = true;
                            selectedElements.MakeBoundsChangeUndoable(false);
                        }
                        // dragged element has been selected before -> move all
                        selectedElements.MoveBy(currentMouse.X - mouseStart.X, currentMouse.Y - mouseStart.Y);
                    }
                    else
                    {
                        if (!isSurfaceMoveMadeUndoable)
                        {
                            // Only allow one undoable per mouse-down/move/up "cycle"
                            isSurfaceMoveMadeUndoable = true;
                            mouseDownElement.MakeBoundsChangeUndoable(false);
                        }
                        // dragged element is not among selected elements -> just move dragged one
                        mouseDownElement.MoveBy(currentMouse.X - mouseStart.X, currentMouse.Y - mouseStart.Y);
                    }
                    mouseStart = currentMouse;
                    mouseDownElement.Invalidate();
                    modified = true;
                }
                else if (drawingElement != null)
                {
                    if (!drawingElement.HandleMouseMove(currentMouse.X, currentMouse.Y))
                    {
                        // an element is currently drawn
                        drawingElement.Invalidate();
                        drawingElement.Width  = currentMouse.X - drawingElement.Left;
                        drawingElement.Height = currentMouse.Y - drawingElement.Top;
                        drawingElement.Invalidate();
                    }
                    modified = true;
                }
            }
        }
 void SurfaceMouseMove(object sender, MouseEventArgs e)
 {
     if (DrawingMode != DrawingModes.None)
     {
         Cursor = Cursors.Cross;
     }
     else
     {
         Cursor = Cursors.Default;
     }
     if (mouseDown)
     {
         if (mouseDownElement != null) // an element is currently dragged
         {
             selectedElements.HideGrippers();
             if (mouseDownElement.Selected) // dragged element has been selected before -> move all
             {
                 selectedElements.MoveBy(e.X - mX, e.Y - mY);
             }
             else // dragged element is not among selected elements -> just move dragged one
             {
                 mouseDownElement.MoveBy(e.X - mX, e.Y - mY);
             }
             mX = e.X;
             mY = e.Y;
             Invalidate();
         }
         else if (drawingElement != null) // an element is currently drawn
         {
             drawingElement.Width  = e.X - drawingElement.Left;
             drawingElement.Height = e.Y - drawingElement.Top;
             Invalidate();
         }
     }
 }
示例#3
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);
                }
            }
        }
示例#4
0
        public bool ApplyCrop(Rectangle cropRectangle)
        {
            if (isCropPossible(ref cropRectangle))
            {
                // we should not forget to Dispose the images!!
                Bitmap tmpImage = ((Bitmap)Image).Clone(cropRectangle, Image.PixelFormat);
                tmpImage.SetResolution(Image.HorizontalResolution, Image.VerticalResolution);

                // Make undoable
                MakeUndoable(new SurfaceCropMemento(this, cropRectangle), false);

                SetImage(tmpImage, false);
                elements.MoveBy(-cropRectangle.Left, -cropRectangle.Top);
                if (SurfaceSizeChanged != null)
                {
                    SurfaceSizeChanged(this);
                }
                Invalidate();
                return(true);
            }
            return(false);
        }
示例#5
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);
        }
        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);
            }
        }
示例#8
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);
            }
        }