Exemple #1
0
        public void TestRegionPosition()
        {
            CardPositions cp       = new CardPositions(1920, 1080);
            CardRegion    expected = new CardRegion(0, 0, 384, 489);

            Assert.AreEqual(expected, cp.Get(0, RegionType.Count));
        }
Exemple #2
0
        public void TestRegionPositionMana2()
        {
            CardPositions cp       = new CardPositions(1920, 1080);
            CardRegion    expected = new CardRegion(40, 40, 537, 183);

            Assert.AreEqual(expected, cp.Get(1, RegionType.Mana));
        }
Exemple #3
0
        public void TestCardRegionDefaultAdd()
        {
            var cr       = new CardRegion();
            var expected = new CardRegion(0, 0, 3, 4);

            Assert.AreEqual <CardRegion>(expected, cr.Add(3, 4));
        }
Exemple #4
0
        public void TestCardRegionAdd()
        {
            var cr       = new CardRegion(20, 30, 164, 80);
            var expected = new CardRegion(20, 30, 100, -6);

            Assert.AreEqual <CardRegion>(expected, cr.Add(-64, -86));
        }
Exemple #5
0
        public bool Equals(CardRegion cr)
        {
            if ((object)cr == null)
            {
                return(false);
            }

            return((Point == cr.Point) && (Size == cr.Size));
        }
Exemple #6
0
        private static bool ReadPixel(Bitmap bmp, CardRegion region,
                                      double minHue, double maxHue, double minBrightness, double maxBrightness)
        {
            var pixel = bmp.GetPixel(region.Point.X + 16, region.Point.Y + 16);
            var hue   = Math.Round(pixel.GetHue());

            Console.Write("[50x30 Hue:{0} Bri:{1}\n", pixel.GetHue(), pixel.GetBrightness());
            return(pixel.GetHue() < 40.0 && pixel.GetBrightness() < 0.4);
        }
Exemple #7
0
        private CardRegion[] CalculateAllPositions(PointF p, double d)
        {
            CardRegion[] regions = new CardRegion[4];
            // calculate the scaled square size
            var dim = (int)Math.Round(Height * d);

            // top row (0-3)
            for (var i = 0; i < 4; i++)
            {
                var tmp = new PointF((float)(p.X + i * xOffset), p.Y);
                regions[i] = new CardRegion(ToPixelCoordinates(tmp), new Size(dim, dim));
            }
            // bottom row (4-7), may be unecessary
            return(regions);
        }
Exemple #8
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            CardRegion cr = obj as CardRegion;

            if ((object)cr == null)
            {
                return(false);
            }
            return((Point == cr.Point) && (Size == cr.Size));
        }
Exemple #9
0
        private static bool ReadRegion(Bitmap bmp, CardRegion region,
                                       double minHue, double maxHue, double minBrightness, double maxBrightness)
        {
            //var full = new Bitmap(width, height, PixelFormat.Format32bppArgb);
            if (region.Size.IsEmpty)
            {
                return(ReadPixel(bmp, region, minHue, maxHue, minBrightness, maxBrightness));
            }
            var regionBitmap = bmp.Clone(
                new Rectangle(region.Point, region.Size), PixelFormat.Format32bppArgb);
            // TODO: Remove
            //var ts = DateTime.Now.ToString("HHmmssff");
            //regionBitmap.Save(ts + ".png", ImageFormat.Png);
            // ---
            var hb         = GetAverageHueAndBrightness(regionBitmap);
            var hue        = hb.Hue;
            var brightness = hb.Brightness;

            Console.Write("[{1} @ {0} - Hue:{2} Bri:{3}]\n", region.Point, region.Size, Math.Round(hue, 4), Math.Round(brightness, 4));
            regionBitmap.Dispose();
            return((hue >= minHue && hue <= maxHue) && (brightness >= minBrightness && brightness <= maxBrightness));
        }