Пример #1
0
        private void AddButton_Click(object sender, EventArgs e)
        {
            int start = 3 + (FileSelectorPanel.Controls.Count * 43);

            var groupBox = new GroupBox
            {
                Text     = "",
                Location = UIHelper.Scale(new Point(6, start)),
                Size     = new Size(FileSelectorPanel.ClientSize.Width - UIHelper.ScaleX(12), UIHelper.ScaleY(41)),
                Anchor   = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top
            };

            var mdf = new MultiDiskFileSelector
            {
                Location = UIHelper.Scale(new Point(7, 12)),
                Width    = groupBox.ClientSize.Width - UIHelper.ScaleX(13),
                Anchor   = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top
            };

            mdf.NameChanged += FileSelector_NameChanged;
            mdf.SystemString = SystemDropDown.SelectedText;


            groupBox.Controls.Add(mdf);

            FileSelectorPanel.Controls.Add(groupBox);
        }
Пример #2
0
        private void DoTabs()
        {
            HotkeyTabControl.TabPages.Clear();

            //Buckets
            var Tabs = Global.Config.HotkeyBindings.Select(x => x.TabGroup).Distinct().ToList();

            foreach (var tab in Tabs)
            {
                var _y = UIHelper.ScaleY(14);
                var _x = UIHelper.ScaleX(6);

                var tb = new TabPage {
                    Name = tab, Text = tab
                };

                var bindings = Global.Config.HotkeyBindings.Where(x => x.TabGroup == tab).OrderBy(x => x.Ordinal).ThenBy(x => x.DisplayName).ToList();

                int iwOffsetX = UIHelper.ScaleX(110);
                int iwOffsetY = UIHelper.ScaleY(-4);
                int iwWidth   = UIHelper.ScaleX(120);
                foreach (var b in bindings)
                {
                    var l = new Label
                    {
                        Text     = b.DisplayName,
                        Location = new Point(_x, _y),
                        Size     = new Size(iwOffsetX - UIHelper.ScaleX(2), UIHelper.ScaleY(15)),
                    };

                    var w = new InputCompositeWidget
                    {
                        Location   = new Point(_x + iwOffsetX, _y + iwOffsetY),
                        AutoTab    = AutoTabCheckBox.Checked,
                        Width      = iwWidth,
                        WidgetName = b.DisplayName,
                    };

                    w.SetupTooltip(toolTip1, b.ToolTip);
                    toolTip1.SetToolTip(l, b.ToolTip);

                    w.Bindings = b.Bindings;

                    tb.Controls.Add(l);
                    tb.Controls.Add(w);

                    _y += UIHelper.ScaleY(24);
                    if (_y > HotkeyTabControl.Height - UIHelper.ScaleY(35))
                    {
                        _x += iwOffsetX + iwWidth + UIHelper.ScaleX(10);
                        _y  = UIHelper.ScaleY(14);
                    }
                }

                HotkeyTabControl.TabPages.Add(tb);
            }
        }
Пример #3
0
        private void SetMaxXy()
        {
            var video = NullVideo.Instance;             // Good enough

            XNumeric.Maximum   = video.BufferWidth - 12;
            YNumeric.Maximum   = video.BufferHeight - 12;
            PositionPanel.Size = new Size(video.BufferWidth + 2, video.BufferHeight + 2);

            PositionGroupBox.Size = new Size(
                Math.Max(video.BufferWidth, UIHelper.ScaleX(128)) + UIHelper.ScaleX(44),
                video.BufferHeight + UIHelper.ScaleY(52));
        }
Пример #4
0
        private void SetMaxXY()
        {
            var video = BizHawk.Emulation.Common.VideoProviderGlue.VideoProvider(Global.Emulator);

            XNumeric.Maximum   = video.BufferWidth - 12;
            YNumeric.Maximum   = video.BufferHeight - 12;
            PositionPanel.Size = new Size(video.BufferWidth + 2, video.BufferHeight + 2);

            PositionGroupBox.Size = new Size(
                Math.Max(video.BufferWidth, UIHelper.ScaleX(128)) + UIHelper.ScaleX(44),
                video.BufferHeight + UIHelper.ScaleY(52));
        }
Пример #5
0
        private void SetMaxXY()
        {
            var video = Global.Emulator.AsVideoProvider();             // TODO: this is objectively wrong, these are core agnostic settings, why is the current core used here? Also this will crash on a core without a video provider

            XNumeric.Maximum   = video.BufferWidth - 12;
            YNumeric.Maximum   = video.BufferHeight - 12;
            PositionPanel.Size = new Size(video.BufferWidth + 2, video.BufferHeight + 2);

            PositionGroupBox.Size = new Size(
                Math.Max(video.BufferWidth, UIHelper.ScaleX(128)) + UIHelper.ScaleX(44),
                video.BufferHeight + UIHelper.ScaleY(52));
        }
Пример #6
0
        private void FileExtensionPreferences_Load(object sender, EventArgs e)
        {
            int spacing = UIHelper.ScaleY(30);
            int count   = 0;

            foreach (var(fileExt, sysID) in _preferredPlatformsForExtensions)
            {
                var picker = new FileExtensionPreferencesPicker(_preferredPlatformsForExtensions)
                {
                    FileExtension      = fileExt,
                    OriginalPreference = sysID,
                    Location           = new Point(UIHelper.ScaleX(15), UIHelper.ScaleY(15) + (spacing * count))
                };

                count++;
                PrefPanel.Controls.Add(picker);
            }
        }
        private void FileExtensionPreferences_Load(object sender, EventArgs e)
        {
            int spacing = UIHelper.ScaleY(30);
            int count   = 0;

            foreach (var kvp in _config.PreferredPlatformsForExtensions)
            {
                var picker = new FileExtensionPreferencesPicker
                {
                    FileExtension      = kvp.Key,
                    OriginalPreference = kvp.Value,
                    Location           = new Point(UIHelper.ScaleX(15), UIHelper.ScaleY(15) + (spacing * count))
                };

                count++;
                PrefPanel.Controls.Add(picker);
            }
        }
Пример #8
0
        private void Startup()
        {
            Console.WriteLine("startup");
            var labelWidth  = _buttons.Max(b => b.Length) * _charWidth;
            var columnWidth = _inputSize + (_labelPadding * 2) + labelWidth;
            int x           = _inputMarginLeft;
            int y           = _marginTop - _ySpacing;

            for (int i = 0; i < _buttons.Count; i++)
            {
                y += _ySpacing;
                if (y > (_panelSize.Height - UIHelper.ScaleY(62)))
                {
                    y  = _marginTop;
                    x += columnWidth;
                }

                var iw = new InputCompositeWidget
                {
                    Location = new Point(x, y),
                    Size     = new Size(_inputSize, UIHelper.ScaleY(23)),
                    TabIndex = i,
                    AutoTab  = _autoTab
                };

                iw.SetupTooltip(Tooltip, null);

                iw.BringToFront();
                Controls.Add(iw);
                _inputs.Add(iw);
                var label = new Label
                {
                    Location = new Point(x + _inputSize + _labelPadding, y + UIHelper.ScaleY(3)),
                    Size     = new Size(UIHelper.ScaleX(labelWidth), UIHelper.ScaleY(15)),
                    Text     = _buttons[i].Replace('_', ' ').Trim()
                };

                Tooltip.SetToolTip(label, label.Text);

                Controls.Add(label);
            }
        }
        protected void Startup()
        {
            int x = InputMarginLeft;
            int y = MarginTop - Spacing;

            for (int i = 0; i < buttons.Count; i++)
            {
                y += Spacing;
                if (y > (_panelSize.Height - UIHelper.ScaleY(62)))
                {
                    y  = MarginTop;
                    x += ColumnWidth;
                }

                InputCompositeWidget iw = new InputCompositeWidget
                {
                    Location = new Point(x, y),
                    Size     = new Size(InputSize, UIHelper.ScaleY(23)),
                    TabIndex = i,
                    AutoTab  = this.Autotab
                };

                iw.SetupTooltip(Tooltip, null);

                iw.BringToFront();
                Controls.Add(iw);
                Inputs.Add(iw);
                Label label = new Label
                {
                    Location = new Point(x + InputSize + LabelPadding, y + UIHelper.ScaleY(3)),
                    Size     = new Size(UIHelper.ScaleX(100), UIHelper.ScaleY(15)),
                    Text     = buttons[i].Replace('_', ' ').Trim(),
                };

                //Tooltip.SetToolTip(label, null); //??? not supported yet

                Controls.Add(label);
                Labels.Add(label);
            }
        }
Пример #10
0
        private void Startup()
        {
            int x = _inputMarginLeft;
            int y = _marginTop - _spacing;

            for (int i = 0; i < _buttons.Count; i++)
            {
                y += _spacing;
                if (y > (_panelSize.Height - UIHelper.ScaleY(62)))
                {
                    y  = _marginTop;
                    x += _columnWidth;
                }

                var iw = new InputCompositeWidget
                {
                    Location = new Point(x, y),
                    Size     = new Size(_inputSize, UIHelper.ScaleY(23)),
                    TabIndex = i,
                    AutoTab  = _autotab
                };

                iw.SetupTooltip(Tooltip, null);

                iw.BringToFront();
                Controls.Add(iw);
                _inputs.Add(iw);
                var label = new Label
                {
                    Location = new Point(x + _inputSize + _labelPadding, y + UIHelper.ScaleY(3)),
                    Size     = new Size(UIHelper.ScaleX(100), UIHelper.ScaleY(15)),
                    Text     = _buttons[i].Replace('_', ' ').Trim(),
                };

                ////Tooltip.SetToolTip(label, null); //??? not supported yet

                Controls.Add(label);
            }
        }
Пример #11
0
        private void DoTabs(List <PathEntry> pathCollection)
        {
            PathTabControl.Visible = false;
            PathTabControl.TabPages.Clear();

            // Separate by system
            var systems = Global.Config.PathEntries
                          .Select(s => s.SystemDisplayName)
                          .Distinct()
                          .ToList();

            systems.Sort();

            // Hacky way to put global first
            var global = systems.FirstOrDefault(s => s == "Global");

            systems.Remove(global);
            systems.Insert(0, global);

            var tabPages = new List <TabPage>(systems.Count);

            int x             = UIHelper.ScaleX(6);
            int textboxWidth  = UIHelper.ScaleX(70);
            int padding       = UIHelper.ScaleX(5);
            int buttonWidth   = UIHelper.ScaleX(26);
            int buttonHeight  = UIHelper.ScaleY(23);
            int buttonOffsetY = -1;             // To align the top with the textbox I guess? Always 1 pixel regardless of scaling.
            int widgetOffset  = UIHelper.ScaleX(85);
            int rowHeight     = UIHelper.ScaleY(30);

            foreach (var systemDisplayName in systems)
            {
                var systemId = Global.Config.PathEntries.First(p => p.SystemDisplayName == systemDisplayName).System;
                var t        = new TabPage
                {
                    Text       = systemDisplayName,
                    Name       = systemId,
                    Width      = UIHelper.ScaleX(200),                // Initial Left/Width of child controls are based on this size.
                    AutoScroll = true
                };
                var paths = pathCollection
                            .Where(p => p.System == systemId)
                            .OrderBy(p => p.Ordinal)
                            .ThenBy(p => p.Type)
                            .ToList();

                var y = UIHelper.ScaleY(14);
                foreach (var path in paths)
                {
                    var box = new TextBox
                    {
                        Text                     = path.Path,
                        Location                 = new Point(x, y),
                        Width                    = textboxWidth,
                        Name                     = path.Type,
                        Anchor                   = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
                        MinimumSize              = new Size(UIHelper.ScaleX(26), UIHelper.ScaleY(23)),
                        AutoCompleteMode         = AutoCompleteMode.SuggestAppend,
                        AutoCompleteCustomSource = AutoCompleteOptions,
                        AutoCompleteSource       = AutoCompleteSource.CustomSource,
                    };

                    var btn = new Button
                    {
                        Text     = "",
                        Image    = Properties.Resources.OpenFile,
                        Location = new Point(widgetOffset, y + buttonOffsetY),
                        Size     = new Size(buttonWidth, buttonHeight),
                        Name     = path.Type,
                        Anchor   = AnchorStyles.Top | AnchorStyles.Right,
                    };

                    var tempBox    = box;
                    var tempPath   = path.Type;
                    var tempSystem = path.System;
                    btn.Click += delegate
                    {
                        BrowseFolder(tempBox, tempPath, tempSystem);
                    };

                    int infoPadding = UIHelper.ScaleX(0);
                    if (t.Name.Contains("Global") && path.Type == "Firmware")
                    {
                        infoPadding = UIHelper.ScaleX(26);

                        var firmwareButton = new Button
                        {
                            Name     = "Global",
                            Text     = "",
                            Image    = Properties.Resources.Help,
                            Location = new Point(UIHelper.ScaleX(115), y + buttonOffsetY),
                            Size     = new Size(buttonWidth, buttonHeight),
                            Anchor   = AnchorStyles.Top | AnchorStyles.Right
                        };

                        firmwareButton.Click += delegate
                        {
                            if (Owner is FirmwaresConfig)
                            {
                                MessageBox.Show("C-C-C-Combo Breaker!", "Nice try, but");
                                return;
                            }

                            var f = new FirmwaresConfig {
                                TargetSystem = "Global"
                            };
                            f.ShowDialog(this);
                        };

                        t.Controls.Add(firmwareButton);
                    }

                    var label = new Label
                    {
                        Text     = path.Type,
                        Location = new Point(widgetOffset + buttonWidth + padding + infoPadding, y + UIHelper.ScaleY(4)),
                        Size     = new Size(UIHelper.ScaleX(100), UIHelper.ScaleY(15)),
                        Name     = path.Type,
                        Anchor   = AnchorStyles.Top | AnchorStyles.Right,
                    };

                    t.Controls.Add(label);
                    t.Controls.Add(btn);
                    t.Controls.Add(box);

                    y += rowHeight;
                }

                var sys = systemDisplayName;
                if (systemDisplayName == "PCE")                 // Hack
                {
                    sys = "PCECD";
                }

                tabPages.Add(t);
            }

            PathTabControl.TabPages.AddRange(tabPages.ToArray());
            PathTabControl.Visible = true;
        }
Пример #12
0
        private void DoTabs()
        {
            HotkeyTabControl.SuspendLayout();
            HotkeyTabControl.TabPages.Clear();

            // Buckets
            var tabs = _config.HotkeyBindings.Select(x => x.TabGroup).Distinct();

            foreach (var tab in tabs)
            {
                var tb = new TabPage {
                    Name = tab, Text = tab
                };
                var bindings  = _config.HotkeyBindings.Where(n => n.TabGroup == tab).OrderBy(n => n.Ordinal).ThenBy(n => n.DisplayName);
                int x         = UIHelper.ScaleX(6);
                int y         = UIHelper.ScaleY(14);
                int iwOffsetX = UIHelper.ScaleX(110);
                int iwOffsetY = UIHelper.ScaleY(-4);
                int iwWidth   = UIHelper.ScaleX(120);

                tb.SuspendLayout();

                foreach (var b in bindings)
                {
                    var l = new Label
                    {
                        Text     = b.DisplayName,
                        Location = new Point(x, y),
                        Size     = new Size(iwOffsetX - UIHelper.ScaleX(2), UIHelper.ScaleY(15))
                    };

                    var w = new InputCompositeWidget
                    {
                        Location   = new Point(x + iwOffsetX, y + iwOffsetY),
                        AutoTab    = AutoTabCheckBox.Checked,
                        Width      = iwWidth,
                        WidgetName = b.DisplayName
                    };

                    w.SetupTooltip(toolTip1, b.ToolTip);
                    toolTip1.SetToolTip(l, b.ToolTip);

                    w.Bindings = b.Bindings;

                    tb.Controls.Add(l);
                    tb.Controls.Add(w);

                    y += UIHelper.ScaleY(24);
                    if (y > HotkeyTabControl.Height - UIHelper.ScaleY(35))
                    {
                        x += iwOffsetX + iwWidth + UIHelper.ScaleX(10);
                        y  = UIHelper.ScaleY(14);
                    }
                }

                if (tab == "TAStudio")
                {
                    tb.Controls.Add(new Label
                    {
                        Text     = "Save States hotkeys operate with branches when TAStudio is engaged.",
                        Location = new Point(x, y),
                        Size     = new Size(iwWidth + iwOffsetX, HotkeyTabControl.Height - y)
                    });
                }

                HotkeyTabControl.TabPages.Add(tb);
                tb.ResumeLayout();
            }

            HotkeyTabControl.ResumeLayout();
        }
        private void EngageDebugger()
        {
            _disassemblyLines.Clear();
            MainForm.OnPauseChanged += OnPauseChanged;
            CancelSeekBtn.Enabled    = false;
            if (CanDisassemble)
            {
                try
                {
                    if (CanSetCpu && Disassembler.AvailableCpus.Count() > 1)
                    {
                        var c = new ComboBox
                        {
                            Location      = new Point(UIHelper.ScaleX(35), UIHelper.ScaleY(17)),
                            Width         = UIHelper.ScaleX(121),
                            DropDownStyle = ComboBoxStyle.DropDownList
                        };

                        c.Items.AddRange(Disassembler.AvailableCpus.Cast <object>().ToArray());
                        c.SelectedItem          = Disassembler.Cpu;
                        c.SelectedIndexChanged += OnCpuDropDownIndexChanged;

                        DisassemblerBox.Controls.Add(c);
                    }
                    else
                    {
                        DisassemblerBox.Controls.Add(new Label
                        {
                            Location = new Point(UIHelper.ScaleX(35), UIHelper.ScaleY(23)),
                            Size     = new Size(UIHelper.ScaleX(100), UIHelper.ScaleY(15)),
                            Text     = Disassembler.Cpu
                        });
                    }
                }
                catch (NotImplementedException)
                {
                    DisassemblerBox.Controls.Add(new Label
                    {
                        Location = new Point(UIHelper.ScaleX(35), UIHelper.ScaleY(23)),
                        Size     = new Size(UIHelper.ScaleX(100), UIHelper.ScaleY(15)),
                        Text     = Disassembler.Cpu
                    });
                }

                _pcRegisterSize = Debuggable.GetCpuFlagsAndRegisters()[Disassembler.PCRegisterName].BitSize / 4;
                SetDisassemblerItemCount();
                UpdateDisassembler();
            }
            else
            {
                DisassemblerBox.Enabled   = false;
                DisassemblerView.RowCount = 0;
                DisassemblerBox.Controls.Add(new Label
                {
                    Location = new Point(UIHelper.ScaleX(35), UIHelper.ScaleY(23)),
                    Size     = new Size(UIHelper.ScaleX(100), UIHelper.ScaleY(15)),
                    Text     = "Unknown"
                });

                toolTip1.SetToolTip(DisassemblerBox, "This core does not currently support disassembling");
            }

            RegisterPanel.Core           = Debuggable;
            RegisterPanel.ParentDebugger = this;
            RegisterPanel.GenerateUI();

            if (CanUseMemoryCallbacks)
            {
                BreakPointControl1.MainForm       = MainForm;
                BreakPointControl1.Core           = Debuggable;
                BreakPointControl1.Mcs            = MemoryCallbacks;
                BreakPointControl1.ParentDebugger = this;
                BreakPointControl1.MemoryDomains  = MemoryDomains;
                BreakPointControl1.GenerateUI();
                EnabledBreakpointBox();
            }
            else
            {
                DisableBreakpointBox();
            }

            SeekToBox.Enabled = SeekToBtn.Enabled = CanUseMemoryCallbacks && RegisterPanel.CanGetCpuRegisters;

            if (RegisterPanel.CanGetCpuRegisters && CanDisassemble)
            {
                var pc = PCRegister;
                SeekToBox.Nullable = false;
                SeekToBox.SetHexProperties((long)Math.Pow(2, pc.BitSize));
                SeekToBox.SetFromRawInt(0);
            }
            else
            {
                SeekToBox.Nullable = true;
                SeekToBox.Text     = "";
            }

            StepIntoMenuItem.Enabled = StepIntoBtn.Enabled = CanStepInto;
            StepOutMenuItem.Enabled  = StepOutBtn.Enabled = CanStepOut;
            StepOverMenuItem.Enabled = StepOverBtn.Enabled = CanStepOver;

            if (!StepIntoMenuItem.Enabled)
            {
                toolTip1.SetToolTip(StepIntoBtn, "This core does not currently implement this feature");
            }

            if (!StepOutMenuItem.Enabled)
            {
                toolTip1.SetToolTip(StepOutBtn, "This core does not currently implement this feature");
            }

            if (!StepOverMenuItem.Enabled)
            {
                toolTip1.SetToolTip(StepOverBtn, "This core does not currently implement this feature");
            }
        }
Пример #14
0
        public void GenerateUI()
        {
            this.Controls.Clear();
            var canget = CanGetCpuRegisters;
            var canset = CanSetCpuRegisters;

            if (!canget && !canset)
            {
                ParentDebugger.DisableRegisterBox();
                this.Enabled = false;
            }

            var registers = Core.GetCpuFlagsAndRegisters();

            int y = UIHelper.ScaleY(0);

            var maxCharSize = registers.Where(r => r.Value.BitSize != 1).Max(r => r.Key.Length);
            var width       = maxCharSize * 5;

            if (width < 20)
            {
                width = 20;
            }

            foreach (var register in registers.Where(r => r.Value.BitSize != 1))
            {
                this.Controls.Add(new Label
                {
                    Text     = register.Key,
                    Location = new Point(UIHelper.ScaleX(5), y + UIHelper.ScaleY(2)),
                    Size     = new Size(UIHelper.ScaleX(width + 5), UIHelper.ScaleY(15))
                });

                if (canset)
                {
                    var t = new TextBox
                    {
                        Name            = register.Key,
                        Text            = register.Value.Value.ToHexString(register.Value.BitSize / 16),
                        Width           = UIHelper.ScaleX(6 + ((register.Value.BitSize / 4) * 9)),
                        Location        = new Point(UIHelper.ScaleX(width + 10), y),
                        MaxLength       = register.Value.BitSize / 4,
                        CharacterCasing = CharacterCasing.Upper
                    };

                    t.TextChanged += (o, e) =>
                    {
                        if (!_supressChangeEvents)
                        {
                            try
                            {
                                Core.SetCpuRegister(t.Name, int.Parse(t.Text));
                            }
                            catch (InvalidOperationException)
                            {
                                t.Enabled = false;
                            }
                        }
                    };

                    this.Controls.Add(t);
                }
                else
                {
                    this.Controls.Add(new Label
                    {
                        Name     = register.Key,
                        Text     = register.Value.Value.ToString(),
                        Size     = new Size(UIHelper.ScaleX(6 + ((register.Value.BitSize / 4) * 9)), UIHelper.ScaleY(15)),
                        Location = new Point(UIHelper.ScaleX(width + 12), y + 2)
                    });
                }

                y += UIHelper.ScaleY(25);
            }

            var flags = registers.Where(r => r.Value.BitSize == 1);

            if (flags.Any())
            {
                var p = new Panel
                {
                    Name        = "FlagPanel",
                    Location    = new Point(UIHelper.ScaleX(5), y),
                    BorderStyle = BorderStyle.None,
                    Size        = new Size(UIHelper.ScaleX(240), UIHelper.ScaleY(23)),
                    AutoScroll  = true
                };

                foreach (var flag in registers.Where(r => r.Value.BitSize == 1).OrderByDescending(x => x.Key))
                {
                    var c = new CheckBox
                    {
                        Appearance = System.Windows.Forms.Appearance.Button,
                        Name       = flag.Key,
                        Text       = flag.Key.Replace("Flag", "").Trim(),                   // Hack
                        Checked    = flag.Value.Value == 1 ? true : false,
                        Location   = new Point(UIHelper.ScaleX(40), y),
                        Dock       = DockStyle.Left,
                        Size       = new Size(UIHelper.ScaleX(23), UIHelper.ScaleY(23)),
                        Enabled    = canset
                    };

                    c.CheckedChanged += (o, e) =>
                    {
                        if (!_supressChangeEvents)
                        {
                            try
                            {
                                Core.SetCpuRegister(c.Name, c.Checked ? 1 : 0);
                            }
                            catch (InvalidOperationException)                             // TODO: This is hacky stuff because NES doesn't support setting flags!  Need to know when a core supports this or not, and enable/disable the box accordingly
                            {
                                _supressChangeEvents = true;
                                c.Checked            = !c.Checked;
                                _supressChangeEvents = false;
                                c.Enabled            = false;
                            }
                        }
                    };

                    p.Controls.Add(c);
                }

                this.Controls.Add(p);
            }
        }
        private void DoTabs(IList <PathEntry> pathCollection, string focusTabOfSystem)
        {
            bool IsTabPendingFocus(string system) => system == focusTabOfSystem || system.Split('_').Contains(focusTabOfSystem);

            int x             = UIHelper.ScaleX(6);
            int textBoxWidth  = UIHelper.ScaleX(70);
            int padding       = UIHelper.ScaleX(5);
            int buttonWidth   = UIHelper.ScaleX(26);
            int buttonHeight  = UIHelper.ScaleY(23);
            int buttonOffsetY = -1;             // To align the top with the TextBox I guess? Always 1 pixel regardless of scaling.
            int widgetOffset  = UIHelper.ScaleX(85);
            int rowHeight     = UIHelper.ScaleY(30);

            void PopulateTabPage(Control t, string system)
            {
                var paths = pathCollection
                            .Where(p => p.System == system)
                            .OrderBy(p => p.Ordinal)
                            .ThenBy(p => p.Type);

                var y = UIHelper.ScaleY(14);

                foreach (var path in paths)
                {
                    var box = new TextBox
                    {
                        Text                     = path.Path,
                        Location                 = new Point(x, y),
                        Width                    = textBoxWidth,
                        Name                     = path.Type,
                        Anchor                   = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
                        MinimumSize              = new Size(UIHelper.ScaleX(26), UIHelper.ScaleY(23)),
                        AutoCompleteMode         = AutoCompleteMode.SuggestAppend,
                        AutoCompleteCustomSource = AutoCompleteOptions,
                        AutoCompleteSource       = AutoCompleteSource.CustomSource
                    };

                    var btn = new Button
                    {
                        Text     = "",
                        Image    = Properties.Resources.OpenFile,
                        Location = new Point(widgetOffset, y + buttonOffsetY),
                        Size     = new Size(buttonWidth, buttonHeight),
                        Name     = path.Type,
                        Anchor   = AnchorStyles.Top | AnchorStyles.Right
                    };

                    var tempBox    = box;
                    var tempPath   = path.Type;
                    var tempSystem = path.System;
                    btn.Click += (sender, args) => BrowseFolder(tempBox, tempPath, tempSystem);

                    var label = new Label
                    {
                        Text     = path.Type,
                        Location = new Point(widgetOffset + buttonWidth + padding, y + UIHelper.ScaleY(4)),
                        Size     = new Size(UIHelper.ScaleX(100), UIHelper.ScaleY(15)),
                        Name     = path.Type,
                        Anchor   = AnchorStyles.Top | AnchorStyles.Right
                    };

                    t.Controls.Add(label);
                    t.Controls.Add(btn);
                    t.Controls.Add(box);

                    y += rowHeight;
                }
            }

            void AddTabPageForSystem(string system, string systemDisplayName)
            {
                var t = new TabPage
                {
                    Name       = system,
                    Text       = systemDisplayName,
                    Width      = UIHelper.ScaleX(200),                // Initial Left/Width of child controls are based on this size.
                    AutoScroll = true
                };

                PopulateTabPage(t, system);
                comboSystem.Items.Add(systemDisplayName);
                PathTabControl.TabPages.Add(t);
                if (IsTabPendingFocus(system))
                {
                    comboSystem.SelectedIndex = comboSystem.Items.Count - 1;                     // event handler selects correct tab in inner TabControl
                    tcMain.SelectTab(1);
                }
            }

            tcMain.Visible = false;

            PathTabControl.TabPages.Clear();
            var systems = _pathEntries.Select(e => e.System).Distinct()             // group entries by "system" (intentionally using instance field here, not parameter)
                          .Select(sys => (SysGroup: sys, DisplayName: PathEntryCollection.GetDisplayNameFor(sys)))
                          .OrderBy(tuple => tuple.DisplayName)
                          .ToList();
            // add the Global tab first...
            const string idGlobal = "Global_NULL";

            tpGlobal.Name = idGlobal;                              // required for SaveSettings
            systems.RemoveAll(tuple => tuple.SysGroup == idGlobal);
            var hack = tpGlobal.Size.Width - UIHelper.ScaleX(220); // whyyyyyyyyyy

            textBoxWidth += hack;
            widgetOffset += hack;
            Size hack1 = new(17, 0);             // also whyyyyyyyyyy

            PopulateTabPage(tpGlobal, idGlobal);
            tpGlobal.Controls[tpGlobal.Controls.Count - 1].Size     -= hack1;         // TextBox
            tpGlobal.Controls[tpGlobal.Controls.Count - 2].Location -= hack1;         // Button
            textBoxWidth -= hack;
            widgetOffset -= hack;
            // ...then continue with the others
            foreach (var(sys, dispName) in systems)
            {
                AddTabPageForSystem(sys, dispName);
            }

            if (IsTabPendingFocus(idGlobal))
            {
                comboSystem.SelectedIndex = systems.FindIndex(tuple => tuple.SysGroup == "NES");                 // event handler selects correct tab in inner TabControl
                // selected tab in tcMain is already 0 (Global)
            }

            tcMain.Visible = true;
        }
Пример #16
0
        private void DoTabs(IList <PathEntry> pathCollection, string focusTabOfSystem)
        {
            int x             = UIHelper.ScaleX(6);
            int textBoxWidth  = UIHelper.ScaleX(70);
            int padding       = UIHelper.ScaleX(5);
            int buttonWidth   = UIHelper.ScaleX(26);
            int buttonHeight  = UIHelper.ScaleY(23);
            int buttonOffsetY = -1;             // To align the top with the TextBox I guess? Always 1 pixel regardless of scaling.
            int widgetOffset  = UIHelper.ScaleX(85);
            int rowHeight     = UIHelper.ScaleY(30);

            void AddTabPageForSystem(string system, string systemDisplayName)
            {
                var t = new TabPage
                {
                    Name       = system,
                    Text       = systemDisplayName,
                    Width      = UIHelper.ScaleX(200),                // Initial Left/Width of child controls are based on this size.
                    AutoScroll = true
                };
                var paths = pathCollection
                            .Where(p => p.System == system)
                            .OrderBy(p => p.Ordinal)
                            .ThenBy(p => p.Type);

                var y = UIHelper.ScaleY(14);

                foreach (var path in paths)
                {
                    var box = new TextBox
                    {
                        Text                     = path.Path,
                        Location                 = new Point(x, y),
                        Width                    = textBoxWidth,
                        Name                     = path.Type,
                        Anchor                   = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
                        MinimumSize              = new Size(UIHelper.ScaleX(26), UIHelper.ScaleY(23)),
                        AutoCompleteMode         = AutoCompleteMode.SuggestAppend,
                        AutoCompleteCustomSource = AutoCompleteOptions,
                        AutoCompleteSource       = AutoCompleteSource.CustomSource
                    };

                    var btn = new Button
                    {
                        Text     = "",
                        Image    = Properties.Resources.OpenFile,
                        Location = new Point(widgetOffset, y + buttonOffsetY),
                        Size     = new Size(buttonWidth, buttonHeight),
                        Name     = path.Type,
                        Anchor   = AnchorStyles.Top | AnchorStyles.Right
                    };

                    var tempBox    = box;
                    var tempPath   = path.Type;
                    var tempSystem = path.System;
                    btn.Click += (sender, args) => BrowseFolder(tempBox, tempPath, tempSystem);

                    var label = new Label
                    {
                        Text     = path.Type,
                        Location = new Point(widgetOffset + buttonWidth + padding, y + UIHelper.ScaleY(4)),
                        Size     = new Size(UIHelper.ScaleX(100), UIHelper.ScaleY(15)),
                        Name     = path.Type,
                        Anchor   = AnchorStyles.Top | AnchorStyles.Right
                    };

                    t.Controls.Add(label);
                    t.Controls.Add(btn);
                    t.Controls.Add(box);

                    y += rowHeight;
                }

                PathTabControl.TabPages.Add(t);
                if (system == focusTabOfSystem || system.Split('_').Contains(focusTabOfSystem))
                {
                    PathTabControl.SelectTab(PathTabControl.TabPages.Count - 1);
                }
            }

            PathTabControl.Visible = false;

            PathTabControl.TabPages.Clear();
            var systems = _pathEntries.Select(e => e.System).Distinct()             // group entries by "system" (intentionally using instance field here, not parameter)
                          .Select(sys => (SysGroup: sys, DisplayName: PathEntryCollection.GetDisplayNameFor(sys)))
                          .OrderBy(tuple => tuple.DisplayName)
                          .ToList();
            // add the Global tab first...
            const string idGlobal = "Global_NULL";

            systems.RemoveAll(tuple => tuple.SysGroup == idGlobal);
            AddTabPageForSystem(idGlobal, PathEntryCollection.GetDisplayNameFor(idGlobal));
            // ...then continue with the others
            foreach (var(sys, dispName) in systems)
            {
                AddTabPageForSystem(sys, dispName);
            }

            PathTabControl.Visible = true;
        }