2014-01-05 17:56:02 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using System.Windows.Media.Animation;
|
|
|
|
|
using System.Windows.Media.Imaging;
|
2015-12-13 11:50:23 +08:00
|
|
|
|
using Wox.Helper;
|
2014-01-05 17:56:02 +08:00
|
|
|
|
|
2016-01-06 14:31:17 +08:00
|
|
|
|
namespace Wox
|
|
|
|
|
{
|
|
|
|
|
public partial class Msg : Window
|
|
|
|
|
{
|
|
|
|
|
Storyboard fadeOutStoryboard = new Storyboard();
|
|
|
|
|
private bool closing = false;
|
2014-01-05 17:56:02 +08:00
|
|
|
|
|
2016-01-06 14:31:17 +08:00
|
|
|
|
public Msg()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
|
|
|
|
|
var dipWorkingArea = WindowIntelopHelper.TransformPixelsToDIP(this,
|
2015-12-13 11:50:23 +08:00
|
|
|
|
screen.WorkingArea.Width,
|
2016-01-06 14:31:17 +08:00
|
|
|
|
screen.WorkingArea.Height);
|
|
|
|
|
Left = dipWorkingArea.X - this.Width;
|
|
|
|
|
Top = dipWorkingArea.Y;
|
|
|
|
|
showAnimation.From = dipWorkingArea.Y;
|
|
|
|
|
showAnimation.To = dipWorkingArea.Y - Height;
|
2014-01-05 17:56:02 +08:00
|
|
|
|
|
2016-01-06 14:31:17 +08:00
|
|
|
|
// Create the fade out storyboard
|
|
|
|
|
fadeOutStoryboard.Completed += new EventHandler(fadeOutStoryboard_Completed);
|
|
|
|
|
DoubleAnimation fadeOutAnimation = new DoubleAnimation(dipWorkingArea.Y - Height, dipWorkingArea.Y, new Duration(TimeSpan.FromSeconds(0.3)))
|
|
|
|
|
{
|
|
|
|
|
AccelerationRatio = 0.2
|
|
|
|
|
};
|
|
|
|
|
Storyboard.SetTarget(fadeOutAnimation, this);
|
|
|
|
|
Storyboard.SetTargetProperty(fadeOutAnimation, new PropertyPath(TopProperty));
|
|
|
|
|
fadeOutStoryboard.Children.Add(fadeOutAnimation);
|
2014-01-05 17:56:02 +08:00
|
|
|
|
|
|
|
|
|
|
2016-01-06 14:31:17 +08:00
|
|
|
|
imgClose.Source = new BitmapImage(new Uri("Images\\close.pn", UriKind.Relative));
|
|
|
|
|
//imgClose.Source = new BitmapImage(new Uri(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "Images\\close.png")));
|
|
|
|
|
imgClose.MouseUp += imgClose_MouseUp;
|
|
|
|
|
}
|
2014-01-05 17:56:02 +08:00
|
|
|
|
|
2016-01-06 14:31:17 +08:00
|
|
|
|
void imgClose_MouseUp(object sender, MouseButtonEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!closing)
|
|
|
|
|
{
|
|
|
|
|
closing = true;
|
|
|
|
|
fadeOutStoryboard.Begin();
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-05 17:56:02 +08:00
|
|
|
|
|
2016-01-06 14:31:17 +08:00
|
|
|
|
private void fadeOutStoryboard_Completed(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Close();
|
|
|
|
|
}
|
2014-01-08 19:08:48 +08:00
|
|
|
|
|
2016-01-06 14:31:17 +08:00
|
|
|
|
public void Show(string title, string subTitle, string icopath)
|
|
|
|
|
{
|
|
|
|
|
tbTitle.Text = title;
|
|
|
|
|
tbSubTitle.Text = subTitle;
|
|
|
|
|
if (string.IsNullOrEmpty(subTitle))
|
|
|
|
|
{
|
|
|
|
|
tbSubTitle.Visibility = Visibility.Collapsed;
|
|
|
|
|
}
|
|
|
|
|
if (!File.Exists(icopath))
|
|
|
|
|
{
|
|
|
|
|
imgIco.Source = new BitmapImage(new Uri("Images\\app.png", UriKind.Relative));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
imgIco.Source = new BitmapImage(new Uri(icopath));
|
|
|
|
|
}
|
2014-05-09 06:58:38 +08:00
|
|
|
|
|
2016-01-06 14:31:17 +08:00
|
|
|
|
Show();
|
2014-05-09 06:58:38 +08:00
|
|
|
|
|
2016-01-06 14:31:17 +08:00
|
|
|
|
Dispatcher.InvokeAsync(async () =>
|
|
|
|
|
{
|
|
|
|
|
if (!closing)
|
|
|
|
|
{
|
|
|
|
|
closing = true;
|
|
|
|
|
await Dispatcher.InvokeAsync(fadeOutStoryboard.Begin);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-05 17:56:02 +08:00
|
|
|
|
}
|