Ejemplo n.º 1
0
        public void showSelectForm(ref Bitmap b, IntPtr fg_hWnd, IWin32Window owner)
        {
            x1         = -1;
            isClicking = false;
            currentCP  = ControlPoints.None;
            rectFrameList.Clear();
            state = SelectionEditState.NoSelection;

            screenShot = b;
            old_hWnd   = fg_hWnd;
            this.Show(owner);
        }
Ejemplo n.º 2
0
        private void Capture_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                abortClip();
                return;
            }

            if (e.KeyCode == rectFrameKey)
            {
                if (state == SelectionEditState.NoSelection)
                {
                    return;
                }
                if (isClicking)
                {
                    return;
                }

                if (state == SelectionEditState.DrawingRectFrame)   // already in drawing rect frame mode
                {
                    state = SelectionEditState.Selected;
                }
                else
                {
                    state = SelectionEditState.DrawingRectFrame;
                }

                this.Cursor = Cursors.Cross;
                this.Refresh();
                return;
            }

            if (e.Control && e.KeyCode == Keys.Z)
            {
                if (isClicking)
                {
                    return;
                }
                if (rectFrameList.Count == 0)
                {
                    return;
                }
                rectFrameList.RemoveAt(rectFrameList.Count - 1);
                this.Refresh();
            }
        }
Ejemplo n.º 3
0
        private void Capture_MouseUp(object sender, MouseEventArgs e)
        {
            isClicking = false;

            if (state == SelectionEditState.Selecting)
            {
                if (x1 == x2 || y1 == y2)
                {
                    // x1 = -1;
                    state = SelectionEditState.NoSelection;
                    this.Refresh();
                }
                else
                {
                    state = SelectionEditState.Selected;
                }
            }

            //x1 = x2 = y1 = y2 = -1;
            //x1 = -1;
        }
Ejemplo n.º 4
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();
            }
        }