Пример #1
0
        public static void Draw(DrawObject drawObj)
        {
            MoveObject move = drawObj as MoveObject;

            if (move == null || move.Picture == null)
            {
                return;
            }

            if ((PictureBoxStatus.IsMovable & move.Picture.Status) == PictureBoxStatus.IsMovable)
            {
                move.Picture.Location = new Point(move.LocationX - move.OffsetX, move.LocationY - move.OffsetY);
            }
        }
Пример #2
0
        private void OnMouseMove(object sender, MouseEventArgs e)
        {
            Point canvasPos = GetCanvasPoint(sender as Control, e.X, e.Y);

            lblPos.Invoke((MethodInvoker) delegate {
                lblPos.Text = canvasPos.ToString();
            });

            if (_paintTool != null)
            {
                DrawObject drObj = _paintTool.Draw(canvasPos.X, canvasPos.Y);
                SendDrawObject(drObj);
            }
        }
Пример #3
0
 public void AddDrawObject(long picID, DrawObject drawObj)
 {
     if (IsCleared || drawObj == null)
     {
         return;
     }
     lock (_canvasSync)
     {
         DrawObjectList drl;
         _editPBDrawObjects.TryGetValue(picID, out drl);
         if (drl != null)
         {
             drl.AddDrawObject(drawObj);
         }
     }
 }
Пример #4
0
        private void SendDrawObject(DrawObject drObj)
        {
            if (drObj == null || drObj.Picture == null)
            {
                return;
            }

            long        picBoxID = drObj.Picture.UniqueID; //canvas
            ICommandArg arg      = null;

            if (drObj is BrushLineObject)
            {
                BrushLineObject line = drObj as BrushLineObject;
                arg = new ArgBrushObject(_netClient.ClientID, picBoxID, line);
            }
            else if (drObj is LineObject)
            {
                LineObject line = drObj as LineObject;
                arg = new ArgLineObject(_netClient.ClientID, picBoxID, line);
            }
            else if (drObj is RectObject)
            {
                RectObject rect = drObj as RectObject;
                arg = new ArgRectObject(_netClient.ClientID, picBoxID, rect);
            }
            else if (drObj is EllipseObject)
            {
                EllipseObject ellipse = drObj as EllipseObject;
                arg = new ArgEllipseObject(_netClient.ClientID, picBoxID, ellipse);
            }
            else if (drObj is MoveObject)
            {
                MoveObject move = drObj as MoveObject;
                arg = new ArgMoveObject(_netClient.ClientID, picBoxID, move);
            }
            else if (drObj is SelectorObject)
            {
                SelectorObject selector = drObj as SelectorObject;
                arg = new ArgSelectorCopyObject(_netClient.ClientID, picBoxID, selector);
            }

            if (arg != null && _netClient.Connector != null)
            {
                _netClient.Connector.SendCommand(arg);
            }
        }
Пример #5
0
        private void OnMouseUp(object sender, MouseEventArgs e)
        {
            if (_paintTool != null)
            {
                Point      canvasPos = GetCanvasPoint(sender as Control, e.X, e.Y);
                DrawObject drObj     = _paintTool.Draw(canvasPos.X, canvasPos.Y);

                if (drObj is SelectorObject)
                {
                    SelectorObject selector = drObj as SelectorObject;
                    selector.NeedCopy = true;
                }

                SendDrawObject(drObj);
                _paintTool = null;
            }
        }
Пример #6
0
        public static void Draw(DrawObject drObj)
        {
            SelectorObject selector = drObj as SelectorObject;

            if (selector == null || selector.Picture == null ||
                selector.SourcePicture == null || selector.SourcePicture.Image == null)
            {
                return;
            }

            selector.Picture.Width    = selector.SizeX;
            selector.Picture.Height   = selector.SizeY;
            selector.Picture.Location = new Point(selector.LocationX, selector.LocationY);

            Bitmap bm = new Bitmap(selector.SizeX <= 0 ? 1 : selector.SizeX, selector.SizeY <= 0 ? 1 : selector.SizeY);

            using (Graphics gr = Graphics.FromImage(bm))
            {
                Rectangle rDest   = new Rectangle(0, 0, bm.Width, bm.Height);
                Rectangle rSource = new Rectangle(selector.LocationX, selector.LocationY, selector.SizeX, selector.SizeY);
                gr.FillRectangle(new SolidBrush(Color.Transparent), rDest);

                if (selector.NeedCopy)
                {
                    if ((PictureBoxStatus.IsDrawable & selector.Picture.Status) == PictureBoxStatus.IsDrawable)
                    {
                        GraphicsUnit units = GraphicsUnit.Pixel;
                        gr.DrawImage(selector.SourcePicture.Image, rDest, rSource, units);
                        selector.Picture.Image = bm;
                    }
                    if (selector.CutObject)
                    {
                        Graphics grSource = Graphics.FromImage(selector.SourcePicture.Image);
                        grSource.FillRectangle(new SolidBrush(Color.White), rSource);
                        selector.SourcePicture.Invalidate();
                    }
                }
            }
        }
Пример #7
0
        public static void Draw(DrawObject drawObj)
        {
            BrushLineObject line = drawObj as BrushLineObject;

            if (line == null || line.Picture == null || line.Picture.Image == null)
            {
                return;
            }
            if (line.Picture.Status != PictureBoxStatus.Canvas)
            {
                return;
            }
            using (Graphics gr = Graphics.FromImage(line.Picture.Image))
            {
                using (Pen pen = new Pen(new SolidBrush(line.BrushColor), line.BrushSize)){
                    gr.DrawLine(pen, new Point(line.LineStartX, line.LineStartY), new Point(line.LineEndX, line.LineEndY));
                }
                //чтобы не было разрывов между линиями
                using (Brush br = new SolidBrush(line.BrushColor)){
                    gr.FillEllipse(br, line.LineEndX - line.BrushSize / 2, line.LineEndY - line.BrushSize / 2, line.BrushSize, line.BrushSize);
                }
            }
            line.Picture.Invalidate();
        }