Skip to content

Commit

Permalink
Merge pull request DynamoDS#863 from kah-heng/MouseOverInfoBubbleTime…
Browse files Browse the repository at this point in the history
…rFix_ChocoButterUI

This fixes a rather important and easy-to-reproduce crash when mouse moves away from out-ports, so I'm accepting this pull request in the interest of having it tested earlier.
  • Loading branch information
Benglin committed Nov 30, 2013
2 parents a571d18 + 4c5e20b commit 9a7a2ec
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 52 deletions.
1 change: 1 addition & 0 deletions src/DynamoCore/Core/Configurations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public class Configurations
#endregion

#region Node Tooltip
public static int ToolTipFadeInDelayInMS = 2000;

public static SolidColorBrush NodeTooltipFrameFill = new SolidColorBrush(Color.FromRgb(255, 255, 255));
public static double NodeTooltipFrameStrokeThickness = 1;
Expand Down
99 changes: 49 additions & 50 deletions src/DynamoCore/UI/Views/dynNodeView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using System.Windows.Media;
using DynCmd = Dynamo.ViewModels.DynamoViewModel;
using System.Windows.Threading;
using Dynamo.Core;

namespace Dynamo.Controls
{
Expand All @@ -42,7 +43,7 @@ public NodeViewModel ViewModel
private set { viewModel = value; }
}

private DispatcherTimer twoSecondsWaitTimer;
private DispatcherTimer toolTipDelayTimer;

#region constructors

Expand Down Expand Up @@ -295,32 +296,24 @@ private void NickNameBlock_OnMouseDown(object sender, MouseButtonEventArgs e)
private void NickNameBlock_OnMouseEnter(object sender, MouseEventArgs e)
{
TextBlock textBlock = sender as TextBlock;
string tooltipContent = ViewModel.Description;
UIElement containingWorkspace = WPF.FindUpVisualTree<TabControl>(this);
Point topLeft = textBlock.TranslatePoint(new Point(0, 0), containingWorkspace);
double actualWidth = textBlock.ActualWidth * dynSettings.Controller.DynamoViewModel.CurrentSpaceViewModel.Zoom;
double actualHeight = textBlock.ActualHeight * dynSettings.Controller.DynamoViewModel.CurrentSpaceViewModel.Zoom;
Point botRight = new Point(topLeft.X + actualWidth, topLeft.Y + actualHeight);

twoSecondsWaitTimer = new DispatcherTimer();
twoSecondsWaitTimer.Interval = TimeSpan.FromSeconds(2); // two seconds wait
InfoBubbleDataPacket data = new InfoBubbleDataPacket();
data.Style = InfoBubbleViewModel.Style.NodeTooltip;
data.TopLeft = textBlock.TranslatePoint(new Point(0, 0), containingWorkspace);
data.BotRight = new Point(data.TopLeft.X + actualWidth, data.TopLeft.Y + actualHeight);
data.Text = ViewModel.Description;
data.ConnectingDirection = InfoBubbleViewModel.Direction.Bottom;

twoSecondsWaitTimer.Tick += delegate(object sender1, EventArgs e1)
{
dynSettings.Controller.DynamoViewModel.CurrentSpaceViewModel.Dispatcher.BeginInvoke((new Action(() =>
{
ViewModel.ShowTooltipCommand.Execute(new InfoBubbleDataPacket(InfoBubbleViewModel.Style.NodeTooltip, topLeft,
botRight, tooltipContent, InfoBubbleViewModel.Direction.Bottom));
})));
};

twoSecondsWaitTimer.Start();
StartDelayedTooltipFadeIn(data);
}

private void NickNameBlock_OnMouseLeave(object sender, MouseEventArgs e)
{
if (twoSecondsWaitTimer.IsEnabled)
twoSecondsWaitTimer.Stop();
if (toolTipDelayTimer != null && toolTipDelayTimer.IsEnabled)
toolTipDelayTimer.Stop();

if (ViewModel != null)
ViewModel.FadeOutTooltipCommand.Execute(null);
Expand All @@ -336,30 +329,23 @@ private void InputPort_OnMouseEnter(object sender, MouseEventArgs e)
return;

UIElement containingWorkspace = WPF.FindUpVisualTree<TabControl>(this);
Point topLeft = inputPort.TranslatePoint(new Point(0, 0), containingWorkspace);
double actualWidth = inputPort.ActualWidth * dynSettings.Controller.DynamoViewModel.CurrentSpaceViewModel.Zoom;
double actualHeight = inputPort.ActualHeight * dynSettings.Controller.DynamoViewModel.CurrentSpaceViewModel.Zoom;
Point botRight = new Point(topLeft.X + actualWidth, topLeft.Y + actualHeight);

twoSecondsWaitTimer = new DispatcherTimer();
twoSecondsWaitTimer.Interval = TimeSpan.FromSeconds(2); // two seconds wait

twoSecondsWaitTimer.Tick += delegate(object sender1, EventArgs e1)
{
dynSettings.Controller.DynamoViewModel.CurrentSpaceViewModel.Dispatcher.BeginInvoke((new Action(() =>
{
ViewModel.ShowTooltipCommand.Execute(new InfoBubbleDataPacket(InfoBubbleViewModel.Style.NodeTooltip, topLeft,
botRight, content, InfoBubbleViewModel.Direction.Right));
})));
};
InfoBubbleDataPacket data = new InfoBubbleDataPacket();
data.Style = InfoBubbleViewModel.Style.NodeTooltip;
data.TopLeft = inputPort.TranslatePoint(new Point(0, 0), containingWorkspace);
data.BotRight = new Point(data.TopLeft.X + actualWidth, data.TopLeft.Y + actualHeight);
data.Text = content;
data.ConnectingDirection = InfoBubbleViewModel.Direction.Right;

twoSecondsWaitTimer.Start();
StartDelayedTooltipFadeIn(data);
}

private void InputPort_OnMouseLeave(object sender, MouseEventArgs e)
{
if (twoSecondsWaitTimer.IsEnabled)
twoSecondsWaitTimer.Stop();
if (toolTipDelayTimer != null && toolTipDelayTimer.IsEnabled)
toolTipDelayTimer.Stop();

if (ViewModel != null)
ViewModel.FadeOutTooltipCommand.Execute(null);
Expand All @@ -381,30 +367,23 @@ private void OutputPort_OnMouseEnter(object sender, MouseEventArgs e)
return;

UIElement containingWorkspace = WPF.FindUpVisualTree<TabControl>(this);
Point topLeft = outputPort.TranslatePoint(new Point(0, 0), containingWorkspace);
double actualWidth = outputPort.ActualWidth * dynSettings.Controller.DynamoViewModel.CurrentSpaceViewModel.Zoom;
double actualHeight = outputPort.ActualHeight * dynSettings.Controller.DynamoViewModel.CurrentSpaceViewModel.Zoom;
Point botRight = new Point(topLeft.X + actualWidth, topLeft.Y + actualHeight);

twoSecondsWaitTimer = new DispatcherTimer();
twoSecondsWaitTimer.Interval = TimeSpan.FromSeconds(2); // two seconds wait

twoSecondsWaitTimer.Tick += delegate(object sender1, EventArgs e1)
{
dynSettings.Controller.DynamoViewModel.CurrentSpaceViewModel.Dispatcher.BeginInvoke((new Action(() =>
{
ViewModel.ShowTooltipCommand.Execute(new InfoBubbleDataPacket(InfoBubbleViewModel.Style.NodeTooltip, topLeft,
botRight, content, InfoBubbleViewModel.Direction.Left));
})));
};
InfoBubbleDataPacket data = new InfoBubbleDataPacket();
data.Style = InfoBubbleViewModel.Style.NodeTooltip;
data.TopLeft = outputPort.TranslatePoint(new Point(0, 0), containingWorkspace);
data.BotRight = new Point(data.TopLeft.X + actualWidth, data.TopLeft.Y + actualHeight);
data.Text = content;
data.ConnectingDirection = InfoBubbleViewModel.Direction.Left;

twoSecondsWaitTimer.Start();
StartDelayedTooltipFadeIn(data);
}

private void OutputPort_OnMouseLeave(object sender, MouseEventArgs e)
{
if (twoSecondsWaitTimer.IsEnabled)
twoSecondsWaitTimer.Stop();
if (toolTipDelayTimer != null && toolTipDelayTimer.IsEnabled)
toolTipDelayTimer.Stop();

if (ViewModel != null)
ViewModel.FadeOutTooltipCommand.Execute(null);
Expand All @@ -424,5 +403,25 @@ private void PreviewArrow_MouseEnter(object sender, MouseEventArgs e)
if (uiElement.Visibility == System.Windows.Visibility.Visible)
ViewModel.ShowPreviewCommand.Execute(null);
}

private void StartDelayedTooltipFadeIn(InfoBubbleDataPacket data)
{
if (toolTipDelayTimer == null)
{
toolTipDelayTimer = new DispatcherTimer();
toolTipDelayTimer.Interval = TimeSpan.FromMilliseconds(Configurations.ToolTipFadeInDelayInMS);

toolTipDelayTimer.Tick += delegate(object sender, EventArgs e)
{
var timer = sender as DispatcherTimer;
timer.Stop(); // stop timer after one tick
ViewModel.ShowTooltipCommand.Execute((InfoBubbleDataPacket)timer.Tag);
};
}

toolTipDelayTimer.Stop();
toolTipDelayTimer.Tag = data;
toolTipDelayTimer.Start();
}
}
}
4 changes: 2 additions & 2 deletions src/DynamoCore/ViewModels/InfoBubbleViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ public partial class InfoBubbleViewModel : ViewModelBase
{
public enum Style
{
None,
LibraryItemPreview,
NodeTooltip,
Error,
ErrorCondensed,
Preview,
PreviewCondensed,
None
PreviewCondensed
}
public enum Direction
{
Expand Down

0 comments on commit 9a7a2ec

Please sign in to comment.