Esempio n. 1
0
        private void canvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (!IsSelectable)
            {
                return;
            }
            MainCanvas.CaptureMouse();  //Capture mouse to receive events even if the pointer is outside the control

            //Start dragging:
            _draggingState.StartDragging(WpfCanvasScoreRenderer.ConvertPoint(e.GetPosition(MainCanvas)));

            //Check if element under cursor is staff element:
            FrameworkElement element = e.OriginalSource as FrameworkElement;

            if (element == null)
            {
                return;
            }
            if (!Renderer.OwnershipDictionary.ContainsKey(element))
            {
                return;
            }

            //Set selected element:
            Select(Renderer.OwnershipDictionary[element]);
        }
Esempio n. 2
0
        private void MainCanvas_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            currentAction = Actions.rotating;

            if (SelectedImage == null)
            {
                var image = e.Source as Image;
                if (image == baseImage)
                {
                    return;
                }
                SelectedImage = image;
            }

            if (MainCanvas.CaptureMouse())
            {
                initialClickPosition.X = Canvas.GetLeft(SelectedImage) + SelectedImage.ActualWidth / 2;;
                initialClickPosition.Y = Canvas.GetTop(SelectedImage) + SelectedImage.ActualHeight / 2;;
                rotateLine.X1          = initialClickPosition.X;
                rotateLine.Y1          = initialClickPosition.Y;
                rotateLine.X2          = e.GetPosition(MainCanvas).X;
                rotateLine.Y2          = e.GetPosition(MainCanvas).Y;
                oldAngle = Math2D.AngleBetween(new Vector(1, 0), new Vector(rotateLine.X2 - rotateLine.X1, rotateLine.Y2 - rotateLine.Y1));
                Panel.SetZIndex(SelectedImage, 2);
            }
        }
        private void Canvas_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (loading)
            {
                return;
            }

            Keyboard.Focus(MainCanvas);

            mouseDownPoint    = e.GetPosition((UIElement)MainCanvas.Parent);
            mouseDownPoint.X -= translate.X;
            mouseDownPoint.Y -= translate.Y;
            MainCanvas.CaptureMouse();
        }
Esempio n. 4
0
        private void MainCanvas_OnMouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.RightButton == MouseButtonState.Pressed)
            {
                ResetSelection();
            }

            if (e.LeftButton != MouseButtonState.Pressed)
            {
                return;
            }

            _firstPoint = e.GetPosition(MainCanvas);

            if (RegionRectangle.Visibility == Visibility.Collapsed)
            {
                RegionRectangle.Visibility = Visibility.Visible;

                HorizontalLine.Visibility = VerticalLine.Visibility = Visibility.Collapsed;

                MainCanvas.CaptureMouse();

                _isMouseLeftButtonDown = true;
            }
            else
            {
                _isMouseLeftButtonDown = false;

                MainCanvas.ReleaseMouseCapture();

                var shape = RegionRectangle as Shape;
                Util.TryBoundShapeToCanvas(ref shape, MainCanvas);

                MainCanvas.Cursor = Cursors.Arrow;

                if (SelectedRegionCompleted == null)
                {
                    return;
                }

                var x      = Convert.ToInt32(Canvas.GetLeft(RegionRectangle));
                var y      = Convert.ToInt32(Canvas.GetTop(RegionRectangle));
                var width  = Convert.ToInt32(RegionRectangle.Width);
                var height = Convert.ToInt32(RegionRectangle.Height);

                SelectedRegion = new Int32Rect(x, y, width, height);

                SelectedRegionCompleted(this, SelectedRegion);
            }
        }
Esempio n. 5
0
        private void MainCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            var image = e.Source as Image;

            if (image == baseImage)
            {
                return;
            }

            if (image != null && MainCanvas.CaptureMouse())
            {
                currentAction        = Actions.dragging;
                initialClickPosition = e.GetPosition(MainCanvas);
                SelectedImage        = image;
                Panel.SetZIndex(SelectedImage, 2); // in case of multiple images
            }
        }
Esempio n. 6
0
        private void MainWindow1_MouseDown(object sender, MouseButtonEventArgs e)
        {
            var rekt = VisualBrush.Viewport;

            var cellPos = e.GetPosition(MainCanvas);
            int tempX   = (int)(cellPos.X / rekt.Width);
            int tempY   = (int)(cellPos.Y / rekt.Height);

            if (e.ChangedButton == MouseButton.Left && e.ButtonState == MouseButtonState.Pressed)
            {
                Rectangle ClickedRectangle = null;

                if (tempX >= Width && tempY >= Height)
                {
                    return;
                }

                if (_lGrid.LogicGrid1[tempX, tempY] != (int)GlobalSettings.States.Empty)
                {
                    try
                    {
                        ClickedRectangle =
                            VisualTreeHelper.HitTest(MainCanvas, cellPos).VisualHit as Rectangle;



                        if (Equals(ClickedRectangle.Fill, GlobalSettings.StateColors[(int)GlobalSettings.States.Alive]))
                        {
                            ClickedRectangle.Fill           = GlobalSettings.StateColors[(int)GlobalSettings.States.Dead];
                            _lGrid.LogicGrid1[tempX, tempY] = (int)GlobalSettings.States.Dead;

                            return;
                        }
                        if (Equals(ClickedRectangle.Fill, GlobalSettings.StateColors[(int)GlobalSettings.States.Dead]))
                        {
                            MainCanvas.Children.Remove(ClickedRectangle);
                            _visualRectangle.Remove(new Point(tempX, tempY));
                            _lGrid.LogicGrid1[tempX, tempY] = (int)GlobalSettings.States.Empty;
                            return;
                        }
                    }
                    catch (NullReferenceException)
                    {
                    }
                }
                else
                {
                    var newCell = new Rectangle
                    {
                        Width  = rekt.Width,
                        Height = rekt.Height,
                        Fill   = GlobalSettings.StateColors[(int)GlobalSettings.States.Alive],
                        Tag    = new Point(tempX, tempY)
                    };



                    Canvas.SetLeft(newCell, tempX * newCell.Width);
                    Canvas.SetTop(newCell, tempY * newCell.Height);


                    _lGrid.LogicGrid1[tempX, tempY] = (int)GlobalSettings.States.Alive;
                    _visualRectangle.Add(new Point(tempX, tempY), newCell);

                    MainCanvas.Children.Add(newCell);
                }
            }



            if (e.ChangedButton == MouseButton.Right && e.ButtonState == MouseButtonState.Pressed)
            {
                _startPoint    = e.GetPosition(MainCanvas);
                _originalPoint = new Point(TranslateTransform.X, TranslateTransform.Y);
                if (!flag)
                {
                    MainCanvas.CaptureMouse();
                    flag = true;
                }
                else
                {
                    MainCanvas.ReleaseMouseCapture();
                    flag = false;
                }
            }


            else if (e.ChangedButton == MouseButton.Right && e.ButtonState == MouseButtonState.Released)
            {
                MainCanvas.ReleaseMouseCapture();
                flag = false;
            }
        }