// --------------------------------------------------------------------------
        /// <summary>
        /// ctor
        /// </summary>
        // --------------------------------------------------------------------------
        public NotificationWidget(TimerInstance data, AppModel appModel, double location)
        {
            InitializeComponent();
            this._data       = data;
            this._appModel   = appModel;
            this.DataContext = data;
            LocationTheta    = location;
            data.OnDismiss  += () => this.Close();

            this.Loaded += (a, b) =>
            {
                _draggingLogic = new DraggingLogic(this, this);
                _draggingLogic.OnPositionChanged += (xm, ym) =>
                {
                    Center = new Point(Center.X + xm / _draggingLogic.DpiCorrectionX, Center.Y + ym / _draggingLogic.DpiCorrectionY);
                };
            };
        }
示例#2
0
        // --------------------------------------------------------------------------
        /// <summary>
        /// Notification handling - make a little animation to alert the user
        /// </summary>
        // --------------------------------------------------------------------------
        private void HandleNewNotification(TimerInstance data)
        {
            Dispatcher.InvokeAsync(() =>
            {
                double theta = rand.NextDouble() * Math.PI * 2;
                lock (_emptyNotificationLocations)
                {
                    if (_emptyNotificationLocations.Count > 0)
                    {
                        int pick = rand.Next(_emptyNotificationLocations.Count);
                        theta    = _emptyNotificationLocations[pick];
                        _emptyNotificationLocations.RemoveAt(pick);
                    }
                }
                var newWidget = new NotificationWidget(data, _theModel, theta);

                var screenArea   = ScreenHelper.MainScreen.WorkingArea;
                newWidget.Center = new Point(screenArea.Left + screenArea.Width / 2, screenArea.Top + screenArea.Height / 2);

                if (newWidget.Center.X == 0)
                {
                    newWidget.Center = new Point(1200, 800);
                }

                newWidget.Closing += (sender, args) =>
                {
                    lock (_notificationWindows)
                    {
                        _notificationWindows.Remove(newWidget);
                    }

                    lock (_emptyNotificationLocations)
                    {
                        _emptyNotificationLocations.Add(newWidget.LocationTheta);
                    }
                };
                newWidget.Show();
                lock (_notificationWindows)
                {
                    _notificationWindows.Add(newWidget);
                }
            });
        }