private void imageGrid_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            System.Windows.Point point = e.GetPosition(imageGrid);

            m_mouseVLine.X1         = point.X;
            m_mouseVLine.Y1         = 0;
            m_mouseVLine.X2         = point.X;
            m_mouseVLine.Y2         = image.ActualHeight;
            m_mouseVLine.Visibility = Visibility.Visible;
            m_mouseHLine.X1         = 0;
            m_mouseHLine.Y1         = point.Y;
            m_mouseHLine.X2         = image.ActualWidth;
            m_mouseHLine.Y2         = point.Y;
            m_mouseHLine.Visibility = Visibility.Visible;
            if (m_currentBox != null && m_currentBox.IsValid())
            {
                if (m_currentLocalCS == null)
                {
                    m_currentLocalCS = new LocalCS(m_currentBox, (float)image.ActualWidth, (float)image.ActualHeight);
                }
                else
                {
                    m_currentLocalCS.Reset(m_currentBox, (float)image.ActualWidth, (float)image.ActualHeight);
                }
                m_mouseTxt.Text = "(" + Util.ToString(m_currentLocalCS.InverseConvertX(point.X))
                                  + " " + Util.ToString(m_currentLocalCS.InverseConvertY(point.Y))
                                  + ")";
                Canvas.SetLeft(m_mouseTxt, point.X + 2);
                Canvas.SetTop(m_mouseTxt, point.Y + 2);
                m_mouseTxt.Visibility = Visibility.Visible;
            }
            else
            {
                m_mouseTxt.Visibility = Visibility.Hidden;
            }

            if (m_mouseDown)
            {
                if (m_pointDown[0] != point.X || m_pointDown[1] != point.Y)
                {
                    double ox = m_pointDown[0];
                    double oy = m_pointDown[1];
                    double x  = Math.Min(Math.Max(point.X, 0), image.ActualWidth);
                    double y  = Math.Min(Math.Max(point.Y, 0), image.ActualHeight);
                    double w  = Math.Abs(x - ox);
                    double h  = Math.Abs(y - oy);

                    double prop  = h / w;
                    double iProp = image.ActualHeight / image.ActualWidth;
                    if (prop < iProp)
                    {
                        h = iProp * w;
                    }
                    else if (prop > iProp)
                    {
                        w = h / iProp;
                    }

                    double l = ox;
                    double t = oy;

                    if (ox <= x)
                    {
                        if (ox + w > image.ActualWidth)
                        {
                            w = image.ActualWidth - ox;
                            h = iProp * w;
                        }
                    }
                    else
                    {
                        if (ox - w < 0)
                        {
                            w = ox;
                            h = iProp * w;
                        }
                        l = ox - w;
                    }

                    if (oy <= y)
                    {
                        if (oy + h > image.ActualHeight)
                        {
                            h = image.ActualHeight - oy;
                            w = h / iProp;
                        }
                    }
                    else
                    {
                        if (oy - h < 0)
                        {
                            h = oy;
                            w = h / iProp;
                        }
                        t = oy - h;
                    }

                    if (w > 0 && h > 0)
                    {
                        Canvas.SetLeft(m_selectionRect, l);
                        Canvas.SetTop(m_selectionRect, t);
                        m_selectionRect.Width  = w;
                        m_selectionRect.Height = h;

                        m_selectionRect.Visibility = Visibility.Visible;
                    }
                }
            }
        }
Esempio n. 2
0
        private void imageGrid_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            System.Windows.Point point = e.GetPosition(imageGrid);

            m_mouseVLine.X1         = point.X;
            m_mouseVLine.Y1         = 0;
            m_mouseVLine.X2         = point.X;
            m_mouseVLine.Y2         = image.ActualHeight;
            m_mouseVLine.Visibility = Visibility.Visible;
            m_mouseHLine.X1         = 0;
            m_mouseHLine.Y1         = point.Y;
            m_mouseHLine.X2         = image.ActualWidth;
            m_mouseHLine.Y2         = point.Y;
            m_mouseHLine.Visibility = Visibility.Visible;
            if (m_currentBox != null && m_currentBox.IsValid())
            {
                // TODO: pass correct fill parameter later when point plot is implemented
                bool fill = true;
                if (m_currentLocalCS == null)
                {
                    m_currentLocalCS = new LocalCS(m_currentBox, (float)image.ActualWidth, (float)image.ActualHeight, fill);
                }
                else
                {
                    m_currentLocalCS.Reset(m_currentBox, (float)image.ActualWidth, (float)image.ActualHeight, fill);
                }
                m_mouseTxt.Text = "(" + Util.ToString(m_currentLocalCS.InverseConvertX(point.X))
                                  + " " + Util.ToString(m_currentLocalCS.InverseConvertY(point.Y))
                                  + ")";
                Canvas.SetLeft(m_mouseTxt, point.X + 2);
                Canvas.SetTop(m_mouseTxt, point.Y + 2);
                m_mouseTxt.Visibility = Visibility.Visible;
            }
            else
            {
                m_mouseTxt.Visibility = Visibility.Hidden;
            }

            if (m_mouseDown)
            {
                if (m_pointDown[0] != point.X || m_pointDown[1] != point.Y)
                {
                    double originx = m_pointDown[0];
                    double originy = m_pointDown[1];
                    double x       = Math.Min(Math.Max(point.X, 0), image.ActualWidth);
                    double y       = Math.Min(Math.Max(point.Y, 0), image.ActualHeight);
                    double width   = Math.Abs(x - originx);
                    double height  = Math.Abs(y - originy);

                    if (originx > x)
                    {
                        originx -= width;
                    }
                    if (originy > y)
                    {
                        originy -= height;
                    }

                    Canvas.SetLeft(m_selectionRect, originx);
                    m_selectionRect.Width = width;
                    Canvas.SetTop(m_selectionRect, originy);
                    m_selectionRect.Height = height;

                    m_selectionRect.Visibility = Visibility.Visible;
                }
            }
        }