Advertisement
StreetKatya

Creator

Dec 21st, 2022
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.65 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Shapes;
  14. using FiguresLib;
  15.  
  16. namespace Abstractus
  17. {
  18. /// <summary>
  19. /// Логика взаимодействия для Creator.xaml
  20. /// </summary>
  21.  
  22. public partial class Creator : Window
  23. {
  24.  
  25. public string typeFigure;
  26. public Creator()
  27. {
  28. var timer = new System.Timers.Timer();
  29. timer.Interval = 500;
  30. timer.Elapsed += OnTimeElapsed;
  31. timer.Start();
  32. InitializeComponent();
  33. StartSettings();
  34. Polsun.Value = 70;
  35. }
  36. public void ChoiceFigure(object sender, string typeFigure)
  37. {
  38. Button button = sender as Button;
  39.  
  40. button.Effect = new System.Windows.Media.Effects.DropShadowEffect() { BlurRadius = 30, ShadowDepth = 0, Color = new Color { A = 100, B = 211, G = 0, R = 148 } };
  41.  
  42. if (typeFigure == "circle")
  43. {
  44. Triangle_button.Effect = new System.Windows.Media.Effects.DropShadowEffect() { BlurRadius = 0, ShadowDepth = 0 };
  45. Square_button.Effect = new System.Windows.Media.Effects.DropShadowEffect() { BlurRadius = 0, ShadowDepth = 0 };
  46. }
  47. else if (typeFigure == "triangle")
  48. {
  49. Circle_button.Effect = new System.Windows.Media.Effects.DropShadowEffect() { BlurRadius = 0, ShadowDepth = 0 };
  50. Square_button.Effect = new System.Windows.Media.Effects.DropShadowEffect() { BlurRadius = 0, ShadowDepth = 0 };
  51. }
  52. else
  53. {
  54. Triangle_button.Effect = new System.Windows.Media.Effects.DropShadowEffect() { BlurRadius = 0, ShadowDepth = 0 };
  55. Circle_button.Effect = new System.Windows.Media.Effects.DropShadowEffect() { BlurRadius = 0, ShadowDepth = 0 };
  56. }
  57. }
  58.  
  59.  
  60. private void OnTimeElapsed(object sender, System.Timers.ElapsedEventArgs e)
  61. {
  62. TextHint.Dispatcher.Invoke(() =>
  63. {
  64. if (Triangle_button.AllowDrop == false && Square_button.AllowDrop == false && Circle_button.AllowDrop == false)
  65. {
  66. TextHint.Foreground = Brushes.RosyBrown;
  67. TextHint.Text = "Выберите фигуру, чтобы начать рисовать";
  68.  
  69. }
  70. else if (Color_comboBox.SelectedIndex == -1) { TextHint.Foreground = Brushes.Coral; TextHint.Text = "Выберите цвет фигуры, чтобы начать рисовать"; }
  71. else { TextHint.Foreground = Brushes.OliveDrab; TextHint.Text = "Рисуйте!"; }
  72. });
  73.  
  74. }
  75.  
  76. private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  77. {
  78.  
  79. }
  80.  
  81. private void ComboBox_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
  82. {
  83.  
  84. }
  85.  
  86. private void Button_Click_Triangle(object sender, RoutedEventArgs e)
  87. {
  88. <<<<<<< HEAD
  89. Triangle_button.AllowDrop = true;
  90. Square_button.AllowDrop = false;
  91. Circle_button.AllowDrop = false;
  92. //Square_button.IsEnabled = false;
  93. //Hexa_button.IsEnabled = false;
  94. //Octa_button.IsEnabled = false;
  95. //Triangle_button.IsEnabled = true;
  96. typeFigure = "Triangle";
  97. Triangle_button.Background = Brushes.Red;
  98. Square_button.Background = Brushes.White;
  99. Circle_button.Background = Brushes.White;
  100. =======
  101. string typefigure = "triangle";
  102. ChoiceFigure(sender, typefigure);
  103. >>>>>>> 73a877980900c1fd2503075fcea0f95f9c1e0cd2
  104. }
  105.  
  106. private void Button_Click_Square(object sender, RoutedEventArgs e)
  107. {
  108. <<<<<<< HEAD
  109. Triangle_button.AllowDrop = false;
  110. Square_button.AllowDrop = true;
  111. Circle_button.AllowDrop = false;
  112. //Square_button.IsEnabled = true;
  113. //Hexa_button.IsEnabled = false;
  114. //Octa_button.IsEnabled = false;
  115. //Triangle_button.IsEnabled = false;
  116. typeFigure = "Square";
  117. Square_button.Background = Brushes.Red;
  118. Triangle_button.Background = Brushes.White;
  119. Circle_button.Background = Brushes.White;
  120. =======
  121. string typefigure = "square";
  122. ChoiceFigure(sender, typefigure);
  123. >>>>>>> 73a877980900c1fd2503075fcea0f95f9c1e0cd2
  124. }
  125. private void Button_Click_Circle(object sender, RoutedEventArgs e)
  126. {
  127. <<<<<<< HEAD
  128. Triangle_button.AllowDrop = false;
  129. Square_button.AllowDrop = false;
  130. Circle_button.AllowDrop = false;
  131. //Square_button.IsEnabled = false;
  132. //Hexa_button.IsEnabled = true;
  133. //Octa_button.IsEnabled = false;
  134. //Triangle_button.IsEnabled = false;
  135. typeFigure = "Hexa";
  136. Circle_button.Background = Brushes.White;
  137. Square_button.Background = Brushes.White;
  138. Triangle_button.Background = Brushes.White;
  139. }
  140.  
  141. private void Button_Click_Octa(object sender, RoutedEventArgs e)
  142. {
  143. Triangle_button.AllowDrop = false;
  144. Square_button.AllowDrop = false;
  145. Circle_button.AllowDrop = true;
  146. //Square_button.IsEnabled = false;
  147. //Hexa_button.IsEnabled = false;
  148. //Octa_button.IsEnabled = true;
  149. //Triangle_button.IsEnabled = false;
  150. typeFigure = "Octa";
  151. Circle_button.Background = Brushes.Red;
  152. Square_button.Background = Brushes.White;
  153. Triangle_button.Background = Brushes.White;
  154. =======
  155. string typefigure = "circle";
  156. ChoiceFigure(sender, typefigure);
  157.  
  158. >>>>>>> 73a877980900c1fd2503075fcea0f95f9c1e0cd2
  159. }
  160. private void StartSettings()
  161. {
  162. Canvas.SetZIndex(Settings_Canvas, 10);
  163. Canvas.SetZIndex(LeftRect, 2);
  164. Canvas.SetZIndex(RightRect, 2);
  165. Canvas.SetZIndex(UpRect, 2);
  166. Canvas.SetZIndex(DownRect, 2);
  167. Canvas.SetZIndex(PaintField_Canvas, 0);
  168. Canvas.SetZIndex(TextHint, 3);
  169.  
  170.  
  171. }
  172. private void AddFigure_button_Click(object sender, RoutedEventArgs e)
  173. {
  174.  
  175. string selectButton;
  176. //foreach(Button button in Settings_Canvas.Children)
  177. //{
  178. // if(button.Background == Brushes.Red)
  179. // {
  180. // selectButton = button.Name;
  181. // }
  182. //}
  183. while (true)
  184. {
  185. Polygon triangle = new Polygon();
  186. Point point1 = new Point();
  187. point1.X = Mouse.GetPosition(this).X;
  188. point1.Y = Mouse.GetPosition(this).Y;
  189. Point point2 = new Point();
  190. point2.X = Mouse.GetPosition((this)).X - 25;
  191. point2.Y = Mouse.GetPosition(this).Y + 25 * Math.Sqrt(3);
  192. Point point3 = new Point();
  193. point3.X = Mouse.GetPosition((this)).X + 25;
  194. point3.Y = Mouse.GetPosition(this).Y + 25 * Math.Sqrt(3);
  195. PointCollection points = new PointCollection() { point1, point2, point3 };
  196. triangle.Points = points;
  197. triangle.Fill = Brushes.AliceBlue;
  198. triangle.Stroke = Brushes.Blue;
  199. if (Mouse.MouseDownEvent != null)
  200. {
  201. Settings_Canvas.Children.Add(triangle);
  202. }
  203. }
  204. //if (typeFigure == "Triangle")
  205. //{
  206.  
  207. //}
  208. //else if(typeFigure == "Square")
  209. //{
  210.  
  211. //}
  212. //else if(typeFigure == "Hexa")
  213. //{
  214.  
  215. //}
  216. //else if(typeFigure == "Octa")
  217. //{
  218.  
  219. //}
  220. }
  221. private void PaintField_Canvas_OnMouseMove(object sender, MouseEventArgs e)
  222. {
  223. if (e.MouseDevice.LeftButton == MouseButtonState.Pressed)
  224. {
  225. //PaintField_Canvas.Children.Add(new Line
  226. //{
  227. // X1 = e.GetPosition(PaintField_Canvas).X,
  228. // Y1 = e.GetPosition(PaintField_Canvas).Y,
  229. // X2 = e.GetPosition(PaintField_Canvas).X + 1,
  230. // Y2 = e.GetPosition(PaintField_Canvas).Y + 1,
  231. // StrokeStartLineCap = PenLineCap.Round,
  232. // StrokeEndLineCap = PenLineCap.Round,
  233. // StrokeThickness = 1,
  234. // Stroke = Brushes.Black
  235. //});
  236. //Ellipse el = new Ellipse();
  237. // el.Fill = Brushes.Black;
  238. // el.Width = 200;
  239. // el.Height = 200;
  240. // el.VerticalAlignment = VerticalAlignment.Center;
  241. // PaintField_Canvas.Children.Add(el);
  242. // el.Visibility = Visibility.Visible;
  243.  
  244. }
  245. }
  246. private void PaintField_Canvas_MouseLeftButtonDown(object sender, MouseEventArgs e)
  247. {
  248. //Point mousePos = e.GetPosition(this);
  249. MyPoint mousePos = new MyPoint(e.GetPosition(this.PaintField_Canvas).X, e.GetPosition(this.PaintField_Canvas).Y);
  250.  
  251.  
  252. if (Circle_button.AllowDrop)
  253. {
  254. var circle = new Circle(mousePos,new Color() { A = 200, R = 0, G = 128, B = 128} , (int)Polsun.Value);
  255. Ellipse newEl = new Ellipse();
  256. newEl.Fill = new SolidColorBrush(circle.color);
  257. newEl.Width = circle.size;
  258. newEl.Height = circle.size;
  259. newEl.Margin = new Thickness(circle.mousePos.X - newEl.Width / 2, circle.mousePos.Y - newEl.Width / 2, 0, 0);
  260. PaintField_Canvas.Children.Add(newEl);
  261.  
  262. Canvas.SetZIndex(newEl, 1);
  263. }
  264. else if(Square_button.AllowDrop)
  265. {
  266. var square = new Square(mousePos, new Color() { A = 128, R = 255, G = 128, B = 0 }, (int)Polsun.Value);
  267. Rectangle newEl = new Rectangle();
  268. newEl.Fill = new SolidColorBrush(square.color);
  269. newEl.Width = square.size;
  270. newEl.Height = square.size;
  271. newEl.Margin = new Thickness(square.mousePos.X - newEl.Width / 2, mousePos.Y - newEl.Width / 2, 0, 0);
  272. PaintField_Canvas.Children.Add(newEl);
  273.  
  274. Canvas.SetZIndex(newEl, 1);
  275. }
  276. else if(Triangle_button.AllowDrop)
  277. {
  278. var triangle = new Triangle(mousePos, new Color() { A = 128, R = 128, G = 255, B = 0 }, (int)Polsun.Value);
  279. Polyline newEl = new Polyline();
  280. newEl.Fill = new SolidColorBrush(triangle.color);
  281. newEl.Margin = new Thickness(triangle.mousePos.X, mousePos.Y, 0, 0);
  282. newEl.Points = new PointCollection() { new Point(triangle.point1.X, triangle.point1.Y), new Point(triangle.point2.X, triangle.point2.Y), new Point(triangle.point3.X, triangle.point3.Y) };
  283.  
  284. PaintField_Canvas.Children.Add(newEl);
  285.  
  286. Canvas.SetZIndex(newEl, 1);
  287. }
  288.  
  289. }
  290. }
  291. }
  292.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement