MainWindow.xaml.cs 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. using Microsoft.Win32;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Controls.Primitives;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Navigation;
  16. using System.Windows.Shapes;
  17. using System.Windows.Threading;
  18. namespace SketchAssistantWPF
  19. {
  20. /// <summary>
  21. /// Interaction logic for MainWindow.xaml
  22. /// </summary>
  23. public partial class MainWindow : Window, MVP_View
  24. {
  25. public MainWindow()
  26. {
  27. InitializeComponent();
  28. ProgramPresenter = new MVP_Presenter(this);
  29. // DispatcherTimer setup
  30. dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
  31. dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
  32. dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 33);
  33. }
  34. public enum ButtonState
  35. {
  36. Enabled,
  37. Disabled,
  38. Active
  39. }
  40. DispatcherTimer dispatcherTimer;
  41. /// <summary>
  42. /// Dialog to select a file.
  43. /// </summary>
  44. OpenFileDialog openFileDialog = new OpenFileDialog();
  45. /// <summary>
  46. /// All Lines in the current session
  47. /// </summary>
  48. List<Tuple<bool, InternalLine>> rightLineList = new List<Tuple<bool, InternalLine>>();
  49. /// <summary>
  50. /// Queue for the cursorPositions
  51. /// </summary>
  52. Queue<Point> cursorPositions = new Queue<Point>();
  53. /// <summary>
  54. /// The Presenter Component of the MVP-Model
  55. /// </summary>
  56. MVP_Presenter ProgramPresenter;
  57. /********************************************/
  58. /*** WINDOW SPECIFIC FUNCTIONS START HERE ***/
  59. /********************************************/
  60. private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
  61. {
  62. }
  63. private void RedoButton_Click(object sender, RoutedEventArgs e)
  64. {
  65. }
  66. private void UndoButton_Click(object sender, RoutedEventArgs e)
  67. {
  68. }
  69. private void DeleteButton_Click(object sender, RoutedEventArgs e)
  70. {
  71. }
  72. private void DrawButton_Click(object sender, RoutedEventArgs e)
  73. {
  74. }
  75. private void RightCanvas_MouseDown(object sender, MouseButtonEventArgs e)
  76. {
  77. }
  78. private void RightCanvas_MouseUp(object sender, MouseButtonEventArgs e)
  79. {
  80. }
  81. private void RightCanvas_MouseMove(object sender, MouseEventArgs e)
  82. {
  83. }
  84. /// <summary>
  85. /// Button to create a new Canvas. Will create an empty image
  86. /// which is the size of the left image, if there is one.
  87. /// If there is no image loaded the canvas will be the size of the right picture box
  88. /// </summary>
  89. private void CanvasButton_Click(object sender, RoutedEventArgs e)
  90. {
  91. ProgramPresenter.NewCanvas();
  92. }
  93. /// <summary>
  94. /// Ticks the Presenter.
  95. /// </summary>
  96. private void dispatcherTimer_Tick(object sender, EventArgs e)
  97. {
  98. ProgramPresenter.Tick();
  99. }
  100. /*************************/
  101. /*** PRESENTER -> VIEW ***/
  102. /*************************/
  103. /// <summary>
  104. /// Displays a list of lines in the left Picture box.
  105. /// </summary>
  106. /// <param name="img">The new image.</param>
  107. public void DisplayInLeftPictureBox(List<InternalLine> lineList)
  108. {
  109. foreach (InternalLine line in lineList)
  110. {
  111. Polyline newPolyLine = new Polyline();
  112. newPolyLine.Stroke = Brushes.Black;
  113. newPolyLine.Points = line.GetPointCollection();
  114. LeftCanvas.Children.Add(newPolyLine);
  115. }
  116. }
  117. /// <summary>
  118. /// Displays a list of lines in the right Picture box.
  119. /// </summary>
  120. /// <param name="img">The new image.</param>
  121. public void DisplayInRightPictureBox(List<InternalLine> lineList)
  122. {
  123. foreach (InternalLine line in lineList)
  124. {
  125. Polyline newPolyLine = new Polyline();
  126. newPolyLine.Stroke = Brushes.Black;
  127. newPolyLine.Points = line.GetPointCollection();
  128. LeftCanvas.Children.Add(newPolyLine);
  129. }
  130. }
  131. /// <summary>
  132. /// Enables the timer of the View, which will tick the Presenter.
  133. /// </summary>
  134. public void EnableTimer()
  135. {
  136. dispatcherTimer.Start();
  137. }
  138. /// <summary>
  139. /// A function that opens a file dialog and returns the filename.
  140. /// </summary>
  141. /// <param name="Filter">The filter that should be applied to the new Dialog.</param>
  142. /// <returns>Returns the FileName and the SafeFileName if the user correctly selects a file,
  143. /// else returns a tuple with empty strigns</returns>
  144. public Tuple<string, string> openNewDialog(string Filter)
  145. {
  146. openFileDialog.Filter = Filter;
  147. if (openFileDialog.ShowDialog() == true)
  148. {
  149. return new Tuple<string, string>(openFileDialog.FileName, openFileDialog.SafeFileName);
  150. }
  151. else
  152. {
  153. return new Tuple<string, string>("", "");
  154. }
  155. }
  156. /// <summary>
  157. /// Sets the contents of the last action taken indicator label.
  158. /// </summary>
  159. /// <param name="message">The new contents</param>
  160. public void SetLastActionTakenText(string message)
  161. {
  162. LastActionBox.Text = message;
  163. }
  164. /// <summary>
  165. /// Changes the states of a tool strip button.
  166. /// </summary>
  167. /// <param name="buttonName">The name of the button.</param>
  168. /// <param name="state">The new state of the button.</param>
  169. public void SetToolStripButtonStatus(string buttonName, MainWindow.ButtonState state)
  170. {
  171. ButtonBase buttonToChange;
  172. bool isToggleable = false;
  173. switch (buttonName)
  174. {
  175. case "canvasButton":
  176. buttonToChange = CanvasButton;
  177. break;
  178. case "drawButton":
  179. buttonToChange = DrawButton;
  180. isToggleable = true;
  181. break;
  182. case "deleteButton":
  183. buttonToChange = DeleteButton;
  184. isToggleable = true;
  185. break;
  186. case "undoButton":
  187. buttonToChange = UndoButton;
  188. break;
  189. case "redoButton":
  190. buttonToChange = RedoButton;
  191. break;
  192. default:
  193. Console.WriteLine("Invalid Button was given to SetToolStripButton. \nMaybe you forgot to add a case?");
  194. return;
  195. }
  196. if (isToggleable)
  197. {
  198. switch (state)
  199. {
  200. case ButtonState.Active:
  201. ((ToggleButton)buttonToChange).IsEnabled = true;
  202. ((ToggleButton)buttonToChange).IsChecked = true;
  203. break;
  204. case ButtonState.Disabled:
  205. ((ToggleButton)buttonToChange).IsEnabled = false;
  206. ((ToggleButton)buttonToChange).IsChecked = false;
  207. break;
  208. case ButtonState.Enabled:
  209. ((ToggleButton)buttonToChange).IsEnabled = true;
  210. ((ToggleButton)buttonToChange).IsChecked = false;
  211. break;
  212. }
  213. }
  214. else
  215. {
  216. switch (state)
  217. {
  218. case ButtonState.Disabled:
  219. ((Button)buttonToChange).IsEnabled = false;
  220. break;
  221. default:
  222. ((Button)buttonToChange).IsEnabled = true;
  223. break;
  224. }
  225. }
  226. }
  227. /// <summary>
  228. /// Sets the contents of the load status indicator label.
  229. /// </summary>
  230. /// <param name="message">The new contents</param>
  231. public void SetToolStripLoadStatus(string message)
  232. {
  233. LoadStatusBox.Text = message;
  234. }
  235. /// <summary>
  236. /// shows the given info message in a popup and asks the user to aknowledge it
  237. /// </summary>
  238. /// <param name="message">the message to show</param>
  239. public void ShowInfoMessage(string message)
  240. {
  241. MessageBox.Show(message);
  242. }
  243. /// <summary>
  244. /// Shows a warning box with the given message (Yes/No Buttons)and returns true if the user aknowledges it.
  245. /// </summary>
  246. /// <param name="message">The message of the warning.</param>
  247. /// <returns>True if the user confirms (Yes), negative if he doesn't (No)</returns>
  248. public bool ShowWarning(string message)
  249. {
  250. MessageBoxResult result = MessageBox.Show(message, "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning);
  251. return (result.Equals(MessageBoxResult.Yes));
  252. }
  253. }
  254. }