新增图片选择选项
This commit is contained in:
+73
-12
@@ -3159,33 +3159,94 @@
|
|||||||
HorizontalAlignment="Left" VerticalAlignment="Top" Margin="800,900,0,0"
|
HorizontalAlignment="Left" VerticalAlignment="Top" Margin="800,900,0,0"
|
||||||
CornerRadius="5" Height="80"
|
CornerRadius="5" Height="80"
|
||||||
Background="{DynamicResource FloatBarBackground}"
|
Background="{DynamicResource FloatBarBackground}"
|
||||||
Visibility="Collapsed"
|
Visibility="{Binding ElementName=GridInkCanvasSelectionCover, Path=Visibility}"
|
||||||
BorderThickness="1" BorderBrush="{DynamicResource FloatBarBorderBrush}">
|
BorderThickness="1" BorderBrush="{DynamicResource FloatBarBorderBrush}">
|
||||||
<Viewbox Margin="0,-2.5">
|
<Viewbox Margin="0,-2.5">
|
||||||
<ui:SimpleStackPanel Orientation="Horizontal" Spacing="10" Height="60">
|
<ui:SimpleStackPanel Orientation="Horizontal" Spacing="10" Height="60">
|
||||||
<Border Name="BorderImageRotateLeft" Margin="0,2,-9,2" Background="Transparent"
|
<Border Name="BorderImageClone" Margin="0,2,-9,2" Background="Transparent"
|
||||||
CornerRadius="{Binding ElementName=BorderImageSelectionControl, Path=CornerRadius}"
|
CornerRadius="{Binding ElementName=BorderImageSelectionControl, Path=CornerRadius}"
|
||||||
Width="40" MouseDown="Border_MouseDown" MouseUp="BorderImageRotateLeft_MouseUp">
|
Width="40" MouseDown="Border_MouseDown" MouseUp="BorderImageClone_MouseUp">
|
||||||
<ui:SimpleStackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
|
<ui:SimpleStackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
|
||||||
<Image Source="/Resources/Icons-Fluent/ic_fluent_flip_horizontal_24_regular.png"
|
<Image Source="/Resources/Icons-Fluent/ic_fluent_copy_24_regular.png"
|
||||||
RenderOptions.BitmapScalingMode="HighQuality" Height="25" Width="25" />
|
RenderOptions.BitmapScalingMode="HighQuality" Height="25" Width="25" />
|
||||||
<TextBlock Text="左转" FontSize="10" Foreground="{DynamicResource FloatBarForeground}"
|
<TextBlock Text="克隆" FontSize="10" Foreground="{DynamicResource FloatBarForeground}"
|
||||||
HorizontalAlignment="Center" />
|
HorizontalAlignment="Center" />
|
||||||
</ui:SimpleStackPanel>
|
</ui:SimpleStackPanel>
|
||||||
</Border>
|
</Border>
|
||||||
<Border Name="BorderImageRotateRight" Margin="0,2,-9,2" Background="Transparent"
|
<Border Name="BorderImageCloneToNewBoard"
|
||||||
|
Margin="0,2,-9,2"
|
||||||
|
Background="Transparent"
|
||||||
CornerRadius="{Binding ElementName=BorderImageSelectionControl, Path=CornerRadius}"
|
CornerRadius="{Binding ElementName=BorderImageSelectionControl, Path=CornerRadius}"
|
||||||
Width="40" MouseDown="Border_MouseDown" MouseUp="BorderImageRotateRight_MouseUp">
|
Width="40"
|
||||||
<ui:SimpleStackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
|
MouseDown="Border_MouseDown"
|
||||||
<Image Source="/Resources/Icons-Fluent/ic_fluent_flip_vertical_24_regular.png"
|
MouseUp="BorderImageCloneToNewBoard_MouseUp"
|
||||||
RenderOptions.BitmapScalingMode="HighQuality" Height="25" Width="25" />
|
Visibility="{Binding Visibility, ElementName=GridBackgroundCover}">
|
||||||
<TextBlock Text="右转" FontSize="10" Foreground="{DynamicResource FloatBarForeground}"
|
<ui:SimpleStackPanel VerticalAlignment="Center"
|
||||||
|
HorizontalAlignment="Center">
|
||||||
|
<Image Source="/Resources/Icons-Fluent/ic_fluent_copy_add_24_regular.png"
|
||||||
|
RenderOptions.BitmapScalingMode="HighQuality"
|
||||||
|
Height="25"
|
||||||
|
Width="25" />
|
||||||
|
<TextBlock Text="克隆至新页"
|
||||||
|
FontSize="8"
|
||||||
|
Foreground="{DynamicResource FloatBarForeground}"
|
||||||
HorizontalAlignment="Center" />
|
HorizontalAlignment="Center" />
|
||||||
</ui:SimpleStackPanel>
|
</ui:SimpleStackPanel>
|
||||||
</Border>
|
</Border>
|
||||||
|
<Border Width="1"
|
||||||
|
Height="45"
|
||||||
|
BorderBrush="{DynamicResource FloatBarForeground}"
|
||||||
|
Background="{DynamicResource FloatBarForeground}" />
|
||||||
|
<Border CornerRadius="{Binding ElementName=BorderImageSelectionControl, Path=CornerRadius}"
|
||||||
|
Height="40">
|
||||||
|
<ui:SimpleStackPanel VerticalAlignment="Center"
|
||||||
|
Spacing="5"
|
||||||
|
Margin="0,-10">
|
||||||
|
<ui:SimpleStackPanel Orientation="Horizontal"
|
||||||
|
Spacing="10">
|
||||||
|
<Image Source="{DynamicResource Rotate45DrawingImage}"
|
||||||
|
Height="22"
|
||||||
|
MouseDown="Border_MouseDown"
|
||||||
|
MouseUp="BorderImageRotateLeft_MouseUp" />
|
||||||
|
<Image Source="{DynamicResource Rotate90DrawingImage}"
|
||||||
|
Height="22"
|
||||||
|
MouseDown="Border_MouseDown"
|
||||||
|
MouseUp="BorderImageRotateRight_MouseUp" />
|
||||||
|
</ui:SimpleStackPanel>
|
||||||
|
<TextBlock Text="旋转"
|
||||||
|
FontSize="10"
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
Foreground="{DynamicResource FloatBarForeground}" />
|
||||||
|
</ui:SimpleStackPanel>
|
||||||
|
</Border>
|
||||||
<Border Width="1" Height="45" BorderBrush="{DynamicResource FloatBarForeground}"
|
<Border Width="1" Height="45" BorderBrush="{DynamicResource FloatBarForeground}"
|
||||||
Background="{DynamicResource FloatBarForeground}" />
|
Background="{DynamicResource FloatBarForeground}" />
|
||||||
<Border Name="BorderImageDelete" Margin="-8,0,0,0"
|
<Border CornerRadius="{Binding ElementName=BorderImageSelectionControl, Path=CornerRadius}"
|
||||||
|
Height="40">
|
||||||
|
<ui:SimpleStackPanel VerticalAlignment="Center" Spacing="5" Margin="0,-10">
|
||||||
|
<ui:SimpleStackPanel Orientation="Horizontal" Spacing="10">
|
||||||
|
<Grid MouseDown="Border_MouseDown" MouseUp="GridImageScaleDecrease_MouseUp">
|
||||||
|
<Image Source="/Resources/Icons-Fluent/ic_fluent_scale_fit_24_regular.png"
|
||||||
|
RenderOptions.BitmapScalingMode="HighQuality" Height="25" Width="25" />
|
||||||
|
<TextBlock Text="-" Foreground="{DynamicResource FloatBarForeground}"
|
||||||
|
VerticalAlignment="Bottom" HorizontalAlignment="Right"
|
||||||
|
Margin="0,0,-2,-7" FontSize="15" />
|
||||||
|
</Grid>
|
||||||
|
<Grid MouseDown="Border_MouseDown" MouseUp="GridImageScaleIncrease_MouseUp">
|
||||||
|
<Image Source="/Resources/Icons-Fluent/ic_fluent_scale_fit_24_regular.png"
|
||||||
|
RenderOptions.BitmapScalingMode="HighQuality" Height="25" Width="25" />
|
||||||
|
<TextBlock Text="+" Foreground="{DynamicResource FloatBarForeground}"
|
||||||
|
VerticalAlignment="Bottom" HorizontalAlignment="Right"
|
||||||
|
Margin="0,0,-3,-4" FontSize="11" />
|
||||||
|
</Grid>
|
||||||
|
</ui:SimpleStackPanel>
|
||||||
|
<TextBlock Text="缩放" FontSize="10" HorizontalAlignment="Center"
|
||||||
|
Foreground="{DynamicResource FloatBarForeground}" />
|
||||||
|
</ui:SimpleStackPanel>
|
||||||
|
</Border>
|
||||||
|
<Border Width="1" Height="45" BorderBrush="{DynamicResource FloatBarForeground}"
|
||||||
|
Background="{DynamicResource FloatBarForeground}" />
|
||||||
|
<Border Margin="-8,0,0,0"
|
||||||
CornerRadius="{Binding ElementName=BorderImageSelectionControl, Path=CornerRadius}"
|
CornerRadius="{Binding ElementName=BorderImageSelectionControl, Path=CornerRadius}"
|
||||||
Width="40" MouseDown="Border_MouseDown" MouseUp="BorderImageDelete_MouseUp">
|
Width="40" MouseDown="Border_MouseDown" MouseUp="BorderImageDelete_MouseUp">
|
||||||
<ui:SimpleStackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
|
<ui:SimpleStackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
|
||||||
|
|||||||
@@ -1521,8 +1521,30 @@ namespace Ink_Canvas {
|
|||||||
|
|
||||||
#region Image Toolbar Event Handlers
|
#region Image Toolbar Event Handlers
|
||||||
|
|
||||||
|
private void BorderImageClone_MouseUp(object sender, MouseButtonEventArgs e)
|
||||||
|
{
|
||||||
|
if (lastBorderMouseDownObject != sender) return;
|
||||||
|
|
||||||
|
if (selectedUIElement is Image image)
|
||||||
|
{
|
||||||
|
CloneImage(image);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BorderImageCloneToNewBoard_MouseUp(object sender, MouseButtonEventArgs e)
|
||||||
|
{
|
||||||
|
if (lastBorderMouseDownObject != sender) return;
|
||||||
|
|
||||||
|
if (selectedUIElement is Image image)
|
||||||
|
{
|
||||||
|
CloneImageToNewBoard(image);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void BorderImageRotateLeft_MouseUp(object sender, MouseButtonEventArgs e)
|
private void BorderImageRotateLeft_MouseUp(object sender, MouseButtonEventArgs e)
|
||||||
{
|
{
|
||||||
|
if (lastBorderMouseDownObject != sender) return;
|
||||||
|
|
||||||
if (selectedUIElement is Image image)
|
if (selectedUIElement is Image image)
|
||||||
{
|
{
|
||||||
RotateImage(image, -90);
|
RotateImage(image, -90);
|
||||||
@@ -1531,14 +1553,38 @@ namespace Ink_Canvas {
|
|||||||
|
|
||||||
private void BorderImageRotateRight_MouseUp(object sender, MouseButtonEventArgs e)
|
private void BorderImageRotateRight_MouseUp(object sender, MouseButtonEventArgs e)
|
||||||
{
|
{
|
||||||
|
if (lastBorderMouseDownObject != sender) return;
|
||||||
|
|
||||||
if (selectedUIElement is Image image)
|
if (selectedUIElement is Image image)
|
||||||
{
|
{
|
||||||
RotateImage(image, 90);
|
RotateImage(image, 90);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void GridImageScaleIncrease_MouseUp(object sender, MouseButtonEventArgs e)
|
||||||
|
{
|
||||||
|
if (lastBorderMouseDownObject != sender) return;
|
||||||
|
|
||||||
|
if (selectedUIElement is Image image)
|
||||||
|
{
|
||||||
|
ScaleImage(image, 1.25); // 放大5%
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void GridImageScaleDecrease_MouseUp(object sender, MouseButtonEventArgs e)
|
||||||
|
{
|
||||||
|
if (lastBorderMouseDownObject != sender) return;
|
||||||
|
|
||||||
|
if (selectedUIElement is Image image)
|
||||||
|
{
|
||||||
|
ScaleImage(image, 0.8); // 缩小5%
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void BorderImageDelete_MouseUp(object sender, MouseButtonEventArgs e)
|
private void BorderImageDelete_MouseUp(object sender, MouseButtonEventArgs e)
|
||||||
{
|
{
|
||||||
|
if (lastBorderMouseDownObject != sender) return;
|
||||||
|
|
||||||
if (selectedUIElement is Image image)
|
if (selectedUIElement is Image image)
|
||||||
{
|
{
|
||||||
DeleteImage(image);
|
DeleteImage(image);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.IO;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Input;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using Ink_Canvas.Helpers;
|
using Ink_Canvas.Helpers;
|
||||||
@@ -219,6 +220,152 @@ namespace Ink_Canvas
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 克隆图片
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="image">要克隆的图片</param>
|
||||||
|
private void CloneImage(Image image)
|
||||||
|
{
|
||||||
|
if (image == null) return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// 创建图片的副本
|
||||||
|
var clonedImage = new Image
|
||||||
|
{
|
||||||
|
Source = image.Source,
|
||||||
|
Width = image.Width,
|
||||||
|
Height = image.Height,
|
||||||
|
Stretch = image.Stretch,
|
||||||
|
RenderTransform = image.RenderTransform?.Clone() as Transform
|
||||||
|
};
|
||||||
|
|
||||||
|
// 设置位置,稍微偏移以避免重叠
|
||||||
|
InkCanvas.SetLeft(clonedImage, InkCanvas.GetLeft(image) + 20);
|
||||||
|
InkCanvas.SetTop(clonedImage, InkCanvas.GetTop(image) + 20);
|
||||||
|
|
||||||
|
// 添加鼠标事件处理,使图片可以被选择
|
||||||
|
clonedImage.MouseDown += UIElement_MouseDown;
|
||||||
|
clonedImage.IsManipulationEnabled = true;
|
||||||
|
|
||||||
|
// 添加到画布
|
||||||
|
inkCanvas.Children.Add(clonedImage);
|
||||||
|
|
||||||
|
// 选择新克隆的图片
|
||||||
|
DeselectUIElement();
|
||||||
|
SelectUIElement(clonedImage);
|
||||||
|
|
||||||
|
// 提交到时间机器以支持撤销
|
||||||
|
timeMachine.CommitElementInsertHistory(clonedImage);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
// 记录错误但不中断程序
|
||||||
|
System.Diagnostics.Debug.WriteLine($"克隆图片时发生错误: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 克隆图片到新页面
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="image">要克隆的图片</param>
|
||||||
|
private void CloneImageToNewBoard(Image image)
|
||||||
|
{
|
||||||
|
if (image == null) return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// 创建图片的副本
|
||||||
|
var clonedImage = new Image
|
||||||
|
{
|
||||||
|
Source = image.Source,
|
||||||
|
Width = image.Width,
|
||||||
|
Height = image.Height,
|
||||||
|
Stretch = image.Stretch,
|
||||||
|
RenderTransform = image.RenderTransform?.Clone() as Transform
|
||||||
|
};
|
||||||
|
|
||||||
|
// 设置位置,稍微偏移以避免重叠
|
||||||
|
InkCanvas.SetLeft(clonedImage, InkCanvas.GetLeft(image) + 20);
|
||||||
|
InkCanvas.SetTop(clonedImage, InkCanvas.GetTop(image) + 20);
|
||||||
|
|
||||||
|
// 添加鼠标事件处理,使图片可以被选择
|
||||||
|
clonedImage.MouseDown += UIElement_MouseDown;
|
||||||
|
clonedImage.IsManipulationEnabled = true;
|
||||||
|
|
||||||
|
// 创建新页面
|
||||||
|
BtnWhiteBoardAdd_Click(null, null);
|
||||||
|
|
||||||
|
// 添加到新页面的画布
|
||||||
|
inkCanvas.Children.Add(clonedImage);
|
||||||
|
|
||||||
|
// 选择新克隆的图片
|
||||||
|
DeselectUIElement();
|
||||||
|
SelectUIElement(clonedImage);
|
||||||
|
|
||||||
|
// 提交到时间机器以支持撤销
|
||||||
|
timeMachine.CommitElementInsertHistory(clonedImage);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
// 记录错误但不中断程序
|
||||||
|
System.Diagnostics.Debug.WriteLine($"克隆图片到新页面时发生错误: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 缩放图片
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="image">要缩放的图片</param>
|
||||||
|
/// <param name="scaleFactor">缩放因子(大于1为放大,小于1为缩小)</param>
|
||||||
|
private void ScaleImage(Image image, double scaleFactor)
|
||||||
|
{
|
||||||
|
if (image == null) return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// 获取当前的变换
|
||||||
|
var transformGroup = image.RenderTransform as TransformGroup ?? new TransformGroup();
|
||||||
|
|
||||||
|
// 查找现有的缩放变换
|
||||||
|
ScaleTransform scaleTransform = null;
|
||||||
|
foreach (Transform transform in transformGroup.Children)
|
||||||
|
{
|
||||||
|
if (transform is ScaleTransform st)
|
||||||
|
{
|
||||||
|
scaleTransform = st;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果没有缩放变换,创建一个新的
|
||||||
|
if (scaleTransform == null)
|
||||||
|
{
|
||||||
|
scaleTransform = new ScaleTransform();
|
||||||
|
transformGroup.Children.Add(scaleTransform);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置缩放中心为图片中心
|
||||||
|
scaleTransform.CenterX = image.ActualWidth / 2;
|
||||||
|
scaleTransform.CenterY = image.ActualHeight / 2;
|
||||||
|
|
||||||
|
// 应用缩放因子
|
||||||
|
scaleTransform.ScaleX *= scaleFactor;
|
||||||
|
scaleTransform.ScaleY *= scaleFactor;
|
||||||
|
|
||||||
|
// 应用变换
|
||||||
|
image.RenderTransform = transformGroup;
|
||||||
|
|
||||||
|
// 提交到时间机器以支持撤销
|
||||||
|
// 注意:缩放操作目前不支持撤销,因为需要更复杂的历史记录机制
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
// 记录错误但不中断程序
|
||||||
|
System.Diagnostics.Debug.WriteLine($"缩放图片时发生错误: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 删除图片
|
/// 删除图片
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -166,6 +166,7 @@ namespace Ink_Canvas {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ... existing code ...
|
||||||
private void ImageRotate45_MouseUp(object sender, MouseButtonEventArgs e) {
|
private void ImageRotate45_MouseUp(object sender, MouseButtonEventArgs e) {
|
||||||
if (lastBorderMouseDownObject != sender) return;
|
if (lastBorderMouseDownObject != sender) return;
|
||||||
|
|
||||||
@@ -179,7 +180,7 @@ namespace Ink_Canvas {
|
|||||||
center = m.Transform(center); // 转换为矩阵缩放和旋转的中心点
|
center = m.Transform(center); // 转换为矩阵缩放和旋转的中心点
|
||||||
|
|
||||||
// Update matrix to reflect translation/rotation
|
// Update matrix to reflect translation/rotation
|
||||||
m.RotateAt(45, center.X, center.Y); // 旋转
|
m.RotateAt(45, center.X, center.Y); // 顺时针旋转45度
|
||||||
|
|
||||||
var targetStrokes = inkCanvas.GetSelectedStrokes();
|
var targetStrokes = inkCanvas.GetSelectedStrokes();
|
||||||
foreach (var stroke in targetStrokes) stroke.Transform(m, false);
|
foreach (var stroke in targetStrokes) stroke.Transform(m, false);
|
||||||
@@ -471,7 +472,7 @@ namespace Ink_Canvas {
|
|||||||
|
|
||||||
// 图片工具栏相关
|
// 图片工具栏相关
|
||||||
private Border borderImageSelectionControl;
|
private Border borderImageSelectionControl;
|
||||||
private double BorderImageSelectionControlWidth = 150.0; // 3个按钮 + 分隔线的实际宽度
|
private double BorderImageSelectionControlWidth = 490.0; // 6个按钮 + 分隔线的实际宽度
|
||||||
private double BorderImageSelectionControlHeight = 80.0;
|
private double BorderImageSelectionControlHeight = 80.0;
|
||||||
|
|
||||||
// 元素变化监听相关
|
// 元素变化监听相关
|
||||||
|
|||||||
Reference in New Issue
Block a user