Esempio n. 1
0
        public void Calibrate()
        {
            sm_log.Info("Calibrating center of hex grid");

            // Drag a glyph of equilibrium onto the center of the grid
            var toolLocation = m_sidebar.ScrollTo(m_sidebar.Glyphs, m_sidebar.Glyphs[GlyphType.Equilibrium]);
            var gridLocation = m_grid.GetScreenLocationForCell(new Vector2(0, 0));

            MouseUtils.LeftDrag(toolLocation, gridLocation);

            // Find where the glyph actually ended up on the screen - this will be the exact center of a hex
            // near the center of the screen.
            var actualCenter = FindGlyph(m_grid.CenterLocation);

            sm_log.Info(Invariant($"Actual hex center is {actualCenter}"));

            // Scroll the grid so this actual center is exactly where we want it
            var desiredCenter = m_grid.Rect.Location.Add(new Point(m_grid.Rect.Width / 2, m_grid.Rect.Height / 2)).Add(CenterOffset);

            MouseUtils.RightDrag(actualCenter, desiredCenter);
            m_grid.CenterLocation = desiredCenter;

            // Delete the glyph from the grid
            KeyboardUtils.KeyPress(Keys.Z);
        }
Esempio n. 2
0
        private Molecule AnalyzeMolecule(Point location)
        {
            // Make sure the molecule is visible in the sidebar
            var screenLocation = m_sidebar.ScrollTo(m_palette, location);

            Molecule molecule;
            bool     edgeChanged;

            using (var captures = new DisposableList <ScreenCapture>())
            {
                var sidebarCapture1 = captures.Add(new ScreenCapture(m_sidebar.Rect));

                // To analyze the molecule, drag it onto the grid. This will expand it to full size and make it much easier to analyze.
                sm_log.Info("Centering grid");
                m_grid.ScrollTo(new Vector2(0, 0));

                sm_log.Info("Dragging molecule onto grid");
                MouseUtils.LeftDrag(screenLocation, m_grid.GetScreenLocationForCell(new Vector2(0, 0)));
                molecule = new MoleculeAnalyzer(m_grid, m_type).Analyze();
                sm_log.Info("Analyzed molecule:" + Environment.NewLine + molecule.ToString());

                var sidebarCapture2 = captures.Add(new ScreenCapture(m_sidebar.Rect));
                edgeChanged = ExcludeChangedPixels(sidebarCapture1, sidebarCapture2);
                sm_log.Info("edgeChanged: " + edgeChanged);
            }

            using (var captures = new DisposableList <ScreenCapture>())
            {
                if (edgeChanged)
                {
                    // A pixel on the bottom edge of the visible part of the sidebar changed, which means
                    // the molecule probably extends onto the next page. So we scroll down and then exclude
                    // any pixels that change there when we delete the molecule.
                    m_sidebar.Area.ScrollBy(new Point(0, m_sidebar.Rect.Height));
                    var sidebarCapture1 = captures.Add(new ScreenCapture(m_sidebar.Rect));

                    // Delete the molecule from the grid
                    KeyboardUtils.KeyPress(Keys.Z);

                    var sidebarCapture2 = captures.Add(new ScreenCapture(m_sidebar.Rect));
                    ExcludeChangedPixels(sidebarCapture1, sidebarCapture2);

                    // Technically the molecule could overlap a third page but we'll ignore that for now.
                }
                else
                {
                    // Delete the molecule from the grid
                    KeyboardUtils.KeyPress(Keys.Z);
                }
            }

            return(molecule);
        }