Scale OxyPlot elements based on DPI

This commit is contained in:
David Wilhelm
2018-01-01 14:12:45 -08:00
parent 10e4975c6d
commit 5ded4049c4
2 changed files with 52 additions and 1 deletions
+30 -1
View File
@@ -35,11 +35,16 @@ namespace OpenHardwareMonitor.GUI {
private UserOption stackedAxes;
private DateTime now;
private float dpiX;
private float dpiY;
private double dpiXscale = 1;
private double dpiYscale = 1;
public PlotPanel(PersistentSettings settings, UnitManager unitManager) {
this.settings = settings;
this.unitManager = unitManager;
this.SetDPI();
this.model = CreatePlotModel();
this.plot = new Plot();
@@ -168,7 +173,7 @@ namespace OpenHardwareMonitor.GUI {
axes.Add(type, axis);
}
var model = new PlotModel();
var model = new PlotModel(this.dpiXscale, this.dpiYscale);
model.Axes.Add(timeAxis);
foreach (var axis in axes.Values)
model.Axes.Add(axis);
@@ -178,6 +183,30 @@ namespace OpenHardwareMonitor.GUI {
return model;
}
private void SetDPI() {
// https://msdn.microsoft.com/en-us/library/windows/desktop/dn469266(v=vs.85).aspx
const int _default_dpi = 96;
Graphics g = this.CreateGraphics();
try
{
this.dpiX = g.DpiX;
this.dpiY = g.DpiY;
}
finally
{
g.Dispose();
}
if (dpiX > 0)
{
this.dpiXscale = dpiX / _default_dpi;
}
if (dpiY > 0)
{
this.dpiYscale = dpiY / _default_dpi;
}
}
public void SetSensors(List<ISensor> sensors,
IDictionary<ISensor, Color> colors) {
this.model.Series.Clear();