using System; using System.Diagnostics; using System.Windows; using System.Windows.Input; using System.Windows.Navigation; using System.Windows.Threading; namespace WarframeClock { /// /// Interaction logic for OverlayWindow.xaml /// public partial class OverlayWindow : OverlayWindowBase { private readonly OverlayWindowViewModel _vm; private readonly System.Windows.Forms.NotifyIcon _notifyIcon; private readonly DispatcherTimer _updateTimer; public OverlayWindow() { InitializeComponent(); DataContext = _vm = new OverlayWindowViewModel(); var iconMenu = new System.Windows.Forms.ContextMenu(); iconMenu.MenuItems.Add(new System.Windows.Forms.MenuItem(App.VersionString) { Enabled = false }); iconMenu.MenuItems.Add(new System.Windows.Forms.MenuItem("Configure", (_, __) => _vm.SettingsMode = true)); iconMenu.MenuItems.Add(new System.Windows.Forms.MenuItem("Quit", (_, __) => ((App)Application.Current).Terminate())); _notifyIcon = new System.Windows.Forms.NotifyIcon { ContextMenu = iconMenu, Icon = Properties.Resources.TrayIcon, Visible = true }; _updateTimer = new DispatcherTimer(TimeSpan.FromMilliseconds(100), DispatcherPriority.Background, UpdateTimerTick, Dispatcher.CurrentDispatcher); _updateTimer.Start(); } protected override void OnClosed(EventArgs e) { base.OnClosed(e); _notifyIcon.Dispose(); _updateTimer.Stop(); } private void UpdateTimerTick(object sender, EventArgs e) { _vm.RefreshOverlayText(); _notifyIcon.Text = $"Warframe Clock - {_vm.OverlayText}"; AdjustOverlay(); } private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e) { Process.Start(e.Uri.AbsoluteUri); } private void DoneSettingsButton_Click(object sender, RoutedEventArgs e) { Settings.Save(); _vm.SettingsMode = false; } private Point _dragOriginalPosition; private bool _dragStarted; private Point _dragOffset; private void OverlayLabelOverlay_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { _dragStarted = true; _dragOriginalPosition = OverlayLabelOverlay.TranslatePoint(new Point(0, 0), this); _dragOffset = e.GetPosition(this); ((UIElement)sender).CaptureMouse(); } private void OverlayLabelOverlay_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { if (_dragStarted) { ((UIElement)sender).ReleaseMouseCapture(); _dragStarted = false; } } private void OverlayLabelOverlay_MouseMove(object sender, MouseEventArgs e) { if (_dragStarted) { var p = e.GetPosition(this); var newX = _dragOriginalPosition.X + p.X - _dragOffset.X; if (newX <= ActualWidth / 2) { Settings.DockToX = Settings.AlignmentX.Left; Settings.MarginX = newX; } else { Settings.DockToX = Settings.AlignmentX.Right; Settings.MarginX = ActualWidth - newX - OverlayLabelOverlay.ActualWidth; } var newY = _dragOriginalPosition.Y + p.Y - _dragOffset.Y; if (newY <= ActualHeight / 2) { Settings.DockToY = Settings.AlignmentY.Top; Settings.MarginY = newY; } else { Settings.DockToY = Settings.AlignmentY.Bottom; Settings.MarginY = ActualHeight - newY - OverlayLabelOverlay.ActualHeight; } _vm.RefreshPosition(); } } private void FontSettingsButton_Click(object sender, RoutedEventArgs e) { var dialog = new System.Windows.Forms.FontDialog { Font = new System.Drawing.Font( new System.Drawing.FontFamily(Settings.FontFamilyName), (float) (Settings.FontSize * 72.0 / 96.0)) }; if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Settings.FontFamilyName = dialog.Font.FontFamily.Name; Settings.FontSize = dialog.Font.SizeInPoints / 72.0 * 96.0; _vm.RefreshFont(); } } } }