public override void updatePreview()
        {
            RailPattern rp = RailPattern.get(currentDirection, currentDirection.opposite);

            using (PreviewDrawer drawer = new PreviewDrawer(preview.Size, new Size(1, 1), 0)) {
                // draw the rail
                for (int i = -5; i < 5; i++)
                {
                    if (currentDirection.isParallelToX)
                    {
                        drawer.draw(rp, i, 0);
                    }
                    else
                    {
                        drawer.draw(rp, 0, i);
                    }
                }

                // draw the signal
                drawer.draw(rp, 0, 0);
                drawer.draw(currentType.getSprite(currentDirection), 0, 0);

                // draw the arrow
                currentDirection.drawArrow(drawer.surface,
                                           drawer.getPoint(-currentDirection.offsetX, -currentDirection.offsetY));

                preview.Image = drawer.createBitmap();
            }
        }
示例#2
0
        /// <summary>
        /// Builds a nice preview of a train.
        /// </summary>
        public PreviewDrawer createPreview(Size pixelSize)
        {
            PreviewDrawer pd = new PreviewDrawer(pixelSize, new Size(1, 3), 0);

            // build up rail like
            //
            //     /~~~~~
            //    /
            for (int x = -10; x < 0; x++)
            {
                pd.draw(RailPattern.get(Direction.WEST, Direction.EAST), x, 0);
            }
            pd.draw(RailPattern.get(Direction.WEST, Direction.SOUTHEAST), 0, 0);
            for (int x = 1; x <= 10; x++)
            {
                pd.draw(RailPattern.get(Direction.NORTHWEST, Direction.SOUTHEAST), x, x);
            }

            TrainCarContribution[] cars = create(5);
            if (cars == null)
            {
                for (int i = 6; cars == null && i < 15; i++)
                {
                    cars = create(i);
                }
                for (int i = 4; cars == null && i > 0; i--)
                {
                    cars = create(i);
                }
                if (cars == null)
                {
                    return(pd);                         // no preview
                }
            }

            int[] pos    = new int[] { -2, 0, -1, 0, 0, 0, 1, 1, 2, 2 };
            int[] angle  = new int[] { 12, 12, 13, 14, 14 };
            int[] offset = new int[] { 0, 0, 0, 0, 4, +2, 0, 0, 0, 0 };

            using (DrawContext dc = new DrawContext(pd.surface)) {
                for (int i = 4; i >= 0; i--)
                {
                    if (cars.Length <= i)
                    {
                        continue;                                       // no car
                    }
                    Point pt = pd.getPoint(pos[i * 2], pos[i * 2 + 1]);
                    cars[i].draw(pd.surface,
                                 new Point(pt.X + offset[i * 2], pt.Y + offset[i * 2 + 1] - 9), angle[i]);
                }
            }

            return(pd);
        }
示例#3
0
        /// <summary>
        /// Creates the preview image of the land builder.
        /// </summary>
        public override PreviewDrawer createPreview(Size pixelSize)
        {
            const int     r      = 8;
            PreviewDrawer drawer = new PreviewDrawer(pixelSize, new Size(r, r), 0);

            for (int y = 0; y < r; y++)
            {
                for (int x = 0; x < r; x++)
                {
                    Point  pt   = drawer.getPoint(x, y, 0);
                    byte[] tree = createRandomTrees();

                    for (int i = 0; i < tree.Length; i += 3)
                    {
                        sprites[tree[i + 2]].draw(drawer.surface,
                                                  new Point(pt.X + tree[i + 0], pt.Y + tree[i + 1]));
                    }
                }
            }

            return(drawer);
        }