Merge pull request #26 from dwilhelm/master
Scale OxyPlot elements based on DPI
This commit is contained in:
+22
@@ -310,6 +310,28 @@ namespace OxyPlot
|
||||
this.Subtitle = subtitle;
|
||||
}
|
||||
|
||||
public PlotModel(double dpiXscale, double dpiYscale)
|
||||
: this()
|
||||
{
|
||||
this.PlotMargins = new OxyThickness(this.PlotMargins.Left * dpiXscale,
|
||||
this.PlotMargins.Top * dpiYscale,
|
||||
this.PlotMargins.Right * dpiXscale,
|
||||
this.PlotMargins.Bottom * dpiYscale
|
||||
);
|
||||
this.Padding = new OxyThickness(this.Padding.Left * dpiXscale,
|
||||
this.Padding.Top * dpiYscale,
|
||||
this.Padding.Right * dpiXscale,
|
||||
this.Padding.Bottom * dpiYscale
|
||||
);
|
||||
this.TitlePadding *= dpiXscale;
|
||||
this.LegendSymbolLength *= dpiXscale;
|
||||
this.LegendSymbolMargin *= dpiXscale;
|
||||
this.LegendPadding *= dpiXscale;
|
||||
this.LegendColumnSpacing *= dpiXscale;
|
||||
this.LegendItemSpacing *= dpiXscale;
|
||||
this.LegendMargin *= dpiXscale;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The synchronization root object.
|
||||
/// </summary>
|
||||
|
||||
+30
-1
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user