Example #1
0
 public override void OnKeyUp(CanvasPanel canvasPanel, KeyEventArgs e)
 {
     if (e.KeyCode==Keys.Delete && SelectedShape!=null)
        {
        DeleteSelectedShape(canvasPanel);
        canvasPanel.Refresh();
        }
 }
Example #2
0
 public override void OnKeyUp(CanvasPanel canvasPanel, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Escape && _activePolygon!=null)
     {
         ShapeCancelledEvent.Invoke(this,new ShapeEventArgs(_activePolygon));
         this._activePolygon = null;
         canvasPanel.Refresh();
     }
 }
Example #3
0
 public override void OnMouseDoubleClick(CanvasPanel canvasPanel, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         if (SelectedShape != null)
         {
             using (var editShapeDialog = new EditShapeDialog(SelectedShape))
             {
                 editShapeDialog.ShowDialog();
                 canvasPanel.Refresh();
             }
         }
     }
 }
Example #4
0
        public override void OnMouseDown(CanvasPanel canvasPanel, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                SelectedShape = GetClickedShape(canvasPanel, e);
                if (this.SelectedShape != null)
                {
                    canvasPanel.Cursor = Cursors.SizeAll;
                    _dragInfo = new DragInfo(e, SelectedShape.GetHandlerAt(e.Location));
                }

            }

            canvasPanel.Refresh();
        }
Example #5
0
        public override void OnDeactivate(CanvasPanel canvasPanel)
        {
            if (this._activePolygon!=null)
            {
                if (!_activePolygon.Created)
                {
                    if (_activePolygon.Vertices.Count >= 3)
                        _activePolygon.Created = true;
                    else
                        canvasPanel.Shapes.Remove(_activePolygon);
                }

                _activePolygon = null;
                canvasPanel.Refresh();
            }
        }
Example #6
0
        public override void OnMouseDown(CanvasPanel canvasPanel, MouseEventArgs e)
        {
            if (_activePolygon == null)
            {
                _activePolygon = new Polygon(canvasPanel.CurrentColor, canvasPanel.CurrentLineWidth);
                canvasPanel.Shapes.Insert(0,_activePolygon);
                _activePolygon.AddVertex(e.Location);
            }

            //Wierzchołek, którym będziemy poruszać
            _activePolygon.AddVertex(e.Location);

            if (_activePolygon.Created)
                ShapeCreatedEvent.Invoke(this,new ShapeEventArgs(_activePolygon));

            canvasPanel.Refresh();
        }
Example #7
0
        private void Init()
        {
            _canvasPanel = new CanvasPanel();
            mainWindowSplitContainer.Panel2.Controls.Add(_canvasPanel);
            mainWindowSplitContainer.FixedPanel = FixedPanel.Panel1;
            _canvasPanel.Location = new Point(3, 3);
            _canvasPanel.Anchor = AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Top | AnchorStyles.Right;
            _canvasPanel.Size = new Size(_canvasPanel.Parent.Width - 8, _canvasPanel.Parent.Height - 5);

            _canvasPanel.MouseMove += canvasPanel_MouseMove;
            _canvasPanel.ToolChangedEvent += canvasPanel_ToolChangedEvent;
            this.Resize += MainForm_Resize;
            _canvasPanel.Paint += canvasPanel_Paint;

            pixelCountLabel.Text = string.Format("Liczba pixeli: " + GraphicsExtensions.PixelCount);
            canvasSizeLabel.Text = string.Format("Rozmiar: " + _canvasPanel.Width + " x " + _canvasPanel.Height);
        }
Example #8
0
 public virtual void OnKeyUp(CanvasPanel canvasPanel,KeyEventArgs e)
 {
 }
Example #9
0
 public override void OnDeactivate(CanvasPanel canvasPanel)
 {
     this.SelectedShape = null;
 }
Example #10
0
 public override void OnActivate(CanvasPanel canvasPanel)
 {
     base.OnActivate(canvasPanel);
 }
Example #11
0
 private void DeleteSelectedShape(CanvasPanel canvasPanel)
 {
     canvasPanel.Shapes.Remove(SelectedShape);
     SelectedShape = null;
 }
Example #12
0
        private Shape GetClickedShape(CanvasPanel canvasPanel, MouseEventArgs e)
        {
            foreach (var shape in canvasPanel.Shapes)
            {
                if (shape.GetHandlerAt(e.Location) > -1)
                    return shape;

                if (shape.Contains(e.Location))
                    return shape;
            }
            return null;
        }
Example #13
0
        public override void OnMouseUp(CanvasPanel canvasPanel, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                canvasPanel.Cursor = this.Cursor;
                _dragInfo = null;
            }
            else if (e.Button==MouseButtons.Right)
            {
                if (_selectedShape!=null)
                {
                    if (_selectedShape.GetType() == typeof(Polygon))
                    {
                        var poly = (Polygon) SelectedShape;
                        int clickedHandler = _selectedShape.GetHandlerAt(e.Location);
                        if (clickedHandler > -1)
                        {
                            poly.RemoveVertex(clickedHandler);
                        }
                        else
                        {
                            poly.AddVertex(e.Location);
                        }

                    }

                    canvasPanel.Refresh();
                }
            }
        }
Example #14
0
 public virtual void OnMouseUp(CanvasPanel canvasPanel, MouseEventArgs e)
 {
 }
Example #15
0
 public override void OnMouseUp(CanvasPanel canvasPanel, MouseEventArgs e)
 {
 }
Example #16
0
        public override void OnMouseMove(CanvasPanel canvasPanel, MouseEventArgs e)
        {
            if (_activePolygon != null)
            {
                _activePolygon.Vertices[_activePolygon.Vertices.Count - 1] = e.Location;
            }

            canvasPanel.Refresh();
        }
Example #17
0
 public virtual void OnDeactivate(CanvasPanel canvasPanel)
 {
 }
Example #18
0
 public override void OnMouseMove(CanvasPanel canvasPanel, MouseEventArgs e)
 {
     if (_selectedShape != null && _dragInfo != null)
     {
         _dragInfo.CurrentPosition = e.Location;
         if (_dragInfo.Button == MouseButtons.Left)
         {
             if (_dragInfo.DraggedHandlerNumber>-1)
             {
                 _selectedShape.MoveHandler(_dragInfo.DraggedHandlerNumber,_dragInfo.DragDelta.X,_dragInfo.DragDelta.Y);
             }
             else
             {
                 _selectedShape.Move(_dragInfo.DragDelta.X, _dragInfo.DragDelta.Y);
             }
         }
         canvasPanel.Refresh();
     }
     else if (_selectedShape!=null && _dragInfo==null && _selectedShape.GetHandlerAt(e.Location)>-1)
     {
         canvasPanel.Cursor = Cursors.Hand;
     }
     else
     {
         canvasPanel.Cursor = this.Cursor;
     }
 }
Example #19
0
 public virtual void OnMouseDoubleClick(CanvasPanel canvasPanel, MouseEventArgs e)
 {
 }