예제 #1
0
        public void AddChatMessage(string sender, string message, Protocol.FontOptions font, DateTime timestamp)
        {
            // Add this color to the brush cache if it's not there already
            SolidColorBrush brush;

            if (!chatBrushCache.TryGetValue(font.Color, out brush))
            {
                brush = new SolidColorBrush(font.Color);
                brush.Freeze();
                chatBrushCache.Add(font.Color, brush);
            }

            var paragraph = new Paragraph()
            {
                Foreground = Brushes.DarkBlue,
                FontSize   = FontSize + 1,
                Margin     = new Thickness(0, 4.0, 0, 0),
            };

            paragraph.Inlines.Add(new Run(sender));
            ChatHistory.Document.Blocks.Add(paragraph);

            paragraph = new Paragraph()
            {
                FontFamily = new FontFamily(font.Family + ",\"Segoe UI\""),
                Foreground = brush,
                LineHeight = 3 * FontSize / 2,
                Margin     = new Thickness(4.0, 0, 0, 0),
            };
            paragraph.Inlines.Add(new Run(message));

            if (font.Style.HasFlag(Protocol.FontStyle.Bold))
            {
                paragraph.FontWeight = FontWeights.Bold;
            }
            if (font.Style.HasFlag(Protocol.FontStyle.Italic))
            {
                paragraph.FontStyle = FontStyles.Italic;
            }
            if (font.Style.HasFlag(Protocol.FontStyle.Underline))
            {
                paragraph.TextDecorations = new TextDecorationCollection();
                paragraph.TextDecorations.Add(TextDecorations.Underline);
            }

            ChatHistory.Document.Blocks.Add(paragraph);
        }
예제 #2
0
        public FontDialog(Protocol.FontOptions currentFont)
        {
            InitializeComponent();

            var families = Fonts.SystemFontFamilies.OrderBy((family) =>
            {
                return(family.Source);
            });

            foreach (var family in families)
            {
                var item = new ListBoxItem()
                {
                    Content = family.Source,
                    VerticalContentAlignment = VerticalAlignment.Top,
                    FontFamily = family,
                    Padding    = new Thickness(2),
                    FontSize   = 14,
                };
                FontFamilyListBox.Items.Add(item);
                if (family.Source == currentFont.Family)
                {
                    FontFamilyListBox.SelectedItem = item;
                }
            }
            FontFamilyListBox.ScrollIntoView(FontFamilyListBox.SelectedItem);

            var colorMap = new Dictionary <string, Color>();

            colorMap.Add("Black", Colors.Black);
            colorMap.Add("Gray", Colors.Gray);
            colorMap.Add("Pink", Colors.Pink);
            colorMap.Add("Red", Colors.Red);
            colorMap.Add("Dark Red", Colors.DarkRed);
            colorMap.Add("Light Blue", Colors.LightBlue);
            colorMap.Add("Blue", Colors.Blue);
            colorMap.Add("Teal", Colors.Teal);
            colorMap.Add("Dark Blue", Colors.DarkBlue);
            colorMap.Add("Light Green", Colors.LightGreen);
            colorMap.Add("Green", Colors.Green);
            colorMap.Add("Dark Green", Colors.DarkGreen);

            foreach (var pair in colorMap)
            {
                var brush = new SolidColorBrush(pair.Value);
                brush.Freeze();

                ColorComboBox.Items.Add(new ComboBoxItem()
                {
                    Content    = pair.Key,
                    Foreground = brush,
                });
            }
            ColorComboBox.SelectedIndex = 0;

            int[] sizes = { 6, 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 36, 40 };

            foreach (int size in sizes)
            {
                SizeComboBox.Items.Add(new ComboBoxItem()
                {
                    Content = size.ToString()
                });
            }
            SizeComboBox.SelectedIndex = 5;

            if (currentFont.Style.HasFlag(Protocol.FontStyle.Bold))
            {
                BoldCheckBox.IsChecked = true;
            }
            if (currentFont.Style.HasFlag(Protocol.FontStyle.Italic))
            {
                ItalicCheckBox.IsChecked = true;
            }
            if (currentFont.Style.HasFlag(Protocol.FontStyle.Underline))
            {
                UnderlineCheckBox.IsChecked = true;
            }
        }