Exemple #1
0
        private IEnumerable <PaletteInfo> FindPalettes()
        {
            sm_log.Info("Finding palettes");

            int startY          = 0;
            int prevNextHeaderY = 0;
            int scrollPosition  = 0;

            for (int i = 0; i < NumPalettes; i++)
            {
                using (var capture = new ScreenCapture(SidebarRect))
                {
                    int?headerY = SidebarUtil.FindPaletteHeader(capture.Bitmap, startY);
                    if (headerY == null)
                    {
                        throw new AnalysisException(Invariant($"Expected to find {NumPalettes} palettes but only found {i}."));
                    }

                    if (i > 0)
                    {
                        scrollPosition += prevNextHeaderY - headerY.Value;
                    }

                    int?nextHeaderY = SidebarUtil.FindPaletteHeader(capture.Bitmap, headerY.Value + 1);
                    if (nextHeaderY.HasValue)
                    {
                        // Capture between the two palette headers
                        int y = headerY.Value + PaletteHeaderHeight;
                        yield return(new PaletteInfo
                        {
                            Capture = capture.Clone(new Rectangle(0, y, capture.Rect.Width, nextHeaderY.Value - y - PaletteBottomSeparationHeight)),
                            ScrollPosition = new Point(0, scrollPosition)
                        });

                        if (m_isScrollable)
                        {
                            // Scroll the next palette up so it's adjacent to the previous one (if possible)
                            MouseUtils.RightDrag(SidebarRect.Location.Add(new Point(0, nextHeaderY.Value)), SidebarRect.Location.Add(new Point(0, headerY.Value + PaletteHeaderSeparationHeight)));
                        }

                        prevNextHeaderY = nextHeaderY.Value;
                    }
                    else
                    {
                        // This must be the last palette, so capture to the bottom of the sidebar
                        int y = headerY.Value + PaletteHeaderHeight;
                        yield return(new PaletteInfo
                        {
                            Capture = capture.Clone(new Rectangle(0, y, capture.Rect.Width, capture.Rect.Height - y - PaletteFooterHeight)),
                            ScrollPosition = new Point(0, scrollPosition)
                        });
                    }

                    // Next iteration, start looking for the palette just below the previous one
                    startY = headerY.Value + 1;
                }
            }
        }
        private DisposableList <ScreenCapture> GetSidebarCaptures()
        {
            // Chop a bit off the bottom of the image because it starts to fade out there, making it more difficult to compare
            var captureRect = new Rectangle(SidebarRect.Left, SidebarRect.Top, SidebarRect.Width, SidebarRect.Height - 70);

            sm_log.Info("Capturing section 0 of the sidebar");
            var prevCapture = new ScreenCapture(captureRect);

            var captures = new DisposableList <ScreenCapture> {
                prevCapture.Clone()
            };

            int scrollDistance = CalculateScrollDistance();

            const int maxIterations = 100;
            int       i             = 0;

            for (; i < maxIterations; i++)
            {
                MouseUtils.RightDrag(SidebarRect.Location.Add(new Point(0, scrollDistance)), SidebarRect.Location);

                // Check if we've reached the bottom
                if (SidebarUtil.FindVisibleSidebarHeight() <= SidebarUtil.MaxHeight)
                {
                    break;
                }

                // Capture the next bit of the sidebar
                prevCapture.Dispose();
                prevCapture = new ScreenCapture(captureRect);
                sm_log.Info(Invariant($"Capturing section {i + 1} of the sidebar"));
                captures.Add(prevCapture.Clone(new Rectangle(0, prevCapture.Rect.Height - scrollDistance, prevCapture.Rect.Width, scrollDistance)));
            }

            if (i >= maxIterations)
            {
                throw new AnalysisException(Invariant($"Couldn't find the bottom of the sidebar after {i} attempts."));
            }

            // Capture the final bit of the sidebar
            var finalCapture = new ScreenCapture(SidebarRect);

            // Work out where it overlaps the previous part, and capture the overlap
            int overlap = BitmapComparer.CalculateVerticalOverlap(prevCapture.Bitmap, finalCapture.Bitmap, m_overlapComparer, 0);

            sm_log.Info("Capturing final section of the sidebar");
            captures.Add(finalCapture.Clone(new Rectangle(0, overlap, finalCapture.Rect.Width, finalCapture.Rect.Height - overlap)));

            prevCapture.Dispose();
            return(captures);
        }
Exemple #3
0
        private bool DetermineContinuousScrolling()
        {
            // Scroll the sidebar up one pixel. If the top header moves, it's continuously scrolling.
            using (var capture1 = new ScreenCapture(m_sidebarRect))
            {
                MouseUtils.RightDrag(m_sidebarRect.Location.Add(new Point(0, 1)), m_sidebarRect.Location);
                using (var capture2 = new ScreenCapture(m_sidebarRect))
                {
                    MouseUtils.RightDrag(m_sidebarRect.Location, m_sidebarRect.Location.Add(new Point(0, 1)));

                    var height1 = SidebarUtil.FindPaletteHeader(capture1.Bitmap, 0);
                    var height2 = SidebarUtil.FindPaletteHeader(capture2.Bitmap, 0);
                    if (!height1.HasValue || !height2.HasValue)
                    {
                        throw new AnalysisException("Could not find any palette headers in the sidebar.");
                    }

                    return(height1.Value != height2.Value);
                }
            }
        }
        private IEnumerable <PaletteInfo> FindPalettes(ScreenCapture capture)
        {
            sm_log.Info("Finding palettes");

            int prevY = 0;

            for (int i = 0; i < NumPalettes; i++)
            {
                int?paletteY = SidebarUtil.FindPaletteHeader(capture.Bitmap, prevY);
                if (paletteY == null)
                {
                    throw new AnalysisException(Invariant($"Expected to find {NumPalettes} palettes but only found {i}."));
                }

                if (i > 0)
                {
                    int y = prevY + PaletteHeaderHeight;
                    yield return(new PaletteInfo
                    {
                        Capture = capture.Clone(new Rectangle(0, y, capture.Rect.Width, paletteY.Value - y - PaletteBottomSeparationHeight)),
                        ScrollPosition = new Point(0, 0)
                    });
                }

                if (i == NumPalettes - 1)
                {
                    int y = paletteY.Value + PaletteHeaderHeight;
                    yield return(new PaletteInfo
                    {
                        Capture = capture.Clone(new Rectangle(0, y, capture.Rect.Width, capture.Rect.Height - y - PaletteFooterHeight)),
                        ScrollPosition = new Point(0, 0)
                    });
                }

                prevY = paletteY.Value + 1;
            }
        }
Exemple #5
0
        private void AnalyzeSidebar()
        {
            sm_log.Info("Analyzing sidebar");

            int height = SidebarUtil.FindVisibleSidebarHeight();

            if (height > SidebarUtil.MaxHeight)
            {
                m_isScrollable = true;
                height         = SidebarUtil.MaxHeight;
            }

            if (height < 100)
            {
                throw new AnalysisException("Cannot find the sidebar.");
            }

            m_sidebarRect = new Rectangle(ScreenCapture.ScreenBounds.Left + PaletteLeft, ScreenCapture.ScreenBounds.Top, PaletteWidth, height);
            sm_log.Info(Invariant($"Sidebar screen rect: {m_sidebarRect}"));
            sm_log.Info(Invariant($"Sidebar is scrollable: {m_isScrollable}"));

            m_isContinuousScrolling = m_isScrollable && DetermineContinuousScrolling();
            sm_log.Info(Invariant($"Sidebar is continuous scrolling: {m_isContinuousScrolling}"));
        }