diff --git a/GsaGH/Components/6_Display/AssemblyResults.cs b/GsaGH/Components/6_Display/AssemblyResults.cs index 25a86c95d..07904a9f7 100644 --- a/GsaGH/Components/6_Display/AssemblyResults.cs +++ b/GsaGH/Components/6_Display/AssemblyResults.cs @@ -776,7 +776,7 @@ Parameters.Results.AssemblyForcesAndMoments forces } }); - int gripheight = _contourLegendManager.Configuration.ActualHeight / ghGradient.GripCount; + int gripHeight = _contourLegendManager.Configuration.ActualHeight / ghGradient.GripCount; var legendValues = new List(); var legendValuePositionsY = new List(); @@ -793,12 +793,12 @@ Parameters.Results.AssemblyForcesAndMoments forces t = Math.Round(t, significantDigits); } - Color gradientcolour = ghGradient.ColourAt((2 * (double)i / ((double)ghGradient.GripCount - 1)) - 1); - cs.Add(gradientcolour); + Color gradientColor = ghGradient.ColourAt((2 * (double)i / ((double)ghGradient.GripCount - 1)) - 1); + cs.Add(gradientColor); - int starty = i * gripheight; - int endy = starty + gripheight; - _gradients.Add((starty, endy, gradientcolour)); + int startY = i * gripHeight; + int endY = startY + gripHeight; + _gradients.Add((startY, endY, gradientColor)); switch (_mode) { case FoldMode.Displacement when (int)_disp < 4: @@ -843,7 +843,7 @@ Parameters.Results.AssemblyForcesAndMoments forces legendValues[i] = legendValues[i].Replace(",", string.Empty); } - legendValuePositionsY.Add(_contourLegendManager.Configuration.ActualHeight - starty + (gripheight / 2) - 2); + legendValuePositionsY.Add(_contourLegendManager.Configuration.ActualHeight - startY + (gripHeight / 2) - 2); } _contourLegendManager.Configuration.SetTextValues(legendValues).SetValuePositionsY(legendValuePositionsY); diff --git a/GsaGH/Components/6_Display/Contour1dResults.cs b/GsaGH/Components/6_Display/Contour1dResults.cs index 767d0462a..2be0c39be 100644 --- a/GsaGH/Components/6_Display/Contour1dResults.cs +++ b/GsaGH/Components/6_Display/Contour1dResults.cs @@ -1027,7 +1027,7 @@ IEntity0dResultCache utilisation } } }); - int gripheight = _contourLegendManager.Configuration.ActualHeight / ghGradient.GripCount; + int gripHeight = _contourLegendManager.Configuration.ActualHeight / ghGradient.GripCount; var legendValues = new List(); var legendValuePositionsY = new List(); @@ -1044,12 +1044,12 @@ IEntity0dResultCache utilisation t = Math.Round(t, significantDigits); } - Color gradientcolour = ghGradient.ColourAt((2 * (double)i / ((double)ghGradient.GripCount - 1)) - 1); - cs.Add(gradientcolour); + Color gradientColor = ghGradient.ColourAt((2 * (double)i / ((double)ghGradient.GripCount - 1)) - 1); + cs.Add(gradientColor); - int starty = i * gripheight; - int endy = starty + gripheight; - _gradients.Add((starty, endy, gradientcolour)); + int startY = i * gripHeight; + int endY = startY + gripHeight; + _gradients.Add((startY, endY, gradientColor)); switch (_mode) { case FoldMode.Displacement when (int)_disp < 4: @@ -1107,7 +1107,7 @@ IEntity0dResultCache utilisation legendValues[i] = legendValues[i].Replace(",", string.Empty); } - legendValuePositionsY.Add(_contourLegendManager.Configuration.ActualHeight - starty + (gripheight / 2) - 2); + legendValuePositionsY.Add(_contourLegendManager.Configuration.ActualHeight - startY + (gripHeight / 2) - 2); } _contourLegendManager.Configuration.SetTextValues(legendValues).SetValuePositionsY(legendValuePositionsY); diff --git a/GsaGH/Components/6_Display/Contour2dResults.cs b/GsaGH/Components/6_Display/Contour2dResults.cs index 555d87130..d881ed894 100644 --- a/GsaGH/Components/6_Display/Contour2dResults.cs +++ b/GsaGH/Components/6_Display/Contour2dResults.cs @@ -861,7 +861,7 @@ IEntity0dResultSubset> nodeFootfal resultMeshes.AddRange(meshes.Values.ToList(), values.Values.ToList(), verticies.Values.ToList(), meshes.Keys.ToList()); - int gripheight = _contourLegendManager.Configuration.ActualHeight / ghGradient.GripCount; + int gripHeight = _contourLegendManager.Configuration.ActualHeight / ghGradient.GripCount; var legendValues = new List(); var legendValuePositionsY = new List(); @@ -878,12 +878,12 @@ IEntity0dResultSubset> nodeFootfal t = Math.Round(t, significantDigits); } - Color gradientcolour = ghGradient.ColourAt((2 * (double)i / ((double)ghGradient.GripCount - 1)) - 1); - cs.Add(gradientcolour); + Color gradientColor = ghGradient.ColourAt((2 * (double)i / ((double)ghGradient.GripCount - 1)) - 1); + cs.Add(gradientColor); - int starty = i * gripheight; - int endy = starty + gripheight; - _gradients.Add((starty, endy, gradientcolour)); + int startY = i * gripHeight; + int endY = startY + gripHeight; + _gradients.Add((startY, endY, gradientColor)); switch (_mode) { case FoldMode.Displacement when (int)_disp < 4: { @@ -932,7 +932,7 @@ IEntity0dResultSubset> nodeFootfal legendValues[i] = legendValues[i].Replace(",", string.Empty); } - legendValuePositionsY.Add(_contourLegendManager.Configuration.ActualHeight - starty + (gripheight / 2) - 2); + legendValuePositionsY.Add(_contourLegendManager.Configuration.ActualHeight - startY + (gripHeight / 2) - 2); } _contourLegendManager.Configuration.SetTextValues(legendValues).SetValuePositionsY(legendValuePositionsY); diff --git a/GsaGH/Components/6_Display/Contour3dResults.cs b/GsaGH/Components/6_Display/Contour3dResults.cs index a863ab3ce..f94392f99 100644 --- a/GsaGH/Components/6_Display/Contour3dResults.cs +++ b/GsaGH/Components/6_Display/Contour3dResults.cs @@ -574,7 +574,7 @@ IMeshResultSubset, IStress, ResultTensor3(); var legendValuePositionsY = new List(); @@ -591,12 +591,12 @@ IMeshResultSubset, IStress, ResultTensor3, IStress, ResultTensor3> springF pts[kvp.Key] = new PointResultGoo(pt, t, valcol, size, kvp.Key); }); - int gripheight = _contourLegendManager.Configuration.ActualHeight / ghGradient.GripCount; + int gripHeight = _contourLegendManager.Configuration.ActualHeight / ghGradient.GripCount; var legendValues = new List(); var _legendValuePositionsY = new List(); @@ -781,13 +781,12 @@ IEntity0dResultSubset> springF t = Math.Round(t, significantDigits); } - Color gradientcolour - = ghGradient.ColourAt((2 * (double)i / ((double)ghGradient.GripCount - 1)) - 1); - cs.Add(gradientcolour); + Color gradientColor = ghGradient.ColourAt((2 * (double)i / ((double)ghGradient.GripCount - 1)) - 1); + cs.Add(gradientColor); - int starty = i * gripheight; - int endy = starty + gripheight; - _gradients.Add((starty, endy, gradientcolour)); + int startY = i * gripHeight; + int endY = startY + gripHeight; + _gradients.Add((startY, endY, gradientColor)); switch (_mode) { case FoldMode.Displacement when (int)_disp < 4: @@ -827,7 +826,7 @@ Color gradientcolour legendValues[i] = legendValues[i].Replace(",", string.Empty); // remove thousand separator } - _legendValuePositionsY.Add(_contourLegendManager.Configuration.ActualHeight - starty + (gripheight / 2) - 2); + _legendValuePositionsY.Add(_contourLegendManager.Configuration.ActualHeight - startY + (gripHeight / 2) - 2); } _contourLegendManager.Configuration.SetTextValues(legendValues).SetValuePositionsY(_legendValuePositionsY); diff --git a/GsaGH/Helpers/GH/Legend/ContourLegend.cs b/GsaGH/Helpers/GH/Legend/ContourLegend.cs index 0451857a9..7ff3c50b2 100644 --- a/GsaGH/Helpers/GH/Legend/ContourLegend.cs +++ b/GsaGH/Helpers/GH/Legend/ContourLegend.cs @@ -15,7 +15,7 @@ public int BitmapWidth { get => _width; set { if (value <= 0) { - throw new ArgumentOutOfRangeException(nameof(_width), "Width must be greater than zero."); + throw new ArgumentOutOfRangeException(nameof(BitmapWidth), "Width must be greater than zero."); } _width = value; diff --git a/GsaGH/Helpers/GH/Legend/ContourLegendConfiguration.cs b/GsaGH/Helpers/GH/Legend/ContourLegendConfiguration.cs index 91036aa8c..9e2572dea 100644 --- a/GsaGH/Helpers/GH/Legend/ContourLegendConfiguration.cs +++ b/GsaGH/Helpers/GH/Legend/ContourLegendConfiguration.cs @@ -29,7 +29,7 @@ public double Scale { get => _scale; set { if (value <= 0) { - throw new ArgumentOutOfRangeException(nameof(_scale), "Scale must be greater than zero."); + throw new ArgumentOutOfRangeException(nameof(Scale), "Scale must be greater than zero."); } _scale = value; @@ -39,7 +39,7 @@ public int Width { get => _width; set { if (value <= 0) { - throw new ArgumentOutOfRangeException(nameof(_width), "Width must be greater than zero."); + throw new ArgumentOutOfRangeException(nameof(Width), "Width must be greater than zero."); } _width = value; @@ -49,7 +49,7 @@ public int Height { get => _height; set { if (value <= 0) { - throw new ArgumentOutOfRangeException(nameof(_height), "Height must be greater than zero."); + throw new ArgumentOutOfRangeException(nameof(Height), "Height must be greater than zero."); } _height = value; diff --git a/GsaGH/Helpers/GH/Legend/LegendMenuBuilder.cs b/GsaGH/Helpers/GH/Legend/LegendMenuBuilder.cs index 995d9e2a5..6be216941 100644 --- a/GsaGH/Helpers/GH/Legend/LegendMenuBuilder.cs +++ b/GsaGH/Helpers/GH/Legend/LegendMenuBuilder.cs @@ -29,9 +29,7 @@ public ToolStripMenuItem CreateLegendToolStripMenuItem( ImageScaling = ToolStripItemImageScaling.SizeToFit, }; - var menuControl - = new GH_MenuCustomControl(legendScaleMenuItem.DropDown, legendScaleTextBox.Control, true, - 200); // needed! don't remove + var menuControl = new GH_MenuCustomControl(legendScaleMenuItem.DropDown, legendScaleTextBox.Control, true, 200); legendScaleMenuItem.DropDownItems[1].MouseUp += (s, e) => { UpdateLegendScale(component, updateUI, setLegendScaleDelegate); diff --git a/GsaGH/Helpers/GH/TextWrapper.cs b/GsaGH/Helpers/GH/TextWrapper.cs index 5ede0345a..3682a89f1 100644 --- a/GsaGH/Helpers/GH/TextWrapper.cs +++ b/GsaGH/Helpers/GH/TextWrapper.cs @@ -4,6 +4,9 @@ namespace GsaGH.Helpers.GH { public static class TextWrapper { + private static Bitmap _bitmap = new Bitmap(1, 1); + private static System.Drawing.Graphics _graphics = System.Drawing.Graphics.FromImage(_bitmap); + /// /// Wraps the given text to fit within the specified maximum width. /// @@ -17,10 +20,10 @@ public static string WrapText(string text, int maxWidth, Font font) { } string[] words = GetTextToWrap(text, out List lines); - string currentLine = ""; + string currentLine = string.Empty; foreach (string word in words) { string testLine = string.IsNullOrEmpty(currentLine) ? word : $"{currentLine} {word}"; - float testLineWidth = CalculateTextWidth(testLine, font, maxWidth); + float testLineWidth = CalculateTextWidth(testLine, font); if (testLineWidth > maxWidth) { lines.Add(currentLine); @@ -52,16 +55,8 @@ private static string[] GetTextToWrap(string text, out List lines) { return textToWrap.Split(' '); } - /// - /// Gets the width of the given text from the cache or measures and caches it. - /// - /// The text to measure. - /// Font used for rendering text - /// Maximum possible width for text - /// The width of the text in pixels. - private static float CalculateTextWidth(string text, Font font, int maxWidth) { - var graphics = System.Drawing.Graphics.FromImage(new Bitmap(maxWidth, 1)); //we care only about width - return graphics.MeasureString(text, font).Width; + private static float CalculateTextWidth(string text, Font font) { + return _graphics.MeasureString(text, font).Width; } } }