private void TickCreateNewPictureBoxes() { ArgNewPictureBox[] pbs = null; lock (_npbSync) { pbs = _incomingPictureBoxes.DequeueAll(); } if (pbs != null) { for (int i = 0; i < pbs.Length; i++) { ArgNewPictureBox arg = pbs[i]; PictureBoxObj pic = new PictureBoxObj(arg.ClientID, arg.PictureBoxID, PictureBoxStatus.IsMovable | PictureBoxStatus.IsDrawable); if (arg.PBImage != null) { pic.Image = arg.PBImage; pic.Width = arg.PBImage.Width; pic.Height = arg.PBImage.Height; } else { pic.BackColor = Color.Transparent; } _canvas.AddPictureObj(pic, new Point(arg.LocationX, arg.LocationY)); } } }
private void pnlImage_DragDrop(object sender, DragEventArgs e) { string[] drops = (string[])e.Data.GetData(DataFormats.FileDrop, false); if (drops != null && drops.Length > 0) { string fileName = Path.GetFileName(drops[0]); Image img = Bitmap.FromFile(drops[0]); if (img == null) { return; } if (_canvas.IsCleared) { SendComNewCanvas(img.Width, img.Height, img); } else { Point cp = _canvas.PointToClient(new Point(e.X, e.Y)); if (_movedControl != null) { SendApplyPictureBox(_movedControl.UniqueID); _movedControl.Dispose(); _movedControl = null; } _movedControl = CreateNewPictureBox(img, cp); } } }
private bool TickCreateNewCanvas() { if (_incomingCanvas != null) { ArgNewPictureBox arg = _incomingCanvas; _incomingCanvas = null; _canvas.Clear(); lock (_npbSync){ _newPB.Clear(); _clientServerPictureBoxID.Clear(); } lock (_astSync){ _argsSendToAllClients.Clear(); _argsSendToAllClients = null; } PictureBoxObj pb = new PictureBoxObj(arg.ClientID, 0, PictureBoxStatus.Canvas); pb.BorderStyle = BorderStyle.FixedSingle; pb.Width = arg.PBImage.Width; pb.Height = arg.PBImage.Height; pb.Image = arg.PBImage; _canvas.SetCanvas(pb); AppLogger.Log("New canvas created by " + arg.ClientID); lock (_astSync) { _argsSendToAllClients = new List <ICommandArg>(); } return(true); } return(false); }
public void SetCanvas(PictureBoxObj pb) { lock (_canvasSync) { if (pb == null || pb.Image == null) { return; } Width = pb.Width; Height = pb.Height; _backPicture = pb; this.Controls.Add(_backPicture); _backPicture.SendToBack(); _backPicture.Invalidate(); _frontPicture = new PictureBoxObj(_backPicture.ClientID, _backPicture.UniqueID, PictureBoxStatus.Canvas); this.Controls.Add(_frontPicture); _frontPicture.Width = pb.Width; _frontPicture.Height = pb.Width; _frontPicture.Image = new Bitmap(Width, Height); _frontPicture.BringToFront(); _editPBDrawObjects[0] = new DrawObjectList(0); } _isCleared = false; _needUpdateFrontPicture = true; AppLogger.Log("Picture loaded: width " + Width + ", height " + Height); }
private void OnMouseDown(object sender, MouseEventArgs e) { PictureBoxObj picObj = sender as PictureBoxObj; if (e.Button == MouseButtons.Right || picObj != _movedControl) { if (_movedControl != null) { SendApplyPictureBox(_movedControl.UniqueID); _movedControl.Dispose(); _movedControl = null; } } else { Point canvasPos = GetCanvasPoint(sender as Control, e.X, e.Y); _paintTool = new PMoveTool(_movedControl, canvasPos); return; } if (_toolType == SelectedTool.None) { return; } if (_toolType == SelectedTool.Brush) { _paintTool = new PBrushTool(sender as PictureBoxObj, _toolSize, _toolColor); } else { Point canvasPos = GetCanvasPoint(sender as Control, e.X, e.Y); _movedControl = CreateNewPictureBox(null, canvasPos); if (_toolType == SelectedTool.Line) { _paintTool = new PDrawLine(_movedControl, canvasPos, _toolSize, _toolColor); } else if (_toolType == SelectedTool.Rect) { _paintTool = new PDrawRect(_movedControl, canvasPos, _toolSize, _toolColor); } else if (_toolType == SelectedTool.Ellipse) { _paintTool = new PDrawEllipse(_movedControl, canvasPos, _toolSize, _toolColor); } else if (_toolType == SelectedTool.SelectorRect) { _paintTool = new PSelectorRect(_movedControl, canvasPos, _canvas.BackPicture, false); } else if (_toolType == SelectedTool.SelectorRect) { _paintTool = new PSelectorRect(_movedControl, canvasPos, _canvas.BackPicture, true); } } }
public PMoveTool(PictureBoxObj moveBox, Point mousePoint) { if (moveBox == null) { throw (new ArgumentNullException("Move box is null")); } _picture = moveBox; _offsetX = mousePoint.X - moveBox.Location.X; _offsetY = mousePoint.Y - moveBox.Location.Y; }
public PDrawRect(PictureBoxObj drawBox, Point startPoint, int brushSize, Color color) { _picture = drawBox; _picture.BackColor = Color.Transparent; _brushSize = brushSize < 1 ? 1 : brushSize; _color = color; _startX = startPoint.X; _startY = startPoint.Y; _picture.BringToFront(); }
public PSelectorRect(PictureBoxObj drawBox, Point startPoint, PictureBoxObj sourceBox, bool isCutted) { _picture = drawBox; _source = sourceBox; _picture.BackColor = Color.Transparent; _needCopy = false; _isCutted = isCutted; _startX = startPoint.X; _startY = startPoint.Y; _picture.BringToFront(); }
private void SendComNewPictureBox(PictureBoxObj picOBj) { ArgNewPictureBox arg = new ArgNewPictureBox(NComCreateNewPictureBox.uniqueID, _netClient.ClientID); arg.PictureBoxID = picOBj.UniqueID; arg.PBImage = picOBj.Image; arg.PBSizeX = picOBj.Width; arg.PBSizeY = picOBj.Height; arg.LocationX = picOBj.Location.X; arg.LocationY = picOBj.Location.Y; if (_netClient.Connector != null) { AppLogger.Log(arg.PictureBoxID + " sended to create"); _netClient.Connector.SendCommand(arg); } }
private void TickCreateNewCanvas() { ArgNewPictureBox arg = null; lock (_npbSync) { if (_incomingCanvas != null) { arg = _incomingCanvas; _incomingCanvas = null; } else { return; } } if (_movedControl != null) { _movedControl.Dispose(); _movedControl = null; } PictureBoxObj pb = new PictureBoxObj(arg.ClientID, 0, PictureBoxStatus.Canvas); pb.BorderStyle = BorderStyle.FixedSingle; pb.Width = arg.PBImage.Width; pb.Height = arg.PBImage.Height; pb.Image = arg.PBImage; UnSubscribeControl(_canvas.FrontPicture); _canvas.Clear(); _canvas.SetCanvas(pb); SubscribeControl(_canvas.FrontPicture); _canvas.UpdateCanvas(); AppLogger.Log("New canvas created by " + arg.ClientID); lblPictureSize.Invoke((MethodInvoker) delegate { lblPictureSize.Text = pb.Size.Width + " x " + pb.Size.Height + " px"; }); }
private PictureBoxObj CreateNewPictureBox(Image img, Point location) { //Create facepictureBox PictureBoxObj pic = new PictureBoxObj(_netClient.ClientID, Uid64.CreateNew().Data, PictureBoxStatus.IsMovable); if (img != null) { pic.Image = img; pic.Width = img.Width; pic.Height = img.Height; } SubscribeControl(pic); pic.BorderStyle = BorderStyle.FixedSingle; pic.BringToFront(); pic.Parent = _canvas.FrontPicture; pic.Location = location; //Send it to serever SendComNewPictureBox(pic); return(pic); }
public void AddPictureObj(PictureBoxObj pic, Point location) { if (IsCleared || pic == null) { return; } lock (_canvasSync) { if (_drawObjects.ContainsKey(pic.UniqueID)) { return; } _backPicture.Controls.Add(pic); pic.Location = location; _drawObjects.Add(pic.UniqueID, pic); _editPBDrawObjects.Add(pic.UniqueID, new DrawObjectList(pic.UniqueID)); pic.Invalidate(); } AppLogger.Log("Created new pictureBox, location: " + location + " size: " + pic.Size); }
private void TickNewClientsSyncronized() { TeamPainterTCPClient[] clients = _worker.GetAllClients(); if (clients == null || clients.Length == 0) { return; } List <TeamPainterTCPClient> unsync = new List <TeamPainterTCPClient>(); for (int i = 0; i < clients.Length; i++) { if (!clients[i].Syncronized) { unsync.Add(clients[i]); } } if (unsync.Count == 0) { return; } if (_canvas.IsCleared) { for (int c = 0; c < unsync.Count; c++) { if (unsync[c].Syncronized) { continue; } unsync[c].Syncronized = true; } return; } ArgNewPictureBox canvasArg = new ArgNewPictureBox(NComCreateNewCanvas.uniqueID, 0); canvasArg.PBImage = _canvas.GetBackPicture(); canvasArg.LocationX = 0; canvasArg.LocationY = 0; canvasArg.PBSizeX = canvasArg.PBImage == null ? 0 : _canvas.Width; canvasArg.PBSizeY = canvasArg.PBImage == null ? 0 : _canvas.Height; canvasArg.PictureBoxID = 0; for (int c = 0; c < unsync.Count; c++) { unsync[c].Connector.SendCommand(canvasArg); unsync[c].Syncronized = true; } PictureBoxObj[] pbs = _canvas.GetAllPictureBoxes(); for (int i = 0; i < pbs.Length; i++) { PictureBoxObj pic = pbs[i]; ArgNewPictureBox picArg = new ArgNewPictureBox(NComCreateNewPictureBox.uniqueID, pic.ClientID); picArg.PBImage = pic.Image; picArg.LocationX = pic.Location.X; picArg.LocationY = pic.Location.Y; picArg.PBSizeX = pic.Width; picArg.PBSizeY = pic.Height; picArg.PictureBoxID = pic.UniqueID; for (int c = 0; c < unsync.Count; c++) { unsync[c].Connector.SendCommand(picArg); } } }
public PBrushTool(PictureBoxObj drawBox, int brushSize, Color color) { _brushSize = brushSize < 1 ? 1 : brushSize; _color = color; _picture = drawBox; }