public Form1() { m_AppKey = Registry.CurrentUser.CreateSubKey( @"Software\GodComplex\StandardizedDiffuseAlbedoMaps" ); m_ApplicationPath = System.IO.Path.GetDirectoryName( Application.ExecutablePath ); InitializeComponent(); // Initialize color swatches m_SwatchMin = new Swatch() { m_Owner = this, m_Panel = panelSwatchMin }; m_SwatchMax = new Swatch() { m_Owner = this, m_Panel = panelSwatchMax }; m_SwatchAvg = new Swatch() { m_Owner = this, m_Panel = panelSwatchAverage }; m_CustomSwatches[0] = new CustomSwatch() { m_Owner = this, m_CheckBox = checkBoxCustomSwatch0, m_Panel = panelCustomSwatch0 }; m_CustomSwatches[1] = new CustomSwatch() { m_Owner = this, m_CheckBox = checkBoxCustomSwatch1, m_Panel = panelCustomSwatch1 }; m_CustomSwatches[2] = new CustomSwatch() { m_Owner = this, m_CheckBox = checkBoxCustomSwatch2, m_Panel = panelCustomSwatch2 }; m_CustomSwatches[3] = new CustomSwatch() { m_Owner = this, m_CheckBox = checkBoxCustomSwatch3, m_Panel = panelCustomSwatch3 }; m_CustomSwatches[4] = new CustomSwatch() { m_Owner = this, m_CheckBox = checkBoxCustomSwatch4, m_Panel = panelCustomSwatch4 }; m_CustomSwatches[5] = new CustomSwatch() { m_Owner = this, m_CheckBox = checkBoxCustomSwatch5, m_Panel = panelCustomSwatch5 }; m_CustomSwatches[6] = new CustomSwatch() { m_Owner = this, m_CheckBox = checkBoxCustomSwatch6, m_Panel = panelCustomSwatch6 }; m_CustomSwatches[7] = new CustomSwatch() { m_Owner = this, m_CheckBox = checkBoxCustomSwatch7, m_Panel = panelCustomSwatch7 }; m_CustomSwatches[8] = new CustomSwatch() { m_Owner = this, m_CheckBox = checkBoxCustomSwatch8, m_Panel = panelCustomSwatch8 }; }
private Palette(List<Swatch> swatches) { mSwatches = swatches; mHighestPopulation = findMaxPopulation(); Int32 index = 0; float movement = 0.1f; do { float minMovement = -(index * movement); float targetMovement = index * movement; float maxMovement = index * movement; if (mVibrantSwatch == null) { mVibrantSwatch = findColor(TARGET_NORMAL_LUMA + targetMovement, MIN_NORMAL_LUMA + minMovement, MAX_NORMAL_LUMA + maxMovement, TARGET_VIBRANT_SATURATION + targetMovement, MIN_VIBRANT_SATURATION + minMovement, 1f + maxMovement); } if (mLightVibrantSwatch == null) { mLightVibrantSwatch = findColor(TARGET_LIGHT_LUMA + targetMovement, MIN_LIGHT_LUMA + minMovement, 1f + maxMovement, TARGET_VIBRANT_SATURATION + targetMovement, MIN_VIBRANT_SATURATION + minMovement, 1f + maxMovement); } if (mDarkVibrantSwatch == null) { mDarkVibrantSwatch = findColor(TARGET_DARK_LUMA + targetMovement, 0f + minMovement, MAX_DARK_LUMA + maxMovement, TARGET_VIBRANT_SATURATION + targetMovement, MIN_VIBRANT_SATURATION + minMovement, 1f + maxMovement); } if (mMutedSwatch == null) { mMutedSwatch = findColor(TARGET_NORMAL_LUMA + targetMovement, MIN_NORMAL_LUMA + minMovement, MAX_NORMAL_LUMA + maxMovement, TARGET_MUTED_SATURATION + targetMovement, 0f + minMovement, MAX_MUTED_SATURATION + maxMovement); } if (mLightMutedColor == null) { mLightMutedColor = findColor(TARGET_LIGHT_LUMA + targetMovement, MIN_LIGHT_LUMA + minMovement, 1f + maxMovement, TARGET_MUTED_SATURATION + targetMovement, 0f + minMovement, MAX_MUTED_SATURATION + maxMovement); } if (mDarkMutedSwatch == null) { mDarkMutedSwatch = findColor(TARGET_DARK_LUMA + targetMovement, 0f + minMovement, MAX_DARK_LUMA + maxMovement, TARGET_MUTED_SATURATION + targetMovement, 0f + minMovement, MAX_MUTED_SATURATION + maxMovement); } index++; } while (generateEmptySwatches() && index <= 5); }
public void ReplacePrimaryColor(Swatch swatch) { if (swatch == null) { throw new ArgumentNullException(nameof(swatch)); } var list = swatch.PrimaryHues.ToList(); var light = list[2]; var mid = swatch.ExemplarHue; var dark = list[7]; foreach (var color in swatch.PrimaryHues) { ReplaceEntry(color.Name, color.Color); ReplaceEntry(color.Name + "Foreground", color.Foreground); } ReplaceEntry("PrimaryHueLightBrush", new SolidColorBrush(light.Color)); ReplaceEntry("PrimaryHueLightForegroundBrush", new SolidColorBrush(light.Foreground)); ReplaceEntry("PrimaryHueMidBrush", new SolidColorBrush(mid.Color)); ReplaceEntry("PrimaryHueMidForegroundBrush", new SolidColorBrush(mid.Foreground)); ReplaceEntry("PrimaryHueDarkBrush", new SolidColorBrush(dark.Color)); ReplaceEntry("PrimaryHueDarkForegroundBrush", new SolidColorBrush(dark.Foreground)); //mahapps brushes ReplaceEntry("HighlightBrush", new SolidColorBrush(dark.Color)); ReplaceEntry("AccentColorBrush", new SolidColorBrush(list[5].Color)); ReplaceEntry("AccentColorBrush2", new SolidColorBrush(list[4].Color)); ReplaceEntry("AccentColorBrush3", new SolidColorBrush(list[3].Color)); ReplaceEntry("AccentColorBrush4", new SolidColorBrush(list[2].Color)); ReplaceEntry("WindowTitleColorBrush", new SolidColorBrush(dark.Color)); ReplaceEntry("AccentSelectedColorBrush", new SolidColorBrush(list[5].Foreground)); ReplaceEntry("ProgressBrush", new LinearGradientBrush(dark.Color, list[3].Color, 90.0)); ReplaceEntry("CheckmarkFill", new SolidColorBrush(list[5].Color)); ReplaceEntry("RightArrowFill", new SolidColorBrush(list[5].Color)); ReplaceEntry("IdealForegroundColorBrush", new SolidColorBrush(list[5].Foreground)); ReplaceEntry("IdealForegroundDisabledBrush", new SolidColorBrush(dark.Color) { Opacity = .4 }); }
public virtual void ReplaceAccentColor(Swatch swatch) { if (swatch == null) { throw new ArgumentNullException(nameof(swatch)); } var palette = QueryPalette(); foreach (var color in swatch.AccentHues) { ReplaceEntry(color.Name, color.Color); ReplaceEntry(color.Name + "Foreground", color.Foreground); } var hue = swatch.AccentHues.ElementAt(palette.AccentHueIndex); ReplaceEntry("SecondaryAccentBrush", new SolidColorBrush(hue.Color)); ReplaceEntry("SecondaryAccentForegroundBrush", new SolidColorBrush(hue.Foreground)); }
public Swatch Load(Stream stream) { using (var reader = new StreamReader(stream)) { var line = reader.ReadLine(); var swatch = new Swatch(); while (line != null) { var color = ColorHelper.ParseColor(line); if (color != null) { swatch.Colors.Add(new RgbColor(color.Value.R, color.Value.G, color.Value.B)); } line = reader.ReadLine(); } return(swatch); } }
public Swatch Load(Stream stream) { using (var reader = new BinaryReader(stream)) { if (Encoding.ASCII.GetString(reader.ReadBytes(4)) != "RIFF" || Encoding.ASCII.GetString(reader.ReadBytes(8), 4, 4) != "PAL ") { throw new Exception("Invalid File Format."); } var swatch = new Swatch(); var chunk = reader.ReadBytes(8); while (chunk != null && chunk.Length == 8) { var chunkSize = BitConverter.ToInt32(chunk, 4); if (Encoding.ASCII.GetString(chunk, 0, 4) == "data") { var buffer = reader.ReadBytes(chunkSize); if (buffer.Length != chunkSize) { throw new InvalidDataException("Failed to read enough data to match chunk size."); } ReadColors(buffer, swatch); break; } else { if (chunkSize % 2 != 0) { chunkSize++; } stream.Seek(chunkSize, SeekOrigin.Current); } chunk = reader.ReadBytes(8); } return(swatch); } }
public Palette GetPalette() { if (PrimaryLightHue == null) { throw new InvalidOperationException($"{nameof(PrimaryLightHue)} is required"); } if (PrimaryMidHue == null) { throw new InvalidOperationException($"{nameof(PrimaryMidHue)} is required"); } if (PrimaryDarkHue == null) { throw new InvalidOperationException($"{nameof(PrimaryDarkHue)} is required"); } if (SecondaryAccentHue == null) { throw new InvalidOperationException($"{nameof(SecondaryAccentHue)} is required"); } var swatch = new Swatch("CustomSwatch", new[] { PrimaryLightHue, PrimaryMidHue, PrimaryDarkHue }, new[] { SecondaryAccentHue }); return(new Palette(swatch, swatch, 0, 1, 2, 0)); }
public void ReplaceAccentColor(Swatch swatch) { if (swatch == null) { throw new ArgumentNullException(nameof(swatch)); } ResourceDictionary oldColorResourceDictionary; if (!TryFindSwatchDictionary(Application.Current.Resources, "SecondaryAccentBrush", out oldColorResourceDictionary)) { throw new ApplicationException("Unable to find accent color definition in Application resources."); } var newColorResourceDictionary = new ResourceDictionary { { "SecondaryAccentBrush", new SolidColorBrush(swatch.AccentExemplarHue.Color) }, { "SecondaryAccentForegroundBrush", new SolidColorBrush(swatch.AccentExemplarHue.Foreground) }, }; Application.Current.Resources.MergedDictionaries.Remove(oldColorResourceDictionary); Application.Current.Resources.MergedDictionaries.Add(newColorResourceDictionary); }
private void Load(XmlDocument dom, Swatch swatch) { if (dom.DocumentElement?.Name != "banlan_swatch") { throw new Exception("Invalid File Format."); } ReadColors(swatch.Colors, dom.DocumentElement.SelectSingleNode("colors") as XmlElement); if (dom.DocumentElement.SelectSingleNode("categories") is XmlElement categoriesNode) { foreach (var categoryNode in categoriesNode.SelectNodes("category").OfType <XmlElement>()) { var category = new Category { Name = categoryNode.GetAttribute("name"), IsOpen = StringHelper.GetBool(categoryNode.GetAttribute("isOpen"), true) }; ReadColors(category.Colors, categoryNode.SelectSingleNode("colors") as XmlElement); swatch.Categories.Add(category); } } }
private void LoadFile(string file) { var selectedFile = new FileInfo(file); if (selectedFile != null) { if (selectedFile.Extension == ".ase") { _loadedPalette = Swatch.ReadExchangeFile(selectedFile.FullName); } else { _loadedPalette = Swatch.ReadSwatchFile(selectedFile.FullName); } Text = string.Format("{0} - {1}", Path.GetFileName(selectedFile.FullName), Application.ProductName); } else { _loadedPalette = null; Text = Application.ProductName; } }
public void AddSwatch(LibraryViewModel libraryViewModel) { Logger.Log.Debug("Adding"); Color color = MainViewModel.WindowManager.LibraryManagementViewModel.NewSwatch; if (libraryViewModel.Swatches.Where(s => s.Color == color).Any()) { Logger.Log.Debug("Swatch Already Exists"); return; } var swatch = new Swatch(color); var swatchViewModel = new SwatchViewModel(MainViewModel, swatch); libraryViewModel.Library.Swatches.Add(swatch); libraryViewModel.Swatches.Add(swatchViewModel); libraryViewModel.IsDirty = true; Logger.Log.DebugFormat("Added Color[{0}]", swatchViewModel.Color); }
public Swatch MakeSwatch(Color color) { if (color == null) { return(null); } if (Option == null || OptionsContainer == null) { this.Init(); } GameObject obj = GameObject.Instantiate(Option, OptionsContainer); obj.SetActive(true); Swatch swatch = obj.AddComponent <Swatch>(); swatch.color = color; obj.transform.SetSiblingIndex(OptionsContainer.childCount - 2); Swatches.Add(swatch); return(swatch); }
//TOGGLEPRIMARYCOLOUR METHOD (PRIMARY COLOUR: RED, GREEN ETC) public static void TogglePrimaryColour(string color) { //UPDATE THE COLOR STRING TO LOWERCASE color = color.ToLower(); //GET THE THEME ITheme theme = paletteHelper.GetTheme(); //GET THE SWATCHES PROVIDER (FOR COLOURS) SwatchesProvider swatchesProvider = new SwatchesProvider(); //CREATE A SWATCH WHERE THE SELECTED COLOR MATCHES THE COLOR IN THE LIST Swatch swatch = swatchesProvider.Swatches.Where(_ => _.Name.Equals(color)).First(); //IF THE SWATCH LIST CONTAINS THE SELECTED SWATCH if (swatchesProvider.Swatches.Contains(swatch)) { //SET THE PRIMARY COLOUR OF THE THEME theme.SetPrimaryColor(swatch.ExemplarHue.Color); } //UPDATE THE THEME (REALTIME) paletteHelper.SetTheme(theme); }
public Swatch Load(Stream stream) { using (var reader = new StreamReader(stream)) { if (reader.ReadLine() != "GIMP Palette") { throw new Exception("Invalid File Format."); } var swatch = new Swatch(); var name = reader.ReadLine(); if (name.StartsWith("Name:")) { swatch.Name = name.Substring(5, name.Length - 5).Trim(); } while (reader.ReadLine() != "#") { } var line = reader.ReadLine(); while (line != null) { if (ColorLineRegex.Match(line) is Match match && match.Success) { swatch.Colors.Add(new RgbColor(Convert.ToByte(match.Groups[1].Value), Convert.ToByte(match.Groups[2].Value), Convert.ToByte(match.Groups[3].Value)) { Name = match.Groups[4].Value }); } line = reader.ReadLine(); } return(swatch); } }
//Create A Button private Button CreateButton(Swatch swatch) { Button ChangeButton = new Button(); ChangeButton.Margin = new Thickness(15, 0, 15, 0); ChangeButton.Tag = swatch.Name; //Create a stackpanel inside button StackPanel content = new StackPanel(); content.Orientation = Orientation.Horizontal; ChangeButton.Content = content; //Add an icon to button's content PackIcon icon = CreateIcon(); content.Children.Add(icon); //Add text to button's content TextBlock text = new TextBlock(); text.Text = " Apply"; content.Children.Add(text); //Set the color of the button from hue in swatch Hue hue = swatch.PrimaryHues.ElementAt(7); SolidColorBrush brush = new SolidColorBrush(swatch.PrimaryHues.ElementAt(7).Color); //Selects seventh hue in selected swatch ChangeButton.Foreground = new SolidColorBrush(Colors.White); //Sets icon and text color to white in all situations ChangeButton.Background = brush; ChangeButton.BorderBrush = brush; ChangeButton.Click += ChangeButton_Click; return(ChangeButton); }
private static void ApplyPrimary(Swatch swatch) { new PaletteHelper().ReplacePrimaryColor(swatch); }
public void Load( FileInfo _FileName ) { m_ManifestFileName = _FileName; XmlDocument Doc = new XmlDocument(); Doc.Load( _FileName.FullName ); XmlElement Root = Doc["Manifest"]; if ( Root == null ) throw new Exception( "Failed to retrieve the root \"Manifest\" node. Is this a manifest file?" ); // Load source image infos XmlElement SourceInfosElement = Root["SourceInfos"]; if ( SourceInfosElement == null ) throw new Exception( "Failed to retrieve the \"SourceInfos\" element!" ); m_SourceImageFileName = SourceInfosElement["SourceImageName"].GetAttribute( "Value" ); m_ISOSpeed = float.Parse( SourceInfosElement["ISOSpeed"].GetAttribute( "Value" ) ); m_ShutterSpeed = float.Parse( SourceInfosElement["ShutterSpeed"].GetAttribute( "Value" ) ); m_Aperture = float.Parse( SourceInfosElement["Aperture"].GetAttribute( "Value" ) ); m_SpatialCorrectionEnabled = SourceInfosElement["SpatialCorrection"].GetAttribute( "Status" ) == "Enabled"; m_WhiteBalanceCorrectionFactor = float.Parse( SourceInfosElement["WhiteReflectanceCorrectionFactor"].GetAttribute( "Value" ) ); if ( SourceInfosElement["WhiteBalance"] != null ) m_WhiteBalancexyY = Vector.Parse( SourceInfosElement["WhiteBalance"].GetAttribute( "xyY" ) ); m_SwatchesWidth = int.Parse( SourceInfosElement["SwatchesSize"].GetAttribute( "Width" ) ); m_SwatchesHeight = int.Parse( SourceInfosElement["SwatchesSize"].GetAttribute( "Height" ) ); m_TargetFormat = SourceInfosElement["TargetFormat"].GetAttribute( "Value" ); // Load calibrated texture infos XmlElement CalibratedTextureElement = Root["CalibratedTexture"]; if ( CalibratedTextureElement == null ) throw new Exception( "Failed to retrieve the \"CalibratedTexture\" element!" ); m_CalibratedTextureFileName = CalibratedTextureElement.GetAttribute( "Name" ); m_CalibratedTextureWidth = int.Parse( CalibratedTextureElement.GetAttribute( "Width" ) ); m_CalibratedTextureHeight = int.Parse( CalibratedTextureElement.GetAttribute( "Height" ) ); XmlElement DefaultSwatchesElement = CalibratedTextureElement["DefaultSwatches"]; m_SwatchMin.Load( DefaultSwatchesElement["Min"] ); m_SwatchMax.Load( DefaultSwatchesElement["Max"] ); m_SwatchAvg.Load( DefaultSwatchesElement["Avg"] ); // Load custom swatches XmlElement CustomSwatchesElement = Root["CustomSwatches"]; if ( CustomSwatchesElement != null ) { int CustomSwatchesCount = int.Parse( CustomSwatchesElement.GetAttribute( "Count" ) ); m_CustomSwatches = new Swatch[CustomSwatchesCount]; for ( int CustomSwatchIndex=0; CustomSwatchIndex < CustomSwatchesCount; CustomSwatchIndex++ ) { m_CustomSwatches[CustomSwatchIndex] = new Swatch(); XmlElement CustomSwatchElement = CustomSwatchesElement["Custom" + CustomSwatchIndex]; if ( CustomSwatchElement == null ) throw new Exception( "Failed to retrieve custom swatch element!" ); m_CustomSwatches[CustomSwatchIndex].Load( CustomSwatchElement ); } } }
private static void ApplyPrimary(Swatch swatch) { ModifyTheme(theme => theme.SetPrimaryColor(swatch.ExemplarHue.Color)); }
private static void ApplyPrimary(Swatch swatch) { new PaletteHelper().ReplacePrimaryColor(swatch); Settings.Same().AppPalettePrimaryName = swatch.Name; ApplyPrimaryChanged?.Invoke(); }
/** * Copy a {@link Swatch}'s HSL values into a new float[]. */ private static float[] copyHslValues(Swatch color) { float[] newHsl = new float[3]; Array.Copy(color.getHsl(), 0, newHsl, 0, 3); return newHsl; }
private static void ApplyPrimary(Swatch swatch) { new PaletteHelper().ReplacePrimaryColor(swatch); SaveSettings.Default.Primary = swatch.Name; }
public ColorItem(System.Windows.Media.SolidColorBrush color, Swatch swatch, string name) { Color = color; Swatch = swatch; Name = name; }
void ShowSwatchArray(Rect position, List <Swatch> swatches, bool isAlpha) { int id = GUIUtility.GetControlID(652347689, FocusType.Passive); Event evt = Event.current; float mouseSwatchTime = GetTime((Event.current.mousePosition.x - position.x) / position.width); Vector2 fixedStepMousePosition = new Vector3(position.x + mouseSwatchTime * position.width, Event.current.mousePosition.y); switch (evt.GetTypeForControl(id)) { case EventType.Repaint: { bool hasSelection = false; foreach (Swatch s in swatches) { if (m_SelectedSwatch == s) { hasSelection = true; continue; } DrawSwatch(position, s, !isAlpha); } // selected swatch drawn last if (hasSelection && m_SelectedSwatch != null) { DrawSwatch(position, m_SelectedSwatch, !isAlpha); } break; } case EventType.MouseDown: { Rect clickRect = position; // Swatches have some thickness thus we enlarge the clickable area clickRect.xMin -= 10; clickRect.xMax += 10; if (clickRect.Contains(evt.mousePosition)) { GUIUtility.hotControl = id; evt.Use(); // Make sure selected is topmost for the click if (swatches.Contains(m_SelectedSwatch) && !m_SelectedSwatch.m_IsAlpha && CalcSwatchRect(position, m_SelectedSwatch).Contains(evt.mousePosition)) { if (evt.clickCount == 2) { //Storing the double click state to open the color picker on Mouse up event so that the user has completed his interaction with swatch movement/drag. m_DoubleClickDetected = true; } break; } bool found = false; foreach (Swatch s in swatches) { if (CalcSwatchRect(position, s).Contains(fixedStepMousePosition)) { found = true; m_SelectedSwatch = s; EditorGUI.EndEditingActiveTextField(); break; } } if (!found) { if (swatches.Count < k_MaxNumKeys) { Color currentColor = m_Gradient.Evaluate(mouseSwatchTime); if (isAlpha) { currentColor = new Color(currentColor.a, currentColor.a, currentColor.a, 1f); } else { currentColor.a = 1f; } m_SelectedSwatch = new Swatch(mouseSwatchTime, currentColor, isAlpha); swatches.Add(m_SelectedSwatch); AssignBack(); } else { Debug.LogWarning("Max " + k_MaxNumKeys + " color keys and " + k_MaxNumKeys + " alpha keys are allowed in a gradient."); } } } break; } case EventType.MouseDrag: if (GUIUtility.hotControl == id && m_SelectedSwatch != null) { evt.Use(); // If user drags swatch outside in vertical direction, we'll remove the swatch if ((evt.mousePosition.y + 5 < position.y || evt.mousePosition.y - 5 > position.yMax)) { if (swatches.Count > 1) { swatches.Remove(m_SelectedSwatch); AssignBack(); break; } } else if (!swatches.Contains(m_SelectedSwatch)) { swatches.Add(m_SelectedSwatch); } m_SelectedSwatch.m_Time = mouseSwatchTime; AssignBack(); } break; case EventType.MouseUp: if (GUIUtility.hotControl == id) { GUIUtility.hotControl = 0; evt.Use(); // If the dragged swatch is NOT in the timeline, it means it was dragged outside. // We just forget about it and let GC get it later. if (!swatches.Contains(m_SelectedSwatch)) { m_SelectedSwatch = null; } // Remove duplicate keys on mouse up so that we do not kill any keys during the drag RemoveDuplicateOverlappingSwatches(); } else if (m_DoubleClickDetected) { m_DoubleClickDetected = false; GUIUtility.keyboardControl = id; ColorPicker.Show(GUIView.current, m_SelectedSwatch.m_Value, false, m_HDR); GUIUtility.ExitGUI(); } break; case EventType.KeyDown: if (evt.keyCode == KeyCode.Delete) { if (m_SelectedSwatch != null) { List <Swatch> listToDeleteFrom; if (m_SelectedSwatch.m_IsAlpha) { listToDeleteFrom = m_AlphaSwatches; } else { listToDeleteFrom = m_RGBSwatches; } if (listToDeleteFrom.Count > 1) { listToDeleteFrom.Remove(m_SelectedSwatch); AssignBack(); HandleUtility.Repaint(); } } evt.Use(); } break; case EventType.ValidateCommand: if (evt.commandName == EventCommandNames.Delete) { Event.current.Use(); } break; case EventType.ExecuteCommand: if (evt.commandName == EventCommandNames.ColorPickerChanged) { GUI.changed = true; m_SelectedSwatch.m_Value = ColorPicker.color; AssignBack(); HandleUtility.Repaint(); } else if (evt.commandName == EventCommandNames.Delete) { if (swatches.Count > 1) { swatches.Remove(m_SelectedSwatch); AssignBack(); HandleUtility.Repaint(); } } break; } }
private static void ApplyAccent(Swatch swatch) { new PaletteHelper().ReplaceAccentColor(swatch); }
public static void Apply(this PaletteHelper self, string swatchName, bool dark) { Swatch swatch = self.GetSwatch(swatchName); self.Apply(swatch, dark); }
private void ShowSwatchArray(Rect position, List<Swatch> swatches, bool isAlpha) { bool flag2; int controlID = GUIUtility.GetControlID(0x26e20929, FocusType.Passive); Event current = Event.current; float time = this.GetTime((Event.current.mousePosition.x - position.x) / position.width); Vector2 point = new Vector3(position.x + (time * position.width), Event.current.mousePosition.y); EventType typeForControl = current.GetTypeForControl(controlID); switch (typeForControl) { case EventType.MouseDown: { Rect rect = position; rect.xMin -= 10f; rect.xMax += 10f; if (rect.Contains(current.mousePosition)) { GUIUtility.hotControl = controlID; current.Use(); if ((!swatches.Contains(this.m_SelectedSwatch) || this.m_SelectedSwatch.m_IsAlpha) || !this.CalcSwatchRect(position, this.m_SelectedSwatch).Contains(current.mousePosition)) { flag2 = false; foreach (Swatch swatch2 in swatches) { if (this.CalcSwatchRect(position, swatch2).Contains(point)) { flag2 = true; this.m_SelectedSwatch = swatch2; break; } } break; } if (current.clickCount == 2) { GUIUtility.keyboardControl = controlID; ColorPicker.Show(GUIView.current, this.m_SelectedSwatch.m_Value, false, false, null); GUIUtility.ExitGUI(); } } return; } case EventType.MouseUp: if (GUIUtility.hotControl == controlID) { GUIUtility.hotControl = 0; current.Use(); if (!swatches.Contains(this.m_SelectedSwatch)) { this.m_SelectedSwatch = null; } this.RemoveDuplicateOverlappingSwatches(); } return; case EventType.MouseDrag: if ((GUIUtility.hotControl == controlID) && (this.m_SelectedSwatch != null)) { current.Use(); if (((current.mousePosition.y + 5f) >= position.y) && ((current.mousePosition.y - 5f) <= position.yMax)) { if (!swatches.Contains(this.m_SelectedSwatch)) { swatches.Add(this.m_SelectedSwatch); } } else if (swatches.Count > 1) { swatches.Remove(this.m_SelectedSwatch); this.AssignBack(); return; } this.m_SelectedSwatch.m_Time = time; this.AssignBack(); } return; case EventType.KeyDown: if (current.keyCode == KeyCode.Delete) { if (this.m_SelectedSwatch != null) { List<Swatch> rGBSwatches; if (!this.m_SelectedSwatch.m_IsAlpha) { rGBSwatches = this.m_RGBSwatches; } else { rGBSwatches = this.m_AlphaSwatches; } if (rGBSwatches.Count > 1) { rGBSwatches.Remove(this.m_SelectedSwatch); this.AssignBack(); HandleUtility.Repaint(); } } current.Use(); } return; case EventType.Repaint: { bool flag = false; foreach (Swatch swatch in swatches) { if (this.m_SelectedSwatch == swatch) { flag = true; } else { this.DrawSwatch(position, swatch, !isAlpha); } } if (flag && (this.m_SelectedSwatch != null)) { this.DrawSwatch(position, this.m_SelectedSwatch, !isAlpha); } return; } default: switch (typeForControl) { case EventType.ValidateCommand: if (current.commandName == "Delete") { Event.current.Use(); } return; case EventType.ExecuteCommand: if (current.commandName == "ColorPickerChanged") { GUI.changed = true; this.m_SelectedSwatch.m_Value = ColorPicker.color; this.AssignBack(); HandleUtility.Repaint(); } else if ((current.commandName == "Delete") && (swatches.Count > 1)) { swatches.Remove(this.m_SelectedSwatch); this.AssignBack(); HandleUtility.Repaint(); } return; default: return; } break; } if (!flag2) { if (swatches.Count < 8) { Color color = this.m_Gradient.Evaluate(time); if (isAlpha) { color = new Color(color.a, color.a, color.a, 1f); } else { color.a = 1f; } this.m_SelectedSwatch = new Swatch(time, color, isAlpha); swatches.Add(this.m_SelectedSwatch); this.AssignBack(); } else { Debug.LogWarning(string.Concat(new object[] { "Max ", 8, " color keys and ", 8, " alpha keys are allowed in a gradient." })); } } }
private int SwatchSort(Swatch lhs, Swatch rhs) { if ((lhs.m_Time == rhs.m_Time) && (lhs == this.m_SelectedSwatch)) { return -1; } if ((lhs.m_Time == rhs.m_Time) && (rhs == this.m_SelectedSwatch)) { return 1; } return lhs.m_Time.CompareTo(rhs.m_Time); }
/** * Try and generate any missing swatches from the swatches we did find. */ private Boolean generateEmptySwatches() { if (mVibrantSwatch == null) { if (mDarkVibrantSwatch != null) { float[] newHsl = copyHslValues(mDarkVibrantSwatch); newHsl[2] = TARGET_NORMAL_LUMA; mVibrantSwatch = new Swatch(ColorUtils.HSLtoRGB(newHsl), 0); } else if (mLightVibrantSwatch != null) { float[] newHsl = copyHslValues(mLightVibrantSwatch); newHsl[2] = TARGET_NORMAL_LUMA; mVibrantSwatch = new Swatch(ColorUtils.HSLtoRGB(newHsl), 0); } } if (mDarkVibrantSwatch == null) { if (mVibrantSwatch != null) { float[] newHsl = copyHslValues(mVibrantSwatch); newHsl[2] = TARGET_DARK_LUMA; mDarkVibrantSwatch = new Swatch(ColorUtils.HSLtoRGB(newHsl), 0); } else if (mLightVibrantSwatch != null) { float[] newHsl = copyHslValues(mLightVibrantSwatch); newHsl[2] = TARGET_DARK_LUMA; mDarkVibrantSwatch = new Swatch(ColorUtils.HSLtoRGB(newHsl), 0); } } if (mLightVibrantSwatch == null) { if (mVibrantSwatch != null) { float[] newHsl = copyHslValues(mVibrantSwatch); newHsl[2] = TARGET_LIGHT_LUMA; mLightVibrantSwatch = new Swatch(ColorUtils.HSLtoRGB(newHsl), 0); } else if (mDarkVibrantSwatch != null) { float[] newHsl = copyHslValues(mDarkVibrantSwatch); newHsl[2] = TARGET_LIGHT_LUMA; mLightVibrantSwatch = new Swatch(ColorUtils.HSLtoRGB(newHsl), 0); } } if (mMutedSwatch == null) { if (mDarkMutedSwatch != null) { float[] newHsl = copyHslValues(mDarkMutedSwatch); newHsl[2] = TARGET_NORMAL_LUMA; mMutedSwatch = new Swatch(ColorUtils.HSLtoRGB(newHsl), 0); } else if (mLightMutedColor != null) { float[] newHsl = copyHslValues(mLightMutedColor); newHsl[2] = TARGET_NORMAL_LUMA; mMutedSwatch = new Swatch(ColorUtils.HSLtoRGB(newHsl), 0); } } if (mDarkMutedSwatch == null) { if (mMutedSwatch != null) { float[] newHsl = copyHslValues(mMutedSwatch); newHsl[2] = TARGET_DARK_LUMA; mDarkMutedSwatch = new Swatch(ColorUtils.HSLtoRGB(newHsl), 0); } else if (mLightMutedColor != null) { float[] newHsl = copyHslValues(mLightMutedColor); newHsl[2] = TARGET_DARK_LUMA; mDarkMutedSwatch = new Swatch(ColorUtils.HSLtoRGB(newHsl), 0); } } if (mLightMutedColor == null) { if (mMutedSwatch != null) { float[] newHsl = copyHslValues(mMutedSwatch); newHsl[2] = TARGET_LIGHT_LUMA; mLightMutedColor = new Swatch(ColorUtils.HSLtoRGB(newHsl), 0); } else if (mDarkMutedSwatch != null) { float[] newHsl = copyHslValues(mDarkMutedSwatch); newHsl[2] = TARGET_LIGHT_LUMA; mLightMutedColor = new Swatch(ColorUtils.HSLtoRGB(newHsl), 0); } } return checkAnySwtchEmpty(); }
public void Init(Gradient gradient, int numSteps) { this.m_Gradient = gradient; this.m_NumSteps = numSteps; this.BuildArrays(); if (this.m_RGBSwatches.Count > 0) { this.m_SelectedSwatch = this.m_RGBSwatches[0]; } }
private static Boolean shouldIgnoreColor(Swatch color) { return shouldIgnoreColor(color.getHsl()); }
public bool Init() { if(!_initialized) { // these seem to return 0 sometimes if we check them too early // so we won't consider the pixel screen initialized until we can get back a non-zero value for these if(Screen.width == 0 || Screen.height == 0) return false; int screenWidth = PlayerPrefs.GetInt("screenWidth", 800); int screenHeight = PlayerPrefs.GetInt("screenHeight", 500); screenWidth = Mathf.Max(screenHeight, 300); screenHeight = Mathf.Max(screenHeight, 300); Screen.SetResolution(screenWidth, screenHeight, false); Camera camera = GetComponent<Camera>(); camera.orthographic = true; camera.orthographicSize = 1; // ---------------------------------------------- // CANVAS // ---------------------------------------------- _canvas = gameObject.AddComponent<Canvas>(); _canvas.Init(this); _lastCanvasWidth = _canvas.pixelWidth; _lastCanvasHeight = _canvas.pixelHeight; _copiedPixels = new Color32[_canvas.pixelWidth * _canvas.pixelHeight]; _canvas.GetPixels(CurrentFrame).CopyTo(_copiedPixels, 0); _pixelDimensionsString = _canvas.pixelWidth.ToString() + "," + _canvas.pixelHeight.ToString(); _hitbox = new PixelRect(0, 0, _canvas.pixelWidth, _canvas.pixelHeight); RefreshHitboxString(); // ---------------------------------------------- // SWATCH // ---------------------------------------------- _swatch = gameObject.AddComponent<Swatch>(); _swatch.Init(this); SetCurrentColor(Color.black); // ---------------------------------------------- // PALETTE // ---------------------------------------------- _palette = gameObject.AddComponent<Palette>(); _palette.Init(this); CreateEffectPlane(); // ---------------------------------------------- // FRAME PREVIEW // ---------------------------------------------- _framePreview = gameObject.AddComponent<FramePreview>(); _framePreview.Init(this); // ---------------------------------------------- // PATTERN VIEWER // ---------------------------------------------- _patternViewer = gameObject.AddComponent<PatternViewer>(); _patternViewer.Init(this); _initialized = true; _textStyle = new GUIStyle(); _textStyle.font = Resources.Load("Fonts/04b03") as Font; _textStyle.normal.textColor = new Color(0.8f, 0.8f, 0.8f); _textStyle.fontSize = 20; _textStyleRed = new GUIStyle(_textStyle); _textStyleRed.normal.textColor = new Color(0.8f, 0.2f, 0.2f); _textStyleFocused = new GUIStyle(); _textStyleFocused.font = Resources.Load("Fonts/04b03") as Font; _textStyleFocused.normal.textColor = Color.white; Texture2D black = new Texture2D(1, 1); black.SetPixel(0, 0, Color.black); black.Apply(); _textStyleFocused.normal.background = black; _textStyleFocused.fontSize = 20; _toolMode = ToolMode.Brush; // Cursor.SetCursor(cursorBrush, Vector2.zero, CursorMode.Auto); _canvas.SetOnionSkinMode((OnionSkinMode)PlayerPrefs.GetInt("onionSkinMode", 0)); _canvas.RefreshOnionSkin(); _canvas.SetMirroringMode((MirroringMode)PlayerPrefs.GetInt("mirroringMode", 0)); _consoleText = gameObject.AddComponent<GUIText>(); _consoleText.color = Color.black; _consoleText.font = Resources.Load("Fonts/04b03") as Font; _consoleText.fontSize = 12; _consoleText.transform.position = new Vector2(0.0025f, 0); _consoleText.anchor = TextAnchor.LowerLeft; _consoleTextWrap = gameObject.AddComponent<ConsoleTextSetter>(); string animData = PlayerPrefs.GetString("animData", ""); Debug.Log("animData: " + animData); if(animData != "") LoadAnimationString(animData); } return _initialized; }
private void ShowSwatchArray(Rect position, List <Swatch> swatches, bool isAlpha) { bool flag2; int controlID = GUIUtility.GetControlID(0x26e20929, FocusType.Passive); Event current = Event.current; float time = this.GetTime((Event.current.mousePosition.x - position.x) / position.width); Vector2 point = new Vector3(position.x + (time * position.width), Event.current.mousePosition.y); EventType typeForControl = current.GetTypeForControl(controlID); switch (typeForControl) { case EventType.MouseDown: { Rect rect = position; rect.xMin -= 10f; rect.xMax += 10f; if (rect.Contains(current.mousePosition)) { GUIUtility.hotControl = controlID; current.Use(); if ((!swatches.Contains(this.m_SelectedSwatch) || this.m_SelectedSwatch.m_IsAlpha) || !this.CalcSwatchRect(position, this.m_SelectedSwatch).Contains(current.mousePosition)) { flag2 = false; foreach (Swatch swatch2 in swatches) { if (this.CalcSwatchRect(position, swatch2).Contains(point)) { flag2 = true; this.m_SelectedSwatch = swatch2; break; } } break; } if (current.clickCount == 2) { GUIUtility.keyboardControl = controlID; ColorPicker.Show(GUIView.current, this.m_SelectedSwatch.m_Value, false, false, null); GUIUtility.ExitGUI(); } } return; } case EventType.MouseUp: if (GUIUtility.hotControl == controlID) { GUIUtility.hotControl = 0; current.Use(); if (!swatches.Contains(this.m_SelectedSwatch)) { this.m_SelectedSwatch = null; } this.RemoveDuplicateOverlappingSwatches(); } return; case EventType.MouseDrag: if ((GUIUtility.hotControl == controlID) && (this.m_SelectedSwatch != null)) { current.Use(); if (((current.mousePosition.y + 5f) >= position.y) && ((current.mousePosition.y - 5f) <= position.yMax)) { if (!swatches.Contains(this.m_SelectedSwatch)) { swatches.Add(this.m_SelectedSwatch); } goto Label_03B1; } if (swatches.Count <= 1) { goto Label_03B1; } swatches.Remove(this.m_SelectedSwatch); this.AssignBack(); } return; case EventType.KeyDown: if (current.keyCode == KeyCode.Delete) { if (this.m_SelectedSwatch != null) { List <Swatch> rGBSwatches; if (!this.m_SelectedSwatch.m_IsAlpha) { rGBSwatches = this.m_RGBSwatches; } else { rGBSwatches = this.m_AlphaSwatches; } if (rGBSwatches.Count > 1) { rGBSwatches.Remove(this.m_SelectedSwatch); this.AssignBack(); HandleUtility.Repaint(); } } current.Use(); } return; case EventType.Repaint: { bool flag = false; foreach (Swatch swatch in swatches) { if (this.m_SelectedSwatch == swatch) { flag = true; } else { this.DrawSwatch(position, swatch, !isAlpha); } } if (flag && (this.m_SelectedSwatch != null)) { this.DrawSwatch(position, this.m_SelectedSwatch, !isAlpha); } return; } default: switch (typeForControl) { case EventType.ValidateCommand: if (current.commandName == "Delete") { Event.current.Use(); } return; case EventType.ExecuteCommand: if (current.commandName == "ColorPickerChanged") { GUI.changed = true; this.m_SelectedSwatch.m_Value = ColorPicker.color; this.AssignBack(); HandleUtility.Repaint(); } else if ((current.commandName == "Delete") && (swatches.Count > 1)) { swatches.Remove(this.m_SelectedSwatch); this.AssignBack(); HandleUtility.Repaint(); } return; default: return; } break; } if (!flag2) { if (swatches.Count < 8) { Color color = this.m_Gradient.Evaluate(time); if (isAlpha) { color = new Color(color.a, color.a, color.a, 1f); } else { color.a = 1f; } this.m_SelectedSwatch = new Swatch(time, color, isAlpha); swatches.Add(this.m_SelectedSwatch); this.AssignBack(); } else { Debug.LogWarning(string.Concat(new object[] { "Max ", 8, " color keys and ", 8, " alpha keys are allowed in a gradient." })); } } return; Label_03B1: this.m_SelectedSwatch.m_Time = time; this.AssignBack(); }
public StatusBarLegendInfo(string name, Swatch swatch, PrimaryColour primaryColour = PrimaryColour.Primary700) : this(name, GetColour(swatch, primaryColour), GetForegroundColor(swatch, primaryColour)) { }
private static void ApplyAccent(Swatch swatch) { new PaletteHelper().ReplaceAccentColor(swatch); SaveSettings.Default.Accent = swatch.Name; }
public StatusBarLegendInfo(string name, Swatch swatch, AccentColour accentColour) : this(name, GetColour(swatch, accentColour), GetForegroundColor(swatch, accentColour)) { }
private static void ApplyAccent(Swatch swatch) { ModifyTheme(theme => theme.SetSecondaryColor(swatch.AccentExemplarHue.Color)); }
private void DrawSwatch(Rect totalPos, Swatch s, bool upwards) { Color backgroundColor = GUI.backgroundColor; Rect position = this.CalcSwatchRect(totalPos, s); GUI.backgroundColor = s.m_Value; GUIStyle style = !upwards ? s_Styles.downSwatch : s_Styles.upSwatch; GUIStyle style2 = !upwards ? s_Styles.downSwatchOverlay : s_Styles.upSwatchOverlay; style.Draw(position, false, false, this.m_SelectedSwatch == s, false); GUI.backgroundColor = backgroundColor; style2.Draw(position, false, false, this.m_SelectedSwatch == s, false); }
private static void ApplyAccent(Swatch swatch) { new PaletteHelper().ReplaceAccentColor(swatch); Settings.Same().AppPaletteAccentName = swatch.Name; ApplyAccentChanged?.Invoke(); }
public Color getDarkMainColor(Color defaultColor) { var mainSwatch = getMainSwatch(); float[] newHsl = copyHslValues(mainSwatch); newHsl[2] = TARGET_DARK_LUMA; var mainDarkSwatch = new Swatch(ColorUtils.HSLtoRGB(newHsl), 0); return mainDarkSwatch != null ? mainDarkSwatch.GetRgb() : defaultColor; }
/** * @return true if we have already selected {@code swatch} */ private Boolean isAlreadySelected(Swatch swatch) { return mVibrantSwatch == swatch || mDarkVibrantSwatch == swatch || mLightVibrantSwatch == swatch || mMutedSwatch == swatch || mDarkMutedSwatch == swatch || mLightMutedColor == swatch; }
private void ChangeTheme(Swatch swatch) { ThemeService.ApplyTheme(swatch); UserConfigurationManager.Instance.SetConfiguration(new ThemeConfig(swatch)); }
private Rect CalcSwatchRect(Rect totalRect, Swatch s) { float time = s.m_Time; return new Rect((totalRect.x + Mathf.Round(totalRect.width * time)) - 5f, totalRect.y, 10f, totalRect.height); }
Rect CalcSwatchRect(Rect totalRect, Swatch s) { float time = s.m_Time; return(new Rect(totalRect.x + Mathf.Round(totalRect.width * time) - 5, totalRect.y, 10, totalRect.height)); }
public ThemeConfig(Swatch swatch) { ThemeName = swatch.Name; }