Input Roll - cache brushes instead of creating and deleting

This commit is contained in:
adelikat 2014-08-09 22:01:00 +00:00
parent 9592f4dacf
commit cb23aaeaa2
2 changed files with 25 additions and 7 deletions

View File

@ -147,6 +147,14 @@ namespace BizHawk.Client.EmuHawk.CustomControls
/// </summary> /// </summary>
public void Dispose() public void Dispose()
{ {
foreach (var brush in BrushCache)
{
if (brush.Value != IntPtr.Zero)
{
DeleteObject(brush.Value);
}
}
if (_c != null) if (_c != null)
{ {
ReleaseDC(_c.Handle, _hdc); ReleaseDC(_c.Handle, _hdc);
@ -161,7 +169,6 @@ namespace BizHawk.Client.EmuHawk.CustomControls
} }
} }
#region Private methods #region Private methods
/// <summary> /// <summary>
@ -229,18 +236,29 @@ namespace BizHawk.Client.EmuHawk.CustomControls
// TODO: use the "current brush" instead of grabbing a new one // TODO: use the "current brush" instead of grabbing a new one
public void SetBrush(Color color) public void SetBrush(Color color)
{
if (BrushCache.ContainsKey(color))
{
_currentBrush = BrushCache[color];
}
else
{ {
int rgb = (color.B & 0xFF) << 16 | (color.G & 0xFF) << 8 | color.R; int rgb = (color.B & 0xFF) << 16 | (color.G & 0xFF) << 8 | color.R;
DeleteObject(_brush); var newBrush = CreateSolidBrush(rgb);
_brush = CreateSolidBrush(rgb); BrushCache.Add(color, newBrush);
_currentBrush = newBrush;
}
} }
private IntPtr _brush = IntPtr.Zero; //private IntPtr _brush = IntPtr.Zero;
Dictionary<Color, IntPtr> BrushCache = new Dictionary<Color, IntPtr>();
private IntPtr _currentBrush = IntPtr.Zero;
public void FillRectangle(int x,int y, int w, int h) public void FillRectangle(int x,int y, int w, int h)
{ {
var r = new GDIRect(new Rectangle(x, y, x + w, y + h)); var r = new GDIRect(new Rectangle(x, y, x + w, y + h));
FillRect(_hdc, ref r, _brush); FillRect(_hdc, ref r, _currentBrush);
} }
public void SetPenPosition(int x, int y) public void SetPenPosition(int x, int y)

View File

@ -25,7 +25,7 @@ namespace BizHawk.Client.EmuHawk
} }
Watches.UpdateValues(); Watches.UpdateValues();
InputView.Invalidate(); InputView.Refresh();
} }
public void FastUpdate() public void FastUpdate()