Skip to content

Commit

Permalink
further UI improvement/fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Aytackydln committed Jan 1, 2024
1 parent 2d64348 commit f18dcb3
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private void UserControl_Loaded(object? sender, EventArgs e)
{
Global.logger.Warning(ex, "DeviceItem update error:");
}
}, DispatcherPriority.Background);
}, DispatcherPriority.Loaded);
}

private void Control_DeviceItem_OnUnloaded(object? sender, EventArgs e)
Expand All @@ -154,7 +154,7 @@ private void OnDeviceOnUpdated(object? o, EventArgs eventArgs)
{
Global.logger.Warning(ex, "DeviceItem update error:");
}
}, Background);
}, DispatcherPriority.DataBind);
}

private void UpdateStatic()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private void UpdateVariables()
{
foreach (var deviceVariable in _deviceVariables)
{
Func<byte[]?, object?> convert = deviceVariable.ValueType switch
Func<byte[]?, object> convert = deviceVariable.ValueType switch
{
VariableType.None => _ => new object(),
VariableType.Boolean => data => BitConverter.ToBoolean(data),
Expand Down
3 changes: 2 additions & 1 deletion Project-Aurora/Project-Aurora/Modules/Inputs/InputEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public sealed class InputEvents : IInputEvents
private static readonly Keys[] WinKeys = { Keys.LWin, Keys.RWin };
public bool Windows => WinKeys.Any(PressedKeys.Contains);

delegate IntPtr WndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
private delegate IntPtr WndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable to keep reference for garbage collector
private readonly WndProc? _fnWndProcHook;
private readonly nint _originalWndProc;
private readonly IntPtr _hWnd;
Expand Down
3 changes: 2 additions & 1 deletion Project-Aurora/Project-Aurora/Project-Aurora.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<Configurations>Debug;Release</Configurations>
<Nullable>enable</Nullable>
<StartupObject>Aurora.App</StartupObject>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
Expand Down Expand Up @@ -95,7 +96,7 @@
<ItemGroup>
<ProjectReference Include="..\AuroraCommon\AuroraCommon.csproj" />
<ProjectReference Include="..\ColorBox\ColorBox.csproj" />
<ProjectReference Include="..\AuroraCommon\AuroraCommon.csproj" >
<ProjectReference Include="..\AuroraCommon\AuroraCommon.csproj">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</ProjectReference>
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ namespace Aurora.Settings.Controls;
/// </summary>
public partial class Control_LayerControlPresenter
{
private bool isSettingNewLayer;
private static readonly Canvas EmptyContent = new();
private bool _isSettingNewLayer;

protected Layer _Layer;
private Layer? _Layer;

public Layer Layer { get => _Layer;
public Layer? Layer { get => _Layer;
set { _Layer = value; SetLayer(value); } }

public Control_LayerControlPresenter()
Expand All @@ -26,13 +27,14 @@ public Control_LayerControlPresenter()

private async void SetLayer(Layer layer)
{
isSettingNewLayer = true;
_isSettingNewLayer = true;

DataContext = layer;

cmbLayerType.ItemsSource = layer.AssociatedApplication.AllowedLayers.OrderBy(l => l.Order).ThenBy(l => l.Name);
cmbLayerType.SelectedValue = Layer.Handler.GetType();

ctrlLayerTypeConfig.Content = EmptyContent;
ctrlLayerTypeConfig.Content = await layer.Control;
chkLayerSmoothing.IsChecked = Layer.Handler.EnableSmoothing;
chk_ExcludeMask.IsChecked = Layer.Handler._EnableExclusionMask ?? false;
Expand All @@ -46,91 +48,88 @@ private async void SetLayer(Layer layer)
btnOverrides.Visibility = Visibility.Visible;
grd_LayerControl.IsHitTestVisible = true;
grd_LayerControl.Effect = null;
isSettingNewLayer = false;
_isSettingNewLayer = false;

overridesEditor.Layer = layer;
}

private void cmbLayerType_SelectionChanged(object? sender, SelectionChangedEventArgs e)
{
if (IsLoaded && !isSettingNewLayer && sender is ComboBox)
{
_Layer?.Dispose();
ResetLayer((Type)(sender as ComboBox).SelectedValue);
}
if (!IsLoaded || _isSettingNewLayer || sender is not ComboBox comboBox) return;
_Layer?.Dispose();
ResetLayer((Type)comboBox.SelectedValue);
}

private async void ResetLayer(Type type)
{
if (IsLoaded && !isSettingNewLayer && type != null)
{
_Layer.Handler = (ILayerHandler)Activator.CreateInstance(type);
if (!IsLoaded || _isSettingNewLayer || type == null) return;

ctrlLayerTypeConfig.Content = await _Layer.Control;
chkLayerSmoothing.IsChecked = _Layer.Handler.EnableSmoothing;
chk_ExcludeMask.IsChecked = Layer.Handler._EnableExclusionMask ?? false;
keyseq_ExcludeMask.Sequence = Layer.Handler._ExclusionMask;
sldr_Opacity.Value = (int)(Layer.Handler.Opacity * 100.0f);
lbl_Opacity_Text.Text = $"{(int)sldr_Opacity.Value} %";
_Layer.AssociatedApplication.SaveProfiles();
_Layer.Handler = (ILayerHandler)Activator.CreateInstance(type);

overridesEditor.ForcePropertyListUpdate();
}
ctrlLayerTypeConfig.Content = EmptyContent;
ctrlLayerTypeConfig.Content = await _Layer.Control;
chkLayerSmoothing.IsChecked = _Layer.Handler.EnableSmoothing;
chk_ExcludeMask.IsChecked = Layer.Handler._EnableExclusionMask ?? false;
keyseq_ExcludeMask.Sequence = Layer.Handler._ExclusionMask;
sldr_Opacity.Value = (int)(Layer.Handler.Opacity * 100.0f);
lbl_Opacity_Text.Text = $"{(int)sldr_Opacity.Value} %";
_Layer.AssociatedApplication.SaveProfiles();

overridesEditor.ForcePropertyListUpdate();
}

private void btnReset_Click(object? sender, RoutedEventArgs e)
{
if (IsLoaded && !isSettingNewLayer && sender is Button)
if (IsLoaded && !_isSettingNewLayer && sender is Button)
{
ResetLayer((Type)cmbLayerType.SelectedValue);
}
}

private void btnConfig_Click(object? sender, RoutedEventArgs e)
{
if (IsLoaded && !isSettingNewLayer && sender is Button)
{
var v = grdLayerConfigs.IsVisible;
grdLayerConfigs.Visibility = v ? Visibility.Hidden : Visibility.Visible;
grd_LayerControl.IsHitTestVisible = v;
grd_LayerControl.Effect = v ? null : new BlurEffect();
btnOverrides.Visibility = v ? Visibility.Visible : Visibility.Collapsed;
}
if (!IsLoaded || _isSettingNewLayer || sender is not Button) return;

var v = grdLayerConfigs.IsVisible;
grdLayerConfigs.Visibility = v ? Visibility.Hidden : Visibility.Visible;
grd_LayerControl.IsHitTestVisible = v;
grd_LayerControl.Effect = v ? null : new BlurEffect();
btnOverrides.Visibility = v ? Visibility.Visible : Visibility.Collapsed;
}

private void chkLayerSmoothing_Checked(object? sender, RoutedEventArgs e)
{
if (IsLoaded && !isSettingNewLayer && sender is CheckBox checkBox)
if (IsLoaded && !_isSettingNewLayer && sender is CheckBox checkBox)
Layer.Handler.EnableSmoothing = checkBox.IsChecked.Value;
}

private void chk_ExcludeMask_Checked(object? sender, RoutedEventArgs e)
{
if (IsLoaded && !isSettingNewLayer && sender is CheckBox checkBox)
if (IsLoaded && !_isSettingNewLayer && sender is CheckBox checkBox)
Layer.Handler._EnableExclusionMask = checkBox.IsChecked.Value;
}

private void keyseq_ExcludeMask_SequenceUpdated(object? sender, RoutedPropertyChangedEventArgs<KeySequence> e)
{
if (IsLoaded && !isSettingNewLayer)
if (IsLoaded && !_isSettingNewLayer)
Layer.Handler._ExclusionMask = e.NewValue;
}

private void sldr_Opacity_ValueChanged(object? sender, RoutedPropertyChangedEventArgs<double> e)
{
if (IsLoaded && !isSettingNewLayer)
{
Layer.Handler._Opacity = (float)e.NewValue / 100.0f;
lbl_Opacity_Text.Text = $"{(int)e.NewValue} %";
}
if (!IsLoaded || _isSettingNewLayer) return;

Layer.Handler._Opacity = (float)e.NewValue / 100.0f;
lbl_Opacity_Text.Text = $"{(int)e.NewValue} %";
}

private void btnOverrides_Click(object? sender, RoutedEventArgs e) {
if (IsLoaded && !isSettingNewLayer) {
var v = overridesEditor.IsVisible;
overridesEditor.Visibility = v ? Visibility.Hidden : Visibility.Visible;
grd_LayerControl.IsHitTestVisible = v;
btnConfig.Visibility = v ? Visibility.Visible : Visibility.Collapsed;
}
private void btnOverrides_Click(object? sender, RoutedEventArgs e)
{
if (!IsLoaded || _isSettingNewLayer) return;

var v = overridesEditor.IsVisible;
overridesEditor.Visibility = v ? Visibility.Hidden : Visibility.Visible;
grd_LayerControl.IsHitTestVisible = v;
btnConfig.Visibility = v ? Visibility.Visible : Visibility.Collapsed;
}
}
9 changes: 5 additions & 4 deletions Project-Aurora/Project-Aurora/Settings/Layers/LayerHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public abstract class LayerHandler<TProperty> : ILayerHandler where TProperty :
public Application Application { get; protected set; }

[JsonIgnore]
protected Task<UserControl>? _Control;
private Task<UserControl>? _Control;

[JsonIgnore]
public Task<UserControl> Control => _Control ??= CreateControlOnMain();
Expand Down Expand Up @@ -387,7 +387,6 @@ public virtual async void SetApplication(Application profile)
{
Application = profile;
await Initialize();
(await Control as IProfileContainingControl)?.SetProfile(profile);
}

protected virtual Task Initialize()
Expand All @@ -397,10 +396,12 @@ protected virtual Task Initialize()

private Task<UserControl> CreateControlOnMain()
{
var tcs = new TaskCompletionSource<UserControl>();
var tcs = new TaskCompletionSource<UserControl>(TaskCreationOptions.RunContinuationsAsynchronously);
System.Windows.Application.Current.Dispatcher.BeginInvoke(() =>
{
tcs.SetResult(CreateControl());
var layerControl = CreateControl();
(layerControl as IProfileContainingControl)?.SetProfile(Application);
tcs.SetResult(layerControl);
}, DispatcherPriority.Loaded);
return tcs.Task;
}
Expand Down
7 changes: 2 additions & 5 deletions Project-Aurora/Project-Aurora/Utils/SystemUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,15 @@ public static string GetSystemInfo()
systemInfoSb.Append($"Executing Directory: {Global.ExecutingDirectory}\r\n");
systemInfoSb.Append($"Launch Directory: {Directory.GetCurrentDirectory()}\r\n");
systemInfoSb.Append($"Processor Count: {Environment.ProcessorCount}\r\n");

systemInfoSb.Append($"SystemPageSize: {Environment.SystemPageSize}\r\n");
systemInfoSb.Append($"Environment Version: {Environment.Version}\r\n");

var identity = WindowsIdentity.GetCurrent();
var principal = new WindowsPrincipal(identity);
systemInfoSb.Append($"Is Elevated: {principal.IsInRole(WindowsBuiltInRole.Administrator)}\r\n");
systemInfoSb.Append($"Aurora Assembly Version: {Assembly.GetExecutingAssembly().GetName().Version}\r\n");
systemInfoSb.Append(
$"Aurora File Version: {FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion}\r\n");
systemInfoSb.Append($"Aurora File Version: {FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion}\r\n");

systemInfoSb.Append("========================================\r\n");
systemInfoSb.Append("========================================");

return systemInfoSb.ToString();
}
Expand Down

0 comments on commit f18dcb3

Please sign in to comment.