private List <IRapidXamlAdornmentTag> ProcessGrid(string xaml)
        {
            var outputTags = new TagList();

            var sut = new GridProcessor(ProjectType.Any, new DefaultTestLogger());

            var snapshot = new FakeTextSnapshot();

            sut.Process("testfile.xaml", 1, xaml, "	    ", snapshot, outputTags);

            return(outputTags);
        }
        private List <IRapidXamlAdornmentTag> ProcessGrid(string xaml)
        {
            var outputTags = new TagList();

            var sut = new GridProcessor(new ProcessorEssentialsForSimpleTests());

            var snapshot = new FakeTextSnapshot(xaml.Length);

            sut.Process("testfile.xaml", 1, xaml, "	    ", snapshot, outputTags);

            return(outputTags);
        }
        private List <IRapidXamlAdornmentTag> ProcessGrid(string xaml)
        {
            var outputTags = new List <IRapidXamlAdornmentTag>();

            var sut = new GridProcessor();

            var snapshot = new FakeTextSnapshot();

            sut.Process(1, xaml, "	    ", snapshot, outputTags);

            return(outputTags);
        }
示例#4
0
        public void Real_ProfileConfigControl_GridProcessor()
        {
            var xaml = System.IO.File.ReadAllText("./Misc/ProfileConfigControl.xaml");

            var outputTags = new TagList();

            var sut = new GridProcessor(new ProcessorEssentialsForSimpleTests(ProjectType.Wpf));

            var snapshot = new FakeTextSnapshot();

            sut.Process("testfile.xaml", 1, xaml, "    ", snapshot, outputTags);

            Assert.AreEqual(0, outputTags.OfType <MissingRowDefinitionTag>().Count());
        }
示例#5
0
        public void NestedSelfClosingElementsDontBreakRowDefinitionDetection()
        {
            var xaml = @"
                        <Grid
                            x:Name=""PaneToggleButtonGrid""
                            Margin=""0,0,0,8""
                            HorizontalAlignment=""Left""
                            VerticalAlignment=""Top""
                            Canvas.ZIndex=""100"">

                            <Grid.RowDefinitions>
                                <RowDefinition Height=""Auto"" />
                                <RowDefinition Height=""Auto"" />
                            </Grid.RowDefinitions>

                            <Grid x:Name=""TogglePaneTopPadding""
                                  Height=""{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.TopPadding}""/>

                            <Grid x:Name=""ButtonHolderGrid"" Grid.Row=""1"">
                                <Button x:Name=""NavigationViewBackButton""
                                        Style=""{StaticResource NavigationBackButtonNormalStyle}""
                                        VerticalAlignment=""Top""
                                        Visibility=""{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.BackButtonVisibility}""
                                        IsEnabled=""{TemplateBinding IsBackEnabled}""/>

                                <Button
                                    x:Name=""TogglePaneButton""
                                    Style=""{TemplateBinding PaneToggleButtonStyle}""
                                    AutomationProperties.LandmarkType=""Navigation""
                                    Visibility=""{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.PaneToggleButtonVisibility}""
                                    VerticalAlignment=""Top""/>
                            </Grid>

                        </Grid>
";

            var outputTags = new TagList();

            var sut = new GridProcessor(new ProcessorEssentialsForSimpleTests());

            var snapshot = new FakeTextSnapshot();

            sut.Process("testfile.xaml", 1, xaml, "	    ", snapshot, outputTags);

            Assert.AreEqual(0, outputTags.OfType <MissingRowDefinitionTag>().Count());
        }
        public void CreateColumnDefinitionTags_IfJustHaveRows()
        {
            var xaml = @"<Grid>
    <Grid.RowDefinitions />

    <!-- Grid contents -->
</Grid>";

            var outputTags = new List <IRapidXamlAdornmentTag>();

            var sut = new GridProcessor();

            var snapshot = new FakeTextSnapshot();

            sut.Process(0, xaml, string.Empty, snapshot, outputTags);

            Assert.AreEqual(1, outputTags.Count);
            Assert.AreEqual(1, outputTags.OfType <AddColumnDefinitionsTag>().Count());
        }
示例#7
0
        public void CreateColumnDefinitionTags_IfJustHaveRows()
        {
            var xaml = @"<Grid>
    <Grid.RowDefinitions />

    <!-- Grid contents -->
</Grid>";

            var outputTags = new TagList();

            var sut = new GridProcessor(new ProcessorEssentialsForSimpleTests());

            var snapshot = new FakeTextSnapshot();

            sut.Process("testfile.xaml", 0, xaml, string.Empty, snapshot, outputTags);

            Assert.AreEqual(1, outputTags.Count);
            Assert.AreEqual(1, outputTags.OfType <AddColumnDefinitionsTag>().Count());
        }
        public void CreateRowDefinitionTags_IfJustHaveColumns()
        {
            var xaml = @"<Grid>
    <Grid.ColumnDefinitions />

    <!-- Grid contents -->
</Grid>";

            var outputTags = new TagList();

            var sut = new GridProcessor(ProjectType.Any, new DefaultTestLogger());

            var snapshot = new FakeTextSnapshot();

            sut.Process("testfile.xaml", 0, xaml, string.Empty, snapshot, outputTags);

            Assert.AreEqual(1, outputTags.Count);
            Assert.AreEqual(1, outputTags.OfType <AddRowDefinitionsTag>().Count());
        }
        public void CreateRowDefinitionTags_WithCorrectLeftPad_SpacesTab()
        {
            var xaml = @"<Grid>
	<Grid.ColumnDefinitions />

	<!-- Grid contents -->
</Grid>";

            var outputTags = new List <IRapidXamlAdornmentTag>();

            var sut = new GridProcessor();

            var snapshot = new FakeTextSnapshot();

            sut.Process(1, xaml, "    	", snapshot, outputTags);

            Assert.AreEqual(1, outputTags.Count);
            Assert.AreEqual(1, outputTags.OfType <AddRowDefinitionsTag>().Count());
            Assert.AreEqual("    		", ((AddRowDefinitionsTag)outputTags[0]).LeftPad);
        }
示例#10
0
        public void CreateRowDefinitionTags_WithCorrectLeftPad_SpacesTab()
        {
            var xaml = @"<Grid>
	<Grid.ColumnDefinitions />

	<!-- Grid contents -->
</Grid>";

            var outputTags = new TagList();

            var sut = new GridProcessor(new ProcessorEssentialsForSimpleTests());

            var snapshot = new FakeTextSnapshot();

            sut.Process("testfile.xaml", 1, xaml, "    	", snapshot, outputTags);

            Assert.AreEqual(1, outputTags.Count);
            Assert.AreEqual(1, outputTags.OfType <AddRowDefinitionsTag>().Count());
            Assert.AreEqual("    		", ((AddRowDefinitionsTag)outputTags[0]).LeftPad);
        }
        public void CreatesMultipleTags()
        {
            var xaml = @"<Grid>
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition />
    </Grid.RowDefinitions>
</Grid>";

            var outputTags = new List <IRapidXamlAdornmentTag>();

            var sut = new GridProcessor();

            var snapshot = new FakeTextSnapshot();

            sut.Process(0, xaml, string.Empty, snapshot, outputTags);

            Assert.AreEqual(3, outputTags.Count);
            Assert.AreEqual(2, outputTags.OfType <InsertRowDefinitionTag>().Count());
            Assert.AreEqual(1, outputTags.OfType <AddColumnDefinitionsTag>().Count());
        }
示例#12
0
        public void CreatesMultipleTags()
        {
            var xaml = @"<Grid>
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition />
    </Grid.RowDefinitions>
</Grid>";

            var outputTags = new TagList();

            var sut = new GridProcessor(new ProcessorEssentialsForSimpleTests());

            var snapshot = new FakeTextSnapshot();

            sut.Process("testfile.xaml", 0, xaml, string.Empty, snapshot, outputTags);

            Assert.AreEqual(3, outputTags.Count);
            Assert.AreEqual(2, outputTags.OfType <InsertRowDefinitionTag>().Count());
            Assert.AreEqual(1, outputTags.OfType <AddColumnDefinitionsTag>().Count());
        }
示例#13
0
        public IObservable <ColoredFrame> GetColoredGray2Frames()
        {
            double lastHue = 0;

            Color[] palette = null;
            int     index   = -1;

            if (_framesColoredGray2 == null)
            {
                var gridProcessor = new GridProcessor {
                    Spacing = 1d
                };
                Logger.Info("Capturing at {0} frames per second...", FramesPerSecond);
                _framesColoredGray2 = Observable.Interval(TimeSpan.FromMilliseconds(1000d / FramesPerSecond))
                                      .Select(x => CaptureWindow())
                                      .Where(bmp => bmp != null)
                                      .Select(bmp => gridProcessor.Process(bmp))
                                      .Select(bmp => TransformationUtil.Transform(bmp, 128, 32, ResizeMode.Stretch, false, false))
                                      .Select(bmp => {
                    double hue;
                    var frame = ImageUtil.ConvertToGray2(bmp, 3, out hue);
                    if (palette == null || Math.Abs(hue - lastHue) > 0.01)
                    {
                        byte r, g, b;
                        ColorUtil.HslToRgb(hue, 1, 0.5, out r, out g, out b);
                        var color = Color.FromRgb(r, g, b);
                        palette   = ColorUtil.GetPalette(new[] { Colors.Black, color }, 4);
                        lastHue   = hue;
                    }
                    return(new ColoredFrame(FrameUtil.Split(bmp.PixelWidth, bmp.PixelHeight, 2, frame), palette, index));
                })
                                      .Publish();

                StartPolling();
            }
            return(_framesColoredGray2);
        }
        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;
                });
            });
        }
示例#15
0
 public void BeforeAnyTestsHaveRun()
 {
     _data      = new DataSource().AsArray();
     _processor = new GridProcessor();
 }
示例#16
0
        public override void Execute(Action onCompleted, Action <Exception> onError)
        {
            // create graph with renderers
            _graph = new RenderGraph {
                Destinations  = GetRenderers(_options),
                RenderAsGray4 = _options.RenderAsGray4
            };

            // instantiate transformation processor
            var transformationProcessor = new TransformationProcessor {
                FlipVertically   = _options.FlipVertically,
                FlipHorizontally = _options.FlipHorizontally
            };

            // setup source and additional processors
            switch (_options.Source)
            {
            case SourceType.PinballFX2: {
                if (_options.GridSize.Length != 2)
                {
                    throw new InvalidOptionException("Argument --grid-size must have two values: \"<Width> <Height>\".");
                }
                if (_options.DmdCrop.Length != 4)
                {
                    throw new InvalidOptionException("Argument --dmd-crop must have four values: \"<Left> <Top> <Right> <Bottom>\".");
                }
                _graph.Source = new PBFX2Grabber {
                    FramesPerSecond = _options.FramesPerSecond,
                    CropLeft        = _options.DmdCrop[0],
                    CropTop         = _options.DmdCrop[1],
                    CropRight       = _options.DmdCrop[2],
                    CropBottom      = _options.DmdCrop[3]
                };
                var gridProcessor = new GridProcessor {
                    Spacing = _options.GridSpacing,
                    Width   = _options.GridSize[0],
                    Height  = _options.GridSize[1]
                };
                var shadeProcessor = new ShadeProcessor {
                    Enabled    = !_options.DisableShading,
                    NumShades  = _options.NumShades,
                    Intensity  = _options.ShadeIntensity,
                    Brightness = _options.ShadeBrightness
                };
                _graph.Processors = new List <AbstractProcessor> {
                    gridProcessor,
                    transformationProcessor,
                    shadeProcessor
                };
                break;
            }

            case SourceType.PinballArcade: {
                _graph.Source = new TPAGrabber {
                    FramesPerSecond = _options.FramesPerSecond
                };
                var shadeProcessor = new ShadeProcessor {
                    Enabled    = !_options.DisableShading,
                    NumShades  = 4,
                    Shades     = new[] { 0d, 0.22, 0.35, 0.55 },
                    Intensity  = 1.9,
                    Brightness = 0
                };
                _graph.Processors = new List <AbstractProcessor>()
                {
                    transformationProcessor,
                    shadeProcessor
                };
                break;
            }

            case SourceType.Screen:
                if (_options.Position.Length != 4)
                {
                    throw new InvalidOptionException("Argument --position must have four values: \"<Left> <Top> <Width> <Height>\".");
                }
                _graph.Source = new ScreenGrabber {
                    FramesPerSecond = _options.FramesPerSecond,
                    Left            = _options.Position[0],
                    Top             = _options.Position[1],
                    Width           = _options.Position[2],
                    Height          = _options.Position[3]
                };
                _graph.Processors = new List <AbstractProcessor>()
                {
                    transformationProcessor
                };
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            // TODO add as option
            var monochromeProcessor = new MonochromeProcessor {
                Tint = Color.FromRgb(255, 155, 0)
            };

            // always transform to correct dimensions
            _renderer = _graph.StartRendering(onCompleted, onError);
        }