Merge branch 'net6' into net462
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
<UserControl x:Class="Ink_Canvas.Controls.BoardToolbarButton"
|
||||
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="50" d:DesignWidth="60">
|
||||
<Border x:Name="ButtonBorder"
|
||||
Width="60" Height="50"
|
||||
MouseDown="ButtonBorder_MouseDown"
|
||||
MouseUp="ButtonBorder_MouseUp"
|
||||
Background="{DynamicResource BoardFloatBarBackground}"
|
||||
Opacity="1"
|
||||
BorderThickness="1"
|
||||
BorderBrush="{DynamicResource BoardFloatBarBorderBrush}">
|
||||
<Grid Margin="6,6,6,4">
|
||||
<Image x:Name="ButtonImage"
|
||||
VerticalAlignment="Top"
|
||||
RenderOptions.BitmapScalingMode="HighQuality"
|
||||
Height="20" Width="20">
|
||||
<Image.Source>
|
||||
<DrawingImage>
|
||||
<DrawingImage.Drawing>
|
||||
<DrawingGroup ClipGeometry="M0,0 V24 H24 V0 H0 Z">
|
||||
<GeometryDrawing x:Name="IconGeometryInternal"
|
||||
Brush="{DynamicResource IconForeground}" />
|
||||
<GeometryDrawing x:Name="IconGeometryInternal2"
|
||||
Brush="{DynamicResource IconForeground}" />
|
||||
</DrawingGroup>
|
||||
</DrawingImage.Drawing>
|
||||
</DrawingImage>
|
||||
</Image.Source>
|
||||
</Image>
|
||||
<TextBlock x:Name="LabelTextBlock"
|
||||
Foreground="{DynamicResource FloatBarForeground}"
|
||||
VerticalAlignment="Bottom"
|
||||
HorizontalAlignment="Center"
|
||||
FontSize="12" />
|
||||
</Grid>
|
||||
</Border>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,195 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace Ink_Canvas.Controls
|
||||
{
|
||||
public enum ButtonPosition
|
||||
{
|
||||
First,
|
||||
Middle,
|
||||
Last,
|
||||
Single
|
||||
}
|
||||
|
||||
public partial class BoardToolbarButton : UserControl
|
||||
{
|
||||
public static readonly DependencyProperty LabelProperty = DependencyProperty.Register(
|
||||
nameof(Label), typeof(string), typeof(BoardToolbarButton),
|
||||
new PropertyMetadata(string.Empty, OnLabelChanged));
|
||||
|
||||
private static void OnLabelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var button = (BoardToolbarButton)d;
|
||||
if (button.LabelTextBlock != null)
|
||||
button.LabelTextBlock.Text = (string)e.NewValue;
|
||||
}
|
||||
|
||||
public string Label
|
||||
{
|
||||
get => (string)GetValue(LabelProperty);
|
||||
set => SetValue(LabelProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IconGeometryProperty = DependencyProperty.Register(
|
||||
nameof(IconGeometry), typeof(string), typeof(BoardToolbarButton),
|
||||
new PropertyMetadata(string.Empty, OnIconGeometryChanged));
|
||||
|
||||
private static void OnIconGeometryChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var button = (BoardToolbarButton)d;
|
||||
if (button.IconGeometryInternal != null && e.NewValue is string geometry && !string.IsNullOrEmpty(geometry))
|
||||
{
|
||||
button.IconGeometryInternal.Geometry = Geometry.Parse(geometry);
|
||||
}
|
||||
}
|
||||
|
||||
public string IconGeometry
|
||||
{
|
||||
get => (string)GetValue(IconGeometryProperty);
|
||||
set => SetValue(IconGeometryProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty PositionProperty = DependencyProperty.Register(
|
||||
nameof(Position), typeof(ButtonPosition), typeof(BoardToolbarButton),
|
||||
new PropertyMetadata(ButtonPosition.Middle, OnPositionChanged));
|
||||
|
||||
private static void OnPositionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var button = (BoardToolbarButton)d;
|
||||
button.UpdateCornerRadius((ButtonPosition)e.NewValue);
|
||||
}
|
||||
|
||||
public ButtonPosition Position
|
||||
{
|
||||
get => (ButtonPosition)GetValue(PositionProperty);
|
||||
set => SetValue(PositionProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IconBrushProperty = DependencyProperty.Register(
|
||||
nameof(IconBrush), typeof(Brush), typeof(BoardToolbarButton),
|
||||
new PropertyMetadata(null, OnIconBrushChanged));
|
||||
|
||||
private static void OnIconBrushChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var button = (BoardToolbarButton)d;
|
||||
if (button.IconGeometryInternal != null && e.NewValue is Brush brush)
|
||||
{
|
||||
button.IconGeometryInternal.Brush = brush;
|
||||
}
|
||||
}
|
||||
|
||||
public Brush IconBrush
|
||||
{
|
||||
get => (Brush)GetValue(IconBrushProperty);
|
||||
set => SetValue(IconBrushProperty, value);
|
||||
}
|
||||
|
||||
public event MouseButtonEventHandler ButtonMouseDown;
|
||||
public event MouseButtonEventHandler ButtonMouseUp;
|
||||
|
||||
public GeometryDrawing IconGeometryDrawing => IconGeometryInternal;
|
||||
public GeometryDrawing IconGeometryDrawing2 => IconGeometryInternal2;
|
||||
|
||||
public Border ButtonBorderControl => ButtonBorder;
|
||||
|
||||
public TextBlock LabelTextBlockControl => LabelTextBlock;
|
||||
|
||||
public new Brush Background
|
||||
{
|
||||
get => ButtonBorder.Background;
|
||||
set => ButtonBorder.Background = value;
|
||||
}
|
||||
|
||||
public new Brush BorderBrush
|
||||
{
|
||||
get => ButtonBorder.BorderBrush;
|
||||
set => ButtonBorder.BorderBrush = value;
|
||||
}
|
||||
|
||||
public new Brush Foreground
|
||||
{
|
||||
get => LabelTextBlock.Foreground;
|
||||
set => LabelTextBlock.Foreground = value;
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IsEnabledBindingProperty = DependencyProperty.Register(
|
||||
nameof(IsEnabledBinding), typeof(bool?), typeof(BoardToolbarButton),
|
||||
new PropertyMetadata(null, OnIsEnabledBindingChanged));
|
||||
|
||||
private static void OnIsEnabledBindingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var button = (BoardToolbarButton)d;
|
||||
if (e.NewValue is bool isEnabled)
|
||||
{
|
||||
button.IsEnabled = isEnabled;
|
||||
button.UpdateIconOpacity(isEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
public bool? IsEnabledBinding
|
||||
{
|
||||
get => (bool?)GetValue(IsEnabledBindingProperty);
|
||||
set => SetValue(IsEnabledBindingProperty, value);
|
||||
}
|
||||
|
||||
private void UpdateIconOpacity(bool isEnabled)
|
||||
{
|
||||
if (ButtonImage != null)
|
||||
{
|
||||
ButtonImage.Opacity = isEnabled ? 1.0 : 0.4;
|
||||
}
|
||||
}
|
||||
|
||||
public BoardToolbarButton()
|
||||
{
|
||||
InitializeComponent();
|
||||
Loaded += BoardToolbarButton_Loaded;
|
||||
}
|
||||
|
||||
private void BoardToolbarButton_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
UpdateCornerRadius(Position);
|
||||
if (!string.IsNullOrEmpty(IconGeometry))
|
||||
{
|
||||
IconGeometryInternal.Geometry = Geometry.Parse(IconGeometry);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateCornerRadius(ButtonPosition position)
|
||||
{
|
||||
if (ButtonBorder == null) return;
|
||||
|
||||
switch (position)
|
||||
{
|
||||
case ButtonPosition.First:
|
||||
ButtonBorder.CornerRadius = new CornerRadius(5, 0, 0, 5);
|
||||
ButtonBorder.BorderThickness = new Thickness(1, 1, 0, 1);
|
||||
break;
|
||||
case ButtonPosition.Middle:
|
||||
ButtonBorder.CornerRadius = new CornerRadius(0);
|
||||
ButtonBorder.BorderThickness = new Thickness(0, 1, 0, 1);
|
||||
break;
|
||||
case ButtonPosition.Last:
|
||||
ButtonBorder.CornerRadius = new CornerRadius(0, 5, 5, 0);
|
||||
ButtonBorder.BorderThickness = new Thickness(0, 1, 1, 1);
|
||||
break;
|
||||
case ButtonPosition.Single:
|
||||
ButtonBorder.CornerRadius = new CornerRadius(5);
|
||||
ButtonBorder.BorderThickness = new Thickness(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonBorder_MouseDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
ButtonMouseDown?.Invoke(this, e);
|
||||
}
|
||||
|
||||
private void ButtonBorder_MouseUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
ButtonMouseUp?.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<UserControl x:Class="Ink_Canvas.Controls.CircularColorButton"
|
||||
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"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="45" d:DesignWidth="45">
|
||||
<Border x:Name="ButtonBorder"
|
||||
BorderBrush="#fed7aa"
|
||||
BorderThickness="1.5"
|
||||
CornerRadius="100"
|
||||
MouseDown="ButtonBorder_MouseDown"
|
||||
MouseLeave="ButtonBorder_MouseLeave"
|
||||
MouseUp="ButtonBorder_MouseUp">
|
||||
<Canvas x:Name="ButtonCanvas">
|
||||
<Image x:Name="TransparentGridImage"
|
||||
Source="/Resources/Icons-png/transparent-grid.png"
|
||||
RenderOptions.BitmapScalingMode="HighQuality">
|
||||
<Image.Clip>
|
||||
<EllipseGeometry x:Name="ImageClipGeometry" Center="21,21" RadiusX="21" RadiusY="21"/>
|
||||
</Image.Clip>
|
||||
</Image>
|
||||
<Border x:Name="ColorOverlay"
|
||||
CornerRadius="21"
|
||||
Opacity="0.75"/>
|
||||
<Viewbox x:Name="CheckViewbox"
|
||||
Visibility="Visible"
|
||||
Canvas.Top="9"
|
||||
Canvas.Left="9"
|
||||
Width="24"
|
||||
Height="24">
|
||||
<Image x:Name="CheckImage"
|
||||
Source="/Resources/new-icons/checked-white.png"
|
||||
RenderOptions.BitmapScalingMode="HighQuality"
|
||||
VerticalAlignment="Top"/>
|
||||
</Viewbox>
|
||||
</Canvas>
|
||||
</Border>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,200 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace Ink_Canvas.Controls
|
||||
{
|
||||
public partial class CircularColorButton : UserControl
|
||||
{
|
||||
public static readonly DependencyProperty ColorProperty = DependencyProperty.Register(
|
||||
nameof(Color), typeof(Color), typeof(CircularColorButton),
|
||||
new PropertyMetadata(Colors.Transparent, OnColorChanged));
|
||||
|
||||
private static void OnColorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var button = (CircularColorButton)d;
|
||||
if (button.ColorOverlay != null)
|
||||
button.ColorOverlay.Background = new SolidColorBrush((Color)e.NewValue);
|
||||
}
|
||||
|
||||
public Color Color
|
||||
{
|
||||
get => (Color)GetValue(ColorProperty);
|
||||
set => SetValue(ColorProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ColorOpacityProperty = DependencyProperty.Register(
|
||||
nameof(ColorOpacity), typeof(double), typeof(CircularColorButton),
|
||||
new PropertyMetadata(0.75, OnColorOpacityChanged));
|
||||
|
||||
private static void OnColorOpacityChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var button = (CircularColorButton)d;
|
||||
if (button.ColorOverlay != null)
|
||||
button.ColorOverlay.Opacity = (double)e.NewValue;
|
||||
}
|
||||
|
||||
public double ColorOpacity
|
||||
{
|
||||
get => (double)GetValue(ColorOpacityProperty);
|
||||
set => SetValue(ColorOpacityProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IsCheckedProperty = DependencyProperty.Register(
|
||||
nameof(IsChecked), typeof(bool), typeof(CircularColorButton),
|
||||
new PropertyMetadata(true, OnIsCheckedChanged));
|
||||
|
||||
private static void OnIsCheckedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var button = (CircularColorButton)d;
|
||||
if (button.CheckViewbox != null)
|
||||
button.CheckViewbox.Visibility = (bool)e.NewValue ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
|
||||
public bool IsChecked
|
||||
{
|
||||
get => (bool)GetValue(IsCheckedProperty);
|
||||
set => SetValue(IsCheckedProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ButtonSizeProperty = DependencyProperty.Register(
|
||||
nameof(ButtonSize), typeof(double), typeof(CircularColorButton),
|
||||
new PropertyMetadata(45.0, OnButtonSizeChanged));
|
||||
|
||||
private static void OnButtonSizeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var button = (CircularColorButton)d;
|
||||
if (button.ButtonBorder == null || button.ColorOverlay == null) return;
|
||||
|
||||
var size = (double)e.NewValue;
|
||||
button.ButtonBorder.Width = size;
|
||||
button.ButtonBorder.Height = size;
|
||||
var radius = (size - 3) / 2;
|
||||
button.ColorOverlay.Width = radius * 2;
|
||||
button.ColorOverlay.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
|
||||
{
|
||||
get => (double)GetValue(ButtonSizeProperty);
|
||||
set => SetValue(ButtonSizeProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty BorderBrushColorProperty = DependencyProperty.Register(
|
||||
nameof(BorderBrushColor), typeof(Color), typeof(CircularColorButton),
|
||||
new PropertyMetadata(Color.FromRgb(254, 215, 170), OnBorderBrushColorChanged));
|
||||
|
||||
private static void OnBorderBrushColorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var button = (CircularColorButton)d;
|
||||
if (button.ButtonBorder != null)
|
||||
button.ButtonBorder.BorderBrush = new SolidColorBrush((Color)e.NewValue);
|
||||
}
|
||||
|
||||
public Color BorderBrushColor
|
||||
{
|
||||
get => (Color)GetValue(BorderBrushColorProperty);
|
||||
set => SetValue(BorderBrushColorProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty CheckIconSourceProperty = DependencyProperty.Register(
|
||||
nameof(CheckIconSource), typeof(string), typeof(CircularColorButton),
|
||||
new PropertyMetadata("/Resources/new-icons/checked-white.png", OnCheckIconSourceChanged));
|
||||
|
||||
private static void OnCheckIconSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var button = (CircularColorButton)d;
|
||||
if (button.CheckImage != null)
|
||||
button.CheckImage.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri((string)e.NewValue, UriKind.Relative));
|
||||
}
|
||||
|
||||
public string CheckIconSource
|
||||
{
|
||||
get => (string)GetValue(CheckIconSourceProperty);
|
||||
set => SetValue(CheckIconSourceProperty, value);
|
||||
}
|
||||
|
||||
public event MouseButtonEventHandler ButtonMouseDown;
|
||||
public event MouseEventHandler ButtonMouseLeave;
|
||||
public event RoutedEventHandler ButtonMouseUp;
|
||||
|
||||
public CircularColorButton()
|
||||
{
|
||||
InitializeComponent();
|
||||
Loaded += CircularColorButton_Loaded;
|
||||
}
|
||||
|
||||
private void CircularColorButton_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ApplyAllProperties();
|
||||
}
|
||||
|
||||
private void ApplyAllProperties()
|
||||
{
|
||||
if (ButtonBorder != null)
|
||||
{
|
||||
ButtonBorder.BorderBrush = new SolidColorBrush(BorderBrushColor);
|
||||
var size = ButtonSize;
|
||||
ButtonBorder.Width = size;
|
||||
ButtonBorder.Height = size;
|
||||
}
|
||||
if (ColorOverlay != null)
|
||||
{
|
||||
ColorOverlay.Background = new SolidColorBrush(Color);
|
||||
ColorOverlay.Opacity = ColorOpacity;
|
||||
var radius = (ButtonSize - 3) / 2;
|
||||
ColorOverlay.Width = radius * 2;
|
||||
ColorOverlay.Height = radius * 2;
|
||||
}
|
||||
if (ImageClipGeometry != null)
|
||||
{
|
||||
var radius = (ButtonSize - 3) / 2;
|
||||
ImageClipGeometry.RadiusX = radius;
|
||||
ImageClipGeometry.RadiusY = radius;
|
||||
ImageClipGeometry.Center = new Point(radius, radius);
|
||||
}
|
||||
if (TransparentGridImage != null)
|
||||
{
|
||||
var radius = (ButtonSize - 3) / 2;
|
||||
TransparentGridImage.Width = radius * 2;
|
||||
TransparentGridImage.Height = radius * 2;
|
||||
}
|
||||
if (CheckViewbox != null)
|
||||
{
|
||||
CheckViewbox.Visibility = IsChecked ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
if (CheckImage != null)
|
||||
{
|
||||
CheckImage.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri(CheckIconSource, UriKind.Relative));
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonBorder_MouseDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
ButtonMouseDown?.Invoke(this, e);
|
||||
}
|
||||
|
||||
private void ButtonBorder_MouseLeave(object sender, MouseEventArgs e)
|
||||
{
|
||||
ButtonMouseLeave?.Invoke(this, e);
|
||||
}
|
||||
|
||||
private void ButtonBorder_MouseUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
ButtonMouseUp?.Invoke(this, new RoutedEventArgs(e.RoutedEvent, this));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<UserControl x:Class="Ink_Canvas.Controls.ColorPickerButton"
|
||||
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"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="13" d:DesignWidth="13">
|
||||
<Border x:Name="ButtonBorder"
|
||||
BorderBrush="#CCCCCC"
|
||||
BorderThickness="1"
|
||||
CornerRadius="3"
|
||||
Margin="1,0,1,0"
|
||||
MouseDown="ButtonBorder_MouseDown"
|
||||
MouseLeave="ButtonBorder_MouseLeave"
|
||||
MouseUp="ButtonBorder_MouseUp">
|
||||
<Border.Style>
|
||||
<Style TargetType="Border">
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="BorderThickness" Value="2"/>
|
||||
<Setter Property="BorderBrush" Value="#666666"/>
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Border.Style>
|
||||
<Grid>
|
||||
<Path x:Name="CheckPath"
|
||||
Data="M9,20.42L2.79,14.21L5.62,11.38L9,14.77L18.88,4.88L21.71,7.71L9,20.42Z"
|
||||
Stretch="Uniform"
|
||||
Opacity="1.0"
|
||||
Visibility="Collapsed"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,148 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace Ink_Canvas.Controls
|
||||
{
|
||||
public partial class ColorPickerButton : UserControl
|
||||
{
|
||||
public static readonly DependencyProperty ColorProperty = DependencyProperty.Register(
|
||||
nameof(Color), typeof(Color), typeof(ColorPickerButton),
|
||||
new PropertyMetadata(Colors.Black, OnColorChanged));
|
||||
|
||||
private static void OnColorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var button = (ColorPickerButton)d;
|
||||
if (button.ButtonBorder != null)
|
||||
button.ButtonBorder.Background = new SolidColorBrush((Color)e.NewValue);
|
||||
}
|
||||
|
||||
public Color Color
|
||||
{
|
||||
get => (Color)GetValue(ColorProperty);
|
||||
set => SetValue(ColorProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IsCheckedProperty = DependencyProperty.Register(
|
||||
nameof(IsChecked), typeof(bool), typeof(ColorPickerButton),
|
||||
new PropertyMetadata(false, OnIsCheckedChanged));
|
||||
|
||||
private static void OnIsCheckedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var button = (ColorPickerButton)d;
|
||||
if (button.CheckPath != null)
|
||||
button.CheckPath.Visibility = (bool)e.NewValue ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
|
||||
public bool IsChecked
|
||||
{
|
||||
get => (bool)GetValue(IsCheckedProperty);
|
||||
set => SetValue(IsCheckedProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty CheckIconFillProperty = DependencyProperty.Register(
|
||||
nameof(CheckIconFill), typeof(Brush), typeof(ColorPickerButton),
|
||||
new PropertyMetadata(Brushes.White, OnCheckIconFillChanged));
|
||||
|
||||
private static void OnCheckIconFillChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var button = (ColorPickerButton)d;
|
||||
if (button.CheckPath != null)
|
||||
button.CheckPath.Fill = (Brush)e.NewValue;
|
||||
}
|
||||
|
||||
public Brush CheckIconFill
|
||||
{
|
||||
get => (Brush)GetValue(CheckIconFillProperty);
|
||||
set => SetValue(CheckIconFillProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ButtonSizeProperty = DependencyProperty.Register(
|
||||
nameof(ButtonSize), typeof(double), typeof(ColorPickerButton),
|
||||
new PropertyMetadata(13.0, OnButtonSizeChanged));
|
||||
|
||||
private static void OnButtonSizeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var button = (ColorPickerButton)d;
|
||||
if (button.ButtonBorder != null)
|
||||
{
|
||||
button.ButtonBorder.Width = (double)e.NewValue;
|
||||
button.ButtonBorder.Height = (double)e.NewValue;
|
||||
}
|
||||
}
|
||||
|
||||
public double ButtonSize
|
||||
{
|
||||
get => (double)GetValue(ButtonSizeProperty);
|
||||
set => SetValue(ButtonSizeProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty CheckIconSizeProperty = DependencyProperty.Register(
|
||||
nameof(CheckIconSize), typeof(double), typeof(ColorPickerButton),
|
||||
new PropertyMetadata(8.0, OnCheckIconSizeChanged));
|
||||
|
||||
private static void OnCheckIconSizeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var button = (ColorPickerButton)d;
|
||||
if (button.CheckPath != null)
|
||||
{
|
||||
button.CheckPath.Width = (double)e.NewValue;
|
||||
button.CheckPath.Height = (double)e.NewValue;
|
||||
}
|
||||
}
|
||||
|
||||
public double CheckIconSize
|
||||
{
|
||||
get => (double)GetValue(CheckIconSizeProperty);
|
||||
set => SetValue(CheckIconSizeProperty, value);
|
||||
}
|
||||
|
||||
public event MouseButtonEventHandler ButtonMouseDown;
|
||||
public event MouseEventHandler ButtonMouseLeave;
|
||||
public event RoutedEventHandler ButtonMouseUp;
|
||||
|
||||
public ColorPickerButton()
|
||||
{
|
||||
InitializeComponent();
|
||||
Loaded += ColorPickerButton_Loaded;
|
||||
}
|
||||
|
||||
private void ColorPickerButton_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ApplyAllProperties();
|
||||
}
|
||||
|
||||
private void ApplyAllProperties()
|
||||
{
|
||||
if (ButtonBorder != null)
|
||||
{
|
||||
ButtonBorder.Background = new SolidColorBrush(Color);
|
||||
ButtonBorder.Width = ButtonSize;
|
||||
ButtonBorder.Height = ButtonSize;
|
||||
}
|
||||
if (CheckPath != null)
|
||||
{
|
||||
CheckPath.Fill = CheckIconFill;
|
||||
CheckPath.Width = CheckIconSize;
|
||||
CheckPath.Height = CheckIconSize;
|
||||
CheckPath.Visibility = IsChecked ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonBorder_MouseDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
ButtonMouseDown?.Invoke(this, e);
|
||||
}
|
||||
|
||||
private void ButtonBorder_MouseLeave(object sender, MouseEventArgs e)
|
||||
{
|
||||
ButtonMouseLeave?.Invoke(this, e);
|
||||
}
|
||||
|
||||
private void ButtonBorder_MouseUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
ButtonMouseUp?.Invoke(this, new RoutedEventArgs(e.RoutedEvent, this));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<UserControl x:Class="Ink_Canvas.Controls.CopyButton"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern">
|
||||
<Button x:Name="CopyButtonControl" Padding="6" Click="CopyButton_Click"
|
||||
ToolTipService.ToolTip="Copy">
|
||||
<Grid>
|
||||
<ui:FontIcon x:Name="FontIcon_Copy" FontSize="16"
|
||||
Icon="{x:Static ui:SegoeFluentIcons.Copy}" RenderTransformOrigin="0.5 0.5">
|
||||
<FrameworkElement.RenderTransform>
|
||||
<ScaleTransform x:Name="ScaleTransform_Copy"
|
||||
ScaleX="1" ScaleY="{Binding ScaleX, RelativeSource={RelativeSource Self}}"/>
|
||||
</FrameworkElement.RenderTransform>
|
||||
</ui:FontIcon>
|
||||
<ui:FontIcon x:Name="FontIcon_Success" FontSize="16"
|
||||
Icon="{x:Static ui:SegoeFluentIcons.CheckMark}" RenderTransformOrigin="0.5 0.5">
|
||||
<FrameworkElement.RenderTransform>
|
||||
<ScaleTransform x:Name="ScaleTransform_Success"
|
||||
ScaleX="0" ScaleY="{Binding ScaleX, RelativeSource={RelativeSource Self}}"/>
|
||||
</FrameworkElement.RenderTransform>
|
||||
</ui:FontIcon>
|
||||
</Grid>
|
||||
</Button>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,115 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Animation;
|
||||
|
||||
namespace Ink_Canvas.Controls
|
||||
{
|
||||
public partial class CopyButton : UserControl
|
||||
{
|
||||
public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
|
||||
nameof(Text), typeof(string), typeof(CopyButton), new PropertyMetadata(string.Empty));
|
||||
|
||||
public string Text
|
||||
{
|
||||
get => (string)GetValue(TextProperty);
|
||||
set => SetValue(TextProperty, value);
|
||||
}
|
||||
|
||||
public event EventHandler Click;
|
||||
|
||||
public CopyButton()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void CopyButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Text))
|
||||
{
|
||||
Clipboard.SetText(Text);
|
||||
}
|
||||
|
||||
ShowSuccessAnimation();
|
||||
Click?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.ToString(), "Unable to Perform Copy", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private async void ShowSuccessAnimation()
|
||||
{
|
||||
var copyScaleAnim = new DoubleAnimation
|
||||
{
|
||||
To = 0,
|
||||
Duration = TimeSpan.FromMilliseconds(150)
|
||||
};
|
||||
ScaleTransform_Copy.BeginAnimation(ScaleTransform.ScaleXProperty, copyScaleAnim);
|
||||
|
||||
var copyOpacityAnim = new DoubleAnimation
|
||||
{
|
||||
To = 0,
|
||||
BeginTime = TimeSpan.FromMilliseconds(100),
|
||||
Duration = TimeSpan.FromMilliseconds(10)
|
||||
};
|
||||
FontIcon_Copy.BeginAnimation(UIElement.OpacityProperty, copyOpacityAnim);
|
||||
|
||||
await Task.Delay(150);
|
||||
var successScaleAnim = new DoubleAnimation
|
||||
{
|
||||
To = 1,
|
||||
Duration = TimeSpan.FromMilliseconds(150),
|
||||
EasingFunction = new BackEase { EasingMode = EasingMode.EaseOut, Amplitude = 0.2 }
|
||||
};
|
||||
ScaleTransform_Success.BeginAnimation(ScaleTransform.ScaleXProperty, successScaleAnim);
|
||||
|
||||
var successOpacityAnim = new DoubleAnimation
|
||||
{
|
||||
To = 1,
|
||||
Duration = TimeSpan.FromMilliseconds(15)
|
||||
};
|
||||
FontIcon_Success.BeginAnimation(UIElement.OpacityProperty, successOpacityAnim);
|
||||
|
||||
await Task.Delay(1000);
|
||||
ShowCopyAnimation();
|
||||
}
|
||||
|
||||
private async void ShowCopyAnimation()
|
||||
{
|
||||
var successOpacityAnim = new DoubleAnimation
|
||||
{
|
||||
To = 0,
|
||||
Duration = TimeSpan.FromMilliseconds(150)
|
||||
};
|
||||
FontIcon_Success.BeginAnimation(UIElement.OpacityProperty, successOpacityAnim);
|
||||
|
||||
await Task.Delay(150);
|
||||
var copyScaleAnim = new DoubleAnimation
|
||||
{
|
||||
To = 1,
|
||||
Duration = TimeSpan.Zero
|
||||
};
|
||||
ScaleTransform_Copy.BeginAnimation(ScaleTransform.ScaleXProperty, copyScaleAnim);
|
||||
|
||||
var copyOpacityAnim = new DoubleAnimation
|
||||
{
|
||||
To = 1,
|
||||
Duration = TimeSpan.FromMilliseconds(150)
|
||||
};
|
||||
FontIcon_Copy.BeginAnimation(UIElement.OpacityProperty, copyOpacityAnim);
|
||||
|
||||
var successScaleAnim = new DoubleAnimation
|
||||
{
|
||||
To = 0,
|
||||
Duration = TimeSpan.Zero
|
||||
};
|
||||
ScaleTransform_Success.BeginAnimation(ScaleTransform.ScaleXProperty, successScaleAnim);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<UserControl x:Class="Ink_Canvas.Controls.GeometryButton"
|
||||
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="38" d:DesignWidth="32">
|
||||
<ikw:SimpleStackPanel x:Name="ButtonPanel"
|
||||
MouseDown="ButtonPanel_MouseDown"
|
||||
MouseUp="ButtonPanel_MouseUp"
|
||||
Background="Transparent"
|
||||
Orientation="Vertical"
|
||||
Height="38" Width="32"
|
||||
Margin="0,0,0,0">
|
||||
<Image x:Name="ButtonImage"
|
||||
RenderOptions.BitmapScalingMode="HighQuality"
|
||||
Margin="0,4,0,2" Height="19" Width="19" />
|
||||
<Label x:Name="LabelControl"
|
||||
FontSize="8"
|
||||
HorizontalAlignment="Center" />
|
||||
</ikw:SimpleStackPanel>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,62 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace Ink_Canvas.Controls
|
||||
{
|
||||
public partial class GeometryButton : UserControl
|
||||
{
|
||||
public static readonly DependencyProperty LabelProperty = DependencyProperty.Register(
|
||||
nameof(Label), typeof(string), typeof(GeometryButton),
|
||||
new PropertyMetadata(string.Empty, OnLabelChanged));
|
||||
|
||||
private static void OnLabelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var button = (GeometryButton)d;
|
||||
if (button.LabelControl != null)
|
||||
button.LabelControl.Content = (string)e.NewValue;
|
||||
}
|
||||
|
||||
public string Label
|
||||
{
|
||||
get => (string)GetValue(LabelProperty);
|
||||
set => SetValue(LabelProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IconSourceProperty = DependencyProperty.Register(
|
||||
nameof(IconSource), typeof(ImageSource), typeof(GeometryButton),
|
||||
new PropertyMetadata(null, OnIconSourceChanged));
|
||||
|
||||
private static void OnIconSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var button = (GeometryButton)d;
|
||||
if (button.ButtonImage != null)
|
||||
button.ButtonImage.Source = (ImageSource)e.NewValue;
|
||||
}
|
||||
|
||||
public ImageSource IconSource
|
||||
{
|
||||
get => (ImageSource)GetValue(IconSourceProperty);
|
||||
set => SetValue(IconSourceProperty, value);
|
||||
}
|
||||
|
||||
public event MouseButtonEventHandler ButtonMouseDown;
|
||||
public event MouseButtonEventHandler ButtonMouseUp;
|
||||
|
||||
public GeometryButton()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void ButtonPanel_MouseDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
ButtonMouseDown?.Invoke(this, e);
|
||||
}
|
||||
|
||||
private void ButtonPanel_MouseUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
ButtonMouseUp?.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net462</TargetFramework>
|
||||
<Nullable>disable</Nullable>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<RootNamespace>Ink_Canvas.Controls</RootNamespace>
|
||||
<AssemblyName>InkCanvas.Controls</AssemblyName>
|
||||
<UseWPF>true</UseWPF>
|
||||
<EnableWindowsTargeting>true</EnableWindowsTargeting>
|
||||
<LangVersion>10</LangVersion>
|
||||
<NoWarn>CA1416</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="iNKORE.UI.WPF.Modern" Version="0.10.2.1" />
|
||||
<PackageReference Include="iNKORE.UI.WPF" Version="1.2.8" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,15 @@
|
||||
<UserControl x:Class="Ink_Canvas.Controls.LabeledSettingsCard"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
|
||||
xmlns:ikw="http://schemas.inkore.net/lib/ui/wpf">
|
||||
<ui:SettingsCard x:Name="SettingsCard"
|
||||
Description="{Binding Description, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
||||
Header="{Binding Header, RelativeSource={RelativeSource AncestorType=UserControl}}">
|
||||
<ui:ToggleSwitch x:Name="ToggleSwitch"
|
||||
OnContent="{DynamicResource Common_On}"
|
||||
OffContent="{DynamicResource Common_Off}"
|
||||
IsOn="{Binding IsOn, RelativeSource={RelativeSource AncestorType=UserControl}, Mode=TwoWay}"
|
||||
Toggled="ToggleSwitch_Toggled"/>
|
||||
</ui:SettingsCard>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,161 @@
|
||||
using iNKORE.UI.WPF.Modern.Common.IconKeys;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace Ink_Canvas.Controls
|
||||
{
|
||||
public partial class LabeledSettingsCard : UserControl
|
||||
{
|
||||
public iNKORE.UI.WPF.Modern.Controls.ToggleSwitch ToggleSwitchControl => ToggleSwitch;
|
||||
|
||||
public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register(
|
||||
nameof(Header), typeof(string), typeof(LabeledSettingsCard), new PropertyMetadata(string.Empty));
|
||||
|
||||
public string Header
|
||||
{
|
||||
get => (string)GetValue(HeaderProperty);
|
||||
set => SetValue(HeaderProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register(
|
||||
nameof(Description), typeof(string), typeof(LabeledSettingsCard), new PropertyMetadata(string.Empty));
|
||||
|
||||
public string Description
|
||||
{
|
||||
get => (string)GetValue(DescriptionProperty);
|
||||
set => SetValue(DescriptionProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IconProperty = DependencyProperty.Register(
|
||||
nameof(Icon), typeof(FontIconData?), typeof(LabeledSettingsCard), new PropertyMetadata(null, OnIconChanged));
|
||||
|
||||
public FontIconData? Icon
|
||||
{
|
||||
get => (FontIconData?)GetValue(IconProperty);
|
||||
set => SetValue(IconProperty, value);
|
||||
}
|
||||
|
||||
private static void OnIconChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (d is LabeledSettingsCard control)
|
||||
control.ApplyIcon();
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IconSourceProperty = DependencyProperty.Register(
|
||||
nameof(IconSource), typeof(ImageSource), typeof(LabeledSettingsCard), new PropertyMetadata(null, OnIconSourceChanged));
|
||||
|
||||
public ImageSource IconSource
|
||||
{
|
||||
get => (ImageSource)GetValue(IconSourceProperty);
|
||||
set => SetValue(IconSourceProperty, value);
|
||||
}
|
||||
|
||||
private static void OnIconSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (d is LabeledSettingsCard control)
|
||||
control.ApplyIcon();
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty HeaderIconProperty = DependencyProperty.Register(
|
||||
nameof(HeaderIcon), typeof(object), typeof(LabeledSettingsCard), new PropertyMetadata(null, OnHeaderIconChanged));
|
||||
|
||||
public object HeaderIcon
|
||||
{
|
||||
get => GetValue(HeaderIconProperty);
|
||||
set => SetValue(HeaderIconProperty, value);
|
||||
}
|
||||
|
||||
private static void OnHeaderIconChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (d is LabeledSettingsCard control)
|
||||
control.ApplyIcon();
|
||||
}
|
||||
|
||||
private void ApplyIcon()
|
||||
{
|
||||
if (SettingsCard == null) return;
|
||||
|
||||
if (IconSource != null)
|
||||
{
|
||||
SettingsCard.HeaderIcon = new Image
|
||||
{
|
||||
Source = IconSource,
|
||||
Width = 16,
|
||||
Height = 16,
|
||||
};
|
||||
}
|
||||
else if (Icon.HasValue)
|
||||
{
|
||||
SettingsCard.HeaderIcon = new iNKORE.UI.WPF.Modern.Controls.FontIcon(Icon.Value);
|
||||
}
|
||||
else if (HeaderIcon != null)
|
||||
{
|
||||
SettingsCard.HeaderIcon = HeaderIcon;
|
||||
}
|
||||
else
|
||||
{
|
||||
SettingsCard.HeaderIcon = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IsOnProperty = DependencyProperty.Register(
|
||||
nameof(IsOn), typeof(bool), typeof(LabeledSettingsCard), new PropertyMetadata(false));
|
||||
|
||||
public bool IsOn
|
||||
{
|
||||
get => (bool)GetValue(IsOnProperty);
|
||||
set => SetValue(IsOnProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ShowWhenProperty = DependencyProperty.Register(
|
||||
nameof(ShowWhen), typeof(bool), typeof(LabeledSettingsCard), new PropertyMetadata(true, OnShowWhenChanged));
|
||||
|
||||
public bool ShowWhen
|
||||
{
|
||||
get => (bool)GetValue(ShowWhenProperty);
|
||||
set => SetValue(ShowWhenProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty SwitchNameProperty = DependencyProperty.Register(
|
||||
nameof(SwitchName), typeof(string), typeof(LabeledSettingsCard), new PropertyMetadata(string.Empty, OnSwitchNameChanged));
|
||||
|
||||
public string SwitchName
|
||||
{
|
||||
get => (string)GetValue(SwitchNameProperty);
|
||||
set => SetValue(SwitchNameProperty, value);
|
||||
}
|
||||
|
||||
private static void OnSwitchNameChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (d is LabeledSettingsCard control && control.ToggleSwitch != null)
|
||||
control.ToggleSwitch.Name = (string)e.NewValue;
|
||||
}
|
||||
|
||||
private static void OnShowWhenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (d is LabeledSettingsCard control)
|
||||
control.Visibility = (bool)e.NewValue ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
|
||||
public event RoutedEventHandler Toggled;
|
||||
|
||||
public LabeledSettingsCard()
|
||||
{
|
||||
InitializeComponent();
|
||||
Loaded += LabeledSettingsCard_Loaded;
|
||||
}
|
||||
|
||||
private void LabeledSettingsCard_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(SwitchName) && ToggleSwitch != null)
|
||||
ToggleSwitch.Name = SwitchName;
|
||||
ApplyIcon();
|
||||
}
|
||||
|
||||
private void ToggleSwitch_Toggled(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Toggled?.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<UserControl x:Class="Ink_Canvas.Controls.LabeledToggleSwitch"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
|
||||
xmlns:ikw="http://schemas.inkore.net/lib/ui/wpf">
|
||||
<ikw:SimpleStackPanel Spacing="4">
|
||||
<ikw:SimpleStackPanel Orientation="Horizontal" HorizontalAlignment="Left">
|
||||
<TextBlock Text="{Binding Label, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="#fafafa"
|
||||
FontSize="14"
|
||||
Margin="0,0,16,0"/>
|
||||
<ui:ToggleSwitch x:Name="ToggleSwitch"
|
||||
OnContent="{Binding OnContent, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
||||
OffContent="{Binding OffContent, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
||||
IsOn="{Binding IsOn, RelativeSource={RelativeSource AncestorType=UserControl}, Mode=TwoWay}"
|
||||
FontWeight="Bold"
|
||||
Toggled="ToggleSwitch_Toggled"/>
|
||||
</ikw:SimpleStackPanel>
|
||||
<TextBlock x:Name="HintTextBlock"
|
||||
Text="{Binding Hint, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
||||
TextWrapping="Wrap"
|
||||
Foreground="#a1a1aa"
|
||||
Visibility="Collapsed"/>
|
||||
</ikw:SimpleStackPanel>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,96 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using ui = iNKORE.UI.WPF.Modern.Controls;
|
||||
|
||||
namespace Ink_Canvas.Controls
|
||||
{
|
||||
public partial class LabeledToggleSwitch : UserControl
|
||||
{
|
||||
public ui.ToggleSwitch ToggleSwitchControl => ToggleSwitch;
|
||||
|
||||
public static readonly DependencyProperty LabelProperty = DependencyProperty.Register(
|
||||
nameof(Label), typeof(string), typeof(LabeledToggleSwitch), new PropertyMetadata(string.Empty));
|
||||
|
||||
public string Label
|
||||
{
|
||||
get => (string)GetValue(LabelProperty);
|
||||
set => SetValue(LabelProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty HintProperty = DependencyProperty.Register(
|
||||
nameof(Hint), typeof(string), typeof(LabeledToggleSwitch), new PropertyMetadata(string.Empty, OnHintChanged));
|
||||
|
||||
public string Hint
|
||||
{
|
||||
get => (string)GetValue(HintProperty);
|
||||
set => SetValue(HintProperty, value);
|
||||
}
|
||||
|
||||
private static void OnHintChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (d is LabeledToggleSwitch control)
|
||||
{
|
||||
var hint = e.NewValue as string;
|
||||
control.HintTextBlock.Visibility = string.IsNullOrEmpty(hint) ? Visibility.Collapsed : Visibility.Visible;
|
||||
}
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IsOnProperty = DependencyProperty.Register(
|
||||
nameof(IsOn), typeof(bool), typeof(LabeledToggleSwitch), new PropertyMetadata(false));
|
||||
|
||||
public bool IsOn
|
||||
{
|
||||
get => (bool)GetValue(IsOnProperty);
|
||||
set => SetValue(IsOnProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty OnContentProperty = DependencyProperty.Register(
|
||||
nameof(OnContent), typeof(string), typeof(LabeledToggleSwitch), new PropertyMetadata(string.Empty));
|
||||
|
||||
public string OnContent
|
||||
{
|
||||
get => (string)GetValue(OnContentProperty);
|
||||
set => SetValue(OnContentProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty OffContentProperty = DependencyProperty.Register(
|
||||
nameof(OffContent), typeof(string), typeof(LabeledToggleSwitch), new PropertyMetadata(string.Empty));
|
||||
|
||||
public string OffContent
|
||||
{
|
||||
get => (string)GetValue(OffContentProperty);
|
||||
set => SetValue(OffContentProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ShowWhenProperty = DependencyProperty.Register(
|
||||
nameof(ShowWhen), typeof(bool), typeof(LabeledToggleSwitch), new PropertyMetadata(true, OnShowWhenChanged));
|
||||
|
||||
public bool ShowWhen
|
||||
{
|
||||
get => (bool)GetValue(ShowWhenProperty);
|
||||
set => SetValue(ShowWhenProperty, value);
|
||||
}
|
||||
|
||||
private static void OnShowWhenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (d is LabeledToggleSwitch control)
|
||||
{
|
||||
control.Visibility = (bool)e.NewValue ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
}
|
||||
|
||||
public event RoutedEventHandler Toggled;
|
||||
|
||||
public LabeledToggleSwitch()
|
||||
{
|
||||
InitializeComponent();
|
||||
Visibility = ShowWhen ? Visibility.Visible : Visibility.Collapsed;
|
||||
HintTextBlock.Visibility = string.IsNullOrEmpty(Hint) ? Visibility.Collapsed : Visibility.Visible;
|
||||
}
|
||||
|
||||
private void ToggleSwitch_Toggled(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Toggled?.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<UserControl x:Class="Ink_Canvas.Controls.PenColorButton"
|
||||
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"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="45" d:DesignWidth="45">
|
||||
<Border x:Name="ButtonBorder"
|
||||
BorderThickness="1.5"
|
||||
CornerRadius="100"
|
||||
Width="45" Height="45"
|
||||
MouseUp="ButtonBorder_MouseUp">
|
||||
<Canvas x:Name="RootCanvas">
|
||||
<Image x:Name="TransparentGridImage"
|
||||
Source="/Resources/Icons-png/transparent-grid.png"
|
||||
Width="42" Height="42"
|
||||
Visibility="Collapsed">
|
||||
<Image.Clip>
|
||||
<EllipseGeometry x:Name="ClipGeometry"
|
||||
Center="21,21"
|
||||
RadiusX="21"
|
||||
RadiusY="21" />
|
||||
</Image.Clip>
|
||||
</Image>
|
||||
<Border x:Name="ColorBorder"
|
||||
Width="42" Height="42"
|
||||
CornerRadius="21"
|
||||
Opacity="1" />
|
||||
<Viewbox x:Name="CheckViewbox"
|
||||
Visibility="Collapsed"
|
||||
Margin="8"
|
||||
Canvas.Top="0"
|
||||
Canvas.Left="0">
|
||||
<Image x:Name="CheckImage"
|
||||
RenderOptions.BitmapScalingMode="HighQuality"
|
||||
VerticalAlignment="Top"
|
||||
Width="24" Height="24" />
|
||||
</Viewbox>
|
||||
</Canvas>
|
||||
</Border>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,141 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace Ink_Canvas.Controls
|
||||
{
|
||||
public partial class PenColorButton : UserControl
|
||||
{
|
||||
public static readonly DependencyProperty ColorProperty = DependencyProperty.Register(
|
||||
nameof(Color), typeof(Color), typeof(PenColorButton),
|
||||
new PropertyMetadata(Colors.Black, OnColorChanged));
|
||||
|
||||
private static void OnColorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var button = (PenColorButton)d;
|
||||
if (button.ColorBorder != null)
|
||||
{
|
||||
button.ColorBorder.Background = new SolidColorBrush((Color)e.NewValue);
|
||||
}
|
||||
}
|
||||
|
||||
public Color Color
|
||||
{
|
||||
get => (Color)GetValue(ColorProperty);
|
||||
set => SetValue(ColorProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty BorderBrushColorProperty = DependencyProperty.Register(
|
||||
nameof(BorderBrushColor), typeof(Color), typeof(PenColorButton),
|
||||
new PropertyMetadata(Colors.Gray, OnBorderBrushColorChanged));
|
||||
|
||||
private static void OnBorderBrushColorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var button = (PenColorButton)d;
|
||||
if (button.ButtonBorder != null)
|
||||
{
|
||||
button.ButtonBorder.BorderBrush = new SolidColorBrush((Color)e.NewValue);
|
||||
}
|
||||
}
|
||||
|
||||
public Color BorderBrushColor
|
||||
{
|
||||
get => (Color)GetValue(BorderBrushColorProperty);
|
||||
set => SetValue(BorderBrushColorProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IsHighlighterProperty = DependencyProperty.Register(
|
||||
nameof(IsHighlighter), typeof(bool), typeof(PenColorButton),
|
||||
new PropertyMetadata(false, OnIsHighlighterChanged));
|
||||
|
||||
private static void OnIsHighlighterChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var button = (PenColorButton)d;
|
||||
if (button.TransparentGridImage != null && button.ColorBorder != null)
|
||||
{
|
||||
bool isHighlighter = (bool)e.NewValue;
|
||||
button.TransparentGridImage.Visibility = isHighlighter ? Visibility.Visible : Visibility.Collapsed;
|
||||
button.ColorBorder.Opacity = isHighlighter ? 0.75 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsHighlighter
|
||||
{
|
||||
get => (bool)GetValue(IsHighlighterProperty);
|
||||
set => SetValue(IsHighlighterProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IsCheckedProperty = DependencyProperty.Register(
|
||||
nameof(IsChecked), typeof(bool), typeof(PenColorButton),
|
||||
new PropertyMetadata(false, OnIsCheckedChanged));
|
||||
|
||||
private static void OnIsCheckedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var button = (PenColorButton)d;
|
||||
if (button.CheckViewbox != null)
|
||||
{
|
||||
button.CheckViewbox.Visibility = (bool)e.NewValue ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsChecked
|
||||
{
|
||||
get => (bool)GetValue(IsCheckedProperty);
|
||||
set => SetValue(IsCheckedProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty CheckIconSourceProperty = DependencyProperty.Register(
|
||||
nameof(CheckIconSource), typeof(string), typeof(PenColorButton),
|
||||
new PropertyMetadata("/Resources/new-icons/checked-white.png", OnCheckIconSourceChanged));
|
||||
|
||||
private static void OnCheckIconSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var button = (PenColorButton)d;
|
||||
if (button.CheckImage != null && e.NewValue is string source)
|
||||
{
|
||||
button.CheckImage.Source = new System.Windows.Media.Imaging.BitmapImage(new System.Uri(source, System.UriKind.Relative));
|
||||
}
|
||||
}
|
||||
|
||||
public string CheckIconSource
|
||||
{
|
||||
get => (string)GetValue(CheckIconSourceProperty);
|
||||
set => SetValue(CheckIconSourceProperty, value);
|
||||
}
|
||||
|
||||
public event MouseButtonEventHandler ButtonMouseUp;
|
||||
|
||||
public PenColorButton()
|
||||
{
|
||||
InitializeComponent();
|
||||
Loaded += PenColorButton_Loaded;
|
||||
}
|
||||
|
||||
private void PenColorButton_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ApplyProperties();
|
||||
}
|
||||
|
||||
private void ApplyProperties()
|
||||
{
|
||||
if (ColorBorder != null)
|
||||
ColorBorder.Background = new SolidColorBrush(Color);
|
||||
if (ButtonBorder != null)
|
||||
ButtonBorder.BorderBrush = new SolidColorBrush(BorderBrushColor);
|
||||
if (TransparentGridImage != null)
|
||||
TransparentGridImage.Visibility = IsHighlighter ? Visibility.Visible : Visibility.Collapsed;
|
||||
if (ColorBorder != null)
|
||||
ColorBorder.Opacity = IsHighlighter ? 0.75 : 1;
|
||||
if (CheckViewbox != null)
|
||||
CheckViewbox.Visibility = IsChecked ? Visibility.Visible : Visibility.Collapsed;
|
||||
if (CheckImage != null && !string.IsNullOrEmpty(CheckIconSource))
|
||||
CheckImage.Source = new System.Windows.Media.Imaging.BitmapImage(new System.Uri(CheckIconSource, System.UriKind.Relative));
|
||||
}
|
||||
|
||||
private void ButtonBorder_MouseUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
ButtonMouseUp?.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 MouseButtonEventHandler ButtonMouseUp;
|
||||
|
||||
public QuickPanelButton()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void ButtonPanel_MouseUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
ButtonMouseUp?.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<UserControl x:Class="Ink_Canvas.Controls.ToolMenuButton"
|
||||
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="38" d:DesignWidth="32">
|
||||
<ikw:SimpleStackPanel x:Name="ButtonPanel"
|
||||
MouseDown="ButtonPanel_MouseDown"
|
||||
MouseLeave="ButtonPanel_MouseLeave"
|
||||
MouseUp="ButtonPanel_MouseUp"
|
||||
Background="Transparent"
|
||||
Orientation="Vertical"
|
||||
HorizontalAlignment="Center"
|
||||
Height="38" Width="32"
|
||||
Margin="0">
|
||||
<Image x:Name="ButtonImage"
|
||||
Margin="0,4,0,2"
|
||||
Height="19" Width="19"
|
||||
RenderOptions.BitmapScalingMode="HighQuality">
|
||||
<Image.Source>
|
||||
<DrawingImage>
|
||||
<DrawingImage.Drawing>
|
||||
<DrawingGroup ClipGeometry="M0,0 V24 H24 V0 H0 Z">
|
||||
<GeometryDrawing x:Name="IconGeometryInternal"
|
||||
Brush="{DynamicResource IconForeground}" />
|
||||
</DrawingGroup>
|
||||
</DrawingImage.Drawing>
|
||||
</DrawingImage>
|
||||
</Image.Source>
|
||||
</Image>
|
||||
<Label x:Name="LabelControl"
|
||||
FontSize="8"
|
||||
HorizontalAlignment="Center"
|
||||
Foreground="{DynamicResource FloatBarForeground}" />
|
||||
</ikw:SimpleStackPanel>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,121 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
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));
|
||||
|
||||
private static void OnLabelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var button = (ToolMenuButton)d;
|
||||
if (button.LabelControl != null)
|
||||
button.LabelControl.Content = (string)e.NewValue;
|
||||
}
|
||||
|
||||
public string Label
|
||||
{
|
||||
get => (string)GetValue(LabelProperty);
|
||||
set => SetValue(LabelProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IconGeometryProperty = DependencyProperty.Register(
|
||||
nameof(IconGeometry), typeof(string), typeof(ToolMenuButton),
|
||||
new PropertyMetadata(string.Empty, OnIconGeometryChanged));
|
||||
|
||||
private static void OnIconGeometryChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var button = (ToolMenuButton)d;
|
||||
if (e.NewValue is string geometry && !string.IsNullOrEmpty(geometry))
|
||||
{
|
||||
button._pendingGeometry = Geometry.Parse(geometry);
|
||||
if (button.IconGeometryInternal != null)
|
||||
button.IconGeometryInternal.Geometry = button._pendingGeometry;
|
||||
}
|
||||
}
|
||||
|
||||
public string IconGeometry
|
||||
{
|
||||
get => (string)GetValue(IconGeometryProperty);
|
||||
set => SetValue(IconGeometryProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IconBrushProperty = DependencyProperty.Register(
|
||||
nameof(IconBrush), typeof(Brush), typeof(ToolMenuButton),
|
||||
new PropertyMetadata(null, OnIconBrushChanged));
|
||||
|
||||
private static void OnIconBrushChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var button = (ToolMenuButton)d;
|
||||
button._pendingBrush = (Brush)e.NewValue;
|
||||
if (button.IconGeometryInternal != null)
|
||||
button.IconGeometryInternal.Brush = button._pendingBrush;
|
||||
}
|
||||
|
||||
public Brush IconBrush
|
||||
{
|
||||
get => (Brush)GetValue(IconBrushProperty);
|
||||
set => SetValue(IconBrushProperty, value);
|
||||
}
|
||||
|
||||
public new Brush Background
|
||||
{
|
||||
get => ButtonPanel.Background;
|
||||
set => ButtonPanel.Background = value;
|
||||
}
|
||||
|
||||
public GeometryDrawing Icon
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IconGeometryInternal != null)
|
||||
return IconGeometryInternal;
|
||||
return new GeometryDrawing(_pendingBrush, null, _pendingGeometry);
|
||||
}
|
||||
}
|
||||
|
||||
public event MouseButtonEventHandler ButtonMouseDown;
|
||||
public event MouseEventHandler ButtonMouseLeave;
|
||||
public event MouseButtonEventHandler ButtonMouseUp;
|
||||
|
||||
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)
|
||||
{
|
||||
ButtonMouseDown?.Invoke(this, e);
|
||||
}
|
||||
|
||||
private void ButtonPanel_MouseLeave(object sender, MouseEventArgs e)
|
||||
{
|
||||
ButtonMouseLeave?.Invoke(this, e);
|
||||
}
|
||||
|
||||
private void ButtonPanel_MouseUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
ButtonMouseUp?.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<UserControl x:Class="Ink_Canvas.Controls.ToolbarImageButton"
|
||||
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="45" d:DesignWidth="28">
|
||||
<ikw:SimpleStackPanel Name="ButtonPanel"
|
||||
MouseDown="ButtonPanel_MouseDown"
|
||||
MouseLeave="ButtonPanel_MouseLeave"
|
||||
MouseUp="ButtonPanel_MouseUp"
|
||||
Background="Transparent" Orientation="Vertical"
|
||||
HorizontalAlignment="Center" Width="28" Margin="0,-2">
|
||||
<Image x:Name="ButtonImage" RenderOptions.BitmapScalingMode="HighQuality" Height="17" Margin="0,3,0,0">
|
||||
<Image.Source>
|
||||
<DrawingImage>
|
||||
<DrawingImage.Drawing>
|
||||
<DrawingGroup ClipGeometry="M0,0 V24 H24 V0 H0 Z">
|
||||
<GeometryDrawing x:Name="IconGeometryInternal" Brush="{DynamicResource IconForeground}" />
|
||||
</DrawingGroup>
|
||||
</DrawingImage.Drawing>
|
||||
</DrawingImage>
|
||||
</Image.Source>
|
||||
</Image>
|
||||
<TextBlock x:Name="LabelTextBlock"
|
||||
Foreground="{DynamicResource FloatBarForeground}"
|
||||
FontSize="8"
|
||||
Margin="0,1,0,0" TextAlignment="Center"
|
||||
Style="{DynamicResource AutoFitMainToolbarLabel8}" />
|
||||
</ikw:SimpleStackPanel>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,124 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace Ink_Canvas.Controls
|
||||
{
|
||||
public partial class ToolbarImageButton : UserControl
|
||||
{
|
||||
private static ToolbarImageButton _lastPressedButton;
|
||||
|
||||
public static readonly DependencyProperty LabelProperty = DependencyProperty.Register(
|
||||
nameof(Label), typeof(string), typeof(ToolbarImageButton),
|
||||
new PropertyMetadata(string.Empty, (d, e) => ((ToolbarImageButton)d).LabelTextBlock.Text = (string)e.NewValue));
|
||||
|
||||
public string Label
|
||||
{
|
||||
get => (string)GetValue(LabelProperty);
|
||||
set => SetValue(LabelProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IconGeometryDrawingProperty = DependencyProperty.Register(
|
||||
nameof(IconGeometryDrawing), typeof(GeometryDrawing), typeof(ToolbarImageButton),
|
||||
new PropertyMetadata(null, OnIconGeometryDrawingChanged));
|
||||
|
||||
private static void OnIconGeometryDrawingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var button = (ToolbarImageButton)d;
|
||||
if (e.NewValue is GeometryDrawing newDrawing)
|
||||
{
|
||||
button.IconGeometryInternal.Geometry = newDrawing.Geometry;
|
||||
button.IconGeometryInternal.Brush = newDrawing.Brush;
|
||||
}
|
||||
}
|
||||
|
||||
public GeometryDrawing IconGeometryDrawing
|
||||
{
|
||||
get => (GeometryDrawing)GetValue(IconGeometryDrawingProperty);
|
||||
set => SetValue(IconGeometryDrawingProperty, value);
|
||||
}
|
||||
|
||||
public GeometryDrawing Icon => IconGeometryInternal;
|
||||
|
||||
public GeometryDrawing GeometryDrawing => IconGeometryInternal;
|
||||
|
||||
public static readonly DependencyProperty IconBrushProperty = DependencyProperty.Register(
|
||||
nameof(IconBrush), typeof(Brush), typeof(ToolbarImageButton),
|
||||
new PropertyMetadata(null, (d, e) => ((ToolbarImageButton)d).IconGeometryInternal.Brush = (Brush)e.NewValue));
|
||||
|
||||
public Brush IconBrush
|
||||
{
|
||||
get => (Brush)GetValue(IconBrushProperty);
|
||||
set => SetValue(IconBrushProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty LabelBrushProperty = DependencyProperty.Register(
|
||||
nameof(LabelBrush), typeof(Brush), typeof(ToolbarImageButton),
|
||||
new PropertyMetadata(null, (d, e) =>
|
||||
{
|
||||
var b = (ToolbarImageButton)d;
|
||||
if (e.NewValue is Brush brush) b.LabelTextBlock.Foreground = brush;
|
||||
}));
|
||||
|
||||
public Brush LabelBrush
|
||||
{
|
||||
get => (Brush)GetValue(LabelBrushProperty);
|
||||
set => SetValue(LabelBrushProperty, value);
|
||||
}
|
||||
|
||||
public new Brush Background
|
||||
{
|
||||
get => ButtonPanel.Background;
|
||||
set => ButtonPanel.Background = value;
|
||||
}
|
||||
|
||||
public event MouseButtonEventHandler ButtonMouseDown;
|
||||
public event MouseEventHandler ButtonMouseLeave;
|
||||
public event MouseButtonEventHandler ButtonMouseUp;
|
||||
|
||||
public ToolbarImageButton()
|
||||
{
|
||||
InitializeComponent();
|
||||
ButtonPanel.Background = Brushes.Transparent;
|
||||
IsEnabledChanged += ToolbarImageButton_IsEnabledChanged;
|
||||
}
|
||||
|
||||
private void ToolbarImageButton_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var isEnabled = (bool)e.NewValue;
|
||||
ButtonImage.Opacity = isEnabled ? 1.0 : 0.5;
|
||||
LabelTextBlock.Opacity = isEnabled ? 1.0 : 0.5;
|
||||
ButtonPanel.IsEnabled = isEnabled;
|
||||
}
|
||||
|
||||
private void ButtonPanel_MouseDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (!IsEnabled) return;
|
||||
if (_lastPressedButton != null && _lastPressedButton != this)
|
||||
{
|
||||
_lastPressedButton.Background = Brushes.Transparent;
|
||||
}
|
||||
_lastPressedButton = this;
|
||||
ButtonPanel.Background = new SolidColorBrush(Color.FromArgb(28, 24, 24, 27));
|
||||
ButtonMouseDown?.Invoke(this, e);
|
||||
}
|
||||
|
||||
private void ButtonPanel_MouseLeave(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (!IsEnabled) return;
|
||||
ButtonMouseLeave?.Invoke(this, e);
|
||||
}
|
||||
|
||||
private void ButtonPanel_MouseUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (!IsEnabled) return;
|
||||
if (_lastPressedButton == this)
|
||||
{
|
||||
ButtonPanel.Background = Brushes.Transparent;
|
||||
_lastPressedButton = null;
|
||||
}
|
||||
ButtonMouseUp?.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user