diff --git a/src/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs b/src/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs index 866a9db62b..60938f3ce4 100644 --- a/src/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs +++ b/src/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs @@ -2,13 +2,16 @@ using System.Collections.Generic; using System.ComponentModel; using System.Drawing; +using System.Drawing.Imaging; +using System.IO; using System.Linq; using System.Reflection; using System.Text; using System.Windows.Forms; - +using BizHawk.Client.Common; using BizHawk.Common; using BizHawk.Common.ReflectionExtensions; +using BizHawk.Emulation.Common; namespace BizHawk.Client.EmuHawk { @@ -268,5 +271,38 @@ namespace BizHawk.Client.EmuHawk using var img = bitmap; Clipboard.SetImage(img); } + + 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); + } } } diff --git a/src/BizHawk.Client.EmuHawk/config/GB/BmpView.cs b/src/BizHawk.Client.EmuHawk/config/GB/BmpView.cs index 88f1e17486..941f0fa09c 100644 --- a/src/BizHawk.Client.EmuHawk/config/GB/BmpView.cs +++ b/src/BizHawk.Client.EmuHawk/config/GB/BmpView.cs @@ -1,13 +1,10 @@ using System; using System.ComponentModel; using System.Drawing.Imaging; -using System.IO; using System.Drawing; using System.Windows.Forms; -using BizHawk.Client.Common; using BizHawk.Common; -using BizHawk.Emulation.Common; namespace BizHawk.Client.EmuHawk { @@ -22,7 +19,6 @@ namespace BizHawk.Client.EmuHawk { if (DesignMode) { - // in the designer SetStyle(ControlStyles.SupportsTransparentBackColor, true); } else @@ -58,10 +54,7 @@ namespace BizHawk.Client.EmuHawk } } - public void ChangeBitmapSize(Size s) - { - ChangeBitmapSize(s.Width, s.Height); - } + public void ChangeBitmapSize(Size s) => ChangeBitmapSize(s.Width, s.Height); public void ChangeBitmapSize(int w, int h) { @@ -91,47 +84,7 @@ namespace BizHawk.Client.EmuHawk public void SaveFile() { - string path = GlobalWin.Config.PathEntries.ScreenshotAbsolutePathFor(GlobalWin.Emulator.SystemId); - - var di = new DirectoryInfo(path); - - if (!di.Exists) - { - di.Create(); - } - - using var sfd = new SaveFileDialog - { - FileName = $"{GlobalWin.Game.FilesystemSafeName()}-Palettes", - InitialDirectory = path, - Filter = FilesystemFilterSet.Screenshots.ToString(), - RestoreDirectory = true - }; - - var result = sfd.ShowHawkDialog(); - if (result != DialogResult.OK) - { - return; - } - - var file = new FileInfo(sfd.FileName); - var b = Bmp; - - ImageFormat i; - string extension = file.Extension.ToUpper(); - - switch (extension) - { - default: - case ".PNG": - i = ImageFormat.Png; - break; - case ".BMP": - i = ImageFormat.Bmp; - break; - } - - b.Save(file.FullName, i); + Bmp.SaveAsFile(GlobalWin.Game, "Palettes", GlobalWin.Emulator.SystemId, GlobalWin.Config.PathEntries); } } } diff --git a/src/BizHawk.Client.EmuHawk/tools/Genesis/VDPViewer.cs b/src/BizHawk.Client.EmuHawk/tools/Genesis/VDPViewer.cs index 5fab1c4c80..d8ee3c128b 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Genesis/VDPViewer.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Genesis/VDPViewer.cs @@ -174,29 +174,34 @@ namespace BizHawk.Client.EmuHawk } } + private void SaveAsFile(Bitmap bitmap, string suffix) + { + bitmap.SaveAsFile(Game, suffix, Emu.SystemId, Config.PathEntries); + } + private void SaveBGAScreenshotToolStripMenuItem_Click(object sender, EventArgs e) { - bmpViewNTA.SaveFile(); + SaveAsFile(bmpViewNTA.Bmp, "NTA"); } private void SaveBGBScreenshotToolStripMenuItem_Click(object sender, EventArgs e) { - bmpViewNTB.SaveFile(); + SaveAsFile(bmpViewNTA.Bmp, "NTB"); } private void SaveTilesScreenshotToolStripMenuItem_Click(object sender, EventArgs e) { - bmpViewTiles.SaveFile(); + SaveAsFile(bmpViewNTA.Bmp, "Tiles"); } private void SaveWindowScreenshotToolStripMenuItem_Click(object sender, EventArgs e) { - bmpViewNTW.SaveFile(); + SaveAsFile(bmpViewNTA.Bmp, "Window"); } private void SavePaletteScreenshotToolStripMenuItem_Click(object sender, EventArgs e) { - bmpViewPal.SaveFile(); + SaveAsFile(bmpViewNTA.Bmp, "Palettes"); } private void CloseMenuItem_Click(object sender, EventArgs e) diff --git a/src/BizHawk.Client.EmuHawk/tools/NES/NESNameTableViewer.cs b/src/BizHawk.Client.EmuHawk/tools/NES/NESNameTableViewer.cs index 33bae8eee2..bfa7a0c535 100644 --- a/src/BizHawk.Client.EmuHawk/tools/NES/NESNameTableViewer.cs +++ b/src/BizHawk.Client.EmuHawk/tools/NES/NESNameTableViewer.cs @@ -1,7 +1,6 @@ using System; using System.Drawing; using System.Drawing.Imaging; -using System.IO; using System.Windows.Forms; using BizHawk.Client.Common; @@ -182,42 +181,11 @@ namespace BizHawk.Client.EmuHawk NameTableView.Refresh(); } - public void Screenshot(Bitmap b) - { - using var sfd = new SaveFileDialog - { - FileName = $"{Game.FilesystemSafeName()}-Nametables", - InitialDirectory = Config.PathEntries.ScreenshotAbsolutePathFor("NES"), - 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; - } - - b.Save(file.FullName, i); - } - private void ScreenshotMenuItem_Click(object sender, EventArgs e) { - Screenshot(NameTableView.ToBitMap()); + NameTableView + .ToBitMap() + .SaveAsFile(Game, "Nametables", "NES", Config.PathEntries); } private void ScreenshotToClipboardMenuItem_Click(object sender, EventArgs e) diff --git a/src/BizHawk.Client.EmuHawk/tools/NES/NESPPU.cs b/src/BizHawk.Client.EmuHawk/tools/NES/NESPPU.cs index b759a88942..f5da14bb60 100644 --- a/src/BizHawk.Client.EmuHawk/tools/NES/NESPPU.cs +++ b/src/BizHawk.Client.EmuHawk/tools/NES/NESPPU.cs @@ -1,7 +1,6 @@ using System; using System.Drawing; using System.Drawing.Imaging; -using System.IO; using System.Windows.Forms; using BizHawk.Client.Common; @@ -312,35 +311,7 @@ namespace BizHawk.Client.EmuHawk private void Screenshot(Bitmap b, string suffix) { - var sfd = new SaveFileDialog - { - FileName = $"{Game.FilesystemSafeName()}-{suffix}", - InitialDirectory = Config.PathEntries.ScreenshotAbsolutePathFor("NES"), - 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; - } - - b.Save(file.FullName, i); + b.SaveAsFile(Game, suffix, "NES", Config.PathEntries); } private void SavePaletteScreenshotMenuItem_Click(object sender, EventArgs e)