private void ColorType_SelectionChanged(object sender, RoutedEventArgs e) { try { string selectedType; if (cboBrushColorType.SelectedItem != null) { selectedType = cboBrushColorType.SelectedItem.ToString().Replace(' ', '_'); _brushColorType = (RandColorType)Enum.Parse(typeof(RandColorType), selectedType); } if (cboRandColorType.SelectedItem != null) // this was null when setting selected item of cboBrushColorType in the constructor { selectedType = cboRandColorType.SelectedItem.ToString().Replace(' ', '_'); _randColorType = (RandColorType)Enum.Parse(typeof(RandColorType), selectedType); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error); } }
private Color GetRandomColor(Random rand, RandColorType colorType) { int drift = 0; Color[] colors = null; bool useMap = true; switch (colorType) { case RandColorType.Any: colors = new Color[] { Color.FromRgb(128, 128, 128) }; drift = 128; useMap = false; break; case RandColorType.Black_Green: drift = 15; break; case RandColorType.Black_Orange: drift = 6; break; case RandColorType.Black_Purple: drift = 10; break; case RandColorType.Red_Tan_Green: drift = 5; break; case RandColorType.Tans: drift = 4; break; case RandColorType.Skittles: drift = 2; break; case RandColorType.Unispew: drift = 2; break; case RandColorType.Camo: drift = 5; break; case RandColorType.Cold_Beach: drift = 7; break; case RandColorType.Mono_Cyan: drift = 0; break; default: throw new ApplicationException("Unknown RandColorType: " + colorType.ToString()); } if (useMap) { colors = _randColors[colorType]; } Color retVal = colors[rand.Next(colors.Length)]; if (drift > 0) { retVal = DriftColor(rand, retVal, drift); } return retVal; }
private Color GetRandomColor(Random rand, RandColorType colorType) { int drift = 0; Color[] colors = null; bool useMap = true; switch (colorType) { case RandColorType.Any: colors = new Color[] { Color.FromRgb(128, 128, 128) }; drift = 128; useMap = false; break; case RandColorType.Black_Green: drift = 15; break; case RandColorType.Black_Orange: drift = 6; break; case RandColorType.Black_Purple: drift = 10; break; case RandColorType.Red_Tan_Green: drift = 5; break; case RandColorType.Tans: drift = 4; break; case RandColorType.Skittles: drift = 2; break; case RandColorType.Unispew: drift = 2; break; case RandColorType.Camo: drift = 5; break; case RandColorType.Cold_Beach: drift = 7; break; case RandColorType.Mono_Cyan: drift = 0; break; default: throw new ApplicationException("Unknown RandColorType: " + colorType.ToString()); } if (useMap) { colors = _randColors[colorType]; } Color retVal = colors[rand.Next(colors.Length)]; if (drift > 0) { retVal = DriftColor(rand, retVal, drift); } return(retVal); }