示例#1
0
        public static void Draw(DrawObject drawObj)
        {
            LineObject line = drawObj as LineObject;

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

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

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

            using (Graphics gr = Graphics.FromImage(bm)){
                gr.FillRectangle(new SolidBrush(Color.Transparent), new Rectangle(0, 0, bm.Width, bm.Height));

                if ((PictureBoxStatus.IsDrawable & line.Picture.Status) == PictureBoxStatus.IsDrawable)
                {
                    using (Pen pen = new Pen(new SolidBrush(line.BrushColor), line.BrushSize))
                    {
                        gr.DrawLine(pen, new Point(line.LinePoint1X, line.LinePoint1Y), new Point(line.LinePoint2X, line.LinePoint2Y));
                    }
                }
            }
            line.Picture.Image = bm;
            line.Picture.Invalidate();
        }
示例#2
0
        public bool UnPack(byte[] pack)
        {
            if (pack == null || pack.Length < 64)
            {
                return(false);
            }
            int ptr = 8;

            CliendID     = BytePacketReader.ReadLong(pack, ref ptr);
            PictureBoxID = BytePacketReader.ReadLong(pack, ref ptr);

            Line = new LineObject();

            byte cR = BytePacketReader.ReadByte(pack, ref ptr);
            byte cG = BytePacketReader.ReadByte(pack, ref ptr);
            byte cB = BytePacketReader.ReadByte(pack, ref ptr);
            byte cA = BytePacketReader.ReadByte(pack, ref ptr);

            Line.BrushColor = Color.FromArgb(cA, cR, cG, cB);

            Line.BrushSize   = BytePacketReader.ReadInt(pack, ref ptr);
            Line.SizeX       = BytePacketReader.ReadInt(pack, ref ptr);
            Line.SizeY       = BytePacketReader.ReadInt(pack, ref ptr);
            Line.LocationX   = BytePacketReader.ReadInt(pack, ref ptr);
            Line.LocationY   = BytePacketReader.ReadInt(pack, ref ptr);
            Line.LinePoint1X = BytePacketReader.ReadInt(pack, ref ptr);
            Line.LinePoint1Y = BytePacketReader.ReadInt(pack, ref ptr);
            Line.LinePoint2X = BytePacketReader.ReadInt(pack, ref ptr);
            Line.LinePoint2Y = BytePacketReader.ReadInt(pack, ref ptr);

            return(true);
        }
示例#3
0
        private void NCDrawByLine(IConnector connection, ArgLineObject arg)
        {
            if (arg == null || arg.PictureBoxID == 0)
            {
                return;
            }
            LineObject line = arg.Line;

            line.Picture = _canvas.GetEditablePictureBox(arg.PictureBoxID);
            _canvas.AddDrawObject(arg.PictureBoxID, line);
        }
示例#4
0
        public ArgLineObject(long clientID, long pictureID, LineObject line)
        {
            if (line == null)
            {
                throw new ArgumentNullException("line is null");
            }

            CliendID     = clientID;
            PictureBoxID = pictureID;

            Line = line;
        }
示例#5
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);
            }
        }
示例#6
0
        private void NCDrawByLine(IConnector connection, ArgLineObject arg)
        {
            if (arg.PictureBoxID == 0)
            {
                return;
            }
            long assocID = GetPictureBoxAssociationID(arg.PictureBoxID);

            if (assocID == 0)
            {
                return;
            }

            arg.PictureBoxID = assocID;
            LineObject line = arg.Line;

            line.Picture = _canvas.GetEditablePictureBox(arg.PictureBoxID);
            _canvas.AddDrawObject(arg.PictureBoxID, line);
            AddCommandToSendClients(arg);
        }
示例#7
0
        public DrawObject GetDrawObject(int pX, int pY)
        {
            LineObject line = new LineObject();

            line.Picture    = _picture;
            line.BrushColor = _color;
            line.BrushSize  = _brushSize;

            line.SizeX = Math.Abs(pX - _startX); if (line.SizeX < line.BrushSize)
            {
                line.SizeX = line.BrushSize;
            }
            line.SizeY = Math.Abs(pY - _startY); if (line.SizeY < line.BrushSize)
            {
                line.SizeY = line.BrushSize;
            }
            int LocationX = pX < _startX ? pX : _startX;

            line.LocationX = line.SizeX == line.BrushSize ? LocationX - line.BrushSize / 2 : LocationX;

            int LocationY = pY < _startY ? pY : _startY;

            line.LocationY = line.SizeY == line.BrushSize ? LocationY - line.BrushSize / 2 : LocationY;

            Point p1         = _picture.PointToScreen(new Point(_startX - LocationX, _startY - LocationY));
            Point linePoint1 = _picture.PointToClient(p1);
            Point p2         = _picture.PointToScreen(new Point(pX - LocationX, pY - LocationY));
            Point linePoint2 = _picture.PointToClient(p2);

            line.LinePoint1X = linePoint1.X;
            line.LinePoint1Y = linePoint1.Y;
            line.LinePoint2X = linePoint2.X;
            line.LinePoint2Y = linePoint2.Y;

            return(line);
        }