Пример #1
0
        // Finish drawing/dragging
        private void pbxDisplay_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right) // Right click
            {
                // Summon a context menu
                SelectedRect = GetPhraseAtPoint(e.Location); // Find all selected phrases
                if (PhraseRects.FindAll(x => x.Selected == true).Count() < 1)
                {
                    return;                    // Don't display menu if nothing's selected
                }
                ctxPhrase.Show(MousePosition); // Display menu
            }
            else                               // Left click
            {
                if (Marking == true)           // We were drawing a bounding box
                {
                    // Create a phrase box
                    Rectangle TestRect = MouseStart.RectTo(MouseEnd);
                    if (TestRect.Width > 25 && TestRect.Height > 15)
                    {
                        ChangeState(State.translated);
                        PhraseRect NewPRect = new PhraseRect(TestRect, OCRResult, this, AsyncTranslation_callback);
                        PhraseRects.Add(NewPRect);
                    }
                    Marking = false;
                }
                else
                { // We were selecting/dragging
                    PhraseRect PRect = GetPhraseAtPoint(e.Location);
                    if (PRect != null)
                    {
                        PhraseRects.FindAll(x => x.Selected == true).ForEach(x => x.UpdateText(OCRResult, AsyncTranslation_callback));
                    }

                    PhraseRects.ForEach(x => x.Clicked = false);
                }

                if (!Dragging && !StartingDrag)
                {
                    // If the user wasn't holding shift, clear all other selections
                    if (!WindowFunctions.IsPressed((int)WindowFunctions.VirtualKeyStates.VK_LSHIFT))
                    {
                        PhraseRects.ForEach(x => { x.Clicked = false; x.Selected = false; });
                    }
                }
            }

            Dragging     = false;
            StartingDrag = false;
            pbxDisplay.Invalidate();
        }
Пример #2
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();
            }
        }
Пример #3
0
        private void horizontallyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int LeftEdge  = PhraseRects.FindAll(x => x.Selected == true).Min(x => x.Location.X);
            int RightEdge = PhraseRects.FindAll(x => x.Selected == true).Max(x => x.Location.X + x.Location.Width);
            int Width     = RightEdge - LeftEdge;
            IOrderedEnumerable <PhraseRect> PRects = PhraseRects.FindAll(x => x.Selected == true)
                                                     .OrderBy(x => x.Location.X);

            int Spacing = Width / PRects.Count();

            for (int x = 1; x < PRects.Count() - 1; x++)
            {
                PhraseRect TRect = PRects.ElementAt(x);
                TRect.Location.X = LeftEdge + (Spacing * (x));
            }
        }
Пример #4
0
        private void verticallyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int TopEdge    = PhraseRects.FindAll(x => x.Selected == true).Min(x => x.Location.Y);
            int BottomEdge = PhraseRects.FindAll(x => x.Selected == true).Max(x => x.Location.Y + x.Location.Height);
            int Height     = BottomEdge - TopEdge;
            IOrderedEnumerable <PhraseRect> PRects = PhraseRects.FindAll(x => x.Selected == true)
                                                     .OrderBy(x => x.Location.Y);

            int Spacing = Height / PRects.Count();

            for (int x = 1; x < PRects.Count() - 1; x++)
            {
                PhraseRect TRect = PRects.ElementAt(x);
                TRect.Location.Y = TopEdge + (Spacing * (x)) + (TRect.Location.Height / 2);
            }
        }
Пример #5
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();
        }