コード例 #1
0
ファイル: ScreenMirror.cs プロジェクト: winleafs/Winleafs
        public ScreenMirror(Orchestrator orchestrator, INanoleafClient nanoleafClient, ScaleType scaleType, FlipType flipType)
        {
            _externalControlEndpoint = nanoleafClient.ExternalControlEndpoint;
            _panelAreas = new List <Rectangle>();
            _panelIds   = new List <int>();
            _deviceType = orchestrator.PanelLayout.DeviceType;

            var screenBounds = ScreenBoundsHelper.GetScreenBounds(UserSettings.Settings.ScreenMirrorMonitorIndex);
            var panels       = orchestrator.PanelLayout.GetScaledPolygons(screenBounds.Width, screenBounds.Height, scaleType, flipType);

            switch (_deviceType)
            {
            case DeviceType.Aurora:
                LoadPanelsForTriangles(panels);
                break;

            case DeviceType.Canvas:
                LoadPanelsForSquares(panels);
                break;

            case DeviceType.Shapes:
                LoadPanelsForShapes(panels);
                break;

            default:
                throw new NotImplementedException($"Screen mirror constructor for device of type {orchestrator.PanelLayout.DeviceType} not implemented");
            }
        }
コード例 #2
0
ファイル: Ambilght.cs プロジェクト: wwh95128870/Winleafs
 public Ambilght(INanoleafClient nanoleafClient, Device device)
 {
     _nanoleafClient = nanoleafClient;
     _screenBounds   = new List <Rectangle> {
         ScreenBoundsHelper.GetScreenBounds(UserSettings.Settings.ScreenMirrorMonitorIndex)
     };
 }
コード例 #3
0
        public OptionsWindow(MainWindow mainWindow)
        {
            _mainWindow = mainWindow;

            InitializeComponent();

            //Initialize the viewmodel
            _monitorNames = ScreenBoundsHelper.GetMonitorNames();

            OptionsViewModel = new OptionsViewModel(this)
            {
                ScreenMirrorAlgorithmPerDevice   = UserSettings.Settings.Devices.ToDictionary(d => d.Name, d => d.ScreenMirrorAlgorithm),
                ScreenMirrorFlipPerDevice        = UserSettings.Settings.Devices.ToDictionary(d => d.Name, d => d.ScreenMirrorFlip),
                ScreenMirrorRefreshRatePerSecond = UserSettings.Settings.ScreenMirrorRefreshRatePerSecond,
                SelectedMonitor       = _monitorNames.ElementAt(UserSettings.Settings.ScreenMirrorMonitorIndex),
                DeviceNames           = new ObservableCollection <string>(UserSettings.Settings.Devices.Select(d => d.Name)),
                MonitorNames          = _monitorNames,
                StartAtWindowsStartUp = UserSettings.Settings.StartAtWindowsStartup,
                Latitude                 = UserSettings.Settings.Latitude?.ToString("N7", CultureInfo.InvariantCulture),
                Longitude                = UserSettings.Settings.Longitude?.ToString("N7", CultureInfo.InvariantCulture),
                SelectedLanguage         = FullNameForCulture(UserSettings.Settings.UserLocale),
                Languages                = _languageDictionary.Keys.ToList(),
                MinimizeToSystemTray     = UserSettings.Settings.MinimizeToSystemTray,
                CustomColorEffects       = UserSettings.Settings.CustomEffects == null ? new List <UserCustomColorEffect>() : UserSettings.Settings.CustomEffects.ToList(),
                WinleafsServerURL        = UserSettings.Settings.WinleafServerURL,
                ProcessResetIntervalText = UserSettings.Settings.ProcessResetIntervalInSeconds.ToString()
            };

            foreach (var customEffects in OptionsViewModel.CustomColorEffects)
            {
                ColorList.Children.Add(new ColorUserControl(this, customEffects.EffectName, customEffects.Color));
            }

            OptionsViewModel.SelectedDevice = UserSettings.Settings.ActiveDevice.Name; //Set this one last since it triggers changes in properties

            //Initialize variables
            _startupKey        = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryRights.FullControl);
            _visualizationOpen = false;

            foreach (var device in UserSettings.Settings.Devices)
            {
                DeviceList.Children.Add(new DeviceUserControl(device.Name, this));
            }

            //Draw monitors
            DrawMonitors();

            //Check Spotify connection
            _winleafsServerClient = new WinleafsServerClient();
            InitializeSpotifyButtons();

            //last: set datacontext
            DataContext = OptionsViewModel;
        }
コード例 #4
0
ファイル: Ambilght.cs プロジェクト: winleafs/Winleafs
        private readonly List <Rectangle> _captureArea; //A list since that is what the screengrabber expects as input

        public Ambilght(INanoleafClient nanoleafClient)
        {
            _nanoleafClient = nanoleafClient;

            var screenBounds = ScreenBoundsHelper.GetScreenBounds(UserSettings.Settings.ScreenMirrorMonitorIndex);

            _captureArea = new List <Rectangle>
            {
                //Which area of the screenshot we need to look at, in the case of Ambilight, we need to look at the whole screenshot.
                //So start at 0, 0 and then use the width and height of the screen being captured
                new Rectangle(0, 0, screenBounds.Width, screenBounds.Height)
            };
        }
コード例 #5
0
        public ScreenMirrorVisualizationWindow(Device device, int monitorIndex, ScreenMirrorAlgorithm screenMirrorAlgorithm)
        {
            _screenMirrorAlgorithm = screenMirrorAlgorithm;
            _device       = device;
            _screenBounds = ScreenBoundsHelper.GetScreenBounds(monitorIndex);


            Width  = _screenBounds.Width;
            Height = _screenBounds.Height;

            Left = _screenBounds.X;
            Top  = _screenBounds.Y;

            InitializeComponent();
        }
コード例 #6
0
ファイル: ScreenMirror.cs プロジェクト: ZenonBuratta/Winleafs
        private readonly Rectangle _capturedBounds; //Simple rectangle that start at 0,0 and has width and height set to the rectangle size

        public ScreenMirror(Device device, Orchestrator orchestrator, INanoleafClient nanoleafClient, ScaleType scaleType)
        {
            _nanoleafClient = nanoleafClient;

            _externalControlEndpoint = _nanoleafClient.ExternalControlEndpoint;

            _screenBounds = ScreenBoundsHelper.GetScreenBounds(device.ScreenMirrorMonitorIndex);

            _panels = orchestrator.PanelLayout.GetScaledTriangles(_screenBounds.Width, _screenBounds.Height, scaleType);

            //Set the rectangle size to 1/3th of the length of a side of the triangle. TODO: test what size is best
            var triangle = _panels.FirstOrDefault().Polygon;

            _rectangleSize  = (int)Math.Floor(System.Windows.Point.Subtract(triangle.Points[0], triangle.Points[1]).Length / 3);
            _capturedBounds = new Rectangle(0, 0, _rectangleSize, _rectangleSize);
        }
コード例 #7
0
ファイル: Ambilght.cs プロジェクト: ZenonBuratta/Winleafs
 public Ambilght(INanoleafClient nanoleafClient, Device device)
 {
     _nanoleafClient    = nanoleafClient;
     _controlBrightness = device.ScreenMirrorControlBrightness;
     _screenBounds      = ScreenBoundsHelper.GetScreenBounds(device.ScreenMirrorMonitorIndex);
 }
コード例 #8
0
        private void DrawMonitors()
        {
            var monitorBounds = new List <System.Drawing.Rectangle>();

            for (var i = 0; i < _monitorNames.Count; i++)
            {
                monitorBounds.Add(ScreenBoundsHelper.GetScreenBounds(i));
            }

            var minX = monitorBounds.Min(bounds => bounds.X);
            var minY = monitorBounds.Min(bounds => bounds.Y);

            //Normalize all X and Y coordinates such that the left most bottom monitor start at 0,0
            for (var i = 0; i < monitorBounds.Count; i++)
            {
                var rectangle = monitorBounds[i];

                var x = rectangle.X;
                if (minX > 0)
                {
                    x = rectangle.X - minX;
                }
                else if (minX < 0)
                {
                    x = rectangle.X + Math.Abs(minX);
                }

                var y = rectangle.Y;
                if (minY > 0)
                {
                    y = rectangle.Y - minY;
                }
                else if (minY < 0)
                {
                    y = rectangle.Y + Math.Abs(minY);
                }

                monitorBounds[i] = new System.Drawing.Rectangle(x, y, rectangle.Width, rectangle.Height);
            }

            var maxMonitorWidth  = monitorBounds.Max(bounds => bounds.X + bounds.Width);
            var maxMonitorHeight = monitorBounds.Max(bounds => bounds.Y + bounds.Height);

            var scale = Math.Max(maxMonitorWidth / MonitorCanvas.Width, maxMonitorHeight / MonitorCanvas.Height);

            for (var i = 0; i < monitorBounds.Count; i++)
            {
                //Draw a polygon in the shape of the monitor, scaled down
                var polygon = new Polygon();

                var scaledX       = monitorBounds[i].X / scale;
                var scaledY       = monitorBounds[i].Y / scale;
                var scaledXWidth  = (monitorBounds[i].X + monitorBounds[i].Width) / scale;
                var scaledYHeight = (monitorBounds[i].Y + monitorBounds[i].Height) / scale;

                polygon.Points.Add(new System.Windows.Point(scaledX, scaledY));            //Left top
                polygon.Points.Add(new System.Windows.Point(scaledX, scaledYHeight));      //Left bottom
                polygon.Points.Add(new System.Windows.Point(scaledXWidth, scaledYHeight)); //Right bottom
                polygon.Points.Add(new System.Windows.Point(scaledXWidth, scaledY));       //Right top

                polygon.Stroke          = Brushes.LightGray;
                polygon.StrokeThickness = 3;

                MonitorCanvas.Children.Add(polygon);

                //Draw the number of the monitor
                var textBlock = new TextBlock();

                textBlock.Text       = (i + 1).ToString(); //+ 1 since i starts at 0
                textBlock.Foreground = Brushes.LightGray;
                textBlock.FontSize   = 20;

                Canvas.SetLeft(textBlock, ((monitorBounds[i].X + (monitorBounds[i].Width / 2)) / scale) - 5); //-5 and -15 to position the numbers more to the center
                Canvas.SetTop(textBlock, ((monitorBounds[i].Y + (monitorBounds[i].Height / 2)) / scale) - 15);

                MonitorCanvas.Children.Add(textBlock);
            }
        }