Zoom form finally pretty much ready.

This commit is contained in:
That_One_Nerd 2024-04-17 14:09:34 -04:00
parent 933fcdf082
commit a6f7279b97
3 changed files with 93 additions and 3 deletions

View File

@ -35,6 +35,8 @@ public partial class GraphForm : Form
{ {
_zoomLevel = new(Math.Clamp(value.x, 1e-5, 1e3), _zoomLevel = new(Math.Clamp(value.x, 1e-5, 1e3),
Math.Clamp(value.y, 1e-5, 1e3)); Math.Clamp(value.y, 1e-5, 1e3));
OnZoomLevelChanged(this, new());
Invalidate(false);
} }
} }
private Float2 _zoomLevel; private Float2 _zoomLevel;
@ -49,6 +51,8 @@ public partial class GraphForm : Form
private readonly List<Graphable> ables; private readonly List<Graphable> ables;
public event EventHandler OnZoomLevelChanged = delegate { };
public GraphForm(string title) public GraphForm(string title)
{ {
SetStyle(ControlStyles.OptimizedDoubleBuffer, true); SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
@ -390,9 +394,7 @@ public partial class GraphForm : Form
private void ResetViewportButton_Click(object? sender, EventArgs e) private void ResetViewportButton_Click(object? sender, EventArgs e)
{ {
ScreenCenter = new Float2(0, 0); ResetAllViewport();
ZoomLevel = new(1, 1);
Invalidate(false);
} }
private void GraphColorPickerButton_Click(Graphable able) private void GraphColorPickerButton_Click(Graphable able)
{ {
@ -549,6 +551,16 @@ public partial class GraphForm : Form
WindowState = FormWindowState.Normal; WindowState = FormWindowState.Normal;
} }
public void ResetAllViewport()
{
ScreenCenter = new Float2(0, 0);
ZoomLevel = new(1, 1);
Location = initialWindowPos;
Size = initialWindowSize;
WindowState = FormWindowState.Normal;
Invalidate(false);
}
private ViewCacheForm? cacheForm; private ViewCacheForm? cacheForm;
private void MenuMiscCaches_Click(object? sender, EventArgs e) private void MenuMiscCaches_Click(object? sender, EventArgs e)
{ {

View File

@ -29,6 +29,9 @@
private void InitializeComponent() private void InitializeComponent()
{ {
EnableBoxSelect = new System.Windows.Forms.Button(); EnableBoxSelect = new System.Windows.Forms.Button();
MatchAspectButton = new System.Windows.Forms.Button();
ResetButton = new System.Windows.Forms.Button();
NormalizeButton = new System.Windows.Forms.Button();
SuspendLayout(); SuspendLayout();
// //
// EnableBoxSelect // EnableBoxSelect
@ -41,11 +44,44 @@
EnableBoxSelect.UseVisualStyleBackColor = true; EnableBoxSelect.UseVisualStyleBackColor = true;
EnableBoxSelect.Click += EnableBoxSelect_Click; EnableBoxSelect.Click += EnableBoxSelect_Click;
// //
// MatchAspectButton
//
MatchAspectButton.Location = new System.Drawing.Point(168, 12);
MatchAspectButton.Name = "MatchAspectButton";
MatchAspectButton.Size = new System.Drawing.Size(187, 46);
MatchAspectButton.TabIndex = 1;
MatchAspectButton.Text = "Match Aspect";
MatchAspectButton.UseVisualStyleBackColor = true;
MatchAspectButton.Click += MatchAspectButton_Click;
//
// ResetButton
//
ResetButton.Location = new System.Drawing.Point(517, 12);
ResetButton.Name = "ResetButton";
ResetButton.Size = new System.Drawing.Size(150, 46);
ResetButton.TabIndex = 2;
ResetButton.Text = "Reset";
ResetButton.UseVisualStyleBackColor = true;
ResetButton.Click += ResetButton_Click;
//
// NormalizeButton
//
NormalizeButton.Location = new System.Drawing.Point(361, 12);
NormalizeButton.Name = "NormalizeButton";
NormalizeButton.Size = new System.Drawing.Size(150, 46);
NormalizeButton.TabIndex = 3;
NormalizeButton.Text = "Normalize";
NormalizeButton.UseVisualStyleBackColor = true;
NormalizeButton.Click += NormalizeButton_Click;
//
// SetZoomForm // SetZoomForm
// //
AutoScaleDimensions = new System.Drawing.SizeF(13F, 32F); AutoScaleDimensions = new System.Drawing.SizeF(13F, 32F);
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
ClientSize = new System.Drawing.Size(800, 450); ClientSize = new System.Drawing.Size(800, 450);
Controls.Add(NormalizeButton);
Controls.Add(ResetButton);
Controls.Add(MatchAspectButton);
Controls.Add(EnableBoxSelect); Controls.Add(EnableBoxSelect);
FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
Name = "SetZoomForm"; Name = "SetZoomForm";
@ -56,5 +92,8 @@
#endregion #endregion
private System.Windows.Forms.Button EnableBoxSelect; private System.Windows.Forms.Button EnableBoxSelect;
private System.Windows.Forms.Button MatchAspectButton;
private System.Windows.Forms.Button ResetButton;
private System.Windows.Forms.Button NormalizeButton;
} }
} }

View File

@ -13,6 +13,8 @@ public partial class SetZoomForm : Form
{ {
InitializeComponent(); InitializeComponent();
this.refForm = refForm; this.refForm = refForm;
refForm.OnZoomLevelChanged += (o, e) => RedeclareValues();
} }
private void EnableBoxSelect_Click(object? sender, EventArgs e) private void EnableBoxSelect_Click(object? sender, EventArgs e)
@ -30,9 +32,46 @@ public partial class SetZoomForm : Form
EnableBoxSelect.Text = "Box Select"; EnableBoxSelect.Text = "Box Select";
} }
} }
private void MatchAspectButton_Click(object? sender, EventArgs e)
{
double zoomXFactor = refForm.ZoomLevel.x / refForm.ZoomLevel.y;
double actualXFactor = refForm.ClientRectangle.Width / refForm.ClientRectangle.Height;
double diff = actualXFactor / zoomXFactor;
int newWidth = (int)(refForm.Width / diff);
refForm.ZoomLevel = new(refForm.ZoomLevel.x * diff, refForm.ZoomLevel.y);
int maxScreenWidth = Screen.FromControl(refForm).WorkingArea.Width;
if (newWidth >= maxScreenWidth)
{
refForm.Location = new(0, refForm.Location.Y);
double xScaleFactor = (double)maxScreenWidth / newWidth;
newWidth = maxScreenWidth;
refForm.Height = (int)(refForm.Height * xScaleFactor);
refForm.ZoomLevel = new(refForm.ZoomLevel.x * xScaleFactor, refForm.ZoomLevel.y * xScaleFactor);
}
refForm.Width = newWidth;
}
private void ResetButton_Click(object? sender, EventArgs e)
{
refForm.ResetAllViewport();
}
private void RedeclareValues()
{
Invalidate(false);
}
internal void CompleteBoxSelection() internal void CompleteBoxSelection()
{ {
if (boxSelectEnabled) EnableBoxSelect_Click(null, new()); if (boxSelectEnabled) EnableBoxSelect_Click(null, new());
} }
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);
}
} }