예제 #1
0
        private void MainCanvas_PointerPressed(object sender, PointerRoutedEventArgs e)
        {
            DrawColor = (ShouldErase ? ((SolidColorBrush)MainCanvas.Background).Color : DrawColor);

            int size = (int)Size;

            Point cp = e.GetCurrentPoint(MainCanvas).Position;

            System.Drawing.Point currentPosition = new System.Drawing.Point((int)cp.X, (int)cp.Y);
            System.Drawing.Color newColor        = System.Drawing.Color.FromArgb(DrawColor.A, DrawColor.R, DrawColor.G, DrawColor.B);


            if (e.Pointer.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Pen)
            {
                size = (int)Math.Ceiling(size * e.GetCurrentPoint(null).Properties.Pressure);
            }

            DrawPacket line = new DrawPacket(currentPosition, currentPosition, newColor, size, (byte)PolySides);

            DrawPacket(line);


            prevPosition             = e.GetCurrentPoint(MainCanvas).Position;
            MainCanvas.PointerMoved += MainCanvas_PointerMoved;
        }
예제 #2
0
        private void _SendDrawPacket(Point p, Phase phase)
        {
            DrawPacket packet = new DrawPacket(ClientManager.instance.id);

            packet.color     = _color;
            packet.thickness = (byte)_thickness;
            packet.x         = (short)p.X;
            packet.y         = (short)p.Y;
            packet.phase     = phase;
            ClientManager.instance.Send(packet.GetBytes());
        }
예제 #3
0
        private void _ProcessPacket(Packet p)
        {
            switch (p.type)
            {
            case PacketType.Ping:
            {
                // userId = 0일 경우 ping용 패킷
                // 그 외는 아이디 할당
                if (p.userId != 0)
                {
                    id = p.userId;
                }
            }
            break;

            case PacketType.Text:
            {
                TextPacket t = (TextPacket)p;
                Application.Current.Dispatcher.Invoke(() => { _mainWindow.ShowMessage(t.text, t.userId); });
            }
            break;

            case PacketType.Draw:
            {
                DrawPacket dp = (DrawPacket)p;
                Application.Current.Dispatcher.Invoke(() => { _mainWindow.Draw(dp); });
            }
            break;

            case PacketType.Clear:
            {
                Application.Current.Dispatcher.Invoke(() => { _mainWindow.ClearDrawing(); });
            }
            break;

            case PacketType.PlayerList:
            {
                PlayerListPacket pl = (PlayerListPacket)p;
                players = pl.list;
                Application.Current.Dispatcher.Invoke(() => { _mainWindow.ShowPlayers(); });
            }
            break;

            case PacketType.Ready:
            {
                ReadyPacket rp = (ReadyPacket)p;
                turn = rp.turn;
                word = rp.word;
                Application.Current.Dispatcher.Invoke(() => { _mainWindow.ShowWord(); });
            }
            break;
            }
        }
예제 #4
0
        private void DrawPacket(DrawPacket packet, bool invokeLineDrawn = true)
        {
            Color color = Color.FromArgb(packet.color.A, packet.color.R, packet.color.G, packet.color.B);

            if (packet.numOfSides < 3)
            {
                Bitmap.FillEllipseCentered(packet.pointA.X, packet.pointA.Y, (int)Math.Ceiling(packet.size / 2.0) - 1, (int)Math.Ceiling(packet.size / 2.0) - 1, color);
                Bitmap.DrawLineAa(packet.pointA.X, packet.pointA.Y, packet.pointB.X, packet.pointB.Y, color, packet.size);
                Bitmap.FillEllipseCentered(packet.pointB.X, packet.pointB.Y, (int)Math.Ceiling(packet.size / 2.0) - 1, (int)Math.Ceiling(packet.size / 2.0) - 1, color);
            }
            else
            {
                System.Drawing.Point[] prevPoints = new System.Drawing.Point[packet.numOfSides];
                System.Drawing.Point[] currPoints = new System.Drawing.Point[packet.numOfSides];
                int[] prevXY  = new int[(prevPoints.Length * 2) + 2];
                int[] currXY  = new int[(currPoints.Length * 2) + 2];
                int   counter = 0;

                for (int i = 0; i < packet.numOfSides; i++)
                {
                    prevPoints[i] = new System.Drawing.Point((int)(packet.pointA.X + packet.size * Math.Sin(2 * Math.PI * i / packet.numOfSides)), (int)(packet.pointA.Y + packet.size * -Math.Cos(2 * Math.PI * i / packet.numOfSides)));
                    currPoints[i] = new System.Drawing.Point((int)(packet.pointB.X + packet.size * Math.Sin(2 * Math.PI * i / packet.numOfSides)), (int)(packet.pointB.Y + packet.size * -Math.Cos(2 * Math.PI * i / packet.numOfSides)));

                    prevXY[counter] = prevPoints[i].X;
                    currXY[counter] = currPoints[i].X;
                    counter++;
                    prevXY[counter] = prevPoints[i].Y;
                    currXY[counter] = currPoints[i].Y;
                    counter++;
                }
                prevXY[prevXY.Length - 1] = prevXY[1];
                prevXY[prevXY.Length - 2] = prevXY[0];
                currXY[prevXY.Length - 1] = currXY[1];
                currXY[prevXY.Length - 2] = currXY[0];
                Bitmap.FillPolygon(prevXY, color);
                Bitmap.FillPolygon(currXY, color);

                BTPaint.Models.DrawPacket.Restore(packet.ToByteArray());
            }


            if (invokeLineDrawn && LineDrawn != null)
            {
                LineDrawn(packet);
            }
        }
예제 #5
0
        private void HandleRequest(IClient client, Packet packet)
        {
            Packet aux;
            IDictionary <string, object> dict = (IDictionary <string, object>)packet.Message;

            switch (packet.Type.ToLower())
            {
            case "draw":
                DrawPacket drawPacket = new DrawPacket();
                drawPacket.Type = (string)dict["Type"];
                switch (drawPacket.Type.ToLower())
                {
                case "start":
                    drawPacket.Color     = (string)dict["Color"];
                    drawPacket.LineWidth = (int)dict["LineWidth"];
                    drawPacket.X         = (int)dict["X"];
                    drawPacket.Y         = (int)dict["Y"];
                    break;

                case "move":
                    drawPacket.X = (int)dict["X"];
                    drawPacket.Y = (int)dict["Y"];
                    break;

                case "clearscreen":
                    break;

                default:
                    break;
                }
                aux = new Packet("draw", drawPacket);
                BroadCast(client, aux);
                break;

            case "chat":
                ChatPacket chatPacket = new ChatPacket();
                chatPacket.User    = (string)dict["User"];
                chatPacket.Message = (string)dict["Message"];
                aux = new Packet("chat", chatPacket);
                BroadCast(client, aux);
                break;

            default:
                break;
            }
        }
예제 #6
0
        public void Draw(DrawPacket dp)
        {
            switch (dp.phase)
            {
            case Phase.Began:
            case Phase.Moved:
                if (_line == null)
                {
                    _line = new Polyline();
                    Color color = Colors.Black;
                    switch (dp.color)
                    {
                    case ColorType.Red: color = Colors.Red; break;

                    case ColorType.Yellow: color = Colors.Yellow; break;

                    case ColorType.Green: color = Colors.Green; break;

                    case ColorType.Blue: color = Colors.Blue; break;

                    case ColorType.White: color = Colors.White; break;
                    }

                    _line.Stroke          = new SolidColorBrush(color);
                    _line.StrokeThickness = dp.thickness;
                    MyCanvas.Children.Add(_line);
                }
                _line.Points.Add(new Point(dp.x, dp.y));
                break;

            case Phase.Ended:
                if (_line != null)
                {
                    _line.Points.Add(new Point(dp.x, dp.y));
                    _line = null;
                }
                break;
            }
        }
예제 #7
0
        public void ProcessPacket(Packet p)
        {
            switch (p.type)
            {
            case PacketType.Text:
            {
                TextPacket t = (TextPacket)p;

                // 텍스트 표시
                if (Application.Current != null)
                {
                    Application.Current.Dispatcher.Invoke(() =>
                        {
                            if (_mainWindow != null)
                            {
                                _mainWindow.ShowMessage(t.text, t.userId);
                            }
                        });
                }
                DispatchPacket(t);

                // 정답 맞춘 경우
                if (turn != p.userId && t.text.Equals(word))
                {
                    Start();
                }
            }
            break;

            case PacketType.Draw:
            {
                DrawPacket dp = (DrawPacket)p;
                if (Application.Current != null)
                {
                    Application.Current.Dispatcher.Invoke(() =>
                        {
                            if (_mainWindow != null)
                            {
                                _mainWindow.Draw(dp);
                            }
                        });
                }
                DispatchPacket(dp);
            }
            break;

            case PacketType.Clear:
            {
                if (Application.Current != null)
                {
                    Application.Current.Dispatcher.Invoke(() =>
                        {
                            if (_mainWindow != null)
                            {
                                _mainWindow.ClearDrawing();
                            }
                        });
                }
                DispatchPacket(p);
            }
            break;
            }
        }
예제 #8
0
 private void CanvasLineDrawn(DrawPacket line)
 {
     client.Send(line);
 }