Exemple #1
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();
        }