move hex editor colors from Config to the tool itself using ConfigPersist

This commit is contained in:
adelikat 2020-01-20 15:58:32 -06:00
parent b1ef7bcbbb
commit 9f06e442ab
4 changed files with 75 additions and 72 deletions

View File

@ -312,14 +312,6 @@ namespace BizHawk.Client.Common
public PreviousType RamWatchDefinePrevious = PreviousType.LastFrame;
public bool DisplayRamWatch = false;
// Hex Editor Colors
public Color HexBackgrndColor = SystemColors.Control;
public Color HexForegrndColor = SystemColors.ControlText;
public Color HexMenubarColor = SystemColors.Control;
public Color HexFreezeColor = Color.LightBlue;
public Color HexHighlightColor = Color.Pink;
public Color HexHighlightFreezeColor = Color.Violet;
// Video dumping settings
public string VideoWriter = "";
public int JMDCompression = 3;
@ -344,8 +336,7 @@ namespace BizHawk.Client.Common
public object GetCoreSettings(Type t)
{
object ret;
CoreSettings.TryGetValue(t.ToString(), out ret);
CoreSettings.TryGetValue(t.ToString(), out var ret);
return ret;
}

View File

@ -9,32 +9,30 @@ namespace BizHawk.Client.EmuHawk
public partial class HexColorsForm : Form
{
private readonly HexEditor _hexEditor;
private readonly Config _config;
public HexColorsForm(HexEditor hexEditor, Config config)
public HexColorsForm(HexEditor hexEditor)
{
_hexEditor = hexEditor;
_config = config;
InitializeComponent();
}
private void HexColors_Form_Load(object sender, EventArgs e)
{
HexBackgrnd.BackColor = _config.HexBackgrndColor;
HexForegrnd.BackColor = _config.HexForegrndColor;
HexMenubar.BackColor = _config.HexMenubarColor;
HexFreeze.BackColor = _config.HexFreezeColor;
HexFreezeHL.BackColor = _config.HexHighlightFreezeColor;
HexHighlight.BackColor = _config.HexHighlightColor;
HexBackgrnd.BackColor = _hexEditor.Colors.Background;
HexForegrnd.BackColor = _hexEditor.Colors.Foreground;
HexMenubar.BackColor = _hexEditor.Colors.MenuBar;
HexFreeze.BackColor = _hexEditor.Colors.Freeze;
HexFreezeHL.BackColor = _hexEditor.Colors.HighlightFreeze;
HexHighlight.BackColor = _hexEditor.Colors.Highlight;
}
private void HexBackground_Click(object sender, MouseEventArgs e)
{
if (colorDialog1.ShowDialog() == DialogResult.OK)
{
_config.HexBackgrndColor = colorDialog1.Color;
_hexEditor.Colors.Background = colorDialog1.Color;
_hexEditor.Header.BackColor = colorDialog1.Color;
_hexEditor.MemoryViewerBox.BackColor = _config.HexBackgrndColor;
_hexEditor.MemoryViewerBox.BackColor = _hexEditor.Colors.Background;
HexBackgrnd.BackColor = colorDialog1.Color;
}
}
@ -43,9 +41,9 @@ namespace BizHawk.Client.EmuHawk
{
if (colorDialog1.ShowDialog() == DialogResult.OK)
{
_config.HexForegrndColor = colorDialog1.Color;
_hexEditor.Colors.Foreground = colorDialog1.Color;
_hexEditor.Header.ForeColor = colorDialog1.Color;
_hexEditor.MemoryViewerBox.ForeColor = _config.HexForegrndColor;
_hexEditor.MemoryViewerBox.ForeColor = _hexEditor.Colors.Foreground;
HexForegrnd.BackColor = colorDialog1.Color;
}
}
@ -54,8 +52,8 @@ namespace BizHawk.Client.EmuHawk
{
if (colorDialog1.ShowDialog() == DialogResult.OK)
{
_config.HexMenubarColor = colorDialog1.Color;
_hexEditor.HexMenuStrip.BackColor = _config.HexMenubarColor;
_hexEditor.Colors.MenuBar = colorDialog1.Color;
_hexEditor.HexMenuStrip.BackColor = _hexEditor.Colors.MenuBar;
HexMenubar.BackColor = colorDialog1.Color;
}
}
@ -64,7 +62,7 @@ namespace BizHawk.Client.EmuHawk
{
if (colorDialog1.ShowDialog().IsOk())
{
_config.HexHighlightColor = colorDialog1.Color;
_hexEditor.Colors.Highlight = colorDialog1.Color;
HexHighlight.BackColor = colorDialog1.Color;
}
}
@ -73,7 +71,7 @@ namespace BizHawk.Client.EmuHawk
{
if (colorDialog1.ShowDialog().IsOk())
{
_config.HexFreezeColor = colorDialog1.Color;
_hexEditor.Colors.Freeze = colorDialog1.Color;
HexFreeze.BackColor = colorDialog1.Color;
}
}
@ -82,7 +80,7 @@ namespace BizHawk.Client.EmuHawk
{
if (colorDialog1.ShowDialog().IsOk())
{
_config.HexHighlightFreezeColor = colorDialog1.Color;
_hexEditor.Colors.HighlightFreeze = colorDialog1.Color;
HexFreezeHL.BackColor = colorDialog1.Color;
}
}

View File

@ -91,6 +91,27 @@ namespace BizHawk.Client.EmuHawk
[ConfigPersist]
private RecentFiles RecentTables { get; set; }
internal class ColorConfig
{
public Color Background { get; set; } = SystemColors.Control;
public Color Foreground { get; set; } = SystemColors.ControlText;
public Color MenuBar { get; set; } = SystemColors.Control;
public Color Freeze { get; set; }= Color.LightBlue;
public Color Highlight { get; set; } = Color.Pink;
public Color HighlightFreeze { get; set; } = Color.Violet;
}
[ConfigPersist]
internal ColorConfig Colors { get; set; } = new ColorConfig();
private WatchSize WatchSize => (WatchSize)DataSize;
private readonly Pen _blackPen = new Pen(Color.Black);
private SolidBrush _freezeBrush;
private SolidBrush _freezeHighlightBrush;
private SolidBrush _highlightBrush;
private SolidBrush _secondaryHighlightBrush;
public HexEditor()
{
_hexFind = new HexFind(this);
@ -116,7 +137,25 @@ namespace BizHawk.Client.EmuHawk
AddressLabel.Font = font;
}
private WatchSize WatchSize => (WatchSize)DataSize;
private void HexEditor_Load(object sender, EventArgs e)
{
LoadConfigSettings();
DataSize = _domain.WordSize;
SetDataSize(DataSize);
if (!string.IsNullOrWhiteSpace(LastDomain)
&& MemoryDomains.Any(m => m.Name == LastDomain))
{
SetMemoryDomain(LastDomain);
}
if (RecentTables.AutoLoad)
{
LoadFileFromRecent(RecentTables[0]);
}
FullUpdate();
}
#region API
@ -439,33 +478,18 @@ namespace BizHawk.Client.EmuHawk
return false;
}
private void HexEditor_Load(object sender, EventArgs e)
{
LoadConfigSettings();
DataSize = _domain.WordSize;
SetDataSize(DataSize);
if (!string.IsNullOrWhiteSpace(LastDomain)
&& MemoryDomains.Any(m => m.Name == LastDomain))
{
SetMemoryDomain(LastDomain);
}
if (RecentTables.AutoLoad)
{
LoadFileFromRecent(RecentTables[0]);
}
FullUpdate();
}
private void LoadConfigSettings()
{
HexMenuStrip.BackColor = Config.HexMenubarColor;
MemoryViewerBox.BackColor = Config.HexBackgrndColor;
MemoryViewerBox.ForeColor = Config.HexForegrndColor;
Header.BackColor = Config.HexBackgrndColor;
Header.ForeColor = Config.HexForegrndColor;
HexMenuStrip.BackColor = Colors.MenuBar;
MemoryViewerBox.BackColor = Colors.Background;
MemoryViewerBox.ForeColor = Colors.Foreground;
Header.BackColor = Colors.Background;
Header.ForeColor = Colors.Foreground;
_freezeBrush = new SolidBrush(Colors.Freeze);
_freezeHighlightBrush = new SolidBrush(Colors.HighlightFreeze);
_highlightBrush = new SolidBrush(Colors.Highlight);
_secondaryHighlightBrush = new SolidBrush(Color.FromArgb(0x44, Colors.Highlight));
}
private void CloseHexFind()
@ -1670,7 +1694,7 @@ namespace BizHawk.Client.EmuHawk
private void SetColorsMenuItem_Click(object sender, EventArgs e)
{
using var form = new HexColorsForm(this, Config);
using var form = new HexColorsForm(this);
form.ShowHawkDialog();
}
@ -1681,12 +1705,7 @@ namespace BizHawk.Client.EmuHawk
HexMenuStrip.BackColor = Color.FromName("Control");
Header.BackColor = Color.FromName("Control");
Header.ForeColor = Color.FromName("ControlText");
Config.HexMenubarColor = Color.FromName("Control");
Config.HexForegrndColor = Color.FromName("ControlText");
Config.HexBackgrndColor = Color.FromName("Control");
Config.HexFreezeColor = Color.LightBlue;
Config.HexHighlightColor = Color.Pink;
Config.HexHighlightFreezeColor = Color.Violet;
Colors = new ColorConfig();
}
#endregion
@ -2060,12 +2079,6 @@ namespace BizHawk.Client.EmuHawk
}
}
private readonly Pen _blackPen = new Pen(Color.Black);
private readonly SolidBrush _freezeBrush = new SolidBrush(Global.Config.HexFreezeColor);
private readonly SolidBrush _freezeHighlightBrush = new SolidBrush(Global.Config.HexHighlightFreezeColor);
private readonly SolidBrush _highlightBrush = new SolidBrush(Global.Config.HexHighlightColor);
private readonly SolidBrush _secondaryHighlightBrush = new SolidBrush(Color.FromArgb(0x44, Global.Config.HexHighlightColor));
private void MemoryViewerBox_Paint(object sender, PaintEventArgs e)
{
var activeCheats = Global.CheatList.Where(x => x.Enabled);
@ -2088,7 +2101,7 @@ namespace BizHawk.Client.EmuHawk
var rect = new Rectangle(GetAddressCoordinates(cheat.Address ?? 0), new Size(width, _fontHeight));
e.Graphics.DrawRectangle(_blackPen, rect);
_freezeBrush.Color = Config.HexFreezeColor;
_freezeBrush.Color = Colors.Freeze;
e.Graphics.FillRectangle(_freezeBrush, rect);
}
}
@ -2110,13 +2123,13 @@ namespace BizHawk.Client.EmuHawk
if (Global.CheatList.IsActive(_domain, addressHighlighted))
{
_freezeHighlightBrush.Color = Config.HexHighlightFreezeColor;
_freezeHighlightBrush.Color = Colors.HighlightFreeze;
e.Graphics.FillRectangle(_freezeHighlightBrush, rect);
e.Graphics.FillRectangle(_freezeHighlightBrush, textRect);
}
else
{
_highlightBrush.Color = Config.HexHighlightColor;
_highlightBrush.Color = Colors.Highlight;
e.Graphics.FillRectangle(_highlightBrush, rect);
e.Graphics.FillRectangle(_highlightBrush, textRect);
}
@ -2137,13 +2150,13 @@ namespace BizHawk.Client.EmuHawk
if (Global.CheatList.IsActive(_domain, address))
{
_freezeHighlightBrush.Color = Config.HexHighlightFreezeColor;
_freezeHighlightBrush.Color = Colors.HighlightFreeze;
e.Graphics.FillRectangle(_freezeHighlightBrush, rect);
e.Graphics.FillRectangle(_freezeHighlightBrush, textRect);
}
else
{
_secondaryHighlightBrush.Color = Color.FromArgb(0x44, Config.HexHighlightColor);
_secondaryHighlightBrush.Color = Color.FromArgb(0x44, Colors.Highlight);
e.Graphics.FillRectangle(_secondaryHighlightBrush, rect);
e.Graphics.FillRectangle(_secondaryHighlightBrush, textRect);
}

View File

@ -250,6 +250,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=filenames/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=filesize/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Finetuned/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Fmpeg/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=fname/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=frameadvance/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=FCEUX/@EntryIndexedValue">True</s:Boolean>