AllScreens() public static method

public static AllScreens ( ) : IEnumerable
return IEnumerable
示例#1
0
        private void Init()
        {
            _screens = WpfScreen.AllScreens();
            //arrange displays by X
            _screens.Sort((s1, s2) => (int)(s1.DeviceBounds.Left - s2.DeviceBounds.Left));

            foreach (var scr in _screens)
            {
                Debug.WriteLine(scr);
            }

            _borders = new BorderBetweenDisplays[_screens.Count - 1];

            var bounds = WPF_Helper.VirtualScreenBounds();

            for (int i = 1; i < _screens.Count; i++)
            {
                _borders[i - 1] = new BorderBetweenDisplays()
                {
                    Index = i - 1,
                    DisplayToDisplay_X          = _screens[i - 1].DeviceBounds.Right,
                    FromDisplayToDisplay_Top    = Math.Max(_screens[i].DeviceBounds.Top, _screens[i - 1].DeviceBounds.Top),
                    FromDisplayToDisplay_Bottom = Math.Min(_screens[i].DeviceBounds.Bottom, _screens[i - 1].DeviceBounds.Bottom)
                };
            }
        }
示例#2
0
        public static List <DisplayInfo> GetDisplays()
        {
            List <DisplayInfo> list    = new List <DisplayInfo>();
            List <WpfScreen>   screens = WpfScreen.AllScreens();

            for (int i = 0; i < screens.Count; i++)
            {
                list.Add(new DisplayInfo(screens[i], i));
            }
            return(list);
        }
示例#3
0
        private IList <ShellWindow> CreateShellWindows()
        {
            var shellWindows = new List <ShellWindow>();
            var primary      = WpfScreen.Primary;

            var shellWindow1 = new ShellWindow();

            shellWindow1.WindowId = ShellConst.WindowId_Shell1;

            shellWindow1.Left       = primary.DeviceBounds.Left;
            shellWindow1.Top        = primary.DeviceBounds.Top;
            shellWindow1.Width      = primary.DeviceBounds.Width;
            shellWindow1.Height     = primary.DeviceBounds.Height;
            shellWindow1.Title      = primary.DeviceName;
            shellWindow1.Background = Brushes.YellowGreen;

            shellWindows.Add(shellWindow1);

            ShellWindow shellWindow2 = null;
            var         second       = WpfScreen.AllScreens().FirstOrDefault(x => !x.IsPrimary);

            if (second != null)
            {
                shellWindow2          = new ShellWindow();
                shellWindow2.WindowId = ShellConst.WindowId_Shell2;

                shellWindow2.Left       = second.DeviceBounds.Left;
                shellWindow2.Top        = second.DeviceBounds.Top;
                shellWindow2.Width      = second.DeviceBounds.Width;
                shellWindow2.Height     = second.DeviceBounds.Height;
                shellWindow2.Title      = second.DeviceName;
                shellWindow2.Background = Brushes.DarkGray;

                shellWindows.Add(shellWindow2);
            }


            var shellApi1 = new ShellApi(this, shellWindow1, shellWindows.ToArray());

            shellWindow1.BindShellApi(shellApi1);
            ShellApiContext.Current.ShellApi1 = shellApi1;

            if (shellWindow2 != null)
            {
                var shellApi2 = new ShellApi(this, shellWindow2, shellWindows.ToArray());
                shellWindow2.BindShellApi(shellApi2);
                ShellApiContext.Current.ShellApi2 = shellApi2;
            }

            return(shellWindows);
        }
        /// <summary>
        /// Massimizzo la finestra indicata sul monitor secondario
        /// </summary>
        internal void massimizzareFinestraSlideShowSulMonitor2()
        {
            // Adesso calcolo la posizione del monitor 2
            WpfScreen scrn = WpfScreen.AllScreens().Where(s => s.IsPrimary == false).FirstOrDefault();

            if (scrn != null)
            {
                // Per prima cosa apro la finestra se questa è chiusa
                aprireFinestraSlideShow();

                // Creo una geometria dalle dimensioni del monitor.
                GeometriaFinestra geo = creaGeometriaDaScreen(scrn);
                posizionaFinestra(_slideShowWindow, geo);

                massimizzareFinestraSlideShow();
            }
            else
            {
                _giornale.Warn("E' stato chiesto di usare il monitor secondario ma questo non è presente");
            }
        }
示例#5
0
        private void DrawScreens(double xOffset, double yOffset, double sizeRatio)
        {
            foreach (var screen in WpfScreen.AllScreens())
            {
                Border result = new Border();
                result.BorderThickness = new Thickness(1);

                // Set border's color to identify the ActivityUse
                Color color = Color.FromRgb(255, 255, 255);
                result.BorderBrush         = new SolidColorBrush(color);
                result.VerticalAlignment   = VerticalAlignment.Top;
                result.HorizontalAlignment = HorizontalAlignment.Left;

                result.Margin = new Thickness(
                    (xOffset + screen.DeviceBounds.Left) * sizeRatio,
                    (yOffset + screen.DeviceBounds.Top) * sizeRatio,
                    0, 0);
                result.Width  = screen.DeviceBounds.Width * sizeRatio;
                result.Height = screen.DeviceBounds.Height * sizeRatio;

                DrawArea.Children.Add(result);
            }
        }
        private void CreateDisplaysRectangles()
        {
            var displays = WpfScreen.AllScreens();

            displays.Sort((d1, d2) => (int)(d1.DeviceBounds.Left - d2.DeviceBounds.Left));

            _diplayRectangles.ForEach(disp => disp.Draggable(false));
            _diplayRectangles.Clear();

            var desktopBounds = WPF_Helper.VirtualScreenBounds();

            displays.ForEach((disp) =>
            {
                Border r          = new Border();
                r.Opacity         = 0.85;
                r.BorderBrush     = Brushes.DimGray;
                r.Background      = Brushes.AliceBlue;
                r.BorderThickness = new Thickness(3);
                r.CornerRadius    = new CornerRadius(3);
                r.Width           = disp.DeviceBounds.Width / 10.0;
                r.Height          = disp.DeviceBounds.Height / 10.0;

                Canvas.SetLeft(r, (disp.DeviceBounds.Left - desktopBounds.Left) / 10.0);
                Canvas.SetTop(r, (disp.DeviceBounds.Top - desktopBounds.Top) / 10.0);

                r.Draggable();
                r.LayoutUpdated += (s, e) => { Debug.WriteLine("R - moved"); };

                TextBlock txt     = new TextBlock();
                txt.FontSize      = 16;
                txt.TextAlignment = TextAlignment.Center;
                txt.Text          = string.Format("Display [{0}]\n\n{1}", disp.Index, disp.WorkingArea);
                r.Child           = txt;

                _diplayRectangles.Add(r);
            });
        }
        private void InitializeComponent(WindowStartupLocation startupLocation, Point location)
        {
            this.DataContext = this;

            InitializeComponent();

            this.WindowStartupLocation = startupLocation;

            this.Draggable(true);

            if (startupLocation == WindowStartupLocation.Manual)
            {
                int screenIdx = WpfScreen.ScreenIndexFromPoint(location.X, location.Y);
                if (screenIdx >= 0)
                {
                    this.Left = location.X;
                    this.Top  = location.Y;
                }
                else //show on first visible screen
                {
                    WpfScreen screen = WpfScreen.AllScreens()[0];
                    this.Left = screen.DeviceBounds.Left + 100;
                    this.Top  = screen.DeviceBounds.Top + 100;
                }
            }

            m_Timer.Interval = TimeSpan.FromMilliseconds(100);
            m_Timer.Tick    += Timer_Tick;

            m_Timer.Start();
            _timer_count = 0;

            _progress.ProgressTheme = GradientProgressBar.TicksTheme.GetBase100Theme();
            _progress.Maximum       = 100;
            _progress.TickColor     = Brushes.Navy;
        }
示例#8
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            if (e.Args.Length > 0 && e.Args[0] == "/update")
            {
                UpdateService.UpdateSettings(HurricaneSettings.Paths.BaseDirectory);
            }
            HurricaneSettings.Instance.Load();

            var openfile = false;

            if (e.Args.Length > 0)
            {
                switch (e.Args[0])
                {
                case "/test":
                    var view = new TestWindow();
                    view.Show();
                    break;

                case "/language_creator":
                    var languageCreator = new LanguageCreatorWindow();
                    languageCreator.ShowDialog();
                    return;

                case "/designer":
                    var resource = new ResourceDictionary {
                        Source = new Uri("/Resources/Themes/Cyan.xaml", UriKind.Relative)
                    };
                    ApplicationThemeManager.Instance.LoadResource("accentcolor", resource);
                    var designer = new Designer.DesignerWindow();
                    designer.ShowDialog();
                    return;

                case "/registry":
                    var manager = new RegistryManager();
                    var item    = manager.ContextMenuItems.First(x => x.Extension == Environment.GetCommandLineArgs()[2]);
                    try
                    {
                        if (item != null)
                        {
                            item.ToggleRegister(!item.IsRegistered, false);
                        }
                    }
                    catch (SecurityException)
                    {
                        MessageBox.Show("Something went extremly wrong. This application didn't got administrator rights so it can't register anything.");
                    }

                    Current.Shutdown();
                    return;

                case "/screeninfo":
                    var message = new StringBuilder();
                    var screens = WpfScreen.AllScreens().ToList();
                    message.AppendLine("Hurricane - Detected Screens");
                    message.AppendLine("-----------------------------------------------------------------------------------");
                    message.AppendFormat("Found screens: {0}", screens.Count);
                    message.AppendLine();
                    foreach (var wpfScreen in screens)
                    {
                        message.AppendFormat("Screen #{0} ({1})", screens.IndexOf(wpfScreen), wpfScreen.DeviceName);
                        message.AppendFormat("Size: Width {0}, Height {1}", wpfScreen.WorkingArea.Width, wpfScreen.WorkingArea.Height);
                        message.AppendFormat("Position: X {0}, Y {1}", wpfScreen.WorkingArea.X, wpfScreen.WorkingArea.Y);
                        message.AppendFormat("IsPrimary: {0}", wpfScreen.IsPrimary);
                        message.AppendLine();
                    }
                    message.AppendLine("-----------------------------------------------------------------------------------");
                    message.AppendLine();
                    message.AppendFormat("Most left x: {0}", WpfScreen.MostLeftX);
                    message.AppendFormat("Most right x: {0}", WpfScreen.MostRightX);
                    MessageBox.Show(message.ToString());
                    Current.Shutdown();
                    return;

                case "/showlines":
                    MagicArrow.StrokeWindow.ShowLines = true;
                    break;

                case "/positiontest":
                    PositionTestWindow positionTest = new PositionTestWindow();
                    positionTest.Show();
                    return;

                default:
                    openfile = true;
                    break;
                }
            }

            bool aIsNewInstance;

            _myMutex = new Mutex(true, "Hurricane", out aIsNewInstance);
            if (!aIsNewInstance)
            {
                IntPtr hwnd = UnsafeNativeMethods.FindWindow(null, "Hurricane");
                if (openfile)
                {
                    WindowMessanger.SendMessageToWindow(hwnd, WindowMessanger.WM_OPENMUSICFILE, new FileInfo(Environment.GetCommandLineArgs()[1]).FullName);
                }
                else
                {
                    WindowMessanger.SendMessageToWindow(hwnd, WindowMessanger.WM_BRINGTOFRONT, string.Empty);
                }
                Current.Shutdown();
                return;
            }
#if !DEBUG
            EnableExteptionless();
#endif
            //We remove the two last resource dictionarys so we can skip the annyoing ThemeManagers/current theme detections, ...
            //HurricaneSettings will load the needed resources
            Resources.MergedDictionaries.RemoveAt(Resources.MergedDictionaries.Count - 2);
            Resources.MergedDictionaries.RemoveAt(Resources.MergedDictionaries.Count - 2);
            ApplicationThemeManager.Instance.Apply(HurricaneSettings.Instance.Config.ApplicationDesign);

            MainWindow window = new MainWindow();

            WindowMessanger messanger = new WindowMessanger(window);
            window.Show();
            if (openfile)
            {
                try
                {
                    foreach (var path in Environment.GetCommandLineArgs().Skip(1))
                    {
                        FileInfo fi = new FileInfo(path);
                        if (fi.Exists)
                        {
                            MainViewModel.Instance.OpenFile(fi, Environment.GetCommandLineArgs().Skip(1).Last() == path);
                        }
                    }
                }
                catch (IOException) { }
            }

            messanger.BringWindowToFront += (s, ev) =>
            {
                window.BringToFront();
            };

            messanger.PlayMusicFile += (s, ev) =>
            {
                FileInfo fi = new FileInfo(ev.Filename);
                if (fi.Exists)
                {
                    MainViewModel.Instance.OpenFile(fi, true);
                }
            };
        }
        public async Task <bool> SetWaveStream(string fileName)
        {
            await Task.Yield();

            WaveStream   = null;
            WaveFormData = null;
            waveSize     = 0L;
            waveFormSize = 0;
            waveDuration = TimeSpan.Zero;
            UpdateVisuals();

            try
            {
                var waveStream = new WaveFileReader(fileName);
                if (waveStream.WaveFormat.Channels != 1 || waveStream.WaveFormat.SampleRate != 16000)
                {
                    throw new FileFormatException("Input should be 16kHz Mono WAV file.");
                }
                var wave = new WaveChannel32(waveStream);

                if (wave == null)
                {
                    return(false);
                }

                waveStream.Position = 0L;
                waveDuration        = waveStream.TotalTime;

                int sampleSize = 0;

                sampleSize = (from i in Utils.Range(1, 512)
                              let align = wave.WaveFormat.BlockAlign * (double)i
                                          let v = wave.Length / align
                                                  where v == (int)v
                                                  select(int) align).Max();

                var bufferSize = (int)(wave.Length / (double)sampleSize);
                int read       = 0;

                //this.waveSize = waveStream.Length;
                waveSize = waveStream.Length;

                ScrollOffset   = 0.0;
                MaxZoom        = Math.Max(wave.TotalTime.TotalSeconds / 4, MinZoom);
                Zoom           = MinZoom;
                SelectionStart = 0;
                SelectionEnd   = 0;

                var maxWidth = Math.Min(WpfScreen.AllScreens().OrderByDescending(s => s.WorkingArea.Width).First().WorkingArea.Width *MaxZoom, waveSize);

                var iter         = 0;
                var waveFormData = new float[(int)(maxWidth * 2)];

                await Task.Run(() =>
                {
                    while (wave.Position < wave.Length)
                    {
                        var rwaIndex     = 0;
                        var rawWaveArray = new float[bufferSize / 4];

                        var buffer = new byte[bufferSize];
                        read       = wave.Read(buffer, 0, bufferSize);

                        for (int i = 0; i < read / 4; i++)
                        {
                            var point = BitConverter.ToSingle(buffer, i * 4);
                            rawWaveArray[rwaIndex++] = point;
                        }
                        buffer = null;

                        var wl       = rawWaveArray.ToList();
                        var rwaCount = rawWaveArray.Length;

                        var samplesPerPixel = (rwaCount / (maxWidth / sampleSize));

                        var writeOffset = (int)((maxWidth / sampleSize) * iter);
                        for (int i = 0; i < (int)(maxWidth / sampleSize); i++)
                        {
                            var offset         = (int)(samplesPerPixel *i);
                            var drawableSample = wl.GetRange(offset, Math.Min((int)samplesPerPixel, read)).ToArray();
                            waveFormData[(i + writeOffset) * 2]       = drawableSample.Max();
                            waveFormData[((i + writeOffset) * 2) + 1] = drawableSample.Min();
                            drawableSample = null;
                        }

                        wl.Clear();
                        wl = null;
                        iter++;
                    }
                });

                maxSpan = waveFormData.Max() - waveFormData.Min();
                Player.Init(waveStream);
                waveStream.Position = 0L;
                WaveStream          = waveStream;
                WaveFormData        = waveFormData.ToList();
                waveFormSize        = waveFormData.Length;
                PlayRangeEnd        = WaveStream.TotalTime;
            }
            catch (TaskCanceledException) { }
            catch (Exception ex)
            {
                WaveStream   = null;
                WaveFormData = null;
                waveSize     = 0L;
                waveFormSize = 0;
                waveDuration = TimeSpan.Zero;
                Logger.Log($"{ex.Message}:\n{ex.StackTrace}", Logger.Type.Error);
                MessageBox.Show(ex.Message, "Program Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            GC.Collect();

            drawWave = true;
            Render();

            var success = (WaveStream != null);

            btnPlayPause.IsEnabled = success;

            return(success);
        }
 void caricaSchermi()
 {
     schermiCV = CollectionViewSource.GetDefaultView(WpfScreen.AllScreens());
     OnPropertyChanged("schermiCV");
 }