More zoom UI progress.

This commit is contained in:
That_One_Nerd 2024-04-20 09:46:23 -04:00
parent a6f7279b97
commit ed4ce2bbeb
4 changed files with 167 additions and 32 deletions

View File

@ -47,23 +47,22 @@ namespace Graphing.Forms
MenuOperationsTranslate = new ToolStripMenuItem();
MenuConvert = new ToolStripMenuItem();
MenuConvertEquation = new ToolStripMenuItem();
MenuConvertSlopeField = new ToolStripMenuItem();
MenuMisc = new ToolStripMenuItem();
MenuMiscCaches = new ToolStripMenuItem();
MiscMenuPreload = new ToolStripMenuItem();
MenuConvertSlopeField = new ToolStripMenuItem();
GraphMenu.SuspendLayout();
SuspendLayout();
//
// ResetViewportButton
//
ResetViewportButton.Anchor = AnchorStyles.Top | AnchorStyles.Right;
ResetViewportButton.Font = new Font("Segoe UI Emoji", 13.875F, FontStyle.Regular, GraphicsUnit.Point, 0);
ResetViewportButton.Font = new Font("Segoe UI Emoji", 12F, FontStyle.Regular, GraphicsUnit.Point, 0);
ResetViewportButton.Location = new Point(1373, 43);
ResetViewportButton.Name = "ResetViewportButton";
ResetViewportButton.Size = new Size(64, 64);
ResetViewportButton.TabIndex = 0;
ResetViewportButton.Text = "⌂";
ResetViewportButton.TextAlign = ContentAlignment.TopRight;
ResetViewportButton.Text = "🏠";
ResetViewportButton.UseVisualStyleBackColor = true;
ResetViewportButton.Click += ResetViewportButton_Click;
//
@ -73,7 +72,7 @@ namespace Graphing.Forms
GraphMenu.Items.AddRange(new ToolStripItem[] { MenuViewport, MenuElements, MenuOperations, MenuConvert, MenuMisc });
GraphMenu.Location = new Point(0, 0);
GraphMenu.Name = "GraphMenu";
GraphMenu.Size = new Size(1449, 42);
GraphMenu.Size = new Size(1449, 40);
GraphMenu.TabIndex = 1;
GraphMenu.Text = "menuStrip1";
//
@ -81,7 +80,7 @@ namespace Graphing.Forms
//
MenuViewport.DropDownItems.AddRange(new ToolStripItem[] { ButtonViewportSetZoom, ButtonViewportSetCenter, ButtonViewportReset, ButtonViewportResetWindow });
MenuViewport.Name = "MenuViewport";
MenuViewport.Size = new Size(129, 38);
MenuViewport.Size = new Size(129, 36);
MenuViewport.Text = "Viewport";
//
// ButtonViewportSetZoom
@ -116,7 +115,7 @@ namespace Graphing.Forms
//
MenuElements.DropDownItems.AddRange(new ToolStripItem[] { MenuElementsColors, MenuElementsRemove });
MenuElements.Name = "MenuElements";
MenuElements.Size = new Size(131, 38);
MenuElements.Size = new Size(131, 36);
MenuElements.Text = "Elements";
//
// MenuElementsColors
@ -135,7 +134,7 @@ namespace Graphing.Forms
//
MenuOperations.DropDownItems.AddRange(new ToolStripItem[] { MenuOperationsDerivative, MenuOperationsIntegral, MenuOperationsTranslate });
MenuOperations.Name = "MenuOperations";
MenuOperations.Size = new Size(151, 38);
MenuOperations.Size = new Size(151, 36);
MenuOperations.Text = "Operations";
//
// MenuOperationsDerivative
@ -160,20 +159,26 @@ namespace Graphing.Forms
//
MenuConvert.DropDownItems.AddRange(new ToolStripItem[] { MenuConvertEquation, MenuConvertSlopeField });
MenuConvert.Name = "MenuConvert";
MenuConvert.Size = new Size(118, 38);
MenuConvert.Size = new Size(118, 36);
MenuConvert.Text = "Convert";
//
// MenuConvertEquation
//
MenuConvertEquation.Name = "MenuConvertEquation";
MenuConvertEquation.Size = new Size(359, 44);
MenuConvertEquation.Size = new Size(297, 44);
MenuConvertEquation.Text = "To Equation";
//
// MenuConvertSlopeField
//
MenuConvertSlopeField.Name = "MenuConvertSlopeField";
MenuConvertSlopeField.Size = new Size(297, 44);
MenuConvertSlopeField.Text = "To Slope Field";
//
// MenuMisc
//
MenuMisc.DropDownItems.AddRange(new ToolStripItem[] { MenuMiscCaches, MiscMenuPreload });
MenuMisc.Name = "MenuMisc";
MenuMisc.Size = new Size(83, 38);
MenuMisc.Size = new Size(83, 36);
MenuMisc.Text = "Misc";
//
// MenuMiscCaches
@ -190,12 +195,6 @@ namespace Graphing.Forms
MiscMenuPreload.Text = "Preload Cache";
MiscMenuPreload.Click += MiscMenuPreload_Click;
//
// MenuConvertSlopeField
//
MenuConvertSlopeField.Name = "MenuConvertSlopeField";
MenuConvertSlopeField.Size = new Size(359, 44);
MenuConvertSlopeField.Text = "To Slope Field";
//
// GraphForm
//
AutoScaleDimensions = new SizeF(13F, 32F);

View File

@ -41,6 +41,29 @@ public partial class GraphForm : Form
}
private Float2 _zoomLevel;
public bool ViewportLocked
{
get => _viewportLocked;
set
{
if (value)
{
FormBorderStyle = FormBorderStyle.FixedSingle;
ResetViewportButton.Text = "🔒";
}
else
{
FormBorderStyle = FormBorderStyle.Sizable;
ResetViewportButton.Text = "🏠";
}
MaximizeBox = !value;
ResetViewportButton.Enabled = !value;
_viewportLocked = value;
}
}
private bool _viewportLocked;
private readonly Point initialWindowPos;
private readonly Size initialWindowSize;
@ -318,7 +341,7 @@ public partial class GraphForm : Form
if (selectState == SelectionState.GraphSelect) Invalidate(false);
}
if (selectState == SelectionState.None)
if (selectState == SelectionState.None && !ViewportLocked)
{
selectState = SelectionState.ViewportDrag;
initialMouseLocation = new Int2(Cursor.Position.X, Cursor.Position.Y);
@ -327,7 +350,8 @@ public partial class GraphForm : Form
}
protected override void OnMouseUp(MouseEventArgs e)
{
if (selectState == SelectionState.ViewportDrag)
if (selectState == SelectionState.None) return;
else if (selectState == SelectionState.ViewportDrag)
{
Int2 pixelDiff = new(initialMouseLocation.x - Cursor.Position.X,
initialMouseLocation.y - Cursor.Position.Y);
@ -365,7 +389,8 @@ public partial class GraphForm : Form
}
protected override void OnMouseMove(MouseEventArgs e)
{
if (selectState == SelectionState.ViewportDrag)
if (selectState == SelectionState.None) return;
else if (selectState == SelectionState.ViewportDrag)
{
Int2 pixelDiff = new(initialMouseLocation.x - Cursor.Position.X,
initialMouseLocation.y - Cursor.Position.Y);
@ -384,6 +409,8 @@ public partial class GraphForm : Form
}
protected override void OnMouseWheel(MouseEventArgs e)
{
if (ViewportLocked) return;
Float2 newZoom = ZoomLevel;
newZoom.x *= 1 - e.Delta * 0.00075; // Zoom factor.
newZoom.y *= 1 - e.Delta * 0.00075;

View File

@ -32,13 +32,20 @@
MatchAspectButton = new System.Windows.Forms.Button();
ResetButton = new System.Windows.Forms.Button();
NormalizeButton = new System.Windows.Forms.Button();
MinBoxX = new System.Windows.Forms.TextBox();
TextX = new System.Windows.Forms.Label();
MaxBoxX = new System.Windows.Forms.TextBox();
MaxBoxY = new System.Windows.Forms.TextBox();
TextY = new System.Windows.Forms.Label();
MinBoxY = new System.Windows.Forms.TextBox();
ViewportLock = new System.Windows.Forms.CheckBox();
SuspendLayout();
//
// EnableBoxSelect
//
EnableBoxSelect.Location = new System.Drawing.Point(12, 12);
EnableBoxSelect.Name = "EnableBoxSelect";
EnableBoxSelect.Size = new System.Drawing.Size(150, 46);
EnableBoxSelect.Size = new System.Drawing.Size(187, 46);
EnableBoxSelect.TabIndex = 0;
EnableBoxSelect.Text = "Box Select";
EnableBoxSelect.UseVisualStyleBackColor = true;
@ -46,7 +53,7 @@
//
// MatchAspectButton
//
MatchAspectButton.Location = new System.Drawing.Point(168, 12);
MatchAspectButton.Location = new System.Drawing.Point(12, 64);
MatchAspectButton.Name = "MatchAspectButton";
MatchAspectButton.Size = new System.Drawing.Size(187, 46);
MatchAspectButton.TabIndex = 1;
@ -56,9 +63,9 @@
//
// ResetButton
//
ResetButton.Location = new System.Drawing.Point(517, 12);
ResetButton.Location = new System.Drawing.Point(12, 168);
ResetButton.Name = "ResetButton";
ResetButton.Size = new System.Drawing.Size(150, 46);
ResetButton.Size = new System.Drawing.Size(187, 46);
ResetButton.TabIndex = 2;
ResetButton.Text = "Reset";
ResetButton.UseVisualStyleBackColor = true;
@ -66,19 +73,89 @@
//
// NormalizeButton
//
NormalizeButton.Location = new System.Drawing.Point(361, 12);
NormalizeButton.Location = new System.Drawing.Point(12, 116);
NormalizeButton.Name = "NormalizeButton";
NormalizeButton.Size = new System.Drawing.Size(150, 46);
NormalizeButton.Size = new System.Drawing.Size(187, 46);
NormalizeButton.TabIndex = 3;
NormalizeButton.Text = "Normalize";
NormalizeButton.UseVisualStyleBackColor = true;
NormalizeButton.Click += NormalizeButton_Click;
//
// MinBoxX
//
MinBoxX.Location = new System.Drawing.Point(227, 49);
MinBoxX.Margin = new System.Windows.Forms.Padding(25, 3, 0, 3);
MinBoxX.Name = "MinBoxX";
MinBoxX.Size = new System.Drawing.Size(108, 39);
MinBoxX.TabIndex = 4;
//
// TextX
//
TextX.Location = new System.Drawing.Point(335, 49);
TextX.Margin = new System.Windows.Forms.Padding(0);
TextX.Name = "TextX";
TextX.Size = new System.Drawing.Size(77, 39);
TextX.TabIndex = 5;
TextX.Text = "≤ x ≤";
TextX.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// MaxBoxX
//
MaxBoxX.Location = new System.Drawing.Point(412, 49);
MaxBoxX.Margin = new System.Windows.Forms.Padding(0, 3, 25, 3);
MaxBoxX.Name = "MaxBoxX";
MaxBoxX.Size = new System.Drawing.Size(108, 39);
MaxBoxX.TabIndex = 6;
//
// MaxBoxY
//
MaxBoxY.Location = new System.Drawing.Point(412, 94);
MaxBoxY.Margin = new System.Windows.Forms.Padding(0, 3, 25, 3);
MaxBoxY.Name = "MaxBoxY";
MaxBoxY.Size = new System.Drawing.Size(108, 39);
MaxBoxY.TabIndex = 9;
//
// TextY
//
TextY.Location = new System.Drawing.Point(335, 94);
TextY.Margin = new System.Windows.Forms.Padding(0);
TextY.Name = "TextY";
TextY.Size = new System.Drawing.Size(77, 39);
TextY.TabIndex = 8;
TextY.Text = "≤ y ≤";
TextY.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// MinBoxY
//
MinBoxY.Location = new System.Drawing.Point(227, 94);
MinBoxY.Margin = new System.Windows.Forms.Padding(25, 3, 0, 3);
MinBoxY.Name = "MinBoxY";
MinBoxY.Size = new System.Drawing.Size(108, 39);
MinBoxY.TabIndex = 7;
//
// ViewportLock
//
ViewportLock.Location = new System.Drawing.Point(227, 139);
ViewportLock.Name = "ViewportLock";
ViewportLock.Size = new System.Drawing.Size(293, 39);
ViewportLock.TabIndex = 10;
ViewportLock.Text = "Lock Viewport";
ViewportLock.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
ViewportLock.UseVisualStyleBackColor = true;
ViewportLock.CheckedChanged += ViewportLock_CheckedChanged;
//
// SetZoomForm
//
AutoScaleDimensions = new System.Drawing.SizeF(13F, 32F);
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
ClientSize = new System.Drawing.Size(800, 450);
ClientSize = new System.Drawing.Size(533, 227);
Controls.Add(ViewportLock);
Controls.Add(MaxBoxY);
Controls.Add(TextY);
Controls.Add(MinBoxY);
Controls.Add(MaxBoxX);
Controls.Add(TextX);
Controls.Add(MinBoxX);
Controls.Add(NormalizeButton);
Controls.Add(ResetButton);
Controls.Add(MatchAspectButton);
@ -87,6 +164,7 @@
Name = "SetZoomForm";
Text = "Set Viewport Zoom";
ResumeLayout(false);
PerformLayout();
}
#endregion
@ -95,5 +173,12 @@
private System.Windows.Forms.Button MatchAspectButton;
private System.Windows.Forms.Button ResetButton;
private System.Windows.Forms.Button NormalizeButton;
private System.Windows.Forms.TextBox MinBoxX;
private System.Windows.Forms.Label TextX;
private System.Windows.Forms.TextBox MaxBoxX;
private System.Windows.Forms.TextBox MaxBoxY;
private System.Windows.Forms.Label TextY;
private System.Windows.Forms.TextBox MinBoxY;
private System.Windows.Forms.CheckBox ViewportLock;
}
}

View File

@ -14,7 +14,8 @@ public partial class SetZoomForm : Form
InitializeComponent();
this.refForm = refForm;
refForm.OnZoomLevelChanged += (o, e) => RedeclareValues();
refForm.Paint += (o, e) => RedeclareValues();
RedeclareValues();
}
private void EnableBoxSelect_Click(object? sender, EventArgs e)
@ -54,6 +55,11 @@ public partial class SetZoomForm : Form
refForm.Width = newWidth;
}
private void NormalizeButton_Click(object? sender, EventArgs e)
{
double factor = 1 / Math.Min(refForm.ZoomLevel.x, refForm.ZoomLevel.y);
refForm.ZoomLevel = new(factor * refForm.ZoomLevel.x, factor * refForm.ZoomLevel.y);
}
private void ResetButton_Click(object? sender, EventArgs e)
{
refForm.ResetAllViewport();
@ -61,7 +67,25 @@ public partial class SetZoomForm : Form
private void RedeclareValues()
{
Invalidate(false);
bool enabled = !refForm.ViewportLocked;
Float2 minGraph = refForm.MinVisibleGraph,
maxGraph = refForm.MaxVisibleGraph;
MinBoxX.Text = $"{minGraph.x:0.000}";
MaxBoxX.Text = $"{maxGraph.x:0.000}";
MinBoxY.Text = $"{minGraph.y:0.000}";
MaxBoxY.Text = $"{maxGraph.y:0.000}";
ViewportLock.Checked = !enabled;
EnableBoxSelect.Enabled = enabled;
MatchAspectButton.Enabled = enabled;
NormalizeButton.Enabled = enabled;
ResetButton.Enabled = enabled;
MinBoxX.Enabled = enabled;
MaxBoxX.Enabled = enabled;
MinBoxY.Enabled = enabled;
MaxBoxY.Enabled = enabled;
}
internal void CompleteBoxSelection()
@ -69,9 +93,9 @@ public partial class SetZoomForm : Form
if (boxSelectEnabled) EnableBoxSelect_Click(null, new());
}
private void NormalizeButton_Click(object sender, EventArgs e)
private void ViewportLock_CheckedChanged(object? sender, EventArgs e)
{
double factor = 1 / Math.Min(refForm.ZoomLevel.x, refForm.ZoomLevel.y);
refForm.ZoomLevel = new(factor * refForm.ZoomLevel.x, factor * refForm.ZoomLevel.y);
refForm.ViewportLocked = ViewportLock.Checked;
RedeclareValues();
}
}