reduce some copy pasta for Bmp file creation across various tool dialogs
This commit is contained in:
parent
f9fff69ce4
commit
777a2e8f3e
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue