Skip to content

Commit ff455c8

Browse files
Merge pull request #165 from mohammadKarimi/122-button-to-take-a-screenshot
take a screen shot and save in app directory.
2 parents 5118396 + b099a4b commit ff455c8

File tree

14 files changed

+100
-13
lines changed

14 files changed

+100
-13
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ Riter is a modern, versatile screen drawing application built with WPF (Windows
110110

111111
### Move Shape
112112
- **Press ALT** -> with press alt you can move objects.
113+
114+
### Screenshot
115+
- **Ctrl + Shift + P** -> Take a screen shot and save it is appDirectory/Screenshots/
113116
---
114117

115118
## Getting Started

src/Riter/App.xaml.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Riter.Services;
88
using Riter.ViewModel;
99
using Riter.ViewModel.Handlers;
10+
using Riter.ViewModel.StateHandlers.Interfaces;
1011

1112
namespace Riter;
1213

@@ -62,6 +63,7 @@ private static void ConfigureServices(ServiceCollection serviceCollection)
6263
serviceCollection.AddSingleton<IHighlighterStateHandler, HighlighterStateHandler>();
6364
serviceCollection.AddSingleton<ISettingPanelStateHandler, SettingsPanelStateHandler>();
6465
serviceCollection.AddSingleton<IButtonSelectedStateHandler, ButtonSelectedStateHandler>();
66+
serviceCollection.AddSingleton<IScreenShotHandler, ScreenShotHandler>();
6567

6668
serviceCollection.AddScoped<IShapeDrawer, LineDrawer>();
6769
serviceCollection.AddScoped<IShapeDrawer, CircleDrawer>();
@@ -79,6 +81,7 @@ private static void ConfigureServices(ServiceCollection serviceCollection)
7981
serviceCollection.AddSingleton<StrokeVisibilityViewModel>();
8082
serviceCollection.AddSingleton<InkEditingModeViewModel>();
8183
serviceCollection.AddSingleton<StartupLocationViewModel>();
84+
serviceCollection.AddSingleton<ScreenShotViewModel>();
8285
serviceCollection.AddSingleton<PaletteStateOrchestratorViewModel>();
8386

8487
serviceCollection.AddTransient(typeof(MainWindow));

src/Riter/Core/HotKey/HotKey.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public enum HotKey
3232
Rectangle = 3,
3333
Database = 4,
3434
Line = 5,
35+
36+
ScreenShot = 6000,
3537
}
3638

3739
public record struct HotKeiesPressed(string Key, bool CtrlPressed, bool ShiftPressed);

src/Riter/Core/IO/FileStorage.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.IO;
22
using System.Text.Json;
3+
using System.Windows.Media.Imaging;
34

45
namespace Riter.Core.IO;
56
public class FileStorage
@@ -11,4 +12,25 @@ public static async Task SaveConfig(AppSettings settings)
1112
var content = JsonSerializer.Serialize(new { AppSettings = settings });
1213
await File.WriteAllTextAsync(FilePath, content);
1314
}
15+
16+
public static void SaveScreenshot(RenderTargetBitmap renderBitmap)
17+
{
18+
try
19+
{
20+
var path = $"{Directory.GetCurrentDirectory()}/Screenshots/";
21+
if (!Directory.Exists(path))
22+
{
23+
Directory.CreateDirectory(path);
24+
}
25+
26+
var filePath = Path.Combine(path, $"Screenshot_{DateTime.Now:yyyyMMddHHmmss}.png");
27+
using FileStream fileStream = new(filePath, FileMode.Create);
28+
PngBitmapEncoder encoder = new();
29+
encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
30+
encoder.Save(fileStream);
31+
}
32+
catch
33+
{
34+
}
35+
}
1436
}

src/Riter/MainWindow.xaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
</Border.Effect>
4848
<subpanel:StrokeSizePanel x:Name="StrokeSizePanel"/>
4949
</Border>
50-
5150
<Border Visibility="{Binding SettingPanelViewModel.ColorPanelVisibility}"
5251
Padding="8,8" HorizontalAlignment="Left"
5352
Margin="8,0,0,8" VerticalAlignment="Bottom"
@@ -63,10 +62,8 @@
6362
<StackPanel Orientation="Horizontal"
6463
HorizontalAlignment="Center"
6564
MinWidth="0" Name="ToolboxContainer">
66-
6765
<local:ToolBox x:Name="ToolBox" DataContext="{Binding}"/>
6866
<local:WindowControl x:Name="WindowControl"/>
69-
7067
</StackPanel>
7168
</StackPanel>
7269
</Canvas>

src/Riter/MainWindow.xaml.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
using System.Diagnostics;
22
using System.Runtime.InteropServices;
3-
using System.Windows.Ink;
4-
using Riter.Core.Drawing;
5-
using Riter.Core.Interfaces;
6-
using Riter.Core.UI;
73
using Riter.Core.WindowExtensions;
84
using Riter.ViewModel;
95

src/Riter/Riter.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<Nullable>disable</Nullable>
77
<ImplicitUsings>enable</ImplicitUsings>
88
<UseWPF>true</UseWPF>
9-
<AssemblyVersion>0.2.6</AssemblyVersion>
9+
<AssemblyVersion>0.2.7</AssemblyVersion>
1010
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
1111
</PropertyGroup>
1212
<PropertyGroup>

src/Riter/Services/HotKeyCommandMapper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@ public static class HotKeyCommandMapper
3535
{ HotKey.Circle, () => viewModel.DrawingViewModel.DrawShapeCommand.Execute(DrawingShape.Circle) },
3636
{ HotKey.Database, () => viewModel.DrawingViewModel.DrawShapeCommand.Execute(DrawingShape.Database) },
3737
{ HotKey.Line, () => viewModel.DrawingViewModel.DrawShapeCommand.Execute(DrawingShape.Line) },
38+
{ HotKey.ScreenShot, () => viewModel.ScreenShotViewModel.TakeCommand.Execute(null) },
3839
};
3940
}

src/Riter/Services/HotkeyCommandService.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ public class HotKeyCommandService(AppSettings appSettings)
66
private readonly AppSettings _appSettings = appSettings;
77
private Dictionary<HotKey, Action> _hotKeyCommandMap;
88

9-
public void InitializeCommands(Dictionary<HotKey, Action> commandMap)
10-
{
11-
_hotKeyCommandMap = commandMap;
12-
}
9+
public void InitializeCommands(Dictionary<HotKey, Action> commandMap) => _hotKeyCommandMap = commandMap;
1310

1411
public void ExecuteHotKey(HotKeiesPressed hotKeies)
1512
{

src/Riter/ViewModel/PaletteStateOrchestratorViewModel.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ public PaletteStateOrchestratorViewModel(
1818
SettingPanelViewModel settingPanelViewModel,
1919
ButtonSelectedViewModel buttonSelectedViewModel,
2020
StartupLocationViewModel startupLocationViewModel,
21-
HotKeyCommandService hotKeyCommandService)
21+
HotKeyCommandService hotKeyCommandService,
22+
ScreenShotViewModel screenShotViewModel)
2223
{
24+
ScreenShotViewModel = screenShotViewModel;
2325
DrawingViewModel = drawingViewModel;
2426
StrokeVisibilityViewModel = strokeVisibilityViewModel;
2527
StrokeHistoryViewModel = strokeHistoryViewModel;
@@ -54,6 +56,8 @@ public PaletteStateOrchestratorViewModel(
5456

5557
public StartupLocationViewModel StartupLocationViewModel { get; }
5658

59+
public ScreenShotViewModel ScreenShotViewModel { get; }
60+
5761
public DrawingAttributes InkDrawingAttributes =>
5862
DrawingAttributesFactory.CreateDrawingAttributes(
5963
BrushSettingsViewModel.InkColor,

0 commit comments

Comments
 (0)