Exemple #1
0
        private void pbxDisplay_MouseMove(object sender, MouseEventArgs e)
        {
            if (StartingDrag == true)
            {
                Dragging = true;
            }

            if (Marking) // We're drawing a bounding box, set the second endpoint
            {
                MouseEnd = e.Location;

                // Draw the phrase box
                Rectangle TestRec = MouseStart.RectTo(MouseEnd);
                if (TestRec.Width < 25 || TestRec.Height < 15) // If it's too small, draw it red
                {
                    BoundingBoxState = BoundingState.TooSmall;
                }
                else if (CheckForText(TestRec))
                {
                    // TODO: This needs to be extended to understand the intersect vs bounding modes
                    BoundingBoxState = BoundingState.RectsFound; // If it's over any text, draw it green
                }
                else
                {
                    BoundingBoxState = BoundingState.Normal; // Otherwise draw it white
                }

                pbxDisplay.Invalidate();
            }
            else if (Dragging)     // We're dragging, move the selected bounding box
            {
                int diffX = MouseStart.X - e.X;
                int diffY = MouseStart.Y - e.Y;
                PhraseRects.FindAll(x => x.Selected).ForEach(x => { x.Location.X -= diffX; x.Location.Y -= diffY; });
                MouseStart = e.Location;
                pbxDisplay.Invalidate();
            }
            else     // Just highlight whatever box the mouse is over
            {
                foreach (PhraseRect TPRect in PhraseRects)
                {
                    TPRect.Hovered = false;
                }                                                // Clear all phrase hover states
                PhraseRect PRect = GetPhraseAtPoint(e.Location); // Check if we're over a phrase
                if (PRect != null)
                {
                    PRect.Hovered = true; // Mark it as hovered
                }
                pbxDisplay.Invalidate();
            }
        }
Exemple #2
0
        //======= Mouse events


        // Begin drawing or dragging bounding box
        private void pbxDisplay_MouseDown(object sender, MouseEventArgs e)
        {
            PhraseRect PRect = GetPhraseAtPoint(e.Location);

            if (e.Button == MouseButtons.Right)
            {
                if (PRect != null)
                {
                    PRect.Selected = true;
                }

                return;
            }

            // Don't permit any mouse actions unless OCR is complete
            // This is a crowbar and we may need a better solution when we implement retained phrases between snaps
            if (OCRResult == null || !OCRResult.isDone)
            {
                return;
            }

            if (PRect != null && !CtrlDown)
            {
                // There was a phrase under the mouse
                // Select it, then set up for a drag if desired

                if (PRect.Selected != true) // If the box wasn't already selected
                {
                    // If the user wasn't holding shift, clear all other selections
                    if (!WindowFunctions.IsPressed((int)WindowFunctions.VirtualKeyStates.VK_LSHIFT))
                    {
                        foreach (PhraseRect TPRect in PhraseRects)
                        {
                            TPRect.Clicked = false; TPRect.Selected = false;
                        }

                        // And begin a drag process on that one item
                        if (e.Button == MouseButtons.Left)
                        {
                            MouseStart   = e.Location;
                            StartingDrag = true;
                        }
                        PRect.Clicked = true;
                    }
                    PRect.Selected = true;
                }
                else   // If the box was already selected
                {
                    if (WindowFunctions.IsPressed((int)WindowFunctions.VirtualKeyStates.VK_LSHIFT))
                    {
                        // If the user is holding shift, deselect the current box and do nothing else.
                        PRect.Selected = false;
                    }
                    else
                    {
                        // If not, then start a drag, which may be multi-drag.
                        PRect.Clicked = true;
                        if (e.Button == MouseButtons.Left)
                        {
                            MouseStart   = e.Location;
                            StartingDrag = true;
                        }
                    }
                }

                // Pop the clicked phrase to the top (technically the bottom) of the stack
                PhraseRects.Remove(PRect);
                PhraseRects.Add(PRect);
            }
            else // There was no phrase under the mouse, start a bounding box
            {
                if (e.Button == MouseButtons.Left)
                {
                    MouseStart       = e.Location;
                    MouseEnd         = e.Location;
                    Marking          = true;
                    BoundingBoxState = BoundingState.TooSmall;
                }
            }
            pbxDisplay.Invalidate();
        }