123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592 |
- using Microsoft.Win32;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Timers;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Controls.Primitives;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using System.Windows.Threading;
- using System.Windows.Ink;
- namespace SketchAssistantWPF
- {
-
-
-
- public partial class MainWindow : Window, MVP_View
- {
- public MainWindow()
- {
- bool InDebugMode = false;
- String[] commArgs = Environment.GetCommandLineArgs();
- InitializeComponent();
- if (commArgs.Length > 1)
- {
- if (commArgs[1].Equals("-debug"))
- {
- InDebugMode = true;
- }
- }
- if(!InDebugMode)
- {
- DebugMode.Visibility = Visibility.Collapsed;
- }
- ProgramPresenter = new MVP_Presenter(this);
-
- dispatcherTimer = new DispatcherTimer(DispatcherPriority.Render);
- dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
- dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 10);
- ProgramPresenter.Resize(new Tuple<int, int>((int)LeftCanvas.Width, (int)LeftCanvas.Height),
- new Tuple<int, int>((int)RightCanvas.Width, (int)RightCanvas.Height));
- }
- public enum ButtonState
- {
- Enabled,
- Disabled,
- Active
- }
- DispatcherTimer dispatcherTimer;
-
-
-
- OpenFileDialog openFileDialog = new OpenFileDialog();
-
-
-
- List<Tuple<bool, InternalLine>> rightLineList = new List<Tuple<bool, InternalLine>>();
-
-
-
- Queue<Point> cursorPositions = new Queue<Point>();
-
-
-
- MVP_Presenter ProgramPresenter;
-
-
-
- Polyline currentLine;
-
-
-
- bool debugRunning = false;
-
-
-
- DebugData debugDat = new DebugData();
-
-
-
- StrokeCollection strokeCollection = new StrokeCollection();
-
-
-
-
-
-
- private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
- {
- ProgramPresenter.Resize(new Tuple<int, int>((int)LeftCanvas.ActualWidth, (int)LeftCanvas.ActualHeight),
- new Tuple<int, int>((int)RightCanvas.ActualWidth, (int)RightCanvas.ActualHeight));
- }
-
-
-
- public void RightCanvas_StrokeCollection(object sender, InkCanvasStrokeCollectedEventArgs e)
- {
- strokeCollection.Add(e.Stroke);
- System.Diagnostics.Debug.WriteLine(strokeCollection.Count);
- }
-
-
-
- private void RedoButton_Click(object sender, RoutedEventArgs e)
- {
- ProgramPresenter.Redo();
- }
-
-
-
- private void UndoButton_Click(object sender, RoutedEventArgs e)
- {
- ProgramPresenter.Undo();
- }
-
-
-
- private void DeleteButton_Click(object sender, RoutedEventArgs e)
- {
- ProgramPresenter.ChangeState(false);
- RightCanvas.EditingMode = InkCanvasEditingMode.EraseByStroke;
- }
-
-
-
- private void DrawButton_Click(object sender, RoutedEventArgs e)
- {
- ProgramPresenter.ChangeState(true);
- RightCanvas.EditingMode = InkCanvasEditingMode.Ink;
- }
-
-
-
- private void RightCanvas_MouseDown(object sender, MouseButtonEventArgs e)
- {
- ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Down);
-
- }
-
-
-
- private void RightCanvas_MouseUp(object sender, MouseButtonEventArgs e)
- {
- if(strokeCollection.Count == 0)
- {
- ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Up_Invalid);
- }
- else
- {
- ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Up);
- RightCanvas.Strokes.RemoveAt(0);
- strokeCollection.RemoveAt(0);
- System.Diagnostics.Debug.WriteLine(strokeCollection.Count);
- }
-
- }
-
-
-
- private void RightCanvas_MouseMove(object sender, MouseEventArgs e)
- {
- ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Move, e.GetPosition(RightCanvas));
-
- }
-
-
-
-
-
- private void CanvasButton_Click(object sender, RoutedEventArgs e)
- {
- ProgramPresenter.NewCanvas();
- RightCanvas.EditingMode = InkCanvasEditingMode.Ink;
- RightCanvas.Strokes.Clear();
- }
-
-
-
- private void dispatcherTimer_Tick(object sender, EventArgs e)
- {
- ProgramPresenter.Tick();
-
- }
-
-
-
- private void ISADMenuItem_Click(object sender, RoutedEventArgs e)
- {
- ProgramPresenter.ExamplePictureToolStripMenuItemClick();
- }
-
-
-
- private void SVGMenuItem_Click(object sender, RoutedEventArgs e)
- {
- ProgramPresenter.SVGToolStripMenuItemClick();
- }
-
-
-
-
-
-
-
- public Point GetCursorPosition()
- {
- return Mouse.GetPosition(RightCanvas);
- }
-
-
-
-
- public bool IsMousePressed()
- {
- if (!debugRunning) {
- return (Mouse.LeftButton.Equals(MouseButtonState.Pressed) || Mouse.RightButton.Equals(MouseButtonState.Pressed)); }
- else return true;
- }
-
-
-
- public void RemoveCurrLine()
- {
- RightCanvas.Children.Remove(currentLine);
- }
-
-
-
-
- public void DisplayCurrLine(Polyline line)
- {
- if (RightCanvas.Children.Contains(currentLine))
- {
- RemoveCurrLine();
- }
- RightCanvas.Children.Add(line);
- currentLine = line;
- }
-
-
-
- public void RemoveAllLeftLines()
- {
- LeftCanvas.Children.Clear();
- }
-
-
-
- public void RemoveAllRightLines()
- {
- RightCanvas.Children.Clear();
- }
-
-
-
-
- public void AddNewLineLeft(Polyline newLine)
- {
- newLine.Stroke = Brushes.Black;
- newLine.StrokeThickness = 2;
- LeftCanvas.Children.Add(newLine);
- }
-
-
-
-
- public void AddNewLineRight(Polyline newLine)
- {
- newLine.Stroke = Brushes.Black;
- newLine.StrokeThickness = 2;
- RightCanvas.Children.Add(newLine);
- }
-
-
-
-
- public void AddNewPointRight(Ellipse newPoint, InternalLine line)
- {
- newPoint.Height = 3; newPoint.Width = 3;
- newPoint.Fill = Brushes.Black;
- RightCanvas.Children.Add(newPoint);
- newPoint.Margin = new Thickness(line.point.X - 1.5, line.point.Y - 1.5, 0,0);
- }
-
-
-
-
- public void AddNewPointLeft(Ellipse newPoint)
- {
- newPoint.Height = 3; newPoint.Width = 3;
- newPoint.Fill = Brushes.Black;
- LeftCanvas.Children.Add(newPoint);
- }
-
-
-
- public void EnableTimer()
- {
- dispatcherTimer.Start();
- }
-
-
-
-
-
-
- public Tuple<string, string> openNewDialog(string Filter)
- {
- openFileDialog.Filter = Filter;
- if (openFileDialog.ShowDialog() == true)
- {
- return new Tuple<string, string>(openFileDialog.FileName, openFileDialog.SafeFileName);
- }
- else
- {
- return new Tuple<string, string>("", "");
- }
- }
-
-
-
-
- public void SetLastActionTakenText(string message)
- {
- LastActionBox.Text = message;
- }
-
-
-
-
-
- public void SetToolStripButtonStatus(string buttonName, MainWindow.ButtonState state)
- {
- ButtonBase buttonToChange;
- bool isToggleable = false;
- switch (buttonName)
- {
- case "canvasButton":
- buttonToChange = CanvasButton;
- break;
- case "drawButton":
- buttonToChange = DrawButton;
- isToggleable = true;
- break;
- case "deleteButton":
- buttonToChange = DeleteButton;
- isToggleable = true;
- break;
- case "undoButton":
- buttonToChange = UndoButton;
- break;
- case "redoButton":
- buttonToChange = RedoButton;
- break;
- default:
- Console.WriteLine("Invalid Button was given to SetToolStripButton. \nMaybe you forgot to add a case?");
- return;
- }
- if (isToggleable)
- {
- switch (state)
- {
- case ButtonState.Active:
- ((ToggleButton)buttonToChange).IsEnabled = true;
- ((ToggleButton)buttonToChange).IsChecked = true;
- ((ToggleButton)buttonToChange).Opacity = 1;
- ((ToggleButton)buttonToChange).Background = Brushes.SkyBlue;
- break;
- case ButtonState.Disabled:
- ((ToggleButton)buttonToChange).IsEnabled = false;
- ((ToggleButton)buttonToChange).IsChecked = false;
- ((ToggleButton)buttonToChange).Opacity = 0.5;
- ((ToggleButton)buttonToChange).Background = Brushes.LightGray;
- break;
- case ButtonState.Enabled:
- ((ToggleButton)buttonToChange).IsEnabled = true;
- ((ToggleButton)buttonToChange).IsChecked = false;
- ((ToggleButton)buttonToChange).Opacity = 1;
- ((ToggleButton)buttonToChange).Background = Brushes.LightGray;
- break;
- }
- }
- else
- {
- switch (state)
- {
- case ButtonState.Disabled:
- ((Button)buttonToChange).IsEnabled = false;
- ((Button)buttonToChange).Opacity = 0.5;
- break;
- default:
- ((Button)buttonToChange).IsEnabled = true;
- ((Button)buttonToChange).Opacity = 1;
- break;
- }
- }
- }
-
-
-
-
- public void SetToolStripLoadStatus(string message)
- {
- LoadStatusBox.Text = message;
- }
-
-
-
-
- public void ShowInfoMessage(string message)
- {
- MessageBox.Show(message);
- }
-
-
-
-
-
- public bool ShowWarning(string message)
- {
- MessageBoxResult result = MessageBox.Show(message, "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning);
- return (result.Equals(MessageBoxResult.Yes));
- }
-
-
-
-
-
- public void SetCanvasState(string canvasName, bool active)
- {
- switch (canvasName)
- {
- case ("LeftCanvas"):
- if (active)
- {
- LeftCanvas.Background = Brushes.White;
- }
- else
- {
- LeftCanvas.Background = Brushes.SlateGray;
- }
- break;
- case ("RightCanvas"):
- if (active)
- {
- RightCanvas.Background = Brushes.White;
- }
- else
- {
- RightCanvas.Background = Brushes.SlateGray;
- }
- break;
- default:
- throw new InvalidOperationException("Unknown canvas name, Check that the canvas passed is either LeftCanvas or RightCanvas");
- }
- }
-
-
-
-
-
-
-
- private void DebugOne_Click(object sender, RoutedEventArgs e)
- {
- Debug(1);
- }
-
-
-
-
- private void DebugTwo_Click(object sender, RoutedEventArgs e)
- {
- Debug(2);
- }
-
-
-
-
- private void DebugThree_Click(object sender, RoutedEventArgs e)
- {
- Debug(3);
- }
-
-
-
-
- private void DebugFour_Click(object sender, RoutedEventArgs e)
- {
- Debug(4);
- }
-
-
-
-
- private async void Debug(int option)
- {
- Point[] points;
- Point start = new Point(50, 50);
- switch (option)
- {
- case 1:
- points = debugDat.debugPoints1;
- break;
- case 2:
- points = debugDat.debugPoints2;
- break;
- case 3:
- points = debugDat.debugPoints3;
- break;
- case 4:
- points = debugDat.debugPoints4;
- start = new Point(284, 148);
- break;
- default:
- return;
- }
- dispatcherTimer.Stop();
- debugRunning = true;
- ProgramPresenter.Tick(); await Task.Delay(10);
- ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Move, start);
- ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Down); await Task.Delay(10);
- for (int x = 0; x < points.Length; x++)
- {
- ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Move, points[x]);
- await Task.Delay(1);
- if (x % 5 == 0)
- {
- ProgramPresenter.Tick();
- await Task.Delay(1);
- }
- }
- ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Up); await Task.Delay(1);
- debugRunning = false;
- dispatcherTimer.Start();
- }
- }
- }
|