forked from ericlaw1979/babysmash
-
Notifications
You must be signed in to change notification settings - Fork 3
/
MainWindow.xaml.cs
122 lines (106 loc) · 3.72 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
namespace BabySmash
{
public partial class MainWindow : Window
{
private readonly Controller controller;
public Controller Controller { get { return controller; } }
private UserControl customCursor;
public UserControl CustomCursor { get { return customCursor; } set { customCursor = value; } }
public void AddFigure(UserControl c)
{
this.figuresCanvas.Children.Add(c);
}
public void RemoveFigure(UserControl c)
{
this.figuresCanvas.Children.Remove(c);
}
public MainWindow(Controller c)
{
this.controller = c;
this.DataContext = controller;
InitializeComponent();
//ResetCanvas();
}
protected override void OnMouseWheel(MouseWheelEventArgs e)
{
base.OnMouseWheel(e);
controller.MouseWheel(this, e);
}
protected override void OnMouseUp(MouseButtonEventArgs e)
{
base.OnMouseUp(e);
controller.MouseUp(this, e);
}
protected override void OnMouseDown(MouseButtonEventArgs e)
{
base.OnMouseDown(e);
controller.MouseDown(this, e);
}
protected override void OnMouseEnter(MouseEventArgs e)
{
base.OnMouseEnter(e);
AssertCursor();
CustomCursor.Visibility = Visibility.Visible;
}
protected override void OnMouseLeave(MouseEventArgs e)
{
base.OnMouseLeave(e);
CustomCursor.Visibility = Visibility.Hidden;
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
if (controller.isOptionsDialogShown == false)
{
CustomCursor.Visibility = Visibility.Visible;
Point p = e.GetPosition(mouseDragCanvas);
double pX = p.X;
double pY = p.Y;
Cursor = Cursors.None;
Canvas.SetTop(CustomCursor, pY);
Canvas.SetLeft(CustomCursor, pX);
Canvas.SetZIndex(CustomCursor, int.MaxValue);
}
controller.MouseMove(this, e);
}
protected override void OnKeyUp(KeyEventArgs e)
{
base.OnKeyUp(e);
e.Handled = true;
controller.ProcessKey(this, e);
}
protected override void OnLostMouseCapture(MouseEventArgs e)
{
base.OnLostMouseCapture(e);
controller.LostMouseCapture(this, e);
}
internal void AssertCursor()
{
try
{
mouseCursorCanvas.Children.Clear();
CustomCursor = Utils.GetCursor();
if (CustomCursor.Parent != null)
{
((Canvas)CustomCursor.Parent).Children.Remove(CustomCursor);
}
CustomCursor.RenderTransform = new ScaleTransform(0.5, 0.5);
CustomCursor.Name = "customCursor";
mouseCursorCanvas.Children.Insert(0, CustomCursor); //in front!
CustomCursor.Visibility = Visibility.Hidden;
}
catch (System.NotSupportedException)
{
//we can die here if we ALT-F4 while in the Options Dialog
}
}
private void Properties_Executed(object sender, ExecutedRoutedEventArgs e)
{
controller.ShowOptionsDialog();
}
}
}