Input Roll - cache brushes instead of creating and deleting
This commit is contained in:
parent
9592f4dacf
commit
cb23aaeaa2
|
@ -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>
|
||||||
|
@ -230,17 +237,28 @@ 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)
|
||||||
{
|
{
|
||||||
int rgb = (color.B & 0xFF) << 16 | (color.G & 0xFF) << 8 | color.R;
|
if (BrushCache.ContainsKey(color))
|
||||||
DeleteObject(_brush);
|
{
|
||||||
_brush = CreateSolidBrush(rgb);
|
_currentBrush = BrushCache[color];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int rgb = (color.B & 0xFF) << 16 | (color.G & 0xFF) << 8 | color.R;
|
||||||
|
var newBrush = 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)
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
|
|
||||||
Watches.UpdateValues();
|
Watches.UpdateValues();
|
||||||
InputView.Invalidate();
|
InputView.Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FastUpdate()
|
public void FastUpdate()
|
||||||
|
|
Loading…
Reference in New Issue