its not working yet, its getting a System.OutOfMemoryException, needs to be fixed
This commit is contained in:
@@ -1,10 +1,67 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using Client.Views;
|
||||
using SharedClientServer;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace Client.ViewModels
|
||||
{
|
||||
class ViewModelGame : INotifyPropertyChanged
|
||||
{
|
||||
private ClientData data = ClientData.Instance;
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
private Point currentPoint = new Point();
|
||||
private Color color;
|
||||
|
||||
public void Canvas_MouseDown(MouseButtonEventArgs e, GameWindow window)
|
||||
{
|
||||
if (e.ButtonState == MouseButtonState.Pressed)
|
||||
{
|
||||
currentPoint = e.GetPosition(window.CanvasForPaint);
|
||||
}
|
||||
}
|
||||
|
||||
public void Canvas_MouseMove(MouseEventArgs e, GameWindow window)
|
||||
{
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
{
|
||||
double[] coordinates = new double[4];
|
||||
Line line = new Line();
|
||||
|
||||
line.Stroke = new SolidColorBrush(color);
|
||||
//line.Stroke = SystemColors.WindowFrameBrush;
|
||||
line.X1 = currentPoint.X;
|
||||
line.Y1 = currentPoint.Y;
|
||||
line.X2 = e.GetPosition(window.CanvasForPaint).X;
|
||||
line.Y2 = e.GetPosition(window.CanvasForPaint).Y;
|
||||
coordinates[0] = line.X1;
|
||||
coordinates[1] = line.Y1;
|
||||
coordinates[2] = line.X2;
|
||||
coordinates[3] = line.Y2;
|
||||
currentPoint = e.GetPosition(window.CanvasForPaint);
|
||||
|
||||
window.CanvasForPaint.Children.Add(line);
|
||||
data.Client.SendMessage(JSONConvert.GetMessageToSend(0x04, coordinates));
|
||||
}
|
||||
}
|
||||
|
||||
public void Color_Picker(RoutedPropertyChangedEventArgs<Color?> e, GameWindow window)
|
||||
{
|
||||
Color colorSelected = new Color();
|
||||
colorSelected.A = 255;
|
||||
colorSelected.R = window.ClrPcker_Background.SelectedColor.Value.R;
|
||||
colorSelected.G = window.ClrPcker_Background.SelectedColor.Value.G;
|
||||
colorSelected.B = window.ClrPcker_Background.SelectedColor.Value.B;
|
||||
color = colorSelected;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,54 +19,24 @@ namespace Client.Views
|
||||
public partial class GameWindow : Window
|
||||
{
|
||||
ClientData data = ClientData.Instance;
|
||||
private ViewModelGame viewModel;
|
||||
public GameWindow()
|
||||
{
|
||||
DataContext = new ViewModelGame();
|
||||
this.viewModel = new ViewModelGame();
|
||||
DataContext = this.viewModel;
|
||||
InitializeComponent();
|
||||
|
||||
}
|
||||
Point currentPoint = new Point();
|
||||
|
||||
|
||||
private void CanvasForPaint_MouseDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (e.ButtonState == MouseButtonState.Pressed)
|
||||
{
|
||||
currentPoint = e.GetPosition(CanvasForPaint);
|
||||
}
|
||||
|
||||
this.viewModel.Canvas_MouseDown(e, this);
|
||||
}
|
||||
|
||||
private void CanvasForPaint_MouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
{
|
||||
Line line = new Line();
|
||||
|
||||
|
||||
line.Stroke = new SolidColorBrush(color);
|
||||
//line.Stroke = SystemColors.WindowFrameBrush;
|
||||
line.X1 = currentPoint.X;
|
||||
line.Y1 = currentPoint.Y;
|
||||
line.X2 = e.GetPosition(CanvasForPaint).X;
|
||||
line.Y2 = e.GetPosition(CanvasForPaint).Y;
|
||||
|
||||
currentPoint = e.GetPosition(CanvasForPaint);
|
||||
|
||||
CanvasForPaint.Children.Add(line);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Color color;
|
||||
|
||||
private void ClrPcker_Background_SelectedColorChanged(object sender, RoutedPropertyChangedEventArgs<Color> e)
|
||||
{
|
||||
Color colorSelected = new Color();
|
||||
colorSelected.A = 255;
|
||||
colorSelected.R = ClrPcker_Background.SelectedColor.Value.R;
|
||||
colorSelected.G = ClrPcker_Background.SelectedColor.Value.G;
|
||||
colorSelected.B = ClrPcker_Background.SelectedColor.Value.B;
|
||||
color = colorSelected;
|
||||
viewModel.Canvas_MouseMove(e, this);
|
||||
}
|
||||
|
||||
private void CanvasReset_Click(object sender, RoutedEventArgs e)
|
||||
@@ -87,12 +57,7 @@ namespace Client.Views
|
||||
|
||||
private void ClrPcker_Background_SelectedColorChanged_1(object sender, RoutedPropertyChangedEventArgs<Color?> e)
|
||||
{
|
||||
Color colorSelected = new Color();
|
||||
colorSelected.A = 255;
|
||||
colorSelected.R = ClrPcker_Background.SelectedColor.Value.R;
|
||||
colorSelected.G = ClrPcker_Background.SelectedColor.Value.G;
|
||||
colorSelected.B = ClrPcker_Background.SelectedColor.Value.B;
|
||||
color = colorSelected;
|
||||
viewModel.Color_Picker(e, this);
|
||||
}
|
||||
|
||||
private void ChatBox_KeyDown(object sender, KeyEventArgs e)
|
||||
|
||||
@@ -82,6 +82,7 @@ namespace Server.Models
|
||||
// start reading for a new message
|
||||
stream.BeginRead(buffer, 0, buffer.Length, new AsyncCallback(OnRead), null);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -123,6 +124,7 @@ namespace Server.Models
|
||||
// lobby data
|
||||
break;
|
||||
case JSONConvert.CANVAS:
|
||||
Debug.WriteLine("GOT A MESSAGE FROM THE CLIENT ABOUT THE CANVAS!!!");
|
||||
// canvas data
|
||||
// todo send canvas data to all other serverclients in lobby
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user