Skip to content

Commit

Permalink
Transparency Slider in Context Menu (with typo fix) (#234)
Browse files Browse the repository at this point in the history
* Update Setup Script.iss

Fixed Typo in FirstRun regkey

* Added transparency slider to context menu until MainForm bug is resolved.

* Update Setup Script.iss

Fixed Typo in FirstRun regkey

(cherry picked from commit 1009c12)

* Change to MACTrackBar

* Fixed references to Core in x84 and x86

* Remove scripts

* Some cleanup

(cherry picked from commit 5d5dd49)

* Use resources for string

Had to fix resources generation with new Visual Studio

(cherry picked from commit 41f7ccd)

* Some more refactoring

(cherry picked from commit f794921)

* Delete backup file

(cherry picked from commit bddfb9b)

* Fix build

---------

Co-authored-by: Michael Scrivo <mscrivo@gmail.com>
  • Loading branch information
dbzfanatic and mscrivo committed Feb 3, 2024
1 parent d06e6f2 commit 4e928b0
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 12 deletions.
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

0 comments on commit 4e928b0

Please sign in to comment.