Esempio n. 1
0
        private void SendActiveEvent(MouseInput input)
        {
            InputData newInput = CreateInputData(input);

            switch (input.State)
            {
            case InputState.Start:
                StartDraw?.Invoke(newInput);
                _previousInput = newInput;
                break;

            case InputState.Draw:
                if (newInput.Position != _previousInput.Position)
                {
                    DrawCall?.Invoke(newInput);
                    _previousInput = newInput;
                }
                break;

            case InputState.End:
                EndDraw?.Invoke(newInput);
                _previousInput = default;
                break;

            default:
                throw new Exception("Try send active event to disactive input");
            }
        }
Esempio n. 2
0
        private async void DrawFractalEventDown(bool showMsgBox)
        {
            try
            {
                IsDrawingGoing = true;
                //start length & recursion depth
                TextBox sLengthBox  = (TextBox)paramsGrid.Children[1];
                TextBox recDepthBox = (TextBox)paramsGrid.Children[3];
                Point   startPoint  = new Point(MainCanvas.Width / (2),
                                                MainCanvas.Height / (2));
                //hex values of start and end color
                string startColorText = ((TextBox)paramsGrid.Children[5]).Text;
                string endColorText   = ((TextBox)paramsGrid.Children[6]).Text;
                if (double.TryParse(sLengthBox.Text, out double length) &&
                    int.TryParse(recDepthBox.Text, out int depth) && depth > 0 &&
                    depth <= MaxRecDepth && length > 0 && length <= MaxLength &&
                    CheckColorString.Check(startColorText) && CheckColorString.Check(endColorText))
                {
                    int numberOfTrues = 0;
                    foreach (bool b in QCSidesDrawability)
                    {
                        if (b)
                        {
                            numberOfTrues++;
                        }
                    }
                    if (numberOfTrues != 3 && CurrentFractal == 1)
                    {
                        MessageBox.Show("Select three ellipses to draw...",
                                        "Soft's message", MessageBoxButton.OK,
                                        MessageBoxImage.Information);
                    }
                    else
                    {
                        //reset the canvas
                        Canvas newCanvas = new Canvas
                        {
                            Width      = 5000,
                            Height     = 5000,
                            Background = new SolidColorBrush(Color.FromRgb(255, 255, 255))
                        };
                        mainCanvasScroll.Content = MainCanvas = newCanvas;
                        //transform the canvas to it's original size
                        ScaleTransform transform = new ScaleTransform
                        {
                            ScaleX = CurrentScale = 1,
                            ScaleY = CurrentScale = 1,
                        };
                        MainCanvas.RenderTransform = transform;
                        Scroll(mainCanvasScroll.ScrollableWidth / 2, mainCanvasScroll.ScrollableHeight / 2);
                        //get the checkbox
                        List <CheckBox> checkBoxes = paramsGrid.Children.OfType <CheckBox>().ToList();
                        CheckBox        checkBox   = checkBoxes[0];
                        //intialize start draw object
                        StartDraw = new StartDraw
                        {
                            CurrentFractal     = CurrentFractal,
                            MainCanvas         = MainCanvas,
                            StartColor         = (Color)ColorConverter.ConvertFromString(startColorText),
                            EndColor           = (Color)ColorConverter.ConvertFromString(endColorText),
                            GoBtn              = (Button)paramsGrid.Children[paramsGrid.Children.Count - 1],
                            QCSidesDrawability = QCSidesDrawability
                        };
                        CancellationToken token = TokenSource.Token;
                        //set the priority
                        if (checkBox.IsChecked == false || checkBox.IsChecked == null)
                        {
                            cancelDrawingFirst.IsEnabled = false;
                            StartDraw.DispatcherPriority = DispatcherPriority.Send;
                            mainCanvasScroll.Content     = MainCanvas = await StartDraw.DrawFractal(length, depth,
                                                                                                    startPoint, Dispatcher, token);

                            cancelDrawingFirst.IsEnabled = true;
                        }
                        else
                        {
                            StartDraw.DispatcherPriority = DispatcherPriority.Background;
                            await StartDraw.DrawFractal(length, depth,
                                                        startPoint, Dispatcher, token);
                        }
                    }
                }
                else
                {
                    if (showMsgBox)
                    {
                        MessageBox.Show("Error in the input data",
                                        "Soft's message", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                }
            }
            catch (NullReferenceException ex)
            {
                MessageBox.Show(ex.Message, "Soft's message", MessageBoxButton.OK,
                                MessageBoxImage.Information);
            }
            catch (InvalidCastException ex)
            {
                MessageBox.Show(ex.Message, "Soft's message", MessageBoxButton.OK,
                                MessageBoxImage.Information);
            }
            catch (OutOfMemoryException ex)
            {
                MessageBox.Show(ex.Message, "Soft's message", MessageBoxButton.OK,
                                MessageBoxImage.Information);
            }
            catch (StackOverflowException ex)
            {
                MessageBox.Show(ex.Message, "Soft's message", MessageBoxButton.OK,
                                MessageBoxImage.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Soft's message", MessageBoxButton.OK,
                                MessageBoxImage.Information);
            }
            finally
            {
                IsDrawingGoing = false;
            }
        }