public void ShowUsers(string[] people)
        {
            SuspendLayout();
            scrollPanel.ContentAdded = true;

            int topPadding = (int)(4.85 * unit);
            int beginIndex;

            if (people[people.Length - 1] == "e")
            {
                endCommon = true;
            }

            for (int i = 0; i < people.Length / 6; i++)
            {
                beginIndex = i * 6;

                Human currentUser = Human.Parse(people, beginIndex);

                if ((I.UserId == currentUser.UserId) ||
                    (friend.ContainsKey(currentUser.UserId)))
                {
                    continue;
                }

                Panel usersPanel = new Panel();
                usersPanel.Size = new Size(scrollPanel.Width, (int)(25.65 * unit));

                int lastPanelBottom;
                if (scrollPanel.Controls.Count == 0)
                {
                    lastPanelBottom = 0;
                }
                else
                {
                    lastPanelBottom =
                        scrollPanel.Controls[scrollPanel.Controls.Count - 1].Bottom;
                }
                usersPanel.Location = new Point(0, lastPanelBottom + 1);


                AvatarBox avatar = new AvatarBox();
                if (currentUser.Avatar == null)
                {
                    avatar.Image = Properties.Resources.AvatarDefault;
                }
                avatar.SizeMode = PictureBoxSizeMode.StretchImage;
                avatar.Size     = new Size((int)(19 * unit), (int)(19 * unit));

                int topAvatar = GetLeftPosition(avatar.Height, usersPanel.Height);
                avatar.Location = new Point(topAvatar, topAvatar);

                usersPanel.Controls.Add(avatar);


                Label nameLabel = new Label();
                nameLabel.Text      = currentUser.Name + " " + currentUser.Surname;
                nameLabel.Font      = boldChatFont;
                nameLabel.ForeColor = Color.FromArgb(42, 88, 133);
                nameLabel.AutoSize  = true;
                nameLabel.TextAlign = ContentAlignment.BottomCenter;

                int leftPadding = (int)(3 * unit);
                nameLabel.Location = new Point
                                         (avatar.Right + leftPadding, (int)(topPadding * 1.25));

                usersPanel.Controls.Add(nameLabel);

                BunifuThinButton2 addButton = new BunifuThinButton2();
                addButton.ButtonText = "Добавить собеседника";
                addButton.Size       = new Size
                                           ((int)(56.22 * unit), (int)(13.5 * unit));
                addButton.Font = chatFont;

                addButton.BackColor = Color.White;

                addButton.ActiveForecolor    = Color.White;
                addButton.ActiveFillColor    = Color.FromArgb(104, 136, 173);
                addButton.ActiveLineColor    = Color.White;
                addButton.ActiveCornerRadius = 7;

                addButton.IdleForecolor    = Color.White;
                addButton.IdleFillColor    = Color.FromArgb(94, 129, 167);
                addButton.IdleLineColor    = Color.White;
                addButton.IdleCornerRadius = 7;

                addButton.Location = new Point
                                         (usersPanel.Width - addButton.Width - topAvatar, topPadding);
                addButton.Click += AddButton_Click;
                addButton.Tag    = currentUser;

                usersPanel.Controls.Add(addButton);

                BunifuSeparator separatorLine = new BunifuSeparator();
                separatorLine.LineColor = lineColor;
                separatorLine.Size      = new Size(usersPanel.Width - 2 * topAvatar, 1);
                separatorLine.Location  =
                    new Point(topAvatar, usersPanel.Height - 1);

                usersPanel.Controls.Add(separatorLine);

                AddPanel AddFriendMethod = scrollPanel.Controls.Add;
                scrollPanel.Invoke(AddFriendMethod, usersPanel);
            }
            downloaded = false;

            scrollPanel.ContentAdded = false;
            ResumeLayout();
        }
Beispiel #2
0
        public void ShowConversationPanel(Human currentFriend)
        {
            if (!aLotOfDownloaded)
            {
                scrollPanel.ContentAdded = true;
            }

            double ratio = 13 / 8.0;

            friend[currentFriend.UserId] = currentFriend;

            int topPanel;

            if (scrollPanel.Controls.Count == 0)
            {
                topPanel = 0;
            }
            else
            {
                topPanel = scrollPanel.Controls[scrollPanel.Controls.Count - 1].Bottom;
            }

            Panel conversationPanel = new Panel();

            conversationPanel.Tag  = currentFriend.UserId;
            conversationPanel.Size =
                new Size(scrollPanel.Width, (int)(header.Height * ratio));
            conversationPanel.Location =
                new Point(0, topPanel);
            conversationPanel.BackColor = Color.White;


            AvatarBox avatarImage = new AvatarBox();

            avatarImage.Image    = Properties.Resources.AvatarDefault;
            avatarImage.SizeMode = PictureBoxSizeMode.StretchImage;

            int length = (int)(conversationPanel.Height / ratio);

            avatarImage.Size = new Size(length, length);

            int padding = (int)(conversationPanel.Height - avatarImage.Height) / 2;

            avatarImage.Location = new Point(padding, padding);
            avatarImage.Enabled  = false;

            conversationPanel.Controls.Add(avatarImage);

            Label completeName = new Label();

            completeName.Text      = currentFriend.Name + " " + currentFriend.Surname;
            completeName.Font      = boldChatFont;
            completeName.TextAlign = ContentAlignment.BottomCenter;
            completeName.AutoSize  = true;
            completeName.ForeColor = Color.FromArgb(66, 100, 139);

            int top =
                GetLeftPosition(completeName.Height, conversationPanel.Height);

            top = (int)(top * 1.2);
            int left = avatarImage.Right + padding;

            completeName.Location = new Point(left, top);

            conversationPanel.Controls.Add(completeName);

            PictureBox chatImage = new PictureBox();

            chatImage.Image    = Properties.Resources.chatImage;
            chatImage.SizeMode = PictureBoxSizeMode.StretchImage;
            chatImage.Visible  = false;
            chatImage.Enabled  = false;

            int sizeChatImage = (int)(3 * length / 4.0);

            chatImage.Size = new Size(sizeChatImage, sizeChatImage);

            int topChatImage =
                GetLeftPosition(chatImage.Height, conversationPanel.Height);
            int paddingRight = sizeChatImage / 2;
            int paddingLeft  = conversationPanel.Width
                               - paddingRight - chatImage.Width;

            chatImage.Location = new Point(paddingLeft, topChatImage);

            conversationPanel.Controls.Add(chatImage);

            conversationPanel.MouseEnter += ConversationPanel_MouseEnter;
            conversationPanel.MouseLeave += ConversationPanel_MouseLeave;

            conversationPanel.Click += ConversationPanel_Click;
            completeName.Click      += ConversationPanel_Click;


            AddPanel addConversation = scrollPanel.Controls.Add;

            Invoke(addConversation, conversationPanel);

            if (!aLotOfDownloaded)
            {
                scrollPanel.ContentAdded = false;
            }
        }
        public void ShowMessage(string text, bool iSender, bool inUp)
        {
            if (!inUp)
            {
                scrollPanel.ContentAdded = true;
            }

            text = LinesFromMessage(text);

            Label messageLabel = new Label();

            messageLabel.ForeColor = Color.Black;
            messageLabel.AutoSize  = true;
            messageLabel.Text      = text;
            messageLabel.Font      = chatFont;
            int padding = 10;

            AvatarBox avatar = new AvatarBox();

            avatar.SizeMode = PictureBoxSizeMode.StretchImage;
            avatar.Size     = new Size(avatarSize, avatarSize);

            Panel messagePanel = new Panel();

            messagePanel.Controls.Add(messageLabel);

            int   paddingContainer = (int)(padding / 2.0);
            Panel containerPanel   = new Panel();

            containerPanel.Controls.Add(avatar);
            containerPanel.Controls.Add(messagePanel);
            scrollPanel.Controls.Add(containerPanel);

            Size messageSize = messageLabel.Size;

            messagePanel.Size = new Size
                                    (messageSize.Width + 2 * padding,
                                    messageSize.Height + 2 * padding);
            messagePanel.Padding = new Padding(padding);

            BunifuElipse ellipse = new BunifuElipse();

            ellipse.TargetControl = messagePanel;
            ellipse.ElipseRadius  = padding;


            containerPanel.Size = new Size
                                      (scrollPanel.Width, messagePanel.Height + 2 * paddingContainer);
            // containerPanel.Padding = new Padding(paddingContainer);

            if (scrollPanel.TopControl == null)
            {
                containerPanel.Location = new Point
                                              (0, scrollPanel.Height - containerPanel.Height);

                scrollPanel.TopControl    = containerPanel;
                scrollPanel.BottomControl = containerPanel;
            }
            else
            {
                if (inUp)
                {
                    containerPanel.Location = new Point
                                                  (0, scrollPanel.TopControl.Top - containerPanel.Height);

                    scrollPanel.TopControl = containerPanel;
                }
                else
                {
                    containerPanel.Location = new Point
                                                  (0, scrollPanel.BottomControl.Bottom);

                    scrollPanel.Top    -= containerPanel.Height;
                    scrollPanel.Height += containerPanel.Height;

                    scrollPanel.BottomControl = containerPanel;
                }
            }


            int avatarPadding = (int)(avatarSize / 5.0);


            if (!iSender)
            {
                avatar.Location = new Point(avatarPadding,
                                            containerPanel.Height - avatarSize - paddingContainer);

                if (friend.Avatar == null)
                {
                    avatar.Image = Properties.Resources.AvatarDefault;
                }

                int leftMessage = avatar.Right + avatarPadding;
                messagePanel.Location  = new Point(leftMessage, paddingContainer);
                messagePanel.BackColor = Color.White;
            }
            else
            {
                int leftMessage = Body.Width - 2 * avatarPadding
                                  - avatarSize - messagePanel.Width;
                messagePanel.Location  = new Point(leftMessage, paddingContainer);
                messagePanel.BackColor = Color.FromArgb(212, 231, 250);

                avatar.Location = new Point(messagePanel.Right + avatarPadding,
                                            containerPanel.Height - avatarSize - paddingContainer);

                if (I.Avatar == null)
                {
                    avatar.Image = Properties.Resources.AvatarDefault;
                }
            }
            // ShiftTopControl(containerPanel.Height);
            if (!inUp)
            {
                scrollPanel.ContentAdded = false;
            }
        }