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.ComponentModel;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Shapes;
|
||||||
|
|
||||||
namespace Client.ViewModels
|
namespace Client.ViewModels
|
||||||
{
|
{
|
||||||
class ViewModelGame : INotifyPropertyChanged
|
class ViewModelGame : INotifyPropertyChanged
|
||||||
{
|
{
|
||||||
|
private ClientData data = ClientData.Instance;
|
||||||
|
|
||||||
public event PropertyChangedEventHandler PropertyChanged;
|
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
|
public partial class GameWindow : Window
|
||||||
{
|
{
|
||||||
ClientData data = ClientData.Instance;
|
ClientData data = ClientData.Instance;
|
||||||
|
private ViewModelGame viewModel;
|
||||||
public GameWindow()
|
public GameWindow()
|
||||||
{
|
{
|
||||||
DataContext = new ViewModelGame();
|
this.viewModel = new ViewModelGame();
|
||||||
|
DataContext = this.viewModel;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
}
|
}
|
||||||
Point currentPoint = new Point();
|
|
||||||
|
|
||||||
private void CanvasForPaint_MouseDown(object sender, MouseButtonEventArgs e)
|
private void CanvasForPaint_MouseDown(object sender, MouseButtonEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.ButtonState == MouseButtonState.Pressed)
|
this.viewModel.Canvas_MouseDown(e, this);
|
||||||
{
|
|
||||||
currentPoint = e.GetPosition(CanvasForPaint);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CanvasForPaint_MouseMove(object sender, MouseEventArgs e)
|
private void CanvasForPaint_MouseMove(object sender, MouseEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.LeftButton == MouseButtonState.Pressed)
|
viewModel.Canvas_MouseMove(e, this);
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CanvasReset_Click(object sender, RoutedEventArgs e)
|
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)
|
private void ClrPcker_Background_SelectedColorChanged_1(object sender, RoutedPropertyChangedEventArgs<Color?> e)
|
||||||
{
|
{
|
||||||
Color colorSelected = new Color();
|
viewModel.Color_Picker(e, this);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ChatBox_KeyDown(object sender, KeyEventArgs e)
|
private void ChatBox_KeyDown(object sender, KeyEventArgs e)
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ namespace Server.Models
|
|||||||
// start reading for a new message
|
// start reading for a new message
|
||||||
stream.BeginRead(buffer, 0, buffer.Length, new AsyncCallback(OnRead), null);
|
stream.BeginRead(buffer, 0, buffer.Length, new AsyncCallback(OnRead), null);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -123,6 +124,7 @@ namespace Server.Models
|
|||||||
// lobby data
|
// lobby data
|
||||||
break;
|
break;
|
||||||
case JSONConvert.CANVAS:
|
case JSONConvert.CANVAS:
|
||||||
|
Debug.WriteLine("GOT A MESSAGE FROM THE CLIENT ABOUT THE CANVAS!!!");
|
||||||
// canvas data
|
// canvas data
|
||||||
// todo send canvas data to all other serverclients in lobby
|
// todo send canvas data to all other serverclients in lobby
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user