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 = new Bitmap(w, h, PixelFormat.Format32bppArgb);
BmpView_SizeChanged(null, null);
Refresh();
@ -82,9 +83,9 @@ namespace BizHawk.Client.EmuHawk
public void Clear()
{
var lockdata = BMP.LockBits(new Rectangle(0, 0, BMP.Width, BMP.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
Win32.MemSet(lockdata.Scan0, 0xff, (uint)(lockdata.Height * lockdata.Stride));
BMP.UnlockBits(lockdata);
var lockBits = BMP.LockBits(new Rectangle(0, 0, BMP.Width, BMP.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
Win32.MemSet(lockBits.Scan0, 0xff, (uint)(lockBits.Height * lockBits.Stride));
BMP.UnlockBits(lockBits);
Refresh();
}

View File

@ -44,11 +44,11 @@ namespace BizHawk.Client.EmuHawk
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* dest = (int*)lockdata.Scan0;
int* dest = (int*)lockBits.Scan0;
for (int j = 0; j < 128; j++)
{
@ -62,10 +62,10 @@ namespace BizHawk.Client.EmuHawk
}
dest -= 256;
dest += lockdata.Stride / sizeof(int);
dest += lockBits.Stride / sizeof(int);
}
bmpView1.BMP.UnlockBits(lockdata);
bmpView1.BMP.UnlockBits(lockBits);
bmpView1.Refresh();
}
@ -101,17 +101,15 @@ namespace BizHawk.Client.EmuHawk
_type = GBColors.ColorType.gba;
}
var radioButton = sender as RadioButton;
if (radioButton != null && radioButton.Checked)
if (sender is RadioButton radioButton && radioButton.Checked)
{
RefreshType();
}
}
public static void DoCGBColorChoserFormDialog(IWin32Window parent, Gameboy.GambatteSettings s)
{
using (var dlg = new CGBColorChooserForm())
public static void DoCGBColorChooserFormDialog(IWin32Window parent, Gameboy.GambatteSettings s)
{
using var dlg = new CGBColorChooserForm();
dlg.LoadType(s);
var result = dlg.ShowDialog(parent);
if (result == DialogResult.OK)
@ -121,4 +119,3 @@ namespace BizHawk.Client.EmuHawk
}
}
}
}

View File

@ -50,7 +50,7 @@ namespace BizHawk.Client.EmuHawk
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 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);
}
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);
_colors[i] = Betweencolor(_colors[firstindex], _colors[lastindex], pos);
double pos = (i - firstIndex) / (double)(lastIndex - firstIndex);
_colors[i] = BetweenColor(_colors[firstIndex], _colors[lastIndex], pos);
}
RefreshAllBackdrops();
@ -118,11 +118,12 @@ namespace BizHawk.Client.EmuHawk
else
return; // i = -1;
using (var dlg = new ColorDialog())
using var dlg = new ColorDialog
{
dlg.AllowFullOpen = true;
dlg.AnyColor = true;
dlg.Color = _colors[i];
AllowFullOpen = true,
AnyColor = true,
Color = _colors[i]
};
// custom colors are ints, not Color structs?
// 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
private static readonly string[] Paletteinikeys =
private static readonly string[] PaletteIniKeys =
{
"Background0",
"Background1",
@ -197,7 +197,7 @@ namespace BizHawk.Client.EmuHawk
{
for (int i = 0; i < 12; i++)
{
ret[i] = lines[Paletteinikeys[i]];
ret[i] = lines[PaletteIniKeys[i]];
}
}
catch (KeyNotFoundException)
@ -214,7 +214,7 @@ namespace BizHawk.Client.EmuHawk
f.WriteLine("[General]");
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();
}
private static void DoColorChooserFormDialog(IWin32Window parent, Gameboy.GambatteSettings s, bool fromemu)
{
using (var dlg = new ColorChooserForm())
private static void DoColorChooserFormDialog(IWin32Window parent, Gameboy.GambatteSettings s, bool fromMenu)
{
using var dlg = new ColorChooserForm();
var gb = Global.Emulator as Gameboy;
if (fromemu)
if (fromMenu)
{
s = gb.GetSettings();
}
@ -244,20 +243,19 @@ namespace BizHawk.Client.EmuHawk
var result = dlg.ShowDialog(parent);
if (result == DialogResult.OK)
{
int[] colorints = new int[12];
int[] colors = new int[12];
for (int i = 0; i < 12; i++)
{
colorints[i] = dlg._colors[i].ToArgb();
colors[i] = dlg._colors[i].ToArgb();
}
s.GBPalette = colorints;
if (fromemu)
s.GBPalette = colors;
if (fromMenu)
{
gb.PutSettings(s);
}
}
}
}
public static void DoColorChooserFormDialog(IWin32Window parent, Gameboy.GambatteSettings s)
{
@ -268,16 +266,14 @@ namespace BizHawk.Client.EmuHawk
{
try
{
using (var f = new StreamReader(filename))
{
int[] newcolors = LoadPalFile(f);
if (newcolors == null)
using var f = new StreamReader(filename);
int[] newColors = LoadPalFile(f);
if (newColors == null)
{
throw new Exception();
}
SetAllColors(newcolors);
}
SetAllColors(newColors);
}
catch
{
@ -292,17 +288,15 @@ namespace BizHawk.Client.EmuHawk
{
try
{
using (var f = new StreamWriter(filename))
{
int[] savecolors = new int[12];
using var f = new StreamWriter(filename);
int[] saveColors = new int[12];
for (int i = 0; i < 12; i++)
{
// 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
{
@ -312,11 +306,12 @@ namespace BizHawk.Client.EmuHawk
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");
ofd.Filter = "Gambatte Palettes (*.pal)|*.pal|All Files|*.*";
ofd.RestoreDirectory = true;
InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries["GB", "Palettes"].Path, "GB"),
Filter = "Gambatte Palettes (*.pal)|*.pal|All Files|*.*",
RestoreDirectory = true
};
var result = ofd.ShowDialog(this);
if (result == DialogResult.OK)
@ -324,7 +319,6 @@ namespace BizHawk.Client.EmuHawk
LoadColorFile(ofd.FileName, true);
}
}
}
private void ColorChooserForm_DragDrop(object sender, DragEventArgs e)
{
@ -350,20 +344,20 @@ namespace BizHawk.Client.EmuHawk
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");
sfd.FileName = $"{Global.Game.Name}.pal";
InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries["GB", "Palettes"].Path, "GB"),
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);
if (result == DialogResult.OK)
{
SaveColorFile(sfd.FileName);
}
}
}
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)
{
Gameboy.GambatteSettings sl;
Gameboy.GambatteSyncSettings ssl;
Gameboy.GambatteSettings sr;
Gameboy.GambatteSyncSettings ssr;
gbPrefControl1.GetSettings(out sl, out ssl);
gbPrefControl2.GetSettings(out sr, out ssr);
gbPrefControl1.GetSettings(out var sl, out var ssl);
gbPrefControl2.GetSettings(out var sr, out var ssr);
s = new GambatteLink.GambatteLinkSettings(sl, sr);
ss = new GambatteLink.GambatteLinkSyncSettings(ssl, ssr);
@ -39,8 +35,7 @@ namespace BizHawk.Client.EmuHawk
var s = gambatte.GetSettings();
var ss = gambatte.GetSyncSettings();
using (var dlg = new DGBPrefs())
{
using var dlg = new DGBPrefs();
dlg.PutSettings(s, ss);
var emu = (GambatteLink)Global.Emulator;
@ -59,4 +54,3 @@ namespace BizHawk.Client.EmuHawk
}
}
}
}

View File

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

View File

@ -18,8 +18,7 @@ namespace BizHawk.Client.EmuHawk
var s = gb.GetSettings();
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)
@ -34,4 +33,3 @@ 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/=Frameskip/@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/=gamedb/@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/=pinvoked/@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/=Prereqs/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=quickload/@EntryIndexedValue">True</s:Boolean>