Ejemplo n.º 1
0
        public static void SaveAsFile(this Bitmap bitmap, IGameInfo game, string suffix, string systemId, PathEntryCollection paths, IDialogParent parent)
        {
            using var sfd = new SaveFileDialog
                  {
                      FileName         = $"{game.FilesystemSafeName()}-{suffix}",
                      InitialDirectory = paths.ScreenshotAbsolutePathFor(systemId),
                      Filter           = FilesystemFilterSet.Screenshots.ToString(),
                      RestoreDirectory = true
                  };

            if (parent.ShowDialogWithTempMute(sfd) != DialogResult.OK)
            {
                return;
            }

            var         file      = new FileInfo(sfd.FileName);
            string      extension = file.Extension.ToUpper();
            ImageFormat i         = extension switch
            {
                ".BMP" => ImageFormat.Bmp,
                _ => ImageFormat.Png,
            };

            bitmap.Save(file.FullName, i);
        }
Ejemplo n.º 2
0
        public static void SaveAsFile(this Bitmap bitmap, IGameInfo game, string suffix, string systemId, PathEntryCollection paths)
        {
            using var sfd = new SaveFileDialog
                  {
                      FileName         = $"{game.FilesystemSafeName()}-{suffix}",
                      InitialDirectory = paths.ScreenshotAbsolutePathFor(systemId),
                      Filter           = FilesystemFilterSet.Screenshots.ToString(),
                      RestoreDirectory = true
                  };

            var result = sfd.ShowHawkDialog();

            if (result != DialogResult.OK)
            {
                return;
            }

            var         file = new FileInfo(sfd.FileName);
            ImageFormat i;
            string      extension = file.Extension.ToUpper();

            switch (extension)
            {
            default:
            case ".PNG":
                i = ImageFormat.Png;
                break;

            case ".BMP":
                i = ImageFormat.Bmp;
                break;
            }

            bitmap.Save(file.FullName, i);
        }
Ejemplo n.º 3
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;
        }
        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;
        }
Ejemplo n.º 5
0
 public UnixLuaLibraries(LuaFileList scriptList, LuaFunctionList registeredFuncList, PathEntryCollection pathEntries)
 {
     PathEntries         = pathEntries;
     RegisteredFunctions = registeredFuncList;
     ScriptList          = scriptList;
 }