Ejemplo n.º 1
0
        public MainWindow()
        {
            InitializeComponent();
            Closing += OnWindowClosing;

            var title   = (AssemblyTitleAttribute)Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false).FirstOrDefault();
            var version = (AssemblyInformationalVersionAttribute)Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false).FirstOrDefault();

            Title = $"{title?.Title} v{version?.InformationalVersion}";


            // define renderers
            var renderers = new List <IDestination> {
                VirtualDmd
            };

            Console.AppendText("Added VirtualDMD renderer.\n");

            try {
                var pinDmd = PinDmd3.GetInstance();
                if (pinDmd.IsAvailable)
                {
                    renderers.Add(pinDmd);
                    Console.AppendText($"Added PinDMDv3 renderer.\n");
                    Console.AppendText($"PinDMDv3 detected at {pinDmd.DmdWidth}x{pinDmd.DmdHeight}\n");
                    Console.AppendText($"Firmware: {pinDmd.Firmware}\n");
                }
                else
                {
                    Console.AppendText("PinDMDv3 not connected.\n");
                }
                var pin2Dmd = Pin2Dmd.GetInstance();
                if (pin2Dmd.IsAvailable)
                {
                    renderers.Add(pin2Dmd);
                    Console.AppendText($"Added PIN2DMD renderer.\n");
                }
                else
                {
                    Console.AppendText("PIN2DMD not connected.\n");
                }
                var pinDmd2 = PinDmd2.GetInstance();
                if (pinDmd2.IsAvailable)
                {
                    renderers.Add(pinDmd2);
                    Console.AppendText($"Added PinDMDv2 renderer.\n");
                }
                else
                {
                    Console.AppendText("PinDMDv2 not connected.\n");
                }
                var pinDmd1 = PinDmd1.GetInstance();
                if (pinDmd1.IsAvailable)
                {
                    renderers.Add(pinDmd1);
                    Console.AppendText($"Added PinDMDv1 renderer.\n");
                }
                else
                {
                    Console.AppendText("PinDMDv1 not connected.\n");
                }
            } catch (DllNotFoundException e) {
                Console.AppendText("A DLL was not found. It's possible that Windows blocked it.\n");
                Console.AppendText("Go look for it in the installation folder. If it's there, right-click, \"Properties\" and \"unblock\".\n");
                Console.AppendText("Then restart the app.\n");
                Console.AppendText("Message: " + e.Message + "\n");
            }

            // define sources
            var grabber = new ScreenGrabber {
                FramesPerSecond = 15
            };

            _pbfxGrabber = new PBFX2Grabber {
                FramesPerSecond = 25
            };
            _tpaGrabber = new TPAGrabber {
                FramesPerSecond = 15
            };

            // define processors
            _pbfxGridProcessor = new GridProcessor {
                Enabled = true, Spacing = 1
            };
            _tpaGridProcessor = new GridProcessor {
                Enabled = true, Spacing = 0, CropRight = 0, CropBottom = 1
            };

            // chain them up
            _screenGraph = new RenderGraph {
                Source       = grabber,
                Destinations = renderers,
                //Processors = new List<AbstractProcessor> { transformationProcessor, monochromeProcessor }
            };
            _pbfxGraph = new RenderGraph {
                Source       = _pbfxGrabber,
                Destinations = renderers,
                //Processors = new List<AbstractProcessor> { _pbfxGridProcessor, transformationProcessor, _pbfxShadeProcessor }
            };
            _tpaGraph = new RenderGraph {
                Source       = _tpaGrabber,
                Destinations = renderers,
                //Processors = new List<AbstractProcessor> { transformationProcessor, _tpaShadeProcessor }
            };

            // init grabber window and link it to grabber
            _grabberWindow = new GrabberWindow()
            {
                Left   = Properties.Settings.Default.GrabLeft,
                Top    = Properties.Settings.Default.GrabTop,
                Width  = Properties.Settings.Default.GrabWidth,
                Height = Properties.Settings.Default.GrabHeight,
            };
            _grabberWindow.WhenPositionChanges.Subscribe(rect => {
                grabber.Move(rect);
                Properties.Settings.Default.GrabLeft   = rect.X;
                Properties.Settings.Default.GrabTop    = rect.Y;
                Properties.Settings.Default.GrabWidth  = rect.Width;
                Properties.Settings.Default.GrabHeight = rect.Height;
                Properties.Settings.Default.Save();
            });

            PreviewKeyDown += _grabberWindow.HotKey;
            PreviewKeyUp   += _grabberWindow.HotKey;
            PreviewKeyDown += HotKey;

            // grid preview images
            _pbfxGridProcessor.WhenProcessed.Subscribe(bmp => {
                ProcessedGrid.Dispatcher.Invoke(() => {
                    ProcessedGrid.Source = bmp;
                });
            });
        }