Пример #1
0
        public static BitmapSource DrawTrack(Track track)
        {
            if (track != null)
            {
                CalculateWidthAndHeight(track);
                Bitmap noTrack     = ImageCache.CreateEmptyBitmap(_globalX * trackSizePx, _globalY * trackSizePx);
                Bitmap emptyTrack  = PutTrack(noTrack, track);
                Bitmap filledTrack = PutParticipants(emptyTrack, track);
                return(ImageCache.CreateBitmapSourceFromGdiBitmap(filledTrack));
            }

            Bitmap finished = ImageCache.CreateEmptyBitmap(512, 512);

            return(ImageCache.CreateBitmapSourceFromGdiBitmap(finished));
        }
Пример #2
0
 public void OnNextRace(object sender, EventArgs e)
 {
     ImageCache.ClearCache();
     Data.CurrentRace.CleanupEvents();
     Data.Competition.ParticipantTimesBroken.Reset();
     Data.Competition.ParticipantsTimes.Reset();
     Data.NextRace();
     if (Data.CurrentRace != null)
     {
         Data.CurrentRace.DriversChanged += DataContextMainWindow.OnDriversChanged;
         if (_currentRaceStats != null)
         {
             Data.CurrentRace.DriversChanged += _currentRaceStats.DataContextCurrentRace.OnDriversChanged;
         }
         if (_competitionPartStats != null)
         {
             Data.CurrentRace.DriversChanged += _competitionPartStats.DataContextCompetition.OnDriversChanged;
         }
         Data.CurrentRace.DriversChanged += OnDriversChanged;
         Data.CurrentRace.NextRace       += OnNextRace;
         Data.CurrentRace.Start();
     }
 }
Пример #3
0
        public static Bitmap PutTrack(Bitmap bitmap, Track track)
        {
            int currentX, currentY;

            currentX = -minX;
            currentY = -minY;
            int      compass = 1;
            Graphics g       = Graphics.FromImage(bitmap);

            foreach (Section section in track.Sections)
            {
                switch (section.SectionType)
                {
                case SectionTypes.StartGrid:
                    Bitmap startGrid = new Bitmap(ImageCache.GetImgBitmap(_start));
                    g.DrawImage(RotateAsset(startGrid, compass, "straight"), new Point(currentX * trackSizePx, currentY * trackSizePx));
                    break;

                case SectionTypes.Finish:
                    Bitmap finish = new Bitmap(ImageCache.GetImgBitmap(_finish));
                    g.DrawImage(RotateAsset(finish, compass, "straight"), new Point(currentX * trackSizePx, currentY * trackSizePx));
                    break;

                case SectionTypes.LeftCorner:
                    Bitmap leftCorner = new Bitmap(ImageCache.GetImgBitmap(_corner));
                    g.DrawImage(RotateAsset(leftCorner, compass, "leftCorner"), new Point(currentX * trackSizePx, currentY * trackSizePx));
                    compass = (compass < 1) ? 3 : compass -= 1;
                    break;

                case SectionTypes.RightCorner:
                    Bitmap rightCorner = new Bitmap(ImageCache.GetImgBitmap(_corner));
                    g.DrawImage(RotateAsset(rightCorner, compass, "rightCorner"), new Point(currentX * trackSizePx, currentY * trackSizePx));
                    compass = (compass > 2) ? 0 : compass += 1;
                    break;

                case SectionTypes.Straight:
                    Bitmap straight = new Bitmap(ImageCache.GetImgBitmap(_straight));
                    g.DrawImage(RotateAsset(straight, compass, "straight"), new Point(currentX * trackSizePx, currentY * trackSizePx));
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                switch (compass)
                {
                case 0:
                    currentY--;
                    break;

                case 1:
                    currentX++;
                    break;

                case 2:
                    currentY++;
                    break;

                case 3:
                    currentX--;
                    break;
                }
            }

            return(bitmap);
        }