Ejemplo n.º 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;
                }
            }
        }
Ejemplo n.º 2
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;
            }
        }