/// <summary> /// Gets the <see cref="System.Drawing.Bitmap"/> with the specified direction and phase. /// </summary> public Bitmap this[MonsterDirection direction, int phase] { get { if (MonsterPict == null) return null; if (_cache == null) _cache = new Dictionary<MonsterDirection, List<CacheElem>>(); if (!_cache.ContainsKey(direction)) { _cache.Add(direction, new List<CacheElem>()); } if (_cache[direction].Find(x => x.ID == phase).CachedBitmap != null) { return _cache[direction].Find(x => x.ID == phase).CachedBitmap; } int phaseLength = MonsterPict.Size.Width / NumberOfPhases; Bitmap tmp = MonsterPict.Clone(new Rectangle(phaseLength * phase, 0, phaseLength, MonsterPict.Size.Height), System.Drawing.Imaging.PixelFormat.Undefined); if ((NumberOfDirectionsInFile == 2) && (tmp.Size.Width > tmp.Size.Height)) { throw new Exception("Incorrect phases number"); } if ((NumberOfDirectionsInFile == 4) && ((tmp.Size.Width * 2) > tmp.Size.Height))//Длина одной фазы*2 будет меньше высоты, если число фаз указано верно //в противном случае будет превышать высоту { throw new Exception("Incorrect phases number"); } switch (direction) { case MonsterDirection.Right: #region Обработка в зависимости от числа направлений в файле switch (NumberOfDirectionsInFile) { case 1: tmp.RotateFlip(RotateFlipType.Rotate180FlipNone); break; case 2: tmp = tmp.Clone(new Rectangle(0, 0, tmp.Size.Width, tmp.Size.Height - tmp.Size.Width), System.Drawing.Imaging.PixelFormat.Undefined); tmp.RotateFlip(RotateFlipType.Rotate180FlipNone); break; case 4: tmp = tmp.Clone(new Rectangle(0, (tmp.Size.Height / 2) - tmp.Size.Width, tmp.Size.Width, (tmp.Size.Height / 2) - tmp.Size.Width), System.Drawing.Imaging.PixelFormat.Undefined); break; } #endregion break; case MonsterDirection.Left: #region Обработка в зависимости от числа направлений в файле switch (NumberOfDirectionsInFile) { //case 1:В файле и так одно направление, влево //break; case 2: tmp = tmp.Clone(new Rectangle(0, 0, tmp.Size.Width, tmp.Size.Height - tmp.Size.Width), System.Drawing.Imaging.PixelFormat.Undefined); break; case 4: tmp = tmp.Clone(new Rectangle(0, 0, tmp.Size.Width, (tmp.Size.Height / 2) - tmp.Size.Width), System.Drawing.Imaging.PixelFormat.Undefined); break; } #endregion break; case MonsterDirection.Up: #region Обработка в зависимости от числа направлений в файле switch (NumberOfDirectionsInFile) { case 1: tmp.RotateFlip(RotateFlipType.Rotate90FlipNone); break; case 2: tmp = tmp.Clone(new Rectangle(0, tmp.Size.Height - tmp.Size.Width, tmp.Size.Width, tmp.Size.Width), System.Drawing.Imaging.PixelFormat.Undefined); break; case 4: tmp = tmp.Clone(new Rectangle(0, tmp.Size.Height - (tmp.Size.Width * 2), tmp.Size.Width, tmp.Size.Width), System.Drawing.Imaging.PixelFormat.Undefined); break; } #endregion break; case MonsterDirection.Down: #region Обработка в зависимости от числа направлений в файле switch (NumberOfDirectionsInFile) { case 1: tmp.RotateFlip(RotateFlipType.Rotate270FlipNone); break; case 2: tmp = tmp.Clone(new Rectangle(0, tmp.Size.Height - tmp.Size.Width, tmp.Size.Width, tmp.Size.Width), System.Drawing.Imaging.PixelFormat.Undefined); tmp.RotateFlip(RotateFlipType.Rotate180FlipNone); break; case 4: tmp = tmp.Clone(new Rectangle(0, tmp.Size.Height - tmp.Size.Width, tmp.Size.Width, tmp.Size.Width), System.Drawing.Imaging.PixelFormat.Undefined); break; } #endregion break; } CacheElem tmpCache = new CacheElem {ID = phase}; tmp.MakeTransparent(Color.FromArgb(255, 0, 255)); tmpCache.CachedBitmap = new Bitmap(tmp); _cache[direction].Add(tmpCache); return tmp; } }