public GraphicsMapRenderer(IMap map, Point targetSize, Graphics graphics) : base(map, targetSize)
 {
     Graphics = graphics;
     Brushes  = new Dictionary <Color, Brush>();
     foreach (var color in Colors)
     {
         Brushes.Add(color.Value, new SolidBrush(color.Value));
     }
 }
Example #2
0
        protected override void DrawPolygon(Point mapPoint, ColoredPolygon polygon)
        {
            if (PictureBox == null)
            {
                return;
            }
            base.DrawPolygon(mapPoint, polygon);
            var invalidateRect = polygon.GetBoundingRectangle();

            PictureBox.Invalidate(invalidateRect);
        }
        public RawGifMapRenderer(IMap map, Point targetSize, string filePath, int frameDelay = 10) : base(map, new Bitmap(targetSize[0], targetSize[1]))
        {
            FilePath   = filePath;
            FrameDelay = frameDelay;
            var ms = new MemoryStream();

            GifImage = new GifImage(ms);
            GifImage.DefaultFrameDelay = FrameDelay;
            GifImage.DefaultWidth      = targetSize[0];
            GifImage.DefaultHeight     = targetSize[1];
        }
Example #4
0
        private Polygon MapPointToHexagon(Point point)
        {
            var centerPoint = GetHexagonCenterPoint(point);
            var points      = new System.Drawing.Point[6];

            for (var i = 0; i < points.Length; i++)
            {
                points[i] = GetPolygonCorner(centerPoint, i, 60, 30);
            }
            var polygon = new Polygon(points);

            return(polygon);
        }
Example #5
0
        private System.Drawing.Point GetHexagonCenterPoint(Point mapPoint)
        {
            var xPart = Convert.ToInt32(OffsetX + mapPoint[0] * CellWidth + CellWidth / 2);
            var yPart = Convert.ToInt32(OffsetY + mapPoint[1] * CellHeight + CellHeight / 2);

            if (mapPoint[1] % 2 == 0)
            {
                xPart += CellWidth / 2;
            }
            var centerPoint = new System.Drawing.Point(xPart, yPart);

            return(centerPoint);
        }
Example #6
0
        private Polygon MapPointToRectangle(Point point)
        {
            var centerPoint = GetRectangleCenterPoint(point);
            var points      = new System.Drawing.Point[4];

            for (var i = 0; i < points.Length; i++)
            {
                points[i] = GetPolygonCorner(centerPoint, i, 90, 45);
            }
            var polygon = new Polygon(points);

            return(polygon);
        }
        protected override void DrawPolygon(Point mapPoint, ColoredPolygon polygon)
        {
            var brush = Brushes[polygon.Color];

            try
            {
                Graphics.FillPolygon(brush, polygon.Points);
            }
            catch (InvalidOperationException ex) when(ex.Message == @"Object is currently in use elsewhere.")
            {
                // TODO: handle this in a proper way
            }
        }
Example #8
0
 public void RenderMap(bool disableCacheReading)
 {
     for (var i = 0; i < Map.Size[0]; i++)
     {
         for (var j = 0; j < Map.Size[1]; j++)
         {
             var point        = new Point(i, j);
             var cell         = Map.GetCell(point);
             var displayState = cell.DisplayState;
             var color        = Colors[displayState];
             DrawCell(point, color, disableCacheReading);
         }
     }
 }
Example #9
0
 public DrawingMapRenderer(IMap map, Point targetSize)
 {
     if (map.Dimensions != 2)
     {
         throw new IncorrectDimensionsException(new [] { 2 }, map.Dimensions);
     }
     if (map.Infinite)
     {
         throw new IncorrectFinityException(false, map.Infinite);
     }
     Map    = map;
     Colors = new Dictionary <CellDisplayState, Color>
     {
         { CellDisplayState.Wall, Color.Black },
         { CellDisplayState.PathWillReturn, Color.BurlyWood },
         { CellDisplayState.Path, Color.Green },
         { CellDisplayState.Active, Color.Brown },
         { CellDisplayState.Unspecified, Color.Magenta }
     };
     TargetSize = targetSize;
 }
Example #10
0
        public BRGifMapRenderer(IMap map, Point targetSize, string filePath, int frameDelay = 10) : base(map, targetSize)
        {
            FilePath   = filePath;
            FrameDelay = frameDelay;
            var ms = new MemoryStream();

            GifImage = new GifImage(ms);
            GifImage.DefaultFrameDelay = FrameDelay;
            GifImage.DefaultWidth      = targetSize[0];
            GifImage.DefaultHeight     = targetSize[1];

            Brushes = new Dictionary <Color, Brush>();
            foreach (var color in Colors)
            {
                Brushes.Add(color.Value, new SolidBrush(color.Value));
            }

            var initialImage = new Bitmap(targetSize[0], targetSize[1]);

            //var initialGraphics = Graphics.FromImage(initialImage);
            //initialGraphics.FillRectangle(new SolidBrush(Color.Red), new Rectangle(0,0,initialImage.Width, initialImage.Height));
            GifImage.AddFrame(initialImage, FrameDelay);
        }
Example #11
0
        private void DrawCell(Point point, Color color, bool disableCacheReading = false)
        {
            if (Cache)
            {
                if (!disableCacheReading)
                {
                    Color cachedColor;
                    var   exists = MapCache.TryGetValue(point, out cachedColor);
                    if (exists)
                    {
                        if (cachedColor.Equals(color))
                        {
                            return;
                        }
                    }
                }
                MapCache[point] = color;
            }
            var poly        = HexagonMode ? MapPointToHexagon(point) : MapPointToRectangle(point);
            var coloredPoly = new ColoredPolygon(poly.Points, color);

            DrawPolygon(point, coloredPoly);
        }
Example #12
0
 protected override void DrawPolygon(Point mapPoint, ColoredPolygon polygon)
 {
     Polygons.Add(polygon);
 }
Example #13
0
 protected abstract void DrawPolygon(Point mapPoint, ColoredPolygon polygon);
Example #14
0
        private System.Drawing.Point GetRectangleCenterPoint(Point mapPoint)
        {
            var centerPoint = new System.Drawing.Point(OffsetX + mapPoint[0] * CellWidth + CellWidth / 2, OffsetY + mapPoint[1] * CellHeight + CellHeight / 2);

            return(centerPoint);
        }
Example #15
0
 protected override void DrawPolygon(Point mapPoint, ColoredPolygon polygon)
 {
     throw new NotImplementedException();
 }