GB config code cleanup

This commit is contained in:
adelikat 2019-12-15 16:06:33 -06:00
parent f833d50f30
commit a39cedb366
7 changed files with 124 additions and 138 deletions

View File

@ -75,6 +75,7 @@ namespace BizHawk.Client.EmuHawk
BMP.Dispose(); BMP.Dispose();
} }
BMP = new Bitmap(w, h, PixelFormat.Format32bppArgb); BMP = new Bitmap(w, h, PixelFormat.Format32bppArgb);
BmpView_SizeChanged(null, null); BmpView_SizeChanged(null, null);
Refresh(); Refresh();
@ -82,17 +83,17 @@ namespace BizHawk.Client.EmuHawk
public void Clear() public void Clear()
{ {
var lockdata = BMP.LockBits(new Rectangle(0, 0, BMP.Width, BMP.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); var lockBits = BMP.LockBits(new Rectangle(0, 0, BMP.Width, BMP.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
Win32.MemSet(lockdata.Scan0, 0xff, (uint)(lockdata.Height * lockdata.Stride)); Win32.MemSet(lockBits.Scan0, 0xff, (uint)(lockBits.Height * lockBits.Stride));
BMP.UnlockBits(lockdata); BMP.UnlockBits(lockBits);
Refresh(); Refresh();
} }
public void SaveFile() public void SaveFile()
{ {
string path = PathManager.MakeAbsolutePath( string path = PathManager.MakeAbsolutePath(
Global.Config.PathEntries[Global.Emulator.SystemId, "Screenshots"].Path, Global.Config.PathEntries[Global.Emulator.SystemId, "Screenshots"].Path,
Global.Emulator.SystemId); Global.Emulator.SystemId);
var di = new DirectoryInfo(path); var di = new DirectoryInfo(path);

View File

@ -44,11 +44,11 @@ namespace BizHawk.Client.EmuHawk
private unsafe void RefreshType() private unsafe void RefreshType()
{ {
var lockdata = bmpView1.BMP.LockBits(new Rectangle(0, 0, 256, 128), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); var lockBits = bmpView1.BMP.LockBits(new Rectangle(0, 0, 256, 128), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
int[] lut = GBColors.GetLut(_type); int[] lut = GBColors.GetLut(_type);
int* dest = (int*)lockdata.Scan0; int* dest = (int*)lockBits.Scan0;
for (int j = 0; j < 128; j++) for (int j = 0; j < 128; j++)
{ {
@ -62,10 +62,10 @@ namespace BizHawk.Client.EmuHawk
} }
dest -= 256; dest -= 256;
dest += lockdata.Stride / sizeof(int); dest += lockBits.Stride / sizeof(int);
} }
bmpView1.BMP.UnlockBits(lockdata); bmpView1.BMP.UnlockBits(lockBits);
bmpView1.Refresh(); bmpView1.Refresh();
} }
@ -101,23 +101,20 @@ namespace BizHawk.Client.EmuHawk
_type = GBColors.ColorType.gba; _type = GBColors.ColorType.gba;
} }
var radioButton = sender as RadioButton; if (sender is RadioButton radioButton && radioButton.Checked)
if (radioButton != null && radioButton.Checked)
{ {
RefreshType(); RefreshType();
} }
} }
public static void DoCGBColorChoserFormDialog(IWin32Window parent, Gameboy.GambatteSettings s) public static void DoCGBColorChooserFormDialog(IWin32Window parent, Gameboy.GambatteSettings s)
{ {
using (var dlg = new CGBColorChooserForm()) using var dlg = new CGBColorChooserForm();
dlg.LoadType(s);
var result = dlg.ShowDialog(parent);
if (result == DialogResult.OK)
{ {
dlg.LoadType(s); s.CGBColors = dlg._type;
var result = dlg.ShowDialog(parent);
if (result == DialogResult.OK)
{
s.CGBColors = dlg._type;
}
} }
} }
} }

View File

@ -50,7 +50,7 @@ namespace BizHawk.Client.EmuHawk
panel12.BackColor = _colors[11]; panel12.BackColor = _colors[11];
} }
private Color Betweencolor(Color left, Color right, double pos) private Color BetweenColor(Color left, Color right, double pos)
{ {
int r = (int)(right.R * pos + left.R * (1.0 - pos) + 0.5); int r = (int)(right.R * pos + left.R * (1.0 - pos) + 0.5);
int g = (int)(right.G * pos + left.G * (1.0 - pos) + 0.5); int g = (int)(right.G * pos + left.G * (1.0 - pos) + 0.5);
@ -60,12 +60,12 @@ namespace BizHawk.Client.EmuHawk
return Color.FromArgb(a, r, g, b); return Color.FromArgb(a, r, g, b);
} }
private void InterpolateColors(int firstindex, int lastindex) private void InterpolateColors(int firstIndex, int lastIndex)
{ {
for (int i = firstindex + 1; i < lastindex; i++) for (int i = firstIndex + 1; i < lastIndex; i++)
{ {
double pos = (i - firstindex) / (double)(lastindex - firstindex); double pos = (i - firstIndex) / (double)(lastIndex - firstIndex);
_colors[i] = Betweencolor(_colors[firstindex], _colors[lastindex], pos); _colors[i] = BetweenColor(_colors[firstIndex], _colors[lastIndex], pos);
} }
RefreshAllBackdrops(); RefreshAllBackdrops();
@ -118,39 +118,39 @@ namespace BizHawk.Client.EmuHawk
else else
return; // i = -1; return; // i = -1;
using (var dlg = new ColorDialog()) using var dlg = new ColorDialog
{ {
dlg.AllowFullOpen = true; AllowFullOpen = true,
dlg.AnyColor = true; AnyColor = true,
dlg.Color = _colors[i]; Color = _colors[i]
};
// custom colors are ints, not Color structs? // custom colors are ints, not Color structs?
// and they don't work right unless the alpha bits are set to 0 // and they don't work right unless the alpha bits are set to 0
// and the rgb order is switched // and the rgb order is switched
int[] customs = new int[12]; int[] customs = new int[12];
for (int j = 0; j < customs.Length; j++) for (int j = 0; j < customs.Length; j++)
{
customs[j] = _colors[j].R | _colors[j].G << 8 | _colors[j].B << 16;
}
dlg.CustomColors = customs;
dlg.FullOpen = true;
var result = dlg.ShowDialog(this);
if (result == DialogResult.OK)
{
if (_colors[i] != dlg.Color)
{ {
customs[j] = _colors[j].R | _colors[j].G << 8 | _colors[j].B << 16; _colors[i] = dlg.Color;
} psender.BackColor = _colors[i];
dlg.CustomColors = customs;
dlg.FullOpen = true;
var result = dlg.ShowDialog(this);
if (result == DialogResult.OK)
{
if (_colors[i] != dlg.Color)
{
_colors[i] = dlg.Color;
psender.BackColor = _colors[i];
}
} }
} }
} }
// ini keys for gambatte palette file // ini keys for gambatte palette file
private static readonly string[] Paletteinikeys = private static readonly string[] PaletteIniKeys =
{ {
"Background0", "Background0",
"Background1", "Background1",
@ -197,7 +197,7 @@ namespace BizHawk.Client.EmuHawk
{ {
for (int i = 0; i < 12; i++) for (int i = 0; i < 12; i++)
{ {
ret[i] = lines[Paletteinikeys[i]]; ret[i] = lines[PaletteIniKeys[i]];
} }
} }
catch (KeyNotFoundException) catch (KeyNotFoundException)
@ -214,7 +214,7 @@ namespace BizHawk.Client.EmuHawk
f.WriteLine("[General]"); f.WriteLine("[General]");
for (int i = 0; i < 12; i++) for (int i = 0; i < 12; i++)
{ {
f.WriteLine($"{Paletteinikeys[i]}={colors[i]}"); f.WriteLine($"{PaletteIniKeys[i]}={colors[i]}");
} }
} }
@ -229,32 +229,30 @@ namespace BizHawk.Client.EmuHawk
RefreshAllBackdrops(); RefreshAllBackdrops();
} }
private static void DoColorChooserFormDialog(IWin32Window parent, Gameboy.GambatteSettings s, bool fromemu) private static void DoColorChooserFormDialog(IWin32Window parent, Gameboy.GambatteSettings s, bool fromMenu)
{ {
using (var dlg = new ColorChooserForm()) using var dlg = new ColorChooserForm();
var gb = Global.Emulator as Gameboy;
if (fromMenu)
{ {
var gb = Global.Emulator as Gameboy; s = gb.GetSettings();
if (fromemu) }
dlg.SetAllColors(s.GBPalette);
var result = dlg.ShowDialog(parent);
if (result == DialogResult.OK)
{
int[] colors = new int[12];
for (int i = 0; i < 12; i++)
{ {
s = gb.GetSettings(); colors[i] = dlg._colors[i].ToArgb();
} }
dlg.SetAllColors(s.GBPalette); s.GBPalette = colors;
if (fromMenu)
var result = dlg.ShowDialog(parent);
if (result == DialogResult.OK)
{ {
int[] colorints = new int[12]; gb.PutSettings(s);
for (int i = 0; i < 12; i++)
{
colorints[i] = dlg._colors[i].ToArgb();
}
s.GBPalette = colorints;
if (fromemu)
{
gb.PutSettings(s);
}
} }
} }
} }
@ -268,16 +266,14 @@ namespace BizHawk.Client.EmuHawk
{ {
try try
{ {
using (var f = new StreamReader(filename)) using var f = new StreamReader(filename);
int[] newColors = LoadPalFile(f);
if (newColors == null)
{ {
int[] newcolors = LoadPalFile(f); throw new Exception();
if (newcolors == null)
{
throw new Exception();
}
SetAllColors(newcolors);
} }
SetAllColors(newColors);
} }
catch catch
{ {
@ -292,17 +288,15 @@ namespace BizHawk.Client.EmuHawk
{ {
try try
{ {
using (var f = new StreamWriter(filename)) using var f = new StreamWriter(filename);
int[] saveColors = new int[12];
for (int i = 0; i < 12; i++)
{ {
int[] savecolors = new int[12]; // clear alpha because gambatte color files don't usually contain it
for (int i = 0; i < 12; i++) saveColors[i] = _colors[i].ToArgb() & 0xffffff;
{
// clear alpha because gambatte color files don't usually contain it
savecolors[i] = _colors[i].ToArgb() & 0xffffff;
}
SavePalFile(f, savecolors);
} }
SavePalFile(f, saveColors);
} }
catch catch
{ {
@ -312,17 +306,17 @@ namespace BizHawk.Client.EmuHawk
private void Button6_Click(object sender, EventArgs e) private void Button6_Click(object sender, EventArgs e)
{ {
using (var ofd = new OpenFileDialog()) using var ofd = new OpenFileDialog
{ {
ofd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries["GB", "Palettes"].Path, "GB"); InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries["GB", "Palettes"].Path, "GB"),
ofd.Filter = "Gambatte Palettes (*.pal)|*.pal|All Files|*.*"; Filter = "Gambatte Palettes (*.pal)|*.pal|All Files|*.*",
ofd.RestoreDirectory = true; RestoreDirectory = true
};
var result = ofd.ShowDialog(this); var result = ofd.ShowDialog(this);
if (result == DialogResult.OK) if (result == DialogResult.OK)
{ {
LoadColorFile(ofd.FileName, true); LoadColorFile(ofd.FileName, true);
}
} }
} }
@ -350,18 +344,18 @@ namespace BizHawk.Client.EmuHawk
private void Button7_Click(object sender, EventArgs e) private void Button7_Click(object sender, EventArgs e)
{ {
using (var sfd = new SaveFileDialog()) using var sfd = new SaveFileDialog
{ {
sfd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries["GB", "Palettes"].Path, "GB"); InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries["GB", "Palettes"].Path, "GB"),
sfd.FileName = $"{Global.Game.Name}.pal"; FileName = $"{Global.Game.Name}.pal",
Filter = "Gambatte Palettes (*.pal)|*.pal|All Files|*.*",
RestoreDirectory = true
};
sfd.Filter = "Gambatte Palettes (*.pal)|*.pal|All Files|*.*"; var result = sfd.ShowDialog(this);
sfd.RestoreDirectory = true; if (result == DialogResult.OK)
var result = sfd.ShowDialog(this); {
if (result == DialogResult.OK) SaveColorFile(sfd.FileName);
{
SaveColorFile(sfd.FileName);
}
} }
} }

View File

@ -20,12 +20,8 @@ namespace BizHawk.Client.EmuHawk
private void GetSettings(out GambatteLink.GambatteLinkSettings s, out GambatteLink.GambatteLinkSyncSettings ss) private void GetSettings(out GambatteLink.GambatteLinkSettings s, out GambatteLink.GambatteLinkSyncSettings ss)
{ {
Gameboy.GambatteSettings sl; gbPrefControl1.GetSettings(out var sl, out var ssl);
Gameboy.GambatteSyncSettings ssl; gbPrefControl2.GetSettings(out var sr, out var ssr);
Gameboy.GambatteSettings sr;
Gameboy.GambatteSyncSettings ssr;
gbPrefControl1.GetSettings(out sl, out ssl);
gbPrefControl2.GetSettings(out sr, out ssr);
s = new GambatteLink.GambatteLinkSettings(sl, sr); s = new GambatteLink.GambatteLinkSettings(sl, sr);
ss = new GambatteLink.GambatteLinkSyncSettings(ssl, ssr); ss = new GambatteLink.GambatteLinkSyncSettings(ssl, ssr);
@ -39,22 +35,20 @@ namespace BizHawk.Client.EmuHawk
var s = gambatte.GetSettings(); var s = gambatte.GetSettings();
var ss = gambatte.GetSyncSettings(); var ss = gambatte.GetSyncSettings();
using (var dlg = new DGBPrefs()) using var dlg = new DGBPrefs();
dlg.PutSettings(s, ss);
var emu = (GambatteLink)Global.Emulator;
dlg.gbPrefControl1.ColorGameBoy = emu.IsCGBMode(false);
dlg.gbPrefControl2.ColorGameBoy = emu.IsCGBMode(true);
if (dlg.ShowDialog(owner) == DialogResult.OK)
{ {
dlg.PutSettings(s, ss); dlg.GetSettings(out s, out ss);
gambatte.PutSettings(s);
var emu = (GambatteLink)Global.Emulator; if (dlg.SyncSettingsChanged)
dlg.gbPrefControl1.ColorGameBoy = emu.IsCGBMode(false);
dlg.gbPrefControl2.ColorGameBoy = emu.IsCGBMode(true);
if (dlg.ShowDialog(owner) == DialogResult.OK)
{ {
dlg.GetSettings(out s, out ss); GlobalWin.MainForm.PutCoreSyncSettings(ss);
gambatte.PutSettings(s);
if (dlg.SyncSettingsChanged)
{
GlobalWin.MainForm.PutCoreSyncSettings(ss);
}
} }
} }
} }

View File

@ -54,7 +54,7 @@ namespace BizHawk.Client.EmuHawk
{ {
if (ColorGameBoy) if (ColorGameBoy)
{ {
CGBColorChooserForm.DoCGBColorChoserFormDialog(ParentForm, _s); CGBColorChooserForm.DoCGBColorChooserFormDialog(ParentForm, _s);
} }
else else
{ {

View File

@ -18,18 +18,16 @@ namespace BizHawk.Client.EmuHawk
var s = gb.GetSettings(); var s = gb.GetSettings();
var ss = gb.GetSyncSettings(); var ss = gb.GetSyncSettings();
using (var dlg = new GBPrefs()) using var dlg = new GBPrefs();
dlg.gbPrefControl1.PutSettings(s, ss);
dlg.gbPrefControl1.ColorGameBoy = gb.IsCGBMode();
if (dlg.ShowDialog(owner) == DialogResult.OK)
{ {
dlg.gbPrefControl1.PutSettings(s, ss); dlg.gbPrefControl1.GetSettings(out s, out ss);
dlg.gbPrefControl1.ColorGameBoy = gb.IsCGBMode(); gb.PutSettings(s);
if (dlg.ShowDialog(owner) == DialogResult.OK) if (dlg.gbPrefControl1.SyncSettingsChanged)
{ {
dlg.gbPrefControl1.GetSettings(out s, out ss); GlobalWin.MainForm.PutCoreSyncSettings(ss);
gb.PutSettings(s);
if (dlg.gbPrefControl1.SyncSettingsChanged)
{
GlobalWin.MainForm.PutCoreSyncSettings(ss);
}
} }
} }
} }

View File

@ -234,6 +234,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Framerate/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Framerate/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Frameskip/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Frameskip/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Frameskipping/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Frameskipping/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=gambatte/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Gameboy/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Gameboy/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=gamedb/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=gamedb/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=gamepad/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=gamepad/@EntryIndexedValue">True</s:Boolean>
@ -289,6 +290,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Phaser/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Phaser/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=pinvoked/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=pinvoked/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Pollable/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Pollable/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Prefs/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=preload/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=preload/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Prereqs/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Prereqs/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=quickload/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=quickload/@EntryIndexedValue">True</s:Boolean>