Example #1
0
        private static void UpdateScreenBounds(FrameworkElement owner, OverlayWindowViewModel.ScreenCoordVM screenCoordVM)
        {
            if (mapTimers.TryGetValue(owner, out var existingTimer))
            {
                if (existingTimer.IsEnabled)
                {
                    existingTimer.Stop();
                }

                mapTimers.Remove(owner);
            }

            if (screenCoordVM != null)
            {
                var canvasOwner  = ViewUtils.FindVisualParent(owner, x => x is Canvas) as Canvas;
                var overlayOwner = ViewUtils.FindVisualParent(owner, x => x is OverlayWindowInteractive) as OverlayWindowInteractive;
                var localPos     = canvasOwner.PointFromScreen(new Point(screenCoordVM.ScreenCoords.X, screenCoordVM.ScreenCoords.Y));

                switch (screenCoordVM.DrawMode)
                {
                case OverlayWindowViewModel.ScreenCoordVM.Mode.CapturePanel:
                    // coord only, anchor: center + bottom (with margin)
                    if (overlayOwner != null)
                    {
                        overlayOwner.SetPanelCanvasPos(localPos.X - (owner.ActualWidth / 2), localPos.Y - owner.ActualHeight - 10);
                    }
                    else
                    {
                        Canvas.SetLeft(owner, localPos.X - (owner.ActualWidth / 2));
                        Canvas.SetTop(owner, localPos.Y - owner.ActualHeight - 10);
                    }
                    break;

                case OverlayWindowViewModel.ScreenCoordVM.Mode.AdjustedCapturePanel:
                    // coord only, anchor: center + top (with margin + coord.height)
                    if (overlayOwner != null)
                    {
                        overlayOwner.SetPanelCanvasPos(localPos.X + ((screenCoordVM.ScreenSize.Width - owner.ActualWidth) / 2), localPos.Y + screenCoordVM.ScreenSize.Height + 50);
                    }
                    else
                    {
                        Canvas.SetLeft(owner, localPos.X + ((screenCoordVM.ScreenSize.Width - owner.ActualWidth) / 2));
                        Canvas.SetTop(owner, localPos.Y + screenCoordVM.ScreenSize.Height + 50);
                    }
                    break;

                case OverlayWindowViewModel.ScreenCoordVM.Mode.SwapWarning:
                    // coord only, anchor: left + bottom (with margin)
                    Canvas.SetLeft(owner, localPos.X);
                    Canvas.SetTop(owner, localPos.Y - owner.ActualHeight - 10);
                    break;

                default:
                    Canvas.SetLeft(owner, localPos.X);
                    Canvas.SetTop(owner, localPos.Y);
                    owner.Width  = screenCoordVM.ScreenSize.Width;
                    owner.Height = screenCoordVM.ScreenSize.Height;
                    break;
                }

                owner.Visibility = Visibility.Visible;
                if (screenCoordVM.Duration > 0)
                {
                    var timer = new DispatcherTimer()
                    {
                        Interval = TimeSpan.FromSeconds(screenCoordVM.Duration)
                    };
                    timer.Tick += (s, e) =>
                    {
                        owner.Visibility = Visibility.Hidden;
                        mapTimers.Remove(owner);
                        ((DispatcherTimer)s).Stop();
                    };

                    timer.Start();
                    mapTimers.Add(owner, timer);
                }
            }
            else
            {
                owner.Visibility = Visibility.Hidden;
            }
        }
Example #2
0
 public static void SetScreenBounds(FrameworkElement owner, OverlayWindowViewModel.ScreenCoordVM value)
 {
     owner.SetValue(ScreenBoundsProperty, value);
 }