Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Ink Canvas/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,8 @@ private static bool IsLaunchByFileOrUri(string[] args)
if (string.IsNullOrWhiteSpace(a)) continue;
string t = a.Trim();
if (t.StartsWith("icc:", StringComparison.OrdinalIgnoreCase)) return true;
if (Path.GetExtension(t).Equals(".icstk", StringComparison.OrdinalIgnoreCase)) return true;
if (Path.GetExtension(t).Equals(".icstk", StringComparison.OrdinalIgnoreCase) ||
FileAssociationManager.IsUInkStrokeFile(t)) return true;
}
return false;
}
Expand Down
29 changes: 29 additions & 0 deletions Ink Canvas/Controls/FloatingFoldBall.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<UserControl x:Class="Ink_Canvas.Controls.FloatingFoldBall"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:props="clr-namespace:Ink_Canvas.Properties"
Width="50.342825" Height="{Binding Width, RelativeSource={RelativeSource Self}}"
HorizontalAlignment="Left" VerticalAlignment="Top"
Cursor="Hand" ToolTip="{x:Static props:ThemeStrings.Theme_FloatingFoldBall_Hint}" Focusable="True"
AutomationProperties.Name="{x:Static props:ThemeStrings.Theme_FloatingFoldBall_Hint}"
Stylus.IsPressAndHoldEnabled="False" Stylus.IsFlicksEnabled="False">
<UserControl.RenderTransform>
<TranslateTransform x:Name="MenuOffset" />
</UserControl.RenderTransform>
<Grid>
<Ellipse Fill="{DynamicResource FloatingBarBackgroundBrush}"
Stroke="{DynamicResource FloatingBarBorderBrush}" StrokeThickness="1">
<Ellipse.Effect>
<DropShadowEffect BlurRadius="8" ShadowDepth="1" Opacity="0.25" />
</Ellipse.Effect>
</Ellipse>
<Grid IsHitTestVisible="False">
<Image x:Name="PenIcon" Source="{DynamicResource QuickPanelEyeIcon}" Width="24" Height="24"
RenderOptions.BitmapScalingMode="HighQuality" />
<Path x:Name="CloseIcon" Data="M 0,0 L 12,12 M 12,0 L 0,12" StrokeThickness="2"
Stroke="{DynamicResource FloatingBarForegroundBrush}" StrokeStartLineCap="Round"
StrokeEndLineCap="Round" HorizontalAlignment="Center" VerticalAlignment="Center"
Visibility="Collapsed" />
</Grid>
</Grid>
</UserControl>
167 changes: 167 additions & 0 deletions Ink Canvas/Controls/FloatingFoldBall.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace Ink_Canvas.Controls
{
public partial class FloatingFoldBall : UserControl
{
public event RoutedEventHandler Click;
public event EventHandler PositionChanged;
public event EventHandler DragMoved;
internal bool IsPointerPressed => _pressed;

private Point _pointerStart;
private Point _positionStart;
private bool _pressed;
private bool _dragged;
private TouchDevice _touch;

public FloatingFoldBall()
{
InitializeComponent();
IsVisibleChanged += (_, _) =>
{
if (!IsVisible)
{
EndDrag(true);
ReleaseMouseCapture();
_touch?.Capture(null);
_touch = null;
}
};
}

internal static Point ClampPosition(Point point, Size bounds, Size size) => new Point(
Math.Clamp(double.IsFinite(point.X) ? point.X : 0, 0, Math.Max(0, bounds.Width - size.Width)),
Math.Clamp(double.IsFinite(point.Y) ? point.Y : 0, 0, Math.Max(0, bounds.Height - size.Height)));

public void SetPosition(Point point)
{
// 首次布局前也保留配置位置,待宿主取得尺寸后再约束到可见区域。
if (Parent is FrameworkElement parent && parent.ActualWidth > 0 && parent.ActualHeight > 0)
point = ClampPosition(point, parent.RenderSize, new Size(Width, Height));
else
point = new Point(double.IsFinite(point.X) ? Math.Max(0, point.X) : 0,
double.IsFinite(point.Y) ? Math.Max(0, point.Y) : 0);
Margin = new Thickness(point.X, point.Y, 0, 0);
}

internal void ShowMenuState(bool isOpen, Vector offset)
{
MenuOffset.X = offset.X;
MenuOffset.Y = offset.Y;
PenIcon.Visibility = isOpen ? Visibility.Collapsed : Visibility.Visible;
CloseIcon.Visibility = isOpen ? Visibility.Visible : Visibility.Collapsed;
}

private void BeginDrag(Point pointer)
{
_pointerStart = pointer;
_positionStart = new Point(Margin.Left + MenuOffset.X, Margin.Top + MenuOffset.Y);
_pressed = true;
_dragged = false;
}

private void MoveDrag(Point pointer)
{
if (!_pressed) return;
var delta = pointer - _pointerStart;
if (!_dragged && Math.Abs(delta.X) < SystemParameters.MinimumHorizontalDragDistance &&
Math.Abs(delta.Y) < SystemParameters.MinimumVerticalDragDistance) return;
_dragged = true;
SetPosition(_positionStart + delta);
DragMoved?.Invoke(this, EventArgs.Empty);
}

private void EndDrag(bool cancelled)
{
if (!_pressed) return;
_pressed = false;
if (_dragged) PositionChanged?.Invoke(this, EventArgs.Empty);
else if (!cancelled) Click?.Invoke(this, new RoutedEventArgs());
_dragged = false;
}

protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonDown(e);
if (_touch != null) return;
if (CaptureMouse()) BeginDrag(e.GetPosition(Parent as IInputElement));
e.Handled = true;
}

protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
if (_touch == null && _pressed)
{
MoveDrag(e.GetPosition(Parent as IInputElement));
e.Handled = true;
}
}

protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonUp(e);
if (_touch != null) return;
MoveDrag(e.GetPosition(Parent as IInputElement));
EndDrag(false);
ReleaseMouseCapture();
e.Handled = true;
}

protected override void OnLostMouseCapture(MouseEventArgs e)
{
base.OnLostMouseCapture(e);
if (_touch == null) EndDrag(true);
}

protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
if (e.Key != Key.Enter && e.Key != Key.Space) return;
if (!e.IsRepeat) Click?.Invoke(this, new RoutedEventArgs());
e.Handled = true;
}

protected override void OnTouchDown(TouchEventArgs e)
{
base.OnTouchDown(e);
e.Handled = true;
if (_pressed || _touch != null) return;
if (e.TouchDevice.Capture(this))
{
_touch = e.TouchDevice;
BeginDrag(e.GetTouchPoint(Parent as IInputElement).Position);
}
}

protected override void OnTouchMove(TouchEventArgs e)
{
base.OnTouchMove(e);
e.Handled = true;
if (e.TouchDevice == _touch) MoveDrag(e.GetTouchPoint(Parent as IInputElement).Position);
}

protected override void OnTouchUp(TouchEventArgs e)
{
base.OnTouchUp(e);
e.Handled = true;
if (e.TouchDevice != _touch) return;
MoveDrag(e.GetTouchPoint(Parent as IInputElement).Position);
EndDrag(false);
_touch = null;
e.TouchDevice.Capture(null);
}

protected override void OnLostTouchCapture(TouchEventArgs e)
{
base.OnLostTouchCapture(e);
if (e.TouchDevice != _touch) return;
EndDrag(true);
_touch = null;
}
}
}
84 changes: 84 additions & 0 deletions Ink Canvas/Controls/FloatingFoldMenu.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<UserControl x:Class="Ink_Canvas.Controls.FloatingFoldMenu"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:props="clr-namespace:Ink_Canvas.Properties"
Width="260" Height="260" HorizontalAlignment="Left" VerticalAlignment="Top"
RenderTransformOrigin="0.5,0.5">
<UserControl.RenderTransform>
<TransformGroup>
<ScaleTransform x:Name="PopScale" />
<RotateTransform x:Name="PopRotation" />
</TransformGroup>
</UserControl.RenderTransform>
<UserControl.LayoutTransform>
<ScaleTransform />
</UserControl.LayoutTransform>
<Canvas x:Name="Ring">
<Canvas.Resources>
<Style TargetType="Button">
<Setter Property="Width" Value="74" />
<Setter Property="Height" Value="70" />
<Setter Property="FontSize" Value="14" />
<Setter Property="FontWeight" Value="SemiBold" />
<Setter Property="Foreground" Value="{DynamicResource FloatingBarForegroundBrush}" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="Cursor" Value="Hand" />
<Setter Property="AutomationProperties.Name" Value="{Binding Content, RelativeSource={RelativeSource Self}}" />
<Setter Property="ToolTip" Value="{Binding Content, RelativeSource={RelativeSource Self}}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border x:Name="Tile" Background="{TemplateBinding Background}" BorderThickness="1"
BorderBrush="Transparent" CornerRadius="17">
<StackPanel VerticalAlignment="Center">
<Image Source="{TemplateBinding Tag}" Width="26" Height="26" Margin="0,0,0,4"
RenderOptions.BitmapScalingMode="HighQuality" />
<TextBlock Text="{TemplateBinding Content}" TextAlignment="Center"
Margin="2,0" TextWrapping="Wrap" />
</StackPanel>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Tile" Property="Background" Value="#22809CF5" />
<Setter TargetName="Tile" Property="BorderBrush" Value="#55809CF5" />
</Trigger>
<Trigger Property="IsKeyboardFocused" Value="True">
<Setter TargetName="Tile" Property="BorderBrush" Value="#FF688BE6" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="Tile" Property="Background" Value="#44809CF5" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Canvas.Resources>
<Ellipse Canvas.Left="3" Canvas.Top="3" Width="254" Height="254"
Fill="{DynamicResource FloatingBarBackgroundBrush}"
Stroke="{DynamicResource FloatingBarBorderBrush}">
<Ellipse.Effect>
<DropShadowEffect BlurRadius="12" ShadowDepth="2" Opacity="0.24" />
</Ellipse.Effect>
</Ellipse>
<Ellipse Canvas.Left="98" Canvas.Top="98" Width="64" Height="64" Stroke="#55809CF5"
IsHitTestVisible="False" />
<Canvas x:Name="Tools" Width="260" Height="260">
<Canvas.Clip>
<EllipseGeometry Center="130,130" RadiusX="127" RadiusY="127" />
</Canvas.Clip>
<Button x:Name="RestoreToolbar" Content="{x:Static props:FloatingBarStrings.QuickPanel_Show}"
Tag="{DynamicResource QuickPanelEyeIcon}" />
<Button x:Name="SingleDraw" Content="{x:Static props:FloatingBarStrings.QuickPanel_SingleDraw}"
Tag="{DynamicResource QuickPanelPersonMoneyIcon}" />
<Button x:Name="RandomDraw" Content="{x:Static props:FloatingBarStrings.Tools_RandomDraw}"
Tag="{DynamicResource QuickPanelPeopleMoneyIcon}" />
<Button x:Name="Timer" Content="{x:Static props:FloatingBarStrings.QuickPanel_Timer}"
Tag="{DynamicResource QuickPanelTimerIcon}" />
<Button x:Name="Whiteboard" Content="{x:Static props:FloatingBarStrings.FloatingBar_Whiteboard}"
Tag="{DynamicResource QuickPanelBlackboardIcon}" />
<Button x:Name="ExitShow" Content="{x:Static props:FloatingBarStrings.QuickPanel_ExitShow}"
Tag="{DynamicResource QuickPanelEndSlideshowIcon}" Visibility="Collapsed" />
</Canvas>
</Canvas>
</UserControl>
Loading
Loading