예제 #1
0
        public override bool Commit()
        {
            var deviceScreenId = _profileSettingsService.GetValue <string[]>(ProfileSettingsCategories.Viewports, SettingsKeys.DeviceViewportsDisplays).First();
            var screen         = Screen.AllScreens.First(s => s.DeviceName == deviceScreenId);

            foreach (var selected in ModuleViewports.Where(mv => mv.IsSelected.Value))
            {
                foreach (var viewport in selected.Viewports)
                {
                    _profileSettingsService.UpsertViewport(selected.Name.Value, selected.Module.Value.ModuleId, screen, viewport);
                }
            }

            return(base.Commit());
        }
예제 #2
0
        public override Task ActivateAsync()
        {
            var selectedDisplays = _profileSettingsService.GetValue(ProfileSettingsCategories.Viewports, SettingsKeys.GameDisplays, new string[0]);

            var screens     = Screen.AllScreens.ToArray();
            var boundingBox = Rect.Empty;

            foreach (var screen in screens)
            {
                var screenBounds = screen.Bounds;

                if (boundingBox == Rect.Empty)
                {
                    boundingBox = screenBounds;
                }
                else
                {
                    boundingBox.Union(screenBounds);
                }
            }

            var nonNegativeOffsetX = 0.0;
            var nonNegativeOffsetY = 0.0;

            if (boundingBox.X < 0)
            {
                nonNegativeOffsetX = Math.Abs(boundingBox.X);
            }

            if (boundingBox.Y < 0)
            {
                nonNegativeOffsetY = Math.Abs(boundingBox.Y);
            }

            var ratioX = 1920 / boundingBox.Width;
            var ratioY = 1080 / boundingBox.Height;
            var ratio  = ratioX < ratioY ? ratioX : ratioY;

            boundingBox = Rect.Empty;

            foreach (var screen in screens)
            {
                var deviceName   = screen.DeviceName;
                var screenBounds = screen.Bounds;
                var x            = (nonNegativeOffsetX + screenBounds.Left) * ratio;
                var y            = (nonNegativeOffsetY + screenBounds.Top) * ratio;
                var width        = screenBounds.Width * ratio;
                var height       = screenBounds.Height * ratio;

                if (boundingBox == Rect.Empty)
                {
                    boundingBox = new Rect(x, y, width, height);
                }
                else
                {
                    boundingBox.Union(new Rect(x, y, width, height));
                }

                var model = new ScreenModel
                {
                    Id             = deviceName,
                    DisplayName    = $"{deviceName.Replace("\\\\.\\DISPLAY", "Display ")} {screenBounds.Width}x{screenBounds.Height}",
                    RelativeX      = x,
                    RelativeY      = y,
                    RelativeWidth  = width,
                    RelativeHeight = height,
                    ImageSource    = ScreenCapture.Snapshot(screen),
                    ScreenBounds   = screenBounds
                };

                model.IsSelected.Value = selectedDisplays.Contains(deviceName);

                Screens.Add(model);
            }

            ViewportWidth.Value  = boundingBox.Width;
            ViewportHeight.Value = boundingBox.Height;

            return(base.InitializeAsync());
        }
 public string[] GetDeviceViewportMonitorIds()
 {
     return(_profileSettingsService.GetValue(ProfileSettingsCategories.Viewports, SettingsKeys.DeviceViewportsDisplays, new string[0]));
 }