Example #1
0
        private void numAlpha_ValueChanged(object sender, EventArgs e)
        {
            if (_lock)
            {
                return;
            }

            CurrentColor = Color.FromArgb((int)numAlpha.Value, CurrentColor);
            if (CurrentDrawObject != null)
            {
                CurrentDrawObject.UpdateColor(CurrentColor);
                redraw(true);
            }
            if (chkErase.Checked)
            {
                EraseColor = CurrentColor;
            }
            else if (chkHighlight.Checked)
            {
                HighlightColor = CurrentColor;
            }
            else
            {
                DrawColor = CurrentColor;
            }
        }
Example #2
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;
            }
        }
Example #3
0
 private void btnColor_Click(object sender, EventArgs e)
 {
     dlgColor.Color = CurrentColor;
     if (dlgColor.ShowDialog() == DialogResult.OK)
     {
         CurrentColor = Color.FromArgb((int)numAlpha.Value, dlgColor.Color);
         if (CurrentDrawObject != null)
         {
             CurrentDrawObject.UpdateColor(CurrentColor);
             redraw(true);
         }
         if (chkErase.Checked)
         {
             EraseColor = CurrentColor;
         }
         else if (chkHighlight.Checked)
         {
             HighlightColor = CurrentColor;
         }
         else
         {
             DrawColor = CurrentColor;
         }
     }
 }
Example #4
0
 private void addUndoAction(UndoActionType type)
 {
     if (CurrentDrawObject == null)
     {
         return;
     }
     _undos.Push(new UndoAction()
     {
         UndoActionType = type,
         DrawObject     = CurrentDrawObject.GetSerializable()
     });
 }
Example #5
0
        private void undoRedo(UndoAction action, Stack <UndoAction> opposites, bool redo)
        {
            var opposite = new UndoAction();

            if (action.UndoActionType == UndoActionType.AddDrawObject)
            {
                opposite.UndoActionType = UndoActionType.DeleteDrawObject;
            }
            else if (action.UndoActionType == UndoActionType.DeleteDrawObject)
            {
                opposite.UndoActionType = UndoActionType.AddDrawObject;
            }
            else
            {
                opposite.UndoActionType = action.UndoActionType;
            }

            if (action.UndoActionType == UndoActionType.DeleteDrawObject)
            {
                CurrentDrawObject   = DrawObject.FromSerialized(_currGraphics, action.DrawObject, _zoomMultiplier);
                opposite.DrawObject = CurrentDrawObject.GetSerializable();
                _drawObjects.Add(CurrentDrawObject);
            }
            else
            {
                var drawObj = _drawObjects.First(d => d.ID == action.DrawObject.ID);
                opposite.DrawObject = drawObj.GetSerializable();
                if (action.UndoActionType == UndoActionType.AddDrawObject)
                {
                    _drawObjects.Remove(drawObj);
                }
                else if (action.UndoActionType == UndoActionType.CropImage)
                {
                    _cropRectangle = redo ?
                                     (CurrentDrawObject as SelectDrawObject).GetSelectionRectangle()
                                                : Rectangle.Empty;
                    LoadImage(true);
                }
                else
                {
                    drawObj.Undo(action.DrawObject);
                }
            }

            opposites.Push(opposite);

            serializeDrawObjects();

            redraw(true);
        }
Example #6
0
        //private void pictMain_KeyPress(object sender, KeyPressEventArgs e)
        //{
        //	if (CurrentDrawObject is TextDrawObject)
        //	{
        //		if (e.KeyChar == 13)
        //			(CurrentDrawObject as TextDrawObject).CurrentText += "\r\n";
        //		else
        //			(CurrentDrawObject as TextDrawObject).CurrentText += e.KeyChar.ToString();
        //		redraw(true);
        //	}
        //}

        private void pictMain_MouseUp(object sender, MouseEventArgs e)
        {
            if (CurrentDrawObject != null && !_drawObjects.Contains(CurrentDrawObject))
            {
                _drawObjects.Add(CurrentDrawObject);
                addUndoAction(UndoActionType.AddDrawObject);
                if (!(CurrentDrawObject is TextDrawObject))
                {
                    serializeDrawObjects();
                }
                btnCrop.Visible            = CurrentDrawObject is SelectDrawObject;
                CurrentDrawObject.Selected = true;
                //if (!(_currentDrawObject is TextDrawObject) && !(_currentDrawObject is SelectDrawObject))
                //	_currentDrawObject = null;
                _lock = true;
                foreach (var tool in _tools)
                {
                    tool.Checked = false;
                }
                _drawObjectType = null;
                setVisibilities();
                _lock = false;
                if (CurrentDrawObject is FillDrawObject)
                {
                    drawObjects(CurrentDrawObject as FillDrawObject);
                }

                redraw(true);
            }
            else if (CurrentDrawObject != null)
            {
                var peek = _undos.Peek();
                if (peek.UndoActionType == UndoActionType.MoveResize)
                {
                    var test = CurrentDrawObject.GetSerializable();
                    if (test.ID == peek.DrawObject.ID &&
                        test.StartPoint.X == peek.DrawObject.StartPoint.X &&
                        test.StartPoint.Y == peek.DrawObject.StartPoint.Y &&
                        test.EndPoint.X == peek.DrawObject.EndPoint.X &&
                        test.EndPoint.Y == peek.DrawObject.EndPoint.Y)
                    {
                        _undos.Pop();
                    }
                }
                serializeDrawObjects();
            }

            _mouseDownLocation = Point.Empty;
        }
Example #7
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();
            }
        }
Example #8
0
        private void moveDeselected(Point newPoint, MouseEventArgs e)
        {
            var cursor = Cursors.Default;

            foreach (var dobj in _drawObjects)
            {
                if (dobj.IsInDrawObject(newPoint))
                {
                    cursor = Cursors.Hand;
                }
            }

            if (CurrentDrawObject != null)
            {
                if (_mouseDownLocation != Point.Empty)
                {
                    if (_resizeRectangle.Key != Rectangle.Empty)
                    {
                        cursor = _resizeRectangle.Value;
                        CurrentDrawObject.ResizeTo(newPoint);
                    }
                    else
                    {
                        CurrentDrawObject.MoveTo(_mouseDownLocation, e.Location);
                    }
                    _mouseDownLocation = e.Location;
                    redraw(true);
                }
                else if ((_resizeRectangle = CurrentDrawObject.GetResizeRectangle(newPoint)).Key
                         != Rectangle.Empty)
                {
                    cursor = _resizeRectangle.Value;
                }
                else if (CurrentDrawObject.IsInDrawObject(newPoint))
                {
                    cursor = Cursors.Hand;
                }
            }

            this.Cursor = cursor;
        }
Example #9
0
        private void pictMain_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Delete)
            {
                DeleteCurrentDrawObject();
            }
            else if (e.KeyCode == Keys.Z && e.Modifiers == Keys.Control)
            {
                btnUndo_Click(sender, e);
            }
            else if (e.KeyCode == Keys.Y && e.Modifiers == Keys.Control)
            {
                btnRedo_Click(sender, e);
            }
            else if (e.KeyCode == Keys.C && e.Modifiers == Keys.Control)
            {
                btnCopy_Click(sender, e);
            }
            else if (e.KeyCode == Keys.S && e.Modifiers == Keys.Control)
            {
                btnSave_Click(sender, e);
            }
            else if ((e.KeyCode == Keys.Down || e.KeyCode == Keys.Up || e.KeyCode == Keys.Left || e.KeyCode == Keys.Right) &&
                     CurrentDrawObject != null)
            {
                int xDelta = 0;
                int yDelta = 0;
                if (e.KeyCode == Keys.Down)
                {
                    yDelta = 1;
                }
                else if (e.KeyCode == Keys.Up)
                {
                    yDelta = -1;
                }
                else if (e.KeyCode == Keys.Left)
                {
                    xDelta = -1;
                }
                else if (e.KeyCode == Keys.Right)
                {
                    xDelta = 1;
                }

                if (e.Modifiers == Keys.Control)
                {
                    xDelta *= 10;
                    yDelta *= 10;
                }

                if (e.Modifiers == Keys.Shift)
                {
                    CurrentDrawObject.MoveEnd(xDelta, yDelta);
                }
                else
                {
                    CurrentDrawObject.Move(xDelta, yDelta);
                }
                redraw(true);
            }
        }
Example #10
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;
                }
            }
        }
Example #11
0
        private void setVisibilities()
        {
            Type[] lineToolTypes = new Type[]
            {
                typeof(ArrowDrawObject),
                typeof(EllipseDrawObject),
                typeof(RectangleDrawObject),
                typeof(LineDrawObject),
                typeof(DoubleArrowDrawObject),
                typeof(FreeFormDrawObject),
                typeof(CurlyBracesDrawObject)
            };

            pnlLineTools.Visible = (_drawObjectType != null && lineToolTypes.Contains(_drawObjectType)) ||
                                   (CurrentDrawObject != null && lineToolTypes.Contains(CurrentDrawObject.GetType()));

            btnFont.Visible = (_drawObjectType != null && _drawObjectType.GetInterface(typeof(ITextDrawObject).Name) != null) ||
                              (CurrentDrawObject != null && CurrentDrawObject is ITextDrawObject);

            pnlBlurTools.Visible = (_drawObjectType != null && _drawObjectType.GetInterface(typeof(IRadiusDrawObject).Name) != null) ||
                                   (CurrentDrawObject != null && CurrentDrawObject is IRadiusDrawObject);
        }