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,9 +83,9 @@ 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();
} }

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,17 +101,15 @@ 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); dlg.LoadType(s);
var result = dlg.ShowDialog(parent); var result = dlg.ShowDialog(parent);
if (result == DialogResult.OK) if (result == DialogResult.OK)
@ -120,5 +118,4 @@ namespace BizHawk.Client.EmuHawk
} }
} }
} }
}
} }

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,11 +118,12 @@ 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
@ -147,10 +148,9 @@ namespace BizHawk.Client.EmuHawk
} }
} }
} }
}
// 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,12 +229,11 @@ 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; var gb = Global.Emulator as Gameboy;
if (fromemu) if (fromMenu)
{ {
s = gb.GetSettings(); s = gb.GetSettings();
} }
@ -244,20 +243,19 @@ namespace BizHawk.Client.EmuHawk
var result = dlg.ShowDialog(parent); var result = dlg.ShowDialog(parent);
if (result == DialogResult.OK) if (result == DialogResult.OK)
{ {
int[] colorints = new int[12]; int[] colors = new int[12];
for (int i = 0; i < 12; i++) for (int i = 0; i < 12; i++)
{ {
colorints[i] = dlg._colors[i].ToArgb(); colors[i] = dlg._colors[i].ToArgb();
} }
s.GBPalette = colorints; s.GBPalette = colors;
if (fromemu) if (fromMenu)
{ {
gb.PutSettings(s); gb.PutSettings(s);
} }
} }
} }
}
public static void DoColorChooserFormDialog(IWin32Window parent, Gameboy.GambatteSettings s) public static void DoColorChooserFormDialog(IWin32Window parent, Gameboy.GambatteSettings 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);
int[] newcolors = LoadPalFile(f); if (newColors == null)
if (newcolors == null)
{ {
throw new Exception(); 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];
int[] savecolors = new int[12];
for (int i = 0; i < 12; i++) for (int i = 0; i < 12; i++)
{ {
// clear alpha because gambatte color files don't usually contain it // clear alpha because gambatte color files don't usually contain it
savecolors[i] = _colors[i].ToArgb() & 0xffffff; saveColors[i] = _colors[i].ToArgb() & 0xffffff;
} }
SavePalFile(f, savecolors); SavePalFile(f, saveColors);
}
} }
catch catch
{ {
@ -312,11 +306,12 @@ 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)
@ -324,7 +319,6 @@ namespace BizHawk.Client.EmuHawk
LoadColorFile(ofd.FileName, true); LoadColorFile(ofd.FileName, true);
} }
} }
}
private void ColorChooserForm_DragDrop(object sender, DragEventArgs e) private void ColorChooserForm_DragDrop(object sender, DragEventArgs e)
{ {
@ -350,20 +344,20 @@ 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|*.*";
sfd.RestoreDirectory = true;
var result = sfd.ShowDialog(this); var result = sfd.ShowDialog(this);
if (result == DialogResult.OK) if (result == DialogResult.OK)
{ {
SaveColorFile(sfd.FileName); SaveColorFile(sfd.FileName);
} }
} }
}
private void Ok_Click(object sender, EventArgs e) private void Ok_Click(object sender, EventArgs e)
{ {

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,8 +35,7 @@ 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); dlg.PutSettings(s, ss);
var emu = (GambatteLink)Global.Emulator; var emu = (GambatteLink)Global.Emulator;
@ -58,5 +53,4 @@ namespace BizHawk.Client.EmuHawk
} }
} }
} }
}
} }

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,8 +18,7 @@ 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.PutSettings(s, ss);
dlg.gbPrefControl1.ColorGameBoy = gb.IsCGBMode(); dlg.gbPrefControl1.ColorGameBoy = gb.IsCGBMode();
if (dlg.ShowDialog(owner) == DialogResult.OK) if (dlg.ShowDialog(owner) == DialogResult.OK)
@ -33,5 +32,4 @@ namespace BizHawk.Client.EmuHawk
} }
} }
} }
}
} }

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>