private void surfaceMovingElementChanged(object sender, DrawableContainerList selectedElements)
        {
            bool elementSelected = (selectedElements.Count > 0);

            this.btnCopy.Enabled                          = elementSelected;
            this.btnCut.Enabled                           = elementSelected;
            this.btnDelete.Enabled                        = elementSelected;
            this.copyToolStripMenuItem.Enabled            = elementSelected;
            this.cutToolStripMenuItem.Enabled             = elementSelected;
            this.duplicateToolStripMenuItem.Enabled       = elementSelected;
            this.removeObjectToolStripMenuItem.Enabled    = elementSelected;
            this.borderColorToolStripMenuItem.Enabled     = (elementSelected && selectedElements.PropertySupported(DrawableContainer.Property.LINECOLOR));
            this.btnBorderColor.Enabled                   = (elementSelected && selectedElements.PropertySupported(DrawableContainer.Property.LINECOLOR));
            this.backgroundColorToolStripMenuItem.Enabled = (elementSelected && selectedElements.PropertySupported(DrawableContainer.Property.FILLCOLOR));
            this.btnBackColor.Enabled                     = (elementSelected && selectedElements.PropertySupported(DrawableContainer.Property.FILLCOLOR));
            this.lineThickness1ToolStripMenuItem.Enabled  = this.lineThicknessToolStripMenuItem.Enabled = (elementSelected && selectedElements.PropertySupported(DrawableContainer.Property.THICKNESS));
            this.comboBoxThickness.Enabled                = (elementSelected && selectedElements.PropertySupported(DrawableContainer.Property.THICKNESS));
            this.btnArrowHeads.Enabled                    = (elementSelected && selectedElements.PropertySupported(DrawableContainer.Property.ARROWHEADS));
            this.arrowHeadsToolStripMenuItem.Enabled      = (elementSelected && selectedElements.PropertySupported(DrawableContainer.Property.ARROWHEADS));

            bool push = surface.CanPushSelectionDown();
            bool pull = surface.CanPullSelectionUp();

            this.arrangeToolStripMenuItem.Enabled = (push || pull);
            if (this.arrangeToolStripMenuItem.Enabled)
            {
                this.upToTopToolStripMenuItem.Enabled      = pull;
                this.upOneLevelToolStripMenuItem.Enabled   = pull;
                this.downToBottomToolStripMenuItem.Enabled = push;
                this.downOneLevelToolStripMenuItem.Enabled = push;
            }
        }
Beispiel #2
0
 public void BindElements(DrawableContainerList dcs)
 {
     foreach (DrawableContainer dc in dcs)
     {
         BindElement(dc);
     }
 }
Beispiel #3
0
 public void BindElements(DrawableContainerList dcs)
 {
     foreach (DrawableContainer dc in dcs)
     {
         BindElement(dc);
     }
 }
 public void SelectElements(DrawableContainerList elements)
 {
     foreach (DrawableContainer element in elements)
     {
         SelectElement(element);
     }
 }
 public void AddElements(DrawableContainerList elems)
 {
     elements.AddRange(elems);
     Invalidate();
 }
 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>
 /// Add the supplied elements to the surface
 /// </summary>
 /// <param name="elementsToAdd"></param>
 public void AddElements(DrawableContainerList elementsToAdd)
 {
     foreach (IDrawableContainer element in elementsToAdd)
     {
         AddElement(element, true);
     }
 }
 /// <summary>
 /// Base Surface constructor
 /// </summary>
 public Surface()
     : base()
 {
     Count++;
     _elements = new DrawableContainerList(_uniqueId);
     selectedElements = new DrawableContainerList(_uniqueId);
     LOG.Debug("Creating surface!");
     MouseDown += SurfaceMouseDown;
     MouseUp += SurfaceMouseUp;
     MouseMove += SurfaceMouseMove;
     MouseDoubleClick += SurfaceDoubleClick;
     Paint += SurfacePaint;
     AllowDrop = true;
     DragDrop += OnDragDrop;
     DragEnter += OnDragEnter;
     // bind selected & elements to this, otherwise they can't inform of modifications
     selectedElements.Parent = this;
     _elements.Parent = this;
     // Make sure we are visible
     Visible = true;
     TabStop = false;
     // Enable double buffering
     DoubleBuffered = true;
     SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.ContainerControl | ControlStyles.OptimizedDoubleBuffer | ControlStyles.SupportsTransparentBackColor, true);
 }
        /// <summary>
        /// This event handler is called when someone presses the mouse on a surface.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SurfaceMouseDown(object sender, MouseEventArgs e)
        {
            _mouseStart = e.Location;

            // check contextmenu
            if (e.Button == MouseButtons.Right)
            {
                DrawableContainerList selectedList = null;
                if (selectedElements != null && selectedElements.Count > 0)
                {
                    selectedList = selectedElements;
                }
                else
                {
                    // Single element
                    IDrawableContainer rightClickedContainer = _elements.ClickableElementAt(_mouseStart.X, _mouseStart.Y);
                    if (rightClickedContainer != null)
                    {
                        selectedList = new DrawableContainerList(ID);
                        selectedList.Add(rightClickedContainer);
                    }
                }
                if (selectedList != null && selectedList.Count > 0)
                {
                    selectedList.ShowContextMenu(e, this);
                }
                return;
            }

            _mouseDown = true;
            _isSurfaceMoveMadeUndoable = false;

            if (_cropContainer != null && ((_undrawnElement == null) || (_undrawnElement != null && DrawingMode != DrawingModes.Crop)))
            {
                RemoveElement(_cropContainer, false);
                _cropContainer = null;
                _drawingElement = null;
            }

            if (_drawingElement == null && DrawingMode != DrawingModes.None)
            {
                if (_undrawnElement == null)
                {
                    DeselectAllElements();
                    if (_undrawnElement == null)
                    {
                        CreateUndrawnElement();
                    }
                }
                _drawingElement = _undrawnElement;
                // if a new element has been drawn, set location and register it
                if (_drawingElement != null)
                {
                    _drawingElement.Status = _undrawnElement.DefaultEditMode;
                    _drawingElement.PropertyChanged += ElementPropertyChanged;
                    if (!_drawingElement.HandleMouseDown(_mouseStart.X, _mouseStart.Y))
                    {
                        _drawingElement.Left = _mouseStart.X;
                        _drawingElement.Top = _mouseStart.Y;
                    }
                    AddElement(_drawingElement);
                    _drawingElement.Selected = true;
                }
                _undrawnElement = null;
            }
            else
            {
                // check whether an existing element was clicked
                // we save mouse down element separately from selectedElements (checked on mouse up),
                // since it could be moved around before it is actually selected
                _mouseDownElement = _elements.ClickableElementAt(_mouseStart.X, _mouseStart.Y);

                if (_mouseDownElement != null)
                {
                    _mouseDownElement.Status = EditStatus.MOVING;
                }
            }
        }
        private void surfaceMovingElementChanged(object sender, DrawableContainerList selectedElements)
        {
            bool elementSelected = (selectedElements.Count > 0);
            this.btnCopy.Enabled = elementSelected;
            this.btnCut.Enabled = elementSelected;
            this.btnDelete.Enabled = elementSelected;
            this.copyToolStripMenuItem.Enabled = elementSelected;
            this.cutToolStripMenuItem.Enabled = elementSelected;
            this.duplicateToolStripMenuItem.Enabled = elementSelected;
            this.removeObjectToolStripMenuItem.Enabled = elementSelected;

            //this.btnBorderColor.Enabled = this.borderColorToolStripMenuItem.Enabled =
            //(elementSelected && selectedElements.PropertySupported(DrawableContainer.Property.LINECOLOR));
            //this.btnBackgroundColor.Enabled = this.backgroundColorToolStripMenuItem.Enabled =
            //(elementSelected && selectedElements.PropertySupported(DrawableContainer.Property.FILLCOLOR));
            //this.comboBoxThickness.Enabled = this.lineThicknessToolStripMenuItem.Enabled =
            //(elementSelected && selectedElements.PropertySupported(DrawableContainer.Property.THICKNESS));
            //this.btnArrowHeads.Enabled = this.arrowHeadsToolStripMenuItem.Enabled =
            //(elementSelected && selectedElements.PropertySupported(DrawableContainer.Property.ARROWHEADS));

            bool push = surface.CanPushSelectionDown();
            bool pull = surface.CanPullSelectionUp();
            this.arrangeToolStripMenuItem.Enabled = (push || pull);
            if (this.arrangeToolStripMenuItem.Enabled)
            {
                this.upToTopToolStripMenuItem.Enabled = pull;
                this.upOneLevelToolStripMenuItem.Enabled = pull;
                this.downToBottomToolStripMenuItem.Enabled = push;
                this.downOneLevelToolStripMenuItem.Enabled = push;
            }
        }