Example #1
0
        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));
                }
            }
        }
Example #2
0
        private void NCCreateNewCanvas(IConnector connector, ArgNewPictureBox arg)
        {
            if (arg == null)
            {
                return;
            }
            if (arg.CommandID != NComCreateNewCanvas.uniqueID)
            {
                return;
            }

            if (arg.PBImage == null)
            {
                if (arg.PBSizeX < 1 || arg.PBSizeY < 1)
                {
                    return;
                }
                Image img = new Bitmap(arg.PBSizeX, arg.PBSizeY);
                using (Graphics grp = Graphics.FromImage(img)){
                    grp.FillRectangle(Brushes.White, 0, 0, img.Width, img.Height);
                }
                arg.PBImage = img;
            }
            lock (_npbSync) { _incomingCanvas = arg; }
        }
Example #3
0
        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);
        }
Example #4
0
        private void NCCreateNewPictureBox(IConnector connection, ArgNewPictureBox arg)
        {
            if (arg == null)
            {
                return;
            }
            if (arg.CommandID != NComCreateNewPictureBox.uniqueID)
            {
                return;
            }

            lock (_npbSync) { _incomingPictureBoxes.Enqueue(arg.PictureBoxID, arg); }
        }
Example #5
0
        private void SendComNewCanvas(int canvasSizeX, int canvasSizeY, Image canvasImage)
        {
            ArgNewPictureBox arg = new ArgNewPictureBox(NComCreateNewCanvas.uniqueID, _netClient.ClientID);

            arg.PBImage = canvasImage;
            arg.PBSizeX = canvasSizeX;
            arg.PBSizeY = canvasSizeY;

            if (_netClient.Connector != null)
            {
                _netClient.Connector.SendCommand(arg, true);
            }
        }
Example #6
0
        private void NCCreateNewPictureBox(IConnector connection, ArgNewPictureBox arg)
        {
            long clientFakePBID   = arg.PictureBoxID;
            long realEditablePBID = Uid64.CreateNew().Data;

            arg.PictureBoxID = realEditablePBID;
            lock (_npbSync)
            {
                _newPB.Enqueue(arg.PictureBoxID, arg);
                _clientServerPictureBoxID[clientFakePBID] = realEditablePBID;
            }
            lock (_astSync) { _argsSendToAllClients.Add(arg); }

            NetLogger.Log("CreatePB from: " + clientFakePBID + " to " + realEditablePBID);
        }
Example #7
0
        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);
            }
        }
Example #8
0
        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";
            });
        }
Example #9
0
        private void NCCreateNewCanvas(IConnector connection, ArgNewPictureBox arg)
        {
            if (arg == null)
            {
                return;
            }
            if (arg.CommandID != NComCreateNewCanvas.uniqueID)
            {
                return;
            }

            if (arg.PBImage == null)
            {
                if (arg.PBSizeX < 1 || arg.PBSizeY < 1)
                {
                    return;
                }
                Image img = new Bitmap(arg.PBSizeX, arg.PBSizeY);
                using (Graphics grp = Graphics.FromImage(img))
                {
                    grp.FillRectangle(Brushes.White, 0, 0, img.Width, img.Height);
                }
                arg.PBImage = img;
            }
            TeamPainterTCPClient[] clients = _worker.GetAllClients();
            for (int i = 0; i < clients.Length; i++)
            {
                if (clients[i] == null)
                {
                    continue;                     //remove this
                }
                clients[i].Connector.SendCommand(arg);
                clients[i].Syncronized = true;
            }

            lock (_npbSync) { _incomingCanvas = arg; }
        }
Example #10
0
        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);
                }
            }
        }