Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ImageGroup.cs
Go to the documentation of this file.
1 using System.Collections.Generic;
2 
3 namespace SiliconStudio.Paradox.Graphics
4 {
5  /// <summary>
6  /// A group of images.
7  /// </summary>
8  /// <typeparam name="T">The type of image</typeparam>
9  public class ImageGroup<T> where T: ImageFragment
10  {
11  /// <summary>
12  /// The list of sprites.
13  /// </summary>
14  public List<T> Images = new List<T>();
15 
16  /// <summary>
17  /// Find the index of a sprite in the group using its name.
18  /// </summary>
19  /// <param name="spriteName">The name of the sprite</param>
20  /// <returns>The index value</returns>
21  /// <remarks>If two sprites have the provided name then the first sprite found is returned</remarks>
22  /// <exception cref="KeyNotFoundException">No sprite in the group have the given name</exception>
23  public int FindImageIndex(string spriteName)
24  {
25  if (Images != null)
26  {
27  for (int i = 0; i < Images.Count; i++)
28  {
29  if (Images[i].Name == spriteName)
30  return i;
31  }
32  }
33 
34  throw new KeyNotFoundException(spriteName);
35  }
36 
37  /// <summary>
38  /// Gets or sets the image of the group at <paramref name="index"/>.
39  /// </summary>
40  /// <param name="index">The image index</param>
41  /// <returns>The image</returns>
42  public T this[int index]
43  {
44  get { return Images[index]; }
45  set { Images[index] = value; }
46  }
47 
48  /// <summary>
49  /// Gets or sets the image of the group having the provided <paramref name="name"/>.
50  /// </summary>
51  /// <param name="name">The name of the image</param>
52  /// <returns>The image</returns>
53  public T this[string name]
54  {
55  get { return Images[FindImageIndex(name)]; }
56  set { Images[FindImageIndex(name)] = value; }
57  }
58  }
59 }
int FindImageIndex(string spriteName)
Find the index of a sprite in the group using its name.
Definition: ImageGroup.cs:23