Esempio n. 1
0
        private void saveAsImageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (engineMgr.Engine == null)
            {
                return;
            }

            Color[,] output = engineMgr.Engine.GetOutputPixels(); //grab the image pixel data before shutting down the engine

            beginDlg();                                           //tell the engine that we are now in a dialog

            ExportToImageDlg imgDlg = new ExportToImageDlg();

            string fileName = String.Format("{0}_{1}x{2}.png", (FractalManager.Fractal.Name ?? "unnamed"), output.GetLength(1), output.GetLength(0));

            imgDlg.FileName     = Path.Combine(config.ImageDir, fileName);
            imgDlg.Format       = ExportToImageDlg.FormatOption.Png;
            imgDlg.Transparency = ExportToImageDlg.TransparencyOption.None;

            if (imgDlg.ShowDialog() == DialogResult.OK)
            {
                try{
                    imgDlg.SaveOutput(output);
                    config.ImageDir = Path.GetDirectoryName(imgDlg.FileName);
                }
                catch (Exception ex)
                {
                    string msg = string.Format(Narratives.Error_ImageSaveFailed, imgDlg.FileName);
                    ErrorForm.Show(msg, ex);
                }
            }
            endDlg();             //bring the engine back online
        }
Esempio n. 2
0
        private void saveLibraryToolStripMenuItem_Click(object sender, EventArgs e)
        {
            beginDlg();

            SaveFileDialog dlg = new SaveFileDialog();

            dlg.Filter           = "Fractal Flame files (*.flame)|*.flame|All Files (*.*)|*.*";
            dlg.DefaultExt       = "flame";
            dlg.InitialDirectory = Config.FractalDir;
            dlg.OverwritePrompt  = true;

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                try{
                    FlameFileIO.WriteFlameFile(dlg.FileName, FractalManager.Fractals);
                    config.CurrentLibraryFile = dlg.FileName;
                    libraryNameLabel.Text     = Path.GetFileName(dlg.FileName);
                }
                catch (Exception ex)
                {
                    string msg = string.Format(Narratives.Error_FlameSaveFailed, dlg.FileName);
                    ErrorForm.Show(msg, ex);
                }
            }
            endDlg();
        }
Esempio n. 3
0
        public static void Show(Exception ex)
        {
            var form = new ErrorForm();

            form.Exception = ex;
            form.chooseTitleAndExplanation(ex);
            form.ShowDialog();
        }
Esempio n. 4
0
        public static void Show(string mergedTitleMessage, Exception ex)
        {
            var form = new ErrorForm();

            form.SetMergedTitleMessage(mergedTitleMessage);
            form.Exception = ex;
            form.ShowDialog();
        }
Esempio n. 5
0
        public static void Show(string title, string explanation, Exception ex)
        {
            var form = new ErrorForm();

            form.Title       = title;
            form.Explanation = explanation;
            form.Exception   = ex;
            form.ShowDialog();
        }
Esempio n. 6
0
        private void trySaveLibrary()
        {
            try{
                FlameFileIO.WriteFlameFile(config.CurrentLibraryFile, FractalManager.Fractals);
            }catch (Exception ex) {
#if DEBUG
                throw ex;
#else
                string msg = string.Format(Narratives.Error_FlameSaveFailed, config.CurrentLibraryFile);
                ErrorForm.Show(msg, ex);
#endif
            }
        }
Esempio n. 7
0
        private void viewEngineErrorButton_Click(object sender, EventArgs e)
        {
            if (engineMgr == null)
            {
                return;
            }

            if (engineMgr.CurrentException == null)
            {
                ErrorForm.Show("No Error::No error", null);
            }
            else
            {
                ErrorForm.Show(engineMgr.CurrentException);
            }
        }
Esempio n. 8
0
        private void openLibraryToolStripMenuItem_Click(object sender, EventArgs e)
        {
            beginDlg();

            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter           = "Fractal Flame files (*.flame)|*.flame|All Files (*.*)|*.*";
            dlg.DefaultExt       = "flame";
            dlg.CheckFileExists  = true;
            dlg.InitialDirectory = Config.FractalDir;
            DialogResult dlgResult = dlg.ShowDialog();

            if (dlgResult == DialogResult.OK)
            {
                bool loadOk = false;
                try{
                    FractalManager.ReadFromFlameFile(dlg.FileName, config);
                    libraryNameLabel.Text = Path.GetFileName(dlg.FileName);
                    loadOk = true;
                }
                catch (FileNotFoundException ex)
                {
                    MessageBox.Show(ex.Message, "File not found", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                catch (Exception ex)
                {
                    ErrorForm.Show(Narratives.Error_FractalOpenFailed, ex);
                }

                if (loadOk)
                {
                    config.CurrentLibraryFile = dlg.FileName;
                    FractronConfig.Save(config);
                    updateLibraryView();
                    sideBar.SelectedTab = libraryPage;
                }
            }

            endDlg();
        }
Esempio n. 9
0
        private void loadImageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            beginDlg();
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter           = "Supported Image Files|*.bmp;*.gif;*.jpg;*.jpeg;*.jfif;*.png;*.tiff";
            dlg.CheckFileExists  = true;
            dlg.CheckPathExists  = true;
            dlg.InitialDirectory = Config.PaletteDir;

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                try{
                    Palette pal = new Palette(dlg.FileName);
                    FractalManager.SetPalette(pal);
                }
                catch (Exception ex) {
                    ErrorForm.Show("Palette Load Failed.", string.Format("Could not open palette file \"{0}\".", dlg.FileName), ex);
                }
            }
            endDlg();
        }
Esempio n. 10
0
        private void openFractronFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            beginDlg();

            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter           = "Fractron 9000 files (*.fractron)|*.fractron|All Files (*.*)|*.*";
            dlg.DefaultExt       = "fractron";
            dlg.CheckFileExists  = true;
            dlg.InitialDirectory = Config.FractalDir;

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                try{
                    Fractal frac = FractronFileIO.ReadFractronFile(dlg.FileName);
                    FractalManager.SetCurrentCopy(frac);
                }catch (Exception ex) {
                    ErrorForm.Show("IO Error", "Failed to open .fractron file.", ex);
                }
            }

            endDlg();
        }
Esempio n. 11
0
        //chooses an appropriate state for the rendering engine
        private void chooseDesiredEngineState()
        {
            FractalEngineState state = FractalEngineState.Offline;

            if (!this.ReadyToRender || !renderer.HasGraphics)
            {
                state = FractalEngineState.Offline;
            }
            else if (
                this.ClientSize.IsEmpty || this.RendererSize.IsEmpty ||
                this.Resizing || this.DlgActive || FractalManager.Fractal == null)
            {
                state = FractalEngineState.Suspended;
            }
            else
            {
                state = FractalEngineState.Online;
            }
            engineMgr.DesiredEngineState = state;

            if (config.AutoSizeRenderer)
            {
                engineMgr.DesiredOutputSize = renderer.ClientSize;
            }
            else
            {
                engineMgr.DesiredOutputSize = config.CustomRes;
            }
            updateEngineStatusPanel();

            //if an engine error hasn't been shown before, do the engine error dialog.
            if (engineMgr.EngineState == FractalEngineState.Error && !engineErrorShown)
            {
                engineErrorShown = true;
                ErrorForm.Show(engineMgr.CurrentException);
            }
        }
Esempio n. 12
0
        private bool engineErrorShown = false;         //set to true the first time an engine error dialog is shown

        #endregion

        #region Constructor of DOOOOOM
        public MainForm()
        {
            engineMgr = new EngineManager(this);

            InitializeComponent();

            if (this.DesignMode)
            {
                return;
            }

            FractronConfig.DoInitialSetup();
            try{
                config = FractronConfig.Load();
            }
            catch (Exception ex)
            {
                ErrorForm.Show(Narratives.Error_InitConfigLoadFailed, ex);
                config = new FractronConfig();
            }

            renderer.MainForm       = this;
            renderer.HandleCreated += new EventHandler(renderer_HandleCreated);
            renderer.InitContext();

            FractalManager.Init();
            try{
                FractalManager.ReadFromFlameFile(config.CurrentLibraryFile, config);
                libraryNameLabel.Text = Path.GetFileName(config.CurrentLibraryFile);
            }
            catch (Exception ex)
            {
                string msg = string.Format(Narratives.Error_FlameLoadFailed, config.CurrentLibraryFile);
                ErrorForm.Show(msg, ex);
            }
            if (FractalManager.Fractals.Count > 0)
            {
                FractalManager.SetCurrentCopy(FractalManager.Fractals[0]);
            }

            brightnessSpinner.ValueChanged += (sender, e) =>
            {
                FractalManager.Fractal.Brightness = (float)brightnessSpinner.Value;
                FractalManager.NotifyToneMapChanged();
            };

            gammaSpinner.ValueChanged += (sender, e) =>
            {
                FractalManager.Fractal.Gamma = (float)gammaSpinner.Value;
                FractalManager.NotifyToneMapChanged();
            };

            vibrancySpinner.ValueChanged += (sender, e) =>
            {
                FractalManager.Fractal.Vibrancy = (float)vibrancySpinner.Value;
                FractalManager.NotifyToneMapChanged();
            };

            weightSpinner.ValueChanged += (sender, e) =>
            {
                if (FractalManager.SelectedBranch != null)
                {
                    FractalManager.SelectedBranch.Weight = (float)weightSpinner.Value;
                    FractalManager.NotifyGeometryChanged();
                }
            };

            colorWeightSpinner.ValueChanged += (sender, e) =>
            {
                if (FractalManager.SelectedBranch != null)
                {
                    FractalManager.SelectedBranch.ColorWeight = (float)colorWeightSpinner.Value;
                    FractalManager.NotifyGeometryChanged();
                }
            };

            localizedCheckbox.CheckedChanged += applyLocalized;

            variDropBoxes = new ComboBox[variControlCount];
            variSpinners  = new DragSpin[variControlCount];
            int variDropWidth = variGroupBox.ClientSize.Width - 76;
            int y             = 38;

            for (int i = 0; i < variControlCount; i++)
            {
                ComboBox variDropBox = new ComboBox();
                DragSpin variSpinner = new DragSpin();

                variDropBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
                variDropBox.Size          = new System.Drawing.Size(variDropWidth, 21);
                variDropBox.Location      = new System.Drawing.Point(6, y);
                variDropBox.TabIndex      = 2 * i;

                if (i > 0)
                {
                    variDropBox.Items.Add("<none>");
                }
                foreach (Variation vari in Variation.Variations)
                {
                    variDropBox.Items.Add(vari);
                }
                variDropBox.SelectedIndexChanged += applyVariControls;


                variSpinner.Size                   = new System.Drawing.Size(58, 20);
                variSpinner.Location               = new System.Drawing.Point(variGroupBox.ClientSize.Width - 64, y);
                variSpinner.FormatString           = "0.###";
                variSpinner.MinVal                 = 0.0;
                variSpinner.MaxVal                 = 1.0;
                variSpinner.MinorTicksPerMajorTick = 12;
                variSpinner.PixelsPerMinorTick     = 24;
                variSpinner.TabIndex               = 2 * i + 1;

                variSpinner.ValueChanged += applyVariControls;

                y += variDropBox.Height + 6;

                helpProvider.SetHelpString(variDropBox, "Selects a variation to apply to the current branch.");
                helpProvider.SetHelpString(variSpinner, "Adjusts the weight of a variation.");

                variGroupBox.Controls.Add(variDropBox);
                variGroupBox.Controls.Add(variSpinner);

                variDropBoxes[i] = variDropBox;
                variSpinners[i]  = variSpinner;
            }

            variGroupBox.Size = new Size(variGroupBox.Width, y);

            helpifyControl(this, null);

            FractalManager.CurrentFractalChanged += handleCurrentFractalChange;

            FractalManager.BranchSelected += (frac) => {
                updateBranchControls();
            };

            //foreach(var spin in branchOptsPanel.Controls.OfType<DragSpin>())
            //	spin.ValueChanged += HandleFactorSpinnerValueChange;
            FractalManager.PaletteChanged += (frac) =>
            {
                engineMgr.MarkPaletteDirty();
            };

            FractalManager.ToneMapChagned += (frac) =>
            {
                engineMgr.MarkToneMapDirty();
            };

            FractalManager.GeometryChanged += (frac) =>
            {
                engineMgr.MarkGeometryDirty();
            };

            nameTextBox.TextChanged += applyFractalName;
            updateLibraryView();

            updateToneControls();
            handleCurrentFractalChange(FractalManager.Fractal);
            updateBranchControls();

            chooseDesiredEngineState();
        }