Skip to content

Commit

Permalink
1. console view as textbox (read only)
Browse files Browse the repository at this point in the history
2. speed improvemance in chat
  • Loading branch information
tym32167 committed Jan 11, 2015
1 parent 3d313e5 commit c7acf16
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
9 changes: 1 addition & 8 deletions src/Arma3BEClient/Chat/ChatControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,7 @@

<ScrollViewer Grid.ColumnSpan="2" Name="ConsoleScrollViewer">

<RichTextBox Name="msgConsole" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" IsReadOnly="True" IsReadOnlyCaretVisible="False"
FontSize="12" FontWeight="Normal" FontStyle="Normal" Background="#F0F0F0">
<RichTextBox.Resources>
<Style TargetType="{x:Type Paragraph}">
<Setter Property="Margin" Value="0"/>
</Style>
</RichTextBox.Resources>
</RichTextBox>
<TextBox Name="msgConsole" FontSize="12" IsReadOnly="True"></TextBox>

</ScrollViewer>
</TabItem>
Expand Down
42 changes: 35 additions & 7 deletions src/Arma3BEClient/Chat/ChatControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
Expand All @@ -14,13 +15,15 @@ namespace Arma3BEClient.Chat
/// Interaction logic for ChatControl.xaml
/// </summary>
public partial class ChatControl : UserControl{



private ServerMonitorChatViewModel Model { get { return DataContext as ServerMonitorChatViewModel; } }

public ChatControl()
{
InitializeComponent();
InitBox();
}

void _model_ChatMessageEventHandler(object sender, Updater.Models.ChatMessage e)
Expand All @@ -30,7 +33,7 @@ void _model_ChatMessageEventHandler(object sender, Updater.Models.ChatMessage e)
if (!Model.EnableChat) return;
var type = e.Type;
if (type != ChatMessage.MessageType.Unknown)
AppendText(msgBox, ChatScrollViewer, e);
AppendText(paragraph, ChatScrollViewer, e);
else
AppendText(msgConsole, ConsoleScrollViewer, e);
});
Expand All @@ -51,14 +54,38 @@ private void KeyDown(object sender, KeyEventArgs e)
}
}

public void AppendText(RichTextBox box, ScrollViewer scroll, ChatMessage message)

private Paragraph paragraph;

private void InitBox()
{
msgBox.Document.Blocks.Clear();
paragraph = new Paragraph();

msgBox.Document.Blocks.Add(paragraph);
}


public void AppendText(Paragraph p, ScrollViewer scroll, ChatMessage message)
{
var text = string.Format("[ {0:HH:mm:ss} ] {1}\n", message.Date, message.Message);
var color = ServerMonitorModel.GetMessageColor(message);
var tr = new TextRange(box.Document.ContentEnd, box.Document.ContentEnd);
tr.Text = text;
tr.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush(color));

var brush = new SolidColorBrush(color);
var span = new Span() { Foreground = brush };
span.Inlines.Add(text);
paragraph.Inlines.Add(span);

if (Model.AutoScroll)
scroll.ScrollToEnd();
}


public void AppendText(TextBox block, ScrollViewer scroll, ChatMessage message)
{
var text = string.Format("[ {0:HH:mm:ss} ] {1}\n", message.Date, message.Message);
block.Text += text;

if (Model.AutoScroll)
scroll.ScrollToEnd();
}
Expand All @@ -71,10 +98,11 @@ private void ToolBar_DataContextChanged(object sender, DependencyPropertyChanged
private void ClearAll_Click(object sender, RoutedEventArgs e)
{
msgBox.Document.Blocks.Clear();
msgConsole.Document.Blocks.Clear();
msgConsole.Text = string.Empty;

InitBox();

msgBox.AppendText(Environment.NewLine);
msgConsole.AppendText(Environment.NewLine);
}
}
}

0 comments on commit c7acf16

Please sign in to comment.