|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 using System; |
|
18 using System.Text; |
|
19 using System.Collections.Generic; |
|
20 using System.Drawing; |
|
21 |
|
22 namespace SymbianUtils.Colour |
|
23 { |
|
24 public class ColourGenerationUtil |
|
25 { |
|
26 #region Constructors |
|
27 public ColourGenerationUtil() |
|
28 { |
|
29 iStandardColors = CreateStandardColors(); |
|
30 iBannedColors = CreateBannedColors(); |
|
31 } |
|
32 #endregion |
|
33 |
|
34 #region API |
|
35 public Color GenerateRandomColour( Random aRandomNumberGenerator ) |
|
36 { |
|
37 Color ret = Color.White; |
|
38 // |
|
39 bool blackListed = false; |
|
40 do |
|
41 { |
|
42 int colItemIndex = aRandomNumberGenerator.Next( (int) KnownColor.Aqua, (int) KnownColor.YellowGreen ); |
|
43 KnownColor col = (KnownColor) colItemIndex; |
|
44 // |
|
45 blackListed = BannedColors.Contains( col ); |
|
46 ret = Color.FromKnownColor( col ); |
|
47 } |
|
48 while ( blackListed ); |
|
49 // |
|
50 return ret; |
|
51 } |
|
52 |
|
53 public Color GenerateRandomColourAndRemoveFromList() |
|
54 { |
|
55 int count = iStandardColors.Count; |
|
56 System.Random random = new Random(); |
|
57 int colItemIndex = random.Next( 0, count ); |
|
58 Color ret = Color.FromKnownColor( iStandardColors[ colItemIndex ] ); |
|
59 iStandardColors.RemoveAt( colItemIndex ); |
|
60 return ret; |
|
61 } |
|
62 |
|
63 public void SuplimentStandardColoursWithAdditionalEntries( int aRequiredEntryCount ) |
|
64 { |
|
65 // Pick colours at random from the standard colours until we have used them all |
|
66 System.Random random = new Random(); |
|
67 |
|
68 // How many objects do we have to colourise? |
|
69 int iterations = 0; |
|
70 int maxIterations = (int) KnownColor.MenuHighlight - iBannedColors.Count; |
|
71 while ( iStandardColors.Count < aRequiredEntryCount && iterations < maxIterations ) |
|
72 { |
|
73 int colItemIndex = random.Next( (int) KnownColor.Aqua, (int) KnownColor.YellowGreen ); |
|
74 KnownColor col = (KnownColor) colItemIndex; |
|
75 // |
|
76 bool alreadyExists = iStandardColors.Contains( col ); |
|
77 bool isBanned = iBannedColors.Contains( col ); |
|
78 if ( !alreadyExists && !isBanned ) |
|
79 { |
|
80 iStandardColors.Add( col ); |
|
81 } |
|
82 |
|
83 ++iterations; |
|
84 } |
|
85 |
|
86 // If we still dont' have enough colours at this point, then just duplicate some of the |
|
87 // known colours |
|
88 iterations = 0; |
|
89 maxIterations = iStandardColors.Count; |
|
90 while ( iStandardColors.Count < aRequiredEntryCount ) |
|
91 { |
|
92 KnownColor col = iStandardColors[ iterations ]; |
|
93 iStandardColors.Add( col ); |
|
94 // |
|
95 if ( iterations >= maxIterations ) |
|
96 { |
|
97 iterations = 0; |
|
98 } |
|
99 } |
|
100 } |
|
101 |
|
102 public List<KnownColor> CreateStandardColors() |
|
103 { |
|
104 List<KnownColor> list = new List<KnownColor>(); |
|
105 // |
|
106 list.Add( KnownColor.Red ); |
|
107 list.Add( KnownColor.IndianRed ); |
|
108 list.Add( KnownColor.Tomato ); |
|
109 list.Add( KnownColor.SandyBrown ); |
|
110 list.Add( KnownColor.Moccasin ); |
|
111 list.Add( KnownColor.Gold ); |
|
112 list.Add( KnownColor.Yellow ); |
|
113 list.Add( KnownColor.YellowGreen ); |
|
114 list.Add( KnownColor.LawnGreen ); |
|
115 list.Add( KnownColor.ForestGreen ); |
|
116 list.Add( KnownColor.Aquamarine ); |
|
117 list.Add( KnownColor.LightSeaGreen ); |
|
118 list.Add( KnownColor.Cyan ); |
|
119 list.Add( KnownColor.SkyBlue ); |
|
120 list.Add( KnownColor.DodgerBlue ); |
|
121 list.Add( KnownColor.LightSteelBlue ); |
|
122 list.Add( KnownColor.SlateBlue ); |
|
123 list.Add( KnownColor.DarkOrchid ); |
|
124 list.Add( KnownColor.Fuchsia ); |
|
125 list.Add( KnownColor.Pink ); |
|
126 // |
|
127 return list; |
|
128 } |
|
129 |
|
130 public List<KnownColor> CreateBannedColors() |
|
131 { |
|
132 List<KnownColor> list = new List<KnownColor>(); |
|
133 // |
|
134 list.Add( KnownColor.Black ); |
|
135 list.Add( KnownColor.LightGray ); |
|
136 list.Add( KnownColor.White ); |
|
137 list.Add( KnownColor.Gray ); |
|
138 list.Add( KnownColor.GrayText ); |
|
139 list.Add( KnownColor.DarkGray ); |
|
140 list.Add( KnownColor.DimGray ); |
|
141 list.Add( KnownColor.Azure ); |
|
142 list.Add( KnownColor.Silver ); |
|
143 list.Add( KnownColor.GhostWhite ); |
|
144 list.Add( KnownColor.DarkKhaki ); |
|
145 list.Add( KnownColor.DarkOliveGreen ); |
|
146 list.Add( KnownColor.NavajoWhite ); |
|
147 list.Add( KnownColor.Ivory ); |
|
148 list.Add( KnownColor.Cornsilk ); |
|
149 list.Add( KnownColor.Honeydew ); |
|
150 list.Add( KnownColor.AliceBlue ); |
|
151 list.Add( KnownColor.Gainsboro ); |
|
152 list.Add( KnownColor.Beige ); |
|
153 list.Add( KnownColor.Lavender ); |
|
154 list.Add( KnownColor.FloralWhite ); |
|
155 // |
|
156 list.Add( KnownColor.Desktop ); |
|
157 list.Add( KnownColor.AppWorkspace ); |
|
158 list.Add( KnownColor.Transparent ); |
|
159 list.Add( KnownColor.Bisque ); |
|
160 list.Add( KnownColor.Control ); |
|
161 list.Add( KnownColor.ControlText ); |
|
162 list.Add( KnownColor.ControlDark ); |
|
163 list.Add( KnownColor.ControlDarkDark ); |
|
164 list.Add( KnownColor.ControlLight ); |
|
165 list.Add( KnownColor.ControlLightLight ); |
|
166 list.Add( KnownColor.ButtonFace ); |
|
167 list.Add( KnownColor.ButtonHighlight ); |
|
168 list.Add( KnownColor.ButtonShadow ); |
|
169 list.Add( KnownColor.GradientActiveCaption ); |
|
170 list.Add( KnownColor.GradientInactiveCaption ); |
|
171 list.Add( KnownColor.HotTrack ); |
|
172 list.Add( KnownColor.Menu ); |
|
173 list.Add( KnownColor.MenuBar ); |
|
174 list.Add( KnownColor.MenuHighlight ); |
|
175 list.Add( KnownColor.MenuText ); |
|
176 list.Add( KnownColor.ActiveBorder ); |
|
177 list.Add( KnownColor.ActiveCaption ); |
|
178 list.Add( KnownColor.ActiveCaptionText ); |
|
179 list.Add( KnownColor.InactiveBorder ); |
|
180 list.Add( KnownColor.InactiveCaption ); |
|
181 list.Add( KnownColor.InactiveCaptionText ); |
|
182 list.Add( KnownColor.Highlight ); |
|
183 list.Add( KnownColor.HighlightText ); |
|
184 list.Add( KnownColor.BlanchedAlmond ); |
|
185 list.Add( KnownColor.Info ); |
|
186 list.Add( KnownColor.InfoText ); |
|
187 list.Add( KnownColor.Window ); |
|
188 list.Add( KnownColor.WindowText ); |
|
189 list.Add( KnownColor.WindowFrame ); |
|
190 list.Add( KnownColor.ScrollBar ); |
|
191 list.Add( KnownColor.LightBlue ); |
|
192 // |
|
193 return list; |
|
194 } |
|
195 #endregion |
|
196 |
|
197 #region Properties |
|
198 public List<KnownColor> StandardColors |
|
199 { |
|
200 get { return iStandardColors; } |
|
201 } |
|
202 |
|
203 public List<KnownColor> BannedColors |
|
204 { |
|
205 get { return iBannedColors; } |
|
206 } |
|
207 #endregion |
|
208 |
|
209 #region Data members |
|
210 private readonly List<KnownColor> iStandardColors; |
|
211 private readonly List<KnownColor> iBannedColors; |
|
212 #endregion |
|
213 } |
|
214 } |