Skip to content

Commit

Permalink
Added fade effect to the color legend
Browse files Browse the repository at this point in the history
  • Loading branch information
Klocman committed May 2, 2017
1 parent dbbbe2a commit b006e0a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.

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

43 changes: 26 additions & 17 deletions source/BulkCrapUninstaller/Forms/ListLegendWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ namespace BulkCrapUninstaller.Forms
{
public partial class ListLegendWindow : Form
{
private const double OpacityChangeAmount = .12;

public ListLegendWindow()
{
InitializeComponent();
Expand All @@ -22,7 +24,7 @@ public ListLegendWindow()
Visible = false;
Owner.Focus();
};

foreach (var control in this.GetAllChildren())
{
control.MouseLeave += ControlOnMouseEvent;
Expand All @@ -41,39 +43,46 @@ public void UpdatePosition(Control owner)

private void ListLegendWindow_VisibleChanged(object sender, System.EventArgs e)
{
if(Opacity < .9)
opacityResetTimer.Enabled = true;
if (Opacity < .9)
opacityResetTimer.Start();
}

private void ListLegendWindow_EnabledChanged(object sender, System.EventArgs e)
{
if (Opacity < .9)
opacityResetTimer.Enabled = true;
opacityResetTimer.Start();
}

private void opacityResetTimer_Tick(object sender, EventArgs e)
{
if (!CheckMouseHover())
{
opacityResetTimer.Stop();
Opacity = 1;
}
}

private void ControlOnMouseEvent(object sender, EventArgs eventArgs)
{
if (CheckMouseHover())
{
Opacity = .3;
opacityResetTimer.Enabled = true;
if (Math.Abs(Opacity - .3) < .03)
opacityResetTimer.Stop();
else
Opacity = OpacityLerp(.3);
}
else
{
Opacity = 1;
opacityResetTimer.Enabled = false;
if (Math.Abs(Opacity - 1) < .03)
opacityResetTimer.Stop();
else
Opacity = OpacityLerp(1);
}
}

private double OpacityLerp(double target)
{
return Opacity > target
? Math.Max(target, Opacity - OpacityChangeAmount)
: Math.Min(target, Opacity + OpacityChangeAmount);
}

private void ControlOnMouseEvent(object sender, EventArgs eventArgs)
{
opacityResetTimer.Start();
}

private bool CheckMouseHover()
{
var pt = PointToClient(Cursor.Position);
Expand Down
1 change: 0 additions & 1 deletion source/BulkCrapUninstaller/Forms/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,6 @@ private void UsageTrackerSendData()
SetupAndShowLegendWindow();
// Needed in case main window starts maximized
_listLegendWindow.UpdatePosition(uninstallerObjectListView);
_listLegendWindow.Opacity = 1;
_listLegendWindow.Visible = _setMan.Selected.Settings.UninstallerListShowLegend;

new Thread(() =>
Expand Down

0 comments on commit b006e0a

Please sign in to comment.