public void Dispose()
 {
     if (drawableContainer != null) {
         drawableContainer.Dispose();
         drawableContainer = null;
     }
 }
 public void DeselectElement(DrawableContainer element)
 {
     element.HideGrippers();
     element.Selected = false;
     selectedElements.Remove(element);
     MovingElementChanged(this, selectedElements);
 }
Exemple #3
0
        /// <summary>
        /// Allow the code to be used externally
        /// </summary>
        /// <param name="caller"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public static bool EllipseContains(DrawableContainer caller, int x, int y)
        {
            double xDistanceFromCenter = x - (caller.Left + caller.Width / 2);
            double yDistanceFromCenter = y - (caller.Top + caller.Height / 2);

            // ellipse: x^2/a^2 + y^2/b^2 = 1
            return(Math.Pow(xDistanceFromCenter, 2) / Math.Pow(caller.Width / 2, 2) + Math.Pow(yDistanceFromCenter, 2) / Math.Pow(caller.Height / 2, 2) < 1);
        }
Exemple #4
0
        private void CreateUndrawnElement()
        {
            if (undrawnElement != null)
            {
                FieldAggregator.UnbindElement(undrawnElement);
            }
            switch (DrawingMode)
            {
            case DrawingModes.Rect:
                undrawnElement = new RectangleContainer(this);
                break;

            case DrawingModes.Ellipse:
                undrawnElement = new EllipseContainer(this);
                break;

            case DrawingModes.Text:
                undrawnElement = new TextContainer(this);
                break;

            case DrawingModes.Line:
                undrawnElement = new LineContainer(this);
                break;

            case DrawingModes.Arrow:
                undrawnElement = new ArrowContainer(this);
                break;

            case DrawingModes.Highlight:
                undrawnElement = new HighlightContainer(this);
                break;

            case DrawingModes.Obfuscate:
                undrawnElement = new ObfuscateContainer(this);
                break;

            case DrawingModes.Crop:
                cropContainer  = new CropContainer(this);
                undrawnElement = cropContainer;
                break;

            case DrawingModes.Bitmap:
                undrawnElement = new BitmapContainer(this);
                break;

            case DrawingModes.Path:
                undrawnElement = new FreehandContainer(this);
                break;

            case DrawingModes.None:
                undrawnElement = null;
                break;
            }
            if (undrawnElement != null)
            {
                FieldAggregator.BindElement(undrawnElement);
            }
        }
 public void DeselectAllElements()
 {
     while (selectedElements.Count > 0)
     {
         DrawableContainer element = selectedElements[0];
         element.HideGrippers();
         element.Selected = false;
         selectedElements.Remove(element);
     }
     MovingElementChanged(this, selectedElements);
 }
 public void SelectElement(DrawableContainer element)
 {
     if (selectedElements.Contains(element))
     {
         return;
     }
     selectedElements.Add(element);
     element.ShowGrippers();
     element.Selected = true;
     MovingElementChanged(this, selectedElements);
     Invalidate();
 }
Exemple #7
0
        void SurfaceMouseDown(object sender, MouseEventArgs e)
        {
            mouseStart = MouseHelper.FixMouseCoordinates(e);
            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;
                drawingElement.Status = EditStatus.DRAWING;
                undrawnElement        = null;
                // if a new element has been drawn, set location and register it
                if (drawingElement != null)
                {
                    drawingElement.PropertyChanged += ElementPropertyChanged;
                    if (!drawingElement.HandleMouseDown(mouseStart.X, mouseStart.Y))
                    {
                        drawingElement.Left = mouseStart.X;
                        drawingElement.Top  = mouseStart.Y;
                    }
                    AddElement(drawingElement);
                    drawingElement.Selected = true;
                }
            }
            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;
                }
            }
        }
Exemple #8
0
        public void DeselectElement(IDrawableContainer container)
        {
            DrawableContainer element = container as DrawableContainer;

            element.HideGrippers();
            element.Selected = false;
            selectedElements.Remove(element);
            FieldAggregator.UnbindElement(element);
            if (MovingElementChanged != null)
            {
                MovingElementChanged(this, selectedElements);
            }
        }
 void SurfaceMouseDown(object sender, MouseEventArgs e)
 {
     mX             = e.X;
     mY             = e.Y;
     mouseDown      = true;
     drawingElement = null;
     if (DrawingMode == DrawingModes.Rect) // draw rectangle
     {
         DeselectAllElements();
         drawingElement = new RectangleContainer(this);
     }
     else if (DrawingMode == DrawingModes.Ellipse) // draw ellipse
     {
         DeselectAllElements();
         drawingElement = new EllipseContainer(this);
     }
     else if (DrawingMode == DrawingModes.Text) // draw textbox
     {
         DeselectAllElements();
         drawingElement = new TextContainer(this);
     }
     else if (DrawingMode == DrawingModes.Line) // draw line
     {
         DeselectAllElements();
         drawingElement = new LineContainer(this);
     }
     else if (DrawingMode == DrawingModes.Arrow) // draw arrow
     {
         DeselectAllElements();
         drawingElement = new LineContainer(this);
         ((LineContainer)drawingElement).HasEndPointArrowHead = true;
     }
     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(e.X, e.Y);
     }
     // if a new element has been drawn, set location and register it
     if (drawingElement != null)
     {
         drawingElement.Left      = e.X;
         drawingElement.Top       = e.Y;
         drawingElement.Selected  = true;
         drawingElement.ForeColor = conf.Editor_ForeColor;
         drawingElement.BackColor = conf.Editor_BackColor;
         drawingElement.Thickness = conf.Editor_Thickness;
         AddElement(drawingElement);
     }
 }
Exemple #10
0
        // drawablecontainers are regarded equal if they are of the same type and their bounds are equal. this should be sufficient.
        public override bool Equals(object obj)
        {
            bool ret = false;

            if (obj != null && GetType() == obj.GetType())
            {
                DrawableContainer other = obj as DrawableContainer;
                if (other != null && left == other.left && top == other.top && width == other.width && height == other.height)
                {
                    ret = true;
                }
            }
            return(ret);
        }
Exemple #11
0
 public void RemoveElement(DrawableContainer element, bool makeUndoable)
 {
     DeselectElement(element);
     elements.Remove(element);
     element.FieldChanged    -= element_FieldChanged;
     element.PropertyChanged -= ElementPropertyChanged;
     // Do not dispose, the memento should!! element.Dispose();
     element.Invalidate();
     if (makeUndoable)
     {
         MakeUndoable(new DeleteElementMemento(this, element), false);
     }
     modified = true;
 }
Exemple #12
0
 /// <summary>
 /// Add a new element to the surface
 /// </summary>
 /// <param name="element">the new element</param>
 /// <param name="makeUndoable">true if the adding should be undoable</param>
 public void AddElement(DrawableContainer element, bool makeUndoable)
 {
     elements.Add(element);
     element.FieldChanged    += element_FieldChanged;
     element.PropertyChanged += ElementPropertyChanged;
     if (element.Status == EditStatus.UNDRAWN)
     {
         element.Status = EditStatus.IDLE;
     }
     element.Invalidate();
     if (makeUndoable)
     {
         MakeUndoable(new AddElementMemento(this, element), false);
     }
     modified = true;
 }
Exemple #13
0
        public void SelectElement(IDrawableContainer container)
        {
            DrawableContainer element = container as DrawableContainer;

            if (!selectedElements.Contains(element))
            {
                selectedElements.Add(element);
                element.ShowGrippers();
                element.Selected = true;
                FieldAggregator.BindElement(element);
                if (MovingElementChanged != null)
                {
                    MovingElementChanged(this, selectedElements);
                }
                element.Invalidate();
            }
        }
Exemple #14
0
 public void DeselectAllElements()
 {
     if (HasSelectedElements())
     {
         while (selectedElements.Count > 0)
         {
             DrawableContainer element = selectedElements[0];
             element.Invalidate();
             element.HideGrippers();
             element.Selected = false;
             selectedElements.Remove(element);
             FieldAggregator.UnbindElement(element);
         }
         if (MovingElementChanged != null)
         {
             MovingElementChanged(this, selectedElements);
         }
     }
 }
Exemple #15
0
//		private void QueryContinueDragDrop(object sender, QueryContinueDragEventArgs e) {
//			LOG.Debug("QueryContinueDrag: " + e.Action);
//			if (e.EscapePressed) {
//				e.Action = DragAction.Cancel;
//			}
//		}
//
//		private void GiveFeedbackDragDrop(object sender, GiveFeedbackEventArgs e) {
//			e.UseDefaultCursors = true;
//		}
        #endregion

        /// <summary>
        /// Auto crop the image
        /// </summary>
        /// <returns>true if cropped</returns>
        public bool AutoCrop()
        {
            Rectangle cropRectangle = ImageHelper.FindAutoCropRectangle(Image);

            if (isCropPossible(ref cropRectangle))
            {
                DrawingMode          = DrawingModes.Crop;
                cropContainer        = new CropContainer(this);
                cropContainer.Left   = cropRectangle.X;
                cropContainer.Top    = cropRectangle.Y;
                cropContainer.Width  = cropRectangle.Width;
                cropContainer.Height = cropRectangle.Height;
                DeselectAllElements();
                AddElement(cropContainer);
                SelectElement(cropContainer);
                return(true);
            }
            return(false);
        }
Exemple #16
0
        void SurfaceMouseDown(object sender, MouseEventArgs e)
        {
            mouseStart = MouseHelper.FixMouseCoordinates(e);
            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;
                drawingElement.Status = EditStatus.DRAWING;
                undrawnElement = null;
                // if a new element has been drawn, set location and register it
                if (drawingElement != null) {
                    drawingElement.PropertyChanged += ElementPropertyChanged;
                    if (!drawingElement.HandleMouseDown(mouseStart.X, mouseStart.Y)) {
                        drawingElement.Left = mouseStart.X;
                        drawingElement.Top = mouseStart.Y;
                    }
                    AddElement(drawingElement);
                    drawingElement.Selected = true;
                }
            } 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;
                }
            }
        }
Exemple #17
0
 /// <summary>
 /// Allow the code to be used externally
 /// </summary>
 /// <param name="caller"></param>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <returns></returns>
 public static bool EllipseContains(DrawableContainer caller, int x, int y)
 {
     double xDistanceFromCenter = x - (caller.Left + caller.Width / 2);
     double yDistanceFromCenter = y - (caller.Top + caller.Height / 2);
     // ellipse: x^2/a^2 + y^2/b^2 = 1
     return Math.Pow(xDistanceFromCenter, 2) / Math.Pow(caller.Width / 2, 2) + Math.Pow(yDistanceFromCenter, 2) / Math.Pow(caller.Height / 2, 2) < 1;
 }
 public AddElementMemento(Surface surface, DrawableContainer drawableContainer)
 {
     this.surface = surface;
     this.drawableContainer = drawableContainer;
 }
Exemple #19
0
        private void SurfaceMouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                mX             = e.X;
                mY             = e.Y;
                mouseDown      = true;
                drawingElement = null;

                if (DrawingMode == DrawingModes.Rect) // Draw rectangle
                {
                    drawingElement = new RectangleContainer(this);
                }
                else if (DrawingMode == DrawingModes.Ellipse) // Draw ellipse
                {
                    drawingElement = new EllipseContainer(this);
                }
                else if (DrawingMode == DrawingModes.Line) // Draw line
                {
                    drawingElement = new LineContainer(this);
                }
                else if (DrawingMode == DrawingModes.Text) // Draw textbox
                {
                    drawingElement = new TextContainer(this);
                }

                // 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
                if (DrawingMode == DrawingModes.None)
                {
                    mouseDownElement = elements.ClickableElementAt(e.X, e.Y);
                }
                else
                {
                    mouseDownElement = selectedElements.ClickableElementAt(e.X, e.Y);
                }

                if (mouseDownElement == null)
                {
                    DeselectAllElements();
                }

                // if a new element has been drawn, set location and register it
                if (drawingElement != null)
                {
                    drawingElement.Left          = e.X;
                    drawingElement.Top           = e.Y;
                    drawingElement.Selected      = true;
                    drawingElement.ForeColor     = conf.Editor_ForeColor;
                    drawingElement.BackColor     = conf.Editor_BackColor;
                    drawingElement.GradientColor = conf.Editor_GradientColor;
                    drawingElement.GradientType  = conf.Editor_GradientType;
                    drawingElement.Thickness     = conf.Editor_Thickness;
                    drawingElement.ArrowHeads    = conf.Editor_ArrowHeads;
                    AddElement(drawingElement);
                }
            }
            else if (e.Button == MouseButtons.Right)
            {
                DeselectAllElements();
            }
        }
Exemple #20
0
 public void RemoveElement(DrawableContainer element, bool makeUndoable)
 {
     DeselectElement(element);
     elements.Remove(element);
     element.FieldChanged -= element_FieldChanged;
     element.PropertyChanged -= ElementPropertyChanged;
     // Do not dispose, the memento should!! element.Dispose();
     element.Invalidate();
     if (makeUndoable) {
         MakeUndoable(new DeleteElementMemento(this, element), false);
     }
     modified = true;
 }
        private void SurfaceMouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                mX = e.X;
                mY = e.Y;
                mouseDown = true;
                drawingElement = null;

                if (DrawingMode == DrawingModes.Rect) // Draw rectangle
                {
                    drawingElement = new RectangleContainer(this);
                }
                else if (DrawingMode == DrawingModes.Ellipse) // Draw ellipse
                {
                    drawingElement = new EllipseContainer(this);
                }
                else if (DrawingMode == DrawingModes.Line) // Draw line
                {
                    drawingElement = new LineContainer(this);
                }
                else if (DrawingMode == DrawingModes.Text) // Draw textbox
                {
                    drawingElement = new TextContainer(this);
                }

                // 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
                if (DrawingMode == DrawingModes.None)
                {
                    mouseDownElement = elements.ClickableElementAt(e.X, e.Y);
                }
                else
                {
                    mouseDownElement = selectedElements.ClickableElementAt(e.X, e.Y);
                }

                if (mouseDownElement == null)
                {
                    DeselectAllElements();
                }

                // if a new element has been drawn, set location and register it
                if (drawingElement != null)
                {
                    drawingElement.Left = e.X;
                    drawingElement.Top = e.Y;
                    drawingElement.Selected = true;
                    drawingElement.ForeColor = conf.Editor_ForeColor;
                    drawingElement.BackColor = conf.Editor_BackColor;
                    drawingElement.GradientColor = conf.Editor_GradientColor;
                    drawingElement.GradientType = conf.Editor_GradientType;
                    drawingElement.Thickness = conf.Editor_Thickness;
                    drawingElement.ArrowHeads = conf.Editor_ArrowHeads;
                    AddElement(drawingElement);
                }
            }
            else if (e.Button == MouseButtons.Right)
            {
                DeselectAllElements();
            }
        }
 public void DeselectElement(DrawableContainer element)
 {
     element.HideGrippers();
     element.Selected = false;
     selectedElements.Remove(element);
     MovingElementChanged(this, selectedElements);
 }
        void SurfaceMouseUp(object sender, MouseEventArgs e)
        {
            mouseDown        = false;
            mouseDownElement = null;
            if (DrawingMode == DrawingModes.None) // check whether an existing element was clicked
            {
                DrawableContainer element = elements.ClickableElementAt(e.X, e.Y);
                bool shiftModifier        = (Control.ModifierKeys & Keys.Shift) == Keys.Shift;
                if (element != null)
                {
                    bool alreadySelected = selectedElements.Contains(element);
                    if (shiftModifier)
                    {
                        if (alreadySelected)
                        {
                            DeselectElement(element);
                        }
                        else
                        {
                            SelectElement(element);
                        }
                    }
                    else
                    {
                        if (!alreadySelected)
                        {
                            DeselectAllElements();
                            SelectElement(element);
                        }
                    }
                }
                else if (!shiftModifier)
                {
                    DeselectAllElements();
                }
            }

            if (selectedElements.Count > 0)
            {
                selectedElements.ShowGrippers();
                selectedElements.Selected = true;
            }
            if (drawingElement != null)
            {
                if (!drawingElement.InitContent())
                {
                    elements.Remove(drawingElement);
                    Invalidate();
                }
                else
                {
                    if (Math.Abs(drawingElement.Width) < 5 && Math.Abs(drawingElement.Height) < 5)
                    {
                        drawingElement.Width  = 25;
                        drawingElement.Height = 25;
                    }
                    SelectElement(drawingElement);
                    drawingElement.Selected = true;
                }
                drawingElement = null;
            }
            Invalidate();
        }
Exemple #24
0
 /// <summary>
 /// Wrapper for makeUndoable flag which was introduced later, will call AddElement with makeundoable set to true
 /// </summary>
 /// <param name="element">the new element</param>
 public void AddElement(DrawableContainer element)
 {
     AddElement(element, true);
 }
 public void AddElement(DrawableContainer element)
 {
     elements.Add(element);
     Invalidate();
 }
 private void CreateUndrawnElement()
 {
     if(undrawnElement != null) {
         FieldAggregator.UnbindElement(undrawnElement);
     }
     switch (DrawingMode) {
         case DrawingModes.Rect:
             undrawnElement = new RectangleContainer(this);
             break;
         case DrawingModes.Ellipse:
             undrawnElement = new EllipseContainer(this);
             break;
         case DrawingModes.Text:
             undrawnElement = new TextContainer(this);
             break;
         case DrawingModes.Line:
             undrawnElement = new LineContainer(this);
             break;
         case DrawingModes.Arrow:
             undrawnElement = new ArrowContainer(this);
             break;
         case DrawingModes.Highlight:
             undrawnElement = new HighlightContainer(this);
             break;
         case DrawingModes.Obfuscate:
             undrawnElement = new ObfuscateContainer(this);
             break;
         case DrawingModes.Crop:
             cropContainer = new CropContainer(this);
             undrawnElement = cropContainer;
             break;
         case DrawingModes.Bitmap:
             undrawnElement = new BitmapContainer(this);
             break;
         case DrawingModes.Path:
             undrawnElement = new FreehandContainer(this);
             break;
         case DrawingModes.None:
             undrawnElement = null;
             break;
     }
     if (undrawnElement != null) {
         FieldAggregator.BindElement(undrawnElement);
     }
 }
        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
                    DrawableContainer rightClickedContainer = elements.ClickableElementAt(mouseStart.X, mouseStart.Y);
                    if (rightClickedContainer != null) {
                        selectedList = new DrawableContainerList();
                        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;
                drawingElement.Status = EditStatus.DRAWING;
                undrawnElement = null;
                // if a new element has been drawn, set location and register it
                if (drawingElement != null) {
                    drawingElement.PropertyChanged += ElementPropertyChanged;
                    if (!drawingElement.HandleMouseDown(mouseStart.X, mouseStart.Y)) {
                        drawingElement.Left = mouseStart.X;
                        drawingElement.Top = mouseStart.Y;
                    }
                    AddElement(drawingElement);
                    drawingElement.Selected = true;
                }
            } 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;
                }
            }
        }
 /// <summary>
 /// Wrapper for makeUndoable flag which was introduced later, will call AddElement with makeundoable set to true
 /// </summary>
 /// <param name="element">the new element</param>
 public void AddElement(DrawableContainer element)
 {
     AddElement(element, true);
 }
 public void AddElement(DrawableContainer element)
 {
     elements.Add(element);
     Invalidate();
 }
 /// <summary>
 /// Add a new element to the surface
 /// </summary>
 /// <param name="element">the new element</param>
 /// <param name="makeUndoable">true if the adding should be undoable</param>
 public void AddElement(DrawableContainer element, bool makeUndoable)
 {
     elements.Add(element);
     element.FieldChanged += element_FieldChanged;
     element.PropertyChanged += ElementPropertyChanged;
     if(element.Status == EditStatus.UNDRAWN) {
         element.Status = EditStatus.IDLE;
     }
     element.Invalidate();
     if (makeUndoable) {
         MakeUndoable(new AddElementMemento(this, element), false);
     }
     modified = true;
 }
 public void SelectElement(DrawableContainer element)
 {
     if (selectedElements.Contains(element)) return;
     selectedElements.Add(element);
     element.ShowGrippers();
     element.Selected = true;
     MovingElementChanged(this, selectedElements);
     Invalidate();
 }
 /// <summary>
 /// Auto crop the image
 /// </summary>
 /// <returns>true if cropped</returns>
 public bool AutoCrop()
 {
     Rectangle cropRectangle = ImageHelper.FindAutoCropRectangle(Image, conf.AutoCropDifference);
     if (isCropPossible(ref cropRectangle)) {
         DrawingMode = DrawingModes.Crop;
         cropContainer = new CropContainer(this);
         cropContainer.Left = cropRectangle.X;
         cropContainer.Top = cropRectangle.Y;
         cropContainer.Width = cropRectangle.Width;
         cropContainer.Height = cropRectangle.Height;
         DeselectAllElements();
         AddElement(cropContainer);
         SelectElement(cropContainer);
         return true;
     }
     return false;
 }
        private void SurfaceMouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (DrawingMode == DrawingModes.None)
                { // check whether an existing element was clicked
                    DrawableContainer element = elements.ClickableElementAt(e.X, e.Y);
                    bool shiftModifier = (Control.ModifierKeys & Keys.Shift) == Keys.Shift;
                    if (element != null)
                    {
                        bool alreadySelected = selectedElements.Contains(element);
                        if (shiftModifier)
                        {
                            if (alreadySelected) DeselectElement(element);
                            else SelectElement(element);
                        }
                        else
                        {
                            if (!alreadySelected)
                            {
                                DeselectAllElements();
                                SelectElement(element);
                            }
                        }
                    }
                    else if (!shiftModifier)
                    {
                        DeselectAllElements();
                    }
                }

                if (selectedElements.Count > 0)
                {
                    selectedElements.ShowGrippers();
                    selectedElements.Selected = true;
                }

                if (drawingElement != null && mouseDownElement == null)
                {
                    if (!drawingElement.InitContent())
                    {
                        elements.Remove(drawingElement);
                        Invalidate();
                    }
                    else
                    {
                        if (Math.Abs(drawingElement.Width) < 5 && Math.Abs(drawingElement.Height) < 5)
                        {
                            drawingElement.Width = 25;
                            drawingElement.Height = 25;
                        }
                        SelectElement(drawingElement);
                        drawingElement.Selected = true;
                    }
                    drawingElement = null;
                }

                mouseDown = false;
                mouseDownElement = null;

                Invalidate();
            }
        }
Exemple #34
0
        void SurfaceMouseUp(object sender, MouseEventArgs e)
        {
            Point currentMouse = MouseHelper.FixMouseCoordinates(e);

            elements.Status = EditStatus.IDLE;
            if (mouseDownElement != null) {
                mouseDownElement.Status = EditStatus.IDLE;
            }
            mouseDown = false;
            mouseDownElement = null;
            if (DrawingMode == DrawingModes.None) {
                // check whether an existing element was clicked
                DrawableContainer element = elements.ClickableElementAt(currentMouse.X, currentMouse.Y);
                bool shiftModifier = (Control.ModifierKeys & Keys.Shift) == Keys.Shift;
                if (element != null) {
                    element.Invalidate();
                    bool alreadySelected = selectedElements.Contains(element);
                    if (shiftModifier) {
                        if (alreadySelected) {
                            DeselectElement(element);
                        } else {
                            SelectElement(element);
                        }
                    } else {
                        if (!alreadySelected) {
                            DeselectAllElements();
                            SelectElement(element);
                        }
                    }
                } else if(!shiftModifier) {
                    DeselectAllElements();
                }
            }

            if (selectedElements.Count > 0) {
                selectedElements.ShowGrippers();
                selectedElements.Selected = true;
            }

            if (drawingElement != null) {
                if (!drawingElement.InitContent()) {
                    elements.Remove(drawingElement);
                    drawingElement.Invalidate();
                } else {
                    drawingElement.HandleMouseUp(currentMouse.X, currentMouse.Y);
                    drawingElement.Invalidate();
                    if (Math.Abs(drawingElement.Width) < 5 && Math.Abs(drawingElement.Height) < 5) {
                        drawingElement.Width = 25;
                        drawingElement.Height = 25;
                    }
                    SelectElement(drawingElement);
                    drawingElement.Selected = true;
                }
                drawingElement = null;
            }
        }