Beispiel #1
0
        private void pictMain_MouseMove(object sender, MouseEventArgs e)
        {
            Point relativePoint = new Point(e.Location.X - _imageRectangle.X, e.Location.Y - _imageRectangle.Y);

            if (_drawObjectType == null)
            {
                moveDeselected(relativePoint, e);
                return;
            }

            _resizeRectangle = default(KeyValuePair <Rectangle, Cursor>);

            if (_imageRectangle.Contains(e.Location))
            {
                //if (_drawObjectType.Equals(typeof(FillDrawObject)))
                //	this.Cursor = Cursors.
                //else
                this.Cursor = Cursors.Cross;
                if (!_drawObjectType.Equals(typeof(TextDrawObject)))
                {
                    if (_mouseDownLocation != Point.Empty)
                    {
                        redraw(false);
                        CurrentDrawObject.Draw(new Point((int)(relativePoint.X / _zoomMultiplier),
                                                         (int)(relativePoint.Y / _zoomMultiplier)));
                        pictMain.Refresh();
                    }
                }
            }
            else
            {
                this.Cursor = Cursors.Default;
            }
        }
Beispiel #2
0
        private void redraw(bool refresh, bool ignoreSelection = false)
        {
            _currGraphics.Clear(Color.Empty);
            if (_originalImage == null)
            {
                return;
            }

            drawObjects(null);

            if (CurrentDrawObject is SelectDrawObject && !ignoreSelection)
            {
                CurrentDrawObject.Draw();
            }

            if (refresh)
            {
                pictMain.Refresh();
            }
        }
Beispiel #3
0
        private void pictMain_MouseDown(object sender, MouseEventArgs e)
        {
            endText();

            var previouslySelected = CurrentDrawObject;

            deselect(true);
            if (_drawObjectType == null)
            {
                for (int i = _drawObjects.Count - 1; i >= 0; i--)
                {
                    var dobj = _drawObjects[i];
                    if (dobj.IsInDrawObject(new Point(e.Location.X - _imageRectangle.X,
                                                      e.Location.Y - _imageRectangle.Y)) ||
                        (previouslySelected != null && previouslySelected.Equals(dobj) && _resizeRectangle.Key != Rectangle.Empty))
                    {
                        CurrentDrawObject          = dobj;
                        CurrentDrawObject.Selected = true;
                        _lock                = true;
                        chkErase.Checked     = CurrentDrawObject.Erase;
                        chkHighlight.Checked = CurrentDrawObject.Highlight;
                        _color               = CurrentDrawObject.GetColor();
                        _currentLineWidth    = CurrentDrawObject.GetWidth();
                        updateColorWidth(true);
                        _lock = false;
                        setVisibilities();

                        addUndoAction(UndoActionType.MoveResize);
                        if (_resizeRectangle.Key != Rectangle.Empty)
                        {
                            CurrentDrawObject.StartResize(_resizeRectangle.Key);
                        }


                        btnDelete.Visible = true;

                        redraw(true);
                        _mouseDownLocation = e.Location;
                        break;
                    }
                }
            }

            if (previouslySelected != null && previouslySelected is SelectDrawObject && _cropRectangle == Rectangle.Empty)
            {
                removeCurrentDrawObject(previouslySelected);
                redraw(true);
            }

            if (_drawObjectType == null)
            {
                return;
            }

            if (_imageRectangle.Contains(e.Location))
            {
                _mouseDownLocation = e.Location;
                CurrentDrawObject  = DrawObject.CreateDrawObject(_drawObjectType,
                                                                 !_drawObjects.Any() ? 1 : _drawObjects.Max(d => d.ID) + 1,
                                                                 _currGraphics, new Pen(CurrentColor, CurrentWidth),
                                                                 new Point((int)((_mouseDownLocation.X - _imageRectangle.X) / _zoomMultiplier),
                                                                           (int)((_mouseDownLocation.Y - _imageRectangle.Y) / _zoomMultiplier)),
                                                                 _zoomMultiplier);

                CurrentDrawObject.Erase     = chkErase.Checked;
                CurrentDrawObject.Highlight = chkHighlight.Checked;

                if (CurrentDrawObject is IRadiusDrawObject)
                {
                    (CurrentDrawObject as IRadiusDrawObject).CurrentImage = _bmp;
                    (CurrentDrawObject as IRadiusDrawObject).Radius       = CurrentRadius;
                }

                if (_drawObjectType.GetInterface(typeof(ITextDrawObject).Name) != null)
                {
                    (CurrentDrawObject as ITextDrawObject).Font = CurrentFont;
                }

                if (CurrentDrawObject is NumberDrawObject)
                {
                    (CurrentDrawObject as NumberDrawObject).CurrentText = _drawObjects.Count(d => d is NumberDrawObject).ToString();
                }

                if (_drawObjectType.Equals(typeof(TextDrawObject)))
                {
                    redraw(false);
                    //(CurrentDrawObject as TextDrawObject).Typing = true;
                    CurrentDrawObject.Draw(new Point((int)((e.Location.X - _imageRectangle.X) / _zoomMultiplier),
                                                     (int)((e.Location.Y - _imageRectangle.Y) / _zoomMultiplier)));
                    //pictMain.Focus();
                    //pictMain.LostFocus += pictMain_LostFocus;
                    //pictMain.KeyPress += pictMain_KeyPress;
                }
            }
        }