This commit is contained in:
PrefacedCorg
2026-04-14 12:19:36 +08:00
parent b64b0a3618
commit d73e87b980
7 changed files with 163 additions and 136 deletions
+12 -6
View File
@@ -66,7 +66,7 @@ namespace Ink_Canvas.Controls
private static void OnButtonSizeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var button = (CircularColorButton)d;
if (button.ButtonBorder == null) return;
if (button.ButtonBorder == null || button.ColorOverlay == null) return;
var size = (double)e.NewValue;
button.ButtonBorder.Width = size;
@@ -74,11 +74,17 @@ namespace Ink_Canvas.Controls
var radius = (size - 3) / 2;
button.ColorOverlay.Width = radius * 2;
button.ColorOverlay.Height = radius * 2;
button.ImageClipGeometry.RadiusX = radius;
button.ImageClipGeometry.RadiusY = radius;
button.ImageClipGeometry.Center = new Point(radius, radius);
button.TransparentGridImage.Width = radius * 2;
button.TransparentGridImage.Height = radius * 2;
if (button.ImageClipGeometry != null)
{
button.ImageClipGeometry.RadiusX = radius;
button.ImageClipGeometry.RadiusY = radius;
button.ImageClipGeometry.Center = new Point(radius, radius);
}
if (button.TransparentGridImage != null)
{
button.TransparentGridImage.Width = radius * 2;
button.TransparentGridImage.Height = radius * 2;
}
}
public double ButtonSize
+25
View File
@@ -0,0 +1,25 @@
<UserControl x:Class="Ink_Canvas.Controls.QuickPanelButton"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ikw="http://schemas.inkore.net/lib/ui/wpf"
mc:Ignorable="d"
d:DesignHeight="30" d:DesignWidth="32">
<ikw:SimpleStackPanel x:Name="ButtonPanel"
MouseUp="ButtonPanel_MouseUp"
Background="Transparent"
Orientation="Vertical"
HorizontalAlignment="Center"
Width="32" Margin="0">
<Image x:Name="ButtonImage"
RenderOptions.BitmapScalingMode="HighQuality"
Height="17" Margin="0,3,0,0" />
<TextBlock x:Name="LabelTextBlock"
Foreground="{DynamicResource FloatBarForeground}"
FontSize="8"
Margin="0,2,0,3"
TextAlignment="Center"
Visibility="Collapsed" />
</ikw:SimpleStackPanel>
</UserControl>
@@ -0,0 +1,80 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
namespace Ink_Canvas.Controls
{
public partial class QuickPanelButton : UserControl
{
public static readonly DependencyProperty LabelProperty = DependencyProperty.Register(
nameof(Label), typeof(string), typeof(QuickPanelButton),
new PropertyMetadata(string.Empty, OnLabelChanged));
private static void OnLabelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var button = (QuickPanelButton)d;
if (button.LabelTextBlock != null)
{
var text = (string)e.NewValue;
button.LabelTextBlock.Text = text;
button.LabelTextBlock.Visibility = string.IsNullOrEmpty(text) ? Visibility.Collapsed : Visibility.Visible;
button.ButtonImage.Margin = string.IsNullOrEmpty(text)
? new Thickness(0, 3, 0, 3)
: new Thickness(0, 3, 0, 0);
}
}
public string Label
{
get => (string)GetValue(LabelProperty);
set => SetValue(LabelProperty, value);
}
public static readonly DependencyProperty IconSourceProperty = DependencyProperty.Register(
nameof(IconSource), typeof(ImageSource), typeof(QuickPanelButton),
new PropertyMetadata(null, OnIconSourceChanged));
private static void OnIconSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var button = (QuickPanelButton)d;
if (button.ButtonImage != null)
button.ButtonImage.Source = (ImageSource)e.NewValue;
}
public ImageSource IconSource
{
get => (ImageSource)GetValue(IconSourceProperty);
set => SetValue(IconSourceProperty, value);
}
public static readonly DependencyProperty LabelFontSizeProperty = DependencyProperty.Register(
nameof(LabelFontSize), typeof(double), typeof(QuickPanelButton),
new PropertyMetadata(8.0, OnLabelFontSizeChanged));
private static void OnLabelFontSizeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var button = (QuickPanelButton)d;
if (button.LabelTextBlock != null)
button.LabelTextBlock.FontSize = (double)e.NewValue;
}
public double LabelFontSize
{
get => (double)GetValue(LabelFontSizeProperty);
set => SetValue(LabelFontSizeProperty, value);
}
public event RoutedEventHandler ButtonMouseUp;
public QuickPanelButton()
{
InitializeComponent();
}
private void ButtonPanel_MouseUp(object sender, MouseButtonEventArgs e)
{
ButtonMouseUp?.Invoke(this, new RoutedEventArgs(e.RoutedEvent, this));
}
}
}
+30 -4
View File
@@ -7,6 +7,9 @@ namespace Ink_Canvas.Controls
{
public partial class ToolMenuButton : UserControl
{
private Geometry _pendingGeometry;
private Brush _pendingBrush;
public static readonly DependencyProperty LabelProperty = DependencyProperty.Register(
nameof(Label), typeof(string), typeof(ToolMenuButton),
new PropertyMetadata(string.Empty, OnLabelChanged));
@@ -31,9 +34,11 @@ namespace Ink_Canvas.Controls
private static void OnIconGeometryChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var button = (ToolMenuButton)d;
if (e.NewValue is string geometry && !string.IsNullOrEmpty(geometry) && button.IconGeometryInternal != null)
if (e.NewValue is string geometry && !string.IsNullOrEmpty(geometry))
{
button.IconGeometryInternal.Geometry = Geometry.Parse(geometry);
button._pendingGeometry = Geometry.Parse(geometry);
if (button.IconGeometryInternal != null)
button.IconGeometryInternal.Geometry = button._pendingGeometry;
}
}
@@ -50,8 +55,9 @@ namespace Ink_Canvas.Controls
private static void OnIconBrushChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var button = (ToolMenuButton)d;
button._pendingBrush = (Brush)e.NewValue;
if (button.IconGeometryInternal != null)
button.IconGeometryInternal.Brush = (Brush)e.NewValue;
button.IconGeometryInternal.Brush = button._pendingBrush;
}
public Brush IconBrush
@@ -66,7 +72,15 @@ namespace Ink_Canvas.Controls
set => ButtonPanel.Background = value;
}
public GeometryDrawing Icon => IconGeometryInternal;
public GeometryDrawing Icon
{
get
{
if (IconGeometryInternal != null)
return IconGeometryInternal;
return new GeometryDrawing(_pendingBrush, null, _pendingGeometry);
}
}
public event MouseButtonEventHandler ButtonMouseDown;
public event MouseEventHandler ButtonMouseLeave;
@@ -75,6 +89,18 @@ namespace Ink_Canvas.Controls
public ToolMenuButton()
{
InitializeComponent();
Loaded += ToolMenuButton_Loaded;
}
private void ToolMenuButton_Loaded(object sender, RoutedEventArgs e)
{
if (IconGeometryInternal != null)
{
if (_pendingGeometry != null)
IconGeometryInternal.Geometry = _pendingGeometry;
if (_pendingBrush != null)
IconGeometryInternal.Brush = _pendingBrush;
}
}
private void ButtonPanel_MouseDown(object sender, MouseButtonEventArgs e)