Skip to content

Commit

Permalink
Small bugfixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
NickeManarin committed Feb 19, 2017
1 parent f26bf2c commit f7eedd9
Show file tree
Hide file tree
Showing 5 changed files with 227 additions and 17 deletions.
200 changes: 200 additions & 0 deletions ScreenToGif/Controls/HexadecimalBox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
using System;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace ScreenToGif.Controls
{
public class HexadecimalBox : ExtendedTextBox
{
#region Dependency Properties

public static readonly DependencyProperty RedProperty = DependencyProperty.Register("Red", typeof(int), typeof(HexadecimalBox), new PropertyMetadata(0, Value_PropertyChanged));

public static readonly DependencyProperty GreenProperty = DependencyProperty.Register("Green", typeof(int), typeof(HexadecimalBox), new PropertyMetadata(0, Value_PropertyChanged));

public static readonly DependencyProperty BlueProperty = DependencyProperty.Register("Blue", typeof(int), typeof(HexadecimalBox), new PropertyMetadata(0, Value_PropertyChanged));

public static readonly DependencyProperty AlphaProperty = DependencyProperty.Register("Alpha", typeof(int), typeof(HexadecimalBox), new PropertyMetadata(255, Value_PropertyChanged));

public static readonly DependencyProperty DisplayGlyphProperty = DependencyProperty.Register("DisplayGlyph", typeof(bool), typeof(HexadecimalBox), new PropertyMetadata(true));

#endregion

#region Properties

public int Red
{
get { return (int) GetValue(RedProperty); }
set { SetValue(RedProperty, value); }
}

public int Blue
{
get { return (int)GetValue(BlueProperty); }
set { SetValue(BlueProperty, value); }
}

public int Green
{
get { return (int)GetValue(GreenProperty); }
set { SetValue(GreenProperty, value); }
}

public int Alpha
{
get { return (int)GetValue(AlphaProperty); }
set { SetValue(AlphaProperty, value); }
}

public bool DisplayGlyph
{
get { return (bool)GetValue(DisplayGlyphProperty); }
set { SetValue(DisplayGlyphProperty, value); }
}

#endregion

private static void Value_PropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
{
var hexaBox = o as HexadecimalBox;

if (hexaBox == null)
return;

hexaBox.Text = $"{(hexaBox.DisplayGlyph ? "#" : "")}{hexaBox.Alpha:X2}{hexaBox.Red:X2}{hexaBox.Green:X2}{hexaBox.Blue:X2}";
}

//input validation,

static HexadecimalBox()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(HexadecimalBox), new FrameworkPropertyMetadata(typeof(HexadecimalBox)));
}

#region Overrides

public override void OnApplyTemplate()
{
base.OnApplyTemplate();

AddHandler(DataObject.PastingEvent, new DataObjectPastingEventHandler(OnPasting));

Text = $"{(DisplayGlyph ? "#" : "")}{Alpha:X2}{Red:X2}{Green:X2}{Blue:X2}";
}

protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
{
if (!IsKeyboardFocusWithin)
{
e.Handled = true;
Focus();
}
}

protected override void OnGotFocus(RoutedEventArgs e)
{
base.OnGotFocus(e);

SelectAll();
}

protected override void OnPreviewTextInput(TextCompositionEventArgs e)
{
if (string.IsNullOrEmpty(e.Text))
{
e.Handled = true;
return;
}

if (!IsEntryAllowed(this, e.Text))
{
e.Handled = true;
return;
}

base.OnPreviewTextInput(e);
}

protected override void OnTextChanged(TextChangedEventArgs e)
{
if (string.IsNullOrEmpty(Text)) return;
if (!IsTextAllowed(Text)) return;



base.OnTextChanged(e);
}

protected override void OnLostFocus(RoutedEventArgs e)
{
base.OnLostFocus(e);


if (string.IsNullOrEmpty(Text) || !IsTextAllowed(Text))
{
//Value = DefaultValueIfEmpty;
return;
}


return;
}

#endregion

#region Base Properties Changed

private void OnPasting(object sender, DataObjectPastingEventArgs e)
{
if (e.DataObject.GetDataPresent(typeof(string)))
{
var text = e.DataObject.GetData(typeof(string)) as string;

if (!IsTextAllowed(text))
{
e.CancelCommand();
}
}
else
{
e.CancelCommand();
}
}

#endregion

#region Methods

private bool IsEntryAllowed(TextBox textBox, string text)
{
//Digits, points or commas.
var regex = new Regex(@"^[0-9]|[A-F]|$");

//Checks if it's a valid char based on the context.
return regex.IsMatch(text) && IsEntryAllowedInContext(textBox, text);
}

private bool IsEntryAllowedInContext(TextBox textBox, string next)
{
//if number, allow.
//if (char.IsNumber(next.ToCharArray().FirstOrDefault()))
// return true;

//TODO: Validate position

return true;
}

private bool IsTextAllowed(string text)
{
return Regex.IsMatch(text, "^#([A-Fa-f0-9]{8})$");
}

#endregion
}
}
15 changes: 8 additions & 7 deletions ScreenToGif/Readme.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#ScreenToGif
#ScreenToGif

This is the current project of ScreenToGif.
This is the current project of ScreenToGif.

VS 2015 and .Net 4.6.1 required.
VS 2015 and .Net 4.6.1 required.


Version 2.5:

• Keypresses recording.
• Option to remove X frames after Y frames, also known as reduce framerate.
• Save directly to clipboard option for gifs.
• 64 bits executable (will run as 32 bits when 64 bits not available).
• Keypresses recording.
• Option to remove X frames after Y frames, also known as reduce framerate.
• Save directly to clipboard option for gifs.
• 64 bits executable (will run as 32 bits when 64 bits not available).

Fixed:

Expand All @@ -21,6 +21,7 @@ Fixed:
♦ The legacy (1.0) encoder was failing to find the transparent color of frames with small changes.
♦ Improved the selection of frames while using the Shift key.
♦ When applying the Progress overlay, a heavy load could freeze the window and crash the app.
♦ The feedback tool now searches for the log files correctly.

Known bugs:

Expand Down
1 change: 1 addition & 0 deletions ScreenToGif/ScreenToGif.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
<Compile Include="Controls\FrameListBoxItem.cs" />
<Compile Include="Controls\GhostWindow.cs" />
<Compile Include="Controls\HeaderedTooltip.cs" />
<Compile Include="Controls\HexadecimalBox.cs" />
<Compile Include="Controls\HideableTabControl.cs" />
<Compile Include="Controls\HierarchicalItem.cs" />
<Compile Include="Controls\ImageButton.cs" />
Expand Down
25 changes: 16 additions & 9 deletions ScreenToGif/Windows/Other/Feedback.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,25 @@ public Feedback()

private void Feedback_OnLoaded(object sender, RoutedEventArgs e)
{
//Search for a Log folder and add the txt files as attachment.
var logFolder = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Logs");

if (Directory.Exists(logFolder))
try
{
var files = Directory.GetFiles(logFolder);
//Search for a Log folder and add the txt files as attachment.
var logFolder = Path.Combine(UserSettings.All.LogsFolder, "ScreenToGif", "Logs");

foreach (string file in files)
if (Directory.Exists(logFolder))
{
AttachmentListBox.Items.Add(new AttachmentListBoxItem(file));
var files = Directory.GetFiles(logFolder);

foreach (string file in files)
{
AttachmentListBox.Items.Add(new AttachmentListBoxItem(file));
}
}
}
catch (Exception ex)
{
LogWriter.Log(ex, "Impossible to search for the logs folder");
}
}

private void AddAttachmentButton_Click(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -105,7 +112,7 @@ private void SendButton_Click(object sender, RoutedEventArgs e)

#endregion

//Please, don't try to enter with this e-mail and password. :/
//Please, don't try to log with this e-mail and password. :/
//Everytime someone does this, I have to change the password and the Feedback feature stops working until I update the app.
var passList = Secret.Password.Split('|');

Expand All @@ -119,7 +126,7 @@ private void SendButton_Click(object sender, RoutedEventArgs e)
Credentials = new NetworkCredential(Secret.Email, passList[_current])
};

//Please, don't try to enter with this e-mail and password. :/
//Please, don't try to log with this e-mail and password. :/
//Everytime someone does this, I have to change the password and the Feedback feature stops working until I update the app.
var mail = new MailMessage
{
Expand Down
3 changes: 2 additions & 1 deletion ScreenToGif/Windows/Webcam.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@

<n:ImageButton Grid.Column="2" x:Name="ScaleButton" Content="{StaticResource Vector.Resize}" TabIndex="1"
Style="{StaticResource Style.Button.NoText}" Effect="{StaticResource Shadow.Border}"
HorizontalContentAlignment="Center" MaxSize="20" Padding="3" Click="ScaleButton_Click">
HorizontalContentAlignment="Center" MaxSize="20" Padding="3" Click="ScaleButton_Click"
IsEnabled="{Binding ElementName=VideoDevicesComboBox, Path=IsEnabled}">
<n:ImageButton.ToolTip>
<ToolTip Placement="Bottom" HorizontalOffset="-5" Content="{DynamicResource Webcam.ChangeScale}" />
</n:ImageButton.ToolTip>
Expand Down

0 comments on commit f7eedd9

Please sign in to comment.