Skip to content

Commit 7a2a8b7

Browse files
cleanup and format
1 parent da02fac commit 7a2a8b7

151 files changed

Lines changed: 534 additions & 358 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CommonControls.Converter/BooleanToVisibilityConverter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
4141
{
4242
if (value is bool b)
4343
return b ? Visibility.Visible : (Collapse ? Visibility.Collapsed : Visibility.Hidden);
44+
4445
return Visibility.Hidden;
4546
}
4647

@@ -55,6 +56,6 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
5556
/// A converted value. If the method returns <see langword="null" />, the valid null value is used.
5657
/// </returns>
5758
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
58-
=> value is Visibility v && v == Visibility.Visible;
59+
=> value is Visibility and Visibility.Visible;
5960
}
6061
}

CommonControls.Converter/EnumToBooleanConverter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu
5050
{
5151
if ((bool)value)
5252
return Enum.Parse(targetType, parameter.ToString()!);
53+
5354
return Binding.DoNothing;
5455
}
5556
}

CommonControls.Images/ColorPicker.xaml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
Background="Transparent"
2828
HorizontalAlignment="Center"
2929
VerticalAlignment="Center"
30-
MouseDown="OnMouseDown"
31-
MouseMove="OnMouseMove"
30+
MouseDown="OnMouseDown"
31+
MouseMove="OnMouseMove"
3232
MouseUp="OnMouseUp">
3333

34-
<Image x:Name="PickerImage"
34+
<Image x:Name="PickerImage"
3535
RenderOptions.BitmapScalingMode="HighQuality"
36-
IsHitTestVisible="False"/>
36+
IsHitTestVisible="False" />
3737

3838
<Canvas x:Name="CursorCanvas" IsHitTestVisible="False">
3939
<Ellipse x:Name="HueCursor" Width="10" Height="10"
@@ -65,10 +65,10 @@
6565
Value="{Binding Alpha, ElementName=ColorPickerControl, Mode=TwoWay}"
6666
HorizontalAlignment="Center" />
6767

68-
<TextBlock Grid.Row="1"
69-
Text="{Binding Alpha, ElementName=ColorPickerControl}"
70-
HorizontalAlignment="Center"
71-
Width="30"
68+
<TextBlock Grid.Row="1"
69+
Text="{Binding Alpha, ElementName=ColorPickerControl}"
70+
HorizontalAlignment="Center"
71+
Width="30"
7272
TextAlignment="Center"
7373
Margin="0,5,0,0" />
7474
</Grid>
@@ -93,27 +93,27 @@
9393
</Grid.RowDefinitions>
9494

9595
<Label Grid.Row="0" Grid.Column="0" Content="Hue" Padding="0" />
96-
<TextBox Grid.Row="1" Grid.Column="0"
96+
<TextBox Grid.Row="1" Grid.Column="0"
9797
Text="{Binding Hue, ElementName=ColorPickerControl, StringFormat=N1, UpdateSourceTrigger=PropertyChanged, Delay=300}" />
9898

9999
<Label Grid.Row="0" Grid.Column="2" Content="Sat" Padding="0" />
100-
<TextBox Grid.Row="1" Grid.Column="2"
100+
<TextBox Grid.Row="1" Grid.Column="2"
101101
Text="{Binding Sat, ElementName=ColorPickerControl, StringFormat=N2, UpdateSourceTrigger=PropertyChanged, Delay=300}" />
102102

103103
<Label Grid.Row="0" Grid.Column="4" Content="Val" Padding="0" />
104-
<TextBox Grid.Row="1" Grid.Column="4"
104+
<TextBox Grid.Row="1" Grid.Column="4"
105105
Text="{Binding Val, ElementName=ColorPickerControl, StringFormat=N2, UpdateSourceTrigger=PropertyChanged, Delay=300}" />
106106

107107
<Label Grid.Row="3" Grid.Column="0" Content="R" Padding="0" />
108-
<TextBox Grid.Row="4" Grid.Column="0"
108+
<TextBox Grid.Row="4" Grid.Column="0"
109109
Text="{Binding R, ElementName=ColorPickerControl, UpdateSourceTrigger=PropertyChanged}" />
110110

111111
<Label Grid.Row="3" Grid.Column="2" Content="G" Padding="0" />
112-
<TextBox Grid.Row="4" Grid.Column="2"
112+
<TextBox Grid.Row="4" Grid.Column="2"
113113
Text="{Binding G, ElementName=ColorPickerControl, UpdateSourceTrigger=PropertyChanged}" />
114114

115115
<Label Grid.Row="3" Grid.Column="4" Content="B" Padding="0" />
116-
<TextBox Grid.Row="4" Grid.Column="4"
116+
<TextBox Grid.Row="4" Grid.Column="4"
117117
Text="{Binding B, ElementName=ColorPickerControl, UpdateSourceTrigger=PropertyChanged}" />
118118

119119
<TextBox Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="5"

CommonControls.Images/ColorPicker.xaml.cs

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
using System;
1+
/*
2+
* COPYRIGHT: See COPYING in the top level directory
3+
* PROJECT: CommonControls.Images
4+
* FILE: ColorPicker.xaml.cs
5+
* PURPOSE: ColorPicker control with a hue ring and saturation/value triangle, supporting RGB/Hex input and output.
6+
* PROGRAMER: Peter Geinitz (Wayfarer)
7+
*/
8+
9+
using System;
210
using System.ComponentModel;
311
using System.Runtime.CompilerServices;
412
using System.Windows;
@@ -10,7 +18,14 @@
1018

1119
namespace CommonControls.Images
1220
{
13-
public sealed partial class ColorPicker : UserControl, INotifyPropertyChanged
21+
/// <inheritdoc cref="INotifyPropertyChanged" />
22+
/// <summary>
23+
/// ColorPicker is a WPF UserControl that provides an interactive color selection interface using a hue ring and saturation/value triangle. It supports RGB and Hex input/output, and raises events when the color changes. The control is designed to be visually intuitive and responsive, allowing users to easily select colors while providing real-time feedback through property bindings and events.
24+
/// </summary>
25+
/// <seealso cref="T:System.Windows.Controls.UserControl" />
26+
/// <seealso cref="T:System.ComponentModel.INotifyPropertyChanged" />
27+
/// <seealso cref="T:System.Windows.Markup.IComponentConnector" />
28+
public sealed partial class ColorPicker : INotifyPropertyChanged
1429
{
1530
private WriteableBitmap _bitmap;
1631
private bool _isDragging;
@@ -24,22 +39,35 @@ public sealed partial class ColorPicker : UserControl, INotifyPropertyChanged
2439
// To prevent infinite loops when updating properties
2540
private bool _ignoreUpdates;
2641

27-
public event PropertyChangedEventHandler PropertyChanged;
42+
/// <inheritdoc />
43+
/// <summary>
44+
/// Occurs when a property value changes.
45+
/// </summary>
46+
public event PropertyChangedEventHandler? PropertyChanged;
2847

48+
/// <summary>
49+
///
50+
/// </summary>
51+
/// <param name="colorHsv">The color HSV.</param>
2952
public delegate void DelegateColor(ColorHsv colorHsv);
3053

54+
/// <summary>
55+
/// Occurs when [color changed].
56+
/// </summary>
3157
public event DelegateColor ColorChanged;
3258

59+
/// <inheritdoc />
3360
/// <summary>
34-
/// Initializes a new instance of the <see cref="ColorPicker"/> class.
61+
/// Initializes a new instance of the <see cref="T:CommonControls.Images.ColorPicker" /> class.
3562
/// </summary>
3663
public ColorPicker()
3764
{
3865
InitializeComponent();
3966
}
4067

68+
/// <inheritdoc />
4169
/// <summary>
42-
/// Initializes a new instance of the <see cref="ColorPicker"/> class.
70+
/// Initializes a new instance of the <see cref="T:CommonControls.Images.ColorPicker" /> class.
4371
/// </summary>
4472
/// <param name="r">The r.</param>
4573
/// <param name="g">The g.</param>
@@ -53,7 +81,8 @@ public ColorPicker()
5381
Alpha = alpha;
5482

5583
// This is the trigger that will finally make it draw
56-
this.SizeChanged += (s, e) => {
84+
this.SizeChanged += (s, e) =>
85+
{
5786
if (e.NewSize.Width > 0 && e.NewSize.Height > 0)
5887
{
5988
RedrawAsync();
@@ -62,6 +91,7 @@ public ColorPicker()
6291
};
6392
}
6493

94+
/// <inheritdoc />
6595
/// <summary>
6696
/// When overridden in a derived class, participates in rendering operations that are directed by the layout system. The rendering instructions for this element are not used directly when this method is invoked, and are instead preserved for later asynchronous use by layout and drawing.
6797
/// </summary>
@@ -78,7 +108,9 @@ protected override void OnRender(System.Windows.Media.DrawingContext drawingCont
78108

79109
// --- DEPENDENCY PROPERTIES (For Bindings) ---
80110

81-
// Show/Hide inputs
111+
/// <summary>
112+
/// Show/Hide inputs
113+
/// </summary>
82114
public static readonly DependencyProperty ShowTextBoxesProperty =
83115
DependencyProperty.Register(nameof(ShowTextBoxes), typeof(bool), typeof(ColorPicker),
84116
new PropertyMetadata(true));
@@ -276,14 +308,16 @@ private void ProcessMouse(Point p)
276308
// Try exact math first
277309
if (GetSvFromPoint(dx, dy, layout.InnerRadius, _h, out double s, out double v))
278310
{
279-
_s = s; _v = v;
311+
_s = s;
312+
_v = v;
280313
}
281314
else
282315
{
283316
// MAGNET FIX: We are inside the circle, but outside the triangle.
284317
// Snap to the closest edge (Clamp).
285318
GetSvFromPointClamped(dx, dy, layout.InnerRadius, _h, out s, out v);
286-
_s = s; _v = v;
319+
_s = s;
320+
_v = v;
287321
}
288322

289323
OnPropertyChanged(nameof(Sat));
@@ -340,7 +374,11 @@ private void OnSizeChanged(object sender, SizeChangedEventArgs e)
340374
// This is the "Magic" pixel drawer (Same as before)
341375
private void RedrawAsync()
342376
{
343-
if (!CheckAccess()) { Dispatcher.BeginInvoke(new Action(RedrawAsync)); return; }
377+
if (!CheckAccess())
378+
{
379+
Dispatcher.BeginInvoke(new Action(RedrawAsync));
380+
return;
381+
}
344382

345383
// 1. Get the AVAILABLE space from the parent container (The Grid in Column 0)
346384
// We cast Parent to FrameworkElement to get its ActualWidth/Height
@@ -352,7 +390,7 @@ private void RedrawAsync()
352390
int size = (int)Math.Min(parent.ActualWidth, parent.ActualHeight);
353391

354392
// 3. FORCE the Container to be this square size.
355-
// Because we set Horizontal/VerticalAlignment="Center" in XAML,
393+
// Because we set Horizontal/VerticalAlignment="Center" in XAML,
356394
// it will float perfectly in the middle.
357395
PickerContainer.Width = size;
358396
PickerContainer.Height = size;
@@ -404,6 +442,7 @@ private void RedrawAsync()
404442
}
405443
}
406444
}
445+
407446
_bitmap.AddDirtyRect(new Int32Rect(0, 0, size, size));
408447
_bitmap.Unlock();
409448
}
@@ -509,8 +548,8 @@ private static int HsvToInt(double h, double s, double v, int alpha)
509548
double c = size / 2.0;
510549

511550
return (
512-
CenterX: c, // Defined X
513-
CenterY: c, // Defined Y (Same as X for a square)
551+
CenterX: c, // Defined X
552+
CenterY: c, // Defined Y (Same as X for a square)
514553
Size: size,
515554
Radius: c,
516555
InnerRadius: c * 0.85
@@ -555,10 +594,10 @@ private void GetSvFromPointClamped(double x, double y, double r, double hue, out
555594
}
556595

557596

558-
559597
private bool SetField<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
560598
{
561599
if (System.Collections.Generic.EqualityComparer<T>.Default.Equals(field, value)) return false;
600+
562601
field = value;
563602
OnPropertyChanged(propertyName);
564603
return true;
@@ -567,4 +606,4 @@ private bool SetField<T>(ref T field, T value, [CallerMemberName] string propert
567606
private void OnPropertyChanged(string propertyName) =>
568607
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
569608
}
570-
}
609+
}

CommonControls.Images/ImageZoom.xaml.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ private void Canvas_MouseUp(object sender, MouseButtonEventArgs e)
625625

626626
// 3. Validation: Ensure we actually drew something substantial
627627
bool isValid = (frame.Width > 0 && frame.Height > 0) ||
628-
(frame.Points != null && frame.Points.Count > 0);
628+
frame.Points is { Count: > 0 };
629629

630630
if (isValid)
631631
{
@@ -732,7 +732,7 @@ private void Canvas_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
732732
_mouseDown = false;
733733
MainCanvas.ReleaseMouseCapture();
734734
// Optional: reset current points in Adorner without committing
735-
// SelectionAdorner.ResetCurrent();
735+
// SelectionAdorner.ResetCurrent();
736736
return;
737737
}
738738

@@ -945,4 +945,4 @@ private static void SafeExecuteCommand(ICommand? cmd, object? parameter)
945945

946946
#endregion
947947
}
948-
}
948+
}

CommonControls.Images/SelectionAdorner.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ protected override void OnRender(DrawingContext drawingContext)
369369
foreach (var points in _committedFreeForms)
370370
{
371371
if (points.Count <= 1) continue;
372+
372373
var geometry = new StreamGeometry();
373374
using (var ctx = geometry.Open())
374375
{
@@ -415,7 +416,7 @@ protected override void OnRender(DrawingContext drawingContext)
415416
using (var ctx = geometry.Open())
416417
{
417418
// Current FreeFormPoints are already in View Coordinates (handled in OnMouseMove or AddFreeFormPoint logic)
418-
// Note: Check if your AddFreeFormPoint stores Transformed or View points.
419+
// Note: Check if your AddFreeFormPoint stores Transformed or View points.
419420
// Based on your original code: AddFreeFormPoint stores transformed (Logic Coordinates).
420421
// So we must Inverse Transform them for display.
421422

@@ -429,4 +430,4 @@ protected override void OnRender(DrawingContext drawingContext)
429430
}
430431
}
431432
}
432-
}
433+
}

CommonControls.Images/SelectionFrame.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ public sealed class SelectionFrame
4949
/// </summary>
5050
public List<Point> Points { get; internal init; } = new();
5151
}
52-
}
52+
}

CommonControls.Images/Thumbnails.xaml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,7 @@ await Application.Current.Dispatcher.InvokeAsync(() =>
674674
bitmapImage.EndInit();
675675
bitmapImage.Freeze(); // Crucial: Makes it accessible to the UI thread
676676
}
677+
677678
return bitmapImage;
678679
}
679680
catch (Exception ex)
@@ -989,4 +990,4 @@ private void Dispose(bool disposing)
989990
Dispose(false);
990991
}
991992
}
992-
}
993+
}

CommonControls/GlobalKeyHandler.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public static class GlobalKeyHandler
3232
/// </summary>
3333
public static readonly DependencyProperty CommandBindingsProperty =
3434
DependencyProperty.RegisterAttached(
35-
ComCtlResources.GlobalKeyCommandBindings, typeof(Dictionary<Tuple<ModifierKeys, Key>, ICommand>), typeof(GlobalKeyHandler),
35+
ComCtlResources.GlobalKeyCommandBindings, typeof(Dictionary<Tuple<ModifierKeys, Key>, ICommand>),
36+
typeof(GlobalKeyHandler),
3637
new PropertyMetadata(null));
3738

3839
/// <summary>
@@ -167,4 +168,4 @@ private static void OnPreviewKeyDown(object sender, KeyEventArgs e)
167168
e.Handled = true;
168169
}
169170
}
170-
}
171+
}

CommonControls/ThumbnailItem.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,26 @@ public class ThumbnailItem : INotifyPropertyChanged
1616
public BitmapSource ImageSource
1717
{
1818
get => _imageSource;
19-
set { _imageSource = value; OnPropertyChanged(); }
19+
set
20+
{
21+
_imageSource = value;
22+
OnPropertyChanged();
23+
}
2024
}
2125

2226
// Two-way binding for the CheckBox
2327
public bool IsSelected
2428
{
2529
get => _isSelected;
26-
set { _isSelected = value; OnPropertyChanged(); }
30+
set
31+
{
32+
_isSelected = value;
33+
OnPropertyChanged();
34+
}
2735
}
2836

2937
public event PropertyChangedEventHandler PropertyChanged;
38+
3039
private void OnPropertyChanged([CallerMemberName] string name = null)
3140
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
3241
}

0 commit comments

Comments
 (0)