Almost done. Added coordinates for selected points.
This commit is contained in:
parent
55cb7af2ac
commit
c30ced7578
@ -206,22 +206,38 @@ public partial class GraphForm : Form
|
||||
clientMousePos.Y));
|
||||
|
||||
// Draw the actual graphs.
|
||||
Pen[] graphPens = new Pen[ables.Count];
|
||||
for (int i = 0; i < ables.Count; i++)
|
||||
{
|
||||
IEnumerable<IGraphPart> lines = ables[i].GetItemsToRender(this);
|
||||
Brush graphBrush = new SolidBrush(ables[i].Color);
|
||||
Pen graphPen = new(graphBrush, DpiFloat * 3 / 192);
|
||||
graphPens[i] = graphPen;
|
||||
foreach (IGraphPart gp in lines) gp.Render(this, g, graphPen);
|
||||
}
|
||||
|
||||
// Equation selection detection.
|
||||
// This system lets you select multiple graphs, and that's cool by me.
|
||||
if (ableDrag)
|
||||
{
|
||||
Font textFont = new(Font.Name, 8, FontStyle.Bold);
|
||||
for (int i = 0; i < ables.Count; i++)
|
||||
{
|
||||
if (ables[i].ShouldSelectGraphable(this, graphMousePos, 2.5))
|
||||
{
|
||||
Float2 selectedPoint = ables[i].GetSelectedPoint(this, graphMousePos);
|
||||
GraphUiCircle select = new(selectedPoint, 8);
|
||||
select.Render(this, g, graphPen);
|
||||
|
||||
Int2 textPos = GraphSpaceToScreenSpace(select.center);
|
||||
textPos.y -= (int)(DpiFloat * 32 / 192);
|
||||
|
||||
string content = $"({selectedPoint.x:0.00}, {selectedPoint.y:0.00})";
|
||||
|
||||
SizeF textSize = g.MeasureString(content, textFont);
|
||||
g.FillRectangle(background, new Rectangle(textPos.x, textPos.y,
|
||||
(int)textSize.Width, (int)textSize.Height));
|
||||
g.DrawString(content, textFont, graphPens[i].Brush, new Point(textPos.x, textPos.y));
|
||||
select.Render(this, g, graphPens[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,9 +23,11 @@ public record struct GraphUiCircle : IGraphPart
|
||||
if (!double.IsFinite(center.x) || !double.IsFinite(center.y) ||
|
||||
!double.IsFinite(radius) || radius == 0) return;
|
||||
|
||||
int rad = (int)(form.DpiFloat * radius / 192);
|
||||
|
||||
Int2 centerPix = form.GraphSpaceToScreenSpace(center);
|
||||
g.FillEllipse(pen.Brush, new Rectangle(new Point(centerPix.x - radius,
|
||||
centerPix.y - radius),
|
||||
new Size(radius * 2, radius * 2)));
|
||||
g.FillEllipse(pen.Brush, new Rectangle(new Point(centerPix.x - rad,
|
||||
centerPix.y - rad),
|
||||
new Size(rad * 2, rad * 2)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,12 +10,12 @@ 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 possibleA = new(x => x * x * x);
|
||||
SlopeField sf = new(2, (x, y) => 1 / x);
|
||||
Equation possibleA = new(Math.Sin);
|
||||
SlopeField sf = new(2, (x, y) => Math.Cos(x));
|
||||
TangentLine tl = new(2, 2, possibleA);
|
||||
graph.Graph(possibleA, sf, tl);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user