Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into rect-based-undo-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
flabbet committed Feb 15, 2022
2 parents 7a6718d + f50f2fe commit d735d59
Show file tree
Hide file tree
Showing 79 changed files with 1,701 additions and 329 deletions.
4 changes: 3 additions & 1 deletion PixiEditor/App.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<Application x:Class="PixiEditor.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Views/MainWindow.xaml">
>
<!--StartupUri="Views/MainWindow.xaml"-->
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
Expand All @@ -26,6 +27,7 @@
<ResourceDictionary Source="Styles/AvalonDock/Themes/Generic.xaml" />
<ResourceDictionary Source="Styles/AvalonDock/PixiEditorDockTheme.xaml" />
<ResourceDictionary Source="Styles/TreeViewStyle.xaml" />
<ResourceDictionary Source="Styles/RadioButtonStyle.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Expand Down
37 changes: 36 additions & 1 deletion PixiEditor/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
using PixiEditor.Models.Dialogs;
using PixiEditor.Models.DataHolders;
using PixiEditor.Models.Dialogs;
using PixiEditor.Models.Enums;
using PixiEditor.ViewModels;
using PixiEditor.Views.Dialogs;
using System;
using System.Diagnostics;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows;

namespace PixiEditor
Expand All @@ -11,6 +16,23 @@ namespace PixiEditor
/// </summary>
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
string arguments = string.Join(' ', e.Args);

if (ParseArgument("--crash (\"?)([A-z0-9:\\/\\ -_.]+)\\1", arguments, out Group[] groups))
{
CrashReport report = CrashReport.Parse(groups[2].Value);
MainWindow = new CrashReportDialog(report);
}
else
{
MainWindow = new MainWindow();
}

MainWindow.Show();
}

protected override void OnSessionEnding(SessionEndingCancelEventArgs e)
{
base.OnSessionEnding(e);
Expand All @@ -21,5 +43,18 @@ protected override void OnSessionEnding(SessionEndingCancelEventArgs e)
e.Cancel = confirmation != ConfirmationType.Yes;
}
}

private bool ParseArgument(string pattern, string args, out Group[] groups)
{
Match match = Regex.Match(args, pattern, RegexOptions.IgnoreCase);
groups = null;

if (match.Success)
{
groups = match.Groups.Values.ToArray();
}

return match.Success;
}
}
}
37 changes: 37 additions & 0 deletions PixiEditor/Helpers/Converters/EnumBooleanConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace PixiEditor.Helpers.Converters
{
public class EnumBooleanConverter : SingleInstanceConverter<EnumBooleanConverter>
{
#region IValueConverter Members
public override object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
string parameterString = parameter as string;
if (parameterString == null)
return DependencyProperty.UnsetValue;

if (Enum.IsDefined(value.GetType(), value) == false)
return DependencyProperty.UnsetValue;

object parameterValue = Enum.Parse(value.GetType(), parameterString);

return parameterValue.Equals(value);
}

public override object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
string parameterString = parameter as string;
if (parameterString == null)
return DependencyProperty.UnsetValue;

return Enum.Parse(targetType, parameterString);
}
#endregion
}
}
29 changes: 29 additions & 0 deletions PixiEditor/Helpers/Converters/EnumToStringConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using PixiEditor.Models.Enums;
using System;

namespace PixiEditor.Helpers.Converters
{
internal class EnumToStringConverter : SingleInstanceConverter<EnumToStringConverter>
{
public override object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
try
{
var type = value.GetType();
if (type == typeof(SizeUnit))
{
var valueCasted = (SizeUnit)value;
if (valueCasted == SizeUnit.Percentage)
return "%";

return "px";
}
return Enum.GetName((value.GetType()), value);
}
catch
{
return string.Empty;
}
}
}
}
46 changes: 24 additions & 22 deletions PixiEditor/Helpers/Converters/FileExtensionToColorConverter.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
using System;
using PixiEditor.Models;
using System;
using System.Linq;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.Globalization;
using System.Windows.Media;
using PixiEditor.Models.Enums;

namespace PixiEditor.Helpers.Converters
{
public class FileExtensionToColorConverter :
SingleInstanceConverter<FileExtensionToColorConverter>
{
private static readonly SolidColorBrush PixiBrush = ColorBrush(226, 1, 45);

private static readonly SolidColorBrush PngBrush = ColorBrush(56, 108, 254);

private static readonly SolidColorBrush JpgBrush = ColorBrush(36, 179, 66);

private static readonly SolidColorBrush UnknownBrush = ColorBrush(100, 100, 100);
private static readonly Dictionary<string, SolidColorBrush> extensionsToBrushes;
public static readonly SolidColorBrush UnknownBrush = ColorBrush(100, 100, 100);

static FileExtensionToColorConverter()
{
extensionsToBrushes = new Dictionary<string, SolidColorBrush>();
AssignFormatToBrush(FileType.Unset, UnknownBrush);
AssignFormatToBrush(FileType.Pixi, ColorBrush(226, 1, 45));
AssignFormatToBrush(FileType.Png, ColorBrush(56, 108, 254));
AssignFormatToBrush(FileType.Jpeg, ColorBrush(36, 179, 66));
AssignFormatToBrush(FileType.Bmp, ColorBrush(255, 140, 0));
AssignFormatToBrush(FileType.Gif, ColorBrush(180, 0, 255));
}
static void AssignFormatToBrush(FileType format, SolidColorBrush brush)
{
SupportedFilesHelper.GetFileTypeDialogData(format).Extensions.ForEach(i => extensionsToBrushes[i] = brush);
}

public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
string extension = (string)value;

if (extension == ".pixi")
{
return PixiBrush;
}
else if (extension == ".png")
{
return PngBrush;
}
else if (extension is ".jpg" or ".jpeg")
{
return JpgBrush;
}

return UnknownBrush;
return extensionsToBrushes.ContainsKey(extension) ? extensionsToBrushes[extension] : UnknownBrush;
}

private static SolidColorBrush ColorBrush(byte r, byte g, byte b)
Expand Down
2 changes: 1 addition & 1 deletion PixiEditor/Helpers/Converters/ToolSizeToIntConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ public override object ConvertBack(object value, Type targetType, object paramet
return int.Parse(match.Groups[0].ValueSpan);
}
}
}
}
83 changes: 63 additions & 20 deletions PixiEditor/Helpers/CrashHelper.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,76 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using ByteSizeLib;
using Hardware.Info;
using PixiEditor.Models.DataHolders;
using System;
using System.Globalization;
using System.Text;
using System.Threading.Tasks;

namespace PixiEditor.Helpers
{
public static class CrashHelper
public class CrashHelper
{
public static void SaveCrashInfo(Exception e)
private readonly IHardwareInfo hwInfo;

public static void SaveCrashInfo(Exception exception)
{
CrashReport report = CrashReport.Generate(exception);
report.TrySave();
report.RestartToCrashReport();
}

public CrashHelper()
{
hwInfo = new HardwareInfo();
}

public void GetCPUInformation(StringBuilder builder)
{
builder.AppendLine("CPU:");
hwInfo.RefreshCPUList(false);

foreach (var processor in hwInfo.CpuList)
{
builder
.AppendLine($" Name: {processor.Name}")
.AppendLine($" Speed: {(processor.CurrentClockSpeed / 1000f).ToString("F2", CultureInfo.InvariantCulture)} GHz")
.AppendLine($" Max Speed: {(processor.MaxClockSpeed / 1000f).ToString("F2", CultureInfo.InvariantCulture)} GHz")
.AppendLine();
}
}

public void GetGPUInformation(StringBuilder builder)
{
StringBuilder builder = new System.Text.StringBuilder();
DateTime currentTime = DateTime.Now;
builder.AppendLine("GPU:");
hwInfo.RefreshVideoControllerList();

foreach (var gpu in hwInfo.VideoControllerList)
{
builder
.AppendLine($" Name: {gpu.Name}")
.AppendLine($" Driver: {gpu.DriverVersion}")
.AppendLine();
}
}

public void GetMemoryInformation(StringBuilder builder)
{
builder.AppendLine("Memory:");
hwInfo.RefreshMemoryStatus();

var memInfo = hwInfo.MemoryStatus;

builder
.AppendLine($" Available: {new ByteSize(memInfo.AvailablePhysical).ToString("", CultureInfo.InvariantCulture)}")
.AppendLine($" Total: {new ByteSize(memInfo.TotalPhysical).ToString("", CultureInfo.InvariantCulture)}");
}

public static void AddExceptionMessage(StringBuilder builder, Exception e)
{
builder
.Append($"PixiEditor crashed on {currentTime:yyyy.MM.dd} at {currentTime:HH:mm:ss}\n\n")
.Append("-------Crash message-------\n")
.AppendLine("\n-------Crash message-------")
.Append(e.GetType().ToString())
.Append(": ")
.Append(e.Message);
.AppendLine(e.Message);
{
var innerException = e.InnerException;
while (innerException != null)
Expand All @@ -46,14 +97,6 @@ public static void SaveCrashInfo(Exception e)
innerException = innerException.InnerException;
}
}

string filename = $"crash-{currentTime:yyyy-MM-dd_HH-mm-ss_fff}.txt";
string path = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"PixiEditor",
"crash_logs");
Directory.CreateDirectory(path);
File.WriteAllText(Path.Combine(path, filename), builder.ToString());
}
}
}
19 changes: 19 additions & 0 deletions PixiEditor/Helpers/ProcessHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Diagnostics;

namespace PixiEditor.Helpers
{
public static class ProcessHelpers
{
public static void ShellExecute(string url)
{
Process.Start(new ProcessStartInfo
{
FileName = url,
UseShellExecute = true
});
}

public static void ShellExecuteEV(string path) => ShellExecute(Environment.ExpandEnvironmentVariables(path));
}
}
20 changes: 20 additions & 0 deletions PixiEditor/Helpers/SizeCalculator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;

namespace PixiEditor.Helpers
{
public static class SizeCalculator
{
public static System.Drawing.Size CalcAbsoluteFromPercentage(float percentage, System.Drawing.Size currentSize)
{
float percFactor = percentage / 100f;
float newWidth = currentSize.Width * percFactor;
float newHeight = currentSize.Height * percFactor;
return new System.Drawing.Size((int)MathF.Round(newWidth), (int)MathF.Round(newHeight));
}

public static int CalcPercentageFromAbsolute(int initAbsoluteSize, int currentAbsoluteSize)
{
return (int)((float)currentAbsoluteSize * 100) / initAbsoluteSize;
}
}
}
Loading

0 comments on commit d735d59

Please sign in to comment.