1 // =================================
 2 // Copyright (c) 2021 Seppo Laakko
 3 // Distributed under the MIT license
 4 // =================================
 5 
 6 using System;
 7 using System.Collections;
 8 
 9 namespace System.Windows
10 {
11     public class ImageList
12     {
13         public nothrow ImageList()
14         {
15         }
16         public void AddImage(const string& imageName)
17         {
18             AddImage(imageNamenew Bitmap(Bitmap.FromResource(imageName)));
19         }
20         public void AddDisabledImage(const string& imageName)
21         {
22             int imageIndex = GetImageIndex(imageName);
23             if (imageIndex != -1)
24             {
25                 Bitmap* bitmap = images[imageIndex].Get();
26                 Bitmap* disabledImage = new Bitmap(bitmap->ToGrayBitmap());
27                 AddImage(imageName + ".disabled"disabledImage);
28             }
29             else
30             {
31                 throw Exception("image '" + imageName + "' not found");
32             }
33         }
34         public void AddImage(const string& imageNameBitmap* bitmap)
35         {
36             int imageIndex = cast<int>(images.Count());
37             images.Add(UniquePtr<Bitmap>(bitmap));
38             imageIndexMap[imageName] = imageIndex;
39         }
40         public nothrow int GetImageIndex(const string& imageName)
41         {
42             Map<stringint>.ConstIterator it = imageIndexMap.CFind(imageName);
43             if (it != imageIndexMap.CEnd())
44             {
45                 return it->second;
46             }
47             else
48             {
49                 return -1;
50             }
51         }
52         public nothrow int GetDisabledImageIndex(const string& imageName)
53         {
54             return GetImageIndex(imageName + ".disabled");
55         }
56         public Bitmap* GetImage(int imageIndex) const
57         {
58             if (imageIndex >= 0 && imageIndex < images.Count())
59             {
60                 return images[imageIndex].Get();
61             }
62             else
63             {
64                 return null;
65             }
66         }
67         private Map<stringint> imageIndexMap;
68         private List<UniquePtr<Bitmap>> images;
69     }
70 }
71