Skip to content

Commit a658067

Browse files
committed
Cache and Dispose Brushes in GraphicsRenderContext (oxyplot#1230)
1 parent 8139434 commit a658067

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ All notable changes to this project will be documented in this file.
5555
- Candle overlap each candle (#623)
5656
- CandleStick is overlapped when item.open == item.close in the CandleStickAndVolumeSeries (#1245)
5757
- Out of memory exception and performance issue with Catmull-Rom Spline (#1237)
58+
- Cache and Dispose Brush and Pen objects used by GraphicsRenderContext (#1230)
5859

5960
## [1.0.0] - 2016-09-11
6061
### Added

Source/OxyPlot.WindowsForms/GraphicsRenderContext.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public override void DrawPolygon(
171171
var pts = this.ToPoints(points);
172172
if (fill.IsVisible())
173173
{
174-
this.g.FillPolygon(fill.ToBrush(), pts);
174+
this.g.FillPolygon(this.GetCachedBrush(fill), pts);
175175
}
176176

177177
if (stroke.IsInvisible() || thickness <= 0)
@@ -214,7 +214,7 @@ public override void DrawRectangle(OxyRect rect, OxyColor fill, OxyColor stroke,
214214
if (fill.IsVisible())
215215
{
216216
this.g.FillRectangle(
217-
fill.ToBrush(), (float)rect.Left, (float)rect.Top, (float)rect.Width, (float)rect.Height);
217+
this.GetCachedBrush(fill), (float)rect.Left, (float)rect.Top, (float)rect.Width, (float)rect.Height);
218218
}
219219

220220
if (stroke.IsInvisible() || thickness <= 0)
@@ -304,18 +304,18 @@ public override void DrawText(
304304
var graphicsState = this.g.Save();
305305

306306
this.g.TranslateTransform((float)p.X, (float)p.Y);
307-
307+
308308
var layoutRectangle = new RectangleF(0, 0, size.Width, size.Height);
309309
if (Math.Abs(rotate) > double.Epsilon)
310310
{
311311
this.g.RotateTransform((float)rotate);
312-
312+
313313
layoutRectangle.Height += (float)(fontSize / 18.0);
314314
}
315315

316316
this.g.TranslateTransform(dx, dy);
317317

318-
this.g.DrawString(text, font, fill.ToBrush(), layoutRectangle, this.stringFormat);
318+
this.g.DrawString(text, font, this.GetCachedBrush(fill), layoutRectangle, this.stringFormat);
319319

320320
this.g.Restore(graphicsState);
321321
}

Source/OxyPlot.WindowsForms/PlotView.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ public void ShowTracker(TrackerHitResult data)
316316

317317
this.trackerLabel.Text = data.ToString();
318318
this.trackerLabel.Top = (int)data.Position.Y - this.trackerLabel.Height;
319-
this.trackerLabel.Left = (int)data.Position.X - this.trackerLabel.Width / 2;
319+
this.trackerLabel.Left = (int)data.Position.X - (this.trackerLabel.Width / 2);
320320
this.trackerLabel.Visible = true;
321321
}
322322

@@ -503,13 +503,35 @@ protected override void OnResize(EventArgs e)
503503
this.InvalidatePlot(false);
504504
}
505505

506+
/// <summary>
507+
/// Disposes the PlotView.
508+
/// </summary>
509+
/// <param name="disposing">Whether to dispose managed resources or not.</param>
510+
protected override void Dispose(bool disposing)
511+
{
512+
bool disposed = this.IsDisposed;
513+
514+
base.Dispose(disposing);
515+
516+
if (disposed)
517+
{
518+
return;
519+
}
520+
521+
if (disposing)
522+
{
523+
this.renderContext.Dispose();
524+
}
525+
}
526+
506527
/// <summary>
507528
/// Gets the current modifier keys.
508529
/// </summary>
509530
/// <returns>A <see cref="OxyModifierKeys" /> value.</returns>
510531
private static OxyModifierKeys GetModifiers()
511532
{
512533
var modifiers = OxyModifierKeys.None;
534+
513535
// ReSharper disable once RedundantNameQualifier
514536
if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift)
515537
{

0 commit comments

Comments
 (0)