diff --git a/Base/Forms/Controls/PieChart.cs b/Base/Forms/Controls/PieChart.cs index 19d0e71..ed5b92f 100644 --- a/Base/Forms/Controls/PieChart.cs +++ b/Base/Forms/Controls/PieChart.cs @@ -6,12 +6,18 @@ public partial class PieChart : UserControl { public List<(Color, double)> Values { get; set; } + public float DpiFloat { get; private set; } + public PieChart() { SetStyle(ControlStyles.OptimizedDoubleBuffer, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.UserPaint, true); + Graphics tempG = CreateGraphics(); + DpiFloat = (tempG.DpiX + tempG.DpiY) / 2; + tempG.Dispose(); + Values = []; InitializeComponent(); } @@ -41,7 +47,7 @@ public partial class PieChart : UserControl } // Draw the outline. - Pen outlinePartsPen = new(Color.FromArgb(unchecked((int)0xFF_202020)), 3); + Pen outlinePartsPen = new(Color.FromArgb(unchecked((int)0xFF_202020)), DpiFloat * 3 / 192); current = 0; foreach ((Color, double value) item in Values) { @@ -53,7 +59,7 @@ public partial class PieChart : UserControl } // Outline - Pen outlinePen = new(Color.FromArgb(unchecked((int)0xFF_202020)), 5); + Pen outlinePen = new(Color.FromArgb(unchecked((int)0xFF_202020)), DpiFloat * 5 / 192); g.DrawEllipse(outlinePen, rect); } } diff --git a/Base/Forms/GraphColorPickerForm.cs b/Base/Forms/GraphColorPickerForm.cs index b1ec674..98147cb 100644 --- a/Base/Forms/GraphColorPickerForm.cs +++ b/Base/Forms/GraphColorPickerForm.cs @@ -37,7 +37,7 @@ public partial class GraphColorPickerForm : Form MessageLabel.Text = $"Pick a color for {able.Name}."; // Add preset buttons. - const int size = 48; + int size = (int)(graph.DpiFloat * 48 / 192); int position = 0; foreach (uint cId in Graphable.DefaultColors) { diff --git a/Base/Forms/GraphForm.cs b/Base/Forms/GraphForm.cs index 5991244..37ef874 100644 --- a/Base/Forms/GraphForm.cs +++ b/Base/Forms/GraphForm.cs @@ -14,6 +14,8 @@ public partial class GraphForm : Form public Float2 ScreenCenter { get; private set; } public Float2 Dpi { get; private set; } + public float DpiFloat { get; private set; } + public double ZoomLevel { get => _zoomLevel; @@ -57,6 +59,9 @@ public partial class GraphForm : Form Graphics tempG = CreateGraphics(); Dpi = new(tempG.DpiX, tempG.DpiY); tempG.Dispose(); + + DpiFloat = (float)((Dpi.x + Dpi.y) / 2); + ables = []; ZoomLevel = 1; initialWindowPos = Location; @@ -102,7 +107,7 @@ public partial class GraphForm : Form // Draw horizontal/vertical quarter-axis. Brush quarterBrush = new SolidBrush(QuarterAxisColor); - Pen quarterPen = new(quarterBrush, 2); + Pen quarterPen = new(quarterBrush, DpiFloat * 2 / 192); for (double x = Math.Ceiling(MinVisibleGraph.x * 4 / axisScale) * axisScale / 4; x <= Math.Floor(MaxVisibleGraph.x * 4 / axisScale) * axisScale / 4; x += axisScale / 4) { @@ -119,7 +124,7 @@ public partial class GraphForm : Form // Draw horizontal/vertical semi-axis. Brush semiBrush = new SolidBrush(SemiAxisColor); - Pen semiPen = new(semiBrush, 2); + Pen semiPen = new(semiBrush, DpiFloat * 2 / 192); for (double x = Math.Ceiling(MinVisibleGraph.x / axisScale) * axisScale; x <= Math.Floor(MaxVisibleGraph.x / axisScale) * axisScale; x += axisScale) { @@ -135,7 +140,7 @@ public partial class GraphForm : Form } Brush mainLineBrush = new SolidBrush(MainAxisColor); - Pen mainLinePen = new(mainLineBrush, 3); + Pen mainLinePen = new(mainLineBrush, DpiFloat * 3 / 192); // Draw the main axis (on top of the semi axis). Int2 startCenterY = GraphSpaceToScreenSpace(new Float2(0, MinVisibleGraph.y)), @@ -162,7 +167,8 @@ public partial class GraphForm : Form { IEnumerable lines = ables[i].GetItemsToRender(this); Brush graphBrush = new SolidBrush(ables[i].Color); - foreach (IGraphPart gp in lines) gp.Render(this, g, graphBrush); + Pen graphPen = new(graphBrush, DpiFloat * 3 / 192); + foreach (IGraphPart gp in lines) gp.Render(this, g, graphPen); } base.OnPaint(e); diff --git a/Base/Forms/ViewCacheForm.cs b/Base/Forms/ViewCacheForm.cs index 55cd1e4..72be698 100644 --- a/Base/Forms/ViewCacheForm.cs +++ b/Base/Forms/ViewCacheForm.cs @@ -32,6 +32,10 @@ public partial class ViewCacheForm : Form CachePie.Values.Add((able.Color, thisBytes)); totalBytes += thisBytes; + int buttonHeight = (int)(refForm.DpiFloat * 46 / 192), + buttonWidth = (int)(refForm.DpiFloat * 92 / 192), + buttonSpaced = (int)(refForm.DpiFloat * 98 / 192); + if (index < labelCache.Count) { Label reuseLabel = labelCache[index]; @@ -45,9 +49,9 @@ public partial class ViewCacheForm : Form Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right, AutoEllipsis = true, ForeColor = able.Color, - Location = new Point(0, labelCache.Count * 46), + Location = new Point(0, labelCache.Count * buttonHeight), Parent = SpecificCachePanel, - Size = new Size(SpecificCachePanel.Width - 98, 46), + Size = new Size(SpecificCachePanel.Width - buttonSpaced, buttonHeight), Text = $"{able.Name}: {thisBytes.FormatAsBytes()}", TextAlign = ContentAlignment.MiddleLeft, }; @@ -59,9 +63,9 @@ public partial class ViewCacheForm : Form Button newButton = new() { Anchor = AnchorStyles.Top | AnchorStyles.Right, - Location = new Point(SpecificCachePanel.Width - 92, buttonCache.Count * 46), + Location = new Point(SpecificCachePanel.Width - buttonWidth, buttonCache.Count * buttonHeight), Parent = SpecificCachePanel, - Size = new Size(92, 46), + Size = new Size(buttonWidth, buttonHeight), Text = "Clear" }; newButton.Click += (o, e) => EraseSpecificGraphable_Click(able); diff --git a/Base/IGraphPart.cs b/Base/IGraphPart.cs index 0e3c592..083ef85 100644 --- a/Base/IGraphPart.cs +++ b/Base/IGraphPart.cs @@ -4,5 +4,5 @@ namespace Graphing; public interface IGraphPart { - public void Render(in GraphForm form, in Graphics g, in Brush brush); + public void Render(in GraphForm form, in Graphics g, in Pen pen); } diff --git a/Base/Parts/GraphLine.cs b/Base/Parts/GraphLine.cs index fff70f1..7c042e1 100644 --- a/Base/Parts/GraphLine.cs +++ b/Base/Parts/GraphLine.cs @@ -18,15 +18,13 @@ public record struct GraphLine : IGraphPart this.b = b; } - public readonly void Render(in GraphForm form, in Graphics g, in Brush brush) + public readonly void Render(in GraphForm form, in Graphics g, in Pen pen) { if (!double.IsFinite(a.x) || !double.IsFinite(a.y) || !double.IsFinite(b.x) || !double.IsFinite(b.y)) return; Int2 start = form.GraphSpaceToScreenSpace(a), end = form.GraphSpaceToScreenSpace(b); - - Pen pen = new(brush, 3); g.DrawLine(pen, start, end); } } diff --git a/Base/Parts/GraphRectangle.cs b/Base/Parts/GraphRectangle.cs index a874a42..54b23fc 100644 --- a/Base/Parts/GraphRectangle.cs +++ b/Base/Parts/GraphRectangle.cs @@ -25,7 +25,7 @@ public record struct GraphRectangle : IGraphPart max = max }; - public void Render(in GraphForm form, in Graphics g, in Brush brush) + public void Render(in GraphForm form, in Graphics g, in Pen pen) { if (!double.IsFinite(max.x) || !double.IsFinite(max.y) || !double.IsFinite(min.x) || !double.IsFinite(min.y)) return; @@ -40,6 +40,6 @@ public record struct GraphRectangle : IGraphPart start.y - end.y); if (size.x == 0 || size.y == 0) return; - g.FillRectangle(brush, new Rectangle(start.x, end.y, size.x, size.y)); + g.FillRectangle(pen.Brush, new Rectangle(start.x, end.y, size.x, size.y)); } } diff --git a/Base/Parts/GraphUiCircle.cs b/Base/Parts/GraphUiCircle.cs index 28bb010..aa3fc96 100644 --- a/Base/Parts/GraphUiCircle.cs +++ b/Base/Parts/GraphUiCircle.cs @@ -18,14 +18,14 @@ public record struct GraphUiCircle : IGraphPart this.radius = radius; } - public readonly void Render(in GraphForm form, in Graphics g, in Brush brush) + public readonly void Render(in GraphForm form, in Graphics g, in Pen pen) { if (!double.IsFinite(center.x) || !double.IsFinite(center.y) || !double.IsFinite(radius) || radius == 0) return; Int2 centerPix = form.GraphSpaceToScreenSpace(center); - g.FillEllipse(brush, new Rectangle(new Point(centerPix.x - radius, - centerPix.y - radius), + g.FillEllipse(pen.Brush, new Rectangle(new Point(centerPix.x - radius, + centerPix.y - radius), new Size(radius * 2, radius * 2))); } } diff --git a/Testing/Program.cs b/Testing/Program.cs index 105bc57..b154bc8 100644 --- a/Testing/Program.cs +++ b/Testing/Program.cs @@ -10,28 +10,14 @@ internal static class Program { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - Application.SetHighDpiMode(HighDpiMode.SystemAware); + Application.SetHighDpiMode(HighDpiMode.PerMonitorV2); GraphForm graph = new("One Of The Graphing Calculators Of All Time"); - Equation equ1 = new(x => - { - // Demonstrate the caching abilities of the software. - // This extra waiting is done every time the form requires a - // calculation done. At the start, it'll be laggy, but as you - // move around and zoom in, more pieces are cached, and when - // you reset, the viewport will be a lot less laggy. - - // Remove this loop to make the equation fast again. I didn't - // slow the engine down much more with this improvement, so any - // speed decrease you might notice is likely this function. - for (int i = 0; i < 1_000_000; i++) ; - return -x * x + 2; - }); + Equation equ1 = new(x => -x * x + 2); Equation equ2 = new(x => x); Equation equ3 = new(x => -Math.Sqrt(x)); - SlopeField sf = new(2, (x, y) => (x * x - y * y) / x); - graph.Graph(equ1, equ2, equ3, sf); + graph.Graph(equ1, equ2, equ3); // You can also now view and reset caches in the UI by going to // Misc > View Caches.