add Screenshot Demo

This commit is contained in:
NaBian 2020-03-07 21:58:46 +08:00
parent 46b1297aa7
commit 4113f9d814
23 changed files with 187 additions and 41 deletions

View File

@ -480,6 +480,9 @@
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\Img\cloud.png">
<Link>Resources\Img\cloud.png</Link>
</Resource>
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\Img\LeftMainContent\WindowScreenshot_16x.png">
<Link>Resources\Img\LeftMainContent\WindowScreenshot_16x.png</Link>
</Resource>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="..\..\Shared\HandyControlDemo_Shared\Properties\Langs\Lang.en.resx">

View File

@ -547,6 +547,9 @@
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\Img\cloud.png">
<Link>Resources\Img\cloud.png</Link>
</Resource>
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\Img\LeftMainContent\WindowScreenshot_16x.png">
<Link>Resources\Img\LeftMainContent\WindowScreenshot_16x.png</Link>
</Resource>
</ItemGroup>
<ItemGroup>
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Data\DemoInfo.json">

View File

@ -610,6 +610,9 @@
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\Img\cloud.png">
<Link>Resources\Img\cloud.png</Link>
</Resource>
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\Img\LeftMainContent\WindowScreenshot_16x.png">
<Link>Resources\Img\LeftMainContent\WindowScreenshot_16x.png</Link>
</Resource>
</ItemGroup>
<ItemGroup>
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\fabric-icons.ttf">

View File

@ -317,6 +317,9 @@
<Resource Include="..\HandyControlDemo_Shared\UserControl\Controls\RunningBlockDemoCtl.xaml">
<Link>UserControl\Controls\RunningBlockDemoCtl.xaml</Link>
</Resource>
<Resource Include="..\HandyControlDemo_Shared\UserControl\Controls\ScreenshotDemoCtl.xaml">
<Link>UserControl\Controls\ScreenshotDemoCtl.xaml</Link>
</Resource>
<Resource Include="..\HandyControlDemo_Shared\UserControl\Controls\ScrollViewerDemoCtl.xaml">
<Link>UserControl\Controls\ScrollViewerDemoCtl.xaml</Link>
</Resource>
@ -713,6 +716,10 @@
<Link>UserControl\Controls\RunningBlockDemoCtl.xaml.cs</Link>
<DependentUpon>RunningBlockDemoCtl.xaml</DependentUpon>
</Resource>
<Resource Include="..\HandyControlDemo_Shared\UserControl\Controls\ScreenshotDemoCtl.xaml.cs">
<Link>UserControl\Controls\ScreenshotDemoCtl.xaml.cs</Link>
<DependentUpon>ScreenshotDemoCtl.xaml</DependentUpon>
</Resource>
<Resource Include="..\HandyControlDemo_Shared\UserControl\Controls\ScrollViewerDemoCtl.xaml.cs">
<Link>UserControl\Controls\ScrollViewerDemoCtl.xaml.cs</Link>
<DependentUpon>ScrollViewerDemoCtl.xaml</DependentUpon>

View File

@ -98,6 +98,7 @@
[ "Sprite", "SpriteDemoCtl", "HandyControl", "" ],
[ "Notification", "NotificationDemoCtl", "Procedure_16x", "" ],
[ "Dialog", "DialogDemoCtl", "Dialog_16x", "" ],
[ "Screenshot", "ScreenshotDemoCtl", "WindowScreenshot_16x", "1" ],
[ "Window", "WindowDemoCtl", "WindowsForm_16x", "1" ]
]
},
@ -106,7 +107,7 @@
"demoItemList": [
[ "HatchBrushGenerator", "HatchBrushGeneratorDemoCtl", "DataGenerator_16x", "" ],
[ "Morphing Animation", "GeometryAnimationDemoCtl", "Animation_16x", "" ],
[ "Effects", "EffectsDemoCtl", "Effects_16x", "1" ]
[ "Effects", "EffectsDemoCtl", "Effects_16x", "" ]
]
}
]

View File

@ -190,6 +190,9 @@
<Compile Include="$(MSBuildThisFileDirectory)UserControl\Controls\RunningBlockDemoCtl.xaml.cs">
<DependentUpon>RunningBlockDemoCtl.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)UserControl\Controls\ScreenshotDemoCtl.xaml.cs">
<DependentUpon>ScreenshotDemoCtl.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)UserControl\Controls\ScrollViewerDemoCtl.xaml.cs">
<DependentUpon>ScrollViewerDemoCtl.xaml</DependentUpon>
</Compile>
@ -684,6 +687,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)UserControl\Controls\ScreenshotDemoCtl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)UserControl\Controls\ScrollViewerDemoCtl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>

View File

@ -1176,15 +1176,6 @@ namespace HandyControlDemo.Properties.Langs {
}
}
/// <summary>
/// 查找类似 概览 的本地化字符串。
/// </summary>
public static string Overview {
get {
return ResourceManager.GetString("Overview", resourceCulture);
}
}
/// <summary>
/// 查找类似 页码条 的本地化字符串。
/// </summary>
@ -1491,6 +1482,15 @@ namespace HandyControlDemo.Properties.Langs {
}
}
/// <summary>
/// 查找类似 截图 的本地化字符串。
/// </summary>
public static string Screenshot {
get {
return ResourceManager.GetString("Screenshot", resourceCulture);
}
}
/// <summary>
/// 查找类似 滚动视图 的本地化字符串。
/// </summary>
@ -1608,6 +1608,15 @@ namespace HandyControlDemo.Properties.Langs {
}
}
/// <summary>
/// 查找类似 开始截图 的本地化字符串。
/// </summary>
public static string StartScreenshot {
get {
return ResourceManager.GetString("StartScreenshot", resourceCulture);
}
}
/// <summary>
/// 查找类似 保持打开 的本地化字符串。
/// </summary>

View File

@ -738,4 +738,10 @@
<data name="PracticalDemos" xml:space="preserve">
<value>Practical demos</value>
</data>
<data name="StartScreenshot" xml:space="preserve">
<value>Start screenshot</value>
</data>
<data name="Screenshot" xml:space="preserve">
<value>Screenshot</value>
</data>
</root>

View File

@ -738,4 +738,10 @@
<data name="PracticalDemos" xml:space="preserve">
<value>Practical demos</value>
</data>
<data name="StartScreenshot" xml:space="preserve">
<value>Start screenshot</value>
</data>
<data name="Screenshot" xml:space="preserve">
<value>Screenshot</value>
</data>
</root>

View File

@ -738,4 +738,10 @@
<data name="PracticalDemos" xml:space="preserve">
<value>Practical demos</value>
</data>
<data name="StartScreenshot" xml:space="preserve">
<value>Start screenshot</value>
</data>
<data name="Screenshot" xml:space="preserve">
<value>Screenshot</value>
</data>
</root>

View File

@ -738,4 +738,10 @@
<data name="PracticalDemos" xml:space="preserve">
<value>Practical demos</value>
</data>
<data name="StartScreenshot" xml:space="preserve">
<value>Start screenshot</value>
</data>
<data name="Screenshot" xml:space="preserve">
<value>Screenshot</value>
</data>
</root>

View File

@ -738,4 +738,10 @@
<data name="PracticalDemos" xml:space="preserve">
<value>实用例子</value>
</data>
<data name="StartScreenshot" xml:space="preserve">
<value>开始截图</value>
</data>
<data name="Screenshot" xml:space="preserve">
<value>截图</value>
</data>
</root>

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 B

View File

@ -0,0 +1,10 @@
<UserControl x:Class="HandyControlDemo.UserControl.ScreenshotDemoCtl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:langs="clr-namespace:HandyControlDemo.Properties.Langs"
Background="{DynamicResource RegionBrush}">
<hc:TransitioningContentControl>
<Button Content="{x:Static langs:Lang.StartScreenshot}" Command="hc:ControlCommands.StartScreenshot"/>
</hc:TransitioningContentControl>
</UserControl>

View File

@ -0,0 +1,33 @@
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using HandyControl.Controls;
using HandyControl.Data;
namespace HandyControlDemo.UserControl
{
public partial class ScreenshotDemoCtl : IDisposable
{
public ScreenshotDemoCtl()
{
InitializeComponent();
Screenshot.Snapped += Screenshot_Snapped;
}
private void Screenshot_Snapped(object sender, FunctionEventArgs<ImageSource> e)
{
new HandyControl.Controls.Window
{
Content = new Image
{
Source = e.Info,
Stretch = Stretch.None
},
WindowStartupLocation = WindowStartupLocation.CenterScreen
}.ShowDialog();
}
public void Dispose() => Screenshot.Snapped -= Screenshot_Snapped;
}
}

View File

@ -3,7 +3,7 @@
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:avalonedit="http://icsharpcode.net/sharpdevelop/avalonedit"
x:Class="HandyControlDemo.UserControl.MainContent">
<Grid Name="GridMain" MinHeight="300" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="16">
<Grid Name="GridMain" MinHeight="300" MinWidth="200" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="16">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>

View File

@ -1,16 +1,15 @@
using System;
using System.Windows.Media;
using HandyControl.Data;
namespace HandyControl.Controls
{
public class Screenshot
{
public event EventHandler Snapped;
public ImageSource Source { get; set; }
public static event EventHandler<FunctionEventArgs<ImageSource>> Snapped;
public void Start() => new ScreenshotWindow(this).Show();
internal void OnSnapped() => Snapped?.Invoke(this, EventArgs.Empty);
internal void OnSnapped(ImageSource source) => Snapped?.Invoke(this, new FunctionEventArgs<ImageSource>(source));
}
}

View File

@ -26,8 +26,6 @@ namespace HandyControl.Controls
#region const
private const int RectMinLength = 14;
private const int IntervalLength = 1;
private const int IntervalBigLength = 10;
@ -60,6 +58,8 @@ namespace HandyControl.Controls
private Point _mousePointOld;
private bool _saveScreenshot;
#endregion
#endregion
@ -177,7 +177,8 @@ namespace HandyControl.Controls
}
break;
case Key.Enter:
SaveScreenshot();
_saveScreenshot = true;
Close();
break;
}
}
@ -185,7 +186,11 @@ namespace HandyControl.Controls
protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e) => _mousePointOld = e.GetPosition(this);
protected override void OnPreviewMouseDoubleClick(MouseButtonEventArgs e) => SaveScreenshot();
protected override void OnPreviewMouseDoubleClick(MouseButtonEventArgs e)
{
_saveScreenshot = true;
Close();
}
protected override void OnPreviewMouseMove(MouseEventArgs e)
{
@ -282,6 +287,11 @@ namespace HandyControl.Controls
private void ScreenshotWindow_Closed(object sender, EventArgs e)
{
if (_saveScreenshot)
{
SaveScreenshot();
}
StopHooks();
IsDrawing = false;
@ -442,10 +452,9 @@ namespace HandyControl.Controls
if (Canvas.Background is ImageBrush imageBrush && imageBrush.ImageSource is BitmapSource bitmapSource)
{
var cb = new CroppedBitmap(bitmapSource, new Int32Rect(_targetWindowRect.Left, _targetWindowRect.Top, _targetWindowRect.Width, _targetWindowRect.Height));
_screenshot.Source = cb;
_screenshot.OnSnapped(cb);
}
_screenshot.OnSnapped();
Close();
}
@ -488,7 +497,21 @@ namespace HandyControl.Controls
}
}
private void RegularRect(ref InteropValues.RECT rect)
private static InteropValues.RECT MoveRect(InteropValues.RECT rect, int leftFlag = 0, int topFlag = 0, int rightFlag = 0, int bottomFlag = 0)
{
var moveLength = Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)
? IntervalBigLength
: IntervalLength;
rect.Left += leftFlag * moveLength;
rect.Top += topFlag * moveLength;
rect.Right += rightFlag * moveLength;
rect.Bottom += bottomFlag * moveLength;
return rect;
}
private void MoveTargetArea(InteropValues.RECT rect)
{
if (rect.Left < 0)
{
@ -516,25 +539,6 @@ namespace HandyControl.Controls
rect.Left = Math.Max(0, rect.Left);
rect.Top = Math.Max(0, rect.Top);
}
private static InteropValues.RECT MoveRect(InteropValues.RECT rect, int leftFlag = 0, int topFlag = 0, int rightFlag = 0, int bottomFlag = 0)
{
var moveLength = Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)
? IntervalBigLength
: IntervalLength;
rect.Left += leftFlag * moveLength;
rect.Top += topFlag * moveLength;
rect.Right += rightFlag * moveLength;
rect.Bottom += bottomFlag * moveLength;
return rect;
}
private void MoveTargetArea(InteropValues.RECT rect)
{
RegularRect(ref rect);
var width = rect.Width;
var height = rect.Height;

View File

@ -61,6 +61,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Data\HwndWrapper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\Commands\CloseWindowCommand.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\Commands\OpenLinkCommand.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\Commands\StartScreenshotCommand.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Media\Animation\DiscreteGeometryKeyFrame.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Media\Animation\EasingGeometryKeyFrame.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Media\Animation\GeometryAnimation.cs" />

View File

@ -161,5 +161,10 @@ namespace HandyControl.Interactivity
/// 关闭窗口
/// </summary>
public static CloseWindowCommand CloseWindow { get; } = new CloseWindowCommand();
/// <summary>
/// 开始截图
/// </summary>
public static StartScreenshotCommand StartScreenshot { get; } = new StartScreenshotCommand();
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Windows.Input;
using HandyControl.Controls;
namespace HandyControl.Interactivity
{
public class StartScreenshotCommand : ICommand
{
public bool CanExecute(object parameter) => true;
public void Execute(object parameter) => new Screenshot().Start();
public event EventHandler CanExecuteChanged;
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Windows.Input;
using HandyControl.Controls;
namespace HandyControl.Interactivity
{
public class StartScreenshotCommand : ICommand
{
public bool CanExecute(object parameter) => true;
public void Execute(object parameter) => new Screenshot().Start();
public event EventHandler CanExecuteChanged;
}
}

View File

@ -6,6 +6,7 @@ using System.Runtime.InteropServices;
using System.Security;
using System.Windows;
using System.Windows.Interop;
using HandyControl.Tools.Extension;
using HandyControl.Tools.Interop;
namespace HandyControl.Tools