/// <summary> /// Builds a nice preview of a train. /// </summary> public PreviewDrawer CreatePreview(Size pixelSize, int trainlength) { 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(trainlength); /*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 * }*/ if (cars == null) { return(pd); // no preview } int[] pos = new int[] { -2, 0, -1, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 }; int[] angle = new int[] { 12, 12, 13, 14, 14, 14, 14, 14 }; int[] offset = new int[] { 0, 0, 0, 0, 4, +2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; using (DrawContext dc = new DrawContext(pd.Surface)) { for (int i = 7; 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); }