From 6d8787cac739f07f8d28cbcafa782d1bd8f76ac4 Mon Sep 17 00:00:00 2001 From: That_One_Nerd Date: Wed, 13 Mar 2024 09:42:03 -0400 Subject: [PATCH] Ready for 1.1. Made a graph cache viewer. --- Base/Base.csproj.user | 6 + Base/Forms/Controls/PieChart.Designer.cs | 44 +++++++ Base/Forms/Controls/PieChart.cs | 59 ++++++++++ Base/Forms/Controls/PieChart.resx | 120 +++++++++++++++++++ Base/Forms/GraphForm.cs | 38 +++---- Base/Forms/ViewCacheForm.Designer.cs | 97 ++++++++++++++++ Base/Forms/ViewCacheForm.cs | 89 +++++++++++++++ Base/Forms/ViewCacheForm.resx | 139 +++++++++++++++++++++++ Base/Graphables/ColumnTable.cs | 4 +- Base/Graphables/Equation.cs | 8 +- Base/Graphables/SlopeField.cs | 16 +-- Base/Graphables/TangentLine.cs | 10 +- Base/Range2d.cs | 27 ----- Testing/Program.cs | 16 ++- 14 files changed, 602 insertions(+), 71 deletions(-) create mode 100644 Base/Forms/Controls/PieChart.Designer.cs create mode 100644 Base/Forms/Controls/PieChart.cs create mode 100644 Base/Forms/Controls/PieChart.resx create mode 100644 Base/Forms/ViewCacheForm.Designer.cs create mode 100644 Base/Forms/ViewCacheForm.cs create mode 100644 Base/Forms/ViewCacheForm.resx delete mode 100644 Base/Range2d.cs diff --git a/Base/Base.csproj.user b/Base/Base.csproj.user index f3bd93a..32278f6 100644 --- a/Base/Base.csproj.user +++ b/Base/Base.csproj.user @@ -1,6 +1,9 @@  + + UserControl + Form @@ -10,5 +13,8 @@ Form + + Form + \ No newline at end of file diff --git a/Base/Forms/Controls/PieChart.Designer.cs b/Base/Forms/Controls/PieChart.Designer.cs new file mode 100644 index 0000000..18b52e0 --- /dev/null +++ b/Base/Forms/Controls/PieChart.Designer.cs @@ -0,0 +1,44 @@ +namespace Graphing.Forms.Controls +{ + partial class PieChart + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + SuspendLayout(); + // + // PieChart + // + AutoScaleDimensions = new SizeF(13F, 32F); + AutoScaleMode = AutoScaleMode.Font; + Name = "PieChart"; + Size = new Size(500, 500); + ResumeLayout(false); + } + + #endregion + } +} diff --git a/Base/Forms/Controls/PieChart.cs b/Base/Forms/Controls/PieChart.cs new file mode 100644 index 0000000..19d0e71 --- /dev/null +++ b/Base/Forms/Controls/PieChart.cs @@ -0,0 +1,59 @@ +using System.Drawing.Drawing2D; + +namespace Graphing.Forms.Controls; + +public partial class PieChart : UserControl +{ + public List<(Color, double)> Values { get; set; } + + public PieChart() + { + SetStyle(ControlStyles.OptimizedDoubleBuffer, true); + SetStyle(ControlStyles.AllPaintingInWmPaint, true); + SetStyle(ControlStyles.UserPaint, true); + + Values = []; + InitializeComponent(); + } + + protected override void OnPaint(PaintEventArgs e) + { + Graphics g = e.Graphics; + g.SmoothingMode = SmoothingMode.HighQuality; + int size = Math.Min(Width, Height); + Rectangle rect = new(5, 5, size - 10, size - 10); + + double sum = 0; + foreach ((Color, double v) item in Values) + sum += item.v; + + // Draw them. + double current = 0; + foreach ((Color color, double value) item in Values) + { + double start = 360 * current / sum, + end = 360 * (current + item.value) / sum; + + Brush filler = new SolidBrush(item.color); + g.FillPie(filler, rect, (float)start, (float)(end - start)); + + current += item.value; + } + + // Draw the outline. + Pen outlinePartsPen = new(Color.FromArgb(unchecked((int)0xFF_202020)), 3); + current = 0; + foreach ((Color, double value) item in Values) + { + double start = 360 * current / sum, + end = 360 * (current + item.value) / sum; + g.DrawPie(outlinePartsPen, rect, (float)start, (float)(end - start)); + + current += item.value; + } + + // Outline + Pen outlinePen = new(Color.FromArgb(unchecked((int)0xFF_202020)), 5); + g.DrawEllipse(outlinePen, rect); + } +} diff --git a/Base/Forms/Controls/PieChart.resx b/Base/Forms/Controls/PieChart.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Base/Forms/Controls/PieChart.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Base/Forms/GraphForm.cs b/Base/Forms/GraphForm.cs index 3a2b587..5991244 100644 --- a/Base/Forms/GraphForm.cs +++ b/Base/Forms/GraphForm.cs @@ -7,6 +7,10 @@ namespace Graphing.Forms; public partial class GraphForm : Form { + public static readonly Color MainAxisColor = Color.Black; + public static readonly Color SemiAxisColor = Color.FromArgb(unchecked((int)0xFF_999999)); + public static readonly Color QuarterAxisColor = Color.FromArgb(unchecked((int)0xFF_E0E0E0)); + public Float2 ScreenCenter { get; private set; } public Float2 Dpi { get; private set; } @@ -97,7 +101,7 @@ public partial class GraphForm : Form double axisScale = Math.Pow(2, Math.Round(Math.Log2(ZoomLevel))); // Draw horizontal/vertical quarter-axis. - Brush quarterBrush = new SolidBrush(Color.FromArgb(unchecked((int)0xFF_E0E0E0))); + Brush quarterBrush = new SolidBrush(QuarterAxisColor); Pen quarterPen = new(quarterBrush, 2); for (double x = Math.Ceiling(MinVisibleGraph.x * 4 / axisScale) * axisScale / 4; x <= Math.Floor(MaxVisibleGraph.x * 4 / axisScale) * axisScale / 4; x += axisScale / 4) @@ -114,7 +118,7 @@ public partial class GraphForm : Form } // Draw horizontal/vertical semi-axis. - Brush semiBrush = new SolidBrush(Color.FromArgb(unchecked((int)0xFF_999999))); + Brush semiBrush = new SolidBrush(SemiAxisColor); Pen semiPen = new(semiBrush, 2); for (double x = Math.Ceiling(MinVisibleGraph.x / axisScale) * axisScale; x <= Math.Floor(MaxVisibleGraph.x / axisScale) * axisScale; x += axisScale) @@ -130,7 +134,7 @@ public partial class GraphForm : Form g.DrawLine(semiPen, startPos, endPos); } - Brush mainLineBrush = new SolidBrush(Color.Black); + Brush mainLineBrush = new SolidBrush(MainAxisColor); Pen mainLinePen = new(mainLineBrush, 3); // Draw the main axis (on top of the semi axis). @@ -251,14 +255,14 @@ public partial class GraphForm : Form colorItem.Click += (o, e) => GraphColorPickerButton_Click(able); MenuColors.DropDownItems.Add(colorItem); - if (able is Equation) + if (able is Equation equ) { ToolStripMenuItem derivativeItem = new() { ForeColor = able.Color, Text = able.Name }; - derivativeItem.Click += (o, e) => EquationComputeDerivative_Click((able as Equation)!); + derivativeItem.Click += (o, e) => EquationComputeDerivative_Click(equ); MenuEquationsDerivative.DropDownItems.Add(derivativeItem); ToolStripMenuItem integralItem = new() @@ -266,7 +270,7 @@ public partial class GraphForm : Form ForeColor = able.Color, Text = able.Name }; - integralItem.Click += (o, e) => EquationComputeIntegral_Click((able as Equation)!); + integralItem.Click += (o, e) => EquationComputeIntegral_Click(equ); MenuEquationsIntegral.DropDownItems.Add(integralItem); } } @@ -361,23 +365,13 @@ public partial class GraphForm : Form private void MenuMiscCaches_Click(object? sender, EventArgs e) { - // TODO: Replace with a form with a pie chart of the use by equation - // and the ability to reset them. - StringBuilder message = new(); - long total = 0; - foreach (Graphable able in ables) + ViewCacheForm cacheForm = new(this) { - long size = able.GetCacheBytes(); - message.AppendLine($"{able.Name}: {size.FormatAsBytes()}"); - total += size; - } + StartPosition = FormStartPosition.Manual + }; - message.AppendLine($"\nTotal: {total.FormatAsBytes()}\n\nErase cache?"); - - DialogResult result = MessageBox.Show(message.ToString(), "Graph Caches", MessageBoxButtons.YesNo, MessageBoxIcon.Information); - if (result == DialogResult.Yes) - { - foreach (Graphable able in ables) able.EraseCache(); - } + cacheForm.Location = new Point(Location.X + ClientRectangle.Width + 10, + Location.Y + (ClientRectangle.Height - cacheForm.ClientRectangle.Height) / 2); + cacheForm.Show(); } } diff --git a/Base/Forms/ViewCacheForm.Designer.cs b/Base/Forms/ViewCacheForm.Designer.cs new file mode 100644 index 0000000..c847e6b --- /dev/null +++ b/Base/Forms/ViewCacheForm.Designer.cs @@ -0,0 +1,97 @@ +namespace Graphing.Forms +{ + partial class ViewCacheForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ViewCacheForm)); + CachePie = new Controls.PieChart(); + TotalCacheText = new Label(); + EraseAllCacheButton = new Button(); + SpecificCachePanel = new Panel(); + SuspendLayout(); + // + // CachePie + // + CachePie.Location = new Point(50, 50); + CachePie.Name = "CachePie"; + CachePie.Size = new Size(450, 450); + CachePie.TabIndex = 0; + // + // TotalCacheText + // + TotalCacheText.Font = new Font("Segoe UI Semibold", 10.125F, FontStyle.Bold, GraphicsUnit.Point, 0); + TotalCacheText.Location = new Point(62, 540); + TotalCacheText.Name = "TotalCacheText"; + TotalCacheText.Size = new Size(425, 45); + TotalCacheText.TabIndex = 1; + TotalCacheText.Text = "Total Cache: Something"; + TotalCacheText.TextAlign = ContentAlignment.TopCenter; + // + // EraseAllCacheButton + // + EraseAllCacheButton.Location = new Point(200, 580); + EraseAllCacheButton.Name = "EraseAllCacheButton"; + EraseAllCacheButton.Size = new Size(150, 46); + EraseAllCacheButton.TabIndex = 2; + EraseAllCacheButton.Text = "Erase All"; + EraseAllCacheButton.UseVisualStyleBackColor = true; + EraseAllCacheButton.Click += EraseAllCacheButton_Click; + // + // SpecificCachePanel + // + SpecificCachePanel.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + SpecificCachePanel.AutoScroll = true; + SpecificCachePanel.Location = new Point(520, 12); + SpecificCachePanel.Name = "SpecificCachePanel"; + SpecificCachePanel.Size = new Size(542, 657); + SpecificCachePanel.TabIndex = 3; + // + // ViewCacheForm + // + AutoScaleDimensions = new SizeF(13F, 32F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1074, 679); + Controls.Add(SpecificCachePanel); + Controls.Add(EraseAllCacheButton); + Controls.Add(TotalCacheText); + Controls.Add(CachePie); + FormBorderStyle = FormBorderStyle.SizableToolWindow; + MinimumSize = new Size(885, 750); + Name = "ViewCacheForm"; + Text = "Graph Caches"; + ResumeLayout(false); + } + + #endregion + + private Controls.PieChart CachePie; + private Label TotalCacheText; + private Button EraseAllCacheButton; + private Panel SpecificCachePanel; + } +} \ No newline at end of file diff --git a/Base/Forms/ViewCacheForm.cs b/Base/Forms/ViewCacheForm.cs new file mode 100644 index 0000000..55cd1e4 --- /dev/null +++ b/Base/Forms/ViewCacheForm.cs @@ -0,0 +1,89 @@ +using Graphing.Extensions; + +namespace Graphing.Forms; + +public partial class ViewCacheForm : Form +{ + private readonly GraphForm refForm; + + private readonly List