From 17707409f3b462ae5566cc164cbd641b6af0e316 Mon Sep 17 00:00:00 2001 From: DominikaLos Date: Wed, 18 Dec 2024 11:24:38 +0100 Subject: [PATCH] refactor: fixed typos, renaming --- GsaGH/Components/6_Display/AssemblyResults.cs | 20 +++++------ .../Components/6_Display/Contour1dResults.cs | 20 +++++------ .../Components/6_Display/Contour2dResults.cs | 20 +++++------ .../Components/6_Display/Contour3dResults.cs | 20 +++++------ .../6_Display/ContourNodeResults.cs | 20 +++++------ GsaGH/Helpers/GH/Legend/ContourLegend.cs | 36 ++++++++++--------- GsaGH/Helpers/GH/Legend/LegendMenuBuilder.cs | 4 ++- 7 files changed, 72 insertions(+), 68 deletions(-) diff --git a/GsaGH/Components/6_Display/AssemblyResults.cs b/GsaGH/Components/6_Display/AssemblyResults.cs index 2ba969e69..25a86c95d 100644 --- a/GsaGH/Components/6_Display/AssemblyResults.cs +++ b/GsaGH/Components/6_Display/AssemblyResults.cs @@ -108,6 +108,7 @@ private enum FoldMode { "Drift Index", "Force", }); + private static readonly ContourLegendManager _contourLegendManager = ContourLegendManager.GetDefault(); private string _case = string.Empty; private double _defScale = 250; private DisplayValue _disp = DisplayValue.ResXyz; @@ -121,7 +122,6 @@ private enum FoldMode { private string _resType; private bool _slider = true; private EnvelopeMethod _envelopeType = EnvelopeMethod.Absolute; - private static readonly ContourLegendManager _contourLegendMenager = ContourLegendManager.GetDefault(); private List<(int startY, int endY, Color gradientColor)> _gradients = new List<(int startY, int endY, Color gradientColor)>(); @@ -139,7 +139,7 @@ public override void CreateAttributes() { public override void DrawViewportWires(IGH_PreviewArgs args) { base.DrawViewportWires(args); - _contourLegendMenager.Legend.DrawLegendRectangle(args, _resType, _case, _gradients); + _contourLegendManager.Legend.DrawLegendRectangle(args, _resType, _case, _gradients); } public override bool Read(GH_IReader reader) { @@ -158,7 +158,7 @@ public override bool Read(GH_IReader reader) { _forceUnit = (ForceUnit)UnitsHelper.Parse(typeof(ForceUnit), reader.GetString("force")); _momentUnit = (MomentUnit)UnitsHelper.Parse(typeof(MomentUnit), reader.GetString("moment")); - _contourLegendMenager.DeserialiseLegendState(reader); + _contourLegendManager.DeserialiseLegendState(reader); return base.Read(reader); } @@ -299,7 +299,7 @@ public override bool Write(GH_IWriter writer) { writer.SetString("moment", Moment.GetAbbreviation(_momentUnit)); writer.SetString("envelope", _envelopeType.ToString()); - _contourLegendMenager.SerialiseLegendState(writer); + _contourLegendManager.SerialiseLegendState(writer); return base.Write(writer); } @@ -314,7 +314,7 @@ protected override void AppendAdditionalComponentMenuItems(ToolStripDropDown men ToolStripMenuItem envelopeMenu = GenerateToolStripMenuItem.GetEnvelopeSubMenuItem(_envelopeType, UpdateEnvelope); menu.Items.Add(envelopeMenu); - Menu_AppendItem(menu, "Show Legend", ShowLegend, true, _contourLegendMenager.Configuration.IsVisible); + Menu_AppendItem(menu, "Show Legend", ShowLegend, true, _contourLegendManager.Configuration.IsVisible); var gradient = new GH_GradientControl(); gradient.CreateAttributes(); @@ -342,7 +342,7 @@ protected override void AppendAdditionalComponentMenuItems(ToolStripDropDown men menu.Items.Add(unitsMenu); - ToolStripMenuItem legendScaleMenu = _contourLegendMenager.CreateMenu(this, () => base.UpdateUI()); + ToolStripMenuItem legendScaleMenu = _contourLegendManager.CreateMenu(this, () => base.UpdateUI()); menu.Items.Add(legendScaleMenu); @@ -776,7 +776,7 @@ Parameters.Results.AssemblyForcesAndMoments forces } }); - int gripheight = _contourLegendMenager.Configuration.ActualHeight / ghGradient.GripCount; + int gripheight = _contourLegendManager.Configuration.ActualHeight / ghGradient.GripCount; var legendValues = new List(); var legendValuePositionsY = new List(); @@ -843,10 +843,10 @@ Parameters.Results.AssemblyForcesAndMoments forces legendValues[i] = legendValues[i].Replace(",", string.Empty); } - legendValuePositionsY.Add(_contourLegendMenager.Configuration.ActualHeight - starty + (gripheight / 2) - 2); + legendValuePositionsY.Add(_contourLegendManager.Configuration.ActualHeight - starty + (gripheight / 2) - 2); } - _contourLegendMenager.Configuration.SetTextValues(legendValues).SetValuePositionsY(legendValuePositionsY); + _contourLegendManager.Configuration.SetTextValues(legendValues).SetValuePositionsY(legendValuePositionsY); da.SetDataTree(0, resultLines); da.SetDataList(1, cs); @@ -926,7 +926,7 @@ private void ReDrawComponent() { } internal void ShowLegend(object sender, EventArgs e) { - _contourLegendMenager.Configuration.ToggleLegendVisibility(); + _contourLegendManager.Configuration.ToggleLegendVisibility(); ExpirePreview(true); } diff --git a/GsaGH/Components/6_Display/Contour1dResults.cs b/GsaGH/Components/6_Display/Contour1dResults.cs index 162b7ed2d..767d0462a 100644 --- a/GsaGH/Components/6_Display/Contour1dResults.cs +++ b/GsaGH/Components/6_Display/Contour1dResults.cs @@ -134,6 +134,7 @@ private enum FoldMode { "Footfall", "Steel Design", }); + private readonly ContourLegendManager _contourLegendManager = ContourLegendManager.GetDefault(); private string _case = string.Empty; private double _defScale = 250; private DisplayValue _disp = DisplayValue.ResXyz; @@ -149,7 +150,6 @@ private enum FoldMode { private bool _slider = true; private PressureUnit _stressUnit = DefaultUnits.StressUnitResult; private EnvelopeMethod _envelopeType = EnvelopeMethod.Absolute; - private readonly ContourLegendManager _contourLegendMenager = ContourLegendManager.GetDefault(); private List<(int startY, int endY, Color gradientColor)> _gradients = new List<(int startY, int endY, Color gradientColor)>(); @@ -167,7 +167,7 @@ public override void CreateAttributes() { public override void DrawViewportWires(IGH_PreviewArgs args) { base.DrawViewportWires(args); - _contourLegendMenager.Legend.DrawLegendRectangle(args, _resType, _case, _gradients); + _contourLegendManager.Legend.DrawLegendRectangle(args, _resType, _case, _gradients); } public override bool Read(GH_IReader reader) { @@ -195,7 +195,7 @@ public override bool Read(GH_IReader reader) { _momentUnit = (MomentUnit)UnitsHelper.Parse(typeof(MomentUnit), reader.GetString("moment")); _energyResultUnit = (EnergyUnit)UnitsHelper.Parse(typeof(EnergyUnit), reader.GetString("energy")); - _contourLegendMenager.DeserialiseLegendState(reader); + _contourLegendManager.DeserialiseLegendState(reader); return base.Read(reader); } @@ -405,7 +405,7 @@ public override bool Write(GH_IWriter writer) { writer.SetString("energy", Energy.GetAbbreviation(_energyResultUnit)); writer.SetString("envelope", _envelopeType.ToString()); - _contourLegendMenager.SerialiseLegendState(writer); + _contourLegendManager.SerialiseLegendState(writer); return base.Write(writer); } @@ -420,7 +420,7 @@ protected override void AppendAdditionalComponentMenuItems(ToolStripDropDown men ToolStripMenuItem envelopeMenu = GenerateToolStripMenuItem.GetEnvelopeSubMenuItem(_envelopeType, UpdateEnvelope); menu.Items.Add(envelopeMenu); - Menu_AppendItem(menu, "Show Legend", ShowLegend, true, _contourLegendMenager.Configuration.IsVisible); + Menu_AppendItem(menu, "Show Legend", ShowLegend, true, _contourLegendManager.Configuration.IsVisible); var gradient = new GH_GradientControl(); gradient.CreateAttributes(); @@ -456,7 +456,7 @@ protected override void AppendAdditionalComponentMenuItems(ToolStripDropDown men menu.Items.Add(unitsMenu); - ToolStripMenuItem legendScaleMenu = _contourLegendMenager.CreateMenu(this, () => base.UpdateUI()); + ToolStripMenuItem legendScaleMenu = _contourLegendManager.CreateMenu(this, () => base.UpdateUI()); menu.Items.Add(legendScaleMenu); Menu_AppendSeparator(menu); @@ -1027,7 +1027,7 @@ IEntity0dResultCache utilisation } } }); - int gripheight = _contourLegendMenager.Configuration.ActualHeight / ghGradient.GripCount; + int gripheight = _contourLegendManager.Configuration.ActualHeight / ghGradient.GripCount; var legendValues = new List(); var legendValuePositionsY = new List(); @@ -1107,10 +1107,10 @@ IEntity0dResultCache utilisation legendValues[i] = legendValues[i].Replace(",", string.Empty); } - legendValuePositionsY.Add(_contourLegendMenager.Configuration.ActualHeight - starty + (gripheight / 2) - 2); + legendValuePositionsY.Add(_contourLegendManager.Configuration.ActualHeight - starty + (gripheight / 2) - 2); } - _contourLegendMenager.Configuration.SetTextValues(legendValues).SetValuePositionsY(legendValuePositionsY); + _contourLegendManager.Configuration.SetTextValues(legendValues).SetValuePositionsY(legendValuePositionsY); da.SetDataTree(0, resultLines); da.SetDataList(1, cs); @@ -1214,7 +1214,7 @@ private void ReDrawComponent() { } internal void ShowLegend(object sender, EventArgs e) { - _contourLegendMenager.Configuration.ToggleLegendVisibility(); + _contourLegendManager.Configuration.ToggleLegendVisibility(); ExpirePreview(true); } diff --git a/GsaGH/Components/6_Display/Contour2dResults.cs b/GsaGH/Components/6_Display/Contour2dResults.cs index 4dc8eac53..555d87130 100644 --- a/GsaGH/Components/6_Display/Contour2dResults.cs +++ b/GsaGH/Components/6_Display/Contour2dResults.cs @@ -112,6 +112,7 @@ private enum FoldMode { "Stress", "Footfall", }); + private readonly ContourLegendManager _contourLegendManager = ContourLegendManager.GetDefault(); private string _case = string.Empty; private double _defScale = 250; private DisplayValue _disp = DisplayValue.ResXyz; @@ -129,7 +130,6 @@ private enum FoldMode { private bool _slider = true; private PressureUnit _stressUnitResult = DefaultUnits.StressUnitResult; private EnvelopeMethod _envelopeType = EnvelopeMethod.Absolute; - private readonly ContourLegendManager _contourLegendMenager = ContourLegendManager.GetDefault(); private List<(int startY, int endY, Color gradientColor)> _gradients = new List<(int startY, int endY, Color gradientColor)>(); @@ -148,7 +148,7 @@ public override void CreateAttributes() { public override void DrawViewportWires(IGH_PreviewArgs args) { base.DrawViewportWires(args); - _contourLegendMenager.Legend.DrawLegendRectangle(args, _resType, _case, _gradients); + _contourLegendManager.Legend.DrawLegendRectangle(args, _resType, _case, _gradients); } public override bool Read(GH_IReader reader) { @@ -172,7 +172,7 @@ public override bool Read(GH_IReader reader) { _forceUnit = (ForceUnit)UnitsHelper.Parse(typeof(ForceUnit), reader.GetString("moment")); _stressUnitResult = (PressureUnit)UnitsHelper.Parse(typeof(PressureUnit), reader.GetString("stress")); - _contourLegendMenager.DeserialiseLegendState(reader); + _contourLegendManager.DeserialiseLegendState(reader); return base.Read(reader); } @@ -392,7 +392,7 @@ public override bool Write(GH_IWriter writer) { writer.SetString("stress", Pressure.GetAbbreviation(_stressUnitResult)); writer.SetString("envelope", _envelopeType.ToString()); - _contourLegendMenager.SerialiseLegendState(writer); + _contourLegendManager.SerialiseLegendState(writer); return base.Write(writer); } @@ -407,7 +407,7 @@ protected override void AppendAdditionalComponentMenuItems(ToolStripDropDown men ToolStripMenuItem envelopeMenu = GenerateToolStripMenuItem.GetEnvelopeSubMenuItem(_envelopeType, UpdateEnvelope); menu.Items.Add(envelopeMenu); - Menu_AppendItem(menu, "Show Legend", ShowLegend, true, _contourLegendMenager.Configuration.IsVisible); + Menu_AppendItem(menu, "Show Legend", ShowLegend, true, _contourLegendManager.Configuration.IsVisible); var gradient = new GH_GradientControl(); gradient.CreateAttributes(); @@ -438,7 +438,7 @@ protected override void AppendAdditionalComponentMenuItems(ToolStripDropDown men menu.Items.Add(unitsMenu); - ToolStripMenuItem legendScaleMenu = _contourLegendMenager.CreateMenu(this, () => base.UpdateUI()); + ToolStripMenuItem legendScaleMenu = _contourLegendManager.CreateMenu(this, () => base.UpdateUI()); menu.Items.Add(legendScaleMenu); Menu_AppendSeparator(menu); @@ -861,7 +861,7 @@ IEntity0dResultSubset> nodeFootfal resultMeshes.AddRange(meshes.Values.ToList(), values.Values.ToList(), verticies.Values.ToList(), meshes.Keys.ToList()); - int gripheight = _contourLegendMenager.Configuration.ActualHeight / ghGradient.GripCount; + int gripheight = _contourLegendManager.Configuration.ActualHeight / ghGradient.GripCount; var legendValues = new List(); var legendValuePositionsY = new List(); @@ -932,10 +932,10 @@ IEntity0dResultSubset> nodeFootfal legendValues[i] = legendValues[i].Replace(",", string.Empty); } - legendValuePositionsY.Add(_contourLegendMenager.Configuration.ActualHeight - starty + (gripheight / 2) - 2); + legendValuePositionsY.Add(_contourLegendManager.Configuration.ActualHeight - starty + (gripheight / 2) - 2); } - _contourLegendMenager.Configuration.SetTextValues(legendValues).SetValuePositionsY(legendValuePositionsY); + _contourLegendManager.Configuration.SetTextValues(legendValues).SetValuePositionsY(legendValuePositionsY); da.SetData(0, resultMeshes); da.SetDataList(1, cs); @@ -1027,7 +1027,7 @@ private void ReDrawComponent() { } internal void ShowLegend(object sender, EventArgs e) { - _contourLegendMenager.Configuration.ToggleLegendVisibility(); + _contourLegendManager.Configuration.ToggleLegendVisibility(); ExpirePreview(true); } diff --git a/GsaGH/Components/6_Display/Contour3dResults.cs b/GsaGH/Components/6_Display/Contour3dResults.cs index a551069ed..a863ab3ce 100644 --- a/GsaGH/Components/6_Display/Contour3dResults.cs +++ b/GsaGH/Components/6_Display/Contour3dResults.cs @@ -85,6 +85,7 @@ private enum FoldMode { "Displacement", "Stress", }); + private readonly ContourLegendManager _contourLegendManager = ContourLegendManager.GetDefault(); private string _case = string.Empty; private double _defScale = 250; private DisplayValue _disp = DisplayValue.ResXyz; @@ -97,7 +98,6 @@ private enum FoldMode { private bool _slider = true; private PressureUnit _stressUnitResult = DefaultUnits.StressUnitResult; private EnvelopeMethod _envelopeType = EnvelopeMethod.Absolute; - private readonly ContourLegendManager _contourLegendMenager = ContourLegendManager.GetDefault(); private List<(int startY, int endY, Color gradientColor)> _gradients = new List<(int startY, int endY, Color gradientColor)>(); @@ -115,7 +115,7 @@ public override void CreateAttributes() { public override void DrawViewportWires(IGH_PreviewArgs args) { base.DrawViewportWires(args); - _contourLegendMenager.Legend.DrawLegendRectangle(args, _resType, _case, _gradients); + _contourLegendManager.Legend.DrawLegendRectangle(args, _resType, _case, _gradients); } public override bool Read(GH_IReader reader) { @@ -134,7 +134,7 @@ public override bool Read(GH_IReader reader) { _lengthResultUnit = (LengthUnit)UnitsHelper.Parse(typeof(LengthUnit), reader.GetString("length")); _stressUnitResult = (PressureUnit)UnitsHelper.Parse(typeof(PressureUnit), reader.GetString("stress")); - _contourLegendMenager.DeserialiseLegendState(reader); + _contourLegendManager.DeserialiseLegendState(reader); return base.Read(reader); } @@ -244,7 +244,7 @@ public override bool Write(GH_IWriter writer) { writer.SetString("stress", Pressure.GetAbbreviation(_stressUnitResult)); writer.SetString("envelope", _envelopeType.ToString()); - _contourLegendMenager.SerialiseLegendState(writer); + _contourLegendManager.SerialiseLegendState(writer); return base.Write(writer); } @@ -259,7 +259,7 @@ protected override void AppendAdditionalComponentMenuItems(ToolStripDropDown men ToolStripMenuItem envelopeMenu = GenerateToolStripMenuItem.GetEnvelopeSubMenuItem(_envelopeType, UpdateEnvelope); menu.Items.Add(envelopeMenu); - Menu_AppendItem(menu, "Show Legend", ShowLegend, true, _contourLegendMenager.Configuration.IsVisible); + Menu_AppendItem(menu, "Show Legend", ShowLegend, true, _contourLegendManager.Configuration.IsVisible); var gradient = new GH_GradientControl(); gradient.CreateAttributes(); @@ -279,7 +279,7 @@ protected override void AppendAdditionalComponentMenuItems(ToolStripDropDown men }); unitsMenu.ImageScaling = ToolStripItemImageScaling.SizeToFit; menu.Items.Add(unitsMenu); - ToolStripMenuItem legendScaleMenu = _contourLegendMenager.CreateMenu(this, () => base.UpdateUI()); + ToolStripMenuItem legendScaleMenu = _contourLegendManager.CreateMenu(this, () => base.UpdateUI()); menu.Items.Add(legendScaleMenu); Menu_AppendSeparator(menu); @@ -574,7 +574,7 @@ IMeshResultSubset, IStress, ResultTensor3(); var legendValuePositionsY = new List(); @@ -623,10 +623,10 @@ IMeshResultSubset, IStress, ResultTensor3 _gradients = new List<(int startY, int endY, Color gradientColor)>(); @@ -142,7 +142,7 @@ public override void CreateAttributes() { public override void DrawViewportWires(IGH_PreviewArgs args) { base.DrawViewportWires(args); - _contourLegendMenager.Legend.DrawLegendRectangle(args, _resType, _case, _gradients); + _contourLegendManager.Legend.DrawLegendRectangle(args, _resType, _case, _gradients); } public override bool Read(GH_IReader reader) { @@ -162,7 +162,7 @@ public override bool Read(GH_IReader reader) { _forceUnit = (ForceUnit)UnitsHelper.Parse(typeof(ForceUnit), reader.GetString("force")); _momentUnit = (MomentUnit)UnitsHelper.Parse(typeof(MomentUnit), reader.GetString("moment")); - _contourLegendMenager.DeserialiseLegendState(reader); + _contourLegendManager.DeserialiseLegendState(reader); return base.Read(reader); } @@ -288,7 +288,7 @@ public override bool Write(GH_IWriter writer) { writer.SetString("moment", Moment.GetAbbreviation(_momentUnit)); writer.SetString("envelope", _envelopeType.ToString()); - _contourLegendMenager.SerialiseLegendState(writer); + _contourLegendManager.SerialiseLegendState(writer); return base.Write(writer); } @@ -303,7 +303,7 @@ protected override void AppendAdditionalComponentMenuItems(ToolStripDropDown men ToolStripMenuItem envelopeMenu = GenerateToolStripMenuItem.GetEnvelopeSubMenuItem(_envelopeType, UpdateEnvelope); menu.Items.Add(envelopeMenu); - Menu_AppendItem(menu, "Show Legend", ShowLegend, true, _contourLegendMenager.Configuration.IsVisible); + Menu_AppendItem(menu, "Show Legend", ShowLegend, true, _contourLegendManager.Configuration.IsVisible); var gradient = new GH_GradientControl(); gradient.CreateAttributes(); @@ -331,7 +331,7 @@ protected override void AppendAdditionalComponentMenuItems(ToolStripDropDown men menu.Items.Add(unitsMenu); - ToolStripMenuItem legendScaleMenu = _contourLegendMenager.CreateMenu(this, () => base.UpdateUI()); + ToolStripMenuItem legendScaleMenu = _contourLegendManager.CreateMenu(this, () => base.UpdateUI()); menu.Items.Add(legendScaleMenu); Menu_AppendSeparator(menu); @@ -764,7 +764,7 @@ IEntity0dResultSubset> springF pts[kvp.Key] = new PointResultGoo(pt, t, valcol, size, kvp.Key); }); - int gripheight = _contourLegendMenager.Configuration.ActualHeight / ghGradient.GripCount; + int gripheight = _contourLegendManager.Configuration.ActualHeight / ghGradient.GripCount; var legendValues = new List(); var _legendValuePositionsY = new List(); @@ -827,10 +827,10 @@ Color gradientcolour legendValues[i] = legendValues[i].Replace(",", string.Empty); // remove thousand separator } - _legendValuePositionsY.Add(_contourLegendMenager.Configuration.ActualHeight - starty + (gripheight / 2) - 2); + _legendValuePositionsY.Add(_contourLegendManager.Configuration.ActualHeight - starty + (gripheight / 2) - 2); } - _contourLegendMenager.Configuration.SetTextValues(legendValues).SetValuePositionsY(_legendValuePositionsY); + _contourLegendManager.Configuration.SetTextValues(legendValues).SetValuePositionsY(_legendValuePositionsY); da.SetDataList(0, pts.OrderBy(x => x.Key).Select(y => y.Value).ToList()); da.SetDataList(1, cs); @@ -910,7 +910,7 @@ private void ReDrawComponent() { } internal void ShowLegend(object sender, EventArgs e) { - _contourLegendMenager.Configuration.ToggleLegendVisibility(); + _contourLegendManager.Configuration.ToggleLegendVisibility(); ExpirePreview(true); } diff --git a/GsaGH/Helpers/GH/Legend/ContourLegend.cs b/GsaGH/Helpers/GH/Legend/ContourLegend.cs index 6f1688ec4..0451857a9 100644 --- a/GsaGH/Helpers/GH/Legend/ContourLegend.cs +++ b/GsaGH/Helpers/GH/Legend/ContourLegend.cs @@ -27,7 +27,7 @@ public int BitmapWidth { private int _width = 15; public int ActualBitmapWidth => (int)(BitmapWidth * _configuration.Scale); private int _leftBitmapEdge; - private int _textHeight; + private int _actualTextHeight; internal bool IsInvalidConfiguration = false; //only for tests public ContourLegend(ContourLegendConfiguration configuration, int bitmapInitialWidth = 15) { @@ -50,7 +50,7 @@ public void DrawLegendRectangle( // Step 1: Apply all gradients to the bitmap foreach ((int startY, int endY, Color gradientColor) in gradients) { - DrawGradientLegend(startY, endY, gradientColor); + DrawGradient(startY, endY, gradientColor); } //Step2 Draw other elements of the legend @@ -60,7 +60,7 @@ public void DrawLegendRectangle( DrawBottomText(args, bottomText); } - private void DrawGradientLegend(int startY, int endY, Color gradientColor) { + private void DrawGradient(int startY, int endY, Color gradientColor) { if (startY < 0 || endY > Bitmap.Height || startY >= endY) { throw new ArgumentOutOfRangeException(nameof(startY), "Invalid start or end positions for the gradient."); } @@ -74,55 +74,57 @@ private void DrawGradientLegend(int startY, int endY, Color gradientColor) { private void DrawBitmap(IGH_PreviewArgs args) { const int TopOffset = 20; - int topPosition = CalculateScaledOffset(TopOffset); + int topPosition = GetScaledValue(TopOffset); args.Display.DrawBitmap(new DisplayBitmap(Bitmap), _leftBitmapEdge, topPosition); } private void DrawTitle(IGH_PreviewArgs args, string title) { const int TopOffset = 7; - int topPosition = CalculateScaledOffset(TopOffset); + int topPosition = GetScaledValue(TopOffset); - args.Display.Draw2dText(title, Color.Black, new Point2d(_leftBitmapEdge, topPosition), false, _textHeight); + args.Display.Draw2dText(title, Color.Black, new Point2d(_leftBitmapEdge, topPosition), false, _actualTextHeight); } private void DrawValues(IGH_PreviewArgs args) { const int LeftOffset = 25; - int leftEdge = _leftBitmapEdge + CalculateScaledOffset(LeftOffset); + int leftEdge = _leftBitmapEdge + GetScaledValue(LeftOffset); var zippedLists = _configuration.Values.Zip(_configuration.ValuePositionsY, (value, positionY) => new { value, positionY, }); foreach (var pair in zippedLists) { - args.Display.Draw2dText(pair.value, Color.Black, new Point2d(leftEdge, pair.positionY), false, _textHeight); + args.Display.Draw2dText(pair.value, Color.Black, new Point2d(leftEdge, pair.positionY), false, + _actualTextHeight); } } private void DrawBottomText(IGH_PreviewArgs args, string bottomText) { const int BottomOffset = 145; const int ExtraOffset = 10; - int rectangularWidth = _configuration.ActualWidth - CalculateScaledOffset(ExtraOffset); - int topPosition = CalculateScaledOffset(BottomOffset); + int textMaxWidth = _configuration.ActualWidth - GetScaledValue(ExtraOffset); + int topPosition = GetScaledValue(BottomOffset); - string wrappedText = WrapText(bottomText, rectangularWidth); - args.Display.Draw2dText(wrappedText, Color.Black, new Point2d(_leftBitmapEdge, topPosition), false, _textHeight); + string wrappedText = WrapText(bottomText, textMaxWidth); + args.Display.Draw2dText(wrappedText, Color.Black, new Point2d(_leftBitmapEdge, topPosition), false, + _actualTextHeight); } private void InitializeDimensions(int viewportEdge) { - _textHeight = GetFont().Height; + _actualTextHeight = GetScaledSystemFont().Height; _leftBitmapEdge = viewportEdge - _configuration.ActualWidth; Bitmap = new Bitmap(ActualBitmapWidth, _configuration.ActualHeight); } - private string WrapText(string bottomText, int width) { - return TextWrapper.WrapText(bottomText, width, GetFont()); + private string WrapText(string bottomText, int maxTextWidth) { + return TextWrapper.WrapText(bottomText, maxTextWidth, GetScaledSystemFont()); } - private int CalculateScaledOffset(int value) { + private int GetScaledValue(int value) { return (int)(value * _configuration.Scale); } - private Font GetFont() { + private Font GetScaledSystemFont() { Font systemFont = SystemFonts.DefaultFont; float fontSize = (float)(systemFont.Size * _configuration.Scale); return new Font(systemFont.FontFamily, fontSize); diff --git a/GsaGH/Helpers/GH/Legend/LegendMenuBuilder.cs b/GsaGH/Helpers/GH/Legend/LegendMenuBuilder.cs index 6be216941..995d9e2a5 100644 --- a/GsaGH/Helpers/GH/Legend/LegendMenuBuilder.cs +++ b/GsaGH/Helpers/GH/Legend/LegendMenuBuilder.cs @@ -29,7 +29,9 @@ public ToolStripMenuItem CreateLegendToolStripMenuItem( ImageScaling = ToolStripItemImageScaling.SizeToFit, }; - var menuControl = new GH_MenuCustomControl(legendScaleMenuItem.DropDown, legendScaleTextBox.Control, true, 200); + var menuControl + = new GH_MenuCustomControl(legendScaleMenuItem.DropDown, legendScaleTextBox.Control, true, + 200); // needed! don't remove legendScaleMenuItem.DropDownItems[1].MouseUp += (s, e) => { UpdateLegendScale(component, updateUI, setLegendScaleDelegate);