2019-08-21 06:37:50 +08:00
|
|
|
using System;
|
2014-01-05 17:56:02 +08:00
|
|
|
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;
|
2016-04-26 05:09:39 +08:00
|
|
|
using Wox.Infrastructure;
|
2016-04-26 09:40:23 +08:00
|
|
|
using Wox.Infrastructure.Image;
|
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();
|
2016-01-07 05:34:42 +08:00
|
|
|
private bool closing;
|
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);
|
2016-08-01 21:12:53 +08:00
|
|
|
var dipWorkingArea = WindowsInteropHelper.TransformPixelsToDIP(this,
|
2015-12-13 11:50:23 +08:00
|
|
|
screen.WorkingArea.Width,
|
2016-01-06 14:31:17 +08:00
|
|
|
screen.WorkingArea.Height);
|
2016-01-07 05:34:42 +08:00
|
|
|
Left = dipWorkingArea.X - Width;
|
2016-01-06 14:31:17 +08:00
|
|
|
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
|
2016-01-07 05:34:42 +08:00
|
|
|
fadeOutStoryboard.Completed += fadeOutStoryboard_Completed;
|
2019-08-21 06:37:50 +08:00
|
|
|
DoubleAnimation fadeOutAnimation = new DoubleAnimation(dipWorkingArea.Y - Height, dipWorkingArea.Y, new Duration(TimeSpan.FromSeconds(5)))
|
2016-01-06 14:31:17 +08:00
|
|
|
{
|
|
|
|
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-05-19 02:38:43 +08:00
|
|
|
imgClose.Source = ImageLoader.Load(Path.Combine(Infrastructure.Constant.ProgramDirectory, "Images\\close.png"));
|
2016-01-06 14:31:17 +08:00
|
|
|
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-04-26 05:09:39 +08:00
|
|
|
public void Show(string title, string subTitle, string iconPath)
|
2016-01-06 14:31:17 +08:00
|
|
|
{
|
|
|
|
tbTitle.Text = title;
|
|
|
|
tbSubTitle.Text = subTitle;
|
|
|
|
if (string.IsNullOrEmpty(subTitle))
|
|
|
|
{
|
|
|
|
tbSubTitle.Visibility = Visibility.Collapsed;
|
|
|
|
}
|
2016-04-26 05:09:39 +08:00
|
|
|
if (!File.Exists(iconPath))
|
2016-01-06 14:31:17 +08:00
|
|
|
{
|
2016-05-19 02:38:43 +08:00
|
|
|
imgIco.Source = ImageLoader.Load(Path.Combine(Infrastructure.Constant.ProgramDirectory, "Images\\app.png"));
|
2016-01-06 14:31:17 +08:00
|
|
|
}
|
|
|
|
else {
|
2016-04-26 09:40:23 +08:00
|
|
|
imgIco.Source = ImageLoader.Load(iconPath);
|
2016-01-06 14:31:17 +08:00
|
|
|
}
|
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
|
|
|
}
|