feat(Eve-O-Preview): add aspect ratio maintenance for thumbnail size

This commit is contained in:
2025-08-29 22:40:31 +02:00
parent 7f5ab131af
commit e53b9712ca
3 changed files with 101 additions and 10 deletions

View File

@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net8.0-windows8.0</TargetFramework>
<OutputType>WinExe</OutputType>
<RootNamespace>EveOMock</RootNamespace>
<AssemblyName>ExeFile</AssemblyName>

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<DefineConstants Condition="'$(EVEOTarget)'=='Linux'">LINUX</DefineConstants>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net8.0-windows8.0</TargetFramework>
<OutputType>WinExe</OutputType>
<PublishSingleFile>true</PublishSingleFile>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>

View File

@@ -41,6 +41,10 @@ namespace EveOPreview.View {
this.InitFormSize();
this.AnimationStyleCombo.DataSource = Enum.GetValues(typeof(AnimationStyle));
// Add mouse wheel event handlers for aspect ratio maintenance
this.ThumbnailsWidthNumericEdit.MouseWheel += ThumbnailSizeNumeric_MouseWheel;
this.ThumbnailsHeightNumericEdit.MouseWheel += ThumbnailSizeNumeric_MouseWheel;
}
public bool MinimizeToTray {
@@ -437,18 +441,105 @@ namespace EveOPreview.View {
return;
}
// Perform some View work that is not properly done in the Control
this._suppressEvents = true;
Size thumbnailSize = this.ThumbnailSize;
thumbnailSize.Width = Math.Min(Math.Max(thumbnailSize.Width, this._minimumSize.Width), this._maximumSize.Width);
thumbnailSize.Height =
Math.Min(Math.Max(thumbnailSize.Height, this._minimumSize.Height), this._maximumSize.Height);
this.ThumbnailSize = thumbnailSize;
this._suppressEvents = false;
// Check if shift is held down for aspect ratio maintenance
bool maintainAspectRatio = ModifierKeys.HasFlag(Keys.Shift);
if (maintainAspectRatio && sender is NumericUpDown changedControl) {
// Calculate the aspect ratio from the current size before the change
double aspectRatio =
(double)this.ThumbnailsWidthNumericEdit.Value / (double)this.ThumbnailsHeightNumericEdit.Value;
// Determine which control was changed and update the other accordingly
if (changedControl == this.ThumbnailsWidthNumericEdit) {
int newWidth = (int)changedControl.Value;
int newHeight = (int)(newWidth / aspectRatio);
// Apply size constraints
newWidth = Math.Min(Math.Max(newWidth, this._minimumSize.Width), this._maximumSize.Width);
newHeight = Math.Min(Math.Max(newHeight, this._minimumSize.Height), this._maximumSize.Height);
this._suppressEvents = true;
this.ThumbnailsWidthNumericEdit.Value = newWidth;
this.ThumbnailsHeightNumericEdit.Value = newHeight;
this._suppressEvents = false;
} else if (changedControl == this.ThumbnailsHeightNumericEdit) {
int newHeight = (int)changedControl.Value;
int newWidth = (int)(newHeight * aspectRatio);
// Apply size constraints
newWidth = Math.Min(Math.Max(newWidth, this._minimumSize.Width), this._maximumSize.Width);
newHeight = Math.Min(Math.Max(newHeight, this._minimumSize.Height), this._maximumSize.Height);
this._suppressEvents = true;
this.ThumbnailsWidthNumericEdit.Value = newWidth;
this.ThumbnailsHeightNumericEdit.Value = newHeight;
this._suppressEvents = false;
}
} else {
// Normal behavior without aspect ratio maintenance
this._suppressEvents = true;
Size thumbnailSize = this.ThumbnailSize;
thumbnailSize.Width =
Math.Min(Math.Max(thumbnailSize.Width, this._minimumSize.Width), this._maximumSize.Width);
thumbnailSize.Height =
Math.Min(Math.Max(thumbnailSize.Height, this._minimumSize.Height), this._maximumSize.Height);
this.ThumbnailSize = thumbnailSize;
this._suppressEvents = false;
}
this.ThumbnailsSizeChanged?.Invoke();
}
private void ThumbnailSizeNumeric_MouseWheel(object sender, MouseEventArgs e) {
if (this._suppressEvents) {
return;
}
// Check if shift is held down for aspect ratio maintenance
bool maintainAspectRatio = ModifierKeys.HasFlag(Keys.Shift);
if (maintainAspectRatio && sender is NumericUpDown control) {
// Calculate the aspect ratio from the current size
double aspectRatio =
(double)this.ThumbnailsWidthNumericEdit.Value / (double)this.ThumbnailsHeightNumericEdit.Value;
// Determine scroll direction and increment
int increment = e.Delta > 0 ? (int)control.Increment : -(int)control.Increment;
// Determine which control was scrolled and update both accordingly
if (control == this.ThumbnailsWidthNumericEdit) {
int newWidth = (int)control.Value + increment;
int newHeight = (int)(newWidth / aspectRatio);
// Apply size constraints
newWidth = Math.Min(Math.Max(newWidth, this._minimumSize.Width), this._maximumSize.Width);
newHeight = Math.Min(Math.Max(newHeight, this._minimumSize.Height), this._maximumSize.Height);
this._suppressEvents = true;
this.ThumbnailsWidthNumericEdit.Value = newWidth;
this.ThumbnailsHeightNumericEdit.Value = newHeight;
this._suppressEvents = false;
} else if (control == this.ThumbnailsHeightNumericEdit) {
int newHeight = (int)control.Value + increment;
int newWidth = (int)(newHeight * aspectRatio);
// Apply size constraints
newWidth = Math.Min(Math.Max(newWidth, this._minimumSize.Width), this._maximumSize.Width);
newHeight = Math.Min(Math.Max(newHeight, this._minimumSize.Height), this._maximumSize.Height);
this._suppressEvents = true;
this.ThumbnailsWidthNumericEdit.Value = newWidth;
this.ThumbnailsHeightNumericEdit.Value = newHeight;
this._suppressEvents = false;
}
// Prevent the default scroll behavior
((HandledMouseEventArgs)e).Handled = true;
this.ThumbnailsSizeChanged?.Invoke();
}
}
private void ActiveClientHighlightColorButton_Click(object sender, EventArgs e) {
using (ColorDialog dialog = new ColorDialog()) {
dialog.Color = this.ActiveClientHighlightColor;