public ArgSelectorCopyObject(long clientID, long pictureID, SelectorObject selectorObj) { if (selectorObj == null) { throw new ArgumentNullException("Selector object is null"); } _clientID = clientID; Selector = selectorObj; PictureBoxID = pictureID; }
private void NCSelectedRect(IConnector connector, ArgSelectorCopyObject arg) { if (arg == null || arg.PictureBoxID == 0) { return; } SelectorObject selector = arg.Selector; selector.Picture = _canvas.GetEditablePictureBox(arg.PictureBoxID); selector.SourcePicture = _canvas.BackPicture; _canvas.AddDrawObject(arg.PictureBoxID, selector); }
public DrawObject GetDrawObject(int pX, int pY) { SelectorObject selector = new SelectorObject(); selector.Picture = _picture; selector.SourcePicture = _source; selector.NeedCopy = _needCopy; selector.CutObject = _isCutted; selector.SizeX = Math.Abs(pX - _startX); selector.SizeY = Math.Abs(pY - _startY); selector.LocationX = pX < _startX ? pX : _startX; selector.LocationY = pY < _startY ? pY : _startY; return(selector); }
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); } }
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; } }
public bool UnPack(byte[] pack) { if (pack == null || pack.Length < 42) { return(false); } int ptr = 8; _clientID = BytePacketReader.ReadLong(pack, ref ptr); PictureBoxID = BytePacketReader.ReadLong(pack, ref ptr); Selector = new SelectorObject(); Selector.LocationX = BytePacketReader.ReadInt(pack, ref ptr); Selector.LocationY = BytePacketReader.ReadInt(pack, ref ptr); Selector.SizeX = BytePacketReader.ReadInt(pack, ref ptr); Selector.SizeY = BytePacketReader.ReadInt(pack, ref ptr); Selector.CutObject = BytePacketReader.ReadBoolean(pack, ref ptr); Selector.NeedCopy = BytePacketReader.ReadBoolean(pack, ref ptr); return(true); }
private void NCSelectCopyRect(IConnector connection, ArgSelectorCopyObject arg) { if (arg.PictureBoxID == 0) { return; } long assocID = GetPictureBoxAssociationID(arg.PictureBoxID); if (assocID == 0) { return; } arg.PictureBoxID = assocID; SelectorObject selector = arg.Selector; selector.Picture = _canvas.GetEditablePictureBox(arg.PictureBoxID); selector.SourcePicture = _canvas.BackPicture; _canvas.AddDrawObject(arg.PictureBoxID, selector); AddCommandToSendClients(arg); }
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(); } } } }