Skip to content

Commit

Permalink
🎨 Plug in the reset image button for embedded monitors.
Browse files Browse the repository at this point in the history
  • Loading branch information
hexawyz committed Feb 9, 2025
1 parent 7a806c8 commit 8e03417
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<Button Grid.Column="2" Margin="{StaticResource RowContentMargin}" HorizontalAlignment="Right" Command="{Binding ResetCommand}">
<Button Grid.Column="2" Margin="{StaticResource RowContentMargin}" HorizontalAlignment="Right" Command="{Binding ResetCommand}" CommandParameter="{Binding}">
<FontIcon Glyph="&#xE777;" />
</Button>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ protected override void Reset()
break;
}
}
_currentGraphics?.Reset();
(_currentGraphics as IResettable)?.Reset();
}

internal void UpdateConfiguration(EmbeddedMonitorConfigurationUpdate configuration)
Expand Down Expand Up @@ -330,7 +330,7 @@ internal void UpdateConfiguration(EmbeddedMonitorConfigurationUpdate configurati
}
}

internal abstract class EmbeddedMonitorGraphicsViewModel : ChangeableBindableObject
internal abstract class EmbeddedMonitorGraphicsViewModel : ResettableBindableObject
{
private readonly EmbeddedMonitorViewModel _monitor;
private readonly Guid _id;
Expand Down Expand Up @@ -367,7 +367,7 @@ protected override void OnChanged(bool isChanged)

internal abstract ValueTask ApplyAsync(CancellationToken cancellationToken);

internal virtual void Reset() { }
protected override void Reset() { }
}

internal sealed class EmbeddedMonitorBuiltInGraphicsViewModel : EmbeddedMonitorGraphicsViewModel
Expand Down Expand Up @@ -440,24 +440,26 @@ public ImageViewModel? Image
if (SetChangeableValue(ref _image, value, ChangedProperty.Image))
{
// TODO: Improve this to initialize the crop rectangle to a better value automatically.
if (value is not null && !IsRegionValid(_cropRectangle))
if (value is not null)
{
var imageSize = Monitor.ImageSize;
if (imageSize.Width == imageSize.Height)
{
var s = Math.Min(value.Width, value.Height);
CropRectangle = new() { Left = (value.Width - s) >>> 1, Top = (value.Height - s) >>> 1, Width = s, Height = s };
var minDimension = Math.Min(value.Width, value.Height);
CropRectangle = new() { Left = (value.Width - minDimension) >>> 1, Top = (value.Height - minDimension) >>> 1, Width = minDimension, Height = minDimension };
// Just to avoid the applicable change below that would be duplicated. This needs to go away.
return;
}
}
else
{
// Not ideal but good enough for now.
IApplicable.NotifyCanExecuteChanged();
}

// Not ideal but good enough for now. (Basically can fire if the applicable state stays false. We can do a check on IsValid later on.)
IApplicable.NotifyCanExecuteChanged();
}
}
}

private bool IsImageChanged => (_image?.Id).GetValueOrDefault() != _initialImageId;

public MonitorShape Shape => Monitor.Shape;

public Size ImageSize => Monitor.ImageSize;
Expand Down Expand Up @@ -549,7 +551,7 @@ internal void UpdateConfiguration(EmbeddedMonitorImageConfiguration configuratio
OnChangeStateChange(wasChanged);
}

internal override void Reset()
protected override void Reset()
{
if (!IsChanged) return;
bool imageChanged = false;
Expand Down

0 comments on commit 8e03417

Please sign in to comment.