Пример #1
0
            // The DrawPixel method updates the WriteableBitmap by using
            // unsafe code to write a pixel into the back buffer.
            static void DrawPixel(MouseEventArgs e)
            {
                int column = (int)e.GetPosition(i).X;
                int row = (int)e.GetPosition(i).Y;

                // Reserve the back buffer for updates.
                writeableBitmap.Lock();

                unsafe
                {
                    // Get a pointer to the back buffer.
                    int pBackBuffer = (int)writeableBitmap.BackBuffer;

                    // Find the address of the pixel to draw.
                    pBackBuffer += row * writeableBitmap.BackBufferStride;
                    pBackBuffer += column * 4;

                    // Compute the pixel's color.
                    int color_data = 255 << 16; // R
                    color_data |= 128 << 8;   // G
                    color_data |= 255 << 0;   // B

                    // Assign the color data to the pixel.
                    *((int*)pBackBuffer) = color_data;
                }

                // Specify the area of the bitmap that changed.
                writeableBitmap.AddDirtyRect(new Int32Rect(column, row, 1, 1));

                // Release the back buffer and make it available for display.
                writeableBitmap.Unlock();
            }
Пример #2
0
        /// <summary> Tests if the cursor position has changed. If so, stores the new position and triggers the tool tip timer. </summary>
        /// <param name="map">Map object needed for position.</param>
        /// <param name="mouseEventArgs">Mouse event arguments, a null value represents an invalid position.</param>
        private void StartToolTipTimer(Map map, MouseEventArgs mouseEventArgs = null)
        {
            if (!IsEnabled)
            {
                return;
            }

            // test if position has changed
            var currentPosition = mouseEventArgs?.GetPosition(map);

            if (LatestPosition.HasValue == currentPosition.HasValue && (!currentPosition.HasValue || (LatestPosition.Value - currentPosition.Value).Length <= 1e-4))
            {
                return;
            }

            ClearToolTip();

            // trigger update, if not any mouse button is pressed
            if (Mouse.LeftButton != MouseButtonState.Released || Mouse.MiddleButton != MouseButtonState.Released || Mouse.RightButton != MouseButtonState.Released)
            {
                return;
            }

            LatestPosition = currentPosition;

            toolTipTimer.Stop();

            // flag indicating if a tool tip is to be shown. Initially, specified position must be valid.
            bool showToolTips = currentPosition.HasValue && ToolTipDelay >= 0 && IsHitTestOKFunc((Point)currentPosition);

            if (!showToolTips)
            {
                return;
            }

            GetToolTipMapObjects();
            if (toolTipMapObjects.Count <= 0)
            {
                return;
            }

            toolTipTimer.Interval = TimeSpan.FromMilliseconds(ToolTipDelay);
            toolTipTimer.Start();
        }
Пример #3
0
        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            Point point = e.GetPosition(this);

            if (point.X > button1.Margin.Left - button1.Width / 2 && point.X < button1.Margin.Left + button1.Width / 2 && point.Y > button1.Margin.Top - button1.Height / 2 && point.Y < button1.Margin.Top + button1.Height / 2)
            {
                tmp_location       = button1.Margin;
                tmp_location.Left += 10;
                tmp_location.Top  += 10;
                button1.Margin     = new Thickness(tmp_location.Left, tmp_location.Top, 0, 0);
                tmp_width          = button1.Width;
                tmp_height         = button1.Height;
                tmp_width         -= 1;
                tmp_height        -= 1;
                button1.Width      = tmp_width;
                button1.Height     = tmp_height;
            }
            if (point.X > button1.Margin.Left + button1.Width / 2 && point.X < button1.Margin.Left + button1.Width * 1.5 && point.Y > button1.Margin.Top - button1.Height / 2 && point.Y < button1.Margin.Top + button1.Height / 2)
            {
                tmp_location       = button1.Margin;
                tmp_location.Left -= 10;
                tmp_location.Top  += 10;
                button1.Margin     = new Thickness(tmp_location.Left, tmp_location.Top, 0, 0);
                tmp_width          = button1.Width;
                tmp_height         = button1.Height;
                tmp_width         -= 1;
                tmp_height        -= 1;
                button1.Width      = tmp_width;
                button1.Height     = tmp_height;
            }
            if (point.X > button1.Margin.Left - button1.Width / 2 && point.X < button1.Margin.Left + button1.Width / 2 && point.Y > button1.Margin.Top + button1.Height / 2 && point.Y < button1.Margin.Top + button1.Height * 1.5)
            {
                tmp_location       = button1.Margin;
                tmp_location.Left += 10;
                tmp_location.Top  -= 10;
                button1.Margin     = new Thickness(tmp_location.Left, tmp_location.Top, 0, 0);
                tmp_width          = button1.Width;
                tmp_height         = button1.Height;
                tmp_width         -= 1;
                tmp_height        -= 1;
                button1.Width      = tmp_width;
                button1.Height     = tmp_height;
            }
            if (point.X > button1.Margin.Left + button1.Width / 2 && point.X < button1.Margin.Left + button1.Width * 1.5 && point.Y > button1.Margin.Top + button1.Height / 2 && point.Y < button1.Margin.Top + button1.Height * 1.5)
            {
                tmp_location       = button1.Margin;
                tmp_location.Left -= 10;
                tmp_location.Top  -= 10;
                button1.Margin     = new Thickness(tmp_location.Left, tmp_location.Top, 0, 0);
                tmp_width          = button1.Width;
                tmp_height         = button1.Height;
                tmp_width         -= 1;
                tmp_height        -= 1;
                button1.Width      = tmp_width;
                button1.Height     = tmp_height;
            }
            if (tmp_height == 0 || tmp_width == 0)
            {
                MessageBox.Show("OK button cannot be pressed");
            }
        }
Пример #4
0
 private void Window_MouseMove(object sender, MouseEventArgs e)
 {
     mousePos = new Vector2D(e.GetPosition(this));
 }
Пример #5
0
        private void cvMap_MouseMove(object sender, MouseEventArgs e)
        {
            int X, Y;        // tọa độ của chuột

            if (isAutoAlign) // tự đọng căn, vẽ tọa độ tương đối
            {
                X = (int)(e.GetPosition(this.cvMap).X / MainWindow.OBJECT_WIDTH) * MainWindow.OBJECT_WIDTH;
                Y = (int)(e.GetPosition(this.cvMap).Y / MainWindow.OBJECT_HEIGHT) * MainWindow.OBJECT_HEIGHT;
            }
            else // vẽ bằng tay, tọa độ tuyệt đối
            {
                X = (int)e.GetPosition(this.cvMap).X;
                Y = (int)e.GetPosition(this.cvMap).Y;
            }

            if (selectedImage == null)
            {
                this.tbX.Text = X.ToString();
                this.tbY.Text = (this._origin - Y).ToString();
            }
            else
            {
                this.tbX.Text = ((int)Canvas.GetLeft(selectedImage)).ToString();
                this.tbY.Text = ((int)(this._origin - Canvas.GetTop(selectedImage))).ToString();
            }

            // remove line căn nếu đã add
            if (this.cvMap.Children.Count > 0)
            {
                List <UIElement> lines = new List <UIElement>();
                foreach (UIElement item in this.cvMap.Children)
                {
                    if (item is Line)
                    {
                        Line l = item as Line;
                        if (l.Tag != null && l.Tag.ToString() == "Align")
                        {
                            lines.Add(item);
                        }
                    }
                }

                if (lines.Count > 0)
                {
                    foreach (var item in lines)
                    {
                        this.cvMap.Children.Remove(item);
                    }
                }
            }

            // tạo hình giả theo chuột
            if (this._image != null)
            {
                if (lastImage != null && lastImage.Opacity == 0.5f)
                {
                    this.cvMap.Children.Remove(lastImage);
                }

                curImage = new Image();
                int w, h;

                Factory.ConvertToStandardImage(this._image, out w, out h);
                curImage.Width   = w;
                curImage.Height  = h;
                curImage.Source  = this._image.Source;
                curImage.Opacity = 0.5f; // dùng để nhận biết và phân biệt với image đc vẽ trong canvas

                Image rel_X, rel_Y;
                Alignment.Direction dir;
                Point p = Alignment.GetAutoAlignOffset(this.cvMap, X, Y, w, h, 3, 3, out rel_X, out rel_Y, out dir);

                if (p != (new Point(0, 0)))
                {
                    X += (int)p.X;
                    Y += (int)p.Y;
                    Alignment.AddAlignLine(this.cvMap, X, Y, w, h, rel_X, rel_Y, dir);
                }

                Canvas.SetLeft(curImage, X);
                Canvas.SetTop(curImage, Y);

                this.cvMap.Children.Add(curImage);
                lastImage = curImage;
                curImage  = null;

                curMouseState = e.LeftButton;
                if (curMouseState == MouseButtonState.Pressed && preMouseState == MouseButtonState.Released) // nhấn chuột trái
                {
                    Management.AddObjectToCanvas(this.cvMap, this._image, X, Y, i_MouseLeftButtonDown, i_MouseLeftButtonUp, canOverlap);
                    _isUnsaved = true;
                    _begin_X   = X;
                    _begin_Y   = Y;
                }
                else if (curMouseState == MouseButtonState.Pressed && e.RightButton == MouseButtonState.Pressed)
                {
                    if (e.GetPosition(this.cvMap).X > _begin_X)
                    {
                        int iWidth, iHeight;
                        Factory.ConvertToStandardImage(this._image, out iWidth, out iHeight);

                        while (_begin_X + iWidth < e.GetPosition(this.cvMap).X)
                        {
                            _begin_X += iWidth;
                            if (Management.HasAlreadyOverLap(this.cvMap, _begin_X, _begin_Y) == false)
                            {
                                Management.AddObjectToCanvas(this.cvMap, this._image, _begin_X, _begin_Y, i_MouseLeftButtonDown, i_MouseLeftButtonUp, canOverlap);
                            }
                        }
                    }
                    else if (e.GetPosition(this.cvMap).X < _begin_X)
                    {
                        int iWidth, iHeight;
                        Factory.ConvertToStandardImage(this._image, out iWidth, out iHeight);

                        while (_begin_X - iWidth > e.GetPosition(this.cvMap).X)
                        {
                            _begin_X -= iWidth;
                            if (Management.HasAlreadyOverLap(this.cvMap, _begin_X, _begin_Y) == false)
                            {
                                Management.AddObjectToCanvas(this.cvMap, this._image, _begin_X, _begin_Y, i_MouseLeftButtonDown, i_MouseLeftButtonUp, canOverlap);
                            }
                        }
                    }
                }

                preMouseState = curMouseState;
            }
            else if (this.selectedImage != null)
            {
                if (e.LeftButton == MouseButtonState.Pressed)
                {
                    isDragDrop = true;

                    selected_Offset_X = (int)e.GetPosition(this.cvMap).X - (selected_X + delta_X);
                    selected_Offset_Y = (selected_Y + delta_Y) - (int)e.GetPosition(this.cvMap).Y;

                    Image rel_X, rel_Y;
                    Alignment.Direction dir;
                    Point p = Alignment.GetAutoAlignOffset(
                        this.cvMap,
                        (int)e.GetPosition(this.cvMap).X - delta_X,
                        (int)e.GetPosition(this.cvMap).Y - delta_Y,
                        (int)selectedImage.Width, (int)selectedImage.Height, 3, 3, out rel_X, out rel_Y, out dir);

                    if (p != (new Point(0, 0)))
                    {
                        selected_Offset_X += (int)p.X;
                        selected_Offset_Y -= (int)p.Y;
                        Alignment.AddAlignLine(this.cvMap, selected_X + selected_Offset_X, selected_Y - selected_Offset_Y, (int)selectedImage.Width, (int)selectedImage.Height, rel_X, rel_Y, dir);
                    }

                    this.tbOffsetX.Text = selected_Offset_X.ToString();
                    this.tbOffsetY.Text = selected_Offset_Y.ToString();
                }
                else
                {
                    this.i_MouseLeftButtonUp(null, null);
                }
            }
        }
 private void Button_MouseMove(object sender, MouseEventArgs e)
 {
     tt.Placement        = System.Windows.Controls.Primitives.PlacementMode.Relative;
     tt.HorizontalOffset = e.GetPosition((IInputElement)sender).X + 16;
     tt.VerticalOffset   = e.GetPosition((IInputElement)sender).Y + 16;
 }
Пример #7
0
        /// <summary>
        /// Called when the mouse moves over the zoom/pan selection canvas.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>
        protected virtual void OnSelectionCanvasMouseMove(object sender, MouseEventArgs e)
        {
            _current_mouse_position = e.GetPosition(_selection_canvas);

            if (_is_selection_mouse_down_zoom && Keyboard.IsKeyDown(Key.LeftCtrl))
            {
                Canvas.SetLeft(_selection_rectangle, _selection_start_point.X);
                Canvas.SetTop(_selection_rectangle, _selection_start_point.Y);

                Point _selection_current_point = e.GetPosition(_selection_canvas);

                if (_selection_current_point.X - _selection_start_point.X > 1)
                {
                    _selection_rectangle.Width = _selection_current_point.X - _selection_start_point.X;
                }

                if (_selection_current_point.Y - _selection_start_point.Y > 1)
                {
                    _selection_rectangle.Height = _selection_current_point.Y - _selection_start_point.Y;
                }

                if (_selection_current_point.X < _selection_start_point.X)
                {
                    Canvas.SetLeft(_selection_rectangle, _selection_current_point.X);
                    _selection_rectangle.Width = _selection_start_point.X - _selection_current_point.X;
                }

                if (_selection_current_point.Y < _selection_start_point.Y)
                {
                    Canvas.SetTop(_selection_rectangle, _selection_current_point.Y);
                    _selection_rectangle.Height = _selection_start_point.Y - _selection_current_point.Y;
                }
            }
            else if (_is_selection_mouse_down_pan && _is_scaled)
            {
                Point _selection_current_point = e.GetPosition(_selection_canvas);

                double delta_x = _current_mouse_position.X - _last_mouse_position.X;
                double delta_y = _current_mouse_position.Y - _last_mouse_position.Y;

                double x = _zoom_rect.Left - delta_x;
                double y = _zoom_rect.Top - delta_y;

                if (x < 0)
                {
                    x = 0;
                }

                if (y < 0)
                {
                    y = 0;
                }

                if (x + _zoom_rect.Width > _size.Width)
                {
                    x = x - (x + _zoom_rect.Width - _size.Width);
                }

                if (y + _zoom_rect.Height > _size.Height)
                {
                    y = y - (y + _zoom_rect.Height - _size.Height);
                }

                _zoom_rect = new System.Drawing.RectangleF((float)x, (float)y, _zoom_rect.Width, _zoom_rect.Height);

                ZoomRectChanged?.Invoke(this, new EventArgs());
            }

            _last_mouse_position = _current_mouse_position;

            OnApplyToolTip(_last_mouse_position);
        }
Пример #8
0
 private void Image_MouseMove(object sender, MouseEventArgs e)
 {
     ImageToolTip.Placement        = System.Windows.Controls.Primitives.PlacementMode.Relative;
     ImageToolTip.HorizontalOffset = e.GetPosition((IInputElement)sender).X + 10;
     ImageToolTip.VerticalOffset   = e.GetPosition((IInputElement)sender).Y;
 }
Пример #9
0
        public void theCanvas_MouseMove(object sender, MouseEventArgs e)
        {
            if (MainWindow.theNeuronArray == null)
            {
                return;
            }
            Point currentPosition    = e.GetPosition(theCanvas);
            Point nonlimitedPosition = currentPosition;

            LimitMousePostion(ref currentPosition);
            int currentNeuron = dp.NeuronFromPoint(currentPosition);

            shapeType theShapeType = SetMouseCursorShape(e, out FrameworkElement theShape);

            if (MainWindow.Busy())
            {
                return;
            }

            if (mouseRepeatTimer != null)
            {
                if (mouseRepeatTimer.IsEnabled && mouseRepeatTimer.Interval == new TimeSpan(0, 0, 0, 0, 100))
                {
                    return;
                }
                mouseRepeatTimer.Stop();
            }

            if (MainWindow.IsArrayEmpty())
            {
                return;
            }

            //You can't do any dragging with the right mouse button
            if (e.RightButton == MouseButtonState.Pressed)
            {
                return;
            }


            //update the status bar
            if (currentPosition == nonlimitedPosition)
            {
                int    y1          = currentNeuron % Rows;
                int    x1          = currentNeuron / Rows;
                string mouseStatus = "ID: " + currentNeuron + "  Row: " + y1 + " Col: " + x1;
                foreach (ModuleView mv in MainWindow.theNeuronArray.modules)
                {
                    if (currentNeuron >= mv.FirstNeuron && currentNeuron <= mv.LastNeuron)
                    {
                        mv.GetNeuronLocation(currentNeuron, out int x, out int y);
                        mouseStatus += "  " + mv.Label + "(" + x + "," + y + ")";
                    }
                }
                MainWindow.thisWindow.SetStatus(1, mouseStatus, 0);
            }
            else
            {
                MainWindow.thisWindow.SetStatus(1, "Mouse outside neuron array", 1);
            }


            if (e.LeftButton == MouseButtonState.Pressed)
            {
                string oString = (theShape == null) ? "null" : theShape.ToString();
                //Debug.WriteLine("MouseMove  currentNeuron: " + currentNeuron
                //    + " Shape type: " + theShapeType.ToString() + " theShape: " + oString);

                //are we dragging a synapse? rubber-band it
                if ((theCanvas.Cursor == Cursors.Arrow || theCanvas.Cursor == Cursors.UpArrow) &&
                    currentOperation == CurrentOperation.draggingSynapse)
                {
                    DragSynapse(currentNeuron);
                }

                //handle the creation/updating of a dragging selection rectangle
                else if ((theShapeType == shapeType.None || theShapeType == shapeType.Selection) &&
                         currentOperation == CurrentOperation.draggingNewSelection)
                {
                    DragNewSelection(currentNeuron);
                }

                //handle moving an existing  selection
                else if (theShapeType == shapeType.Selection &&
                         theCanvas.Cursor == Cursors.ScrollAll)
                {
                    MoveSelection(currentNeuron);
                }

                //handle moving of a module
                else if (theShapeType == shapeType.Module && currentOperation == CurrentOperation.movingModule)
                {
                    MoveModule(theShape, currentNeuron);
                }

                //handle sizing of a module
                else if (theShapeType == shapeType.Module && currentOperation == CurrentOperation.sizingModule)
                {
                    ResizeModule(theShape, currentNeuron);
                }

                else if (theCanvas.Cursor == Cursors.Hand)
                {
                    if (e.LeftButton == MouseButtonState.Pressed)
                    {
                        ContinuePan(e.GetPosition((UIElement)theCanvas.Parent));
                        //lastPositionOnGrid = e.GetPosition((UIElement)theCanvas.Parent);
                    }
                    else
                    {
                        lastPositionOnCanvas = new Point(0, 0);
                    }
                }
            }    //end of Left-button down
            else //no button pressed
            {
                //handle the special case of no mouse cursor we must be inserting a module inserting a module
                //it's the only thing we drag without a button press
                if (currentOperation == CurrentOperation.insertingModule)
                {
                    DragInsertingModule(currentNeuron);
                }
                else
                {
                    currentOperation = CurrentOperation.idle;
                }
            }
        }
Пример #10
0
 private void SLSelector_MouseLeave(object sender, MouseEventArgs e)
 {
     if (MouseButtonPressed)
     {
         Canvas canvas      = (Canvas)sender;
         Point  point       = e.GetPosition(canvas);
         bool   isXfeasible = point.X >= 0 && point.X <= canvas.ActualWidth;
         bool   isYfeasible = point.Y >= 0 && point.Y <= canvas.ActualHeight;
         if (isXfeasible && isYfeasible)
         {
             Canvas.SetLeft(ellipse, point.X - ellipse.Width / 2);
             Canvas.SetTop(ellipse, point.Y - ellipse.Height / 2);
         }
         else if (!isXfeasible && isYfeasible)
         {
             if (point.X < 0)
             {
                 Canvas.SetLeft(ellipse, 0 - ellipse.Width / 2);
                 Canvas.SetTop(ellipse, point.Y - ellipse.Height / 2);
             }
             else
             {
                 Canvas.SetLeft(ellipse, canvas.ActualWidth - ellipse.Width / 2);
                 Canvas.SetTop(ellipse, point.Y - ellipse.Height / 2);
             }
         }
         else if (isXfeasible && !isYfeasible)
         {
             if (point.Y < 0)
             {
                 Canvas.SetLeft(ellipse, point.X - ellipse.Width / 2);
                 Canvas.SetTop(ellipse, 0 - ellipse.Height / 2);
             }
             else
             {
                 Canvas.SetLeft(ellipse, point.X - ellipse.Width / 2);
                 Canvas.SetTop(ellipse, canvas.ActualHeight - ellipse.Height / 2);
             }
         }
         else
         {
             if (point.X < 0 && point.Y < 0)
             {
                 Canvas.SetLeft(ellipse, 0 - ellipse.Width / 2);
                 Canvas.SetTop(ellipse, 0 - ellipse.Height / 2);
             }
             else if (point.X > 0 && point.Y < 0)
             {
                 Canvas.SetLeft(ellipse, canvas.ActualWidth - ellipse.Width / 2);
                 Canvas.SetTop(ellipse, 0 - ellipse.Height / 2);
             }
             else if (point.X < 0 && point.Y > 0)
             {
                 Canvas.SetLeft(ellipse, 0 - ellipse.Width / 2);
                 Canvas.SetTop(ellipse, canvas.ActualHeight - ellipse.Height / 2);
             }
             else if (point.X > 0 && point.Y > 0)
             {
                 Canvas.SetLeft(ellipse, canvas.ActualWidth - ellipse.Width / 2);
                 Canvas.SetTop(ellipse, canvas.ActualHeight - ellipse.Height / 2);
             }
         }
         if (ellipse.Parent == null)
         {
             canvas.Children.Add(ellipse);
         }
         MouseButtonPressed = false;
         SLSelector_Changed(sender);
     }
 }
Пример #11
0
        // MouseMoveEvent handler.
        private static void OnMouseMoveWithFocus(TextEditor This, MouseEventArgs e)
        {
            // Ignore the event if it was caused by us capturing the mouse
            if (This._mouseCapturingInProgress)
            {
                return;
            }

            // Clear a flag indicating that Shift key was pressed without any following key
            // This flag is necessary for KeyUp(RightShift/LeftShift) processing.
            TextEditor._ThreadLocalStore.PureControlShift = false;

            // Get the mouse move point.
            Point mouseMovePoint = e.GetPosition(This.TextView.RenderScope);

            // Update mouse cursor shape
            TextEditorMouse.UpdateCursor(This, mouseMovePoint);

            // For bug 1547567, remove when resolved.
            Invariant.Assert(This.Selection != null);

            // We're only interested in moves when the left button is down.
            if (e.LeftButton != MouseButtonState.Pressed)
            {
                return;
            }

            // We didn't get the original mouse down event, perhaps a listener
            // handled it.
            if (!This.UiScope.IsMouseCaptured)
            {
                return;
            }

            // Scale back any background layout in progress.
            This.TextView.ThrottleBackgroundTasksForUserInput();

            if (This._tableColResizeInfo != null)
            {
                This._tableColResizeInfo.UpdateAdorner(mouseMovePoint);
            }
            else
            {
                // Consider event handled
                e.Handled = true;

                // For bug 1547567, remove when resolved.
                Invariant.Assert(This.Selection != null);

                // Find a text position for this mouse point
                ITextPointer snappedCursorPosition = This.TextView.GetTextPositionFromPoint(mouseMovePoint, /*snapToText:*/ true);

                // For bug 1547567, remove when resolved.
                Invariant.Assert(This.Selection != null);

                if (snappedCursorPosition == null)
                {
                    This.RequestExtendSelection(mouseMovePoint);
                }
                else
                {
                    This.CancelExtendSelection();

                    // For bug 1547567, remove when resolved.
                    Invariant.Assert(This.Selection != null);

                    if (!This._dragDropProcess.SourceOnMouseMove(mouseMovePoint))
                    {
                        // Auto-scrolling behavior during selection guesture -
                        // works when the mouse is outside of scroller's viewport.
                        // In such case we artificially increase coordinates to
                        // get to farther text position - which would speed-up scrolling
                        // in particular direction.
                        FrameworkElement scroller = This._Scroller;
                        if (scroller != null && This.UiScope is TextBoxBase)
                        {
                            ITextPointer acceleratedCursorPosition = null; // cursorPosition corrected to accelerate scrolling

                            Point targetPoint   = new Point(mouseMovePoint.X, mouseMovePoint.Y);
                            Point pointScroller = e.GetPosition((IInputElement)scroller);

                            double pageHeight    = (double)((TextBoxBase)This.UiScope).ViewportHeight;
                            double slowAreaDelta = ScrollViewer._scrollLineDelta;

                            // Auto scrolling up/down page for the page height if the mouse Y
                            // position is out of viewport.
                            if (pointScroller.Y < 0 - slowAreaDelta)
                            {
                                Rect targetRect = This.TextView.GetRectangleFromTextPosition(snappedCursorPosition);
                                targetPoint = new Point(targetPoint.X, targetRect.Bottom - pageHeight);
                                acceleratedCursorPosition = This.TextView.GetTextPositionFromPoint(targetPoint, /*snapToText:*/ true);
                            }
                            else if (pointScroller.Y > pageHeight + slowAreaDelta)
                            {
                                Rect targetRect = This.TextView.GetRectangleFromTextPosition(snappedCursorPosition);
                                targetPoint = new Point(targetPoint.X, targetRect.Top + pageHeight);
                                acceleratedCursorPosition = This.TextView.GetTextPositionFromPoint(targetPoint, /*snapToText:*/ true);
                            }

                            double pageWidth = (double)((TextBoxBase)This.UiScope).ViewportWidth;

                            // Auto scrolling to left/right scroll delta amount if the mouse X position
                            // is out of viewport area.
                            if (pointScroller.X < 0)
                            {
                                targetPoint = new Point(targetPoint.X - slowAreaDelta, targetPoint.Y);
                                acceleratedCursorPosition = This.TextView.GetTextPositionFromPoint(targetPoint, /*snapToText:*/ true);
                            }
                            else if (pointScroller.X > pageWidth)
                            {
                                targetPoint = new Point(targetPoint.X + slowAreaDelta, targetPoint.Y);
                                acceleratedCursorPosition = This.TextView.GetTextPositionFromPoint(targetPoint, /*snapToText:*/ true);
                            }

                            // Use acceleratedcursorPosition instead of real one to make scrolling reasonable faster
                            if (acceleratedCursorPosition != null)
                            {
                                snappedCursorPosition = acceleratedCursorPosition;
                            }
                        }

                        using (This.Selection.DeclareChangeBlock())
                        {
                            // Check end-of-container condition
                            if (snappedCursorPosition.GetNextInsertionPosition(LogicalDirection.Forward) == null &&
                                snappedCursorPosition.ParentType != null) //  This check is a work around of bug that Parent can be null for some text boxes.
                            {
                                // We are at the end of text container. Check whether mouse is farther than a last character
                                Rect lastCharacterRect = snappedCursorPosition.GetCharacterRect(LogicalDirection.Backward);
                                if (mouseMovePoint.X > lastCharacterRect.X + lastCharacterRect.Width)
                                {
                                    snappedCursorPosition = This.TextContainer.End;
                                }
                            }

                            // Move the caret/selection to match the cursor position.
                            This.Selection.ExtendSelectionByMouse(snappedCursorPosition, This._forceWordSelection, This._forceParagraphSelection);
                        }
                    }
                }
            }
        }
Пример #12
0
        //------------------------------------------------------
        //
        //  Private Methods
        //
        //------------------------------------------------------

        #region Private Methods

        // ................................................................
        //
        // Event Handlers: Selection Building
        //
        // ................................................................

        // MouseMoveEvent handler.
        private static void OnMouseMoveWithoutFocus(TextEditor This, MouseEventArgs e)
        {
            // Note that position can be null here, because we did not request to snap it to text
            TextEditorMouse.UpdateCursor(This, e.GetPosition(This.TextView.RenderScope));
        }
 private void cnv_Main_MouseMove(object sender, MouseEventArgs e)
 {
     lbl_Xcoords.Content = e.GetPosition(cnv_Main).X;
     lbl_Ycoords.Content = e.GetPosition(cnv_Main).Y;
 }
        private void Control_MouseMove(object sender, MouseEventArgs e)
        {
            var draggableControl = sender as UserControl;

            if (isDragging && draggableControl != null)
            {
                Point currentPosition = e.GetPosition(this.Parent as UIElement);

                var transform = draggableControl.RenderTransform as TranslateTransform;
                if (transform == null)
                {
                    transform = new TranslateTransform();
                    draggableControl.RenderTransform = transform;
                }

                transform.X = currentPosition.X - clickPosition.X;
                transform.Y = currentPosition.Y - clickPosition.Y;
            }
        }
Пример #15
0
            static void ErasePixel(MouseEventArgs e)
            {
                byte[] ColorData = { 0, 0, 0, 0 }; // B G R

                Int32Rect rect = new Int32Rect(
                        (int)(e.GetPosition(i).X),
                        (int)(e.GetPosition(i).Y),
                        1,
                        1);

                writeableBitmap.WritePixels(rect, ColorData, 4, 0);
            }
Пример #16
0
        public void RaiseHorizontalRulerMoveEvent(MouseEventArgs e)
        {
            Point mousePoint = e.GetPosition(this);

            mouseHorizontalTrackLine.X1 = mouseHorizontalTrackLine.X2 = mousePoint.X;
        }
Пример #17
0
 private void SLSelector_MouseMove(object sender, MouseEventArgs e)
 {
     SLSelector.Cursor = new Cursor(e.GetPosition(SLSelector).Y / SLSelector.ActualHeight < 0.5 ? CursorFile : CursorFile2);
 }
Пример #18
0
        private void CanvasTest_MouseMove(object sender, MouseEventArgs e)
        {
            Point newMousePosition = e.GetPosition(mainCanvas);

            if (e.RightButton == MouseButtonState.Pressed)
            {
                if (OptionMode.mode == Mode.modeDraw)
                {
                    List <Point> pts = listFigure[indexFigure].points;
                    if (pts.Count > 0)
                    {
                        if (startDrawing)
                        {
                            listFigure[indexFigure].points.RemoveAt(pts.Count - 1);
                        }
                        Point normalizedPoint = FindClosestDot(newMousePosition);
                        listFigure[indexFigure].AddPoint(normalizedPoint);
                        DrawLine(pts[pts.Count - 2], pts[pts.Count - 1], mainCanvas);
                        startDrawing = true;
                    }
                }
            }

            //if (e.LeftButton == MouseButtonState.Pressed)
            //{
            //    if(OptionMode.mode == Mode.modeDrawCurve)
            //    {
            //        mainCanvas.Children.Remove(listFigure[indexFigure].NewPointEllipse);
            //        mainCanvas.Children.Remove(changedLine);
            //        ChangeBezierPoints(chosenPts, e.GetPosition(mainCanvas));
            //        changedLine = GeometryHelper.SetBezier(OptionColor.colorCurve, chosenPts[0], chosenPts[1], chosenPts[2], chosenPts[3], mainCanvas);
            //    }

            //    if (OptionMode.mode == Mode.modeDrawArc)
            //    {
            //        mainCanvas.Children.Remove(listFigure[indexFigure].NewPointEllipse);
            //        mainCanvas.Children.Remove(changedLine);
            //        chosenPts[2] = e.GetPosition(mainCanvas);
            //        changedLine = GeometryHelper.SetArc(OptionColor.colorArc, chosenPts[0], chosenPts[1], chosenPts[2], mainCanvas);
            //    }
            //    if (OptionMode.mode == Mode.modeMovePoints)
            //    {
            //        mainCanvas.Children.Remove(listFigure[indexFigure].NewPointEllipse);
            //        mainCanvas.Children.Remove(firstRec);
            //        Vector delta = e.GetPosition(mainCanvas) - prevPoint;
            //        ManipulateShapes(delta);
            //        prevPoint = e.GetPosition(mainCanvas);
            //    }
            //    if (OptionMode.mode == Mode.modeCursorMoveRect)
            //    {
            //        Vector delta = e.GetPosition(mainCanvas) - prevPoint;
            //        MoveFigureRectangle(chRec, delta, mainCanvas);
            //        foreach (Rectangle rec in movingFigurePoints)
            //            MoveFigureRectangle(rec, delta, mainCanvas);
            //        prevPoint = e.GetPosition(mainCanvas);
            //    }
            //    if (OptionMode.mode == Mode.modeEditPoints)
            //    {
            //        if (choosingRectangle.points.Count > 0)
            //        {
            //            if(!startDrawing)
            //            {
            //                mainCanvas.Children.Remove(chRec);
            //            }
            //            chRec = DrawChoosingRectangle(choosingRectangle.points[0], e.GetPosition(mainCanvas), mainCanvas);
            //            startDrawing = false;
            //        }
            //    }

            //    if ((OptionMode.mode == Mode.modeTatami || OptionMode.mode == Mode.modeSatin) && !startDrawing)
            //    {
            //        if (controlLine.points.Count > 1)
            //        {
            //            mainCanvas.Children.RemoveAt(mainCanvas.Children.Count - 1);
            //            controlLine.points.RemoveAt(controlLine.points.Count - 1);
            //        }
            //        Line line = controlLine.GetLine(controlLine.points[0], e.GetPosition(mainCanvas));
            //        Vector vect1 = new Vector(e.GetPosition(mainCanvas).X - controlLine.points[0].X,
            //            e.GetPosition(mainCanvas).Y - controlLine.points[0].Y);
            //        vect1.Normalize();
            //        Vector vect2 = new Vector(1, 0);
            //        double contLineAngle = Vector.AngleBetween(vect1, vect2);
            //        if (contLineAngle > 0)
            //            contLineAngle -= 180;
            //        else
            //            contLineAngle +=180;
            //        statusbar3.Content = "Угол секущей = " + Math.Round(contLineAngle, 1);
            //        DoubleCollection dashes = new DoubleCollection();
            //        dashes.Add(2);
            //        dashes.Add(2);
            //        line.StrokeDashArray = dashes;
            //        line.StrokeThickness = OptionDrawLine.strokeThickness;
            //        line.Stroke = OptionColor.colorInactive;
            //        mainCanvas.Children.Add(line);
            //        mainCanvas.UpdateLayout();
            //        controlLine.points.Add(e.GetPosition(mainCanvas));
            //    }
            //    if (OptionMode.mode == Mode.modeScaleFigure)
            //    {
            //        mainCanvas.Children.Remove(chRec);
            //        if (Keyboard.IsKeyDown(Key.LeftShift))
            //            MoveScalingRectangleRelativeToCenter(e.GetPosition(mainCanvas), mainCanvas);
            //        else
            //            MoveScalingRectangle(e.GetPosition(mainCanvas),mainCanvas);

            //        ShowPositionStatus(listFigure[indexFigure], false, true);
            //    }
            //    if (OptionMode.mode == Mode.rotateFigure)
            //    {
            //        Rectangle centerRect = transRectangles[8];
            //        Point centerPoint = new Point(Canvas.GetLeft(centerRect) + centerRect.Width / 2, Canvas.GetTop(centerRect) + centerRect.Width / 2);
            //        RotateRotatingRectangle(e.GetPosition(mainCanvas), centerPoint,prevPoint, mainCanvas);
            //    }
            //    if(OptionMode.mode == Mode.modeChangeRotatingCenter)
            //    {
            //        Rectangle centerRect = transRectangles[8];
            //        mainCanvas.Children.Remove(centerRect);
            //        Canvas.SetTop(centerRect, e.GetPosition(mainCanvas).Y - centerRect.Height / 2);
            //        Canvas.SetLeft(centerRect, e.GetPosition(mainCanvas).X - centerRect.Height / 2);
            //        mainCanvas.Children.Add(centerRect);
            //    }
            //}
        }
Пример #19
0
        //This sets the mouse cursor depending on the mouse location and current operation.
        private shapeType SetMouseCursorShape(MouseEventArgs e, out FrameworkElement theShape)
        {
            theShape = prevShape;

            //if dragging, don't change the cursor but return the hit
            if (currentOperation != CurrentOperation.idle)
            {
                if (currentOperation == CurrentOperation.draggingSynapse)
                {
                    return(shapeType.Synapse);
                }
                if (currentOperation == CurrentOperation.movingModule)
                {
                    return(shapeType.Module);
                }
                if (currentOperation == CurrentOperation.draggingNewSelection)
                {
                    return(shapeType.Selection);
                }
                if (currentOperation == CurrentOperation.insertingModule)
                {
                    return(shapeType.None);
                }
                if (!MainWindow.ctrlPressed)
                {
                    if (currentOperation == CurrentOperation.movingSelection)
                    {
                        return(shapeType.Selection);
                    }
                    if (currentOperation == CurrentOperation.sizingModule)
                    {
                        return(shapeType.Module);
                    }
                }
            }

            //don't change the cursor if dragging, panning
            if (theCanvas.Cursor == Cursors.Hand)
            {
                return(shapeType.None);
            }

            //if busy, make sure the cursor is hourglass
            if (MainWindow.Busy())
            {
                theCanvas.Cursor = Cursors.Wait;
                return(shapeType.None);
            }

            //what type of shape is the mouse  over?
            HitTestResult result = VisualTreeHelper.HitTest(theCanvas, e.GetPosition(theCanvas));

            if (result != null && result.VisualHit is FrameworkElement theShape0)
            {
                theShape = theShape0;

                //Get the type of the hit...

                shapeType st = (shapeType)theShape.GetValue(ShapeType);

                //Set the cursor shape based on the type of object the mouse is over
                switch (st)
                {
                case shapeType.None:
                    theCanvas.Cursor = Cursors.Cross;
                    st = shapeType.Canvas;
                    break;

                case shapeType.Synapse:
                    theCanvas.Cursor = Cursors.Arrow;
                    break;

                case shapeType.Neuron:
                    theCanvas.Cursor = Cursors.UpArrow;
                    break;

                case shapeType.Module:     //for a module, set directional stretch arrow cursors
                    if (!MainWindow.ctrlPressed)
                    {
                        theCanvas.Cursor = Cursors.ScrollAll;
                        SetScrollCursor(e.GetPosition(this), theShape);
                    }
                    else     //ctrl pressed
                    {
                        theCanvas.Cursor = Cursors.Cross;
                        st = shapeType.Canvas;
                    }
                    break;

                case shapeType.Selection:     //TODO add directional arrow code
                    theCanvas.Cursor = Cursors.ScrollAll;
                    break;
                }
                prevShape = theShape;
                return(st);
            }
            //mouse is not over anything
            theCanvas.Cursor = Cursors.Cross;
            return(shapeType.Canvas);
        }
Пример #20
0
        private void OnCategoryChartMouseMove(object sender, MouseEventArgs e)
        {
            DataSource data    = new DataSource();
            var        series1 = this.CategoryChart.Series.FirstOrDefault();

            if (series1 == null)
            {
                return;
            }

            var position = e.GetPosition(series1);

            // calculate crosshair coordinates on CategoryDateTimeXAxis
            if (((XamDataChart)series1.SeriesViewer).Axes.OfType <CategoryDateTimeXAxis>().Any())
            {
                var xAxis = ((XamDataChart)series1.SeriesViewer).Axes.OfType <CategoryDateTimeXAxis>().First();
                var yAxis = ((XamDataChart)series1.SeriesViewer).Axes.OfType <NumericYAxis>().First();

                var viewport = new Rect(0, 0, xAxis.ActualWidth, yAxis.ActualHeight);
                var window   = series1.SeriesViewer.WindowRect;

                bool         isInverted = xAxis.IsInverted;
                ScalerParams param      = new ScalerParams(window, viewport, isInverted);
                var          unscaledX  = xAxis.GetUnscaledValue(position.X, param);

                isInverted = yAxis.IsInverted;
                param      = new ScalerParams(window, viewport, isInverted);
                var unscaledY = yAxis.GetUnscaledValue(position.Y, param);

                if ((long)unscaledX > DateTime.MaxValue.Ticks || (long)unscaledX < DateTime.MinValue.Ticks)
                {
                    return;
                }

                DateTime xDate = new DateTime((long)unscaledX);

                this.CategoryXCoordinateTextBlock.Text = String.Format("{0:MM-dd}", xDate);
                this.CategoryYCoordinateTextBlock.Text = String.Format("{0:0.00}", unscaledY);

                string dateStr = String.Format("{0:MM-dd}", xDate);
                if (colCorn != null && colCorn.Visibility == Visibility.Visible)
                {
                    foreach (DataValue data1 in predictY1Data)
                    {
                        string dateStr1 = String.Format("{0:MM-dd}", data1.date);
                        if (dateStr1.Equals(dateStr))
                        {
                            textDate.Text = dateStr;
                            textCha.Text  = String.Format("{0:0.00}", data1.ChaValue);
                            break;
                        }
                    }
                }
                else if (colGrain != null && colGrain.Visibility == Visibility.Visible)
                {
                    foreach (DataValue data1 in predictYData)
                    {
                        string dateStr1 = String.Format("{0:MM-dd}", data1.date);
                        if (dateStr1.Equals(dateStr))
                        {
                            textDate.Text = dateStr;
                            textCha.Text  = String.Format("{0:0.00}", data1.ChaValue);
                            break;
                        }
                    }
                }
                else if (colTCC != null && colTCC.Visibility == Visibility.Visible)
                {
                    foreach (DataValue data1 in predictY3Data)
                    {
                        string dateStr1 = String.Format("{0:MM-dd}", data1.date);
                        if (dateStr1.Equals(dateStr))
                        {
                            textCha.Text = String.Format("{0:0.00}", data1.ChaValue);
                            break;
                        }
                    }
                }
                else if (colRice != null && colRice.Visibility == Visibility.Visible)
                {
                    foreach (DataValue data1 in predictY2Data)
                    {
                        string dateStr1 = String.Format("{0:MM-dd}", data1.date);
                        if (dateStr1.Equals(dateStr))
                        {
                            textDate.Text = dateStr;
                            textCha.Text  = String.Format("{0:0.00}", data1.ChaValue);
                            break;
                        }
                    }
                }

                textGrainY.Text    = String.Format("{0:0.00}", unscaledY);
                textGrainDate.Text = String.Format("{0:MM-dd}", xDate);

                textCornY1.Text   = String.Format("{0:0.00}", unscaledY);
                textCornDate.Text = String.Format("{0:MM-dd}", xDate);

                textRiceY2.Text   = String.Format("{0:0.00}", unscaledY);
                textRiceDate.Text = String.Format("{0:MM-dd}", xDate);

                textTCCY3.Text   = String.Format("{0:0.00}", unscaledY);
                textTCCDate.Text = String.Format("{0:MM-dd}", xDate);
            }
        }
        private void Knob_MouseMove(object sender, MouseEventArgs e)
        {
            double slope, absX, absY;

            if (e.LeftButton == MouseButtonState.Pressed)
            {
                double x = e.GetPosition(this).X - knobLocation.X;
                double y = e.GetPosition(this).Y - knobLocation.Y;
                //knobPosition.X = x;
                //knobPosition.Y = y;
                if (Math.Sqrt(x * x + y * y) <= Base.Width / 2)
                {
                    knobPosition.X = x;
                    knobPosition.Y = y;
                }
                else
                {
                    //linear equation to calculate point at radious on same line.
                    slope = y / x;
                    if (Double.IsInfinity(slope))
                    {
                        knobPosition.X = 0;
                        if (slope < 0)
                        {
                            knobPosition.Y = Base.Height / -2;
                        }
                        else
                        {
                            knobPosition.Y = Base.Height / 2;
                        }
                    }
                    else
                    {
                        absX = Math.Sqrt(Math.Pow(Base.Width / 2, 2) / (Math.Pow(slope, 2) + 1));
                        absY = absX * slope;
                        if (x > 0)
                        {
                            knobPosition.X = absX;
                        }
                        else if (x < 0)
                        {
                            knobPosition.X = -absX;
                        }
                        else
                        {
                            knobPosition.X = 0;
                        }
                        if (y > 0)
                        {
                            if (x > 0)
                            {
                                knobPosition.Y = absY;
                            }
                            else
                            {
                                knobPosition.Y = -absY;
                            }
                        }
                        else if (y < 0)
                        {
                            if (x < 0)
                            {
                                knobPosition.Y = -absY;
                            }
                            else
                            {
                                knobPosition.Y = absY;
                            }
                        }
                        else
                        {
                            knobPosition.Y = 0;
                        }
                    }
                }

                Window parentWin = Window.GetWindow(this);
                _vm = ((MainWindow)Application.Current.MainWindow).getVM();
                /// the values to send to simulator, the joystick range is between -1 to 1 when the horizontal to the right take value 1 and most vertical up takes vlaue 1
                yoso.Text = (knobPosition.X / (Base.Width / 2)).ToString();
                yosi.Text = (knobPosition.Y / (Base.Height / -2)).ToString();
                _vm.FlyPlane(knobPosition.X / (Base.Width / 2), knobPosition.Y / (Base.Height / -2));
            }
        }
Пример #22
0
        protected override void OnPreviewMouseMove(MouseEventArgs e)
        {
            base.OnPreviewMouseMove(e);
            if (this.addButtonRect.Contains(e.GetPosition(this)) && this.addButton.Background != Brushes.White && this.addButton.Background != Brushes.DarkGray)
            {
                this.addButton.Background = Brushes.White;
                this.InvalidateVisual();
            }
            else if (!this.addButtonRect.Contains(e.GetPosition(this)) && this.addButton.Background != null)
            {
                this.addButton.Background = null;
                this.InvalidateVisual();
            }
            if (this.draggedTab == null || this.draggingWindow)
            {
                return;
            }


            //TEST: JW tab tear test
            var  y         = e.GetPosition(this).Y;
            bool aboveTabs = y >= this.ActualHeight * 1.5;
            bool belowTabs = y < this.ActualHeight * -0.5;

            if (e.LeftButton == MouseButtonState.Pressed)
            {
                Console.WriteLine(y);
                if (aboveTabs || belowTabs)
                {
                    MessageBox.Show("Moved out!");
                }
            }
            //end


            Point     nowPoint = e.GetPosition(this);
            Thickness margin   = new Thickness(nowPoint.X - this.downPoint.X, 0, this.downPoint.X - nowPoint.X, 0);

            this.draggedTab.Margin = margin;
            if (margin.Left != 0)
            {
                int guardValue = Interlocked.Increment(ref this.captureGuard);
                if (guardValue == 1)
                {
                    this.originalIndex  = this.draggedTab.Index;
                    this.slideIndex     = this.originalIndex + 1;
                    this.slideIntervals = new List <double>();
                    this.slideIntervals.Add(double.NegativeInfinity);
                    for (int i = 1; i <= this.Children.Count; i += 1)
                    {
                        var diff  = i - this.slideIndex;
                        var sign  = diff == 0 ? 0 : diff / Math.Abs(diff);
                        var bound = Math.Min(1, Math.Abs(diff)) * ((sign * this.currentTabWidth / 3) + ((Math.Abs(diff) < 2) ? 0 : (diff - sign) * (this.currentTabWidth - this.overlap)));
                        this.slideIntervals.Add(bound);
                    }
                    this.slideIntervals.Add(double.PositiveInfinity);
                    this.CaptureMouse();
                }
                else
                {
                    int changed = 0;
                    if (margin.Left < this.slideIntervals[this.slideIndex - 1])
                    {
                        SwapSlideInterval(this.slideIndex - 1);
                        this.slideIndex -= 1;
                        changed          = 1;
                    }
                    else if (margin.Left > this.slideIntervals[this.slideIndex + 1])
                    {
                        SwapSlideInterval(this.slideIndex + 1);
                        this.slideIndex += 1;
                        changed          = -1;
                    }
                    if (changed != 0)
                    {
                        var rightedOriginalIndex = this.originalIndex + 1;
                        var diff = 1;
                        if (changed > 0 && this.slideIndex >= rightedOriginalIndex)
                        {
                            changed = 0;
                            diff    = 0;
                        }
                        else if (changed < 0 && this.slideIndex <= rightedOriginalIndex)
                        {
                            changed = 0;
                            diff    = 2;
                        }
                        ChromeTabItem shiftedTab = this.Children[this.slideIndex - diff] as ChromeTabItem;
                        if (shiftedTab != this.draggedTab)
                        {
                            StickyReanimate(shiftedTab, changed * (this.currentTabWidth - this.overlap), .25);
                        }
                    }
                }
            }
        }
Пример #23
0
 private void ImageEdit_MouseMove(object sender, MouseEventArgs e)
 {
     viewModel.MouseMove(e.GetPosition(CanvasBorder));
 }
        private void OnMouseMove(object sender, MouseEventArgs e)
        {
            Point pnt = e.GetPosition(mrRec);

            txt2.Text = "Mouse Move: " + pnt.ToString();
        }
Пример #25
0
        private void Canvas_MouseMove(object sender, MouseEventArgs e)
        {
            //画矩形
            if (mouseDownCount == 1)
            {
                double width  = e.GetPosition(this).X - startPoint.X;
                double height = e.GetPosition(this).Y - startPoint.Y;
                Rectangle1.Width  = Math.Abs(width);
                Rectangle1.Height = Math.Abs(height);

                if (width >= 0)
                {
                    Canvas.SetLeft(Rectangle1, startPoint.X);
                }
                else
                {
                    Canvas.SetLeft(Rectangle1, e.GetPosition(this).X);
                }

                if (height >= 0)
                {
                    Canvas.SetTop(Rectangle1, startPoint.Y);
                }
                else
                {
                    Canvas.SetTop(Rectangle1, e.GetPosition(this).Y);
                }

                SetImage();
            }
            else if (canMove && mouseDownCount >= 2)
            {
                if (e.GetPosition(Rectangle1).X > 0 && e.GetPosition(Rectangle1).X < Rectangle1.Width &&
                    e.GetPosition(Rectangle1).Y > 0 && e.GetPosition(Rectangle1).Y < Rectangle1.Height)
                {
                    //移动矩形
                    double left = rectangle.X - startPoint.X + e.GetPosition(this).X;
                    double top  = rectangle.Y - startPoint.Y + e.GetPosition(this).Y;

                    Canvas.SetLeft(Rectangle1, left);
                    Canvas.SetTop(Rectangle1, top);
                    SetImage();
                }

                Console.WriteLine("---1---");
            }
            else if (canChangeSize)
            {
                //调整矩形大小
                double height = e.GetPosition(this).Y - Canvas.GetTop(Rectangle1);

                if (height < 0)
                {
                    Canvas.SetTop(Rectangle1, e.GetPosition(this).Y);
                    Rectangle1.Height = sizePoint.Y - e.GetPosition(this).Y;
                }
                else
                {
                    Rectangle1.Height = Math.Abs(height);
                }
            }
        }
Пример #26
0
        public bool HandleMouseMove(MouseEventArgs e)
        {
            // Retrieve the coordinates of the mouse button event.
            Point pt = e.GetPosition(_drawingCanvas);

            Drawing hitVisual = HitTest(pt);

            if (_selectedVisual != null && hitVisual == _selectedVisual)
            {
                _drawingCanvas.Cursor = Cursors.Hand;

                return(true);
            }

            string itemName = null;

            if (hitVisual == null)
            {
                if (_hitVisual != null)
                {
                    itemName = _hitVisual.GetValue(FrameworkElement.NameProperty) as string;
                    if (itemName == null)
                    {
                        _hitVisual = null;
                        return(false);
                    }
                    if (_visualBrushes.ContainsKey(itemName) && (_hitVisual != _selectedVisual))
                    {
                        SolidColorBrush brush = _visualBrushes[itemName] as SolidColorBrush;
                        if (brush != null)
                        {
                            brush.Color = _colorLink;
                        }
                    }
                    _hitVisual = null;
                }

                if (_tooltip != null)
                {
                    _tooltip.IsOpen     = false;
                    _tooltip.Visibility = Visibility.Hidden;
                }

                return(false);
            }
            else
            {
                _drawingCanvas.Cursor = Cursors.Hand;

                if (hitVisual == _hitVisual)
                {
                    return(false);
                }

                if (_hitVisual != null)
                {
                    itemName = _hitVisual.GetValue(FrameworkElement.NameProperty) as string;
                    if (itemName == null)
                    {
                        _hitVisual = null;
                        return(false);
                    }
                    if (_visualBrushes.ContainsKey(itemName) && (_hitVisual != _selectedVisual))
                    {
                        SolidColorBrush brush = _visualBrushes[itemName] as SolidColorBrush;
                        if (brush != null)
                        {
                            brush.Color = _colorLink;
                        }
                    }
                    _hitVisual = null;
                }

                itemName = hitVisual.GetValue(FrameworkElement.NameProperty) as string;
                if (itemName == null)
                {
                    return(false);
                }
                if (_visualBrushes.ContainsKey(itemName))
                {
                    SolidColorBrush brush = _visualBrushes[itemName] as SolidColorBrush;
                    if (brush != null)
                    {
                        brush.Color = _colorHover;
                    }
                }
                _hitVisual = hitVisual;

                string        tooltipText = itemName;
                SvgLinkAction linkAction  = SvgLink.GetAction(hitVisual);
                if (linkAction == SvgLinkAction.LinkTooltip &&
                    _tooltip != null && !string.IsNullOrWhiteSpace(tooltipText))
                {
                    Rect rectBounds = hitVisual.Bounds;

                    _tooltip.PlacementRectangle = rectBounds;

                    _tooltipText.Text = tooltipText;

                    if (_tooltip.Visibility == Visibility.Hidden)
                    {
                        _tooltip.Visibility = Visibility.Visible;
                    }

                    _tooltip.IsOpen = true;
                }
                else
                {
                    if (_tooltip != null)
                    {
                        _tooltip.IsOpen     = false;
                        _tooltip.Visibility = Visibility.Hidden;
                    }
                }
            }

            return(true);
        }
        private void MouseNavigationLayer_MouseMove(object sender, MouseEventArgs e)
        {
            Point cursorPosition = e.GetPosition(this);

            if (!CheckCursor(cursorPosition))
            {
                wasInside = true;
                MouseNavigationLayer_MouseLeave(sender, e);
                return;
            }
            else
            {
                if (wasInside && isLeftClicked)
                {
                    HandleMouseUp();
                    HandleMouseDown(e);
                }
            }

            if (isPanning)
            {
                if (!transformChangeRequested)
                {
                    transformChangeRequested = true;
                    panningEnd = e.GetPosition(this);
                    DoPan(panningStart, panningEnd);
                    panningStart = panningEnd;
                    InvalidateArrange();
                }
            }

            if (isSelecting)
            {
                selectEnd = e.GetPosition(this);
                if (!selectingStarted)
                {
                    if ((Math.Abs(selectStart.X - selectEnd.X) > 4) || (Math.Abs(selectStart.Y - selectEnd.Y) > 4))
                    {
                        selectingStarted           = true;
                        selectArea                 = new Rectangle();
                        selectArea.Fill            = new SolidColorBrush(Colors.LightGray);
                        selectArea.StrokeThickness = 2;
                        selectArea.Stroke          = new SolidColorBrush(Color.FromArgb(255, 40, 0, 120));
                        selectArea.Opacity         = 0.6;

                        if (masterPlot != null)
                        {
                            plot.IsAutoFitEnabled = false;

                            plot.Children.Clear();
                            plot.Children.Add(selectArea);

                            if (!masterPlot.Children.Contains(plot))
                            {
                                masterPlot.Children.Add(plot);
                                Canvas.SetZIndex(plot, 40000);
                            }

                            double width  = Math.Abs(masterPlot.XFromLeft(selectStart.X) - masterPlot.XFromLeft(selectEnd.X));
                            double height = Math.Abs(masterPlot.YFromTop(selectStart.Y) - masterPlot.YFromTop(selectEnd.Y));
                            double xmin   = masterPlot.XFromLeft(Math.Min(selectStart.X, selectEnd.X));
                            double ymin   = masterPlot.YFromTop(Math.Max(selectStart.Y, selectEnd.Y));

                            Plot.SetX1(selectArea, xmin);
                            Plot.SetY1(selectArea, ymin);
                            Plot.SetX2(selectArea, xmin + width);
                            Plot.SetY2(selectArea, ymin + height);
                        }
                        else
                        {
                            navigationCanvas.Children.Add(selectArea);
                            Canvas.SetLeft(selectArea, selectStart.X);
                            Canvas.SetTop(selectArea, selectStart.Y);
                        }
                    }
                }
                else
                {
                    if (masterPlot == null)
                    {
                        double width  = Math.Abs(selectStart.X - selectEnd.X);
                        double height = Math.Abs(selectStart.Y - selectEnd.Y);
                        selectArea.Width  = width;
                        selectArea.Height = height;

                        if (selectEnd.X < selectStart.X)
                        {
                            Canvas.SetLeft(selectArea, selectStart.X - width);
                        }

                        if (selectEnd.Y < selectStart.Y)
                        {
                            Canvas.SetTop(selectArea, selectStart.Y - height);
                        }
                    }
                    else
                    {
                        double width  = Math.Abs(masterPlot.XFromLeft(selectStart.X) - masterPlot.XFromLeft(selectEnd.X));
                        double height = Math.Abs(masterPlot.YFromTop(selectStart.Y) - masterPlot.YFromTop(selectEnd.Y));
                        double xmin   = masterPlot.XFromLeft(Math.Min(selectStart.X, selectEnd.X));
                        double ymin   = masterPlot.YFromTop(Math.Max(selectStart.Y, selectEnd.Y));

                        Plot.SetX1(selectArea, xmin);
                        Plot.SetY1(selectArea, ymin);
                        Plot.SetX2(selectArea, xmin + width);
                        Plot.SetY2(selectArea, ymin + height);
                    }
                }
            }

            wasInside = false;
        }
Пример #28
0
 void MouseEvent(RawMouseEventType type, MouseEventArgs e)
 => _ttl.Input?.Invoke(new RawMouseEventArgs(_mouse, (uint)e.Timestamp, _inputRoot, type,
                                             e.GetPosition(this).ToAvaloniaPoint(), GetModifiers()));
Пример #29
0
 private void DockIconContainer_LostMouseCapture(object sender, MouseEventArgs e)
 {
     MouseReleased(e.GetPosition(container));
 }
Пример #30
0
        private void Area_OnMouseMove(object sender, MouseEventArgs e)
        {
            Point mousePoint = e.GetPosition(sender as Image);

            _canvasViewModel.HandleMouseMove(mousePoint);
        }
Пример #31
0
        private void UpdateStatus(MouseEventArgs e)
        {
            Point location = e.GetPosition(null);

            uxStatus.Text = string.Format("({0},{1}) IsMoving={2}", location.X, location.Y, isMoving);
        }
Пример #32
0
        private void OnMergeDrag(object o, MouseEventArgs e)
        {
            if (_startDragPos.X == -1)
            {
                _startDragPos = e.GetPosition(Preview);
            }

            GridLayoutModel model = Model;

            if (_startDragPos.X != -1)
            {
                Point dragPos = e.GetPosition(Preview);

                _startRow = -1;
                _endRow   = -1;
                _startCol = -1;
                _endCol   = -1;

                int rows = model.Rows;
                int cols = model.Columns;

                double minX, maxX;
                if (dragPos.X < _startDragPos.X)
                {
                    minX = dragPos.X;
                    maxX = _startDragPos.X;
                }
                else
                {
                    minX = _startDragPos.X;
                    maxX = dragPos.X;
                }

                double minY, maxY;
                if (dragPos.Y < _startDragPos.Y)
                {
                    minY = dragPos.Y;
                    maxY = _startDragPos.Y;
                }
                else
                {
                    minY = _startDragPos.Y;
                    maxY = dragPos.Y;
                }

                for (int row = 0; row < rows; row++)
                {
                    if (_startRow == -1)
                    {
                        if (_rowInfo[row].End > minY)
                        {
                            _startRow = row;
                        }
                    }
                    else if (_rowInfo[row].Start > maxY)
                    {
                        _endRow = row - 1;
                        break;
                    }
                }

                if ((_startRow >= 0) && (_endRow == -1))
                {
                    _endRow = rows - 1;
                }

                for (int col = 0; col < cols; col++)
                {
                    if (_startCol == -1)
                    {
                        if (_colInfo[col].End > minX)
                        {
                            _startCol = col;
                        }
                    }
                    else if (_colInfo[col].Start > maxX)
                    {
                        _endCol = col - 1;
                        break;
                    }
                }

                if ((_startCol >= 0) && (_endCol == -1))
                {
                    _endCol = cols - 1;
                }

                ExtendRangeToHaveEvenCellEdges();

                for (int row = 0; row < rows; row++)
                {
                    for (int col = 0; col < cols; col++)
                    {
                        ((GridZone)Preview.Children[model.CellChildMap[row, col]]).IsSelected = (row >= _startRow) && (row <= _endRow) && (col >= _startCol) && (col <= _endCol);
                    }
                }

                e.Handled = true;
            }

            OnPreviewMouseMove(e);
        }
Пример #33
0
        public void RaiseVerticalRulerMoveEvent(MouseEventArgs e)
        {
            Point mousePoint = e.GetPosition(this);

            mouseVerticalTrackLine.Y1 = mouseVerticalTrackLine.Y2 = mousePoint.Y;
        }
Пример #34
0
        private void MainPage_MouseMove(object sender, MouseEventArgs e)
        {
            if (!_isDragging)
                return;

            if (!SearchPopup.IsOpen)
                SearchPopup.IsOpen = true;

            Point position = e.GetPosition(null);

            SearchPopup.HorizontalOffset = position.X;
            SearchPopup.VerticalOffset = position.Y;
        }