Beispiel #1
0
        private void Capture_MouseMove(object sender, MouseEventArgs e)
        {
            if (isClicking)
            {
                if (state == SelectionEditState.DrawingRectFrame)
                {
                    RectFrame frame = rectFrameList[rectFrameList.Count - 1];
                    if (e.X < Math.Min(x1, x2))
                    {
                        frame.x2 = Math.Min(x1, x2);
                    }
                    else if (e.X > Math.Max(x1, x2))
                    {
                        frame.x2 = Math.Max(x1, x2);
                    }
                    else
                    {
                        frame.x2 = e.X;
                    }

                    if (e.Y < Math.Min(y1, y2))
                    {
                        frame.y2 = Math.Min(y1, y2);
                    }
                    else if (e.Y > Math.Max(y1, y2))
                    {
                        frame.y2 = Math.Max(y1, y2);
                    }
                    else
                    {
                        frame.y2 = e.Y;
                    }
                    rectFrameList[rectFrameList.Count - 1] = frame;
                }
                else if (currentCP == ControlPoints.None)   // first/re select

                /*x2 += e.X - old_x;
                 * y2 += e.Y - old_y;
                 * old_x = e.X;
                 * old_y = e.Y;*/
                {
                    x2 = e.X;
                    y2 = e.Y;
                }
                else   // modifying selection
                {
                    if (currentCP == ControlPoints.LeftTop ||
                        currentCP == ControlPoints.LeftBottom ||
                        currentCP == ControlPoints.RightTop ||
                        currentCP == ControlPoints.RightBottom)
                    {
                        x2 = e.X;
                        y2 = e.Y;
                    }

                    else if (currentCP == ControlPoints.Left ||
                             currentCP == ControlPoints.Right)
                    {
                        x2 = e.X;
                    }
                    else if (currentCP == ControlPoints.Top ||
                             currentCP == ControlPoints.Bottom)
                    {
                        y2 = e.Y;
                    }
                    else if (currentCP == ControlPoints.Inside)
                    {
                        int dx, dy, minX, minY, maxX, maxY;
                        dx   = e.X - old_x;
                        dy   = e.Y - old_y;
                        minX = Math.Min(x1, x2);
                        minY = Math.Min(y1, y2);
                        maxX = Math.Max(x1, x2);
                        maxY = Math.Max(y1, y2);

                        if (minX + dx < 0)
                        {
                            dx = -minX;
                        }
                        else if (maxX + dx >= screenShot.Width)
                        {
                            dx = screenShot.Width - maxX - 1;
                        }

                        if (minY + dy < 0)
                        {
                            dy = -minY;
                        }
                        else if (maxY + dy >= screenShot.Height)
                        {
                            dy = screenShot.Height - maxY - 1;
                        }

                        x1   += dx;
                        y1   += dy;
                        x2   += dx;
                        y2   += dy;
                        old_x = e.X;
                        old_y = e.Y;
                    }
                }
                this.Refresh();
            }
            else   // mouse left button not clicking


            //check if mouse clicked on control points
            {
                if (state == SelectionEditState.Selected)   // not possible to clicked on CP if no selections yet
                {
                    currentCP = getControlPoint(e.X, e.Y);
                }
            }



            //this.Refresh();
        }
Beispiel #2
0
        private void Capture_MouseDown(object sender, MouseEventArgs e)
        {
            int tx1, ty1, tx2, ty2; // tmp x, y

            if (e.Button == MouseButtons.Left)
            {
                isClicking = true;

                if (state == SelectionEditState.DrawingRectFrame)   // is drawing rect frame
                {
                    if (e.X < Math.Min(x1, x2) || e.X > Math.Max(x1, x2) || e.Y < Math.Min(y1, y2) || e.Y > Math.Max(y1, y2))
                    {
                        // start position out of range, cancel current clicking
                        isClicking = false;
                        return;
                    }
                    RectFrame frame = new RectFrame();
                    frame.x1 = e.X;
                    frame.y1 = e.Y;
                    rectFrameList.Add(frame);
                }
                else   // selection

                {
                    switch (currentCP)
                    {
                    case ControlPoints.None:     // first/re select
                        state = SelectionEditState.Selecting;
                        rectFrameList.Clear();
                        x1 = x2 = old_x = e.X;
                        y1 = y2 = old_y = e.Y;
                        break;

                    case ControlPoints.Top:
                    case ControlPoints.Left:
                    case ControlPoints.LeftTop:     // modifying selection
                        tx2 = Math.Min(x1, x2);
                        ty2 = Math.Min(y1, y2);
                        tx1 = Math.Max(x1, x2);
                        ty1 = Math.Max(y1, y2);
                        x1  = tx1;
                        y1  = ty1;
                        x2  = tx2;
                        y2  = ty2;
                        break;

                    case ControlPoints.Bottom:
                    case ControlPoints.Right:
                    case ControlPoints.RightBottom:
                        tx2 = Math.Max(x1, x2);
                        ty2 = Math.Max(y1, y2);
                        tx1 = Math.Min(x1, x2);
                        ty1 = Math.Min(y1, y2);
                        x1  = tx1;
                        y1  = ty1;
                        x2  = tx2;
                        y2  = ty2;
                        break;

                    case ControlPoints.LeftBottom:
                        tx2 = Math.Min(x1, x2);
                        ty2 = Math.Max(y1, y2);
                        tx1 = Math.Max(x1, x2);
                        ty1 = Math.Min(y1, y2);
                        x1  = tx1;
                        y1  = ty1;
                        x2  = tx2;
                        y2  = ty2;
                        break;

                    case ControlPoints.RightTop:
                        tx2 = Math.Max(x1, x2);
                        ty2 = Math.Min(y1, y2);
                        tx1 = Math.Min(x1, x2);
                        ty1 = Math.Max(y1, y2);
                        x1  = tx1;
                        y1  = ty1;
                        x2  = tx2;
                        y2  = ty2;
                        break;

                    case ControlPoints.Inside:
                        old_x = e.X;
                        old_y = e.Y;
                        break;
                    }
                }
            }
            else if (e.Button == MouseButtons.Right)
            {
                if (state == SelectionEditState.NoSelection)
                {
                    abortClip();
                    return;
                }

                commitClip();
            }
        }