2016-02-21 05:35:03 +03:00
|
|
|
|
using System.Windows;
|
2008-06-14 08:45:23 +04:00
|
|
|
|
using System.Windows.Controls;
|
2008-06-12 09:31:43 +04:00
|
|
|
|
using System.Windows.Input;
|
2008-07-18 21:07:51 +04:00
|
|
|
|
using System.Windows.Media;
|
2008-06-12 09:31:43 +04:00
|
|
|
|
|
|
|
|
|
namespace BabySmash
|
|
|
|
|
{
|
2008-07-11 00:47:38 +04:00
|
|
|
|
public partial class MainWindow : Window
|
|
|
|
|
{
|
|
|
|
|
private readonly Controller controller;
|
|
|
|
|
public Controller Controller { get { return controller; } }
|
|
|
|
|
|
2008-07-18 21:07:51 +04:00
|
|
|
|
private UserControl customCursor;
|
|
|
|
|
public UserControl CustomCursor { get { return customCursor; } set { customCursor = value; } }
|
2016-02-21 05:35:03 +03:00
|
|
|
|
|
2008-07-29 04:45:54 +04:00
|
|
|
|
public void AddFigure(UserControl c)
|
2008-07-11 00:47:38 +04:00
|
|
|
|
{
|
2008-07-29 04:45:54 +04:00
|
|
|
|
this.figuresCanvas.Children.Add(c);
|
2008-07-11 00:47:38 +04:00
|
|
|
|
}
|
|
|
|
|
|
2008-07-29 04:45:54 +04:00
|
|
|
|
public void RemoveFigure(UserControl c)
|
|
|
|
|
{
|
2016-02-21 05:35:03 +03:00
|
|
|
|
this.figuresCanvas.Children.Remove(c);
|
2008-07-29 04:45:54 +04:00
|
|
|
|
}
|
2008-07-18 21:07:51 +04:00
|
|
|
|
|
2008-07-11 00:47:38 +04:00
|
|
|
|
public MainWindow(Controller c)
|
|
|
|
|
{
|
|
|
|
|
this.controller = c;
|
|
|
|
|
this.DataContext = controller;
|
|
|
|
|
InitializeComponent();
|
2008-07-18 21:07:51 +04:00
|
|
|
|
|
2008-09-18 04:03:58 +04:00
|
|
|
|
//ResetCanvas();
|
2008-07-11 00:47:38 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnMouseWheel(MouseWheelEventArgs e)
|
|
|
|
|
{
|
2016-02-21 05:35:03 +03:00
|
|
|
|
base.OnMouseWheel(e);
|
|
|
|
|
controller.MouseWheel(this, e);
|
2008-07-11 00:47:38 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnMouseUp(MouseButtonEventArgs e)
|
|
|
|
|
{
|
2016-02-21 05:35:03 +03:00
|
|
|
|
base.OnMouseUp(e);
|
|
|
|
|
controller.MouseUp(this, e);
|
2008-07-11 00:47:38 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnMouseDown(MouseButtonEventArgs e)
|
|
|
|
|
{
|
2016-02-21 05:35:03 +03:00
|
|
|
|
base.OnMouseDown(e);
|
|
|
|
|
controller.MouseDown(this, e);
|
2008-07-11 00:47:38 +04:00
|
|
|
|
}
|
|
|
|
|
|
2008-07-18 21:07:51 +04:00
|
|
|
|
protected override void OnMouseEnter(MouseEventArgs e)
|
|
|
|
|
{
|
2016-02-21 05:35:03 +03:00
|
|
|
|
base.OnMouseEnter(e);
|
|
|
|
|
AssertCursor();
|
|
|
|
|
CustomCursor.Visibility = Visibility.Visible;
|
2008-07-18 21:07:51 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnMouseLeave(MouseEventArgs e)
|
|
|
|
|
{
|
2016-02-21 05:35:03 +03:00
|
|
|
|
base.OnMouseLeave(e);
|
|
|
|
|
CustomCursor.Visibility = Visibility.Hidden;
|
2008-07-18 21:07:51 +04:00
|
|
|
|
}
|
|
|
|
|
|
2008-07-11 00:47:38 +04:00
|
|
|
|
protected override void OnMouseMove(MouseEventArgs e)
|
|
|
|
|
{
|
2016-02-21 05:35:03 +03:00
|
|
|
|
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);
|
2008-07-11 00:47:38 +04:00
|
|
|
|
}
|
2016-02-21 05:35:03 +03:00
|
|
|
|
|
2008-07-11 00:47:38 +04:00
|
|
|
|
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);
|
|
|
|
|
}
|
2008-07-18 21:07:51 +04:00
|
|
|
|
|
2008-09-18 04:03:58 +04:00
|
|
|
|
internal void AssertCursor()
|
2008-07-18 21:07:51 +04:00
|
|
|
|
{
|
2016-02-21 05:35:03 +03:00
|
|
|
|
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
|
|
|
|
|
}
|
2008-07-18 21:07:51 +04:00
|
|
|
|
}
|
2008-07-11 00:47:38 +04:00
|
|
|
|
}
|
|
|
|
|
}
|