Skip to content
This repository has been archived by the owner on Sep 30, 2018. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Added support for taking and sending screenshots
  • Loading branch information
alexbakker committed Aug 7, 2015
1 parent edccbf5 commit e50ec84
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 2 deletions.
24 changes: 22 additions & 2 deletions Toxy.sln
@@ -1,14 +1,18 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Toxy", "Toxy\Toxy.csproj", "{89DDAE37-13A3-4201-B83B-C73BA2500B25}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Toxy.Tools", "Toxy.Tools\Toxy.Tools.vcxproj", "{148E78B8-E2B8-4266-9BBC-2535FBCEEE6F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpTox", "SharpTox\SharpTox\SharpTox.csproj", "{B3AB7D92-3D7A-41B2-86D1-D1B256B07663}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShareX.ScreenCaptureLib", "ShareX\ShareX.ScreenCaptureLib\ShareX.ScreenCaptureLib.csproj", "{DBDB0DAA-B3AE-4CC4-A8C2-20550B7F32E3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShareX.HelpersLib", "ShareX\ShareX.HelpersLib\ShareX.HelpersLib.csproj", "{327750E1-9FB7-4CC3-8AEA-9BC42180CAD3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Expand Down Expand Up @@ -41,6 +45,22 @@ Global
{B3AB7D92-3D7A-41B2-86D1-D1B256B07663}.Release|x64.Build.0 = Release|x64
{B3AB7D92-3D7A-41B2-86D1-D1B256B07663}.Release|x86.ActiveCfg = Release|x86
{B3AB7D92-3D7A-41B2-86D1-D1B256B07663}.Release|x86.Build.0 = Release|x86
{DBDB0DAA-B3AE-4CC4-A8C2-20550B7F32E3}.Debug|x64.ActiveCfg = Debug|Any CPU
{DBDB0DAA-B3AE-4CC4-A8C2-20550B7F32E3}.Debug|x64.Build.0 = Debug|Any CPU
{DBDB0DAA-B3AE-4CC4-A8C2-20550B7F32E3}.Debug|x86.ActiveCfg = Debug|Any CPU
{DBDB0DAA-B3AE-4CC4-A8C2-20550B7F32E3}.Debug|x86.Build.0 = Debug|Any CPU
{DBDB0DAA-B3AE-4CC4-A8C2-20550B7F32E3}.Release|x64.ActiveCfg = Release|Any CPU
{DBDB0DAA-B3AE-4CC4-A8C2-20550B7F32E3}.Release|x64.Build.0 = Release|Any CPU
{DBDB0DAA-B3AE-4CC4-A8C2-20550B7F32E3}.Release|x86.ActiveCfg = Release|Any CPU
{DBDB0DAA-B3AE-4CC4-A8C2-20550B7F32E3}.Release|x86.Build.0 = Release|Any CPU
{327750E1-9FB7-4CC3-8AEA-9BC42180CAD3}.Debug|x64.ActiveCfg = Debug|Any CPU
{327750E1-9FB7-4CC3-8AEA-9BC42180CAD3}.Debug|x64.Build.0 = Debug|Any CPU
{327750E1-9FB7-4CC3-8AEA-9BC42180CAD3}.Debug|x86.ActiveCfg = Debug|Any CPU
{327750E1-9FB7-4CC3-8AEA-9BC42180CAD3}.Debug|x86.Build.0 = Debug|Any CPU
{327750E1-9FB7-4CC3-8AEA-9BC42180CAD3}.Release|x64.ActiveCfg = Release|Any CPU
{327750E1-9FB7-4CC3-8AEA-9BC42180CAD3}.Release|x64.Build.0 = Release|Any CPU
{327750E1-9FB7-4CC3-8AEA-9BC42180CAD3}.Release|x86.ActiveCfg = Release|Any CPU
{327750E1-9FB7-4CC3-8AEA-9BC42180CAD3}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
5 changes: 5 additions & 0 deletions Toxy/Managers/TransferManager.cs
Expand Up @@ -134,6 +134,11 @@ public FileTransfer SendFile(int friendNumber, string path)
try { stream = new FileStream(path, FileMode.Open, FileAccess.Read); }
catch { return null; }

return SendFile(friendNumber, stream, fileName);
}

public FileTransfer SendFile(int friendNumber, Stream stream, string fileName)
{
long size = stream.Length;
var error = ToxErrorFileSend.Ok;

Expand Down
12 changes: 12 additions & 0 deletions Toxy/Resources/Icons.xaml
Expand Up @@ -442,4 +442,16 @@
</Path.Data>
</Path>
</Canvas>

<!-- this was taken from qtox, https://raw.githubusercontent.com/tux3/qTox/master/ui/screenshotButton/screenshotButton.svg -->
<Canvas x:Key="tox_screenshot" Width="16" Height="16" ClipToBounds="True" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Canvas>
<Rectangle RadiusX="1" RadiusY="1" Stroke="#FFFFFFFF" StrokeThickness="2" StrokeMiterLimit="4" Width="14" Height="8" Canvas.Left="1" Canvas.Top="3" />
<Path Fill="#FFFFFFFF" Stroke="#FFFFFFFF" StrokeMiterLimit="4">
<Path.Data>
<PathGeometry FillRule="Nonzero" Figures="M4.50183,15.49984L8.00043,11.37776 11.49909,15.49984 4.50184,15.49984z" />
</Path.Data>
</Path>
</Canvas>
</Canvas>
</ResourceDictionary>
5 changes: 5 additions & 0 deletions Toxy/Toxy.csproj
Expand Up @@ -101,6 +101,7 @@
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
Expand Down Expand Up @@ -374,6 +375,10 @@
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ShareX\ShareX.ScreenCaptureLib\ShareX.ScreenCaptureLib.csproj">
<Project>{dbdb0daa-b3ae-4cc4-a8c2-20550b7f32e3}</Project>
<Name>ShareX.ScreenCaptureLib</Name>
</ProjectReference>
<ProjectReference Include="..\SharpTox\SharpTox\SharpTox.csproj">
<Project>{b3ab7d92-3d7a-41b2-86d1-d1b256b07663}</Project>
<Name>SharpTox</Name>
Expand Down
13 changes: 13 additions & 0 deletions Toxy/Views/ConversationView.xaml
Expand Up @@ -214,6 +214,19 @@
</Rectangle.OpacityMask>
</Rectangle>
</Button>
<Button Grid.Column="1" Grid.Row="2"
Width="19"
Margin="-41 0 0 0"
Style="{StaticResource ToxGreenButtonStyle}"
IsEnabled="{Binding Friend.IsOnline, Mode=OneWay}"
Click="ButtonSendScreenshot_Click">
<Rectangle Width="13.736" Height="13.708"
Fill="{StaticResource ToxWhiteBrush}">
<Rectangle.OpacityMask>
<VisualBrush Stretch="Fill" Visual="{StaticResource tox_screenshot}" />
</Rectangle.OpacityMask>
</Rectangle>
</Button>
</Grid>
<Button Grid.Column="2" Width="50"
Style="{StaticResource ToxGreenButtonStyle}"
Expand Down
29 changes: 29 additions & 0 deletions Toxy/Views/ConversationView.xaml.cs
Expand Up @@ -9,6 +9,9 @@
using Microsoft.Win32;
using System.Windows;
using System.Threading;
using ShareX.ScreenCaptureLib;
using System.IO;
using System.Drawing.Imaging;

namespace Toxy.Views
{
Expand Down Expand Up @@ -203,5 +206,31 @@ private void TextBoxEnteredText_TextChanged(object sender, TextChangedEventArgs
Context.Friend.SetSelfTypingStatus(true);
}
}

private void ButtonSendScreenshot_Click(object sender, RoutedEventArgs e)
{
using (var screenshot = Screenshot.CaptureFullscreen())
using (var surface = new RectangleRegion())
{
surface.SurfaceImage = screenshot;
surface.Prepare();
surface.ShowDialog();

using (var img = surface.GetRegionImage())
{
var stream = new MemoryStream();
img.Save(stream, ImageFormat.Png);

var transfer = TransferManager.Instance.SendFile(Context.Friend.ChatNumber, stream, "screenshot.png");
if (transfer == null)
{
MessageBox.Show("Could not send screenshot.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}

(Context.Friend.ConversationView as ConversationViewModel).AddTransfer(transfer);
}
}
}
}
}

0 comments on commit e50ec84

Please sign in to comment.