Ejemplo n.º 1
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            bmp = new Bgra32BitmapTool(100, 100, 10);
            bmp.PropertyChanged += Bmp_PropertyChanged;
            bmp.SaveCheckpoint();

            this.CurrentBackColor = Colors.White;
            this.CurrentForeColor = Colors.Black;

            this.CurrentTool = ToolType.Freehand_DrawLine;
        }
Ejemplo n.º 2
0
        private void MenuItem_EasterEgg_Click(object sender, RoutedEventArgs e)
        {
            if (EasterEgg_Timer != null)
            {
                EasterEgg_Timer.Stop();
                EasterEgg_Timer     = null;
                EasterEgg_Counter   = 0;
                EasterEgg_isGrowing = true;
                return;
            }
            bmp = new Bgra32BitmapTool(
                width: 113,
                height: 213,
                xResolution: 96.0,
                yResolution: 96.0);
            bmp.PropertyChanged += Bmp_PropertyChanged;

            bmp.Ellipse_BresenhamRect(10, 10, 100, 100, Colors.Orange);

            bmp.Circle_Bresenham(40, 40, 5, Colors.Orange);
            bmp.Fill_FF4_Dynamic(40, 40, Colors.LightGray);

            bmp.Circle_Bresenham(70, 40, 5, Colors.Orange);
            bmp.Fill_FF4_Dynamic(70, 40, Colors.LightGray);

            bmp.QuadraticBezier(30, 75, 55, 95, 80, 75, Colors.Orange);

            bmp.Rectangle_Empty(1, 100, 111, 210, Colors.Blue);
            bmp.Rectangle_Empty(16, 115, 96, 195, Colors.Blue);
            bmp.Fill_FF4_Dynamic(2, 101, Colors.SteelBlue);

            bmp.Apply();
            bmp.SaveCheckpoint();
            EasterEgg_Timer          = new Timer(2 * 1000);
            EasterEgg_Timer.Elapsed += (_sender, _e) =>
            {
                if (EasterEgg_isGrowing)
                {
                    if (EasterEgg_Counter < EasterEgg_MaxGrow)
                    {
                        EasterEgg_Counter++;
                    }
                    else
                    {
                        EasterEgg_isGrowing = false;
                        EasterEgg_Counter--;
                    }
                }
                else
                if (EasterEgg_Counter > 0)
                {
                    EasterEgg_Counter--;
                }
                else
                {
                    EasterEgg_isGrowing = true;
                    EasterEgg_Counter++;
                }
                this.Dispatcher.Invoke(delegate
                {
                    bmp.Rotate_90C();
                    if (EasterEgg_isGrowing)
                    {
                        bmp.Scale(bmp.Width * 2, bmp.Height * 2, bmp.XResolution, bmp.YResolution);
                    }
                    else
                    {
                        bmp.Scale(bmp.Width / 2, bmp.Height / 2, bmp.XResolution, bmp.YResolution);
                    }
                    bmp.Apply();
                    bmp.SaveCheckpoint();
                });
            };
            EasterEgg_Timer.Start();
        }
Ejemplo n.º 3
0
        private void CommandExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            RoutedUICommand cmd = e.Command as RoutedUICommand;

            switch (cmd.Name)
            {
            case "Undo": bmp.Undo(); break;

            case "Redo": bmp.Redo(); break;

            case "Close": this.Close(); break;

            case "New":
                SizeDialogBox sdb = new SizeDialogBox()
                {
                    Values_Width       = bmp.Width,
                    Values_Height      = bmp.Height,
                    Values_XResolution = bmp.XResolution,
                    Values_YResolution = bmp.YResolution
                };

                sdb.Owner = this;
                var res = sdb.ShowDialog();

                if (res.HasValue)
                {
                    if (res.Value)
                    {
                        bmp = new Bgra32BitmapTool(
                            sdb.Values_Width,
                            sdb.Values_Height,
                            sdb.Values_XResolution,
                            sdb.Values_YResolution
                            );
                        bmp.PropertyChanged += Bmp_PropertyChanged;
                        this.CurrentFilePath = null;
                    }
                }
                break;

            case "Open":
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Filter = "Supported image files (*.jpg;*.jpeg;*.png;*.bmp;*.gif;*.tif;*.tiff;*.ico)|*.jpg;*.jpeg;*.png;*.bmp;*.gif;*.tif;*.tiff;*.ico|All files (*.*)|*.*";
                if (ofd.ShowDialog() == true)
                {
                    bmp = new Bgra32BitmapTool(new Uri(ofd.FileName, UriKind.RelativeOrAbsolute));
                    bmp.PropertyChanged += Bmp_PropertyChanged;
                    this.CurrentFilePath = ofd.FileName;
                }
                break;

            case "SaveAs":
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Filter = "Supported image files (*.png;*.jpg;*.jpeg;*.bmp;*.gif;*.tif;*.tiff;*.ico)|*.png;*.jpg;*.jpeg;*.bmp;*.gif;*.tif;*.tiff;*.ico|All files (*.*)|*.*";
                if (sfd.ShowDialog() == true)
                {
                    this.CurrentFilePath = sfd.FileName;
                    this.GetCommand("Save")?.Execute(null, null);
                }
                break;

            case "Save":
                if (string.IsNullOrEmpty(this.CurrentFilePath))
                {
                    this.GetCommand("SaveAs")?.Execute(null, null);
                }
                else
                {
                    do
                    {
                        try
                        {
                            switch (this.CurrentFileExtension)
                            {
                            case ".bmp":
                                bmp.SaveBmp(this.CurrentFilePath);
                                break;

                            case ".gif":
                                bmp.SaveGif(this.CurrentFilePath);
                                break;

                            case ".jpg":
                            case ".jpeg":
                                bmp.SaveJpeg(this.CurrentFilePath);
                                break;

                            case ".png":
                                bmp.SavePng(this.CurrentFilePath);
                                break;

                            case ".tiff":
                                bmp.SaveTiff(this.CurrentFilePath);
                                break;

                            case ".wmp":
                                bmp.SaveWmp(this.CurrentFilePath);
                                break;

                            default:
                                break;
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBoxResult mbr = MessageBox.Show(ex.Message, "Try again?", MessageBoxButton.YesNo, MessageBoxImage.Error);
                            if (mbr == MessageBoxResult.Yes)
                            {
                                continue;
                            }
                        }
                        break;
                    } while (true);
                }
                break;

            default:
                break;
            }
        }