コード例 #1
0
ファイル: Surface.cs プロジェクト: SupremeGenius/espUrl
        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;
                }
            }
        }
コード例 #2
0
ファイル: Surface.cs プロジェクト: SupremeGenius/espUrl
        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;
                }
            }
        }
コード例 #3
0
        private void gripperMouseMove(object sender, MouseEventArgs e)
        {
            Point mouseLocation = MouseHelper.FixMouseCoordinates(e);

            if (Status.Equals(EditStatus.RESIZING))
            {
                // check if we already made this undoable
                if (!isMadeUndoable)
                {
                    // don't allow another undo until we are finished with this move
                    isMadeUndoable = true;
                    // Make undo-able
                    MakeBoundsChangeUndoable(false);
                }
                Invalidate();
                SuspendLayout();
                Label gr           = (Label)sender;
                int   gripperIndex = Int16.Parse(gr.Name.Substring(7));
                if (gripperIndex <= 2)                   // top row
                {
                    this.Top    += mouseLocation.Y - my;
                    this.Height -= mouseLocation.Y - my;
                }
                else if (gripperIndex >= 4 && gripperIndex <= 6)                     // bottom row
                {
                    this.Height += mouseLocation.Y - my;
                }
                if (gripperIndex >= 2 && gripperIndex <= 4)                  // right row
                {
                    this.Width += mouseLocation.X - mx;
                }
                else if (gripperIndex >= 6 || gripperIndex == 0)                    // left row
                {
                    this.Left  += mouseLocation.X - mx;
                    this.Width -= mouseLocation.X - mx;
                }
                ResumeLayout();
                Invalidate();
            }
        }
コード例 #4
0
ファイル: Surface.cs プロジェクト: SupremeGenius/espUrl
        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;
            }
        }