Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transparency Slider in Context Menu (with typo fix) #234

Merged
merged 12 commits into from
Feb 3, 2024
60 changes: 60 additions & 0 deletions OotD.Core/Controls/TransparencyMenuSlider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System;
using System.Drawing;
using System.Windows.Forms;
using MACTrackBarLib;

namespace OotD.Controls;

public class TrackBarMenuItem : ToolStripControlHost
{
#pragma warning disable CS3003
public MACTrackBar TrackBar { get; }
#pragma warning restore CS3003

public event EventHandler? ValueChanged;

public ToolTip ToolTip { get; } = new ToolTip(); // Add ToolTip property

public TrackBarMenuItem() : base(new MACTrackBar())
{
TrackBar = (MACTrackBar)Control;
TrackBar.Scroll += TrackBar_Scroll;
}

public Point Location
{
get { return TrackBar.Location; }
set { TrackBar.Location = value; }
}

public int Minimum
{
get { return TrackBar.Minimum; }
set { TrackBar.Minimum = value; }
}

public int Maximum
{
get { return TrackBar.Maximum; }
set { TrackBar.Maximum = value; }
}

public int Value
{
get { return TrackBar.Value; }
set { TrackBar.Value = value; }
}

public TickStyle TickStyle
{
get { return TrackBar.TickStyle; }
set { TrackBar.TickStyle = value; }
}

// Add more properties as needed...

private void TrackBar_Scroll(object? sender, EventArgs e)
{
ValueChanged?.Invoke(this, EventArgs.Empty);
}
}
30 changes: 28 additions & 2 deletions OotD.Core/Forms/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 26 additions & 2 deletions OotD.Core/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Microsoft.Office.Interop.Outlook;
using Microsoft.Win32;
using NLog;
using OotD.Controls;
using OotD.Enums;
using OotD.Events;
using OotD.Preferences;
Expand Down Expand Up @@ -345,6 +346,8 @@ private void SetWindowOpacity()
}

TransparencySlider.Value = (int)(Preferences.Opacity * 100);
TransparencyMenuSlider.Value = (int)(Preferences.Opacity * 100);
OpacityLabel.Text = Resources.Opacity + Math.Round(Preferences.Opacity * 100) + Resources.Percentage;
}

/// <summary>
Expand Down Expand Up @@ -1234,16 +1237,37 @@ private CurrentCalendarView GetCurrentCalendarViewMode()
return mode;
}

private void TransparencySlider_ValueChanged(object sender, EventArgs e, decimal value)
private void TransparencySlider_ValueChanged(object sender, EventArgs args, decimal value)
{
var opacityVal = (double)(value / 100);
if (Math.Abs(opacityVal - 1) < double.Epsilon)
{
opacityVal = 0.99;
}

OpacityLabel.Text = Resources.Opacity + Math.Round(opacityVal * 100) + Resources.Percentage;

Opacity = opacityVal;
Preferences.Opacity = opacityVal;

// Keep the other slider in sync
TransparencyMenuSlider.Value = (int)(opacityVal * 100);
}

private void TransparencyMenuSlider_ValueChanged(object sender, EventArgs e)
{
var trackBar = (TrackBarMenuItem)sender;
var opacityVal = (double)trackBar.Value / 100; // Get the value from TransparencyMenuSlider
if (Math.Abs(opacityVal - 1) < double.Epsilon)
{
opacityVal = 0.99;
}

// Keep the other slider in sync
TransparencySlider.Value = (int)(opacityVal * 100);

// Trigger the ValueChanged event for TransparencySlider to make sure it's persisted
TransparencySlider_ValueChanged(TransparencySlider, EventArgs.Empty, (decimal)(opacityVal * 100));
}

private void WindowMessageTimer_Tick(object sender, EventArgs e)
Expand All @@ -1255,7 +1279,7 @@ private void WindowMessageTimer_Tick(object sender, EventArgs e)

/// <summary>
/// Standard windows message handler. The main reason this exists is to ensure
/// the OotD window always stays behind other windows. A side affect of that is that even
/// the OotD window always stays behind other windows. A side effect of that is that even
/// context menus from OotD show up behind the main window, so we have to do some trickery below
/// to handle that case and make sure that the outlook view control context menu shows up in front of
/// the main window. Since we don't have access to the context menu directly, we have to bring the
Expand Down
13 changes: 13 additions & 0 deletions OotD.Core/OotD.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,17 @@
<PackageReference Include="NLog.Schema" Version="5.2.8" />
<PackageReference Include="TaskScheduler" Version="2.10.1" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project>
17 changes: 13 additions & 4 deletions OotD.Core/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions OotD.Core/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Position" xml:space="preserve">
<value>Position</value>
Expand Down Expand Up @@ -144,7 +144,7 @@
<data name="CancelButton" xml:space="preserve">
<value>&amp;Cancel</value>
</data>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="_8" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Icons\8.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
Expand Down Expand Up @@ -224,7 +224,7 @@
<value>Width</value>
</data>
<data name="Opacity" xml:space="preserve">
<value>Opacity:</value>
<value>Opacity: </value>
</data>
<data name="ErrorSettingFolder" xml:space="preserve">
<value>There was an error changing to the folder you specified. It may not be compatible with Outlook on the Desktop.</value>
Expand Down Expand Up @@ -492,4 +492,7 @@ If you have 32-bit Office installed, please use the 32-bit Outlook on the Deskto
<data name="OutlookNotRunning" xml:space="preserve">
<value>OotD detected that Outlook is not running. Perhaps it crashed or was closed accidentally. OotD cannot run without it and will need to be restarted. OotD will now close. </value>
</data>
<data name="Percentage" xml:space="preserve">
<value>%</value>
</data>
</root>
1 change: 1 addition & 0 deletions OotD.x64/OotD.x64.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="..\OotD.Core\Startup.cs" Link="Startup.cs" />
<Compile Include="..\OotD.Core\Controls\TransparencyMenuSlider.cs" Link="Controls\TransparencyMenuSlider.cs" />
<Compile Include="..\OotD.Core\Utility\OutlookFolderDefinition.cs" Link="Utility\OutlookFolderDefinition.cs" />
<Compile Include="..\OotD.Core\Utility\RegistryHelper.cs" Link="Utility\RegistryHelper.cs" />
<Compile Include="..\OotD.Core\Utility\StickyWindow.cs" Link="Utility\StickyWindow.cs" />
Expand Down
1 change: 1 addition & 0 deletions OotD.x86/OotD.x86.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="..\OotD.Core\Startup.cs" Link="Startup.cs" />
<Compile Include="..\OotD.Core\Controls\TransparencyMenuSlider.cs" Link="Controls\TransparencyMenuSlider.cs" />
<Compile Include="..\OotD.Core\Utility\OutlookFolderDefinition.cs" Link="Utility\OutlookFolderDefinition.cs" />
<Compile Include="..\OotD.Core\Utility\RegistryHelper.cs" Link="Utility\RegistryHelper.cs" />
<Compile Include="..\OotD.Core\Utility\StickyWindow.cs" Link="Utility\StickyWindow.cs" />
Expand Down
4 changes: 2 additions & 2 deletions Setup Script.iss
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Name: {group}\{cm:UninstallProgram,{#MyAppName}}; Filename: {uninstallexe}
[Registry]
Root: "HKCU"; Subkey: "Software\Microsoft\Windows\CurrentVersion\Run"; ValueName: "OutlookOnDesktop"; ValueType: string; Flags: deletevalue;
Root: "HKCU"; Subkey: "Software\SMR Computer Services\Outlook On The Desktop"; Flags: createvalueifdoesntexist uninsdeletekey
Root: "HKCU"; Subkey: "Software\SMR Computer Services\Outlook On The Desktop\"; ValueType: string; ValueName: "First Run"; ValueData: "True"
Root: "HKCU"; Subkey: "Software\SMR Computer Services\Outlook On The Desktop\"; ValueType: string; ValueName: "FirstRun"; ValueData: "True"
Root: "HKCU"; Subkey: "Software\SMR Computer Services\Outlook On The Desktop\AutoUpdate"; Flags: createvalueifdoesntexist uninsdeletekey

[Dirs]
Expand Down Expand Up @@ -160,4 +160,4 @@ Name: {app}; Type: dirifempty

[InstallDelete]
Name: C:\{app}\*; Type: filesandordirs
Name: C:\{app}; Type: dirifempty
Name: C:\{app}; Type: dirifempty