Skip to content

Commit

Permalink
sync back fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
LoneWandererProductions committed Nov 7, 2024
1 parent 2a7d96c commit 11703b9
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 40 deletions.
13 changes: 9 additions & 4 deletions CommonControls/ComCtlResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,25 @@ internal static class ComCtlResources
internal const string ErrorWrongParameters = "Wrong Arguments provided: ";

/// <summary>
/// Error, Color Selection parameters (const). Value: "Error selecting color".
/// Error, Color Selection parameters (const). Value: "Error selecting color.".
/// </summary>
internal const string ErrorColorSelection = "Error selecting color";
internal const string ErrorColorSelection = "Error selecting color.";

/// <summary>
/// Error, Color switching parameters (const). Value:"Error switching color".
/// Error, Color switching parameters (const). Value:"Error switching color.".
/// </summary>
internal const string ErrorSwitchingColor = "Error switching color";
internal const string ErrorSwitchingColor = "Error switching color.";

/// <summary>
/// The error could not load image (const). Value: "Error could not load Image:".
/// </summary>
internal const string ErrorCouldNotLoadImage = "Error could not load Image:";

/// <summary>
/// The information ardoner null (const). Value: "Adorner was outside of the image control.".
/// </summary>
internal const string InformationArdonerNull = "Adorner was outside of the image control.";

/// <summary>
/// Error, Color Selection initializing parameters (const). Value: "Error initializing color selection control"
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions CommonControls/ImageZoom.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// ReSharper disable UnusedType.Global

using System;
using System.Diagnostics;
using System.IO;
using System.Windows;
using System.Windows.Documents;
Expand Down Expand Up @@ -420,6 +421,12 @@ private void Canvas_MouseUp(object sender, MouseButtonEventArgs e)
_mouseDown = false;
MainCanvas.ReleaseMouseCapture();

if (_selectionAdorner == null)
{
Trace.Write(ComCtlResources.InformationArdonerNull);
return;
}

//clicked Endpoint

switch (ZoomTool)
Expand Down
26 changes: 12 additions & 14 deletions CommonControls/Thumbnails.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,17 @@
d:DesignHeight="450"
d:DesignWidth="800" Loaded="UserControl_Loaded">
<Grid x:Name="Thb">
<ScrollViewer>
<ItemsControl>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Image Source="{Binding ImageSource}" Width="{Binding CellSize}" Height="{Binding CellSize}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
<ItemsControl>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Image Source="{Binding ImageSource}" Width="{Binding CellSize}" Height="{Binding CellSize}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</UserControl>
100 changes: 80 additions & 20 deletions CommonControls/Thumbnails.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,6 @@ public sealed partial class Thumbnails : IDisposable
/// </summary>
private int _originalWidth;

/// <summary>
/// The previous selected border
/// </summary>
private Border _previousSelectedBorder;

/// <summary>
/// The selection
/// </summary>
Expand Down Expand Up @@ -305,6 +300,11 @@ public ICommand ImageLoadedCommand
/// </value>
private ConcurrentDictionary<int, CheckBox> ChkBox { get; set; }

/// <summary>
/// The border
/// </summary>
private ConcurrentDictionary<int, Border> Border { get; set; }

/// <summary>
/// Gets or sets the selection.
/// </summary>
Expand Down Expand Up @@ -417,6 +417,7 @@ private async void LoadImages()

Keys = new ConcurrentDictionary<string, int>();
ImageDct = new ConcurrentDictionary<string, Image>();
Border = new ConcurrentDictionary<int, Border>();
Selection = new List<int>();

if (SelectBox) ChkBox = new ConcurrentDictionary<int, CheckBox>();
Expand Down Expand Up @@ -494,9 +495,13 @@ private async Task LoadImageAsync(int key, string name, Panel exGrid)
Child = images, // Set the image as the child of the border
BorderThickness = new Thickness(0), // Initially no border
BorderBrush = Brushes.Transparent, // Initially transparent
Margin = new Thickness(1) // Optionally add some margin for spacing
Margin = new Thickness(1), // Optionally add some margin for spacing
Name = string.Concat(ComCtlResources.ImageAdd, key)
};

//add a reference to Border for later use
Border.TryAdd(key, border);

// Add image click handler (this should run on the UI thread)
images.MouseDown += ImageClick_MouseDown;

Expand Down Expand Up @@ -624,22 +629,28 @@ private void ImageClick_MouseDown(object sender, MouseButtonEventArgs e)
var clickedBorder = clickedImage.Parent as Border;
if (clickedBorder == null) return;

// Clear previous selection highlight if any
if (_previousSelectedBorder != null)
{
_previousSelectedBorder.BorderBrush = Brushes.Transparent; // Reset previous border highlight
_previousSelectedBorder.BorderThickness = new Thickness(0); // Reset thickness
}

// Highlight the currently clicked thumbnail
clickedBorder.BorderBrush = Brushes.Blue; // Highlight with blue border
clickedBorder.BorderThickness = new Thickness(2); // Set border thickness
// Update the selected border (reuse the UpdateSelectedBorder method)
UpdateSelectedBorder(clickedBorder);
}

// Update the currently selected border
_currentSelectedBorder = clickedBorder;
/// <summary>
/// Next Border of this instance.
/// </summary>
public void Next()
{
int currentIndex = _currentSelectedBorder == null ? -1 : GetCurrentIndex(_currentSelectedBorder.Name);
int newIndex = (currentIndex + 1) % Border.Count; // Loop to the start if at the end
SelectImageAtIndex(newIndex);
}

// Update the previous selected border to the current one
_previousSelectedBorder = _currentSelectedBorder;
/// <summary>
/// Previous Border of this instance.
/// </summary>
public void Previous()
{
int currentIndex = _currentSelectedBorder == null ? -1 : GetCurrentIndex(_currentSelectedBorder.Name);
int newIndex = (currentIndex - 1 + Border.Count) % Border.Count; // Loop to the end if at the start
SelectImageAtIndex(newIndex);
}

/// <summary>
Expand Down Expand Up @@ -738,6 +749,55 @@ private void OnImageThumbClicked(ImageEventArgs args)
ImageClicked?.Invoke(this, args);
}

/// <summary>
/// Gets the index of the current.
/// </summary>
/// <param name="name">The key.</param>
/// <returns>Index of Border</returns>
private int GetCurrentIndex(string name)
{
// Find the index of the selected border
return Border
.Where(pair => pair.Value.Name == name)
.Select(pair => pair.Key)
.FirstOrDefault();
}

/// <summary>
/// Selects the index of the image at.
/// </summary>
/// <param name="index">The index.</param>
private void SelectImageAtIndex(int index)
{
if (index < 0 || index >= Border.Count || !Border.ContainsKey(index)) return;

var border = Border[index];

// Now, update the current selected border with the found Border
UpdateSelectedBorder(border);
}

/// <summary>
/// Updates the selected border.
/// </summary>
/// <param name="newSelectedBorder">The new selected border.</param>
private void UpdateSelectedBorder(Border newSelectedBorder)
{
// Remove the "selected" style from the previously selected border
if (_currentSelectedBorder != null)
{
_currentSelectedBorder.BorderBrush = Brushes.Transparent; // Reset previous border
_currentSelectedBorder.BorderThickness = new Thickness(0); // Reset thickness
}

// Set the new border as selected
newSelectedBorder.BorderBrush = Brushes.Blue; // Set a color for the border
newSelectedBorder.BorderThickness = new Thickness(2); // Set thickness to highlight

// Update the current selected border reference
_currentSelectedBorder = newSelectedBorder;
}

/// <summary>
/// Disposes the specified disposing.
/// </summary>
Expand Down
4 changes: 3 additions & 1 deletion Imaging/ColorHsv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,9 @@ public override int GetHashCode()
/// </returns>
public static bool operator ==(ColorHsv left, ColorHsv right)
{
return left?.Equals(right) == true;
if (ReferenceEquals(left, right)) return true; // Same reference
if (left is null || right is null) return false; // One is null
return left.Equals(right);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Imaging/TextureGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Imaging
/// Main Entry Class that will handle all things related to textures
/// </summary>
/// <seealso cref="T:Imaging.ITextureGenerator" />
public class TextureGenerator : ITextureGenerator
public sealed class TextureGenerator : ITextureGenerator
{
/// <summary>
/// Initializes a new instance of the <see cref="TextureGenerator" /> class.
Expand Down

0 comments on commit 11703b9

Please sign in to comment.