Skip to content

Commit

Permalink
Add "Shadow color", "Shadow depth", "Shadow blur radius", "Shadow opa…
Browse files Browse the repository at this point in the history
…city" and "Shadow direction" options
  • Loading branch information
rampaa committed Nov 13, 2024
1 parent 0bf1907 commit 4218ed3
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 5 deletions.
45 changes: 40 additions & 5 deletions JL.Windows/ConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ internal static class ConfigManager
public static double MaxDelayBetweenCopiesForMergingMatchingSequentialTextsInMilliseconds { get; private set; } = 5000;
public static bool TextBoxUseCustomLineHeight { get; private set; } // = false;
public static double TextBoxCustomLineHeight { get; private set; } = 75;
public static Color MainTextBoxDropShadowEffectColor { get; private set; } = Colors.Black;
public static double MainTextBoxDropShadowEffectShadowDepth { get; private set; } = 1.3;
public static int MainTextBoxDropShadowEffectBlurRadius { get; private set; } = 4;
public static int MainTextBoxDropShadowEffectBlurOpacity { get; private set; } = 80;
public static int MainTextBoxDropShadowEffectDirection { get; private set; } = 320;
private static VerticalAlignment MainWindowTextVerticalAlignment { get; set; } = VerticalAlignment.Top;

#endregion
Expand Down Expand Up @@ -329,15 +334,21 @@ public static void ApplyPreferences()
HideAllTitleBarButtonsWhenMouseIsNotOverTitleBar = ConfigDBManager.GetValueFromConfig(connection, HideAllTitleBarButtonsWhenMouseIsNotOverTitleBar, nameof(HideAllTitleBarButtonsWhenMouseIsNotOverTitleBar), bool.TryParse);
MainWindow.Instance.ChangeVisibilityOfTitleBarButtons();

MainTextBoxDropShadowEffectShadowDepth = ConfigDBManager.GetNumberWithDecimalPointFromConfig(connection, MainTextBoxDropShadowEffectShadowDepth, nameof(MainTextBoxDropShadowEffectShadowDepth), double.TryParse);
MainTextBoxDropShadowEffectDirection = ConfigDBManager.GetValueFromConfig(connection, MainTextBoxDropShadowEffectDirection, nameof(MainTextBoxDropShadowEffectDirection), int.TryParse);
MainTextBoxDropShadowEffectBlurRadius = ConfigDBManager.GetValueFromConfig(connection, MainTextBoxDropShadowEffectBlurRadius, nameof(MainTextBoxDropShadowEffectBlurRadius), int.TryParse);
MainTextBoxDropShadowEffectBlurOpacity = ConfigDBManager.GetValueFromConfig(connection, MainTextBoxDropShadowEffectBlurOpacity, nameof(MainTextBoxDropShadowEffectBlurOpacity), int.TryParse);
MainTextBoxDropShadowEffectColor = GetColorFromConfig(connection, MainTextBoxDropShadowEffectColor, nameof(MainTextBoxDropShadowEffectColor));
TextBoxApplyDropShadowEffect = ConfigDBManager.GetValueFromConfig(connection, TextBoxApplyDropShadowEffect, nameof(TextBoxApplyDropShadowEffect), bool.TryParse);
if (TextBoxApplyDropShadowEffect)
{
DropShadowEffect dropShadowEffect = new()
{
Direction = 320,
BlurRadius = 4,
ShadowDepth = 1.3,
Opacity = 0.8,
Direction = MainTextBoxDropShadowEffectDirection,
BlurRadius = MainTextBoxDropShadowEffectBlurRadius,
ShadowDepth = MainTextBoxDropShadowEffectShadowDepth,
Opacity = MainTextBoxDropShadowEffectBlurOpacity / 100.0,
Color = MainTextBoxDropShadowEffectColor,
RenderingBias = RenderingBias.Quality
};

Expand Down Expand Up @@ -415,7 +426,7 @@ public static void ApplyPreferences()

MainWindow.Instance.MainGrid.Opacity = TextOnlyVisibleOnHover && !MainWindow.Instance.IsMouseOver && !PreferencesWindow.IsItVisible() ? 0 : 1;

// MAKE SURE YOU FREEZE ANY NEW COLOR OBJECTS YOU ADD
// MAKE SURE YOU FREEZE ANY NEW FREEZABLE OBJECTS YOU ADD
// OR THE PROGRAM WILL CRASH AND BURN
MainWindowTextColor = GetFrozenBrushFromConfig(connection, MainWindowTextColor, nameof(MainWindowTextColor));
MainWindowBacklogTextColor = GetFrozenBrushFromConfig(connection, MainWindowBacklogTextColor, nameof(MainWindowBacklogTextColor));
Expand Down Expand Up @@ -771,6 +782,7 @@ public static void LoadPreferenceWindow(PreferencesWindow preferenceWindow)
WindowsUtils.SetButtonColor(preferenceWindow.MainWindowBackgroundColorButton, MainWindow.Instance.Background.CloneCurrentValue());
WindowsUtils.SetButtonColor(preferenceWindow.TextBoxTextColorButton, MainWindowTextColor);
WindowsUtils.SetButtonColor(preferenceWindow.TextBoxBacklogTextColorButton, MainWindowBacklogTextColor);
WindowsUtils.SetButtonColor(preferenceWindow.MainTextBoxDropShadowEffectColorButton, MainTextBoxDropShadowEffectColor);
WindowsUtils.SetButtonColor(preferenceWindow.DeconjugationInfoColorButton, DeconjugationInfoColor);
WindowsUtils.SetButtonColor(preferenceWindow.DefinitionsColorButton, DefinitionsColor);
WindowsUtils.SetButtonColor(preferenceWindow.FrequencyColorButton, FrequencyColor);
Expand Down Expand Up @@ -822,6 +834,11 @@ public static void LoadPreferenceWindow(PreferencesWindow preferenceWindow)
preferenceWindow.ChangeMainWindowBackgroundOpacityOnUnhoverCheckBox.IsChecked = ChangeMainWindowBackgroundOpacityOnUnhover;
preferenceWindow.MainWindowBackgroundOpacityOnUnhoverNumericUpDown.Value = MainWindowBackgroundOpacityOnUnhover;

preferenceWindow.MainTextBoxDropShadowEffectDirectionNumericUpDown.Value = MainTextBoxDropShadowEffectDirection;
preferenceWindow.MainTextBoxDropShadowEffectBlurRadiusNumericUpDown.Value = MainTextBoxDropShadowEffectBlurRadius;
preferenceWindow.MainTextBoxDropShadowEffectShadowDepthNumericUpDown.Value = MainTextBoxDropShadowEffectShadowDepth;
preferenceWindow.MainTextBoxDropShadowEffectBlurOpacityNumericUpDown.Value = MainTextBoxDropShadowEffectBlurOpacity;

preferenceWindow.TextBoxIsReadOnlyCheckBox.IsChecked = TextBoxIsReadOnly;
preferenceWindow.AlwaysShowMainTextBoxCaretCheckBox.IsChecked = AlwaysShowMainTextBoxCaret;
preferenceWindow.TextBoxTrimWhiteSpaceCharactersCheckBox.IsChecked = CoreConfigManager.TextBoxTrimWhiteSpaceCharacters;
Expand Down Expand Up @@ -1037,6 +1054,12 @@ public static async Task SavePreferences(PreferencesWindow preferenceWindow)
ConfigDBManager.UpdateSetting(connection, nameof(MainWindowHeight),
preferenceWindow.MainWindowHeightNumericUpDown.Value.ToString(CultureInfo.InvariantCulture));

ConfigDBManager.UpdateSetting(connection, nameof(MainTextBoxDropShadowEffectDirection), preferenceWindow.MainTextBoxDropShadowEffectDirectionNumericUpDown.Value.ToString(CultureInfo.InvariantCulture));
ConfigDBManager.UpdateSetting(connection, nameof(MainTextBoxDropShadowEffectBlurRadius), preferenceWindow.MainTextBoxDropShadowEffectBlurRadiusNumericUpDown.Value.ToString(CultureInfo.InvariantCulture));
ConfigDBManager.UpdateSetting(connection, nameof(MainTextBoxDropShadowEffectShadowDepth), preferenceWindow.MainTextBoxDropShadowEffectShadowDepthNumericUpDown.Value.ToString(CultureInfo.InvariantCulture));
ConfigDBManager.UpdateSetting(connection, nameof(MainTextBoxDropShadowEffectBlurOpacity), preferenceWindow.MainTextBoxDropShadowEffectBlurOpacityNumericUpDown.Value.ToString(CultureInfo.InvariantCulture));
ConfigDBManager.UpdateSetting(connection, nameof(MainTextBoxDropShadowEffectColor), preferenceWindow.MainTextBoxDropShadowEffectColorButton.Tag.ToString()!);

// We want the opaque color here
ConfigDBManager.UpdateSetting(connection, "MainWindowBackgroundColor",
preferenceWindow.MainWindowBackgroundColorButton.Background.ToString(CultureInfo.InvariantCulture));
Expand Down Expand Up @@ -1383,6 +1406,18 @@ private static Brush GetBrushFromConfig(SqliteConnection connection, Brush solid
: solidColorBrush;
}

private static Color GetColorFromConfig(SqliteConnection connection, Color color, string configKey)
{
string? configValue = ConfigDBManager.GetSettingValue(connection, configKey);
if (configValue is not null)
{
return WindowsUtils.ColorFromHex(configValue);
}

ConfigDBManager.InsertSetting(connection, configKey, color.ToString(CultureInfo.InvariantCulture));
return WindowsUtils.ColorFromHex(color.ToString(CultureInfo.InvariantCulture));
}

private static Brush GetFrozenBrushFromConfig(SqliteConnection connection, Brush solidColorBrush, string configKey)
{
Brush brush = GetBrushFromConfig(connection, solidColorBrush, configKey);
Expand Down
41 changes: 41 additions & 0 deletions JL.Windows/GUI/PreferencesWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,47 @@
<CheckBox x:Name="TextBoxApplyDropShadowEffectCheckBox" HorizontalAlignment="Right" />
</DockPanel>

<DockPanel>
<TextBlock HorizontalAlignment="Left" Text="Shadow color"
Style="{StaticResource TextBlockDefault}"
TextWrapping="Wrap" VerticalAlignment="Center" />
<Button x:Name="MainTextBoxDropShadowEffectColorButton" HorizontalAlignment="Right"
Width="60" Height="32" BorderThickness="5,5,5,5"
Click="ShowColorPicker" BorderBrush="#FF707070" />
</DockPanel>

<DockPanel>
<TextBlock HorizontalAlignment="Left" Text="Shadow depth"
Style="{StaticResource TextBlockDefault}"
TextWrapping="Wrap" VerticalAlignment="Center" />
<hc:NumericUpDown x:Name="MainTextBoxDropShadowEffectShadowDepthNumericUpDown" Maximum="10" Minimum="0" DecimalPlaces="1"
HorizontalAlignment="Right" />
</DockPanel>

<DockPanel>
<TextBlock HorizontalAlignment="Left" Text="Shadow blur radius"
Style="{StaticResource TextBlockDefault}"
TextWrapping="Wrap" VerticalAlignment="Center" />
<hc:NumericUpDown x:Name="MainTextBoxDropShadowEffectBlurRadiusNumericUpDown" Maximum="100" Minimum="0" DecimalPlaces="0"
HorizontalAlignment="Right" />
</DockPanel>

<DockPanel>
<TextBlock HorizontalAlignment="Left" Text="Shadow opacity"
Style="{StaticResource TextBlockDefault}"
TextWrapping="Wrap" VerticalAlignment="Center" />
<hc:NumericUpDown x:Name="MainTextBoxDropShadowEffectBlurOpacityNumericUpDown" Maximum="100" Minimum="0" DecimalPlaces="0"
HorizontalAlignment="Right" />
</DockPanel>

<DockPanel>
<TextBlock HorizontalAlignment="Left" Text="Shadow direction (in degrees)"
Style="{StaticResource TextBlockDefault}"
TextWrapping="Wrap" VerticalAlignment="Center" />
<hc:NumericUpDown x:Name="MainTextBoxDropShadowEffectDirectionNumericUpDown" Maximum="360" Minimum="0" DecimalPlaces="0"
HorizontalAlignment="Right" />
</DockPanel>

<DockPanel>
<TextBlock HorizontalAlignment="Left" Text="Focus on hover"
Style="{StaticResource TextBlockDefault}"
Expand Down
11 changes: 11 additions & 0 deletions JL.Windows/Utilities/WindowsUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,11 @@ public static Brush FrozenBrushFromHex(string hexColorString)
return brush;
}

public static Color ColorFromHex(string hexColorString)
{
return (Color)ColorConverter.ConvertFromString(hexColorString);
}

public static void Alert(AlertLevel alertLevel, string message)
{
_ = Application.Current.Dispatcher.InvokeAsync(async () =>
Expand Down Expand Up @@ -515,6 +520,12 @@ public static void SetButtonColor(Button button, Brush selectedBrush)
button.Background = CreateFrozenOpaqueBrush(selectedBrushColor);
}

public static void SetButtonColor(Button button, Color selectedColor)
{
button.Tag = new SolidColorBrush(selectedColor);
button.Background = CreateFrozenOpaqueBrush(selectedColor);
}

private static Brush CreateFrozenOpaqueBrush(Color color)
{
Brush opaqueBrush = new SolidColorBrush(Color.FromRgb(color.R, color.G, color.B));
Expand Down

0 comments on commit 4218ed3

Please sign in to comment.